Skip to content

Commit

Permalink
Inspector nearly finished, except for renaming methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Baltasarq committed May 16, 2016
1 parent 47284ea commit 22df450
Show file tree
Hide file tree
Showing 65 changed files with 1,007 additions and 618 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.class
out
out/
# Backup files
*~
*.bak
Expand Down
612 changes: 292 additions & 320 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion ToDo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
- Needs Math object with sqr, sqrt, PI.
- Needs "os" object with import()... These could be imported objects stored in a special dir (part of the jar) that could be imported.
- Needs libraries, such as Complex. This could be provided with import, and loaded as any transcription.
- Store the last directory
4 changes: 2 additions & 2 deletions src/com/devbaltasarq/pooi/core/Interpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.devbaltasarq.pooi.core.evaluables.Command;
import com.devbaltasarq.pooi.core.evaluables.Method;
import com.devbaltasarq.pooi.core.evaluables.Reference;
import com.devbaltasarq.pooi.core.evaluables.method.InterpretedMethod;
import com.devbaltasarq.pooi.core.evaluables.method.NativeMethod;
import com.devbaltasarq.pooi.core.evaluables.methods.InterpretedMethod;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.exceps.InterpretError;
import com.devbaltasarq.pooi.core.objs.ObjectStr;

Expand Down
78 changes: 77 additions & 1 deletion src/com/devbaltasarq/pooi/core/ObjectBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,22 @@ public String getNameOrValueAsString() {
return toret;
}

/**
* Returns the number of attributes in this object
* @return The number of attributes, as an int.
*/
public int getNumberOfAttributes() {
return this.attributes.size();
}

/**
* Returns the number of methods in this object
* @return the number of methods, as an int
*/
public int getNumberOfMethods() {
return this.methods.size();
}

/** @return the number of objects between this object and root, plus itself */
public int getInheritanceLevel() {
int toret = 1;
Expand Down Expand Up @@ -407,7 +423,7 @@ public String toJson()
public Reference toReference()
{
Attribute[] path = this.getObjectPath();
ArrayList<String> toret = new ArrayList<>();
ArrayList<String> toret = new ArrayList<>( path.length );

for(int i = 0; i < path.length; ++i) {
toret.add( path[ i ].getName() );
Expand Down Expand Up @@ -594,6 +610,66 @@ public Attribute lookUpAttribute(String atrName)
return toret;
}

public void renameMember(String oldName, String newName) throws InterpretError
{
final Attribute attr = this.localLookUpAttribute( oldName );
final Method mth = this.localLookUpMethod( oldName );

if ( attr != null ) {
this.renameAttribute( oldName, newName );
}
else
if ( mth != null ) {
this.renameMethod( oldName, newName );
}
else {
throw new InterpretError( "member " + oldName + " was not found" );
}

return;
}

public void renameMethod(String oldName, String newName) throws InterpretError {

}

public void renameAttribute(String oldName, String newName) throws InterpretError {
final Attribute attr = this.localLookUpAttribute( oldName );
ObjectBag ref = null;

if ( attr != null ) {
try {
ref = attr.getReference();
if ( ref != null ) {
ref.setName( newName );
attr.setName( newName );
this.attributes.remove( oldName );
this.attributes.put( newName, attr );
} else {
throw new InterpretError( "INTERNAL ERROR: reference points to void" );
}
} catch(InterpretError exc) {
if ( ref != null
&& ref.getName().equals( newName ) )
{
ref.setName( oldName );
}

if ( attr != null
&& attr.getName().equals( newName ) )
{
attr.setName( oldName );
this.attributes.remove( newName );
this.attributes.put( oldName, attr );
}

throw exc;
}
} else {
throw new InterpretError( "attribute " + oldName + " was not found" );
}
}

/**
* Returns an attribute by its name, in *this* object *only*
* @param atrName The name of the attribute
Expand Down
6 changes: 3 additions & 3 deletions src/com/devbaltasarq/pooi/core/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import com.devbaltasarq.pooi.core.evaluables.literals.IntLiteral;
import com.devbaltasarq.pooi.core.evaluables.literals.RealLiteral;
import com.devbaltasarq.pooi.core.evaluables.literals.StrLiteral;
import com.devbaltasarq.pooi.core.evaluables.method.InterpretedMethod;
import com.devbaltasarq.pooi.core.evaluables.method.nativemethods.NativeMethodSet;
import com.devbaltasarq.pooi.core.evaluables.method.nativemethods.NativeMethodStr;
import com.devbaltasarq.pooi.core.evaluables.methods.InterpretedMethod;
import com.devbaltasarq.pooi.core.evaluables.methods.nativemethods.NativeMethodSet;
import com.devbaltasarq.pooi.core.evaluables.methods.nativemethods.NativeMethodStr;
import com.devbaltasarq.pooi.core.exceps.InterpretError;

import java.util.ArrayList;
Expand Down
4 changes: 2 additions & 2 deletions src/com/devbaltasarq/pooi/core/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import com.devbaltasarq.pooi.core.evaluables.literals.IntLiteral;
import com.devbaltasarq.pooi.core.evaluables.literals.RealLiteral;
import com.devbaltasarq.pooi.core.evaluables.literals.StrLiteral;
import com.devbaltasarq.pooi.core.evaluables.method.InterpretedMethod;
import com.devbaltasarq.pooi.core.evaluables.method.nativemethods.*;
import com.devbaltasarq.pooi.core.evaluables.methods.InterpretedMethod;
import com.devbaltasarq.pooi.core.evaluables.methods.nativemethods.*;
import com.devbaltasarq.pooi.core.exceps.AttributeNotFound;
import com.devbaltasarq.pooi.core.exceps.InterpretError;
import com.devbaltasarq.pooi.core.objs.*;
Expand Down
21 changes: 21 additions & 0 deletions src/com/devbaltasarq/pooi/core/evaluables/Method.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ public static String getStringFrom(Evaluable e)
return toret;
}

/**
* Returns a list with the formal parameters of the method
* @return a primitive vector of String, containing the formal parameters
*/
public abstract String[] getFormalParameters();

/**
* Returns a string with the formal parameters of the method
* @return a String, with the formal parameters
*/
public String getFormalParametersAsString() {
StringBuilder toret = new StringBuilder();

for(String param: this.getFormalParameters()) {
toret.append( toret );
toret.append( ' ' );
}

return toret.toString().trim();
}

/** @return Gets the body of the method as a representation in text */
public abstract String getMethodBodyAsString();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devbaltasarq.pooi.core.evaluables.method;
package com.devbaltasarq.pooi.core.evaluables.methods;

import com.devbaltasarq.pooi.core.*;
import com.devbaltasarq.pooi.core.evaluables.Command;
Expand Down Expand Up @@ -47,7 +47,7 @@ public void setCmds(String cmds) throws InterpretError

public void setRealParams(ObjectBag self, Evaluable[] args) throws InterpretError
{
String[] formalParams = this.getFormalParams();
String[] formalParams = this.getFormalParameters();

if ( args.length != formalParams.length ) {
throw new InterpretError( "formal and real arguments do not match" );
Expand Down Expand Up @@ -145,7 +145,8 @@ public Evaluable getRealParameter(String id)
return ( this.params.get( id ) );
}

public String[] getFormalParams()
@Override
public String[] getFormalParameters()
{
return this.formalParams;
}
Expand All @@ -157,7 +158,7 @@ public String getMethodBodyAsString() {
toret.append( "{" );

// Add params
for(String param: this.getFormalParams()) {
for(String param: this.getFormalParameters()) {
toret.append( param );
toret.append( ' ' );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.devbaltasarq.pooi.core.evaluables.method;
package com.devbaltasarq.pooi.core.evaluables.methods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.devbaltasarq.pooi.core.evaluables.method.nativemethods;
package com.devbaltasarq.pooi.core.evaluables.methods.nativemethods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.evaluables.method.NativeMethod;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.exceps.InterpretError;

/**
Expand Down Expand Up @@ -41,4 +41,9 @@ public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
public int getNumParams() {
return 0;
}

@Override
public String[] getFormalParameters() {
return new String[ 0 ];
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.devbaltasarq.pooi.core.evaluables.method.nativemethods;
package com.devbaltasarq.pooi.core.evaluables.methods.nativemethods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.evaluables.method.NativeMethod;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.exceps.InterpretError;

/**
Expand Down Expand Up @@ -37,4 +37,9 @@ public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
public int getNumParams() {
return 0;
}

@Override
public String[] getFormalParameters() {
return new String[ 0 ];
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.devbaltasarq.pooi.core.evaluables.method.nativemethods;
package com.devbaltasarq.pooi.core.evaluables.methods.nativemethods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.evaluables.method.NativeMethod;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.exceps.InterpretError;

/**
Expand Down Expand Up @@ -39,4 +39,9 @@ public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
public int getNumParams() {
return 1;
}

@Override
public String[] getFormalParameters() {
return new String[]{ "attrName" };
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.devbaltasarq.pooi.core.evaluables.method.nativemethods;
package com.devbaltasarq.pooi.core.evaluables.methods.nativemethods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.Runtime;
import com.devbaltasarq.pooi.core.evaluables.method.NativeMethod;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.exceps.InterpretError;

/**
Expand Down Expand Up @@ -33,4 +33,9 @@ public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
public int getNumParams() {
return 0;
}

@Override
public String[] getFormalParameters() {
return new String[ 0 ];
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.devbaltasarq.pooi.core.evaluables.method.nativemethods;
package com.devbaltasarq.pooi.core.evaluables.methods.nativemethods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.Runtime;
import com.devbaltasarq.pooi.core.evaluables.method.NativeMethod;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.exceps.InterpretError;

/**
Expand Down Expand Up @@ -33,4 +33,9 @@ public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
public int getNumParams() {
return 0;
}

@Override
public String[] getFormalParameters() {
return new String[ 0 ];
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.devbaltasarq.pooi.core.evaluables.method.nativemethods;
package com.devbaltasarq.pooi.core.evaluables.methods.nativemethods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.Runtime;
import com.devbaltasarq.pooi.core.evaluables.method.NativeMethod;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.exceps.InterpretError;
import com.devbaltasarq.pooi.core.objs.ObjectInt;

Expand Down Expand Up @@ -44,4 +44,9 @@ public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
public int getNumParams() {
return 0;
}

@Override
public String[] getFormalParameters() {
return new String[ 0 ];
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.devbaltasarq.pooi.core.evaluables.method.nativemethods;
package com.devbaltasarq.pooi.core.evaluables.methods.nativemethods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.Runtime;
import com.devbaltasarq.pooi.core.evaluables.method.NativeMethod;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.exceps.InterpretError;
import com.devbaltasarq.pooi.core.objs.ObjectInt;
import com.devbaltasarq.pooi.core.objs.ObjectReal;
Expand Down Expand Up @@ -80,4 +80,9 @@ public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
public int getNumParams() {
return 1;
}

@Override
public String[] getFormalParameters() {
return new String[]{ "x" };
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.devbaltasarq.pooi.core.evaluables.method.nativemethods;
package com.devbaltasarq.pooi.core.evaluables.methods.nativemethods;

import com.devbaltasarq.pooi.core.Evaluable;
import com.devbaltasarq.pooi.core.ObjectBag;
import com.devbaltasarq.pooi.core.Runtime;
import com.devbaltasarq.pooi.core.evaluables.method.NativeMethod;
import com.devbaltasarq.pooi.core.evaluables.methods.NativeMethod;
import com.devbaltasarq.pooi.core.exceps.InterpretError;
import com.devbaltasarq.pooi.core.objs.ObjectInt;
import com.devbaltasarq.pooi.core.objs.ObjectReal;
Expand Down Expand Up @@ -64,4 +64,9 @@ public ObjectBag doIt(ObjectBag ref, Evaluable[] params, StringBuilder msg)
public int getNumParams() {
return 1;
}

@Override
public String[] getFormalParameters() {
return new String[]{ "x" };
}
}
Loading

0 comments on commit 22df450

Please sign in to comment.