Removing FESI from Trunk
This commit is contained in:
parent
817262b331
commit
d4b8b3c2af
145 changed files with 0 additions and 33117 deletions
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTAllocationExpression.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTAllocationExpression extends SimpleNode {
|
||||
public ASTAllocationExpression(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTAllocationExpression(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTAllocationExpression(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTAllocationExpression(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTAndExpressionSequence.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTAndExpressionSequence extends SimpleNode {
|
||||
public ASTAndExpressionSequence(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTAndExpressionSequence(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTAndExpressionSequence(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTAndExpressionSequence(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTAssignmentExpression.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTAssignmentExpression extends SimpleNode {
|
||||
public ASTAssignmentExpression(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTAssignmentExpression(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTAssignmentExpression(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTAssignmentExpression(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTBinaryExpressionSequence.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTBinaryExpressionSequence extends SimpleNode {
|
||||
public ASTBinaryExpressionSequence(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTBinaryExpressionSequence(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTBinaryExpressionSequence(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTBinaryExpressionSequence(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTBreakStatement.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTBreakStatement extends SimpleNode {
|
||||
public ASTBreakStatement(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTBreakStatement(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTBreakStatement(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTBreakStatement(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTCompositeReference.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTCompositeReference extends SimpleNode {
|
||||
public ASTCompositeReference(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTCompositeReference(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTCompositeReference(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTCompositeReference(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTConditionalExpression.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTConditionalExpression extends SimpleNode {
|
||||
public ASTConditionalExpression(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTConditionalExpression(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTConditionalExpression(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTConditionalExpression(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTContinueStatement.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTContinueStatement extends SimpleNode {
|
||||
public ASTContinueStatement(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTContinueStatement(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTContinueStatement(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTContinueStatement(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTEmptyExpression.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTEmptyExpression extends SimpleNode {
|
||||
public ASTEmptyExpression(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTEmptyExpression(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTEmptyExpression(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTEmptyExpression(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTExpressionList.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTExpressionList extends SimpleNode {
|
||||
public ASTExpressionList(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTExpressionList(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTExpressionList(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTExpressionList(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTForInStatement.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTForInStatement extends SimpleNode {
|
||||
public ASTForInStatement(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTForInStatement(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTForInStatement(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTForInStatement(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTForStatement.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTForStatement extends SimpleNode {
|
||||
public ASTForStatement(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTForStatement(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTForStatement(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTForStatement(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTForVarInStatement.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTForVarInStatement extends SimpleNode {
|
||||
public ASTForVarInStatement(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTForVarInStatement(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTForVarInStatement(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTForVarInStatement(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTForVarStatement.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTForVarStatement extends SimpleNode {
|
||||
public ASTForVarStatement(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTForVarStatement(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTForVarStatement(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTForVarStatement(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTFormalParameterList.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTFormalParameterList extends SimpleNode {
|
||||
public ASTFormalParameterList(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTFormalParameterList(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTFormalParameterList(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTFormalParameterList(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
// JMCL
|
||||
public String [] getArguments() {
|
||||
int n = jjtGetNumChildren();
|
||||
String [] args = new String[n];
|
||||
for (int i=0; i<n; i++) {
|
||||
ASTIdentifier idNode = (ASTIdentifier) (jjtGetChild(i));
|
||||
args[i]=idNode.getName();
|
||||
}
|
||||
return args;
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTFunctionCallParameters.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTFunctionCallParameters extends SimpleNode {
|
||||
public ASTFunctionCallParameters(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTFunctionCallParameters(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTFunctionCallParameters(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTFunctionCallParameters(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTFunctionDeclaration.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTFunctionDeclaration extends SimpleNode {
|
||||
|
||||
private String sourceString = null;
|
||||
|
||||
public ASTFunctionDeclaration(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTFunctionDeclaration(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTFunctionDeclaration(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTFunctionDeclaration(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
public void setSourceString(String sourceString) {
|
||||
this.sourceString = sourceString;
|
||||
}
|
||||
public String getSourceString() {
|
||||
return sourceString;
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTIdentifier.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTIdentifier extends SimpleNode {
|
||||
|
||||
private String identifierName = null;
|
||||
private int hash = 0;
|
||||
|
||||
public ASTIdentifier(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTIdentifier(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTIdentifier(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTIdentifier(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
// JMCL
|
||||
public void setName(String identifierName) {
|
||||
this.identifierName = identifierName.intern(); // to lower number of strings
|
||||
this.hash = identifierName.hashCode();
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return identifierName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "<" + identifierName + ">";
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTIfStatement.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTIfStatement extends SimpleNode {
|
||||
public ASTIfStatement(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTIfStatement(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTIfStatement(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTIfStatement(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,210 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTLiteral.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
import FESI.Data.*;
|
||||
import FESI.Exceptions.*;
|
||||
|
||||
|
||||
public class ASTLiteral extends SimpleNode {
|
||||
|
||||
private ESValue theValue = null;
|
||||
|
||||
public ASTLiteral(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTLiteral(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTLiteral(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTLiteral(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
// JMCL
|
||||
public ESValue getValue() {
|
||||
return theValue;
|
||||
}
|
||||
|
||||
static final int hexval(char c) throws ProgrammingError {
|
||||
switch(c)
|
||||
{
|
||||
case '0' :
|
||||
return 0;
|
||||
case '1' :
|
||||
return 1;
|
||||
case '2' :
|
||||
return 2;
|
||||
case '3' :
|
||||
return 3;
|
||||
case '4' :
|
||||
return 4;
|
||||
case '5' :
|
||||
return 5;
|
||||
case '6' :
|
||||
return 6;
|
||||
case '7' :
|
||||
return 7;
|
||||
case '8' :
|
||||
return 8;
|
||||
case '9' :
|
||||
return 9;
|
||||
|
||||
case 'a' :
|
||||
case 'A' :
|
||||
return 10;
|
||||
case 'b' :
|
||||
case 'B' :
|
||||
return 11;
|
||||
case 'c' :
|
||||
case 'C' :
|
||||
return 12;
|
||||
case 'd' :
|
||||
case 'D' :
|
||||
return 13;
|
||||
case 'e' :
|
||||
case 'E' :
|
||||
return 14;
|
||||
case 'f' :
|
||||
case 'F' :
|
||||
return 15;
|
||||
}
|
||||
|
||||
throw new ProgrammingError("Illegal hex or unicode constant"); // Should never come here
|
||||
}
|
||||
static final int octval(char c) throws ProgrammingError {
|
||||
switch(c)
|
||||
{
|
||||
case '0' :
|
||||
return 0;
|
||||
case '1' :
|
||||
return 1;
|
||||
case '2' :
|
||||
return 2;
|
||||
case '3' :
|
||||
return 3;
|
||||
case '4' :
|
||||
return 4;
|
||||
case '5' :
|
||||
return 5;
|
||||
case '6' :
|
||||
return 6;
|
||||
case '7' :
|
||||
return 7;
|
||||
case '8' :
|
||||
return 8;
|
||||
case '9' :
|
||||
return 9;
|
||||
|
||||
case 'a' :
|
||||
case 'A' :
|
||||
return 10;
|
||||
case 'b' :
|
||||
case 'B' :
|
||||
return 11;
|
||||
case 'c' :
|
||||
case 'C' :
|
||||
return 12;
|
||||
case 'd' :
|
||||
case 'D' :
|
||||
return 13;
|
||||
case 'e' :
|
||||
case 'E' :
|
||||
return 14;
|
||||
case 'f' :
|
||||
case 'F' :
|
||||
return 15;
|
||||
}
|
||||
|
||||
throw new ProgrammingError("Illegal octal constant"); // Should never come here
|
||||
}
|
||||
|
||||
public void setStringValue(String image) {
|
||||
int l = image.length();
|
||||
StringBuffer sb = new StringBuffer(l);
|
||||
for (int i=0; i<l; i++) {
|
||||
char c = image.charAt(i);
|
||||
if ((c == '\\') && (i+1<l)){
|
||||
i++;
|
||||
c = image.charAt(i);
|
||||
if (c=='n') c='\n';
|
||||
else if (c=='b') c = '\b';
|
||||
else if (c=='f') c = '\f';
|
||||
else if (c=='r') c = '\r';
|
||||
else if (c=='t') c = '\t';
|
||||
else if (c =='x') {
|
||||
c = (char)(hexval(image.charAt(i+1)) << 4 |
|
||||
hexval(image.charAt(i+1)));
|
||||
i +=2;
|
||||
} else if (c =='u') {
|
||||
c = (char)(hexval(image.charAt(i+1)) << 12 |
|
||||
hexval(image.charAt(i+2)) << 8 |
|
||||
hexval(image.charAt(i+3)) << 4 |
|
||||
hexval(image.charAt(i+4)));
|
||||
i +=4;
|
||||
} else if (c >='0' && c <= '7') {
|
||||
c = (char)(octval(image.charAt(i)));
|
||||
if ((image.length()>i) &&
|
||||
(image.charAt(i+1)>='0') && (image.charAt(i+1)<='7')) {
|
||||
i++;
|
||||
c = (char) ((c<<4) | octval(image.charAt(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
theValue = new ESString(sb.toString());
|
||||
}
|
||||
public void setDecimalValue(String image) {
|
||||
try {
|
||||
theValue = new ESNumber(Long.parseLong(image));
|
||||
} catch (NumberFormatException e) {
|
||||
Double value = new Double(image);
|
||||
theValue = new ESNumber(value.doubleValue());
|
||||
}
|
||||
}
|
||||
public void setOctalValue(String image) {
|
||||
try {
|
||||
String imageWithout0 = image.substring(1);
|
||||
theValue = new ESNumber(Long.parseLong(imageWithout0,8));
|
||||
} catch (NumberFormatException e) {
|
||||
Double value = new Double(image);
|
||||
theValue = new ESNumber(value.doubleValue());
|
||||
}
|
||||
}
|
||||
public void setHexValue(String image) {
|
||||
try {
|
||||
String imageWithout0x = image.substring(2);
|
||||
theValue = new ESNumber(Long.parseLong(imageWithout0x,16));
|
||||
} catch (NumberFormatException e) {
|
||||
Double value = new Double(image);
|
||||
theValue = new ESNumber(value.doubleValue());
|
||||
}
|
||||
}
|
||||
public void setFloatingPointValue(String image) {
|
||||
Double value = new Double(image);
|
||||
theValue = new ESNumber(value.doubleValue());
|
||||
}
|
||||
public void setBooleanValue(boolean value) {
|
||||
theValue = ESBoolean.makeBoolean(value);
|
||||
}
|
||||
public void setNullValue() {
|
||||
theValue = ESNull.theNull;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "[" + theValue.toString() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTOperator.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTOperator extends SimpleNode {
|
||||
|
||||
private int operatorCode = EOF;
|
||||
|
||||
public ASTOperator(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTOperator(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTOperator(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTOperator(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
// JMCL
|
||||
public void setOperator(int operatorCode) {
|
||||
this.operatorCode = operatorCode;
|
||||
}
|
||||
public int getOperator() {
|
||||
return operatorCode;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "<" + tokenImage[operatorCode] + ">";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTOrExpressionSequence.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTOrExpressionSequence extends SimpleNode {
|
||||
public ASTOrExpressionSequence(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTOrExpressionSequence(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTOrExpressionSequence(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTOrExpressionSequence(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTPostfixExpression.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTPostfixExpression extends SimpleNode {
|
||||
public ASTPostfixExpression(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTPostfixExpression(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTPostfixExpression(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTPostfixExpression(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTProgram.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTProgram extends SimpleNode {
|
||||
public ASTProgram(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTProgram(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTProgram(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTProgram(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTPropertyIdentifierReference.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTPropertyIdentifierReference extends SimpleNode {
|
||||
public ASTPropertyIdentifierReference(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTPropertyIdentifierReference(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTPropertyIdentifierReference(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTPropertyIdentifierReference(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTPropertyValueReference.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTPropertyValueReference extends SimpleNode {
|
||||
public ASTPropertyValueReference(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTPropertyValueReference(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTPropertyValueReference(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTPropertyValueReference(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTReturnStatement.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTReturnStatement extends SimpleNode {
|
||||
public ASTReturnStatement(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTReturnStatement(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTReturnStatement(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTReturnStatement(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTStatement.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTStatement extends SimpleNode {
|
||||
public ASTStatement(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTStatement(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTStatement(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTStatement(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTStatementList.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTStatementList extends SimpleNode {
|
||||
public ASTStatementList(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTStatementList(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTStatementList(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTStatementList(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTThisReference.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTThisReference extends SimpleNode {
|
||||
public ASTThisReference(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTThisReference(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTThisReference(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTThisReference(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTUnaryExpression.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTUnaryExpression extends SimpleNode {
|
||||
public ASTUnaryExpression(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTUnaryExpression(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTUnaryExpression(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTUnaryExpression(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTVariableDeclaration.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTVariableDeclaration extends SimpleNode {
|
||||
public ASTVariableDeclaration(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTVariableDeclaration(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTVariableDeclaration(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTVariableDeclaration(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTWhileStatement.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTWhileStatement extends SimpleNode {
|
||||
public ASTWhileStatement(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTWhileStatement(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTWhileStatement(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTWhileStatement(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. ASTWithStatement.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class ASTWithStatement extends SimpleNode {
|
||||
|
||||
Object evaluationSource = null;
|
||||
|
||||
public ASTWithStatement(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public ASTWithStatement(EcmaScript p, int id) {
|
||||
super(p, id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(int id) {
|
||||
return new ASTWithStatement(id);
|
||||
}
|
||||
|
||||
public static Node jjtCreate(EcmaScript p, int id) {
|
||||
return new ASTWithStatement(p, id);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
// JMCL
|
||||
public void setEvaluationSource(Object evaluationSource) {
|
||||
this.evaluationSource = evaluationSource;
|
||||
}
|
||||
|
||||
public Object getEvaluationSource() {
|
||||
return evaluationSource;
|
||||
}
|
||||
}
|
|
@ -1,263 +0,0 @@
|
|||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
|
||||
public class EcmaScriptDumpVisitor implements EcmaScriptVisitor
|
||||
{
|
||||
private int indent = 0;
|
||||
|
||||
private String indentString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < indent; ++i) {
|
||||
sb.append(" ");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object visit(SimpleNode node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTProgram node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTStatementList node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTFunctionDeclaration node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTFormalParameterList node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTStatement node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTVariableDeclaration node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTIfStatement node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTWhileStatement node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTForStatement node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTForInStatement node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTForVarStatement node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTForVarInStatement node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTContinueStatement node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTBreakStatement node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTReturnStatement node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTWithStatement node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTThisReference node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTCompositeReference node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTFunctionCallParameters node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTPropertyIdentifierReference node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTPropertyValueReference node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTAllocationExpression node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTOperator node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTPostfixExpression node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTUnaryExpression node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTBinaryExpressionSequence node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTOrExpressionSequence node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTAndExpressionSequence node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTConditionalExpression node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTAssignmentExpression node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTExpressionList node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTEmptyExpression node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTLiteral node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
public Object visit(ASTIdentifier node, Object data) {
|
||||
System.out.println(indentString() + node);
|
||||
++indent;
|
||||
data = node.childrenAccept(this, data);
|
||||
--indent;
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. EcmaScriptTreeConstants.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
public interface EcmaScriptTreeConstants
|
||||
{
|
||||
public int JJTLITERAL = 0;
|
||||
public int JJTIDENTIFIER = 1;
|
||||
public int JJTVOID = 2;
|
||||
public int JJTTHISREFERENCE = 3;
|
||||
public int JJTCOMPOSITEREFERENCE = 4;
|
||||
public int JJTFUNCTIONCALLPARAMETERS = 5;
|
||||
public int JJTPROPERTYVALUEREFERENCE = 6;
|
||||
public int JJTPROPERTYIDENTIFIERREFERENCE = 7;
|
||||
public int JJTALLOCATIONEXPRESSION = 8;
|
||||
public int JJTOPERATOR = 9;
|
||||
public int JJTPOSTFIXEXPRESSION = 10;
|
||||
public int JJTUNARYEXPRESSION = 11;
|
||||
public int JJTBINARYEXPRESSIONSEQUENCE = 12;
|
||||
public int JJTANDEXPRESSIONSEQUENCE = 13;
|
||||
public int JJTOREXPRESSIONSEQUENCE = 14;
|
||||
public int JJTCONDITIONALEXPRESSION = 15;
|
||||
public int JJTASSIGNMENTEXPRESSION = 16;
|
||||
public int JJTEXPRESSIONLIST = 17;
|
||||
public int JJTSTATEMENT = 18;
|
||||
public int JJTSTATEMENTLIST = 19;
|
||||
public int JJTVARIABLEDECLARATION = 20;
|
||||
public int JJTIFSTATEMENT = 21;
|
||||
public int JJTWHILESTATEMENT = 22;
|
||||
public int JJTFORSTATEMENT = 23;
|
||||
public int JJTEMPTYEXPRESSION = 24;
|
||||
public int JJTFORVARSTATEMENT = 25;
|
||||
public int JJTFORINSTATEMENT = 26;
|
||||
public int JJTFORVARINSTATEMENT = 27;
|
||||
public int JJTCONTINUESTATEMENT = 28;
|
||||
public int JJTBREAKSTATEMENT = 29;
|
||||
public int JJTRETURNSTATEMENT = 30;
|
||||
public int JJTWITHSTATEMENT = 31;
|
||||
public int JJTFUNCTIONDECLARATION = 32;
|
||||
public int JJTFORMALPARAMETERLIST = 33;
|
||||
public int JJTPROGRAM = 34;
|
||||
|
||||
|
||||
public String[] jjtNodeName = {
|
||||
"Literal",
|
||||
"Identifier",
|
||||
"void",
|
||||
"ThisReference",
|
||||
"CompositeReference",
|
||||
"FunctionCallParameters",
|
||||
"PropertyValueReference",
|
||||
"PropertyIdentifierReference",
|
||||
"AllocationExpression",
|
||||
"Operator",
|
||||
"PostfixExpression",
|
||||
"UnaryExpression",
|
||||
"BinaryExpressionSequence",
|
||||
"AndExpressionSequence",
|
||||
"OrExpressionSequence",
|
||||
"ConditionalExpression",
|
||||
"AssignmentExpression",
|
||||
"ExpressionList",
|
||||
"Statement",
|
||||
"StatementList",
|
||||
"VariableDeclaration",
|
||||
"IfStatement",
|
||||
"WhileStatement",
|
||||
"ForStatement",
|
||||
"EmptyExpression",
|
||||
"ForVarStatement",
|
||||
"ForInStatement",
|
||||
"ForVarInStatement",
|
||||
"ContinueStatement",
|
||||
"BreakStatement",
|
||||
"ReturnStatement",
|
||||
"WithStatement",
|
||||
"FunctionDeclaration",
|
||||
"FormalParameterList",
|
||||
"Program",
|
||||
};
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. EcmaScriptVisitor.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
public interface EcmaScriptVisitor
|
||||
{
|
||||
public Object visit(SimpleNode node, Object data);
|
||||
public Object visit(ASTLiteral node, Object data);
|
||||
public Object visit(ASTIdentifier node, Object data);
|
||||
public Object visit(ASTThisReference node, Object data);
|
||||
public Object visit(ASTCompositeReference node, Object data);
|
||||
public Object visit(ASTFunctionCallParameters node, Object data);
|
||||
public Object visit(ASTPropertyValueReference node, Object data);
|
||||
public Object visit(ASTPropertyIdentifierReference node, Object data);
|
||||
public Object visit(ASTAllocationExpression node, Object data);
|
||||
public Object visit(ASTOperator node, Object data);
|
||||
public Object visit(ASTPostfixExpression node, Object data);
|
||||
public Object visit(ASTUnaryExpression node, Object data);
|
||||
public Object visit(ASTBinaryExpressionSequence node, Object data);
|
||||
public Object visit(ASTAndExpressionSequence node, Object data);
|
||||
public Object visit(ASTOrExpressionSequence node, Object data);
|
||||
public Object visit(ASTConditionalExpression node, Object data);
|
||||
public Object visit(ASTAssignmentExpression node, Object data);
|
||||
public Object visit(ASTExpressionList node, Object data);
|
||||
public Object visit(ASTStatement node, Object data);
|
||||
public Object visit(ASTStatementList node, Object data);
|
||||
public Object visit(ASTVariableDeclaration node, Object data);
|
||||
public Object visit(ASTIfStatement node, Object data);
|
||||
public Object visit(ASTWhileStatement node, Object data);
|
||||
public Object visit(ASTForStatement node, Object data);
|
||||
public Object visit(ASTEmptyExpression node, Object data);
|
||||
public Object visit(ASTForVarStatement node, Object data);
|
||||
public Object visit(ASTForInStatement node, Object data);
|
||||
public Object visit(ASTForVarInStatement node, Object data);
|
||||
public Object visit(ASTContinueStatement node, Object data);
|
||||
public Object visit(ASTBreakStatement node, Object data);
|
||||
public Object visit(ASTReturnStatement node, Object data);
|
||||
public Object visit(ASTWithStatement node, Object data);
|
||||
public Object visit(ASTFunctionDeclaration node, Object data);
|
||||
public Object visit(ASTFormalParameterList node, Object data);
|
||||
public Object visit(ASTProgram node, Object data);
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. JJTEcmaScriptState.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
public class JJTEcmaScriptState {
|
||||
private java.util.Stack nodes;
|
||||
private java.util.Stack marks;
|
||||
|
||||
private int sp; // number of nodes on stack
|
||||
private int mk; // current mark
|
||||
private boolean node_created;
|
||||
|
||||
public JJTEcmaScriptState() {
|
||||
nodes = new java.util.Stack();
|
||||
marks = new java.util.Stack();
|
||||
sp = 0;
|
||||
mk = 0;
|
||||
}
|
||||
|
||||
/* Determines whether the current node was actually closed and
|
||||
pushed. This should only be called in the final user action of a
|
||||
node scope. */
|
||||
public boolean nodeCreated() {
|
||||
return node_created;
|
||||
}
|
||||
|
||||
/* Call this to reinitialize the node stack. It is called
|
||||
automatically by the parser's ReInit() method. */
|
||||
public void reset() {
|
||||
nodes.removeAllElements();
|
||||
marks.removeAllElements();
|
||||
sp = 0;
|
||||
mk = 0;
|
||||
}
|
||||
|
||||
/* Returns the root node of the AST. It only makes sense to call
|
||||
this after a successful parse. */
|
||||
public Node rootNode() {
|
||||
return (Node)nodes.elementAt(0);
|
||||
}
|
||||
|
||||
/* Pushes a node on to the stack. */
|
||||
public void pushNode(Node n) {
|
||||
nodes.push(n);
|
||||
++sp;
|
||||
}
|
||||
|
||||
/* Returns the node on the top of the stack, and remove it from the
|
||||
stack. */
|
||||
public Node popNode() {
|
||||
if (--sp < mk) {
|
||||
mk = ((Integer)marks.pop()).intValue();
|
||||
}
|
||||
return (Node)nodes.pop();
|
||||
}
|
||||
|
||||
/* Returns the node currently on the top of the stack. */
|
||||
public Node peekNode() {
|
||||
return (Node)nodes.peek();
|
||||
}
|
||||
|
||||
/* Returns the number of children on the stack in the current node
|
||||
scope. */
|
||||
public int nodeArity() {
|
||||
return sp - mk;
|
||||
}
|
||||
|
||||
|
||||
public void clearNodeScope(Node n) {
|
||||
while (sp > mk) {
|
||||
popNode();
|
||||
}
|
||||
mk = ((Integer)marks.pop()).intValue();
|
||||
}
|
||||
|
||||
|
||||
public void openNodeScope(Node n) {
|
||||
marks.push(new Integer(mk));
|
||||
mk = sp;
|
||||
n.jjtOpen();
|
||||
}
|
||||
|
||||
|
||||
/* A definite node is constructed from a specified number of
|
||||
children. That number of nodes are popped from the stack and
|
||||
made the children of the definite node. Then the definite node
|
||||
is pushed on to the stack. */
|
||||
public void closeNodeScope(Node n, int num) {
|
||||
mk = ((Integer)marks.pop()).intValue();
|
||||
while (num-- > 0) {
|
||||
Node c = popNode();
|
||||
c.jjtSetParent(n);
|
||||
n.jjtAddChild(c, num);
|
||||
}
|
||||
n.jjtClose();
|
||||
pushNode(n);
|
||||
node_created = true;
|
||||
}
|
||||
|
||||
|
||||
/* A conditional node is constructed if its condition is true. All
|
||||
the nodes that have been pushed since the node was opened are
|
||||
made children of the the conditional node, which is then pushed
|
||||
on to the stack. If the condition is false the node is not
|
||||
constructed and they are left on the stack. */
|
||||
public void closeNodeScope(Node n, boolean condition) {
|
||||
if (condition) {
|
||||
int a = nodeArity();
|
||||
mk = ((Integer)marks.pop()).intValue();
|
||||
while (a-- > 0) {
|
||||
Node c = popNode();
|
||||
c.jjtSetParent(n);
|
||||
n.jjtAddChild(c, a);
|
||||
}
|
||||
n.jjtClose();
|
||||
pushNode(n);
|
||||
node_created = true;
|
||||
} else {
|
||||
mk = ((Integer)marks.pop()).intValue();
|
||||
node_created = false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. Node.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
/* All AST nodes must implement this interface. It provides basic
|
||||
machinery for constructing the parent and child relationships
|
||||
between nodes. */
|
||||
|
||||
public interface Node {
|
||||
|
||||
/** This method is called after the node has been made the current
|
||||
node. It indicates that child nodes can now be added to it. */
|
||||
public void jjtOpen();
|
||||
|
||||
/** This method is called after all the child nodes have been
|
||||
added. */
|
||||
public void jjtClose();
|
||||
|
||||
/** This pair of methods are used to inform the node of its
|
||||
parent. */
|
||||
public void jjtSetParent(Node n);
|
||||
public Node jjtGetParent();
|
||||
|
||||
/** This method tells the node to add its argument to the node's
|
||||
list of children. */
|
||||
public void jjtAddChild(Node n, int i);
|
||||
|
||||
/** This method returns a child node. The children are numbered
|
||||
from zero, left to right. */
|
||||
public Node jjtGetChild(int i);
|
||||
|
||||
/** Return the number of children the node has. */
|
||||
public int jjtGetNumChildren();
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data);
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
/* Generated By:JJTree: Do not edit this line. SimpleNode.java */
|
||||
|
||||
package FESI.AST;
|
||||
|
||||
import FESI.Parser.*;
|
||||
import FESI.Exceptions.*;
|
||||
|
||||
public abstract class SimpleNode implements Node, EcmaScriptConstants {
|
||||
protected Node parent;
|
||||
protected Node[] children;
|
||||
protected int id;
|
||||
protected EcmaScript parser;
|
||||
protected int line = 0; // JMCL
|
||||
|
||||
public SimpleNode(int i) {
|
||||
id = i;
|
||||
}
|
||||
|
||||
public SimpleNode(EcmaScript p, int i) {
|
||||
this(i);
|
||||
parser = p;
|
||||
}
|
||||
|
||||
public void jjtOpen() {
|
||||
}
|
||||
|
||||
public void jjtClose() {
|
||||
}
|
||||
|
||||
public void jjtSetParent(Node n) { parent = n; }
|
||||
public Node jjtGetParent() { return parent; }
|
||||
|
||||
public void jjtAddChild(Node n, int i) {
|
||||
if (children == null) {
|
||||
children = new Node[i + 1];
|
||||
} else if (i >= children.length) {
|
||||
Node c[] = new Node[i + 1];
|
||||
System.arraycopy(children, 0, c, 0, children.length);
|
||||
children = c;
|
||||
}
|
||||
children[i] = n;
|
||||
}
|
||||
|
||||
public Node jjtGetChild(int i) {
|
||||
return children[i];
|
||||
}
|
||||
|
||||
public int jjtGetNumChildren() {
|
||||
return (children == null) ? 0 : children.length;
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object jjtAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
return visitor.visit(this, data);
|
||||
}
|
||||
|
||||
/** Accept the visitor. **/
|
||||
public Object childrenAccept(EcmaScriptVisitor visitor, Object data) {
|
||||
if (children != null) {
|
||||
for (int i = 0; i < children.length; ++i) {
|
||||
children[i].jjtAccept(visitor, data);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/* You can override these two methods in subclasses of SimpleNode to
|
||||
customize the way the node appears when the tree is dumped. If
|
||||
your output uses more than one line you should override
|
||||
toString(String), otherwise overriding toString() is probably all
|
||||
you need to do. */
|
||||
|
||||
// JMCL
|
||||
public String toString() {
|
||||
return EcmaScriptTreeConstants.jjtNodeName[id];
|
||||
}
|
||||
public String toString(String prefix) { return prefix + toString(); }
|
||||
|
||||
/* Override this method if you want to customize how the node dumps
|
||||
out its children. */
|
||||
|
||||
public void dump(String prefix) {
|
||||
System.out.println(toString(prefix));
|
||||
if (children != null) {
|
||||
for (int i = 0; i < children.length; ++i) {
|
||||
SimpleNode n = (SimpleNode)children[i];
|
||||
if (n != null) {
|
||||
n.dump(prefix + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// JMCL
|
||||
public void setLineNumber(int line) {
|
||||
this.line = line;
|
||||
}
|
||||
|
||||
public int getLineNumber() {
|
||||
return line;
|
||||
}
|
||||
|
||||
public void assertNoChildren() {
|
||||
if (jjtGetNumChildren()>0) {
|
||||
throw new ProgrammingError("AST Should have no children");
|
||||
}
|
||||
}
|
||||
public void assertOneChild() {
|
||||
if (jjtGetNumChildren()!=1) {
|
||||
throw new ProgrammingError("AST Should have 1 child");
|
||||
}
|
||||
}
|
||||
public void assertTwoChildren() {
|
||||
if (jjtGetNumChildren()!=2) {
|
||||
throw new ProgrammingError("AST Should have 2 children");
|
||||
}
|
||||
}
|
||||
public void assertThreeChildren() {
|
||||
if (jjtGetNumChildren()!=3) {
|
||||
throw new ProgrammingError("AST Should have 3 children");
|
||||
}
|
||||
}
|
||||
public void assertFourChildren() {
|
||||
if (jjtGetNumChildren()!=4) {
|
||||
throw new ProgrammingError("AST Should have 4 children");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) Attribute.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.Attribute
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
import FESI.ClassFile.UTF8Constant;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The Attribute class is an abstract base class for all Attribute types
|
||||
* found in the Java VM ClassFile format specification. This is a simple
|
||||
* implementationd designed to support the minimal functionaliuty required
|
||||
* to emit a valid ClassFile stream.
|
||||
* </p>
|
||||
*/
|
||||
|
||||
abstract class Attribute {
|
||||
|
||||
final static String SOURCEFILE = "SourceFile";
|
||||
final static String CONSTANTVALUE = "ConstantValue";
|
||||
final static String LOCALVARIABLETABLE = "LocalVariableTable";
|
||||
final static String EXCEPTIONS = "Exceptions";
|
||||
final static String LINENUMBERTABLE = "LineNumberTable";
|
||||
final static String CODE = "Code";
|
||||
|
||||
private UTF8Constant name;
|
||||
private ClassFile classFile;
|
||||
|
||||
/**
|
||||
* <p> Construct an Attribute, enter it into the ConstantPool. </p>
|
||||
*/
|
||||
|
||||
protected Attribute(String n, ClassFile cf) {
|
||||
UTF8Constant utf8 = (UTF8Constant)
|
||||
cf.match(ConstantPoolEntry.CONSTANT_UTF8, (Object)n);
|
||||
|
||||
if (utf8 == null) utf8 = new UTF8Constant(n, cf);
|
||||
|
||||
name = utf8;
|
||||
classFile = cf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ClassFile this Attribute is contained within
|
||||
*/
|
||||
|
||||
ClassFile getClassFile() { return classFile; }
|
||||
|
||||
/**
|
||||
* @return the "name" of the Attribute.
|
||||
*/
|
||||
|
||||
String getName() { return name.getString(); }
|
||||
|
||||
/**
|
||||
* @return get the index of this Attribute in the ConstantPool
|
||||
*/
|
||||
|
||||
short getNameConstantPoolIndex() {
|
||||
return name.getConstantPoolIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length of the attribute as defined by the concrete subclass.
|
||||
*/
|
||||
|
||||
abstract int getLength();
|
||||
|
||||
/**
|
||||
* <p> write the concrete Attribute subclass to the stream <p>
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
abstract void write(DataOutputStream dos) throws IOException;
|
||||
|
||||
/**
|
||||
* <p> Compare this Attribute with the object and return equality. </p>
|
||||
*
|
||||
* @return is it equal
|
||||
*/
|
||||
|
||||
abstract public boolean equals(Object o);
|
||||
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) ClassConstant.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.ClassConstant
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
import FESI.ClassFile.UTF8Constant;
|
||||
|
||||
class ClassConstant extends ConstantPoolEntry {
|
||||
|
||||
private UTF8Constant name;
|
||||
|
||||
/**
|
||||
* <p> Construct a CONSTANT_CLASS constant pool entry </p>
|
||||
*/
|
||||
|
||||
ClassConstant(String className, ClassFile cf) {
|
||||
super(CONSTANT_CLASS, cf);
|
||||
|
||||
name = cf.addUTF8Constant(ClassFile.fullyQualifiedForm(className));
|
||||
|
||||
addToConstantPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the CONSTANT_CLASS to the stream </p>
|
||||
*
|
||||
* @param dos the stream.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
|
||||
if (debug()) {
|
||||
System.err.println(getConstantPoolIndex() +
|
||||
" CLASS: " +
|
||||
name.getConstantPoolIndex()
|
||||
);
|
||||
}
|
||||
|
||||
dos.writeByte(getTag());
|
||||
dos.writeShort(name.getConstantPoolIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> return the class represented by the CONSTANT_CLASS </p>
|
||||
*
|
||||
* @return the name of the class
|
||||
*/
|
||||
|
||||
String getClassName() { return name.getString(); }
|
||||
|
||||
/**
|
||||
* <p> returns the Class object for the class represented by the constant. </p>
|
||||
*
|
||||
* @return The java.lang.Class object for the class.
|
||||
*/
|
||||
|
||||
Class getClassObject() throws ClassNotFoundException {
|
||||
return Class.forName(name.getString());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> compare the object, by name or value. </p>
|
||||
*
|
||||
* @param the object for comparison
|
||||
*
|
||||
* @return object equality.
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) return false;
|
||||
|
||||
if (o instanceof String) {
|
||||
return ((String)o).equals(name.getString());
|
||||
} else if (o instanceof ClassConstant) {
|
||||
ClassConstant cc = (ClassConstant)o;
|
||||
|
||||
return name.getString().equals(cc.getClassName());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,469 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) ClassFile.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.ClassFile
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import FESI.ClassFile.Attribute;
|
||||
import FESI.ClassFile.ClassConstant;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
import FESI.ClassFile.FieldDesc;
|
||||
import FESI.ClassFile.MethodDesc;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The ClassFile class is designed to provide lightweight, minimal support
|
||||
* for the runtime construction of Java VM ClassFile's, or Class
|
||||
* implementations.
|
||||
* </p>
|
||||
* <p>
|
||||
* The ClassFile provides API's to construct an in-core description of a
|
||||
* Java class implementation, and subsequently write that description to
|
||||
* a stream which may then be either loaded into the VM via a ClassLoader
|
||||
* or written to some persistent store.
|
||||
* </p>
|
||||
* <p>
|
||||
* It should be noted that the ClassFile provide little or no validation of
|
||||
* the Class it describes during the construction of that description, and
|
||||
* therefore users of this class and package should be familiar with the
|
||||
* contents of the Java VM Specification published by Addison-Wesley.
|
||||
* </p>
|
||||
*/
|
||||
|
||||
final class ClassFile {
|
||||
|
||||
/**
|
||||
* <p> the magic number for Java VM class files. </p>
|
||||
*/
|
||||
|
||||
final private static int MAGIC = 0xcafebabe;
|
||||
|
||||
/**
|
||||
* <p> the major and minor version numbers for Java VM class files. </p>
|
||||
*/
|
||||
|
||||
final private static short MAJOR = 45;
|
||||
final private static short MINOR = 3;
|
||||
|
||||
/**
|
||||
* <p> the access flags constants for Java VM class files. </p>
|
||||
*/
|
||||
|
||||
final static short ACC_PUBLIC = 0x0001;
|
||||
final static short ACC_FINAL = 0x0010;
|
||||
final static short ACC_SUPER = 0x0020;
|
||||
final static short ACC_INTERFACE = 0x0200;
|
||||
final static short ACC_ABSTRACT = 0x0400;
|
||||
|
||||
/*
|
||||
* inst vars represent the format of the classfile itself.
|
||||
*/
|
||||
|
||||
private Vector constantPool = new Vector(1);
|
||||
|
||||
private short accessFlags = (short)(ACC_PUBLIC | ACC_SUPER);
|
||||
|
||||
private ClassConstant thisClass;
|
||||
private ClassConstant superClass;
|
||||
|
||||
private Vector interfaces;
|
||||
private Vector fields;
|
||||
private Vector methods;
|
||||
private Vector attributes;
|
||||
|
||||
/**
|
||||
* @return are we debuging (used to print audit trail).
|
||||
*/
|
||||
|
||||
static boolean debug() { return false; }
|
||||
|
||||
/**
|
||||
* <p> Construct a new ClassFile object. </p>
|
||||
*
|
||||
* @param tClass name of "this" class
|
||||
*
|
||||
* @param sClass name of superclass
|
||||
*
|
||||
*/
|
||||
|
||||
ClassFile(String tClass, String sClass) {
|
||||
thisClass = addClassConstant(tClass);
|
||||
superClass = addClassConstant(sClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Write the constant pool to the stream </p>
|
||||
*
|
||||
* @param dos the stream to write to.
|
||||
*/
|
||||
|
||||
private void writeConstantPool(DataOutputStream dos) throws IOException {
|
||||
|
||||
if (debug()) System.err.println("write constant pool: " + constantPool.size());
|
||||
|
||||
dos.writeShort(constantPool.size() + 1); // for index zero
|
||||
|
||||
for (int i = 0; i < constantPool.size(); i++) {
|
||||
((ConstantPoolEntry)constantPool.elementAt(i)).write(dos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Write the list of interfaces to the stream </p>
|
||||
*
|
||||
* @param dos the stream to write to.
|
||||
*/
|
||||
|
||||
private void writeInterfaces(DataOutputStream dos) throws IOException {
|
||||
if (interfaces != null) {
|
||||
if (debug()) System.err.println("write interfaces: " + interfaces.size());
|
||||
dos.writeShort(interfaces.size());
|
||||
|
||||
for (int i = 0; i < interfaces.size(); i++) {
|
||||
dos.writeShort(
|
||||
((ConstantPoolEntry)interfaces.elementAt(i)).getConstantPoolIndex()
|
||||
);
|
||||
}
|
||||
} else dos.writeShort(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Write the list of Fields defs to the stream </p>
|
||||
*
|
||||
* @param dos the stream to write to.
|
||||
*/
|
||||
|
||||
private void writeFields(DataOutputStream dos) throws IOException {
|
||||
if (fields != null) {
|
||||
if (debug()) System.err.println("write fields: " + fields.size());
|
||||
|
||||
dos.writeShort(fields.size());
|
||||
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
((FieldDesc)fields.elementAt(i)).write(dos);
|
||||
}
|
||||
} else dos.writeShort(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Write the list of Method defs to the stream. </p>
|
||||
*
|
||||
* @param dos the stream to write to.
|
||||
*/
|
||||
|
||||
private void writeMethods(DataOutputStream dos) throws IOException {
|
||||
if (methods != null) {
|
||||
if (debug()) System.err.println("write methods: " + methods.size());
|
||||
|
||||
dos.writeShort(methods.size());
|
||||
|
||||
for (int i = 0; i < methods.size(); i++) {
|
||||
((MethodDesc)methods.elementAt(i)).write(dos);
|
||||
}
|
||||
} else dos.writeShort(0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Write the list of Attributes to the stream </p>
|
||||
*
|
||||
* @param dos the stream to write to.
|
||||
*/
|
||||
|
||||
private void writeAttributes(DataOutputStream dos) throws IOException {
|
||||
if (attributes != null) {
|
||||
if (debug()) System.err.println("write attributes: " + attributes.size());
|
||||
|
||||
dos.writeShort(attributes.size());
|
||||
|
||||
for (int i = 0; i < attributes.size(); i++) {
|
||||
((Attribute)attributes.elementAt(i)).write(dos);
|
||||
}
|
||||
} else dos.writeShort(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Write the ClassFile to the Stream </p>
|
||||
*
|
||||
* @param os the stream to write to.
|
||||
*/
|
||||
|
||||
public synchronized void write(OutputStream os) throws IOException {
|
||||
DataOutputStream dos = new DataOutputStream(os);
|
||||
|
||||
try {
|
||||
dos.writeInt(MAGIC);
|
||||
|
||||
dos.writeShort(MINOR);
|
||||
dos.writeShort(MAJOR);
|
||||
|
||||
writeConstantPool(dos);
|
||||
|
||||
if (debug()) System.err.println("access: " + accessFlags);
|
||||
|
||||
dos.writeShort(accessFlags);
|
||||
|
||||
dos.writeShort(thisClass.getConstantPoolIndex());
|
||||
dos.writeShort(superClass.getConstantPoolIndex());
|
||||
|
||||
writeInterfaces(dos);
|
||||
|
||||
writeFields(dos);
|
||||
|
||||
writeMethods(dos);
|
||||
|
||||
writeAttributes(dos);
|
||||
|
||||
dos.close(); // all done!
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("Bad IO");
|
||||
} catch (Exception e) {
|
||||
System.err.println("Oops");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Add an entry to the Constant Pool. </p>
|
||||
*
|
||||
* @param cpe the new constant pool entry
|
||||
*
|
||||
* @return the index of the new entry in the pool
|
||||
*/
|
||||
|
||||
public synchronized short addConstantPoolEntry(ConstantPoolEntry cpe) {
|
||||
if (!constantPool.contains(cpe)) constantPool.addElement(cpe);
|
||||
|
||||
return (short)(constantPool.indexOf(cpe) + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Find a matching Constant Pool Entry. </p>
|
||||
*
|
||||
* @param tag The tag value of the constant pool entries to match on.
|
||||
* @param value The value to match on.
|
||||
*
|
||||
* @return the matching entry or null.
|
||||
*/
|
||||
|
||||
synchronized ConstantPoolEntry match(byte tag, Object value) {
|
||||
for (int i = 0; i < constantPool.size(); i++) {
|
||||
ConstantPoolEntry cpe = (ConstantPoolEntry)constantPool.elementAt(i);
|
||||
|
||||
if (cpe.getTag() == tag && cpe.equals(value))
|
||||
return cpe;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current value of the accessFlags.
|
||||
*/
|
||||
|
||||
public synchronized short getAccessFlags() { return accessFlags; }
|
||||
|
||||
/**
|
||||
* <p> modify the value of the Class File's access flags </p>
|
||||
*
|
||||
* @param newf the new flag values. [NOT VALIDATED]
|
||||
*/
|
||||
|
||||
public synchronized void setAccessFlags(short newf) {
|
||||
|
||||
// TODO - verify new flag combination.
|
||||
|
||||
accessFlags = newf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newMethod the method desc to add to the class file.
|
||||
*/
|
||||
|
||||
public synchronized void addMethodDesc(MethodDesc newMethod) {
|
||||
if (methods == null) methods = new Vector(1);
|
||||
|
||||
methods.addElement(newMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newField the field desc to add to the class file.
|
||||
*/
|
||||
|
||||
public synchronized void addFieldDesc(FieldDesc newField) {
|
||||
if (fields == null) fields = new Vector(1);
|
||||
|
||||
fields.addElement(newField);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sConstant add a CONSTANT_STRING to the ClassFile.
|
||||
*
|
||||
* @param sConstant the string value to add.
|
||||
*
|
||||
* @return The new StringConstant
|
||||
*/
|
||||
|
||||
public StringConstant addStringConstant(String sConstant) {
|
||||
UTF8Constant c = (UTF8Constant)match(ConstantPoolEntry.CONSTANT_UTF8, sConstant);
|
||||
|
||||
if (c == null) {
|
||||
c = new UTF8Constant(sConstant, this);
|
||||
}
|
||||
|
||||
StringConstant s = new StringConstant(c, this);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Add a new CONSTANT_INTEGER to the Constant Pool </p>
|
||||
*
|
||||
* @param iConstant the integer value to add.
|
||||
*
|
||||
* @return the new IntegerConstant.
|
||||
*/
|
||||
|
||||
public IntegerConstant addIntegerConstant(int iConstant) {
|
||||
IntegerConstant c = (IntegerConstant)match(ConstantPoolEntry.CONSTANT_INTEGER, new Integer(iConstant));
|
||||
|
||||
if (c == null) {
|
||||
c = new IntegerConstant(iConstant, this);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Add a new UTF8_CONSTANT to the constant pool </p>
|
||||
*
|
||||
* @param sConstant the string to add.
|
||||
*
|
||||
* @return the new UUTF8Constant
|
||||
*/
|
||||
|
||||
public UTF8Constant addUTF8Constant(String sConstant) {
|
||||
UTF8Constant c = (UTF8Constant)match(ConstantPoolEntry.CONSTANT_UTF8, sConstant);
|
||||
|
||||
if (c == null) {
|
||||
c = new UTF8Constant(sConstant, this);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> add a new CONSTANT_CLASS to the Constant Pool </p>
|
||||
*
|
||||
* @param classConstant the name of the class to add
|
||||
*
|
||||
* @return the newly ClassConstant
|
||||
*/
|
||||
|
||||
public ClassConstant addClassConstant(String classConstant) {
|
||||
ClassConstant c = (ClassConstant)match(ConstantPoolEntry.CONSTANT_CLASS, classConstant);
|
||||
|
||||
if (c == null) {
|
||||
c = new ClassConstant(classConstant, this);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> add a CONSTANT_METHOD to the constant pool </p>
|
||||
*
|
||||
* @param cName the name of the defining class
|
||||
* @param mName the method name
|
||||
* @param tName the fully qualified type descriptor for the method
|
||||
*
|
||||
* @return the new created CONSTANT_METHOD
|
||||
*/
|
||||
|
||||
public MethodConstant addMethodConstant(String cName, String mName, String tName) {
|
||||
return new MethodConstant(cName, mName, tName, this);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param cName the name of the defining class
|
||||
* @param fName the name of the field
|
||||
* @param tName the fully qualified type descriptor of the field
|
||||
*
|
||||
* @return the new created CONSTANT_FIELD
|
||||
*/
|
||||
|
||||
public FieldConstant addFieldConstant(String cName, String fName, String tName) {
|
||||
return new FieldConstant(cName, fName, tName, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> add the name of an interface this class implements to the constant pool </p>
|
||||
*
|
||||
* @param iName the name of the interface
|
||||
*/
|
||||
|
||||
public void addInterface(String iName) {
|
||||
if (interfaces == null) interfaces = new Vector(1);
|
||||
|
||||
interfaces.addElement((Object)addClassConstant(iName));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* convenience routine to take a type name and map it to the internal form.
|
||||
* java.lang.Object -> java/lang/Object
|
||||
* </p>
|
||||
*
|
||||
* @param str the string to map
|
||||
*
|
||||
* @return the mapped string value.
|
||||
*/
|
||||
|
||||
public static String fullyQualifiedForm(String str) {
|
||||
return str.replace('.', '/');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* convenience routine to construct type descriptors from fully
|
||||
* qualified names, e.g: java.lang.Object => Ljava/lang/Object;
|
||||
* </p>
|
||||
*
|
||||
* @param str name of a java "type"
|
||||
*
|
||||
* @return the class descriptor.
|
||||
*/
|
||||
|
||||
public static String fieldType(String str) {
|
||||
return "L" + ClassFile.fullyQualifiedForm(str) + ";";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,702 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) Code.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.Code
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import FESI.ClassFile.Attribute;
|
||||
import FESI.ClassFile.ClassConstant;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The Code attribute is defined to describe the implementation for each
|
||||
* Method Implementation in a class. In particular it contains the byte
|
||||
* codes and exception information.
|
||||
* </p>
|
||||
*/
|
||||
|
||||
final class Code extends Attribute {
|
||||
|
||||
final static byte OP_NOP = (byte) 0x00;
|
||||
final static byte OP_ACONST_NULL = (byte) 0x01;
|
||||
|
||||
// int consts
|
||||
|
||||
final static byte OP_ICONST_m1 = (byte) 0x02;
|
||||
final static byte OP_ICONST_0 = (byte) 0x03;
|
||||
final static byte OP_ICONST_1 = (byte) 0x04;
|
||||
final static byte OP_ICONST_2 = (byte) 0x05;
|
||||
final static byte OP_ICONST_3 = (byte) 0x06;
|
||||
final static byte OP_ICONST_4 = (byte) 0x07;
|
||||
final static byte OP_ICONST_5 = (byte) 0x08;
|
||||
|
||||
// long consts
|
||||
|
||||
final static byte OP_LCONST_0 = (byte) 0x09;
|
||||
final static byte OP_LCONST_1 = (byte) 0x0A;
|
||||
|
||||
// float consts
|
||||
|
||||
final static byte OP_FCONST_0 = (byte) 0x0B;
|
||||
final static byte OP_FCONST_1 = (byte) 0x0C;
|
||||
final static byte OP_FCONST_2 = (byte) 0x0D;
|
||||
|
||||
// double consts
|
||||
|
||||
final static byte OP_DCONST_0 = (byte) 0x0E;
|
||||
final static byte OP_DCONST_1 = (byte) 0x0F;
|
||||
|
||||
final static byte OP_BIPUSH = (byte) 0x10;
|
||||
final static byte OP_SIPUSH = (byte) 0x11;
|
||||
|
||||
final static byte OP_LDC = (byte) 0x12;
|
||||
final static byte OP_LDC_WIDE = (byte) 0x13;
|
||||
final static byte OP_LDC2_WIDE = (byte) 0x14;
|
||||
|
||||
|
||||
// typed loads local
|
||||
|
||||
final static byte OP_ILOAD = (byte) 0x15;
|
||||
final static byte OP_LLOAD = (byte) 0x16;
|
||||
final static byte OP_FLOAD = (byte) 0x17;
|
||||
final static byte OP_DLOAD = (byte) 0x18;
|
||||
final static byte OP_ALOAD = (byte) 0x19;
|
||||
|
||||
// int loads
|
||||
|
||||
final static byte OP_ILOAD_0 = (byte) 0x1A;
|
||||
final static byte OP_ILOAD_1 = (byte) 0x1B;
|
||||
final static byte OP_ILOAD_2 = (byte) 0x1C;
|
||||
final static byte OP_ILOAD_3 = (byte) 0x1D;
|
||||
|
||||
// long loads
|
||||
|
||||
final static byte OP_LLOAD_0 = (byte) 0x1E;
|
||||
final static byte OP_LLOAD_1 = (byte) 0x1F;
|
||||
final static byte OP_LLOAD_2 = (byte) 0x20;
|
||||
final static byte OP_LLOAD_3 = (byte) 0x21;
|
||||
|
||||
// float loads
|
||||
|
||||
final static byte OP_FLOAD_0 = (byte) 0x22;
|
||||
final static byte OP_FLOAD_1 = (byte) 0x23;
|
||||
final static byte OP_FLOAD_2 = (byte) 0x24;
|
||||
final static byte OP_FLOAD_3 = (byte) 0x25;
|
||||
|
||||
// double loads
|
||||
|
||||
final static byte OP_DLOAD_0 = (byte) 0x26;
|
||||
final static byte OP_DLOAD_1 = (byte) 0x27;
|
||||
final static byte OP_DLOAD_2 = (byte) 0x28;
|
||||
final static byte OP_DLOAD_3 = (byte) 0x29;
|
||||
|
||||
// ref loads
|
||||
|
||||
final static byte OP_ALOAD_0 = (byte) 0x2A;
|
||||
final static byte OP_ALOAD_1 = (byte) 0x2B;
|
||||
final static byte OP_ALOAD_2 = (byte) 0x2C;
|
||||
final static byte OP_ALOAD_3 = (byte) 0x2D;
|
||||
|
||||
final static byte OP_IALOAD = (byte) 0x2E;
|
||||
final static byte OP_LALOAD = (byte) 0x2F;
|
||||
|
||||
// array loads
|
||||
|
||||
final static byte OP_FALOAD = (byte) 0x30;
|
||||
final static byte OP_DALOAD = (byte) 0x31;
|
||||
final static byte OP_AALOAD = (byte) 0x32;
|
||||
final static byte OP_BALOAD = (byte) 0x33;
|
||||
final static byte OP_CALOAD = (byte) 0x34;
|
||||
final static byte OP_SALOAD = (byte) 0x35;
|
||||
|
||||
final static byte OP_ISTORE = (byte) 0x36;
|
||||
final static byte OP_LSTORE = (byte) 0x37;
|
||||
final static byte OP_FSTORE = (byte) 0x38;
|
||||
final static byte OP_DSTORE = (byte) 0x39;
|
||||
final static byte OP_ASTORE = (byte) 0x3A;
|
||||
|
||||
// int stores
|
||||
|
||||
final static byte OP_ISTORE_0 = (byte) 0x3B;
|
||||
final static byte OP_ISTORE_1 = (byte) 0x3C;
|
||||
final static byte OP_ISTORE_2 = (byte) 0x3D;
|
||||
final static byte OP_ISTORE_3 = (byte) 0x3E;
|
||||
|
||||
// long stores
|
||||
|
||||
final static byte OP_LSTORE_0 = (byte) 0x3F;
|
||||
final static byte OP_LSTORE_1 = (byte) 0x40;
|
||||
final static byte OP_LSTORE_2 = (byte) 0x41;
|
||||
final static byte OP_LSTORE_3 = (byte) 0x42;
|
||||
|
||||
// float stores
|
||||
|
||||
final static byte OP_FSTORE_0 = (byte) 0x43;
|
||||
final static byte OP_FSTORE_1 = (byte) 0x44;
|
||||
final static byte OP_FSTORE_2 = (byte) 0x45;
|
||||
final static byte OP_FSTORE_3 = (byte) 0x46;
|
||||
|
||||
// double stores
|
||||
|
||||
final static byte OP_DSTORE_0 = (byte) 0x47;
|
||||
final static byte OP_DSTORE_1 = (byte) 0x48;
|
||||
final static byte OP_DSTORE_2 = (byte) 0x49;
|
||||
final static byte OP_DSTORE_3 = (byte) 0x4A;
|
||||
|
||||
// ref stores
|
||||
|
||||
final static byte OP_ASTORE_0 = (byte) 0x4B;
|
||||
final static byte OP_ASTORE_1 = (byte) 0x4C;
|
||||
final static byte OP_ASTORE_2 = (byte) 0x4D;
|
||||
final static byte OP_ASTORE_3 = (byte) 0x4E;
|
||||
|
||||
final static byte OP_IASTORE = (byte) 0x4F;
|
||||
|
||||
// array stores
|
||||
|
||||
final static byte OP_LASTORE = (byte) 0x50;
|
||||
final static byte OP_FASTORE = (byte) 0x51;
|
||||
final static byte OP_DASTORE = (byte) 0x52;
|
||||
final static byte OP_AASTORE = (byte) 0x53;
|
||||
final static byte OP_BASTORE = (byte) 0x54;
|
||||
final static byte OP_CASTORE = (byte) 0x55;
|
||||
final static byte OP_SASTORE = (byte) 0x56;
|
||||
|
||||
final static byte OP_POP = (byte) 0x57;
|
||||
final static byte OP_POP2 = (byte) 0x58;
|
||||
|
||||
// dup's
|
||||
|
||||
final static byte OP_DUP = (byte) 0x59;
|
||||
final static byte OP_DUP_X1 = (byte) 0x5A;
|
||||
final static byte OP_DUP_X2 = (byte) 0x5B;
|
||||
final static byte OP_DUP2 = (byte) 0x5C;
|
||||
final static byte OP_DUP2_X1 = (byte) 0x5D;
|
||||
final static byte OP_DUP2_X2 = (byte) 0x5E;
|
||||
final static byte OP_SWAP = (byte) 0x5F;
|
||||
|
||||
// arith
|
||||
|
||||
final static byte OP_IADD = (byte) 0x60;
|
||||
final static byte OP_LADD = (byte) 0x61;
|
||||
final static byte OP_FADD = (byte) 0x62;
|
||||
final static byte OP_DADD = (byte) 0x63;
|
||||
|
||||
final static byte OP_ISUB = (byte) 0x64;
|
||||
final static byte OP_LSUB = (byte) 0x65;
|
||||
final static byte OP_FSUB = (byte) 0x66;
|
||||
final static byte OP_DSUB = (byte) 0x67;
|
||||
|
||||
final static byte OP_IMUL = (byte) 0x68;
|
||||
final static byte OP_LMUL = (byte) 0x69;
|
||||
final static byte OP_FMUL = (byte) 0x6A;
|
||||
final static byte OP_DMUL = (byte) 0x6B;
|
||||
|
||||
final static byte OP_IDIV = (byte) 0x6C;
|
||||
final static byte OP_FDIV = (byte) 0x6E;
|
||||
final static byte OP_LDIV = (byte) 0x6D;
|
||||
final static byte OP_DDIV = (byte) 0x6F;
|
||||
|
||||
// arith misc
|
||||
|
||||
final static byte OP_IREM = (byte) 0x70;
|
||||
final static byte OP_LREM = (byte) 0x71;
|
||||
final static byte OP_FREM = (byte) 0x72;
|
||||
final static byte OP_DREM = (byte) 0x73;
|
||||
|
||||
final static byte OP_INEG = (byte) 0x74;
|
||||
final static byte OP_LNEG = (byte) 0x75;
|
||||
final static byte OP_FNEG = (byte) 0x76;
|
||||
final static byte OP_DNEG = (byte) 0x77;
|
||||
|
||||
final static byte OP_ISHL = (byte) 0x78;
|
||||
final static byte OP_LSHL = (byte) 0x79;
|
||||
|
||||
final static byte OP_ISHR = (byte) 0x7A;
|
||||
final static byte OP_LSHR = (byte) 0x7B;
|
||||
|
||||
final static byte OP_IUSHR = (byte) 0x7C;
|
||||
final static byte OP_LUSHR = (byte) 0x7D;
|
||||
|
||||
final static byte OP_IAND = (byte) 0x7E;
|
||||
final static byte OP_LAND = (byte) 0x7F;
|
||||
|
||||
final static byte OP_IOR = (byte) 0x80;
|
||||
final static byte OP_LOR = (byte) 0x81;
|
||||
|
||||
final static byte OP_IXOR = (byte) 0x82;
|
||||
final static byte OP_LXOR = (byte) 0x83;
|
||||
|
||||
// local int += const
|
||||
|
||||
final static byte OP_IINC = (byte) 0x84;
|
||||
|
||||
// int conversions
|
||||
|
||||
final static byte OP_I2L = (byte) 0x85;
|
||||
final static byte OP_I2F = (byte) 0x86;
|
||||
final static byte OP_I2D = (byte) 0x87;
|
||||
|
||||
// long conversions
|
||||
|
||||
final static byte OP_L2I = (byte) 0x88;
|
||||
final static byte OP_L2F = (byte) 0x89;
|
||||
final static byte OP_L2D = (byte) 0x8A;
|
||||
|
||||
// float conversions
|
||||
|
||||
final static byte OP_F2I = (byte) 0x8B;
|
||||
final static byte OP_F2L = (byte) 0x8C;
|
||||
final static byte OP_F2D = (byte) 0x8D;
|
||||
|
||||
// double conversions
|
||||
|
||||
final static byte OP_D2I = (byte) 0x8E;
|
||||
final static byte OP_D2L = (byte) 0x8F;
|
||||
final static byte OP_D2F = (byte) 0x90;
|
||||
|
||||
// int conversions
|
||||
|
||||
final static byte OP_I2B = (byte) 0x91;
|
||||
final static byte OP_I2C = (byte) 0x92;
|
||||
final static byte OP_I2S = (byte) 0x93;
|
||||
|
||||
// long comparision's
|
||||
|
||||
final static byte OP_LCMP = (byte) 0x94;
|
||||
|
||||
// float comparision's
|
||||
|
||||
final static byte OP_FCMPL = (byte) 0x95;
|
||||
final static byte OP_FCMPG = (byte) 0x96;
|
||||
|
||||
// double comparision's
|
||||
|
||||
final static byte OP_DCMPL = (byte) 0x97;
|
||||
final static byte OP_DCMPG = (byte) 0x98;
|
||||
|
||||
// int to zero comparisions
|
||||
|
||||
final static byte OP_IFEQ = (byte) 0x99;
|
||||
final static byte OP_IFNE = (byte) 0x9A;
|
||||
final static byte OP_IFLT = (byte) 0x9B;
|
||||
final static byte OP_IFGE = (byte) 0x9C;
|
||||
final static byte OP_IFGT = (byte) 0x9D;
|
||||
final static byte OP_IFLE = (byte) 0x9E;
|
||||
|
||||
// int to int comparision's
|
||||
|
||||
final static byte OP_IFICMPEQ = (byte) 0x9F;
|
||||
final static byte OP_IFICMPNE = (byte) 0xA0;
|
||||
final static byte OP_IFICMPLT = (byte) 0xA1;
|
||||
final static byte OP_IFICMPGE = (byte) 0xA2;
|
||||
final static byte OP_IFICMPGT = (byte) 0xA3;
|
||||
final static byte OP_IFICMPLE = (byte) 0xA4;
|
||||
|
||||
// ref comparisions
|
||||
|
||||
final static byte OP_IFACMPEQ = (byte) 0xA5;
|
||||
final static byte OP_IFACMPNE = (byte) 0xA6;
|
||||
|
||||
// goto
|
||||
|
||||
final static byte OP_GOTO = (byte) 0xA7;
|
||||
|
||||
final static byte OP_JSR = (byte) 0xA8;
|
||||
|
||||
final static byte OP_RET = (byte) 0xA9;
|
||||
|
||||
final static byte OP_TABLESWITCH = (byte) 0xAA;
|
||||
|
||||
final static byte OP_LOOKUP_SWITCH = (byte) 0xAB;
|
||||
|
||||
|
||||
// return's
|
||||
|
||||
final static byte OP_IRETURN = (byte) 0xAC;
|
||||
final static byte OP_LRETURN = (byte) 0xAD;
|
||||
final static byte OP_FRETURN = (byte) 0xAE;
|
||||
final static byte OP_DRETURN = (byte) 0xAF;
|
||||
final static byte OP_ARETURN = (byte) 0xB0;
|
||||
final static byte OP_RETURN = (byte) 0xB1;
|
||||
|
||||
|
||||
// getfield's
|
||||
|
||||
final static byte OP_GETSTATIC = (byte) 0xB2;
|
||||
final static byte OP_GETFIELD = (byte) 0xB4;
|
||||
|
||||
// invoke virtual
|
||||
|
||||
final static byte OP_INVOKE_VIRTUAL = (byte) 0xB6;
|
||||
|
||||
// invoke static
|
||||
|
||||
final static byte OP_INVOKE_STATIC = (byte) 0xB8;
|
||||
|
||||
// method invocation
|
||||
|
||||
final static byte OP_INVOKE_SPECIAL = (byte) 0xB7;
|
||||
|
||||
// invoke interface
|
||||
|
||||
final static byte OP_INVOKE_INTERFACE = (byte) 0xB9;
|
||||
|
||||
// new
|
||||
|
||||
final static byte OP_NEW = (byte) 0xBB;
|
||||
|
||||
// array misc
|
||||
|
||||
final static byte OP_NEWARRAY = (byte) 0xBD;
|
||||
|
||||
final static byte ARRAY_T_BOOLEAN = (byte) 0x4;
|
||||
final static byte ARRAY_T_CHAR = (byte) 0x5;
|
||||
final static byte ARRAY_T_FLOAT = (byte) 0x6;
|
||||
final static byte ARRAY_T_DOUBLE = (byte) 0x7;
|
||||
final static byte ARRAY_T_BYTE = (byte) 0x8;
|
||||
final static byte ARRAY_T_SHORT = (byte) 0x9;
|
||||
final static byte ARRAY_T_INT = (byte) 0xA;
|
||||
final static byte ARRAY_T_LONG = (byte) 0xB;
|
||||
|
||||
// putfield's
|
||||
|
||||
final static byte OP_PUTSTATIC = (byte) 0xB3;
|
||||
final static byte OP_PUTFIELD = (byte) 0xB5;
|
||||
|
||||
// array's
|
||||
|
||||
final static byte OP_ANEWARRAY = (byte) 0xBD;
|
||||
final static byte OP_ARRAYLENGTH = (byte) 0xBE;
|
||||
|
||||
// exceptions
|
||||
|
||||
final static byte OP_ATHROW = (byte) 0xBF;
|
||||
|
||||
// cast
|
||||
|
||||
final static byte OP_CHECKCAST = (byte) 0xC0;
|
||||
|
||||
// instanceof
|
||||
|
||||
final static byte OP_INSTANCEOF = (byte) 0xC1;
|
||||
|
||||
// monitor
|
||||
|
||||
final static byte OP_MONITOR_ENTER = (byte) 0xC2;
|
||||
final static byte OP_MONITOR_EXIT = (byte) 0xC3;
|
||||
|
||||
// wide
|
||||
|
||||
final static byte OP_WIDE = (byte) 0xC4;
|
||||
|
||||
// arrays
|
||||
|
||||
final static byte OP_MULTI_NEW_ARRAY = (byte) 0xC5;
|
||||
|
||||
// compare to null
|
||||
|
||||
final static byte OP_IFNULL = (byte) 0xc6;
|
||||
final static byte OP_IFNONNULL = (byte) 0xc7;
|
||||
|
||||
// goto wide
|
||||
|
||||
final static byte OP_GOTO_WIDE = (byte) 0xc8;
|
||||
|
||||
final static byte OP_JSR_WIDE = (byte) 0xc9;
|
||||
|
||||
|
||||
/*
|
||||
* inst vars
|
||||
*/
|
||||
|
||||
private Vector attributes;
|
||||
|
||||
private int length = 12; // starting value
|
||||
|
||||
private short currentPC;
|
||||
|
||||
private short maxLocals;
|
||||
|
||||
private short maxStack;
|
||||
|
||||
private Vector byteCodes = new Vector(1);
|
||||
|
||||
private Vector exceptions;
|
||||
|
||||
/**
|
||||
* <p> construct a Code Attribute </p>
|
||||
*
|
||||
* @param locals number of words used to describe local vars
|
||||
* @param maxstack max number of stack words used.
|
||||
*
|
||||
*/
|
||||
|
||||
Code(ClassFile cf, short locals, short stack) {
|
||||
super(CODE, cf);
|
||||
|
||||
maxLocals = (locals >= 0 ? locals : 0);
|
||||
maxStack = (stack > 2 ? stack : 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the code attribute to the stream </p>
|
||||
*
|
||||
* @param dos the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
int i;
|
||||
|
||||
dos.writeShort(getNameConstantPoolIndex());
|
||||
dos.writeInt(getLength());
|
||||
dos.writeShort(maxStack);
|
||||
dos.writeShort(maxLocals);
|
||||
|
||||
// write the code ...
|
||||
|
||||
dos.writeInt(byteCodes.size());
|
||||
|
||||
for (i = 0; i < byteCodes.size(); i++) {
|
||||
dos.writeByte(((Byte)byteCodes.elementAt(i)).byteValue());
|
||||
}
|
||||
|
||||
// write exceptions (if any)
|
||||
|
||||
if (exceptions != null) {
|
||||
dos.writeShort(exceptions.size());
|
||||
|
||||
for (i = 0; i < exceptions.size(); i++) {
|
||||
((ExceptionTableEntry)exceptions.elementAt(i)).write(dos);
|
||||
}
|
||||
} else dos.writeShort(0);
|
||||
|
||||
// write attributes (if any)
|
||||
|
||||
if (attributes != null) {
|
||||
dos.writeShort(attributes.size());
|
||||
|
||||
for (i = 0; i < attributes.size(); i ++) {
|
||||
((Attribute)attributes.elementAt(i)).write(dos);
|
||||
}
|
||||
} else dos.writeShort(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> returns the length of the Code attribute in bytes </p>
|
||||
*
|
||||
* @return the length of the attribute.
|
||||
*/
|
||||
|
||||
int getLength() { return length; }
|
||||
|
||||
/**
|
||||
* @return object equality.
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return ((Object)this).equals(o);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current PC offset from the start of the method.
|
||||
*/
|
||||
|
||||
short getCurrentPC() { return currentPC; }
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* adds per Code attribute, can be used for SourceFile, LocalVariable,
|
||||
* and LineNumberTable attributes etc.
|
||||
* </p>
|
||||
*
|
||||
* @param attr Attribte to be added.
|
||||
*/
|
||||
|
||||
void addAttribute(Attribute attr) {
|
||||
if (attributes == null) attributes = new Vector(1);
|
||||
|
||||
attributes.addElement(attr);
|
||||
length += attr.getLength() + 6; // sizeof(Attribute)
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Adds an entry to the Exception handler table for this Code attribute.
|
||||
* An entry describes the start and stop pc offset within the Code fragment
|
||||
* for which an exception handler is provided, the start pc of the handler
|
||||
* code within the fragment itself, and the class of the exception type
|
||||
* for this handler.
|
||||
* </p>
|
||||
*
|
||||
* @param start start pc offset for this exception handler range
|
||||
* @param stop stop pc offset for this exception handler range
|
||||
* @param handler handler pc start offset for this exception
|
||||
* @param ct CONSTANT_CLASS describing the exception class handled
|
||||
*/
|
||||
|
||||
void addExceptionTableEntry(short start, short stop,
|
||||
short handler, ClassConstant ct) {
|
||||
exceptions.addElement(
|
||||
new ExceptionTableEntry(start, stop, handler, ct)
|
||||
);
|
||||
|
||||
length += 8; // sizeof(ExceptionTableEntry)
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> add an opcode to the implementation </p>
|
||||
*/
|
||||
|
||||
void addOp(byte opCode) {
|
||||
byteCodes.addElement(new Byte(opCode));
|
||||
currentPC++;
|
||||
length++;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> add an opcode and a 1 byte operand </p>
|
||||
*/
|
||||
|
||||
void addOp1(byte opCode, byte op1) {
|
||||
byteCodes.addElement(new Byte(opCode));
|
||||
byteCodes.addElement(new Byte(op1));
|
||||
currentPC += 2;
|
||||
length += 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> add an opcode and 2, 1 byte operands </p>
|
||||
*/
|
||||
|
||||
void addOp2(byte opCode, byte op1, byte op2) {
|
||||
byteCodes.addElement(new Byte(opCode));
|
||||
byteCodes.addElement(new Byte(op1));
|
||||
byteCodes.addElement(new Byte(op2));
|
||||
currentPC += 3;
|
||||
length += 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> add an opcode and 4, 1 byte operands </p>
|
||||
*/
|
||||
|
||||
void addOp4(byte opCode, byte op1, byte op2, byte op3, byte op4) {
|
||||
byteCodes.addElement(new Byte(opCode));
|
||||
byteCodes.addElement(new Byte(op1));
|
||||
byteCodes.addElement(new Byte(op2));
|
||||
byteCodes.addElement(new Byte(op3));
|
||||
byteCodes.addElement(new Byte(op4));
|
||||
currentPC += 5;
|
||||
length += 5;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> add an opcode and a 2 byte operand </p>
|
||||
*/
|
||||
|
||||
void addOpShort(byte opCode,short op) {
|
||||
addOp2(opCode,
|
||||
(byte)((op >>> 8) & 0xff),
|
||||
(byte)( op & 0xff)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> add an opcode and a 4 byte operand </p>
|
||||
*/
|
||||
|
||||
void addOpInt(byte opCode,int op) {
|
||||
addOp4(opCode,
|
||||
(byte)((op >>> 24) & 0xff),
|
||||
(byte)((op >>> 16) & 0xff),
|
||||
(byte)((op >>> 8) & 0xff),
|
||||
(byte)( op & 0xff)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> increment the local word count </p>
|
||||
*
|
||||
* @param n the number of local words to increment by.
|
||||
*/
|
||||
|
||||
void incrLocals(short n) { maxLocals += n; }
|
||||
|
||||
/**
|
||||
* <p> increment the max operand stack word count </p>
|
||||
*
|
||||
* @param n the number of words to increment the max stack count by
|
||||
*/
|
||||
|
||||
void incrMaxStack(short n) { maxStack += n; }
|
||||
}
|
||||
|
||||
/*
|
||||
* private implementation class to represent exception table entries.
|
||||
*/
|
||||
|
||||
final class ExceptionTableEntry {
|
||||
private short startPC;
|
||||
private short stopPC;
|
||||
private short handlerPC;
|
||||
private ClassConstant exceptionType;
|
||||
|
||||
/*
|
||||
* construct and Exception Table Entry
|
||||
*/
|
||||
|
||||
ExceptionTableEntry(short start, short stop,
|
||||
short handler, ClassConstant eType) {
|
||||
super();
|
||||
|
||||
startPC = start;
|
||||
stopPC = stop;
|
||||
handlerPC = handler;
|
||||
exceptionType = eType;
|
||||
}
|
||||
|
||||
/*
|
||||
* wrote the exception table entry to the stream
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeShort(startPC);
|
||||
dos.writeShort(stopPC);
|
||||
dos.writeShort(handlerPC);
|
||||
if (exceptionType != null)
|
||||
dos.writeShort(exceptionType.getConstantPoolIndex());
|
||||
else
|
||||
dos.writeShort(0);
|
||||
}
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) ConstantPoolEntry.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.ConstantPoolEntry
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The ConstantPoolEntry is an abstract base class representing common
|
||||
* behaviors of specific subtypes, as defined below and in the VM spec.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* In particular this class handles, equality, sharing, output and indexing
|
||||
* of all subtypes.
|
||||
* </p>
|
||||
*/
|
||||
|
||||
abstract class ConstantPoolEntry {
|
||||
|
||||
/*
|
||||
* subtype tag values.
|
||||
*/
|
||||
|
||||
final static byte CONSTANT_UTF8 = 1;
|
||||
final static byte CONSTANT_UNICODE = 2;
|
||||
final static byte CONSTANT_INTEGER = 3;
|
||||
final static byte CONSTANT_FLOAT = 4;
|
||||
final static byte CONSTANT_LONG = 5;
|
||||
final static byte CONSTANT_DOUBLE = 6;
|
||||
final static byte CONSTANT_CLASS = 7;
|
||||
final static byte CONSTANT_STRING = 8;
|
||||
final static byte CONSTANT_FIELDREF = 9;
|
||||
final static byte CONSTANT_METHODREF = 10;
|
||||
final static byte CONSTANT_INTERFACEMETHODREF = 11;
|
||||
final static byte CONSTANT_NAMEANDTYPE = 12;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
private byte tag;
|
||||
|
||||
private ClassFile classFile;
|
||||
|
||||
private short index = -1;
|
||||
|
||||
/**
|
||||
* <p> construct the CPE, set the type tag and class file </p>
|
||||
*/
|
||||
|
||||
ConstantPoolEntry(byte t, ClassFile cf) {
|
||||
tag = t;
|
||||
classFile = cf;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
byte getTag() { return tag; }
|
||||
|
||||
/**
|
||||
* @return the CPE's constant pool index.
|
||||
*/
|
||||
|
||||
short getConstantPoolIndex() {
|
||||
if (index == -1) index = classFile.addConstantPoolEntry(this);
|
||||
|
||||
return (short)index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Class File this CPE is contained within.
|
||||
*/
|
||||
|
||||
ClassFile getClassFile() { return classFile; };
|
||||
|
||||
/**
|
||||
* <p> * write the CPE to the stream </p>
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
abstract void write(DataOutputStream dos) throws IOException;
|
||||
|
||||
/**
|
||||
* <p> test the CPE for equality </p>
|
||||
*
|
||||
* @return object's equality.
|
||||
*/
|
||||
|
||||
public abstract boolean equals(Object o);
|
||||
|
||||
/**
|
||||
* <p> add the CPE into the Class File's constant pool </p>
|
||||
*/
|
||||
|
||||
protected void addToConstantPool() {
|
||||
if (index == -1) index = classFile.addConstantPoolEntry(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return are we in debug mode?
|
||||
*/
|
||||
|
||||
protected static boolean debug() { return ClassFile.debug(); }
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) ConstantValue.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.ConstantValue
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.Attribute;
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
import FESI.ClassFile.IntegerConstant;
|
||||
import FESI.ClassFile.FloatConstant;
|
||||
import FESI.ClassFile.DoubleConstant;
|
||||
import FESI.ClassFile.LongConstant;
|
||||
import FESI.ClassFile.StringConstant;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This class provides Constant Pool support for all the simple constant
|
||||
* value data types supported in the class file format.
|
||||
* </p>
|
||||
*/
|
||||
|
||||
class ConstantValue extends Attribute {
|
||||
|
||||
private ConstantPoolEntry constant;
|
||||
|
||||
/**
|
||||
* <p> construct an Attribute describing a Constant </p>
|
||||
*
|
||||
* @param cf the class file
|
||||
* @param cpe the cpe of the constant
|
||||
*/
|
||||
|
||||
private ConstantValue(ClassFile cf, ConstantPoolEntry cpe) {
|
||||
super(Attribute.CONSTANTVALUE, cf);
|
||||
constant = cpe;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Integer Constant </p>
|
||||
*
|
||||
* @param cf the class file
|
||||
* @param ic the Integer Constant
|
||||
*/
|
||||
|
||||
ConstantValue(ClassFile cf, IntegerConstant ic) {
|
||||
this(cf, (ConstantPoolEntry)ic);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Long Constant </p>
|
||||
*
|
||||
* @param cf the class file
|
||||
* @param lc the Long Constant
|
||||
*/
|
||||
|
||||
ConstantValue(ClassFile cf, LongConstant lc) {
|
||||
this(cf, (ConstantPoolEntry)lc);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Float Constant </p>
|
||||
*
|
||||
* @param cf the class file
|
||||
* @param fc the Float Constant
|
||||
*/
|
||||
|
||||
ConstantValue(ClassFile cf, FloatConstant fc) {
|
||||
this(cf, (ConstantPoolEntry)fc);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Double Constant </p>
|
||||
*
|
||||
* @param cf the class file
|
||||
* @param dc the Double Constant
|
||||
*/
|
||||
|
||||
ConstantValue(ClassFile cf, DoubleConstant dc) {
|
||||
this(cf, (ConstantPoolEntry)dc);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> String Constant </p>
|
||||
*
|
||||
* @param cf the class file
|
||||
* @param sc the String Constant
|
||||
*/
|
||||
|
||||
ConstantValue(ClassFile cf, StringConstant sc) {
|
||||
this(cf, (ConstantPoolEntry)sc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length of this ConstantValue Attribute (minus header)
|
||||
*/
|
||||
|
||||
int getLength() { return 2; }
|
||||
|
||||
/**
|
||||
* @return the CPE of the constant represented
|
||||
*/
|
||||
|
||||
ConstantPoolEntry getConstant() { return constant; }
|
||||
|
||||
/**
|
||||
* @return the CPE type tag of the constant represented
|
||||
*/
|
||||
|
||||
byte getConstantTag() { return constant.getTag(); }
|
||||
|
||||
/**
|
||||
*<p> write the Attribute to the stream </p>
|
||||
*
|
||||
* @param dos the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeShort(getNameConstantPoolIndex());
|
||||
dos.writeInt(getLength());
|
||||
dos.writeShort(constant.getConstantPoolIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the objects equality.
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return constant.equals(o);
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) DoubleConstant.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.DoubleConstant
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
|
||||
/**
|
||||
* <p> implements a DOUBLE_CONSTANT CPE </p>
|
||||
*/
|
||||
|
||||
class DoubleConstant extends ConstantPoolEntry {
|
||||
|
||||
private double doubler;
|
||||
|
||||
/**
|
||||
* <p> construct a DOUBLE_CONSTANT CPE </p>
|
||||
*
|
||||
* @param d the double constant
|
||||
* @param cf the class file
|
||||
*/
|
||||
|
||||
DoubleConstant(double d, ClassFile cf) {
|
||||
super(CONSTANT_DOUBLE, cf);
|
||||
|
||||
doubler = d;
|
||||
|
||||
addToConstantPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the constant CPE to the stream </p>
|
||||
*
|
||||
* @param dos the stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeByte(getTag());
|
||||
dos.writeDouble(doubler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the double constant value.
|
||||
*/
|
||||
|
||||
double getValue() { return doubler; }
|
||||
|
||||
/**
|
||||
* @return the object's equality.
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Double) {
|
||||
return doubler == ((Double)o).doubleValue();
|
||||
} else if (o instanceof DoubleConstant) {
|
||||
DoubleConstant dc = (DoubleConstant)o;
|
||||
|
||||
return doubler == dc.getValue();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,809 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) EncapsulatedEventAdaptorClassFile.java 1.3@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.EncapsulatedEventAdaptorClassFile
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import FESI.Interpreter.EventAdaptor;
|
||||
import FESI.Interpreter.EventAdaptorGenerator;
|
||||
|
||||
import FESI.ClassFile.Attribute;
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ClassConstant;
|
||||
import FESI.ClassFile.Code;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
import FESI.ClassFile.Exceptions;
|
||||
import FESI.ClassFile.IntegerConstant;
|
||||
import FESI.ClassFile.FieldDesc;
|
||||
import FESI.ClassFile.FieldConstant;
|
||||
import FESI.ClassFile.MethodDesc;
|
||||
import FESI.ClassFile.MethodConstant;
|
||||
import FESI.ClassFile.StringConstant;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This class is used by the EventAdaptorGenerator to author the
|
||||
* implementation of the EventAdaptor classes that it is responsible
|
||||
* for generating and loading.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* This class wraps all the ClassFile generic support classes and provides
|
||||
* the adaptor specific implemenetation.
|
||||
* </p>
|
||||
*
|
||||
* @see FESI.Interpreter.EventAdaptorGenerator
|
||||
*/
|
||||
|
||||
public final class EventAdaptorClassFile {
|
||||
|
||||
private static String superClassName =
|
||||
"FESI.Interpreter.EventAdaptor";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
private String listenerName;
|
||||
private Class listenerClass;
|
||||
|
||||
private String adaptorName;
|
||||
private ClassFile classFile;
|
||||
|
||||
private Method[] listenerMethods;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
private StringConstant listenerNameConst;
|
||||
|
||||
private FieldConstant methodsField;
|
||||
private FieldConstant clazzField;
|
||||
|
||||
private MethodConstant fireMethod;
|
||||
private MethodConstant crackedFireMethod;
|
||||
|
||||
private MethodConstant forNameMethod;
|
||||
|
||||
private MethodConstant getMethodsMethod;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This statis function creates the class file implementation and writes
|
||||
* it to the stream for loading ...
|
||||
* </p>
|
||||
*
|
||||
* @param className the name of the adaptor class to synthesize.
|
||||
* @param os the stream to write the class file into
|
||||
* @exception IOException If any IO error occured during class loading
|
||||
* @exception ClassNotFoundException If the class could not be loaded
|
||||
*
|
||||
* @returns
|
||||
*/
|
||||
|
||||
public EventAdaptorClassFile(String className, OutputStream os)
|
||||
throws IOException, ClassNotFoundException {
|
||||
|
||||
adaptorName = className;
|
||||
listenerName = EventAdaptorGenerator.getBaseNameFromAdaptorName(className);
|
||||
|
||||
listenerClass = Class.forName(listenerName);
|
||||
|
||||
listenerMethods = listenerClass.getMethods();
|
||||
|
||||
classFile = new ClassFile(className, superClassName);
|
||||
|
||||
// generate the misc class descriptions ...
|
||||
|
||||
generateClassSundries();
|
||||
|
||||
// generate the class initializer
|
||||
|
||||
generateInitializer();
|
||||
|
||||
// now the constructor ...
|
||||
|
||||
generateConstructor();
|
||||
|
||||
// now the methods ...
|
||||
|
||||
generateListenerMethods();
|
||||
|
||||
// write the resulting adaptor class to the stream provided.
|
||||
|
||||
write(os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Are we running debug for this Adaptor generation?
|
||||
*/
|
||||
|
||||
private boolean debug() { return false; }
|
||||
|
||||
/**
|
||||
* Generate misc constant pool entries etc etc ...
|
||||
*/
|
||||
|
||||
private void generateClassSundries() {
|
||||
|
||||
// the adaptor implements the Listener interface.
|
||||
|
||||
classFile.addInterface(ClassFile.fullyQualifiedForm(listenerName));
|
||||
|
||||
listenerNameConst = classFile.addStringConstant(listenerName);
|
||||
|
||||
/*
|
||||
* private static java.lang.reflect.Method[] methods;
|
||||
*/
|
||||
|
||||
classFile.addFieldDesc(
|
||||
new FieldDesc(
|
||||
"methods",
|
||||
"[Ljava/lang/reflect/Method;",
|
||||
(short)(FieldDesc.ACC_STATIC | FieldDesc.ACC_PRIVATE),
|
||||
classFile,
|
||||
(Attribute[])null
|
||||
)
|
||||
);
|
||||
|
||||
methodsField = classFile.addFieldConstant(adaptorName,
|
||||
"methods",
|
||||
"[Ljava/lang/reflect/Method;"
|
||||
);
|
||||
|
||||
/*
|
||||
* java.lang.reflect.Method[] java.lang.reflect.Method.getMethods();
|
||||
*/
|
||||
|
||||
getMethodsMethod = classFile.addMethodConstant(
|
||||
"java/lang/Class",
|
||||
"getMethods",
|
||||
"()[Ljava/lang/reflect/Method;"
|
||||
);
|
||||
|
||||
/*
|
||||
* java.lang.Class java.lang.Class.forName();
|
||||
*/
|
||||
|
||||
forNameMethod = classFile.addMethodConstant(
|
||||
"java/lang/Class",
|
||||
"forName",
|
||||
"(Ljava/lang/String;)Ljava/lang/Class;"
|
||||
);
|
||||
/*
|
||||
* private static java.lang.Class clazz;
|
||||
*/
|
||||
|
||||
classFile.addFieldDesc(
|
||||
new FieldDesc(
|
||||
"clazz",
|
||||
"Ljava/lang/Class;",
|
||||
(short)(FieldDesc.ACC_STATIC | FieldDesc.ACC_PRIVATE),
|
||||
classFile,
|
||||
(Attribute[])null
|
||||
)
|
||||
);
|
||||
|
||||
clazzField = classFile.addFieldConstant(adaptorName,
|
||||
"clazz",
|
||||
"Ljava/lang/Class;"
|
||||
);
|
||||
|
||||
/*
|
||||
* these are superclass methods called from listener stubs ...
|
||||
*/
|
||||
|
||||
fireMethod = classFile.addMethodConstant(
|
||||
adaptorName,
|
||||
"fire",
|
||||
"(Ljava/util/EventObject;Ljava/lang/reflect/Method;)V"
|
||||
);
|
||||
|
||||
crackedFireMethod = classFile.addMethodConstant(
|
||||
adaptorName,
|
||||
"fire",
|
||||
"([Ljava/lang/Object;Ljava/lang/reflect/Method;)V"
|
||||
);
|
||||
|
||||
/*
|
||||
* stub out base class abstract method:
|
||||
*
|
||||
* public static Class getListenerClass() { return clazz; }
|
||||
*
|
||||
*/
|
||||
|
||||
Code c = new Code(classFile, (short)1, (short)2);
|
||||
|
||||
c.addOpShort(Code.OP_GETSTATIC, clazzField.getConstantPoolIndex());
|
||||
c.addOp (Code.OP_ARETURN);
|
||||
|
||||
Code[] ary = { c };
|
||||
|
||||
classFile.addMethodDesc(
|
||||
new MethodDesc(
|
||||
"getListenerClass",
|
||||
"()Ljava/lang/Class;",
|
||||
(short)MethodDesc.ACC_PUBLIC,
|
||||
classFile,
|
||||
ary
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Generate class Initializer method </p>
|
||||
*/
|
||||
|
||||
private void generateInitializer() {
|
||||
Code c = new Code(classFile, (short)0, (short)3);
|
||||
Code[] ary = { c };
|
||||
short i = listenerNameConst.getConstantPoolIndex();
|
||||
|
||||
|
||||
// clazz = Class.forName( <The_Listener_Interface> );
|
||||
|
||||
if (i <= 255)
|
||||
c.addOp1(Code.OP_LDC, (byte)i);
|
||||
else
|
||||
c.addOpShort(Code.OP_LDC_WIDE, i);
|
||||
|
||||
c.addOpShort(Code.OP_INVOKE_STATIC,
|
||||
forNameMethod.getConstantPoolIndex()
|
||||
);
|
||||
|
||||
c.addOp(Code.OP_DUP);
|
||||
|
||||
c.addOpShort(Code.OP_PUTSTATIC,
|
||||
clazzField.getConstantPoolIndex()
|
||||
);
|
||||
|
||||
|
||||
// methods = clazz.getMethods();
|
||||
|
||||
c.addOpShort(Code.OP_INVOKE_VIRTUAL,
|
||||
getMethodsMethod.getConstantPoolIndex()
|
||||
);
|
||||
|
||||
c.addOpShort(Code.OP_PUTSTATIC,
|
||||
methodsField.getConstantPoolIndex()
|
||||
);
|
||||
|
||||
c.addOp (Code.OP_RETURN);
|
||||
|
||||
classFile.addMethodDesc(
|
||||
new MethodDesc(
|
||||
"<clinit>",
|
||||
"()V",
|
||||
(short)(MethodDesc.ACC_PRIVATE | MethodDesc.ACC_STATIC),
|
||||
classFile,
|
||||
ary
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Author the no-args public constructor for this Adaptor
|
||||
*
|
||||
* public void <init>() { super(); }
|
||||
*/
|
||||
|
||||
private void generateConstructor() {
|
||||
Code c = new Code(classFile, (short)1, (short)2);
|
||||
Code[] ary = { c };
|
||||
MethodConstant mc;
|
||||
|
||||
// get a MethodConstant for the superclass constructor
|
||||
|
||||
mc = classFile.addMethodConstant(
|
||||
ClassFile.fullyQualifiedForm(superClassName),
|
||||
"<init>",
|
||||
"()V"
|
||||
);
|
||||
|
||||
// push this onto the stack
|
||||
|
||||
c.addOp (Code.OP_ALOAD_0);
|
||||
|
||||
// call the superclass constructor
|
||||
|
||||
c.addOpShort(Code.OP_INVOKE_SPECIAL, mc.getConstantPoolIndex());
|
||||
|
||||
c.addOp (Code.OP_RETURN);
|
||||
|
||||
|
||||
// now add a method to the class file describing the constructor ...
|
||||
|
||||
classFile.addMethodDesc(
|
||||
new MethodDesc(
|
||||
"<init>",
|
||||
"()V",
|
||||
(short)MethodDesc.ACC_PUBLIC,
|
||||
classFile,
|
||||
ary
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Author the Listener Method Stubs for the EventListener interface
|
||||
* this class is adapting to the EventListener interface.
|
||||
*/
|
||||
|
||||
private void generateListenerMethods() {
|
||||
for (int i = 0; i < listenerMethods.length; i++) {
|
||||
|
||||
/* we can only generate code for EventListener methods of
|
||||
* the form:
|
||||
*
|
||||
* void <method_name> ( <EventObject Subtype> )
|
||||
* or:
|
||||
* void <method_name> ( {<arbitrary arg list>} )
|
||||
*
|
||||
* if we dont match these patterns we drop the method on the
|
||||
* floor.
|
||||
*/
|
||||
|
||||
if (!Void.TYPE.equals(listenerMethods[i].getReturnType())) {
|
||||
System.err.println(
|
||||
"Detected unexpected method signature: " +
|
||||
listenerMethods[i] +
|
||||
" in interface: " +
|
||||
listenerName
|
||||
);
|
||||
} else {
|
||||
Class[] lmParams = listenerMethods[i].getParameterTypes();
|
||||
Class[] lmExceptions = listenerMethods[i].getExceptionTypes();
|
||||
|
||||
|
||||
if (lmParams != null &&
|
||||
lmParams.length == 1 &&
|
||||
java.util.EventObject.class.isAssignableFrom(lmParams[0])) {
|
||||
generateSimpleListenerMethodStub(listenerMethods[i],
|
||||
lmParams[0],
|
||||
lmExceptions,
|
||||
i
|
||||
);
|
||||
} else {
|
||||
generateCrackedListenerMethodStub(listenerMethods[i],
|
||||
lmParams,
|
||||
lmExceptions,
|
||||
i
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a simple EventListener interface method stub
|
||||
*/
|
||||
|
||||
private void generateSimpleListenerMethodStub(Method listenerMethod, Class listenerParam, Class[] listenerExceptions, int listenerMethodTableIndex) {
|
||||
Code c = new Code(classFile, (short)2, (short)4);
|
||||
Attribute[] ary;
|
||||
|
||||
/*
|
||||
* public void <EventListenerMethod>(<EventObject> e)
|
||||
* {
|
||||
* EncapsulatedEvent t = new EncapsulatedEvent(e);
|
||||
* Method m = findListenerMethod();
|
||||
*
|
||||
* fire(t, m);
|
||||
* }
|
||||
*/
|
||||
|
||||
c.addOp (Code.OP_ALOAD_0); // this
|
||||
c.addOp (Code.OP_ALOAD_1); // event object
|
||||
|
||||
c.addOpShort(Code.OP_GETSTATIC,
|
||||
methodsField.getConstantPoolIndex()
|
||||
);
|
||||
|
||||
if (listenerMethodTableIndex <= 255) {
|
||||
c.addOp1(Code.OP_BIPUSH, (byte)listenerMethodTableIndex);
|
||||
} else {
|
||||
short i = classFile.addIntegerConstant(listenerMethodTableIndex).getConstantPoolIndex();
|
||||
|
||||
if (i <= 255)
|
||||
c.addOp1(Code.OP_LDC, (byte)i);
|
||||
else
|
||||
c.addOpShort(Code.OP_LDC_WIDE, i);
|
||||
}
|
||||
|
||||
c.addOp (Code.OP_AALOAD);
|
||||
|
||||
c.addOpShort(Code.OP_INVOKE_VIRTUAL,
|
||||
fireMethod.getConstantPoolIndex()
|
||||
); // call fire();
|
||||
|
||||
c.addOp (Code.OP_RETURN); // get out of here
|
||||
|
||||
if (listenerExceptions != null && listenerExceptions.length > 0) {
|
||||
ary = new Attribute[2];
|
||||
|
||||
ary[1] = new Exceptions(listenerExceptions, classFile);
|
||||
} else {
|
||||
ary = new Attribute[1];
|
||||
}
|
||||
|
||||
ary[0] = c;
|
||||
|
||||
// define the listener method
|
||||
|
||||
classFile.addMethodDesc(
|
||||
new MethodDesc(
|
||||
listenerMethod.getName(),
|
||||
"(" + ClassFile.fieldType(listenerParam.getName()) + ")V",
|
||||
(short)(listenerMethod.getModifiers() & ~MethodDesc.ACC_ABSTRACT),
|
||||
classFile,
|
||||
ary
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a cracked EventListener interface method stub
|
||||
*/
|
||||
|
||||
private void generateCrackedListenerMethodStub(Method listenerMethod, Class[] listenerParams, Class[] listenerExceptions, int listenerMethodTableIndex) {
|
||||
Code c = new Code(classFile,
|
||||
(short)(listenerParams.length * 2 + 1),
|
||||
(short)9
|
||||
);
|
||||
Attribute[] ary;
|
||||
String methodPDesc = "";
|
||||
boolean wasDoubleWord; // was the last param processed double?
|
||||
|
||||
c.addOp (Code.OP_ALOAD_0); // this
|
||||
|
||||
/*
|
||||
* For cracked Event listener methods we construct an array of Objects
|
||||
* to contain the cracked actual parameters ... primitive types are
|
||||
* wrapped in a container object suitable for their type.
|
||||
*/
|
||||
|
||||
if (listenerParams.length <= 255) {
|
||||
c.addOp1(Code.OP_BIPUSH, (byte)listenerParams.length);
|
||||
} else {
|
||||
short i = classFile.addIntegerConstant(listenerParams.length).getConstantPoolIndex();
|
||||
|
||||
if (i <= 255)
|
||||
c.addOp1(Code.OP_LDC, (byte)i);
|
||||
else
|
||||
c.addOpShort(Code.OP_LDC_WIDE, (short)i);
|
||||
}
|
||||
|
||||
c.addOpShort(Code.OP_ANEWARRAY,
|
||||
classFile.addClassConstant("java.lang.Object").getConstantPoolIndex()
|
||||
);
|
||||
|
||||
/*
|
||||
* we've now constructed and array of java/lang/Object ... now populate
|
||||
* it with the actual params.
|
||||
*/
|
||||
|
||||
int lvarIdx = 1; // because locals[0] == this
|
||||
|
||||
/*
|
||||
* for each formal parameter, generate code to load the actual
|
||||
* param from this methods local vars, then if it is a primitive
|
||||
* type, then construct a container object and initialize it
|
||||
* to the primitives value.
|
||||
*
|
||||
* as a side effect of this loop we also construct the methods
|
||||
* descriptor to optimise processing of the type info
|
||||
*/
|
||||
|
||||
for (int i = 0; i < listenerParams.length; i++, lvarIdx += (wasDoubleWord ? 2 : 1)) {
|
||||
|
||||
c.addOp(Code.OP_DUP); // the array reference
|
||||
|
||||
if (lvarIdx <= 255) { // the array index
|
||||
c.addOp1(Code.OP_BIPUSH, (byte)i);
|
||||
} else {
|
||||
short ic = classFile.addIntegerConstant(i).getConstantPoolIndex();
|
||||
if (ic < 255)
|
||||
c.addOp1(Code.OP_LDC, (byte)ic);
|
||||
else
|
||||
c.addOpShort(Code.OP_LDC_WIDE, (short)ic);
|
||||
}
|
||||
|
||||
/*
|
||||
* get the param value onto TOS
|
||||
* as a side effect gather method descriptor string.
|
||||
*/
|
||||
|
||||
String s = processParam(c, listenerParams[i], lvarIdx);
|
||||
|
||||
c.addOp(Code.OP_AASTORE); // arrayref, index, value
|
||||
|
||||
wasDoubleWord = s.equals("J") || s.equals("D");
|
||||
|
||||
methodPDesc += s;
|
||||
}
|
||||
|
||||
// that's the array constructed ... now lets call my superclass fire
|
||||
|
||||
// but first we need to tell that method which listener is firing ...
|
||||
|
||||
c.addOpShort(Code.OP_GETSTATIC,
|
||||
methodsField.getConstantPoolIndex()
|
||||
);
|
||||
|
||||
if (listenerMethodTableIndex <= 255) {
|
||||
c.addOp1(Code.OP_BIPUSH, (byte)listenerMethodTableIndex);
|
||||
} else {
|
||||
short i = classFile.addIntegerConstant(listenerMethodTableIndex).getConstantPoolIndex();
|
||||
|
||||
if (i <= 255)
|
||||
c.addOp1(Code.OP_LDC, (byte)i);
|
||||
else
|
||||
c.addOpShort(Code.OP_LDC_WIDE, i);
|
||||
}
|
||||
|
||||
c.addOp (Code.OP_AALOAD); // this, array, method
|
||||
|
||||
// now we can call the fire method
|
||||
|
||||
c.addOpShort(Code.OP_INVOKE_VIRTUAL,
|
||||
crackedFireMethod.getConstantPoolIndex()
|
||||
); // call fire();
|
||||
|
||||
c.addOp (Code.OP_RETURN); // get out of here
|
||||
|
||||
if (listenerExceptions != null && listenerExceptions.length > 0) {
|
||||
ary = new Attribute[2];
|
||||
|
||||
ary[1] = new Exceptions(listenerExceptions, classFile);
|
||||
} else {
|
||||
ary = new Attribute[1];
|
||||
}
|
||||
|
||||
ary[0] = c;
|
||||
|
||||
// define the listener method
|
||||
|
||||
classFile.addMethodDesc(
|
||||
new MethodDesc(
|
||||
listenerMethod.getName(),
|
||||
"(" + methodPDesc + ")V",
|
||||
(short)(listenerMethod.getModifiers() & ~MethodDesc.ACC_ABSTRACT),
|
||||
classFile,
|
||||
ary
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* This method is used to generate code for cracked event listener
|
||||
* stubs. Its job is to generate code to load the appropriate parameter
|
||||
* data type onto the stack, create a wrapper object if needed and leave
|
||||
* the appropriate value on TOS for storing into the objects array.
|
||||
*/
|
||||
|
||||
private String processParam(Code c, Class pClass, int pIdx) {
|
||||
ClassConstant cc = null;
|
||||
MethodConstant mc = null;
|
||||
byte ldOpCode = Code.OP_ALOAD; // load ref by default
|
||||
byte convOpCode = 0;
|
||||
boolean singleWordParam = true;
|
||||
Class pType = pClass;
|
||||
boolean isPrimitive;
|
||||
boolean isArrayRef;
|
||||
|
||||
String pDesc = "";
|
||||
|
||||
// is this an array reference?
|
||||
|
||||
while (pType.isArray()) { // side - effect: construct array param desc
|
||||
pType = pType.getComponentType();
|
||||
pDesc += "[";
|
||||
}
|
||||
|
||||
isPrimitive = pType.isPrimitive();
|
||||
isArrayRef = pClass.isArray();
|
||||
|
||||
if (isPrimitive) { // builtin datatype
|
||||
if (pType.equals(java.lang.Long.TYPE)) {
|
||||
pDesc += "J";
|
||||
|
||||
if (!isArrayRef) {
|
||||
cc = classFile.addClassConstant("java/lang/Long");
|
||||
|
||||
mc = classFile.addMethodConstant(
|
||||
"java/lang/Long",
|
||||
"<init>",
|
||||
"(J)V"
|
||||
);
|
||||
|
||||
ldOpCode = Code.OP_LLOAD;
|
||||
singleWordParam = false;
|
||||
}
|
||||
} else if (pType.equals(java.lang.Float.TYPE)) {
|
||||
pDesc += "F";
|
||||
|
||||
if (!isArrayRef) {
|
||||
cc = classFile.addClassConstant("java/lang/Float");
|
||||
|
||||
mc = classFile.addMethodConstant(
|
||||
"java/lang/Float",
|
||||
"<init>",
|
||||
"(F)V"
|
||||
);
|
||||
|
||||
ldOpCode = Code.OP_FLOAD;
|
||||
}
|
||||
} else if (pType.equals(java.lang.Double.TYPE)) {
|
||||
pDesc += "D";
|
||||
|
||||
if (!isArrayRef) {
|
||||
cc = classFile.addClassConstant("java/lang/Double");
|
||||
|
||||
mc = classFile.addMethodConstant(
|
||||
"java/lang/Double",
|
||||
"<init>",
|
||||
"(D)V"
|
||||
);
|
||||
|
||||
ldOpCode = Code.OP_DLOAD;
|
||||
singleWordParam = false;
|
||||
}
|
||||
} else { // integer, array or objref computational types ...
|
||||
|
||||
ldOpCode = Code.OP_ILOAD;
|
||||
|
||||
if (pType.equals(java.lang.Boolean.TYPE)) {
|
||||
pDesc += "Z";
|
||||
|
||||
if (!isArrayRef) {
|
||||
cc = classFile.addClassConstant("java/lang/Boolean");
|
||||
|
||||
mc = classFile.addMethodConstant(
|
||||
"java/lang/Boolean",
|
||||
"<init>",
|
||||
"(Z)V"
|
||||
);
|
||||
|
||||
convOpCode = Code.OP_I2B;
|
||||
}
|
||||
} else if (pType.equals(java.lang.Character.TYPE)) {
|
||||
pDesc += "C";
|
||||
|
||||
if (!isArrayRef) {
|
||||
cc = classFile.addClassConstant("java/lang/Character");
|
||||
|
||||
mc = classFile.addMethodConstant(
|
||||
"java/lang/Character",
|
||||
"<init>",
|
||||
"(C)V"
|
||||
);
|
||||
|
||||
convOpCode = Code.OP_I2C;
|
||||
}
|
||||
} else if (pType.equals(java.lang.Byte.TYPE)) {
|
||||
pDesc += "B";
|
||||
|
||||
if (!isArrayRef) {
|
||||
cc = classFile.addClassConstant("java/lang/Byte");
|
||||
|
||||
mc = classFile.addMethodConstant(
|
||||
"java/lang/Character",
|
||||
"<init>",
|
||||
"(C)V"
|
||||
);
|
||||
|
||||
convOpCode = Code.OP_I2B;
|
||||
}
|
||||
} else if (pType.equals(java.lang.Short.TYPE)) {
|
||||
pDesc += "S";
|
||||
|
||||
if (!isArrayRef) {
|
||||
cc = classFile.addClassConstant("java/lang/Short");
|
||||
|
||||
mc = classFile.addMethodConstant(
|
||||
"java/lang/Short",
|
||||
"<init>",
|
||||
"(S)V"
|
||||
);
|
||||
|
||||
convOpCode = Code.OP_I2S;
|
||||
}
|
||||
} else if (pType.equals(java.lang.Integer.TYPE)) {
|
||||
pDesc += "I";
|
||||
|
||||
if (!isArrayRef) {
|
||||
cc = classFile.addClassConstant("java/lang/Integer");
|
||||
|
||||
mc = classFile.addMethodConstant(
|
||||
"java/lang/Integer",
|
||||
"<init>",
|
||||
"(I)V"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // handle descriptors for non-primitives ...
|
||||
pDesc += ClassFile.fieldType(pType.getName());
|
||||
}
|
||||
|
||||
// now load the param value onto TOS ...
|
||||
|
||||
if (pIdx < 255)
|
||||
c.addOp1(ldOpCode, (byte)pIdx);
|
||||
else {
|
||||
c.addOp(Code.OP_WIDE);
|
||||
c.addOpShort(ldOpCode, (short)pIdx);
|
||||
}
|
||||
|
||||
if (isPrimitive && !isArrayRef) { // additional processing for primitives
|
||||
if (convOpCode != 0) { // narrow Int?
|
||||
c.addOp(convOpCode); // then widen the reference
|
||||
}
|
||||
|
||||
// we now have the param's value of TOS,
|
||||
// construct a container object for it
|
||||
|
||||
c.addOpShort(Code.OP_NEW, (short)cc.getConstantPoolIndex());
|
||||
|
||||
if (singleWordParam) {
|
||||
c.addOp(Code.OP_DUP_X1); // this, <param_word>, this
|
||||
c.addOp(Code.OP_SWAP); // this, <param_word>
|
||||
} else {
|
||||
c.addOp(Code.OP_DUP_X2); // this, <param_2word>, this
|
||||
c.addOp(Code.OP_DUP_X2); // this, this, <param_2word>, this
|
||||
c.addOp(Code.OP_POP); // this, this, <param_2word>
|
||||
}
|
||||
|
||||
c.addOpShort(Code.OP_INVOKE_SPECIAL, mc.getConstantPoolIndex());
|
||||
}
|
||||
|
||||
// param value on TOS
|
||||
|
||||
return pDesc; // type descriptor - side effect
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the class file to the stream </p>
|
||||
*
|
||||
* @param os the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
private void write(OutputStream os) throws IOException {
|
||||
classFile.write(os);
|
||||
}
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) Exceptions.java 1.3@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.Exceptions
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.Attribute;
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ClassConstant;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The Exceptions class extends the Attribute class to enumerate the
|
||||
* exception types generated by method implementations in a class file
|
||||
* </p>
|
||||
*/
|
||||
|
||||
class Exceptions extends Attribute {
|
||||
|
||||
private ClassConstant[] exceptions;
|
||||
|
||||
/**
|
||||
* <p> construct an Exceptions attribute that enumerates the exceptions </p>
|
||||
*
|
||||
* @param exs[] an array of exception class constants
|
||||
* @param cf the containing class file
|
||||
*/
|
||||
|
||||
Exceptions(ClassConstant[] exs, ClassFile cf) {
|
||||
super(Attribute.EXCEPTIONS, cf);
|
||||
|
||||
// we should validate that the ClassConstants are all
|
||||
// subclasses of Exception here ...
|
||||
|
||||
exceptions = exs;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> construct an Exceptions attribute that enumerates the exceptions </p>
|
||||
*
|
||||
* @param exs[] an array of exception class types
|
||||
* @param cf the containing class file
|
||||
*
|
||||
*/
|
||||
Exceptions(Class[] exs, ClassFile cf) {
|
||||
super(Attribute.EXCEPTIONS, cf);
|
||||
|
||||
// we should validate that the ClassConstants are all
|
||||
// subclasses of Exception here ...
|
||||
|
||||
ClassConstant[] cc = new ClassConstant[exs.length];
|
||||
|
||||
for (int i = 0; i < exs.length; i++)
|
||||
cc[i] = cf.addClassConstant(exs[i].getName());
|
||||
|
||||
exceptions = cc;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the Exceptions attribute to the stream </p>
|
||||
*
|
||||
* @param dos the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeShort(getNameConstantPoolIndex());
|
||||
dos.writeInt(getLength());
|
||||
|
||||
if (exceptions != null && exceptions.length > 0) {
|
||||
dos.writeShort(exceptions.length);
|
||||
|
||||
for (int i = 0; i < exceptions.length; i++) {
|
||||
dos.writeShort(exceptions[i].getConstantPoolIndex());
|
||||
}
|
||||
} else dos.writeShort(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Object's equality
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Exceptions) {
|
||||
Exceptions other = (Exceptions)o;
|
||||
|
||||
if (exceptions.length == other.exceptions.length) {
|
||||
for (int i = 0; i < exceptions.length; i++) {
|
||||
if (!exceptions[i].equals(other.exceptions[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the length of the Attribute in bytes
|
||||
*/
|
||||
|
||||
int getLength() { return exceptions.length * 2 + 2; }
|
||||
|
||||
/**
|
||||
* <p> adds exception class to the attribute. </p>
|
||||
*
|
||||
* @param a class constant to add to the attribute
|
||||
*
|
||||
*/
|
||||
|
||||
void addException(ClassConstant ex) {
|
||||
|
||||
// should verify that ClassConstant is exception subclass and not
|
||||
// already in the attribute
|
||||
|
||||
if (exceptions == null) {
|
||||
exceptions = new ClassConstant[1];
|
||||
|
||||
exceptions[0] = ex;
|
||||
} else {
|
||||
ClassConstant[] temp = new ClassConstant[exceptions.length + 1];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < exceptions.length; i++) {
|
||||
temp[i] = exceptions[i];
|
||||
}
|
||||
|
||||
temp[i] = ex;
|
||||
|
||||
exceptions = temp;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) FieldConstant.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.FieldConstant
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.RefConstant;
|
||||
|
||||
/**
|
||||
* <p> implements a CONSTANT_FIELDREF CPE </p>
|
||||
*/
|
||||
|
||||
final class FieldConstant extends RefConstant {
|
||||
|
||||
/**
|
||||
* <p> construct a CONSTANT_FIELDREF CPE </p>
|
||||
*
|
||||
* @param cName the class name
|
||||
* @param nName the name of the field
|
||||
* @param tName the type descriptor for the field
|
||||
* @param cf the class file
|
||||
*/
|
||||
|
||||
FieldConstant(String cName, String nName, String tName, ClassFile cf) {
|
||||
super(CONSTANT_FIELDREF, cName, nName, tName, cf);
|
||||
}
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) FieldDesc.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.FieldDesc
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.UTF8Constant;
|
||||
import FESI.ClassFile.Attribute;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Implements the field_info structure of a class file, used to describe
|
||||
* the attributes of all fields implemented by this class. The class provides
|
||||
* minimal support to write the formatted structure to the stream.
|
||||
* </p>
|
||||
*/
|
||||
|
||||
final class FieldDesc {
|
||||
|
||||
final static short ACC_PUBLIC = 0x0001;
|
||||
final static short ACC_PRIVATE = 0x0002;
|
||||
final static short ACC_PROTECTED = 0x0004;
|
||||
final static short ACC_STATIC = 0x0008;
|
||||
final static short ACC_FINAL = 0x0010;
|
||||
final static short ACC_VOLATILE = 0x0040;
|
||||
final static short ACC_TRANSIENT = 0x0080;
|
||||
|
||||
private UTF8Constant name;
|
||||
private UTF8Constant descriptor;
|
||||
|
||||
private short accessFlags;
|
||||
|
||||
private ClassFile classFile;
|
||||
|
||||
private Attribute[] attributes;
|
||||
|
||||
/**
|
||||
* <p> construct a descriptor for a field. </p>
|
||||
*
|
||||
* @param field name
|
||||
* @param desc its type descriptor
|
||||
* @param flags access flags
|
||||
* @param cf the class file
|
||||
* @param attrs any associated attributes
|
||||
*
|
||||
*/
|
||||
|
||||
FieldDesc(String field, String desc, short flags, ClassFile cf, Attribute[] attrs) {
|
||||
super();
|
||||
|
||||
// we would validate here ...
|
||||
|
||||
name = new UTF8Constant(field, cf);
|
||||
descriptor = new UTF8Constant(desc, cf);
|
||||
accessFlags = flags;
|
||||
classFile = cf;
|
||||
attributes = attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the field to the stream </p>
|
||||
*
|
||||
* @param dos the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeShort(accessFlags);
|
||||
dos.writeShort(name.getConstantPoolIndex());
|
||||
dos.writeShort(descriptor.getConstantPoolIndex());
|
||||
|
||||
if (attributes != null && attributes.length == 0) {
|
||||
dos.writeShort(attributes.length);
|
||||
|
||||
for (int i = 0; i < attributes.length; i++) {
|
||||
attributes[i].write(dos);
|
||||
}
|
||||
} else dos.writeShort(0);
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) FloatConstant.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.FloatConstant
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
|
||||
/**
|
||||
* <p> provides minimal support for FLOAT_CONSTANT CPE </p>
|
||||
*/
|
||||
|
||||
class FloatConstant extends ConstantPoolEntry {
|
||||
|
||||
private float floating;
|
||||
|
||||
/**
|
||||
* <p> construct a CONSTANT_FLOAT </p>
|
||||
*
|
||||
* @param f the float value
|
||||
* @param cf the class file
|
||||
*/
|
||||
|
||||
FloatConstant(float f, ClassFile cf) {
|
||||
super(CONSTANT_FLOAT, cf);
|
||||
|
||||
floating = f;
|
||||
|
||||
addToConstantPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the CONSTANT_FLOAT to the stream </p>
|
||||
*
|
||||
* @param dos the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeByte(getTag());
|
||||
dos.writeFloat(floating);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> return the value of the constant </p>
|
||||
*
|
||||
* @return the value of the CONSTANT_FLOAT
|
||||
*/
|
||||
|
||||
float getValue() { return floating; }
|
||||
|
||||
/**
|
||||
* @return object equality
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Float) {
|
||||
return floating == ((Float)o).floatValue();
|
||||
} else if (o instanceof FloatConstant) {
|
||||
FloatConstant fc = (FloatConstant)o;
|
||||
|
||||
return floating == fc.getValue();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) IntegerConstant.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.IntegerConstant
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
|
||||
/**
|
||||
* <p> this class provides minimal support for the CONSTANT_INTEGER CPE </p>
|
||||
*/
|
||||
|
||||
class IntegerConstant extends ConstantPoolEntry {
|
||||
|
||||
private int integer;
|
||||
|
||||
/**
|
||||
* <p> construct a CONSTANT_INTEGER CPE </p>
|
||||
*
|
||||
* @param i the integer constant
|
||||
* @param cf the class file
|
||||
*/
|
||||
|
||||
IntegerConstant(int i, ClassFile cf) {
|
||||
super(CONSTANT_INTEGER, cf);
|
||||
|
||||
integer = i;
|
||||
|
||||
addToConstantPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the CONSTANT_INTEGER to the stream </p>
|
||||
*
|
||||
* @param dos the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeByte(getTag());
|
||||
dos.writeInt(integer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value of the CONSTANT_INTEGER
|
||||
*/
|
||||
|
||||
int getValue() { return integer; }
|
||||
|
||||
/**
|
||||
* @return object equality
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Integer) {
|
||||
return integer == ((Integer)o).intValue();
|
||||
} else if (o instanceof IntegerConstant) {
|
||||
IntegerConstant ic = (IntegerConstant)o;
|
||||
|
||||
return integer == ic.getValue();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) InterfaceMethodConstant.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.InterfaceMethodConstant
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.RefConstant;
|
||||
|
||||
/**
|
||||
* <p> this class provides minimal support for CONSTANT_INTERFACEMETHODREF CPE's </p>
|
||||
*/
|
||||
|
||||
class InterfaceMethodConstant extends RefConstant {
|
||||
|
||||
/**
|
||||
* <p> construct a CONSTANT_INTERFACEMETHODREF </p>
|
||||
*
|
||||
* @param cName name of interface
|
||||
* @param nName name of method
|
||||
* @param tName method type descriptor
|
||||
* @param cf class file
|
||||
*
|
||||
*/
|
||||
|
||||
InterfaceMethodConstant(String cName, String nName, String tName, ClassFile cf) {
|
||||
super(CONSTANT_INTERFACEMETHODREF, cName, nName, tName, cf);
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) LongConstant.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.LongConstant
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
|
||||
/**
|
||||
* <p> this class provides minimal support for CONSTANT_LONG CPE's </p>
|
||||
*/
|
||||
|
||||
class LongConstant extends ConstantPoolEntry {
|
||||
|
||||
private long longish;
|
||||
|
||||
/**
|
||||
* <p> construct a CONSTANT_LONG </p>
|
||||
*
|
||||
* @param l the long constant
|
||||
* @param cf the class file
|
||||
*/
|
||||
|
||||
LongConstant(long l, ClassFile cf) {
|
||||
super(CONSTANT_LONG, cf);
|
||||
|
||||
longish = l;
|
||||
|
||||
addToConstantPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the CONSTANT_LONG to the stream </p>
|
||||
*
|
||||
* @param dos the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeByte(getTag());
|
||||
dos.writeLong(longish);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the long constant value
|
||||
*/
|
||||
|
||||
long getValue() { return longish; }
|
||||
|
||||
/**
|
||||
* @return object equality
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Long) {
|
||||
return longish == ((Long)o).longValue();
|
||||
} else if (o instanceof LongConstant) {
|
||||
LongConstant lc = (LongConstant)o;
|
||||
|
||||
return longish == lc.getValue();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) MethodConstant.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.MethodConstant
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.RefConstant;
|
||||
|
||||
/**
|
||||
* <p> this class provides minimal support for the CONSTANT_METHODREF CPE </p>
|
||||
*/
|
||||
|
||||
class MethodConstant extends RefConstant {
|
||||
|
||||
/**
|
||||
* <p> construct a CONSTANT_METHODREF </p>
|
||||
*
|
||||
* @param cName the name of the implementing class
|
||||
* @param nName the name of the method
|
||||
* @param tName the type descriptor of the method
|
||||
* @param cf the class file
|
||||
*/
|
||||
|
||||
MethodConstant(String cName, String nName, String tName, ClassFile cf) {
|
||||
super(CONSTANT_METHODREF, cName, nName, tName, cf);
|
||||
}
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) MethodDesc.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.MethodDesc
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.UTF8Constant;
|
||||
import FESI.ClassFile.Attribute;
|
||||
|
||||
/**
|
||||
* <p> this class provides minimal support for method_info structures </p>
|
||||
*/
|
||||
|
||||
final class MethodDesc {
|
||||
|
||||
final static short ACC_PUBLIC = 0x0001;
|
||||
final static short ACC_PRIVATE = 0x0002;
|
||||
final static short ACC_PROTECTED = 0x0004;
|
||||
final static short ACC_STATIC = 0x0008;
|
||||
final static short ACC_FINAL = 0x0010;
|
||||
final static short ACC_SYNCHRONIZED = 0x0020;
|
||||
final static short ACC_NATIVE = 0x0100;
|
||||
final static short ACC_ABSTRACT = 0x0400;
|
||||
|
||||
private UTF8Constant name;
|
||||
private UTF8Constant descriptor;
|
||||
|
||||
private short accessFlags;
|
||||
|
||||
private ClassFile classFile;
|
||||
|
||||
private Attribute[] attributes;
|
||||
|
||||
/**
|
||||
* <p> construct a descriptor for a method </p>
|
||||
*
|
||||
* @param method the name of the method
|
||||
* @param desc a type descriptor for its signature
|
||||
* @param flags access flags
|
||||
* @param cf the class file
|
||||
* @param attrs arbitrary attributes
|
||||
*
|
||||
*/
|
||||
|
||||
MethodDesc(String method, String desc, short flags, ClassFile cf, Attribute[] attrs) {
|
||||
super();
|
||||
|
||||
// we would validate here ...
|
||||
|
||||
name = new UTF8Constant(method, cf);
|
||||
descriptor = new UTF8Constant(desc, cf);
|
||||
accessFlags = flags;
|
||||
classFile = cf;
|
||||
attributes = attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the method to the stream </p>
|
||||
*
|
||||
* @param dos the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeShort(accessFlags);
|
||||
dos.writeShort(name.getConstantPoolIndex());
|
||||
dos.writeShort(descriptor.getConstantPoolIndex());
|
||||
|
||||
if (attributes != null && attributes.length > 0) {
|
||||
dos.writeShort(attributes.length);
|
||||
|
||||
for (int i = 0; i < attributes.length; i++) {
|
||||
attributes[i].write(dos);
|
||||
}
|
||||
} else dos.writeShort(0);
|
||||
}
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) NameAndTypeConstant.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.NameAndTypeConstant
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
import FESI.ClassFile.UTF8Constant;
|
||||
|
||||
/**
|
||||
* <p> this class provides minimal support for NAME_AND_TYPE CPE's </p>
|
||||
*/
|
||||
|
||||
class NameAndTypeConstant extends ConstantPoolEntry {
|
||||
|
||||
private UTF8Constant name;
|
||||
private UTF8Constant desc;
|
||||
|
||||
/**
|
||||
* <p> construct a CONSTANT_NAMEANDTYPE CPE </p>
|
||||
*
|
||||
* @param n the name
|
||||
* @param d the type
|
||||
* @param cf the class file
|
||||
*/
|
||||
|
||||
NameAndTypeConstant(String n, String d, ClassFile cf) {
|
||||
super(CONSTANT_NAMEANDTYPE, cf);
|
||||
|
||||
name = new UTF8Constant(n, cf);
|
||||
desc = new UTF8Constant(d, cf);
|
||||
|
||||
addToConstantPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the CPE to the stream </p>
|
||||
*
|
||||
* @param dos the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
|
||||
if (debug()) {
|
||||
System.err.println(getConstantPoolIndex() +
|
||||
" NAME: " +
|
||||
name.getConstantPoolIndex() +
|
||||
" TYPE: " +
|
||||
desc.getConstantPoolIndex()
|
||||
);
|
||||
}
|
||||
|
||||
dos.writeByte(getTag());
|
||||
dos.writeShort(name.getConstantPoolIndex());
|
||||
dos.writeShort(desc.getConstantPoolIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name string
|
||||
*/
|
||||
|
||||
String getName() { return name.getString(); }
|
||||
|
||||
/**
|
||||
* @return the type descriptor string
|
||||
*/
|
||||
|
||||
String getDescriptor() { return desc.getString(); }
|
||||
|
||||
/**
|
||||
* @return object equality
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof String) {
|
||||
return name.getString().equals(o) ||
|
||||
desc.getString().equals(o);
|
||||
} else if (o instanceof NameAndTypeConstant) {
|
||||
NameAndTypeConstant nandt = (NameAndTypeConstant)o;
|
||||
|
||||
return name.equals(nandt.getName()) &&
|
||||
desc.equals(nandt.getDescriptor());
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) RefConstant.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.RefConstant
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
import FESI.ClassFile.ClassConstant;
|
||||
import FESI.ClassFile.NameAndTypeConstant;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* this base class provides minimal support for METHODREF, FIELDREF, and
|
||||
* INTERFACEMETHODREF CPE's
|
||||
* </p>
|
||||
*/
|
||||
|
||||
class RefConstant extends ConstantPoolEntry {
|
||||
|
||||
private ClassConstant clazz;
|
||||
private NameAndTypeConstant nandt;
|
||||
|
||||
/**
|
||||
* <p> construct a CPE </p>
|
||||
*
|
||||
* @param t the CPE tag value
|
||||
* @param cName the class name
|
||||
* @param nName the name of the referenced field or method
|
||||
* @param tName the type descriptor of the field or method
|
||||
* @param cf the class file
|
||||
*
|
||||
*/
|
||||
|
||||
protected RefConstant(byte t, String cName,
|
||||
String nName, String tName, ClassFile cf) {
|
||||
super(t, cf);
|
||||
|
||||
clazz = new ClassConstant(cName, cf);
|
||||
nandt = new NameAndTypeConstant(nName, tName, cf);
|
||||
|
||||
addToConstantPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the referenced object to the stream </p>
|
||||
*
|
||||
* @param dos the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeByte(getTag());
|
||||
dos.writeShort(clazz.getConstantPoolIndex());
|
||||
dos.writeShort(nandt.getConstantPoolIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the class constant for the referenced object
|
||||
*/
|
||||
|
||||
ClassConstant getClassObject() { return clazz; }
|
||||
|
||||
/**
|
||||
* @return the name and type CPE for the referenced object
|
||||
*/
|
||||
|
||||
NameAndTypeConstant getNameAndType() { return nandt; }
|
||||
|
||||
/**
|
||||
* @return object equality
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof String) {
|
||||
return ((String)o).equals(nandt.getName());
|
||||
} else if (o instanceof RefConstant) {
|
||||
RefConstant rc = (RefConstant)o;
|
||||
|
||||
return clazz.equals(rc.getClassObject()) &&
|
||||
nandt.equals(rc.getNameAndType());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) StringConstant.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.StringConstant
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
import FESI.ClassFile.UTF8Constant;
|
||||
|
||||
/**
|
||||
* <p> this class provides minimal support for CONSTANT_STRING CPE's <p>
|
||||
*/
|
||||
|
||||
final class StringConstant extends ConstantPoolEntry {
|
||||
|
||||
private UTF8Constant string;
|
||||
|
||||
/**
|
||||
* <p> construct a CONSTANT_STRING CPE </p>
|
||||
*
|
||||
* @param str the constant
|
||||
* @param cf the class file
|
||||
*/
|
||||
|
||||
StringConstant(String str, ClassFile cf) {
|
||||
super(CONSTANT_STRING, cf);
|
||||
|
||||
string = new UTF8Constant(str, cf);
|
||||
|
||||
addToConstantPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> construct a CONSTANT_STRING CPE </p>
|
||||
*
|
||||
* @param utf8 the utf8 constant
|
||||
* @param cf the class file
|
||||
*/
|
||||
|
||||
StringConstant(UTF8Constant utf8, ClassFile cf) {
|
||||
super(CONSTANT_STRING, cf);
|
||||
|
||||
string = utf8;
|
||||
|
||||
addToConstantPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the constant to the stream </p>
|
||||
*
|
||||
* @param dos the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeByte(getTag());
|
||||
dos.writeShort(string.getConstantPoolIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the string constant
|
||||
*/
|
||||
|
||||
String getString() { return string.getString(); }
|
||||
|
||||
/**
|
||||
* @return object equality
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof String) {
|
||||
return string.equals(o);
|
||||
} else if (o instanceof StringConstant) {
|
||||
return string.equals(((StringConstant)o).getString());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
*
|
||||
* @(#) UTF8Constant.java 1.2@(#)
|
||||
*
|
||||
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
|
||||
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
|
||||
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
|
||||
* THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* FESI.ClassFile.UTF8Constant
|
||||
* </p>
|
||||
*
|
||||
* @version 1.0
|
||||
* @author Laurence P. G. Cable
|
||||
*/
|
||||
|
||||
|
||||
package FESI.ClassFile;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import FESI.ClassFile.ClassFile;
|
||||
import FESI.ClassFile.ConstantPoolEntry;
|
||||
|
||||
/**
|
||||
* <p> this class provides minimal support for CONSTANT_UTF8 CPE's </p>
|
||||
*/
|
||||
|
||||
class UTF8Constant extends ConstantPoolEntry {
|
||||
|
||||
private String string;
|
||||
|
||||
/**
|
||||
* <p> construct a CONSTANT_UTF8 CPE </p>
|
||||
*
|
||||
* @param s the string
|
||||
* @param cf the class file
|
||||
*/
|
||||
|
||||
UTF8Constant(String s, ClassFile cf) {
|
||||
super(CONSTANT_UTF8, cf);
|
||||
|
||||
string = s;
|
||||
|
||||
addToConstantPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> write the CPE to the output stream </p>
|
||||
*
|
||||
* @param dos the output stream
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeByte(getTag());
|
||||
dos.writeUTF(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the string constant
|
||||
*/
|
||||
|
||||
String getString() { return string; }
|
||||
|
||||
/**
|
||||
* @return object equality
|
||||
*/
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof String) {
|
||||
return string.equals((String)o);
|
||||
} else if (o instanceof UTF8Constant) {
|
||||
return string.equals(((UTF8Constant)o).getString());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,185 +0,0 @@
|
|||
// ArrayObject.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
/**
|
||||
* Implements the Array EcmaScript object. This is a singleton
|
||||
*/
|
||||
public class ArrayObject extends BuiltinFunctionObject {
|
||||
|
||||
private static final String JOINstring = ("join").intern();
|
||||
private static final int JOINhash = JOINstring.hashCode();
|
||||
private static final String LENGTHstring = ("length").intern();
|
||||
private static final int LENGTHhash = LENGTHstring.hashCode();
|
||||
private static final String ZEROstring = ("0").intern();
|
||||
private static final int ZEROhash = ZEROstring.hashCode();
|
||||
|
||||
/**
|
||||
* Create a new Array object - used by makeArrayObject
|
||||
*
|
||||
* @param prototype Must be an ArrayPrototype
|
||||
* @param evaluator the evaluator
|
||||
*/
|
||||
private ArrayObject(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator, "Array", 1);
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
return doConstruct(thisObject, arguments);
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESObject ap = evaluator.getArrayPrototype();
|
||||
ArrayPrototype theArray = new ArrayPrototype(ap, evaluator);
|
||||
if (arguments.length > 1) {
|
||||
for (int i=0; i<arguments.length; i++) {
|
||||
String iString = Integer.toString(i);
|
||||
theArray.putProperty(iString, arguments[i], iString.hashCode());
|
||||
}
|
||||
} else if (arguments.length == 1) {
|
||||
ESValue firstArg = arguments[0];
|
||||
// Not clear in standard:
|
||||
if (firstArg.isNumberValue()) {
|
||||
int length = (int) firstArg.toInt32();
|
||||
theArray.putProperty(LENGTHstring, firstArg, LENGTHhash);
|
||||
} else {
|
||||
theArray.putProperty(ZEROstring, firstArg, ZEROhash);
|
||||
}
|
||||
}
|
||||
return theArray;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Utility function to create the single Array object
|
||||
*
|
||||
* @param evaluator the Evaluator
|
||||
* @param objectPrototype The Object prototype attached to the evaluator
|
||||
* @param functionPrototype The Function prototype attached to the evaluator
|
||||
*
|
||||
* @return The Array singleton
|
||||
*/
|
||||
|
||||
public static ArrayObject makeArrayObject(Evaluator evaluator,
|
||||
ObjectPrototype objectPrototype,
|
||||
FunctionPrototype functionPrototype) {
|
||||
|
||||
ArrayPrototype arrayPrototype = new ArrayPrototype(objectPrototype, evaluator);
|
||||
ArrayObject arrayObject = new ArrayObject(functionPrototype, evaluator);
|
||||
|
||||
try {
|
||||
// For arrayPrototype
|
||||
class ArrayPrototypeToString extends BuiltinFunctionObject {
|
||||
ArrayPrototypeToString(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
BuiltinFunctionObject join = (BuiltinFunctionObject)
|
||||
thisObject.getProperty(JOINstring, JOINhash);
|
||||
return join.callFunction(thisObject, new ESValue[0]);
|
||||
}
|
||||
}
|
||||
class ArrayPrototypeJoin extends BuiltinFunctionObject {
|
||||
ArrayPrototypeJoin(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String separator = ",";
|
||||
if (arguments.length > 0) {
|
||||
separator = arguments[0].toString();
|
||||
}
|
||||
int length = (thisObject.getProperty(ArrayObject.LENGTHstring, ArrayObject.LENGTHhash)).toInt32();
|
||||
for (int i =0; i<length; i++) {
|
||||
if (i>0) buffer.append(separator);
|
||||
String iString = Integer.toString(i);
|
||||
ESValue value = thisObject.getProperty(iString,iString.hashCode());
|
||||
if (value!=ESUndefined.theUndefined && value!=ESNull.theNull) {
|
||||
buffer.append(value.toString());
|
||||
}
|
||||
}
|
||||
return new ESString(buffer.toString());
|
||||
}
|
||||
}
|
||||
class ArrayPrototypeReverse extends BuiltinFunctionObject {
|
||||
ArrayPrototypeReverse(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (!(thisObject instanceof ArrayPrototype)) {
|
||||
throw new EcmaScriptException ("reverse only implemented for arrays");
|
||||
}
|
||||
return ((ArrayPrototype) thisObject).reverse();
|
||||
}
|
||||
}
|
||||
class ArrayPrototypeSort extends BuiltinFunctionObject {
|
||||
ArrayPrototypeSort(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (!(thisObject instanceof ArrayPrototype)) {
|
||||
throw new EcmaScriptException ("sort only implemented for arrays");
|
||||
}
|
||||
ESValue compareFn = null;
|
||||
if (arguments.length>0) compareFn = arguments[0];
|
||||
return ((ArrayPrototype) thisObject).sort(compareFn);
|
||||
}
|
||||
}
|
||||
|
||||
arrayObject.putHiddenProperty("prototype",arrayPrototype);
|
||||
arrayObject.putHiddenProperty(LENGTHstring,new ESNumber(1));
|
||||
|
||||
arrayPrototype.putHiddenProperty("constructor",arrayObject);
|
||||
arrayPrototype.putHiddenProperty("toString",
|
||||
new ArrayPrototypeToString("toString", evaluator, functionPrototype));
|
||||
arrayPrototype.putHiddenProperty("join",
|
||||
new ArrayPrototypeJoin("join", evaluator, functionPrototype));
|
||||
arrayPrototype.putHiddenProperty("reverse",
|
||||
new ArrayPrototypeReverse("reverse", evaluator, functionPrototype));
|
||||
arrayPrototype.putHiddenProperty("sort",
|
||||
new ArrayPrototypeSort("sort", evaluator, functionPrototype));
|
||||
} catch (EcmaScriptException e) {
|
||||
e.printStackTrace();
|
||||
throw new ProgrammingError(e.getMessage());
|
||||
}
|
||||
|
||||
evaluator.setArrayPrototype(arrayPrototype);
|
||||
|
||||
return arrayObject;
|
||||
}
|
||||
}
|
|
@ -1,585 +0,0 @@
|
|||
// ArrayPrototype.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
/**
|
||||
* Implements the prototype and is the class of all Array objects
|
||||
*/
|
||||
public class ArrayPrototype extends ESObject {
|
||||
|
||||
private static final String LENGTHstring = ("length").intern();
|
||||
private static final int LENGTHhash = LENGTHstring.hashCode();
|
||||
|
||||
// The array value
|
||||
// We could use a non synchronized vector or directly and array
|
||||
protected Vector theArray = new Vector();
|
||||
|
||||
/**
|
||||
* Create a new empty array
|
||||
* @param prototype the ArrayPrototype
|
||||
* @param evaluator The evaluator
|
||||
*/
|
||||
public ArrayPrototype(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getESClassName() {
|
||||
return "Array";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Java array object which is the object to pass to Java routines
|
||||
* called by FESI.
|
||||
* @ param componentType the type of the component of the array
|
||||
* @return a java array object
|
||||
*/
|
||||
public Object toJavaArray(Class componentType) throws EcmaScriptException {
|
||||
int l = size();
|
||||
Object array = Array.newInstance(componentType, l);
|
||||
if (l ==0) return array;
|
||||
for (int i =0; i<l; i++) {
|
||||
ESValue element = (ESValue) theArray.elementAt(i);
|
||||
if (componentType==Integer.TYPE) {
|
||||
if (element.isNumberValue()) {
|
||||
double d = element.doubleValue();
|
||||
int value = (int) d;
|
||||
if (value != d) {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array is too large for class " + componentType);
|
||||
}
|
||||
Array.setInt(array,i,value);
|
||||
} else {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array cannot be converted to class " + componentType);
|
||||
}
|
||||
} else if (componentType==Short.TYPE) {
|
||||
if (element.isNumberValue()) {
|
||||
double d = element.doubleValue();
|
||||
short value = (short) d;
|
||||
if (value != d) {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array is too large for class " + componentType);
|
||||
}
|
||||
Array.setShort(array,i,value);
|
||||
} else {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array cannot be converted to class " + componentType);
|
||||
}
|
||||
} else if (componentType==Byte.TYPE) {
|
||||
if (element.isNumberValue()) {
|
||||
double d = element.doubleValue();
|
||||
byte value = (byte) d;
|
||||
if (value != d) {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array is too large for class " + componentType);
|
||||
}
|
||||
Array.setByte(array,i,value);
|
||||
} else {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array cannot be converted to class " + componentType);
|
||||
}
|
||||
} else if (componentType==Long.TYPE) {
|
||||
if (element.isNumberValue()) {
|
||||
double d = element.doubleValue();
|
||||
long value = (long) d;
|
||||
if (value != d) {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array is too large for class " + componentType);
|
||||
}
|
||||
Array.setLong(array,i,value);
|
||||
} else {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array cannot be converted to class " + componentType);
|
||||
}
|
||||
} else if (componentType==Float.TYPE) {
|
||||
if (element.isNumberValue()) {
|
||||
double d = element.doubleValue();
|
||||
float value = (float) d;
|
||||
if (value != d) {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array is too large for class " + componentType);
|
||||
}
|
||||
Array.setFloat(array,i,value);
|
||||
} else {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array cannot be converted to class " + componentType);
|
||||
}
|
||||
} else if (componentType==Double.TYPE) {
|
||||
if (element.isNumberValue()) {
|
||||
double d = element.doubleValue();
|
||||
Array.setDouble(array,i,d);
|
||||
} else {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array cannot be converted to class " + componentType);
|
||||
}
|
||||
} else if (componentType==Boolean.TYPE) {
|
||||
if (element.isBooleanValue()) {
|
||||
boolean b = element.booleanValue();
|
||||
Array.setBoolean(array,i,b);
|
||||
} else {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array cannot be converted to class " + componentType);
|
||||
}
|
||||
} else if (componentType==Character.TYPE) {
|
||||
if (element.isStringValue()) {
|
||||
String s = element.toString();
|
||||
if (s.length()!=1) {
|
||||
throw new EcmaScriptException("A string (" + element + ") of array is not of size 1 for conversion to Character");
|
||||
}
|
||||
Array.setChar(array,i,s.charAt(0));
|
||||
} else {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array cannot be converted to class " + componentType);
|
||||
}
|
||||
} else {
|
||||
Object o = element.toJavaObject();
|
||||
if (o==null) {
|
||||
Array.set(array,i,o);
|
||||
} else {
|
||||
Class sourceClass = o.getClass();
|
||||
if (componentType.isAssignableFrom(sourceClass)) {
|
||||
Array.set(array,i,o);
|
||||
} else {
|
||||
throw new EcmaScriptException("An element (" + element + ") of array cannot be converted to class " + componentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return "ES:[" + getESClassName() + ":" + this.getClass().getName() +"]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the size of the array
|
||||
* @return the size as an int
|
||||
*/
|
||||
public int size() {
|
||||
return theArray.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the size of the array, truncating if needed
|
||||
* @param size the new size 90 or positive)
|
||||
*/
|
||||
public void setSize(int size) {
|
||||
theArray.setSize(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a specific element
|
||||
*
|
||||
* @param theElement the new element value
|
||||
* @param index the index of the element
|
||||
*/
|
||||
public void setElementAt(ESValue theElement, int index) {
|
||||
theArray.setElementAt(theElement, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the orders of the elements in an array
|
||||
* @return the reversed array (which is the same as this one)
|
||||
*/
|
||||
public ESValue reverse() throws EcmaScriptException {
|
||||
int size = theArray.size();
|
||||
if (size>0) {
|
||||
Vector reversed = new Vector(size);
|
||||
reversed.setSize(size);
|
||||
for (int i = 0, j=size-1; i<size; i++, j--) {
|
||||
reversed.setElementAt(theArray.elementAt(j),i);
|
||||
}
|
||||
theArray = reversed;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// This routines are taken from Java examples in a nutshell
|
||||
static interface Comparer {
|
||||
/**
|
||||
* Compare objects and return a value that indicates their relative order:
|
||||
* if (a > b) return a number > 0;
|
||||
* if (a == b) return 0;
|
||||
* if (a < b) return a number < 0.
|
||||
**/
|
||||
int compare(ESValue a, ESValue b) throws EcmaScriptException;
|
||||
}
|
||||
|
||||
static class DefaultComparer implements Comparer {
|
||||
public int compare(ESValue v1, ESValue v2) throws EcmaScriptException {
|
||||
ESValue v1p = v1.toESPrimitive(ESValue.EStypeNumber);
|
||||
ESValue v2p = v2.toESPrimitive(ESValue.EStypeNumber);
|
||||
if (v1p == ESUndefined.theUndefined && v2p == ESUndefined.theUndefined) return 0;
|
||||
if (v1p == ESUndefined.theUndefined ) return 1;
|
||||
if (v2p == ESUndefined.theUndefined ) return -1;
|
||||
//System.out.println("v1p = " + v1 + " v2p = " + v2);
|
||||
String s1 = v1.toString();
|
||||
String s2 = v2.toString();
|
||||
//System.out.println("s1 = " + s1 + " s2 = " + s2);
|
||||
return s1.compareTo(s2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the main sort() routine. It performs a quicksort on the elements
|
||||
* of array a between the element from and the element to.
|
||||
* The Comparer argument c is used to perform
|
||||
* comparisons between elements of the array.
|
||||
**/
|
||||
private void sort(int from, int to,
|
||||
Comparer c) throws EcmaScriptException
|
||||
{
|
||||
// If there is nothing to sort, return
|
||||
if (theArray.size() < 2) return;
|
||||
|
||||
// This is the basic quicksort algorithm, stripped of frills that can make
|
||||
// it faster but even more confusing than it already is. You should
|
||||
// understand what the code does, but don't have to understand just
|
||||
// why it is guaranteed to sort the array...
|
||||
// Note the use of the compare() method of the Comparer object.
|
||||
int i = from, j = to;
|
||||
ESValue center = (ESValue) theArray.elementAt((from + to) / 2);
|
||||
do {
|
||||
ESValue ai = (ESValue) theArray.elementAt(i);
|
||||
ESValue aj = (ESValue) theArray.elementAt(j);
|
||||
while((i < to) && (c.compare(center, ai) > 0)) { i++; ai = (ESValue) theArray.elementAt(i);}
|
||||
while((j > from) && (c.compare(center, aj) < 0)) {j--; aj = (ESValue) theArray.elementAt(j);}
|
||||
if (i < j) {
|
||||
Object tmp = ai; theArray.setElementAt(aj,i); theArray.setElementAt(tmp, j);
|
||||
}
|
||||
if (i <= j) { i++; j--; }
|
||||
} while(i <= j);
|
||||
if (from < j) sort(from, j, c); // recursively sort the rest
|
||||
if (i < to) sort(i, to, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the array with a specified compare routine
|
||||
* @param compareFn A function returning a comparer
|
||||
* @return the sorted array (in place)
|
||||
*/
|
||||
public ESValue sort(ESValue compareFn) throws EcmaScriptException {
|
||||
if ((compareFn != null) &&
|
||||
(!(compareFn instanceof FunctionPrototype))) {
|
||||
throw new EcmaScriptException("Compare function not a function: " + compareFn);
|
||||
}
|
||||
Comparer c = null;
|
||||
if (compareFn != null)
|
||||
c = new FunctionComparer((FunctionPrototype) compareFn);
|
||||
else
|
||||
c = new DefaultComparer();
|
||||
|
||||
sort(0, theArray.size()-1, c);
|
||||
return this;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public void putProperty(String propertyName, ESValue propertyValue, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (hash==LENGTHhash && propertyName.equals(LENGTHstring)) {
|
||||
int length = (int) (((ESPrimitive) propertyValue).doubleValue());
|
||||
if (length<0) {
|
||||
throw new EcmaScriptException("Invalid length value: " + propertyValue);
|
||||
}
|
||||
theArray.setSize(length);
|
||||
} else {
|
||||
int index = -1; // indicates not a valid index value
|
||||
try {
|
||||
index = Integer.parseInt(propertyName); // should be uint
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (index<0) {
|
||||
super.putProperty(propertyName, propertyValue, hash);
|
||||
} else {
|
||||
putProperty(index, propertyValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public void putProperty(int index, ESValue propertyValue)
|
||||
throws EcmaScriptException {
|
||||
|
||||
if (index>=theArray.size()) {
|
||||
theArray.setSize(index+1);
|
||||
}
|
||||
theArray.setElementAt(propertyValue, index);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getPropertyInScope(String propertyName, ScopeChain previousScope, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (hash==LENGTHhash && propertyName.equals(LENGTHstring)) {
|
||||
return new ESNumber(theArray.size());
|
||||
}
|
||||
if (hasProperty(propertyName, hash)) {
|
||||
return getProperty(propertyName, hash);
|
||||
}
|
||||
if (previousScope == null) {
|
||||
throw new EcmaScriptException("global variable '" + propertyName + "' does not have a value");
|
||||
} else {
|
||||
return previousScope.getValue(propertyName, hash);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (hash==LENGTHhash && propertyName.equals(LENGTHstring)) {
|
||||
return new ESNumber(theArray.size());
|
||||
} else {
|
||||
int index = -1; // indicates not a valid index value
|
||||
try {
|
||||
index = Integer.parseInt(propertyName); // should be uint
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (index<0) {
|
||||
return super.getProperty(propertyName, hash);
|
||||
} else {
|
||||
return getProperty(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getProperty(int index)
|
||||
throws EcmaScriptException {
|
||||
Object theElement = null;
|
||||
if (index<theArray.size()) theElement = theArray.elementAt(index);
|
||||
if (theElement == null) {
|
||||
return ESUndefined.theUndefined;
|
||||
} else {
|
||||
return (ESValue) theElement;
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean hasProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (hash==LENGTHhash && propertyName.equals(LENGTHstring)) {
|
||||
return true;
|
||||
} else {
|
||||
int index = -1; // indicates not a valid index value
|
||||
try {
|
||||
index = Integer.parseInt(propertyName); // should be uint
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (index<0) {
|
||||
return super.hasProperty(propertyName, hash);
|
||||
} else {
|
||||
return index<theArray.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
// Skip elements which were never set (are null), as Netscape
|
||||
/*
|
||||
OLD - DID IGNORE THE NORMAL PROPERTIES OF AN ARRAY
|
||||
public Enumeration getProperties() {
|
||||
return new Enumeration() {
|
||||
int nextIndex = 0;
|
||||
public boolean hasMoreElements() {
|
||||
while ( (nextIndex<theArray.size()) &&
|
||||
(theArray.elementAt(nextIndex) == null))
|
||||
nextIndex++;
|
||||
return nextIndex<theArray.size();
|
||||
}
|
||||
public Object nextElement() {
|
||||
if (hasMoreElements()) {
|
||||
return new ESNumber(nextIndex++);
|
||||
} else {
|
||||
throw new java.util.NoSuchElementException();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* Returns an enumerator for the key elements of this object,
|
||||
* that is all is enumerable properties and the (non hidden)
|
||||
* ones of its prototype, etc... As used for the for in
|
||||
* statement.
|
||||
*<P> Skip elements which were never set (are null), as Netscape
|
||||
* SHOULD USE SUPER INSTEAD !
|
||||
* @return the enumerator
|
||||
*/
|
||||
public Enumeration getProperties() {
|
||||
return new Enumeration() {
|
||||
Enumeration props = properties.keys();
|
||||
Object currentKey = null;
|
||||
int currentHash = 0;
|
||||
int nextIndex = 0;
|
||||
boolean inside = false;
|
||||
ESObject prototype = ArrayPrototype.this.getPrototype();
|
||||
public boolean hasMoreElements() {
|
||||
// Check if hasMoreElements was already called
|
||||
if (currentKey != null) return true;
|
||||
|
||||
// Check if a numeric key is appropriate
|
||||
while ( (nextIndex<theArray.size()) &&
|
||||
(theArray.elementAt(nextIndex) == null)) {
|
||||
nextIndex++;
|
||||
}
|
||||
if (nextIndex<theArray.size()) {
|
||||
// Should it be an ESNumber?
|
||||
currentKey = new ESNumber(nextIndex++);
|
||||
return true;
|
||||
}
|
||||
|
||||
while (props.hasMoreElements()) {
|
||||
currentKey = props.nextElement();
|
||||
currentHash = currentKey.hashCode();
|
||||
if (inside) {
|
||||
if (properties.containsKey((String) currentKey, currentHash)) continue;
|
||||
} else {
|
||||
if (isHiddenProperty((String) currentKey, currentHash)) continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!inside && prototype != null) {
|
||||
inside = true;
|
||||
props = prototype.getProperties();
|
||||
while (props.hasMoreElements()) {
|
||||
currentKey = props.nextElement();
|
||||
currentHash = currentKey.hashCode();
|
||||
if (properties.containsKey((String) currentKey, currentHash)) continue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
if (hasMoreElements()) {
|
||||
Object key = currentKey;
|
||||
currentKey = null;
|
||||
return key;
|
||||
} else {
|
||||
throw new java.util.NoSuchElementException();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all properties (including hidden ones), for the command
|
||||
* @listall of the interpreter. Include the visible properties of the
|
||||
* prototype (that is the one added by the user) but not the
|
||||
* hidden ones of the prototype (otherwise this would list
|
||||
* all functions for any object).
|
||||
* <P> Hidde elements which are null (as netscape)
|
||||
*
|
||||
* @return An enumeration of all properties (visible and hidden).
|
||||
*/
|
||||
public Enumeration getAllProperties() {
|
||||
return new Enumeration() {
|
||||
String [] specialProperties = getSpecialPropertyNames();
|
||||
int specialEnumerator = 0;
|
||||
Enumeration props = properties.keys(); // all of object properties
|
||||
String currentKey = null;
|
||||
int currentHash = 0;
|
||||
boolean inside = false; // true when examing prototypes properties
|
||||
int nextIndex = 0;
|
||||
public boolean hasMoreElements() {
|
||||
// OK if we already checked for a property and one exists
|
||||
if (currentKey != null) return true;
|
||||
// loop on idex properties
|
||||
if (nextIndex<theArray.size()) {
|
||||
while ( (nextIndex<theArray.size()) &&
|
||||
(theArray.elementAt(nextIndex) == null))
|
||||
nextIndex++;
|
||||
if (nextIndex<theArray.size()) {
|
||||
currentKey = Integer.toString(nextIndex);
|
||||
currentHash = currentKey.hashCode();
|
||||
nextIndex++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Loop on special properties first
|
||||
if (specialEnumerator < specialProperties.length) {
|
||||
currentKey = specialProperties[specialEnumerator];
|
||||
currentHash = currentKey.hashCode();
|
||||
specialEnumerator++;
|
||||
return true;
|
||||
}
|
||||
// loop on standard or prototype properties
|
||||
while (props.hasMoreElements()) {
|
||||
currentKey = (String) props.nextElement();
|
||||
currentHash = currentKey.hashCode();
|
||||
if (inside) {
|
||||
if (properties.containsKey(currentKey, currentHash)) continue;
|
||||
// SHOULD CHECK IF NOT IN SPECIAL
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// If prototype properties have not yet been examined, look for them
|
||||
if (!inside && getPrototype() != null) {
|
||||
inside = true;
|
||||
props = getPrototype().getProperties();
|
||||
while (props.hasMoreElements()) {
|
||||
currentKey = (String) props.nextElement();
|
||||
currentHash = currentKey.hashCode();
|
||||
if (properties.containsKey(currentKey, currentHash)) continue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Object nextElement() {
|
||||
if (hasMoreElements()) {
|
||||
String key = currentKey;
|
||||
currentKey = null;
|
||||
return key;
|
||||
} else {
|
||||
throw new java.util.NoSuchElementException();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public String[] getSpecialPropertyNames() {
|
||||
String [] ns = {LENGTHstring};
|
||||
return ns;
|
||||
}
|
||||
|
||||
// Support of custom compare function for sort
|
||||
class FunctionComparer implements Comparer {
|
||||
FunctionPrototype compareFn;
|
||||
ESValue arguments[];
|
||||
ESObject thisObject;
|
||||
public FunctionComparer (FunctionPrototype fn) {
|
||||
this.compareFn = fn;
|
||||
this.arguments = new ESValue[2];
|
||||
this.thisObject = evaluator.getGlobalObject ();
|
||||
}
|
||||
public int compare(ESValue v1, ESValue v2) throws EcmaScriptException {
|
||||
ESValue v1p = v1.toESPrimitive(ESValue.EStypeNumber);
|
||||
ESValue v2p = v2.toESPrimitive(ESValue.EStypeNumber);
|
||||
if (v1p == ESUndefined.theUndefined && v2p == ESUndefined.theUndefined) return 0;
|
||||
if (v1p == ESUndefined.theUndefined ) return 1;
|
||||
if (v2p == ESUndefined.theUndefined ) return -1;
|
||||
arguments[0] = v1;
|
||||
arguments[1] = v2;
|
||||
ESValue compValue = compareFn.callFunction (thisObject, arguments);
|
||||
return compValue.toInt32 ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
// BooleanObject.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
/**
|
||||
* Implemements the EcmaScript Boolean singleton.
|
||||
*/
|
||||
public class BooleanObject extends BuiltinFunctionObject {
|
||||
|
||||
|
||||
private BooleanObject(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator, "Boolean", 1);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return "<Boolean>";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (arguments.length==0) {
|
||||
return ESBoolean.makeBoolean(false);
|
||||
} else {
|
||||
return ESBoolean.makeBoolean(arguments[0].booleanValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
BooleanPrototype theObject = null;
|
||||
ESObject bp = evaluator.getBooleanPrototype();
|
||||
theObject= new BooleanPrototype(bp, evaluator);
|
||||
if (arguments.length>0) {
|
||||
theObject.value = ESBoolean.makeBoolean(arguments[0].booleanValue());
|
||||
} else {
|
||||
theObject.value = ESBoolean.makeBoolean(false);
|
||||
}
|
||||
return theObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to create the single Boolean object
|
||||
*
|
||||
* @param evaluator the Evaluator
|
||||
* @param objectPrototype The Object prototype attached to the evaluator
|
||||
* @param functionPrototype The Function prototype attached to the evaluator
|
||||
*
|
||||
* @return the Boolean singleton
|
||||
*/
|
||||
public static BooleanObject makeBooleanObject(Evaluator evaluator,
|
||||
ObjectPrototype objectPrototype,
|
||||
FunctionPrototype functionPrototype) {
|
||||
|
||||
BooleanPrototype booleanPrototype = new BooleanPrototype(objectPrototype, evaluator);
|
||||
BooleanObject booleanObject = new BooleanObject(functionPrototype, evaluator);
|
||||
try {
|
||||
// For booleanPrototype
|
||||
class BooleanPrototypeToString extends BuiltinFunctionObject {
|
||||
BooleanPrototypeToString(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESValue v = ((BooleanPrototype) thisObject).value;
|
||||
String s = v.toString();
|
||||
return new ESString(s);
|
||||
}
|
||||
}
|
||||
class BooleanPrototypeValueOf extends BuiltinFunctionObject {
|
||||
BooleanPrototypeValueOf(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
return ((BooleanPrototype) thisObject).value;
|
||||
}
|
||||
}
|
||||
|
||||
booleanObject.putHiddenProperty("prototype",booleanPrototype);
|
||||
booleanObject.putHiddenProperty("length",new ESNumber(1));
|
||||
|
||||
booleanPrototype.putHiddenProperty("constructor",booleanObject);
|
||||
booleanPrototype.putHiddenProperty("toString",
|
||||
new BooleanPrototypeToString("toString", evaluator, functionPrototype));
|
||||
booleanPrototype.putHiddenProperty("valueOf",
|
||||
new BooleanPrototypeValueOf("valueOf", evaluator, functionPrototype));
|
||||
} catch (EcmaScriptException e) {
|
||||
e.printStackTrace();
|
||||
throw new ProgrammingError(e.getMessage());
|
||||
}
|
||||
|
||||
evaluator.setBooleanPrototype(booleanPrototype);
|
||||
|
||||
return booleanObject;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
// BooleanPrototype.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
/**
|
||||
* Implements the prototype and is the class of all Boolean objects
|
||||
*/
|
||||
class BooleanPrototype extends ESObject {
|
||||
|
||||
// The value
|
||||
protected ESBoolean value = ESBoolean.makeBoolean(false);
|
||||
|
||||
/** Create a new Boolean initialized to false
|
||||
* @param prototype the BooleanPrototype
|
||||
* @param evaluator the evaluator
|
||||
*/
|
||||
BooleanPrototype(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getESClassName() {
|
||||
return "Boolean";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString(Evaluator evaluator) throws EcmaScriptException {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public double doubleValue() throws EcmaScriptException {
|
||||
return value.doubleValue();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue toESBoolean() throws EcmaScriptException {
|
||||
return value;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean booleanValue() {
|
||||
return value.booleanValue();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public Object toJavaObject() {
|
||||
return new Boolean(value.booleanValue());
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return "ES:[Object: builtin " + this.getClass().getName() + ":" +
|
||||
((value == null) ? "null" : value.toString()) + "]";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean isBooleanValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
// BuiltinFunctionObject.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.Evaluator;
|
||||
|
||||
/**
|
||||
* Implement the common functionality of all built-in functions
|
||||
*/
|
||||
public abstract class BuiltinFunctionObject extends FunctionPrototype {
|
||||
|
||||
|
||||
protected BuiltinFunctionObject(ESObject functionPrototype,
|
||||
Evaluator evaluator,
|
||||
String functionName,
|
||||
int length) {
|
||||
super(functionPrototype, evaluator, functionName, length);
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public void putProperty(String propertyName, ESValue propertyValue, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (!propertyName.equals("prototype")) {
|
||||
super.putProperty(propertyName, propertyValue, hash);
|
||||
} // Allowed via putHiddenProperty, used internally !
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the string defining the function
|
||||
* @return a string indicating that the function is native
|
||||
*/
|
||||
public String getFunctionImplementationString() {
|
||||
return "{[native: " + this.getClass().getName() + "]}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the function parameter description as a string
|
||||
*
|
||||
* @return the function parameter string as (a,b,c)
|
||||
*/
|
||||
public String getFunctionParametersString() {
|
||||
return "(<" + getLengthProperty()+ " args>)";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return "<" + this.getFunctionName() + ":" + this.getClass().getName() +">";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
// ESLoader.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
/**
|
||||
* Descripe the compatibility of a method, allowing to
|
||||
* postpone the choice of the method to call until all
|
||||
* potentially compatible ones have been examined.
|
||||
*/
|
||||
class CompatibilityDescriptor {
|
||||
int distance;
|
||||
boolean [] convertToChar = null; // flag to indicate if conversion to char is needed
|
||||
Object [] convertedArrays = null; // Converted array if any needed
|
||||
|
||||
/*
|
||||
* Create a new descrptor (note that there is a predefined one for
|
||||
* incompatible parameters).
|
||||
* @param distance -1 if incompatible, or evaluation of conversion distance
|
||||
* @param convertToChar Optional flag for each parameter
|
||||
* @param convertedArrays Optional list of converted arrays
|
||||
*/
|
||||
CompatibilityDescriptor(int distance,
|
||||
boolean[] convertedToChar,
|
||||
Object[] convertedArrays) {
|
||||
this.distance = distance;
|
||||
if (distance>=0) {
|
||||
this.convertToChar = convertedToChar;
|
||||
this.convertedArrays = convertedArrays;
|
||||
}
|
||||
}
|
||||
|
||||
/** Return true if the method is compatible with the parameters */
|
||||
public boolean isCompatible() {
|
||||
return distance>=0;
|
||||
}
|
||||
|
||||
/** Return the distance between perfect compatibility and this one */
|
||||
public int getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
/** Convert the parameters for this method call */
|
||||
public void convert(Object params[]) {
|
||||
if (params != null && distance>=0) {
|
||||
// Modify the parameters
|
||||
int n = params.length;
|
||||
|
||||
if (convertToChar!=null) {
|
||||
for (int i=0; i<n; i++) {
|
||||
if (convertToChar[i]) {
|
||||
String s = (String) params[i];
|
||||
Character c = new Character(s.charAt(0));
|
||||
params[i] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (convertedArrays!=null) {
|
||||
for (int i=0; i<n; i++) {
|
||||
if (convertedArrays[i] != null) {
|
||||
params[i] = convertedArrays[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// convert
|
||||
|
||||
}
|
||||
|
||||
// class CompatibilityDescriptor
|
||||
|
|
@ -1,256 +0,0 @@
|
|||
// ConstructedFunctionObject.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Vector;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.AST.ASTStatementList;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
/**
|
||||
* Implements functions constructed from source text
|
||||
*/
|
||||
public class ConstructedFunctionObject extends FunctionPrototype {
|
||||
|
||||
private static final String PROTOTYPEstring = new String("prototype").intern();
|
||||
private static final int PROTOTYPEhash=PROTOTYPEstring.hashCode();
|
||||
|
||||
private ASTStatementList theFunctionAST;
|
||||
private String [] theArguments;
|
||||
private Vector localVariableNames;
|
||||
private EvaluationSource evaluationSource = null;
|
||||
private String functionSource = null;
|
||||
|
||||
private ESValue currentArguments = ESNull.theNull;
|
||||
|
||||
private ConstructedFunctionObject(FunctionPrototype functionPrototype,
|
||||
Evaluator evaluator,
|
||||
String functionName,
|
||||
EvaluationSource evaluationSource,
|
||||
String functionSource,
|
||||
String [] arguments,
|
||||
Vector localVariableNames,
|
||||
ASTStatementList aFunctionAST) {
|
||||
super(functionPrototype, evaluator, functionName, arguments.length);
|
||||
this.evaluationSource = evaluationSource;
|
||||
this.functionSource = functionSource;
|
||||
theFunctionAST = aFunctionAST;
|
||||
theArguments = arguments;
|
||||
this.localVariableNames = localVariableNames;
|
||||
|
||||
//try {
|
||||
// targetObject.putProperty(functionName, this);
|
||||
//} catch (EcmaScriptException e) {
|
||||
// throw new ProgrammingError(e.getMessage());
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the string defining the function
|
||||
* @return the source string
|
||||
*/
|
||||
public String getFunctionImplementationString() {
|
||||
if (functionSource == null) {
|
||||
StringBuffer str = new StringBuffer();
|
||||
str.append("function ");
|
||||
str.append(getFunctionName());
|
||||
str.append("(");
|
||||
for (int i=0; i<theArguments.length; i++) {
|
||||
if (i>0) str.append(",");
|
||||
str.append(theArguments[i]);
|
||||
}
|
||||
str.append(")");
|
||||
str.append("function {<internal abstract syntax tree representation>}");
|
||||
return str.toString();
|
||||
} else {
|
||||
return functionSource;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of local variables of the function as a vector
|
||||
* @return the Vector of local variable name strings
|
||||
*/
|
||||
public Vector getLocalVariableNames() {
|
||||
return localVariableNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the function parameter description as a string
|
||||
*
|
||||
* @return the function parameter string as (a,b,c)
|
||||
*/
|
||||
public String getFunctionParametersString() {
|
||||
StringBuffer str = new StringBuffer();
|
||||
str.append("(");
|
||||
for (int i=0; i<theArguments.length; i++) {
|
||||
if (i>0) str.append(",");
|
||||
str.append(theArguments[i]);
|
||||
}
|
||||
str.append(")");
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESValue value = null;
|
||||
ESArguments args = ESArguments.makeNewESArguments(evaluator,
|
||||
this,
|
||||
theArguments,
|
||||
arguments);
|
||||
ESValue oldArguments = currentArguments;
|
||||
currentArguments = args;
|
||||
try {
|
||||
value = evaluator.evaluateFunction(theFunctionAST,
|
||||
evaluationSource,
|
||||
args,
|
||||
localVariableNames,
|
||||
thisObject);
|
||||
} finally {
|
||||
currentArguments = oldArguments;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESValue prototype = getProperty(PROTOTYPEstring, PROTOTYPEhash);
|
||||
ESObject op = evaluator.getObjectPrototype();
|
||||
if (!(prototype instanceof ESObject)) prototype = op;
|
||||
ESObject obj = new ObjectPrototype((ESObject) prototype, evaluator);
|
||||
ESValue result = callFunction(obj, arguments);
|
||||
// The next line was probably a misinterpretation of // 15.3.2.1 (18)
|
||||
// which returned an other object if the function returned an object
|
||||
// if (result instanceof ESObject) obj = (ESObject) result;
|
||||
return obj;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString () {
|
||||
return getFunctionImplementationString();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
StringBuffer str = new StringBuffer();
|
||||
str.append("<Function: ");
|
||||
str.append(getFunctionName());
|
||||
str.append("(");
|
||||
for (int i=0; i<theArguments.length; i++) {
|
||||
if (i>0) str.append(",");
|
||||
str.append(theArguments[i]);
|
||||
}
|
||||
str.append(")>");
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to create a function object. Used by the
|
||||
* EcmaScript Function function to create new functions
|
||||
*
|
||||
* @param evaluator the Evaluator
|
||||
* @param functionName the name of the new function
|
||||
* @param evaluationSource An identification of the source of the function
|
||||
* @param sourceString The source of the parsed function
|
||||
* @param arguments The array of arguments
|
||||
* @param localVariableNames the list of local variable declared by var
|
||||
* @param aFunctionAST the parsed function
|
||||
*
|
||||
* @return A new function object
|
||||
*/
|
||||
public static ConstructedFunctionObject makeNewConstructedFunction(
|
||||
Evaluator evaluator,
|
||||
String functionName,
|
||||
EvaluationSource evaluationSource,
|
||||
String sourceString,
|
||||
String [] arguments,
|
||||
Vector localVariableNames,
|
||||
ASTStatementList aFunctionAST) {
|
||||
ConstructedFunctionObject theNewFunction = null;
|
||||
try {
|
||||
FunctionPrototype fp = (FunctionPrototype) evaluator.getFunctionPrototype();
|
||||
|
||||
theNewFunction = new ConstructedFunctionObject (
|
||||
fp,
|
||||
evaluator,
|
||||
functionName,
|
||||
evaluationSource,
|
||||
sourceString,
|
||||
arguments,
|
||||
localVariableNames,
|
||||
aFunctionAST);
|
||||
ObjectPrototype thePrototype = ObjectObject.createObject(evaluator);
|
||||
theNewFunction.putHiddenProperty("prototype",thePrototype);
|
||||
thePrototype.putHiddenProperty("constructor",theNewFunction);
|
||||
} catch (EcmaScriptException e) {
|
||||
e.printStackTrace();
|
||||
throw new ProgrammingError(e.getMessage());
|
||||
}
|
||||
return theNewFunction;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getPropertyInScope(String propertyName, ScopeChain previousScope, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (propertyName.equals("arguments")) {
|
||||
return currentArguments;
|
||||
} else {
|
||||
return super.getPropertyInScope(propertyName, previousScope, hash);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (propertyName.equals("arguments")) {
|
||||
return currentArguments;
|
||||
} else {
|
||||
return super.getProperty(propertyName, hash);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean hasProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (propertyName.equals("arguments")) {
|
||||
return true;
|
||||
} else {
|
||||
return super.hasProperty(propertyName, hash);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public void putProperty(String propertyName, ESValue propertyValue, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (!propertyName.equals("arguments")) {
|
||||
super.putProperty(propertyName, propertyValue, hash);
|
||||
} // Allowed via putHiddenProperty, used internally !
|
||||
}
|
||||
|
||||
// public ESValue replaceCurrentArguments(ESObject newArguments) {
|
||||
// ESValue oldArguments = currentArguments;
|
||||
// currentArguments = newArguments;
|
||||
// return oldArguments;
|
||||
// }
|
||||
|
||||
}
|
|
@ -1,803 +0,0 @@
|
|||
// DateObject.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.text.DateFormat;
|
||||
|
||||
public class DateObject extends BuiltinFunctionObject {
|
||||
|
||||
|
||||
private DateObject(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator, "Date", 7);
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return "<Date>";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
return new ESString(new Date().toString());
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype theObject = null;
|
||||
ESObject dp = evaluator.getDatePrototype();
|
||||
theObject= new DatePrototype(dp, evaluator);
|
||||
int l = arguments.length;
|
||||
|
||||
if (l==2 || l == 0) {
|
||||
theObject.date = new Date();
|
||||
} else if (l==1) {
|
||||
double d = arguments[0].doubleValue();
|
||||
if (Double.isNaN(d)) {
|
||||
theObject.date = null;
|
||||
} else {
|
||||
theObject.date = new Date((long) d);
|
||||
}
|
||||
} else {
|
||||
int year = arguments[0].toInt32();
|
||||
if (0 <= year && year<=99) year += 1900;
|
||||
int month = arguments[1].toInt32();
|
||||
int day = arguments[2].toInt32();
|
||||
int hour = (l>3) ? arguments[3].toInt32() : 0;
|
||||
int minute = (l>4) ? arguments[4].toInt32() : 0;
|
||||
int second = (l>5) ? arguments[5].toInt32() : 0;
|
||||
int ms = (l>6) ? arguments[6].toInt32() : 0;
|
||||
// Using current current locale, set it to the specified time
|
||||
// System.out.println("YEAR IS " + year);
|
||||
GregorianCalendar cal =
|
||||
new GregorianCalendar(year,month,day,hour,minute,second);
|
||||
if (ms != 0) cal.set(Calendar.MILLISECOND, ms);
|
||||
theObject.date = cal.getTime();
|
||||
}
|
||||
return theObject;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Utility function to create the single Date object
|
||||
*
|
||||
* @param evaluator the Evaluator
|
||||
* @param objectPrototype The Object prototype attached to the evaluator
|
||||
* @param functionPrototype The Function prototype attached to the evaluator
|
||||
*
|
||||
* @return the Date singleton
|
||||
*/
|
||||
public static DateObject makeDateObject(Evaluator evaluator,
|
||||
ObjectPrototype objectPrototype,
|
||||
FunctionPrototype functionPrototype) {
|
||||
|
||||
|
||||
DatePrototype datePrototype = new DatePrototype(objectPrototype, evaluator);
|
||||
DateObject dateObject = new DateObject(functionPrototype, evaluator);
|
||||
|
||||
try {
|
||||
|
||||
// For datePrototype
|
||||
class DatePrototypeToString extends BuiltinFunctionObject {
|
||||
DatePrototypeToString(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return (aDate.date == null) ?
|
||||
new ESString("NaN"):
|
||||
new ESString(aDate.date.toString());
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeValueOf extends BuiltinFunctionObject {
|
||||
DatePrototypeValueOf(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
if (aDate.date == null) {
|
||||
return new ESNumber(Double.NaN);
|
||||
} else {
|
||||
long t = aDate.date.getTime();
|
||||
return new ESNumber((double) t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeToLocaleString extends BuiltinFunctionObject {
|
||||
DatePrototypeToLocaleString(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
DateFormat df = DateFormat.getDateTimeInstance();
|
||||
df.setTimeZone(TimeZone.getDefault());
|
||||
return (aDate.date == null) ?
|
||||
new ESString("NaN"):
|
||||
new ESString(df.format(aDate.date));
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeToGMTString extends BuiltinFunctionObject {
|
||||
DatePrototypeToGMTString(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL);
|
||||
df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
return (aDate.date == null) ?
|
||||
new ESString("NaN"):
|
||||
new ESString(df.format(aDate.date));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DatePrototypeGetYear extends BuiltinFunctionObject {
|
||||
DatePrototypeGetYear(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
ESValue v = aDate.get(Calendar.YEAR);
|
||||
return new ESNumber(v.doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeGetFullYear extends BuiltinFunctionObject {
|
||||
DatePrototypeGetFullYear(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.get(Calendar.YEAR);
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeGetUTCFullYear extends BuiltinFunctionObject {
|
||||
DatePrototypeGetUTCFullYear(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.getUTC(Calendar.YEAR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DatePrototypeGetMonth extends BuiltinFunctionObject {
|
||||
DatePrototypeGetMonth(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.get(Calendar.MONTH);
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeGetUTCMonth extends BuiltinFunctionObject {
|
||||
DatePrototypeGetUTCMonth(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.getUTC(Calendar.MONTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DatePrototypeGetDate extends BuiltinFunctionObject {
|
||||
DatePrototypeGetDate(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeGetUTCDate extends BuiltinFunctionObject {
|
||||
DatePrototypeGetUTCDate(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.getUTC(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DatePrototypeGetDay extends BuiltinFunctionObject {
|
||||
DatePrototypeGetDay(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
// EcmaScript has SUNDAY=0, java SUNDAY=1 - converted in DatePrototype
|
||||
return aDate.get(Calendar.DAY_OF_WEEK);
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeGetUTCDay extends BuiltinFunctionObject {
|
||||
DatePrototypeGetUTCDay(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.getUTC(Calendar.DAY_OF_WEEK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class DatePrototypeGetHours extends BuiltinFunctionObject {
|
||||
DatePrototypeGetHours(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeGetUTCHours extends BuiltinFunctionObject {
|
||||
DatePrototypeGetUTCHours(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.getUTC(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DatePrototypeGetMinutes extends BuiltinFunctionObject {
|
||||
DatePrototypeGetMinutes(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.get(Calendar.MINUTE);
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeGetUTCMinutes extends BuiltinFunctionObject {
|
||||
DatePrototypeGetUTCMinutes(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.getUTC(Calendar.MINUTE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DatePrototypeGetSeconds extends BuiltinFunctionObject {
|
||||
DatePrototypeGetSeconds(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.get(Calendar.SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeGetUTCSeconds extends BuiltinFunctionObject {
|
||||
DatePrototypeGetUTCSeconds(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.getUTC(Calendar.SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DatePrototypeGetMilliseconds extends BuiltinFunctionObject {
|
||||
DatePrototypeGetMilliseconds(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.get(Calendar.MILLISECOND);
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeGetUTCMilliseconds extends BuiltinFunctionObject {
|
||||
DatePrototypeGetUTCMilliseconds(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.getUTC(Calendar.MILLISECOND);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class DatePrototypeSetYear extends BuiltinFunctionObject {
|
||||
DatePrototypeSetYear(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
ESValue v = aDate.get(Calendar.YEAR);
|
||||
return aDate.setYear(arguments);
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeSetFullYear extends BuiltinFunctionObject {
|
||||
DatePrototypeSetFullYear(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setTime(arguments,
|
||||
new int [] {Calendar.YEAR,Calendar.MONTH,Calendar.DAY_OF_MONTH});
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeSetUTCFullYear extends BuiltinFunctionObject {
|
||||
DatePrototypeSetUTCFullYear(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setUTCTime(arguments,
|
||||
new int [] {Calendar.YEAR,Calendar.MONTH,Calendar.DAY_OF_MONTH});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DatePrototypeSetMonth extends BuiltinFunctionObject {
|
||||
DatePrototypeSetMonth(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setTime(arguments,
|
||||
new int [] {Calendar.MONTH,Calendar.DAY_OF_MONTH});
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeSetUTCMonth extends BuiltinFunctionObject {
|
||||
DatePrototypeSetUTCMonth(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setUTCTime(arguments,
|
||||
new int [] {Calendar.MONTH,Calendar.DAY_OF_MONTH});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DatePrototypeSetDate extends BuiltinFunctionObject {
|
||||
DatePrototypeSetDate(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setTime(arguments,
|
||||
new int [] {Calendar.DAY_OF_MONTH});
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeSetUTCDate extends BuiltinFunctionObject {
|
||||
DatePrototypeSetUTCDate(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setUTCTime(arguments,
|
||||
new int [] {Calendar.DAY_OF_MONTH});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class DatePrototypeSetHours extends BuiltinFunctionObject {
|
||||
DatePrototypeSetHours(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setTime(arguments,
|
||||
new int [] {Calendar.HOUR_OF_DAY,Calendar.MINUTE,Calendar.SECOND,Calendar.MILLISECOND});
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeSetUTCHours extends BuiltinFunctionObject {
|
||||
DatePrototypeSetUTCHours(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setUTCTime(arguments,
|
||||
new int [] {Calendar.HOUR_OF_DAY,Calendar.MINUTE,Calendar.SECOND,Calendar.MILLISECOND});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DatePrototypeSetMinutes extends BuiltinFunctionObject {
|
||||
DatePrototypeSetMinutes(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setTime(arguments,
|
||||
new int [] {Calendar.MINUTE,Calendar.SECOND,Calendar.MILLISECOND});
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeSetUTCMinutes extends BuiltinFunctionObject {
|
||||
DatePrototypeSetUTCMinutes(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setUTCTime(arguments,
|
||||
new int [] {Calendar.MINUTE,Calendar.SECOND,Calendar.MILLISECOND});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DatePrototypeSetSeconds extends BuiltinFunctionObject {
|
||||
DatePrototypeSetSeconds(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setTime(arguments,
|
||||
new int [] {Calendar.SECOND,Calendar.MILLISECOND});
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeSetUTCSeconds extends BuiltinFunctionObject {
|
||||
DatePrototypeSetUTCSeconds(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setUTCTime(arguments,
|
||||
new int [] {Calendar.SECOND,Calendar.MILLISECOND});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DatePrototypeSetMilliseconds extends BuiltinFunctionObject {
|
||||
DatePrototypeSetMilliseconds(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setTime(arguments, new int [] {Calendar.MILLISECOND});
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeSetUTCMilliseconds extends BuiltinFunctionObject {
|
||||
DatePrototypeSetUTCMilliseconds(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
return aDate.setUTCTime(arguments, new int [] {Calendar.MILLISECOND});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class DatePrototypeGetTimezoneOffset extends BuiltinFunctionObject {
|
||||
DatePrototypeGetTimezoneOffset(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getDefault());
|
||||
cal.setTime(aDate.date);
|
||||
TimeZone tz = cal.getTimeZone();
|
||||
int offset = tz.getOffset(cal.get(Calendar.ERA),
|
||||
cal.get(Calendar.YEAR),
|
||||
cal.get(Calendar.MONTH),
|
||||
cal.get(Calendar.DATE),
|
||||
cal.get(Calendar.DAY_OF_WEEK),
|
||||
cal.get(Calendar.HOUR_OF_DAY) * 86400000
|
||||
+ cal.get(Calendar.MINUTE) * 3600000
|
||||
+ cal.get(Calendar.SECOND) * 1000);
|
||||
// int offset = TimeZone.getDefault().getRawOffset();
|
||||
//System.out.println("TimeZone.getDefault().getID(): " + TimeZone.getDefault().getID());
|
||||
// System.out.println("TimeZone.getDefault().getRawOffset(): " + TimeZone.getDefault().getRawOffset());
|
||||
|
||||
int minutes = -(offset / 1000 / 60); // convert to minutes
|
||||
return new ESNumber(minutes);
|
||||
}
|
||||
}
|
||||
|
||||
class DatePrototypeSetTime extends BuiltinFunctionObject {
|
||||
DatePrototypeSetTime(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
DatePrototype aDate = (DatePrototype) thisObject;
|
||||
double dateValue = Double.NaN;
|
||||
if (arguments.length>0) {
|
||||
dateValue = arguments[0].doubleValue();
|
||||
}
|
||||
if (Double.isNaN(dateValue)) {
|
||||
aDate.date = null;
|
||||
} else {
|
||||
aDate.date = new Date((long) dateValue);
|
||||
}
|
||||
return new ESNumber(dateValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// For dateObject
|
||||
class DateObjectParse extends BuiltinFunctionObject {
|
||||
DateObjectParse(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (arguments.length<=0) {
|
||||
throw new EcmaScriptException("Missing argument");
|
||||
}
|
||||
String dateString = arguments[0].toString();
|
||||
DateFormat df = DateFormat.getDateInstance();
|
||||
ESValue dateValue = null;
|
||||
try {
|
||||
Date date = df.parse(dateString);
|
||||
dateValue = new ESNumber(date.getTime());
|
||||
} catch (java.text.ParseException e) {
|
||||
dateValue = new ESNumber(Double.NaN);
|
||||
}
|
||||
return dateValue;
|
||||
}
|
||||
}
|
||||
|
||||
class DateObjectUTC extends BuiltinFunctionObject {
|
||||
DateObjectUTC(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 7);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
int l = arguments.length;
|
||||
if (l<=2) {
|
||||
throw new EcmaScriptException("Missing argument");
|
||||
}
|
||||
int year = arguments[0].toInt32();
|
||||
if (0 <= year && year<=99) year += 1900;
|
||||
int month = arguments[1].toInt32();
|
||||
int day = arguments[2].toInt32();
|
||||
int hour = (l>3) ? arguments[3].toInt32() : 0;
|
||||
int minute = (l>4) ? arguments[4].toInt32() : 0;
|
||||
int second = (l>5) ? arguments[5].toInt32() : 0;
|
||||
int ms = (l>6) ? arguments[6].toInt32() : 0;
|
||||
Calendar cal =
|
||||
new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
||||
cal.set(Calendar.YEAR, year);
|
||||
cal.set(Calendar.MONTH, month);
|
||||
cal.set(Calendar.DAY_OF_MONTH, day);
|
||||
cal.set(Calendar.HOUR_OF_DAY, hour);
|
||||
cal.set(Calendar.MINUTE, minute);
|
||||
cal.set(Calendar.SECOND, second);
|
||||
cal.set(Calendar.MILLISECOND, ms );
|
||||
long timeinms = cal.getTime().getTime();
|
||||
return new ESNumber((double) timeinms);
|
||||
}
|
||||
}
|
||||
|
||||
dateObject.putHiddenProperty("prototype",datePrototype);
|
||||
dateObject.putHiddenProperty("length",new ESNumber(7));
|
||||
dateObject.putHiddenProperty("parse",
|
||||
new DateObjectParse("parse", evaluator, functionPrototype));
|
||||
dateObject.putHiddenProperty("UTC",
|
||||
new DateObjectUTC("UTC", evaluator, functionPrototype));
|
||||
|
||||
datePrototype.putHiddenProperty("constructor",dateObject);
|
||||
datePrototype.putHiddenProperty("toString",
|
||||
new DatePrototypeToString("toString", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("toLocaleString",
|
||||
new DatePrototypeToLocaleString("toLocaleString", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("toGMTString",
|
||||
new DatePrototypeToGMTString("toGMTString", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("toUTCString",
|
||||
new DatePrototypeToGMTString("toUTCString", evaluator, functionPrototype));
|
||||
|
||||
datePrototype.putHiddenProperty("valueOf",
|
||||
new DatePrototypeValueOf("valueOf", evaluator, functionPrototype));
|
||||
|
||||
datePrototype.putHiddenProperty("getTime",
|
||||
new DatePrototypeValueOf("getTime", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getYear",
|
||||
new DatePrototypeGetYear("getYear", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getFullYear",
|
||||
new DatePrototypeGetFullYear("getFullYear", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getUTCFullYear",
|
||||
new DatePrototypeGetUTCFullYear("getUTCFullYear", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getMonth",
|
||||
new DatePrototypeGetMonth("getMonth", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getUTCMonth",
|
||||
new DatePrototypeGetUTCMonth("getUTCMonth", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getDate",
|
||||
new DatePrototypeGetDate("getDate", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getUTCDate",
|
||||
new DatePrototypeGetUTCDate("getUTCDate", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getDay",
|
||||
new DatePrototypeGetDay("getDay", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getUTCDay",
|
||||
new DatePrototypeGetUTCDay("getUTCDay", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getHours",
|
||||
new DatePrototypeGetHours("getHours", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getUTCHours",
|
||||
new DatePrototypeGetUTCHours("getUTCHours", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getMinutes",
|
||||
new DatePrototypeGetMinutes("getMinutes", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getUTCMinutes",
|
||||
new DatePrototypeGetUTCMinutes("getUTCMinutes", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getSeconds",
|
||||
new DatePrototypeGetSeconds("getSeconds", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getUTCSeconds",
|
||||
new DatePrototypeGetUTCSeconds("getUTCSeconds", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getMilliseconds",
|
||||
new DatePrototypeGetMilliseconds("getMilliseconds", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("getUTCMilliseconds",
|
||||
new DatePrototypeGetUTCMilliseconds("getUTCMilliseconds", evaluator, functionPrototype));
|
||||
|
||||
datePrototype.putHiddenProperty("setYear",
|
||||
new DatePrototypeSetYear("setYear", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setFullYear",
|
||||
new DatePrototypeSetFullYear("setFullYear", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setUTCFullYear",
|
||||
new DatePrototypeSetUTCFullYear("setUTCFullYear", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setMonth",
|
||||
new DatePrototypeSetMonth("setMonth", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setUTCMonth",
|
||||
new DatePrototypeSetUTCMonth("setUTCMonth", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setDate",
|
||||
new DatePrototypeSetDate("setDate", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setUTCDate",
|
||||
new DatePrototypeSetUTCDate("setUTCDate", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setHours",
|
||||
new DatePrototypeSetHours("setHours", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setUTCHours",
|
||||
new DatePrototypeSetUTCHours("setUTCHours", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setMinutes",
|
||||
new DatePrototypeSetMinutes("setMinutes", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setUTCMinutes",
|
||||
new DatePrototypeSetUTCMinutes("setUTCMinutes", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setSeconds",
|
||||
new DatePrototypeSetSeconds("setSeconds", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setUTCSeconds",
|
||||
new DatePrototypeSetUTCSeconds("setUTCSeconds", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setMilliseconds",
|
||||
new DatePrototypeSetMilliseconds("setMilliseconds", evaluator, functionPrototype));
|
||||
datePrototype.putHiddenProperty("setUTCMilliseconds",
|
||||
new DatePrototypeSetUTCMilliseconds("setUTCMilliseconds", evaluator, functionPrototype));
|
||||
|
||||
datePrototype.putHiddenProperty("getTimezoneOffset",
|
||||
new DatePrototypeGetTimezoneOffset("getTimezoneOffset", evaluator, functionPrototype));
|
||||
|
||||
datePrototype.putHiddenProperty("setTime",
|
||||
new DatePrototypeSetTime("setTime", evaluator, functionPrototype));
|
||||
|
||||
} catch (EcmaScriptException e) {
|
||||
e.printStackTrace();
|
||||
throw new ProgrammingError(e.getMessage());
|
||||
}
|
||||
|
||||
evaluator.setDatePrototype(datePrototype);
|
||||
|
||||
return dateObject;
|
||||
}
|
||||
}
|
|
@ -1,225 +0,0 @@
|
|||
// DatePrototype.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Implements the prototype and is the class of all Date objects
|
||||
*/
|
||||
public class DatePrototype extends ESObject {
|
||||
|
||||
// The value
|
||||
protected Date date = null;
|
||||
|
||||
/**
|
||||
* Create a new Date object with a null date
|
||||
* @param prototype the Date prototype
|
||||
* @param evaluator the Evaluator
|
||||
*/
|
||||
DatePrototype(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator);
|
||||
date = new Date();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Date object with a specified date
|
||||
* @param prototype the Date prototype
|
||||
* @param evaluator the Evaluator
|
||||
* @param date the Date
|
||||
*/
|
||||
public DatePrototype (Evaluator evaluator, Date aDate) {
|
||||
super(evaluator.getDatePrototype(), evaluator);
|
||||
date = new Date(aDate.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Date object with a specified date
|
||||
* @param prototype the Date prototype
|
||||
* @param evaluator the Evaluator
|
||||
* @param time the Date
|
||||
*/
|
||||
public DatePrototype (Evaluator evaluator, long time) {
|
||||
super(evaluator.getDatePrototype(), evaluator);
|
||||
date = new Date(time);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getESClassName() {
|
||||
return "Date";
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the year value of the date. BEWARE: Fixed as base 1900 !
|
||||
* @param arguments The array of arguments, the first one being the year
|
||||
* @return the new date as a number
|
||||
*/
|
||||
public ESValue setYear(ESValue[] arguments) throws EcmaScriptException {
|
||||
if (date == null) {
|
||||
return new ESNumber(Double.NaN);
|
||||
} else {
|
||||
if (arguments.length<=0) {
|
||||
date = null;
|
||||
return new ESNumber(Double.NaN);
|
||||
}
|
||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getDefault());
|
||||
cal.setTime(date);
|
||||
double d = arguments[0].doubleValue();
|
||||
if (Double.isNaN(d)) {
|
||||
date = null;
|
||||
return new ESNumber(Double.NaN);
|
||||
}
|
||||
if (d <100) d+= 1900;
|
||||
// System.out.println("SETYEAR to " + d);
|
||||
cal.set(Calendar.YEAR, (int) d);
|
||||
date = cal.getTime();
|
||||
long t = date.getTime();
|
||||
return new ESNumber((double) t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the time value of the date based on the element type to change
|
||||
* Assume that the time elements are in the local time zone
|
||||
* @param arguments The array of arguments
|
||||
* @para, argTypes The array of element type
|
||||
* @return the new date as a number
|
||||
*/
|
||||
public ESValue setTime(ESValue[] arguments, int [] argTypes) throws EcmaScriptException {
|
||||
if (date == null) {
|
||||
return new ESNumber(Double.NaN);
|
||||
} else {
|
||||
if (arguments.length<=0) {
|
||||
date = null;
|
||||
return new ESNumber(Double.NaN);
|
||||
}
|
||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getDefault());
|
||||
cal.setTime(date);
|
||||
for (int iarg=0; (iarg<argTypes.length) && (iarg<arguments.length); iarg++) {
|
||||
double d = arguments[iarg].doubleValue();
|
||||
if (Double.isNaN(d)) {
|
||||
date = null;
|
||||
return new ESNumber(Double.NaN);
|
||||
}
|
||||
// System.out.println("SET " + argTypes[iarg] + " to " + d);
|
||||
cal.set(argTypes[iarg], (int) d);
|
||||
}
|
||||
date = cal.getTime();
|
||||
long t = date.getTime();
|
||||
return new ESNumber((double) t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the time value of the date based on the element type to change
|
||||
* Assume that the time elements are in the UTC time zone
|
||||
* @param arguments The array of arguments
|
||||
* @para, argTypes The array of element type
|
||||
* @return the new date as a number
|
||||
*/
|
||||
public ESValue setUTCTime(ESValue[] arguments, int [] argTypes) throws EcmaScriptException {
|
||||
if (date == null) {
|
||||
return new ESNumber(Double.NaN);
|
||||
} else {
|
||||
if (arguments.length<=0) {
|
||||
date = null;
|
||||
return new ESNumber(Double.NaN);
|
||||
}
|
||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
||||
cal.setTime(date);
|
||||
for (int iarg=0; (iarg<argTypes.length) && (iarg<arguments.length); iarg++) {
|
||||
double d = arguments[iarg].doubleValue();
|
||||
if (Double.isNaN(d)) {
|
||||
date = null;
|
||||
return new ESNumber(Double.NaN);
|
||||
}
|
||||
// System.out.println("UTCSET " + argTypes[iarg] + " to " + d);
|
||||
cal.set(argTypes[iarg], (int) d);
|
||||
}
|
||||
date = cal.getTime();
|
||||
long t = date.getTime();
|
||||
return new ESNumber((double) t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an element of the date (in local time zone)
|
||||
* @param element The type of the element
|
||||
* @return the element as a value
|
||||
*/
|
||||
public ESValue get(int element) {
|
||||
if (date == null) {
|
||||
return new ESNumber(Double.NaN);
|
||||
} else {
|
||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getDefault());
|
||||
cal.setTime(date);
|
||||
long t = cal.get(element);
|
||||
// EcmaScript has SUNDAY=0, java SUNDAY=1 - converted in DatePrototype
|
||||
if (element == Calendar.DAY_OF_WEEK) t--;
|
||||
return new ESNumber((double) t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an element of the date (in UTC time zone)
|
||||
* @param element The type of the element
|
||||
* @return the element as a value
|
||||
*/
|
||||
public ESValue getUTC(int element) {
|
||||
if (date == null) {
|
||||
return new ESNumber(Double.NaN);
|
||||
} else {
|
||||
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
||||
cal.setTime(date);
|
||||
long t = cal.get(element);
|
||||
// EcmaScript has SUNDAY=0, java SUNDAY=1 - converted in DatePrototype
|
||||
if (element == Calendar.DAY_OF_WEEK) t--;
|
||||
return new ESNumber((double) t);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return (date==null ? "null" : date.toString());
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return "ES:[Object: builtin " + this.getClass().getName() + ":" +
|
||||
((date == null) ? "null" : date.toString()) + "]";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public Object toJavaObject() {
|
||||
return date;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getDefaultValue()
|
||||
throws EcmaScriptException {
|
||||
return this.getDefaultValue(EStypeString);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,257 +0,0 @@
|
|||
// ESArguments.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
/**
|
||||
* Implements the "arguments" object for function call
|
||||
*/
|
||||
public final class ESArguments extends ESObject {
|
||||
|
||||
private ESObject callee; // Called object
|
||||
private int length; // Number of arguments
|
||||
String [] argumentNames; // Argument names from 0 to n
|
||||
// (not readily available) int [] hashCodes; // Argument hash codes from 0 to n
|
||||
|
||||
/**
|
||||
* Create a new arguments object - only called by makeNewESArgument
|
||||
* @param prototype The Object prototype
|
||||
* @param evaluator The evaluator
|
||||
* @param argumentNames The array of argument names
|
||||
* @param length The number of arguments (max of names and values
|
||||
* @param callee The called object
|
||||
*/
|
||||
private ESArguments(ESObject prototype,
|
||||
Evaluator evaluator,
|
||||
String [] argumentNames,
|
||||
int length,
|
||||
ESObject callee) {
|
||||
super(prototype, evaluator, (length<3) ? 5 : 11 ); // limit space requirements
|
||||
this.argumentNames = argumentNames;
|
||||
this.length = length;
|
||||
this.callee = callee;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getPropertyInScope(String propertyName,
|
||||
ScopeChain previousScope,
|
||||
int hash)
|
||||
throws EcmaScriptException {
|
||||
if (propertyName.equals("callee")) {
|
||||
return callee;
|
||||
} else if (propertyName.equals("arguments")) {
|
||||
return this;
|
||||
} else if (propertyName.equals("length")) {
|
||||
return new ESNumber((double) length);
|
||||
}
|
||||
// directly test on get
|
||||
if (super.hasProperty(propertyName, hash)) {
|
||||
return (ESValue) super.getProperty(propertyName, hash);
|
||||
}
|
||||
int index = -1; // indicates not a valid index value
|
||||
try {
|
||||
char c = propertyName.charAt(0);
|
||||
if ('0' <= c && c <= '9') {
|
||||
index = Integer.parseInt(propertyName);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
} catch (StringIndexOutOfBoundsException e) { // for charAt
|
||||
}
|
||||
if (index>=0 && index<argumentNames.length) {
|
||||
propertyName = argumentNames[index];
|
||||
hash = propertyName.hashCode();
|
||||
return super.getProperty(propertyName, hash); // will be defined
|
||||
}
|
||||
if (previousScope == null) {
|
||||
throw new EcmaScriptException("global variable '" + propertyName + "' does not have a value");
|
||||
} else {
|
||||
return previousScope.getValue(propertyName, hash);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue doIndirectCallInScope(Evaluator evaluator,
|
||||
ScopeChain previousScope,
|
||||
ESObject thisObject,
|
||||
String functionName,
|
||||
int hash,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (functionName.equals("callee")) {
|
||||
return callee.callFunction(thisObject,arguments);
|
||||
} else {
|
||||
return super.doIndirectCallInScope(evaluator, previousScope, thisObject, functionName, hash, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
|
||||
if (propertyName.equals("callee")) {
|
||||
return callee;
|
||||
} else if (propertyName.equals("arguments")) {
|
||||
return this;
|
||||
} else if (propertyName.equals("length")) {
|
||||
return new ESNumber((double) length);
|
||||
} else {
|
||||
// Assume that it is more likely a name than a number
|
||||
if (super.hasProperty(propertyName, hash)) {
|
||||
return super.getProperty(propertyName, hash);
|
||||
}
|
||||
int index = -1; // indicates not a valid index value
|
||||
try {
|
||||
char c = propertyName.charAt(0);
|
||||
if ('0' <= c && c <= '9') {
|
||||
index = Integer.parseInt(propertyName);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (index>=0 && index<argumentNames.length) {
|
||||
propertyName = argumentNames[index];
|
||||
hash = propertyName.hashCode();
|
||||
}
|
||||
return super.getProperty(propertyName, hash);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getProperty(int index)
|
||||
throws EcmaScriptException {
|
||||
if (index>=0 && index<argumentNames.length) {
|
||||
String propertyName = argumentNames[index];
|
||||
return super.getProperty(propertyName, propertyName.hashCode());
|
||||
} else {
|
||||
String iString = Integer.toString(index);
|
||||
return getProperty(iString, iString.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean hasProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (propertyName.equals("callee")) {
|
||||
return true;
|
||||
} else if (propertyName.equals("arguments")) {
|
||||
return true;
|
||||
} else if (propertyName.equals("length")) {
|
||||
return true;
|
||||
} else if (super.hasProperty(propertyName, hash)) {
|
||||
return true;
|
||||
} else {
|
||||
int index = -1; // indicates not a valid index value
|
||||
try {
|
||||
char c = propertyName.charAt(0);
|
||||
if ('0' <= c && c <= '9') {
|
||||
index = Integer.parseInt(propertyName);
|
||||
} } catch (NumberFormatException e) {
|
||||
}
|
||||
if (index>=0 && index<argumentNames.length) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a new ESArgument from names and values - the number
|
||||
* of names and values do not have to be identical.
|
||||
* @param evaluator theEvaluator
|
||||
* @param callee the called function
|
||||
* @param argumentNames the names of the arguments of the function
|
||||
* @param agumentValues the values of the argument.
|
||||
* @return the new ESArguments
|
||||
*/
|
||||
public static ESArguments makeNewESArguments(Evaluator evaluator,
|
||||
ESObject callee,
|
||||
String [] argumentNames,
|
||||
ESValue[] argumentValues) {
|
||||
ObjectPrototype op =
|
||||
(ObjectPrototype) evaluator.getObjectPrototype();
|
||||
// Get maximum number of arguments (formal or actual), as
|
||||
// more than the number of formal arguments can be reached
|
||||
// using the (old fashioned) arguments variable).
|
||||
int maxArgs = Math.max(argumentValues.length, argumentNames.length);
|
||||
ESArguments args = new ESArguments(op, evaluator, argumentNames,
|
||||
maxArgs,
|
||||
callee);
|
||||
try {
|
||||
for (int i=0; i<maxArgs; i++) {
|
||||
ESValue val = (i<argumentValues.length) ? argumentValues[i] :
|
||||
ESUndefined.theUndefined;
|
||||
if (i<argumentNames.length) {
|
||||
args.putProperty(argumentNames[i], val, argumentNames[i].hashCode());
|
||||
} else {
|
||||
String iString = Integer.toString(i);
|
||||
args.putProperty(iString, val, iString.hashCode()); // arguments after name use index as name
|
||||
}
|
||||
}
|
||||
} catch (EcmaScriptException e) {
|
||||
e.printStackTrace();
|
||||
throw new ProgrammingError(e.getMessage());
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean deleteProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
return !hasProperty(propertyName, hash); // none can be deleted...
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getDefaultValue(Evaluator evaluator, int hint)
|
||||
throws EcmaScriptException {
|
||||
return callee.getDefaultValue(hint);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public int getTypeOf() {
|
||||
return callee.getTypeOf();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public Object toJavaObject() {
|
||||
return callee.toJavaObject();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getTypeofString() {
|
||||
return callee.getTypeofString();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return callee.toString();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return callee.toDetailString();
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public String[] getSpecialPropertyNames() {
|
||||
String [] ns = {"arguments","callee","length"};
|
||||
return ns;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,319 +0,0 @@
|
|||
// ESArrayWrapper.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Date;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
|
||||
// Class to wrap a Java array as an EcmaScript object
|
||||
public class ESArrayWrapper extends ESObject {
|
||||
|
||||
// The java array
|
||||
protected Object javaArray;
|
||||
|
||||
/**
|
||||
* Create a new array wrapper
|
||||
* @param javaArray the java array to wrap
|
||||
* @param evaluator the evaluator
|
||||
*/
|
||||
public ESArrayWrapper(Object javaArray, Evaluator evaluator) {
|
||||
super(null, evaluator);
|
||||
this.javaArray = javaArray;
|
||||
if (!javaArray.getClass().isArray()) {
|
||||
throw new ProgrammingError("Array wrapper used on non array object");
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESObject getPrototype() {
|
||||
throw new ProgrammingError("Cannot get prototype of Array Wrapper");
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getESClassName() {
|
||||
return "Java Array";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public int getTypeOf() {
|
||||
return EStypeObject;
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public void putProperty(String propertyName, ESValue propertyValue, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (propertyName.equals("length")) {
|
||||
int length = (int) (((ESPrimitive) propertyValue).doubleValue());
|
||||
if (length<0) {
|
||||
throw new EcmaScriptException("Invalid length value: " + propertyValue);
|
||||
}
|
||||
throw new EcmaScriptException("length of Java Arrays is immutable");
|
||||
} else {
|
||||
int index = -1; // indicates not a valid index value
|
||||
try {
|
||||
index = Integer.parseInt(propertyName); // should be uint
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (index<0) {
|
||||
throw new EcmaScriptException("Java Arrays accept only index properties");
|
||||
} else {
|
||||
putProperty(index, propertyValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public void putProperty(int index, ESValue propertyValue)
|
||||
throws EcmaScriptException {
|
||||
|
||||
int l = Array.getLength(javaArray);
|
||||
if (index>=l || index<0) {
|
||||
throw new EcmaScriptException("Index " + index + " outside of Java Arrays size of " + l);
|
||||
}
|
||||
Object obj = propertyValue.toJavaObject();
|
||||
try {
|
||||
Array.set(javaArray, index, obj);
|
||||
} catch (IllegalArgumentException e) {
|
||||
String type = "null";
|
||||
if (obj!=null) type = ESLoader.typeName(obj.getClass());
|
||||
throw new EcmaScriptException("Cannot store a " + type +
|
||||
" in the java array " + ESLoader.typeName(javaArray.getClass()));
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getPropertyInScope(String propertyName, ScopeChain previousScope, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (propertyName.equals("length")) {
|
||||
return new ESNumber(Array.getLength(javaArray));
|
||||
}
|
||||
// Do not examine the integer values...
|
||||
if (previousScope == null) {
|
||||
throw new EcmaScriptException("global variable '" + propertyName + "' does not have a value");
|
||||
} else {
|
||||
return previousScope.getValue(propertyName, hash);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (propertyName.equals("length")) {
|
||||
return new ESNumber(Array.getLength(javaArray));
|
||||
} else {
|
||||
int index = -1; // indicates not a valid index value
|
||||
try {
|
||||
index = Integer.parseInt(propertyName); // should be uint
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (index<0) {
|
||||
throw new EcmaScriptException("Java Arrays accept only index properties");
|
||||
} else {
|
||||
return getProperty(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getProperty(int index)
|
||||
throws EcmaScriptException {
|
||||
Object theElement = null;
|
||||
int l = Array.getLength(javaArray);
|
||||
if (index>=l || index<0) {
|
||||
throw new EcmaScriptException("Java Array index " + index + " is out of range " + l);
|
||||
}
|
||||
theElement = Array.get(javaArray,index);
|
||||
return ESLoader.normalizeValue(theElement, evaluator);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean hasProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (propertyName.equals("length")) {
|
||||
return true;
|
||||
} else {
|
||||
int index = -1; // indicates not a valid index value
|
||||
try {
|
||||
index = Integer.parseInt(propertyName); // should be uint
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (index<0) {
|
||||
return false;
|
||||
} else {
|
||||
return (index>=0) && (index<Array.getLength(javaArray));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
// Skip elements which were never set (are null), as Netscape
|
||||
public Enumeration getProperties() {
|
||||
return new Enumeration() {
|
||||
int nextIndex = 0;
|
||||
int length = Array.getLength(javaArray);
|
||||
public boolean hasMoreElements() {
|
||||
while ( (nextIndex<length) &&
|
||||
(Array.get(javaArray,nextIndex) == null))
|
||||
nextIndex++;
|
||||
return nextIndex<length;
|
||||
}
|
||||
public Object nextElement() {
|
||||
if (hasMoreElements()) {
|
||||
return new ESNumber(nextIndex++);
|
||||
} else {
|
||||
throw new java.util.NoSuchElementException();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all properties (including hidden ones), for the command
|
||||
* @listall of the interpreter.
|
||||
* <P>An ESArrayWrapper has no prototype, but it has the hidden property LENGTH.
|
||||
*
|
||||
* @return An enumeration of all properties (visible and hidden).
|
||||
*/
|
||||
public Enumeration getAllProperties() {
|
||||
return new Enumeration() {
|
||||
String [] specialProperties = getSpecialPropertyNames();
|
||||
int specialEnumerator = 0;
|
||||
Enumeration props = properties.keys(); // all of object properties
|
||||
String currentKey = null;
|
||||
int currentHash = 0;
|
||||
int nextIndex = 0;
|
||||
int length = Array.getLength(javaArray);
|
||||
public boolean hasMoreElements() {
|
||||
// OK if we already checked for a property and one exists
|
||||
if (currentKey != null) return true;
|
||||
// loop on index properties
|
||||
if (nextIndex<length) {
|
||||
while ( (nextIndex<length) &&
|
||||
(Array.get(javaArray,nextIndex) == null))
|
||||
// ignore null entries
|
||||
nextIndex++;
|
||||
if (nextIndex<length) {
|
||||
currentKey = Integer.toString(nextIndex);
|
||||
currentHash = currentKey.hashCode();
|
||||
nextIndex++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Loop on special properties first
|
||||
if (specialEnumerator < specialProperties.length) {
|
||||
currentKey = specialProperties[specialEnumerator];
|
||||
currentHash = currentKey.hashCode();
|
||||
specialEnumerator++;
|
||||
return true;
|
||||
}
|
||||
// loop on standard or prototype properties
|
||||
if (props.hasMoreElements()) {
|
||||
currentKey = (String) props.nextElement();
|
||||
currentHash = currentKey.hashCode();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Object nextElement() {
|
||||
if (hasMoreElements()) {
|
||||
String key = currentKey;
|
||||
currentKey = null;
|
||||
return key;
|
||||
} else {
|
||||
throw new java.util.NoSuchElementException();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String[] getSpecialPropertyNames() {
|
||||
String [] ns = {"length"};
|
||||
return ns;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean isHiddenProperty(String propertyName, int hash) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public void putHiddenProperty(String propertyName, ESValue propertyValue)
|
||||
throws EcmaScriptException {
|
||||
throw new ProgrammingError("Cannot put hidden property in " + this);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean deleteProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
return !hasProperty(propertyName, hash); // none can be deleted
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getDefaultValue(int hint)
|
||||
throws EcmaScriptException {
|
||||
if (hint == EStypeString) {
|
||||
return new ESString(javaArray.toString());
|
||||
} else {
|
||||
throw new EcmaScriptException ("No default value for " + this +
|
||||
" and hint " + hint);
|
||||
}
|
||||
}
|
||||
|
||||
public ESValue getDefaultValue()
|
||||
throws EcmaScriptException {
|
||||
return this.getDefaultValue(EStypeString);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public double doubleValue() {
|
||||
double d = Double.NaN;
|
||||
return d;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean booleanValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return (javaArray == null) ? "<?Array Wrapper to null?>" : "[object JavaArray]";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public Object toJavaObject() {
|
||||
return javaArray;
|
||||
}
|
||||
|
||||
//public String getTypeofString() {
|
||||
// return "JavaArray";
|
||||
//}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return "ES:[" + getESClassName() + ":" + javaArray.toString() + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
// ESBeans.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.EventListener;
|
||||
import java.util.zip.*;
|
||||
import java.beans.Beans;
|
||||
|
||||
/**
|
||||
* Implements the beans loader
|
||||
*/
|
||||
public class ESBeans extends ESLoader {
|
||||
|
||||
/**
|
||||
* Create the top level bean loader (object Bean)
|
||||
* @param evaluator the evaluator
|
||||
*/
|
||||
public ESBeans(Evaluator evaluator) {
|
||||
super(evaluator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new bean loader or package prefix
|
||||
* @param packageName The extension of the package name
|
||||
* @param previousPackage Represents the higher level package names
|
||||
* @param classLoader the class loader to use for this loader
|
||||
* @param evaluator the evaluator
|
||||
*/
|
||||
public ESBeans(String packageName,
|
||||
ESBeans previousPackage,
|
||||
ClassLoader classLoader,
|
||||
Evaluator evaluator) {
|
||||
super(packageName,previousPackage,classLoader,evaluator);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESObject getPrototype() {
|
||||
throw new ProgrammingError("Cannot get prototype of Beans");
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getESClassName() {
|
||||
return "Beans";
|
||||
}
|
||||
|
||||
// overrides
|
||||
// Getting a property dynamically creates a new Beans prefix object
|
||||
public ESValue getProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
ESValue value = (ESValue) properties.get(propertyName, hash);
|
||||
if (value == null) {
|
||||
String packageName = buildPrefix();
|
||||
value = new ESBeans(propertyName, this, classLoader, evaluator);
|
||||
properties.put(propertyName, hash, false, false, value); // Cache it for faster retrievial
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
// Establish a bean classloader
|
||||
// The parameter is the directory or jar to load from
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (previousPackage == null && classLoader == null) {
|
||||
// This is the Beans object
|
||||
if (arguments.length<1) {
|
||||
throw new EcmaScriptException("Missing class directory or jar file name");
|
||||
}
|
||||
String directoryOrJar = arguments[0].toString();
|
||||
ClassLoader classLoader =
|
||||
LocalClassLoader.makeLocalClassLoader(directoryOrJar);
|
||||
return new ESBeans(null, null, classLoader, evaluator);
|
||||
} else {
|
||||
throw new EcmaScriptException("Java class not found: '" + buildPrefix() +"'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
// instantiates a bean
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
|
||||
String beanName = buildPrefix();
|
||||
ESObject value = null;
|
||||
|
||||
if (beanName == null) {
|
||||
throw new EcmaScriptException("cannot create beans without a package name");
|
||||
}
|
||||
|
||||
try {
|
||||
Object bean = Beans.instantiate(classLoader, beanName);
|
||||
if (debugJavaAccess) {
|
||||
System.out.println(" ** Bean '" + beanName + "' created");
|
||||
}
|
||||
value = new ESWrapper(bean, evaluator, true);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new EcmaScriptException("Bean '" + beanName + "' not found: " + e);
|
||||
} catch (IOException e) {
|
||||
throw new EcmaScriptException("IOexception loading bean '" + beanName + "': " + e);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public String getTypeofString() {
|
||||
return "JavaBeans";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return "ES:<" + getESClassName() + ":'" + buildPrefix() + "'" +
|
||||
((classLoader==null) ? "" : (",@" + classLoader)) + ">";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
// ESBoolean.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.Evaluator;
|
||||
|
||||
/**
|
||||
* Boolean primitive value
|
||||
*/
|
||||
public final class ESBoolean extends ESPrimitive {
|
||||
|
||||
// There is only one true and one false value (allowing
|
||||
// efficient comparisons)
|
||||
private static ESBoolean trueValue = new ESBoolean();
|
||||
private static ESBoolean falseValue = new ESBoolean();
|
||||
|
||||
|
||||
private ESBoolean() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a boolean primitive (either true or false)
|
||||
* by returning the predefined (unique) true or false values
|
||||
*
|
||||
* @return either trueValue or falseValue
|
||||
*/
|
||||
static public ESBoolean makeBoolean(boolean value) {
|
||||
return value ? trueValue: falseValue;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return "ES:<" + (this==trueValue ? "true" : "false") + ">";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public int getTypeOf() {
|
||||
return EStypeBoolean;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getTypeofString() {
|
||||
return "boolean";
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return this==trueValue ? "true" : "false";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public double doubleValue() {
|
||||
return this==trueValue ? 1 : 0;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean booleanValue() {
|
||||
return this==trueValue;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue toESBoolean() {
|
||||
return this;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue toESObject(Evaluator evaluator) throws EcmaScriptException {
|
||||
BooleanPrototype theObject = null;
|
||||
ESObject bp = evaluator.getBooleanPrototype();
|
||||
theObject = new BooleanPrototype(bp, evaluator);
|
||||
theObject.value = this;
|
||||
return theObject;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public Object toJavaObject() {
|
||||
return new Boolean(this==trueValue);
|
||||
}
|
||||
|
||||
// overrides
|
||||
/**
|
||||
* returns true as we implement booleanValue without an evaluator.
|
||||
* @return true
|
||||
*/
|
||||
public boolean isBooleanValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,510 +0,0 @@
|
|||
// ESLoader.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
import FESI.jslib.JSFunction;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.EventListener;
|
||||
import java.util.zip.*;
|
||||
|
||||
/**
|
||||
* Implements the common functionality of package(object) and beans loaders
|
||||
*/
|
||||
public abstract class ESLoader extends ESObject {
|
||||
|
||||
// Debug support
|
||||
static protected boolean debugJavaAccess = false;
|
||||
public static void setDebugJavaAccess(boolean b) {
|
||||
debugJavaAccess = b;
|
||||
}
|
||||
static public boolean isDebugJavaAccess() {
|
||||
return debugJavaAccess;
|
||||
}
|
||||
|
||||
static protected boolean debugLoader = false;
|
||||
public static void setDebugLoader(boolean b) {
|
||||
debugLoader = b;
|
||||
}
|
||||
static public boolean isDebugLoader() {
|
||||
return debugLoader;
|
||||
}
|
||||
|
||||
// Incremental package name
|
||||
protected String packageName = null;
|
||||
protected ESLoader previousPackage = null;
|
||||
protected ClassLoader classLoader = null;
|
||||
|
||||
// the non compatible flag
|
||||
static private CompatibilityDescriptor nonCompatible =
|
||||
new CompatibilityDescriptor(-1, null, null);
|
||||
|
||||
|
||||
/**
|
||||
* To contruct the Bean or Package object
|
||||
*/
|
||||
public ESLoader(Evaluator evaluator) {
|
||||
super(null, evaluator);
|
||||
}
|
||||
|
||||
/**
|
||||
* To contruct the Bean or Package object with a specific class loader
|
||||
*/
|
||||
public ESLoader(Evaluator evaluator, ClassLoader loader) {
|
||||
super(null, evaluator);
|
||||
this.classLoader = loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* To construct a bean or package sub-object (with a specific
|
||||
* partial or complete package name
|
||||
* @param packageName The extension of the package name
|
||||
* @param previousPackage Represents the higher level package names
|
||||
* @param classLoader the class loader to use for this loader
|
||||
* @param evaluator the evaluator
|
||||
*/
|
||||
public ESLoader(String packageName,
|
||||
ESLoader previousPackage,
|
||||
ClassLoader classLoader,
|
||||
Evaluator evaluator) {
|
||||
super(null, evaluator);
|
||||
this.packageName = packageName;
|
||||
this.previousPackage = previousPackage;
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the prefix name of the package, concatenating
|
||||
* all upper level prefix separated by dots
|
||||
* @return prefix of the current package name
|
||||
*/
|
||||
protected String buildPrefix() {
|
||||
if (previousPackage == null) {
|
||||
return null;
|
||||
} else {
|
||||
String prefix = previousPackage.buildPrefix();
|
||||
if (prefix == null) {
|
||||
return packageName;
|
||||
} else {
|
||||
return prefix + "." + packageName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESObject getPrototype() {
|
||||
throw new ProgrammingError("Cannot get prototype of Package");
|
||||
}
|
||||
|
||||
// overrides
|
||||
public int getTypeOf() {
|
||||
return EStypeObject;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getPropertyInScope(String propertyName, ScopeChain previousScope, int hash)
|
||||
throws EcmaScriptException {
|
||||
throw new EcmaScriptException("A loader object ("+this+") should not be part of a with statement");
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public boolean hasProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
return true; // So it can be dereferenced by scopechain
|
||||
// and wont be created
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean isHiddenProperty(String propertyName, int hash) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public void putProperty(String propertyName, ESValue propertyValue, int hash)
|
||||
throws EcmaScriptException {
|
||||
return; // None can be put by the user
|
||||
}
|
||||
|
||||
// overrides
|
||||
public void putHiddenProperty(String propertyName, ESValue propertyValue)
|
||||
throws EcmaScriptException {
|
||||
throw new ProgrammingError("Cannot put hidden property in " + this);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean deleteProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
// all possible package name do potentialy exists and
|
||||
// cannot be deleted, as they are recreated at the first
|
||||
// reference.
|
||||
return false;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getDefaultValue(int hint)
|
||||
throws EcmaScriptException {
|
||||
if (hint == EStypeString) {
|
||||
return new ESString(this.toString());
|
||||
} else {
|
||||
throw new EcmaScriptException ("No default value for " + this +
|
||||
" and hint " + hint);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getDefaultValue()
|
||||
throws EcmaScriptException {
|
||||
return this.getDefaultValue(EStypeString);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
throw new EcmaScriptException("No constructor for loader object: " + this);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public double doubleValue() {
|
||||
double d = Double.NaN;
|
||||
return d;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean booleanValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return this.toDetailString();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Tools for the java wrapper objects
|
||||
//---------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns true if it is a primitive type
|
||||
* @param the Class to test
|
||||
* @return true if primitive type
|
||||
*/
|
||||
static boolean isBasicClass(Class cls) {
|
||||
return cls == String.class ||
|
||||
cls == Character.class ||
|
||||
cls == Byte.class ||
|
||||
cls == Short.class ||
|
||||
cls == Integer.class ||
|
||||
cls == Long.class ||
|
||||
cls == Float.class ||
|
||||
cls == Double.class ||
|
||||
cls == Boolean.class ||
|
||||
cls == Date.class;
|
||||
}
|
||||
|
||||
// With the Hop, all instances of Number (including java.math.BigXXX) are
|
||||
// treated as native numbers, so this is not called by normalizeValue.
|
||||
static boolean isPrimitiveNumberClass(Class cls) {
|
||||
return cls == Byte.class ||
|
||||
cls == Short.class ||
|
||||
cls == Integer.class ||
|
||||
cls == Long.class ||
|
||||
cls == Float.class ||
|
||||
cls == Double.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a java object to an EcmaScript value (primitive if possible)
|
||||
* @param obj the object to transform
|
||||
* @param evaluator the evaluator
|
||||
* @return the EcmaScript object
|
||||
* @exception EcmaScriptException the normalization failed
|
||||
*/
|
||||
public static ESValue normalizeValue(Object obj, Evaluator evaluator)
|
||||
throws EcmaScriptException {
|
||||
if (obj == null) {
|
||||
return ESNull.theNull;
|
||||
} else if (obj instanceof String) {
|
||||
return new ESString((String) obj);
|
||||
} else if (obj instanceof Number) {
|
||||
return new ESNumber(((Number) obj).doubleValue());
|
||||
} else if (obj instanceof Boolean) {
|
||||
return ESBoolean.makeBoolean(((Boolean) obj).booleanValue());
|
||||
} else if (obj instanceof Character) {
|
||||
return new ESNumber(((Character) obj).charValue());
|
||||
} else if (obj instanceof JSFunction) {
|
||||
return JSWrapper.wrapJSFunction(evaluator, (JSFunction) obj);
|
||||
} else if (obj instanceof JSWrapper) {
|
||||
return ((JSWrapper)obj).getESObject();
|
||||
} else if (obj instanceof Date) {
|
||||
return new DatePrototype(evaluator, (Date) obj);
|
||||
} else if (obj instanceof ESWrapper) {
|
||||
return (ESWrapper) obj; // A wrapper received externally
|
||||
} else if (obj instanceof ESArrayWrapper) {
|
||||
return (ESArrayWrapper) obj; // An array wrapper received externally
|
||||
} else if (obj.getClass().isArray()) {
|
||||
return new ESArrayWrapper(obj, evaluator);
|
||||
} // else if (obj instanceof helma.framework.IPathElement) { // Hannes Wallnoefer, 13. Aug 2001
|
||||
// return evaluator.engine.getElementWrapper ((helma.framework.IPathElement) obj);
|
||||
// }
|
||||
// return new ESWrapper(obj, evaluator);
|
||||
return evaluator.engine.getObjectWrapper (obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a java object to an EcmaScript object (not a primitive)
|
||||
* @param obj the object to transform
|
||||
* @param evaluator the evaluator
|
||||
* @return the EcmaScript object
|
||||
* @exception EcmaScriptException the normalization failed
|
||||
*/
|
||||
public static ESObject normalizeObject(Object obj, Evaluator evaluator)
|
||||
throws EcmaScriptException {
|
||||
ESValue value = normalizeValue(obj, evaluator);
|
||||
return (ESObject) value.toESObject(evaluator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the primitive class types to their corresponding
|
||||
* class types. Must be called for primitive classes only.
|
||||
*
|
||||
* @param target The primitive class to convert
|
||||
* @return The converted class
|
||||
*/
|
||||
private static Class convertPrimitive(Class target) {
|
||||
if (target==java.lang.Boolean.TYPE) {
|
||||
target=Boolean.class;
|
||||
} else if (target==java.lang.Character.TYPE) {
|
||||
target=Character.class;
|
||||
} else if (target==java.lang.Byte.TYPE) {
|
||||
target=Byte.class;
|
||||
} else if (target==java.lang.Short.TYPE) {
|
||||
target=Short.class;
|
||||
} else if (target==java.lang.Integer.TYPE) {
|
||||
target=Integer.class;
|
||||
} else if (target==java.lang.Long.TYPE) {
|
||||
target=Long.class;
|
||||
} else if (target==java.lang.Float.TYPE) {
|
||||
target=Float.class;
|
||||
} else if (target==java.lang.Double.TYPE) {
|
||||
target=Double.class;
|
||||
} else {
|
||||
throw new ProgrammingError("Not a recognized primitive type: " + target);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a number correlated to the wideness of the class in some lousy sense
|
||||
*/
|
||||
static private int getNumberSize(Class cls) {
|
||||
|
||||
if (cls == Byte.class) {
|
||||
return 1;
|
||||
} else if (cls == Character.class) {
|
||||
return 2;
|
||||
} else if (cls == Short.class) { // short and char widen in the same way
|
||||
return 2;
|
||||
} else if (cls == Integer.class) {
|
||||
return 3;
|
||||
} else if (cls == Long.class) {
|
||||
return 4;
|
||||
} else if (cls == Float.class) {
|
||||
return 5;
|
||||
} else if (cls == Double.class) {
|
||||
return 6;
|
||||
} else {
|
||||
throw new ProgrammingError("Unexpected number class");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that each object in the paremeter array can be converted
|
||||
* to the type specified by the target array and convert them if needed.
|
||||
* <P>Even if the parameters are compatible with an EcmaScript value,
|
||||
|
||||
* some may have to be converted to an intermediate type. For example
|
||||
* an EcmaScript string of 1 character long is compatible with a Java
|
||||
* Character, but some conversion is needed. Arrays need a similar
|
||||
* special processing.
|
||||
* <P> The parameters have been converted to java Objects by the routine
|
||||
* toJavaObject. Wrapped objects (java objects given to an EcmaScript
|
||||
* routine and given back as parameters) have been unwrapped, so they
|
||||
* are their original object again (including arrays), we do therefore
|
||||
* not have ESWrapped objects as parameters.
|
||||
* ESObjects have been wrapped in a JSObject, including Array objects.
|
||||
* The handling of array is more delicate as they
|
||||
* could not be converted to a cannonical form - we must know the element
|
||||
* type to understand if they are convertible.
|
||||
* <P> The target classes which are primitive are converted to their
|
||||
* object counterpart, as only object can be given as parameter and the
|
||||
* invoke mechanism will convert them back to primitive if needed.
|
||||
* <P>All the conversion needed are described in the returned
|
||||
* compatibilityDescriptor and will only be applied for the selected
|
||||
* routine.
|
||||
* <P>The distance is a metric on how "far" a parameter list is
|
||||
* from the immediate value (used currntly only for simple value
|
||||
* widening). It allows to select the routine having the nearest
|
||||
* parameter list. This is not totally full proof and multiple routine
|
||||
* can have the same distance (including 0, because of the conversion
|
||||
* of primitive type to the corresponding objects).
|
||||
* <P>The tracing must allow to find the logic of the conversion.
|
||||
* @param target The class objects of the target routine
|
||||
* @param parms The EcmaScript objects converted to Java objects (IN/OUT)
|
||||
* @return a compatibility descriptor.
|
||||
*/
|
||||
static CompatibilityDescriptor areParametersCompatible(Class target[], Object params[]) {
|
||||
int n = target.length;
|
||||
if (n!=params.length) return nonCompatible; // Ensure we have the same number
|
||||
boolean [] convertToChar = null; // flag to indicate if conversion to char is needed
|
||||
Object [] convertedArrays = null; // Converted array if any needed
|
||||
int distance = 0; // For perfect match, something added for widening
|
||||
for (int i=0; i<n; i++) {
|
||||
boolean accepted = false;
|
||||
Class targetClass = target[i];
|
||||
Class sourceClass = null;
|
||||
String debugInfo = " not accepted";
|
||||
if (params[i] == null) {
|
||||
// A null parameter is of type Object, so we check
|
||||
// that whatever is the target class be an object
|
||||
if (targetClass.isPrimitive()) { // or: Object.class.isAssignableFrom(targetClass)
|
||||
accepted = false;
|
||||
debugInfo = " rejected (null cannot be assigned to primitive)";
|
||||
|
||||
} else {
|
||||
accepted = true;
|
||||
debugInfo = " accepted (null to Object)";
|
||||
}
|
||||
} else {
|
||||
// We consider all primitive types as they object
|
||||
// equivallent, as the parameter can only be done as
|
||||
// object anyhow. Invoke will convert back if needed.
|
||||
if (targetClass.isPrimitive()) {
|
||||
// To accept long by Long, etc... - must be done after test of assigning null to object
|
||||
targetClass = convertPrimitive(targetClass);
|
||||
}
|
||||
// The simplest case is direct object compatibility
|
||||
sourceClass = params[i].getClass();
|
||||
accepted = targetClass.isAssignableFrom(sourceClass);
|
||||
if (targetClass != sourceClass) {
|
||||
if (targetClass == Object.class)
|
||||
distance += 2;
|
||||
else
|
||||
distance += 1;
|
||||
}
|
||||
debugInfo = " accepted (subclassing)";
|
||||
|
||||
if (!accepted) {
|
||||
// If we do not have direct object compatibility, we check various
|
||||
// allowed conversions.
|
||||
|
||||
// Handle number and number widening
|
||||
if ((isPrimitiveNumberClass(sourceClass) ||
|
||||
sourceClass == Character.class)
|
||||
&& isPrimitiveNumberClass(targetClass)) {
|
||||
// Can be widened ?
|
||||
int targetSize = getNumberSize(targetClass);
|
||||
int sourceSize = getNumberSize(sourceClass);
|
||||
if (targetSize>sourceSize) {
|
||||
accepted = true; // if == already accepted because same class
|
||||
// or must be rejected (because char != short)
|
||||
distance += Math.abs(targetSize-sourceSize);
|
||||
debugInfo = " accepted (number widening: " + distance + ")";
|
||||
} else {
|
||||
debugInfo = " rejected (not widening numbers)";
|
||||
}
|
||||
// Handle String of length 1 as a Char, which can be converted to a number
|
||||
} else if (targetClass == Character.class
|
||||
&& params[i] instanceof String) {
|
||||
if (((String) params[i]).length()==1) {
|
||||
accepted = true; // will require conversion of parameter
|
||||
if (convertToChar == null) {
|
||||
convertToChar = new boolean[n];
|
||||
}
|
||||
convertToChar[i] = true;
|
||||
distance += 1;
|
||||
debugInfo = " accepted (String(1) as Character)";
|
||||
} else {
|
||||
debugInfo = " rejected (String not of length 1)";
|
||||
}
|
||||
|
||||
// Handle array conversion if not from a native java array
|
||||
} else if (targetClass.isArray()) {
|
||||
if (params[i] instanceof JSWrapper) {
|
||||
ESObject esArray = ((JSWrapper) params[i]).getESObject();
|
||||
if (esArray instanceof ArrayPrototype) {
|
||||
Object array = null;
|
||||
try {
|
||||
// We convert to the orginal class (possibly a primitive type)
|
||||
array = ((ArrayPrototype) esArray).toJavaArray(targetClass.getComponentType());
|
||||
accepted = true;
|
||||
debugInfo = " accepted (array converted)";
|
||||
if (convertedArrays == null) {
|
||||
convertedArrays = new Object[n];
|
||||
}
|
||||
convertedArrays[i] = array; // save it for replacement at end
|
||||
} catch (EcmaScriptException e) {
|
||||
// ignore
|
||||
debugInfo = " rejected ("+e.getMessage()+")";
|
||||
}
|
||||
} else {
|
||||
debugInfo = " rejected (EcmaScript object is not an array)";
|
||||
}
|
||||
} else {
|
||||
debugInfo = " rejected (only same native array or EcmaScript Array can be assigned to array)";
|
||||
}
|
||||
|
||||
} else {
|
||||
debugInfo = " rejected (incompatible types)";
|
||||
}
|
||||
} // if ! acccepted
|
||||
} // if ! null
|
||||
|
||||
if (debugJavaAccess) System.out.println (" Assign " + sourceClass +
|
||||
" to " + target[i] +
|
||||
debugInfo);
|
||||
if (!accepted) return nonCompatible;
|
||||
|
||||
} // for
|
||||
|
||||
// Compatible, return appropriate descriptor for future
|
||||
// processing of conversion of the "nearest" method
|
||||
return new CompatibilityDescriptor(distance,convertToChar,convertedArrays);
|
||||
}
|
||||
|
||||
// overrides
|
||||
static public String typeName(Class t) {
|
||||
String brackets = "";
|
||||
while (t.isArray()) {
|
||||
brackets += "[]";
|
||||
t = t.getComponentType();
|
||||
}
|
||||
return t.getName() + brackets;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
// ESNull.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
/**
|
||||
* Implements the NULL EcmaScript primitive value
|
||||
* <P> There is only one value of this type which is referenced
|
||||
* by ESNull.theNull. In general it is not identical for a routine
|
||||
* to return ESNull, ESUndefined or the java null. They all have
|
||||
* different purposes.
|
||||
*/
|
||||
public final class ESNull extends ESPrimitive {
|
||||
|
||||
/**
|
||||
* the READ-ONLY null value
|
||||
*/
|
||||
public static ESNull theNull = new ESNull();
|
||||
|
||||
private ESNull() {
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return "ES:<null>";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public int getTypeOf() {
|
||||
return EStypeNull;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return "null";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getTypeofString() {
|
||||
return "object";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public double doubleValue() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean booleanValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public Object toJavaObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
// ESNumber.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.Evaluator;
|
||||
|
||||
/**
|
||||
* Implements the number primitive value as a double
|
||||
*/
|
||||
|
||||
public final class ESNumber extends ESPrimitive {
|
||||
|
||||
// The value
|
||||
private double value;
|
||||
|
||||
/**
|
||||
* Create a new double with a specific value
|
||||
*
|
||||
* @param value The (immutable) value
|
||||
*/
|
||||
public ESNumber(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public int getTypeOf() {
|
||||
return EStypeNumber;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getTypeofString() {
|
||||
return "number";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean isNumberValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public double doubleValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean booleanValue() {
|
||||
return !(Double.isNaN(value) || value==0.0);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
long intValue = (long) value;
|
||||
if (((double) intValue) == value) {
|
||||
return Long.toString(intValue);
|
||||
} else {
|
||||
return Double.toString(value);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue toESObject(Evaluator evaluator) throws EcmaScriptException {
|
||||
NumberPrototype theObject = null;
|
||||
ESObject np = evaluator.getNumberPrototype();
|
||||
theObject = new NumberPrototype(np, evaluator);
|
||||
theObject.value = this;
|
||||
return theObject;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue toESNumber() {
|
||||
return this;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public Object toJavaObject() {
|
||||
long longValue = (long) value;
|
||||
Object o = null;
|
||||
if (((double) longValue) == value) {
|
||||
if (((byte) longValue) == longValue) {
|
||||
o = new Byte((byte) longValue);
|
||||
} else if (((short) longValue) == longValue) {
|
||||
o = new Short((short) longValue);
|
||||
} else if (((int) longValue) == longValue) {
|
||||
o = new Integer((int) longValue);
|
||||
} else {
|
||||
o = new Long(longValue);
|
||||
}
|
||||
} else {
|
||||
o= new Double(value);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return "ES:#'" + Double.toString(value)+"'";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,785 +0,0 @@
|
|||
// ESObject.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.Evaluator;
|
||||
import FESI.Interpreter.FesiHashtable;
|
||||
import FESI.Interpreter.ScopeChain;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
public abstract class ESObject extends ESValue {
|
||||
|
||||
/** Contains the properties of this object */
|
||||
protected FesiHashtable properties;
|
||||
|
||||
/** The evaluator owning this object */
|
||||
protected Evaluator evaluator;
|
||||
|
||||
/**
|
||||
* The prototype of this object ([[prototype]] in the standard,
|
||||
* not the "prototype" property of functions!)
|
||||
*/
|
||||
private ESObject prototype = null;
|
||||
|
||||
// Prepare common names and their hash value
|
||||
static private final String TOSTRINGstring = ("toString").intern();
|
||||
static private final int TOSTRINGhash = TOSTRINGstring.hashCode();
|
||||
static private final String VALUEOFstring = ("valueOf").intern();
|
||||
static private final int VALUEOFhash = VALUEOFstring.hashCode();
|
||||
|
||||
|
||||
/**
|
||||
* Create an object with a specific prototype (which may be null)
|
||||
* in the context of a specific evaluator (which may not be null)
|
||||
* Uses the default hashTable size.
|
||||
*
|
||||
* @param prototype The prototype ESObject - may be null
|
||||
* @param evaluator The evaluator - must not be null
|
||||
*/
|
||||
protected ESObject(ESObject prototype, Evaluator evaluator) {
|
||||
this.prototype = prototype;
|
||||
this.properties = new FesiHashtable();
|
||||
this.evaluator = evaluator; // It will crash somewhere if null...
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create an object with a specific prototype (which may be null)
|
||||
* in the context of a specific evaluator (which may not be null)
|
||||
* Uses the specified hashTable size, which should be a prime.
|
||||
* size is usefull for very small (arguments) or very large objects.
|
||||
*
|
||||
* @param prototype The prototype ESObject - may be null
|
||||
* @param evaluator The evaluator - must not be null
|
||||
*/
|
||||
protected ESObject(ESObject prototype, Evaluator evaluator, int initialSize) {
|
||||
this.prototype = prototype;
|
||||
this.properties = new FesiHashtable(initialSize);
|
||||
this.evaluator = evaluator; // It will crash somewhere if null...
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the evaluator for this object
|
||||
*
|
||||
* @return the evaluator
|
||||
*/
|
||||
public final Evaluator getEvaluator() {
|
||||
return evaluator;
|
||||
}
|
||||
|
||||
/**
|
||||
* All objects and thir subclasses are non primitive
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public final boolean isPrimitive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements the [[prototype]] property (see 8.6.2)
|
||||
*
|
||||
* @return The prototype object or null
|
||||
*/
|
||||
public ESObject getPrototype() {
|
||||
return prototype;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allow the prototype to be set, added 2001-04-05 by Hannes Wallnöfer
|
||||
*
|
||||
* @param prototype The new prototype object
|
||||
*/
|
||||
public void setPrototype(ESObject prototype) {
|
||||
this.prototype = prototype;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of the class of objects ([[class]]), as used in the default toString
|
||||
* method of objects (15.2.4.2)
|
||||
*
|
||||
* @return the [[Class]] property of this object
|
||||
*/
|
||||
public String getESClassName() {
|
||||
return "Object";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a code indicating the type of the object for the implementation
|
||||
* of the "==" operator.
|
||||
*
|
||||
* @return A type code
|
||||
*/
|
||||
public int getTypeOf() {
|
||||
return EStypeObject;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Either return the property value of the specified property
|
||||
* in the current object, or lookup the next object in the scope chain
|
||||
* if there is one. If there is nones, generate an error message.
|
||||
* <P>This routine must be overriden by subclass which change the
|
||||
* implementation of getProperty.
|
||||
*
|
||||
* @param propertyName The property to look for
|
||||
* @param previousScope The previous scope or null
|
||||
* @param hash The hashCode of propertyName
|
||||
* @return The value of the specified variable
|
||||
* @exception EcmaScriptException if not found in any scope
|
||||
*/
|
||||
public ESValue getPropertyInScope(String propertyName,
|
||||
ScopeChain previousScope,
|
||||
int hash)
|
||||
throws EcmaScriptException {
|
||||
ESValue value = (ESValue) properties.get(propertyName, hash);
|
||||
if (value == null) {
|
||||
if (previousScope == null) {
|
||||
// Return null for undefined global variables.
|
||||
// throw new EcmaScriptException("global variable '" + propertyName + "' does not have a value");
|
||||
value = ESNull.theNull;
|
||||
} else {
|
||||
value = previousScope.getValue(propertyName, hash);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the property by name (see 8.6.2.1) propagating to
|
||||
* the prototype if required
|
||||
*
|
||||
* @param propertyName The string naming the property
|
||||
* @param hash The hashCode of propertyName
|
||||
* @return The property or <em>undefined</em>
|
||||
* @exception EcmaScriptException Error in host objects ?
|
||||
*/
|
||||
public ESValue getProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
ESValue value = (ESValue) properties.get(propertyName, hash);
|
||||
if (value == null) {
|
||||
if (prototype == null) {
|
||||
value = ESUndefined.theUndefined;
|
||||
} else {
|
||||
value = prototype.getProperty(propertyName, hash);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the property by index value. By default the index is
|
||||
* converted to a string, but this can be optimized for arrays.
|
||||
* <P>This is not the same as the indexed properties of the first
|
||||
* version of JavaScript and does not allow to access named
|
||||
* properties other than the property using the integer string
|
||||
* representation as a name.
|
||||
*
|
||||
* @param index The property name as an integer.
|
||||
* @return The property or <em>undefined</em>
|
||||
* @exception EcmaScriptException Error in host objects ?
|
||||
*/
|
||||
public ESValue getProperty(int index)
|
||||
throws EcmaScriptException {
|
||||
String iString = Integer.toString(index);
|
||||
return getProperty(iString, iString.hashCode());
|
||||
}
|
||||
|
||||
public boolean hasProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
boolean found = properties.containsKey(propertyName, hash);
|
||||
if (!found && prototype != null) {
|
||||
found = prototype.hasProperty(propertyName, hash);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
public boolean isHiddenProperty(String propertyName, int hash) {
|
||||
return properties.isHidden(propertyName, hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates that the getProperties return an enumerator to the
|
||||
* index rather rather than to the value index (see ESWrapper).
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public boolean isDirectEnumerator() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an enumerator for the key elements of this object,
|
||||
* that is all is enumerable properties and the (non hidden)
|
||||
* ones of its prototype, etc... As used for the for in
|
||||
* statement.
|
||||
*
|
||||
* @return the enumerator
|
||||
*/
|
||||
public Enumeration getProperties() {
|
||||
return new Enumeration() {
|
||||
Enumeration props = properties.keys();
|
||||
String currentKey = null;
|
||||
int currentHash = 0;
|
||||
boolean inside = false;
|
||||
public boolean hasMoreElements() {
|
||||
if (currentKey != null) return true;
|
||||
while (props.hasMoreElements()) {
|
||||
currentKey = (String) props.nextElement();
|
||||
currentHash = currentKey.hashCode();
|
||||
if (inside) {
|
||||
if (properties.containsKey(currentKey, currentHash)) continue;
|
||||
} else {
|
||||
if (isHiddenProperty(currentKey, currentHash)) continue;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (!inside && prototype != null) {
|
||||
inside = true;
|
||||
props = prototype.getProperties();
|
||||
while (props.hasMoreElements()) {
|
||||
currentKey = (String) props.nextElement();
|
||||
currentHash = currentKey.hashCode();
|
||||
if (properties.containsKey(currentKey, currentHash)) continue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Object nextElement() {
|
||||
if (hasMoreElements()) {
|
||||
String key = currentKey;
|
||||
currentKey = null;
|
||||
return key;
|
||||
} else {
|
||||
throw new java.util.NoSuchElementException();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all properties (including hidden ones), for the command
|
||||
* @listall of the interpreter. Include the visible properties of the
|
||||
* prototype (that is the one added by the user) but not the
|
||||
* hidden ones of the prototype (otherwise this would list
|
||||
* all functions for any object).
|
||||
*
|
||||
* @return An enumeration of all properties (visible and hidden).
|
||||
*/
|
||||
public Enumeration getAllProperties() {
|
||||
return new Enumeration() {
|
||||
String [] specialProperties = getSpecialPropertyNames();
|
||||
int specialEnumerator = 0;
|
||||
Enumeration props = properties.keys(); // all of object properties
|
||||
String currentKey = null;
|
||||
int currentHash = 0;
|
||||
boolean inside = false; // true when examing prototypes properties
|
||||
public boolean hasMoreElements() {
|
||||
// OK if we already checked for a property and one exists
|
||||
if (currentKey != null) return true;
|
||||
// Loop on special properties first
|
||||
if (specialEnumerator < specialProperties.length) {
|
||||
currentKey = specialProperties[specialEnumerator];
|
||||
currentHash = currentKey.hashCode();
|
||||
specialEnumerator++;
|
||||
return true;
|
||||
}
|
||||
// loop on standard or prototype properties
|
||||
while (props.hasMoreElements()) {
|
||||
currentKey = (String) props.nextElement();
|
||||
currentHash = currentKey.hashCode();
|
||||
if (inside) {
|
||||
if (properties.containsKey(currentKey, currentHash)) continue;
|
||||
// SHOULD CHECK IF NOT IN SPECIAL
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// If prototype properties have not yet been examined, look for them
|
||||
if (!inside && prototype != null) {
|
||||
inside = true;
|
||||
props = prototype.getProperties();
|
||||
while (props.hasMoreElements()) {
|
||||
currentKey = (String) props.nextElement();
|
||||
currentHash = currentKey.hashCode();
|
||||
if (properties.containsKey(currentKey, currentHash)) continue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Object nextElement() {
|
||||
if (hasMoreElements()) {
|
||||
String key = currentKey;
|
||||
currentKey = null;
|
||||
return key;
|
||||
} else {
|
||||
throw new java.util.NoSuchElementException();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put the property by name (see 8.6.2.2), ignoring if
|
||||
* read only (integrate functionality of canPut) and
|
||||
* creating it if needed and possible.
|
||||
* <P>The routine implement the functionality of the canPut attribute.
|
||||
*
|
||||
* @param propertyName The string naming the property
|
||||
* @param propertyValue The value to put
|
||||
* @exception EcmaScriptException Error in host objects ?
|
||||
*/
|
||||
public void putProperty(String propertyName,
|
||||
ESValue propertyValue,
|
||||
int hash)
|
||||
throws EcmaScriptException {
|
||||
properties.put(propertyName, hash, false, false, propertyValue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Put the property by index value. By default the index is
|
||||
* converted to a string, but this can be optimized for arrays.
|
||||
* <P>This is not the same as the indexed properties of the first
|
||||
* version of JavaScript and does not allow to access named
|
||||
* properties other than the property using the integer string
|
||||
* representation as a name.
|
||||
*
|
||||
* @param index The property name as an integer.
|
||||
* @param propertyValue The value to put
|
||||
* @exception EcmaScriptException Error in host objects ?
|
||||
*/
|
||||
public void putProperty(int index, ESValue propertyValue)
|
||||
throws EcmaScriptException {
|
||||
String iString = Integer.toString(index);
|
||||
putProperty(iString, propertyValue, iString.hashCode());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Put the property as hidden. This is mostly used by initialization
|
||||
* code, so a hash value is computed localy and the string is interned.
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @param propertyValue Its value
|
||||
* @exception EcmaScriptException Not used
|
||||
*/
|
||||
public void putHiddenProperty(String propertyName,
|
||||
ESValue propertyValue)
|
||||
throws EcmaScriptException {
|
||||
propertyName = propertyName.intern();
|
||||
int hash = propertyName.hashCode();
|
||||
properties.put(propertyName, hash, true, false, propertyValue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements the [[delete]] function (8.6.2.5), only
|
||||
* called by the DELETE operator. Should return true if
|
||||
* the propery does not exist any more (or did not exist
|
||||
* at all) after the return.
|
||||
* <P>This routine must implement the DontDelete attribue too.
|
||||
*
|
||||
* @param propertyName The name of the property
|
||||
* @return true if the property is not present anymore
|
||||
* @exception EcmaScriptException Not used
|
||||
*/
|
||||
public boolean deleteProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
properties.remove(propertyName, hash);
|
||||
return true; // either it did not exist or was deleted !
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements [[DefaultValue]] with hint
|
||||
*
|
||||
* @param hint A type hint (only string or number)
|
||||
|
||||
* @exception EcmaScriptException Propagated or bad hint
|
||||
* @return the default value of this object
|
||||
*/
|
||||
public ESValue getDefaultValue(int hint)
|
||||
throws EcmaScriptException {
|
||||
ESValue theResult = null;
|
||||
ESValue theFunction = null;
|
||||
|
||||
if (hint == ESValue.EStypeString) {
|
||||
theFunction = this.getProperty(TOSTRINGstring,TOSTRINGhash);
|
||||
if (theFunction instanceof ESObject) {
|
||||
theResult = theFunction.callFunction(this, new ESValue[0]);
|
||||
if (theResult.isPrimitive()) {
|
||||
return theResult;
|
||||
}
|
||||
}
|
||||
theFunction = this.getProperty(VALUEOFstring,VALUEOFhash);
|
||||
if (theFunction instanceof ESObject) {
|
||||
theResult = theFunction.callFunction(this, new ESValue[0]);
|
||||
if (theResult.isPrimitive()) {
|
||||
return theResult;
|
||||
}
|
||||
}
|
||||
// Throw errror on super to avoid evaluating this with as a string,
|
||||
// as this is exactly what we cannot do.
|
||||
throw new EcmaScriptException ("No default value for " + super.toString() + " and hint " + hint);
|
||||
} else if (hint == ESValue.EStypeNumber) {
|
||||
theFunction = this.getProperty(VALUEOFstring,VALUEOFhash);
|
||||
if (theFunction instanceof ESObject) {
|
||||
theResult = theFunction.callFunction(this, new ESValue[0]);
|
||||
if (theResult.isPrimitive()) {
|
||||
return theResult;
|
||||
}
|
||||
}
|
||||
theFunction = this.getProperty(TOSTRINGstring,TOSTRINGhash);
|
||||
if (theFunction instanceof ESObject) {
|
||||
theResult = theFunction.callFunction(this, new ESValue[0]);
|
||||
if (theResult.isPrimitive()) {
|
||||
return theResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new EcmaScriptException ("No default value for " + this + " and hint " + hint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements [[DefaultValue]] with no hint
|
||||
* <P> The default is different for dates
|
||||
*
|
||||
* @exception EcmaScriptException Propagated
|
||||
* @return the default value of this object
|
||||
*/
|
||||
public ESValue getDefaultValue()
|
||||
throws EcmaScriptException {
|
||||
|
||||
return this.getDefaultValue(EStypeNumber);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call a function object - not implemented for default objecr
|
||||
*
|
||||
* @param thisObject The current object
|
||||
* @param arguments The arguments to the function
|
||||
* @return The calculated value
|
||||
* @exception EcmaScriptException thrown because the function is not implemented
|
||||
*/
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
throw new EcmaScriptException("No function defined on: " + this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A construct as thisObject.functionName() was detected,
|
||||
* The functionName is looked up, then a call is made.
|
||||
* This avoid creating a dummy function object when one does not
|
||||
* exists, like for the ESWrapper objects (where functions are
|
||||
* really java methods).
|
||||
* <P>Only method which do not use the standard EcmaScript
|
||||
* function evaluation mechanism need to override this method.
|
||||
*
|
||||
* @param evaluator The evaluator
|
||||
* @param target The original target (for recursive calls)
|
||||
* @param functionName The name of the function property
|
||||
* @param arguments The arguments of the function
|
||||
* @return The result of calling the function
|
||||
* @exception EcmaScriptException Function not defined
|
||||
* @exception NoSuchMethodException Method not found
|
||||
*/
|
||||
public ESValue doIndirectCall(Evaluator evaluator,
|
||||
ESObject target,
|
||||
String functionName,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException, NoSuchMethodException {
|
||||
ESValue theFunction = (ESValue) properties.get(functionName, functionName.hashCode());
|
||||
if (theFunction == null) {
|
||||
if (prototype == null) {
|
||||
throw new EcmaScriptException("The function '"+functionName+
|
||||
"' is not defined for object '"+target.toString()+"'");
|
||||
} else {
|
||||
return prototype.doIndirectCall(evaluator, target, functionName, arguments);
|
||||
}
|
||||
} else {
|
||||
return theFunction.callFunction(target,arguments);
|
||||
}
|
||||
}
|
||||
|
||||
// A routine which may return a function as the value of a builtin
|
||||
// property must override this function
|
||||
public ESValue doIndirectCallInScope(Evaluator evaluator,
|
||||
ScopeChain previousScope,
|
||||
ESObject thisObject,
|
||||
String functionName,
|
||||
int hash,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESValue theFunction = (ESValue) properties.get(functionName, hash);
|
||||
if (theFunction == null) {
|
||||
if (previousScope == null) {
|
||||
throw new EcmaScriptException("no global function named '" + functionName + "'");
|
||||
} else {
|
||||
return previousScope.doIndirectCall(evaluator, thisObject, functionName, hash, arguments);
|
||||
}
|
||||
}
|
||||
return theFunction.callFunction(thisObject,arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the constructor - not implemented on default object
|
||||
*
|
||||
* @param thisObject The current object
|
||||
* @param arguments Arguments to new
|
||||
* @return The created obbjecr
|
||||
* @exception EcmaScriptException thrown because this function is not implemented
|
||||
*/
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
throw new EcmaScriptException("No constructor defined on: " + this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return a double value for this object if possible
|
||||
*
|
||||
* @return The double value
|
||||
* @exception EcmaScriptException If not a suitable primitive
|
||||
*/
|
||||
public double doubleValue() throws EcmaScriptException {
|
||||
ESValue value = ESUndefined.theUndefined;
|
||||
double d = Double.NaN;
|
||||
try {
|
||||
value = toESPrimitive(EStypeNumber);
|
||||
d = value.doubleValue();
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new ProgrammingError(e.getMessage());
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the boolean value of this object if possible
|
||||
*
|
||||
* @return the boolean value
|
||||
* @exception EcmaScriptException If not a suitable primitive
|
||||
*/
|
||||
public boolean booleanValue() throws EcmaScriptException {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
ESValue value = ESUndefined.theUndefined;
|
||||
String string = null;
|
||||
try {
|
||||
value = toESPrimitive(EStypeString);
|
||||
} catch (EcmaScriptException e) {
|
||||
return this.toDetailString();
|
||||
}
|
||||
string = value.toString();
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert to an object
|
||||
*
|
||||
* @param evaluator The evaluator
|
||||
* @return This
|
||||
* @exception EcmaScriptException not thrown
|
||||
*/
|
||||
public final ESValue toESObject(Evaluator evaluator) throws EcmaScriptException {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert to a primitive
|
||||
*
|
||||
* @param preferedType For string or number
|
||||
* @return The primitive value
|
||||
* @exception EcmaScriptException If no suitable default value
|
||||
*/
|
||||
public final ESValue toESPrimitive(int preferedType) throws EcmaScriptException {
|
||||
return getDefaultValue(preferedType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert to a primitive
|
||||
*
|
||||
* @return The primitive value
|
||||
* @exception EcmaScriptException If no suitable default value
|
||||
*/
|
||||
public final ESValue toESPrimitive() throws EcmaScriptException {
|
||||
return getDefaultValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Java object which is the object to pass to Java routines
|
||||
* called by FESI. By default wrap the ESObject in a wrapper object,
|
||||
* used by the jslib. Overriden by subclass if a better type can be found.
|
||||
*
|
||||
* @return a wrapper object over this ESObject.
|
||||
*/
|
||||
public Object toJavaObject() {
|
||||
return new JSWrapper(this, evaluator);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of the type of the object for the typeof operator
|
||||
*
|
||||
* @return The name of the type as a String
|
||||
*/
|
||||
public String getTypeofString() {
|
||||
return "object";
|
||||
}
|
||||
|
||||
public String toDetailString() {
|
||||
return "ES:[" + getESClassName() + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true to indicate that this value is composite.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public boolean isComposite() {return true; }
|
||||
|
||||
|
||||
/**
|
||||
* Return the list of proprties which are not listed by getAll,
|
||||
* that is all special properties handled directly by getProperty,
|
||||
* which are not in the property hash table (they are considered
|
||||
* hidden)
|
||||
* Must be overriden by a subclass which overrides getProperty!
|
||||
*
|
||||
* return The array of special property names
|
||||
*/
|
||||
public String[] getSpecialPropertyNames() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an enumeration of the description of various aspects
|
||||
* of the object, including all properties.
|
||||
*/
|
||||
public Enumeration getAllDescriptions() {
|
||||
return new Enumeration() {
|
||||
String [] specialProperties = getSpecialPropertyNames();
|
||||
int specialEnumerator = 0;
|
||||
Enumeration props = properties.keys();
|
||||
String currentKey = null;
|
||||
int currentHash = 0;
|
||||
boolean inside = false;
|
||||
boolean inSpecial = true;
|
||||
public boolean hasMoreElements() {
|
||||
// If we have one already, send it
|
||||
if (currentKey != null) return true;
|
||||
// Loop on special properties first
|
||||
if (specialEnumerator < specialProperties.length) {
|
||||
currentKey = specialProperties[specialEnumerator];
|
||||
currentHash = currentKey.hashCode();
|
||||
specialEnumerator++;
|
||||
return true;
|
||||
}
|
||||
inSpecial = false;
|
||||
// Otherwise check in current enumeration
|
||||
while (props.hasMoreElements()) {
|
||||
currentKey = (String) props.nextElement();
|
||||
currentHash = currentKey.hashCode();
|
||||
//if (inside) {
|
||||
// if (properties.containsKey(currentKey, currentHash)) continue;
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
// Got to prototype enumeration if needed
|
||||
if (!inside && prototype != null) {
|
||||
inside = true;
|
||||
props = prototype.getProperties();
|
||||
while (props.hasMoreElements()) {
|
||||
currentKey = (String) props.nextElement();
|
||||
currentHash = currentKey.hashCode();
|
||||
//if (properties.containsKey(currentKey, currentHash)) continue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public Object nextElement() {
|
||||
if (hasMoreElements()) {
|
||||
String key = currentKey;
|
||||
int hash = key.hashCode();
|
||||
currentKey = null;
|
||||
ESValue value = null;
|
||||
try {
|
||||
value = ESObject.this.getProperty(key, hash);
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new ProgrammingError("Unexpected exception " + e);
|
||||
}
|
||||
String propertyKind;
|
||||
if (inSpecial) {
|
||||
propertyKind = "HIDDEN";
|
||||
} else if (inside && properties.containsKey(key, hash)) {
|
||||
propertyKind = "INVISIBLE";
|
||||
} else {
|
||||
propertyKind = isHiddenProperty(key, hash) ? "HIDDEN" : "VISIBLE";
|
||||
}
|
||||
propertyKind += (inside ? " PROTOTYPE" : " OBJECT");
|
||||
propertyKind += " PROPERTY";
|
||||
return new ValueDescription(key,
|
||||
propertyKind,
|
||||
value.toString());
|
||||
} else {
|
||||
throw new java.util.NoSuchElementException();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a full description of the value, with the specified name.
|
||||
*
|
||||
* @param name The name of the value to describe
|
||||
*
|
||||
* @return the description of this value
|
||||
*/
|
||||
public ValueDescription getDescription(String name) {
|
||||
return new ValueDescription(name,
|
||||
"OBJECT",
|
||||
this.toString());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
// ESPackages.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.EventListener;
|
||||
import java.util.zip.*;
|
||||
|
||||
/**
|
||||
* Implements the object loader
|
||||
*/
|
||||
public class ESPackages extends ESLoader {
|
||||
|
||||
/**
|
||||
* Create the top level package loader (object Package)
|
||||
* @param evaluator the evaluator
|
||||
*/
|
||||
public ESPackages(Evaluator evaluator) {
|
||||
super(evaluator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the top level package loader (object Package)
|
||||
* @param evaluator the evaluator
|
||||
*/
|
||||
public ESPackages(Evaluator evaluator, ClassLoader loader) {
|
||||
super(evaluator, loader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new package loader or package prefix
|
||||
* @param packageName The extension of the package name
|
||||
* @param previousPackage Represents the higher level package names
|
||||
* @param classLoader the class loader to use for this loader
|
||||
* @param evaluator the evaluator
|
||||
*/
|
||||
public ESPackages(String packageName,
|
||||
ESPackages previousPackage,
|
||||
ClassLoader classLoader,
|
||||
Evaluator evaluator) {
|
||||
super(packageName,previousPackage,classLoader,evaluator);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESObject getPrototype() {
|
||||
throw new ProgrammingError("Cannot get prototype of Package");
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getESClassName() {
|
||||
return "Packages";
|
||||
}
|
||||
|
||||
// Utility routine to load a class
|
||||
private Class loadClass(String className) throws ClassNotFoundException {
|
||||
if (classLoader == null) {
|
||||
return Class.forName(className);
|
||||
} else {
|
||||
return classLoader.loadClass(className); // use our own class loader
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
// Getting a property dynamically creates a new Package prefix object
|
||||
// If the resulting name represents a class then the class object is created
|
||||
// and returned (and will be used for example by the "new" operator).
|
||||
public ESValue getProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
ESValue value = (ESValue) properties.get(propertyName, hash);
|
||||
if (value == null) {
|
||||
String packageName = buildPrefix();
|
||||
String fullName = (packageName == null) ? propertyName : (packageName + "." + propertyName);
|
||||
try {
|
||||
Class cls = loadClass(fullName);
|
||||
if (debugJavaAccess) {
|
||||
System.out.println("** Class '" + fullName + "' loaded");
|
||||
}
|
||||
value = new ESWrapper(cls, evaluator);
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (debugJavaAccess) {
|
||||
System.out.println("** Could not load '" + fullName +
|
||||
"' by " + this);
|
||||
System.out.println("** Exception: " + e);
|
||||
}
|
||||
value = new ESPackages(propertyName, this, classLoader, evaluator);
|
||||
}
|
||||
properties.put(propertyName, hash, false, false, value); // Cache it for faster retrievial
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// overrides
|
||||
// Establish a bean classloader
|
||||
// The parameter is the directory or jar to load from
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (previousPackage == null && classLoader == null) {
|
||||
// This is the Package object
|
||||
if (arguments.length<1) {
|
||||
throw new EcmaScriptException("Missing class directory or file name");
|
||||
}
|
||||
String directoryOrJar = arguments[0].toString();
|
||||
ClassLoader classLoader =
|
||||
LocalClassLoader.makeLocalClassLoader(directoryOrJar);
|
||||
return new ESPackages(null, null, classLoader, evaluator);
|
||||
} else {
|
||||
throw new EcmaScriptException("Java class not found: '" + buildPrefix() +"'");
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getTypeofString() {
|
||||
return "JavaPackage";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return "ES:<" + getESClassName() + ":'" + buildPrefix() + "'" +
|
||||
((classLoader==null) ? "" : (",@" + classLoader)) + ">";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
// ESPrimitive.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
|
||||
/**
|
||||
* This is the superclass of all primitive values (non object)
|
||||
* of FESI. The conversion to a primitive value from a primitive
|
||||
* value is always the same value, independently of the hint (9.1).
|
||||
* <P>Use the isPrimitive function, so that further primitive could
|
||||
* be added without subclassing this class.
|
||||
*/
|
||||
public abstract class ESPrimitive extends ESValue {
|
||||
|
||||
|
||||
/**
|
||||
* Create a new primitive value. Does not add any specific information.
|
||||
*
|
||||
*/
|
||||
public ESPrimitive() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indicate that this value is a primitive value, useful for various
|
||||
* tests in conversions. This avoid testing the type, in case additional
|
||||
* primitives must be created.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public final boolean isPrimitive() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return false to indicate that this value is not composite.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public boolean isComposite() {return false; }
|
||||
|
||||
|
||||
/**
|
||||
* Convert to a primitive - a NOOP for a primitive.
|
||||
*
|
||||
* @return this
|
||||
* @exception EcmaScriptException not thrown
|
||||
*/
|
||||
public final ESValue toESPrimitive() throws EcmaScriptException {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert to a primitive - a NOOP for a primitive.
|
||||
*
|
||||
* @param hint ignored
|
||||
* @return this
|
||||
* @exception EcmaScriptException not thrown
|
||||
*/
|
||||
public final ESValue toESPrimitive(int hint) throws EcmaScriptException {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a full description of the value, with the specified name.
|
||||
*
|
||||
* @param name The name of the value to describe
|
||||
*
|
||||
* @return the description of this value
|
||||
*/
|
||||
public ValueDescription getDescription(String name) {
|
||||
return new ValueDescription(name,
|
||||
"PRIMITIVE",
|
||||
this.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
// ESreference.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
|
||||
/**
|
||||
* Currently a reference is not a FESI value, as it can never be returned
|
||||
* as a valid value by an EcmaScript function (8.7). It would be easy
|
||||
* to make ESReference a subclass of ESValue or to create a common
|
||||
* superclass (ESData) for both ESReference and ESValue if so desired in
|
||||
* the future (in fact this was the case in the first version of the system).
|
||||
* <P>References are less used than in the standard, as they are built only
|
||||
* if required for assignement.
|
||||
*/
|
||||
public class ESReference {
|
||||
|
||||
private ESObject base; // null means a property of the global object
|
||||
private String propertyName; // Should never be null for a valid reference
|
||||
private int hash; // hashCode of propertyName
|
||||
|
||||
/**
|
||||
* Create a new reference given a base and a property name
|
||||
*
|
||||
* @param base - may be null
|
||||
* @param propertyName - may not be null
|
||||
* @param hash - hashCode of propertyName
|
||||
*/
|
||||
public ESReference(ESValue base, String propertyName, int hash) {
|
||||
// Make sure the property name is not null
|
||||
if (propertyName == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.base = (ESObject) base;
|
||||
this.propertyName = propertyName;
|
||||
this.hash = hash;
|
||||
// System.out.println("NEWREF: " + this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the base object to which the property applies
|
||||
* Only used for the DELETE operation. See 8.7.1
|
||||
*
|
||||
* @return The base object, possibly null
|
||||
* @exception EcmaScriptException Not thrown
|
||||
*/
|
||||
public ESValue getBase() throws EcmaScriptException {
|
||||
return base;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the property to apply to the base object
|
||||
* Only used for the DELETE operation. See 8.7.2
|
||||
*
|
||||
* @return The name of the property, never null
|
||||
* @exception EcmaScriptException not thrown
|
||||
*/
|
||||
public String getPropertyName() throws EcmaScriptException {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the referenced value unless it is global and not defined, in which case
|
||||
* an exception is raised (see 8.7.3). By the definition of getProperty, and undefined
|
||||
* value is returned if the base object is defined but the property does
|
||||
* not exist (see 8.6.2.1).
|
||||
*
|
||||
* @return The referenced value
|
||||
* @exception EcmaScriptException if the value is not defined
|
||||
*/
|
||||
public ESValue getValue() throws EcmaScriptException {
|
||||
if (base == null) {
|
||||
throw new EcmaScriptException("global variable '" + propertyName + "' does not have a value");
|
||||
}
|
||||
return base.getProperty(propertyName, hash);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the referenced value, creating it if needed. If the base is
|
||||
* is null use the global object, otherwise use the base object.
|
||||
* See 8.7.4.
|
||||
*
|
||||
* @param g The global object to use if thre base is null
|
||||
* @param v The value to put
|
||||
* @exception EcmaScriptException May be thrown by putProperty
|
||||
*/
|
||||
public void putValue(ESObject g, ESValue v) throws EcmaScriptException {
|
||||
// System.out.println("PUT " + v + " to " + this);
|
||||
if (base==null) {
|
||||
g.putProperty(propertyName, v, hash);
|
||||
} else {
|
||||
base.putProperty(propertyName, v, hash);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string identifying the reference type and its content
|
||||
*
|
||||
* @return a string
|
||||
*/
|
||||
public String toDetailString() {
|
||||
return "ES:*<" + ((base==null) ? "null" : base.toString()) + ":" + propertyName +">";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of the reference, using a dot notation (could use
|
||||
* the bracket notation, or check which one is most appropriate).
|
||||
* Note that the base object is returned between braces, we do
|
||||
* not know its name at this stage. This is used for debugging
|
||||
* purpose, there is no way to get the string of a reference in
|
||||
* EcmaScript.
|
||||
*
|
||||
* @return The string naming the reference.
|
||||
*/
|
||||
public String toString() {
|
||||
return ((base==null) ? "" : ("{" + base.toString() + "}.")) + propertyName;
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
// ESString.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Interpreter.Evaluator;
|
||||
import FESI.Exceptions.*;
|
||||
|
||||
/**
|
||||
* Implements the string primitive value
|
||||
*/
|
||||
public final class ESString extends ESPrimitive {
|
||||
|
||||
// The value
|
||||
private String string;
|
||||
|
||||
/**
|
||||
* Create a new value from the string parameters
|
||||
*
|
||||
* @param value The immutable value
|
||||
*/
|
||||
public ESString(String value) {
|
||||
this.string = value;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return "ES:\"" + string + "\"";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public int getTypeOf() {
|
||||
return EStypeString;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getTypeofString() {
|
||||
return "string";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the string
|
||||
*
|
||||
* @return the length of the string
|
||||
*/
|
||||
public int getStringLength() {
|
||||
return string.length();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public double doubleValue() {
|
||||
double value = Double.NaN;
|
||||
try {
|
||||
// Will accept leading / trailing spaces, unlike new Integer !
|
||||
value = (Double.valueOf(string)).doubleValue();
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean booleanValue() {
|
||||
return string.length()>0;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue toESString() {
|
||||
return this;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue toESObject(Evaluator evaluator) throws EcmaScriptException {
|
||||
StringPrototype theObject = null;
|
||||
ESObject sp = evaluator.getStringPrototype();
|
||||
theObject= new StringPrototype(sp, evaluator);
|
||||
theObject.value = this;
|
||||
return theObject;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public Object toJavaObject() {
|
||||
return string;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean isStringValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,101 +0,0 @@
|
|||
// ESUndefined.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
|
||||
|
||||
/**
|
||||
* Implements the Undefined primitive value.
|
||||
* <P>There is a single Undefined value reached by ESUndefined.theUndefined
|
||||
* <P>The primitive Undefined, null and the java null are not
|
||||
* equivallent and must be used in the appropriate context
|
||||
*/
|
||||
public final class ESUndefined extends ESPrimitive {
|
||||
|
||||
/**
|
||||
* the READ-ONLY undefined value
|
||||
*/
|
||||
public static ESUndefined theUndefined = new ESUndefined();
|
||||
|
||||
private ESUndefined() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements a specific error message if an undfined value is called
|
||||
* @param thisObject The object on which the call is made
|
||||
* @param arguments The arguments of the function
|
||||
* @exception EcmaScriptException Thrown to indicate call on undefined value
|
||||
* @return never
|
||||
*/
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
throw new EcmaScriptException("Function called on undefined value or property");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements a specific error message if an undfined value is called via new
|
||||
* @param thisObject The object on which the call is made
|
||||
* @param arguments The arguments of the function
|
||||
* @exception EcmaScriptException Thrown to indicate call on undefined value
|
||||
* @return never
|
||||
*/
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
throw new EcmaScriptException("'new' called on undefined value or property");
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return "ES:<undefined>";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public int getTypeOf() {
|
||||
return EStypeUndefined;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getTypeofString() {
|
||||
return "undefined";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return "undefined";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public double doubleValue() {
|
||||
return Double.NaN;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean booleanValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public Object toJavaObject() {
|
||||
return null; // should throw an error
|
||||
}
|
||||
|
||||
}
|
|
@ -1,338 +0,0 @@
|
|||
// ESValue.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.Evaluator;
|
||||
|
||||
/**
|
||||
* All EcmaScript values are subclasses of this class.
|
||||
* The ESValue support many operations which may not be
|
||||
* implemented by all type (and then generate an error),
|
||||
* to simplify type checking.
|
||||
* <P>ESReference are currently not value - see ESReference.
|
||||
*/
|
||||
public abstract class ESValue {
|
||||
|
||||
// Codes for the getTypeOf, used to implement "=="
|
||||
public static final int EStypeUndefined = 1;
|
||||
public static final int EStypeNull = 2;
|
||||
public static final int EStypeBoolean = 3;
|
||||
public static final int EStypeNumber = 4;
|
||||
public static final int EStypeString = 5;
|
||||
public static final int EStypeObject = 6;
|
||||
|
||||
// The following routines access the value as a primitive type. They are
|
||||
// the prefered way to access the value of a primitive type or the default
|
||||
// value of an object if its type is known.
|
||||
// If the object is a reference, it will be dereferenced until a value is
|
||||
// found, this may generate an error or return a dummy value.
|
||||
//
|
||||
// toString() is considered part of these data access routine, however
|
||||
// it may never fail. It is implemented as described in 9.8.
|
||||
|
||||
|
||||
/**
|
||||
* Returns a detailed description of the value, intended for debugging.
|
||||
* (toString returns the official string representation, as defined in 9.8).
|
||||
*
|
||||
* @return the detailled information
|
||||
*/
|
||||
abstract public String toDetailString();
|
||||
|
||||
/**
|
||||
* Return a Java object which is the object to pass to Java routines
|
||||
* called by FESI. This may be the corresponding Java object (for
|
||||
* example the String), or a wrapper object. When received back from
|
||||
* a Java routine, an equivallent (but probably not identical) object
|
||||
* must be built.
|
||||
*
|
||||
* @return a Java object equivallent to the EcmaScript object.
|
||||
*/
|
||||
public abstract Object toJavaObject();
|
||||
|
||||
|
||||
/**
|
||||
* Return the double value of this ESValue as defined in 9.3, throw an
|
||||
* exception if not defined.
|
||||
*
|
||||
* @return a double
|
||||
* @exception EcmaScriptException Thrown because by default this is not supported
|
||||
*/
|
||||
public double doubleValue() throws EcmaScriptException {
|
||||
throw new EcmaScriptException("Conversion to double unsupported by " + this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the boolean value of this ESValue as defined in 9.2, throw an
|
||||
* exception if not defined.
|
||||
*
|
||||
* @return a boolean
|
||||
* @exception EcmaScriptException Thrown because by default this is not supported
|
||||
*/
|
||||
public boolean booleanValue() throws EcmaScriptException {
|
||||
throw new EcmaScriptException("Conversion to boolean unsupported by " + this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the EcmaScript object of this ESValue as definined in 9.9, throw
|
||||
* an exception if not defined.
|
||||
*
|
||||
* @param evaluator The evaluator object
|
||||
* @return an ESObject
|
||||
* @exception EcmaScriptException Thrown because by default this is not supported
|
||||
*/
|
||||
public ESValue toESObject(Evaluator evaluator) throws EcmaScriptException {
|
||||
throw new EcmaScriptException("Conversion to object unsupported by " + this);
|
||||
}
|
||||
|
||||
// The following routines are derived from the doubleValue of the
|
||||
// ESvalue. They may be overriden for efficiency by classes which
|
||||
// contain an integer or other equivallent.
|
||||
|
||||
|
||||
/**
|
||||
* Return the Integer value, as defined in 9.4.
|
||||
*
|
||||
* @return An integer inside a double
|
||||
* @exception EcmaScriptException Not thrown
|
||||
*/
|
||||
public double toInteger() throws EcmaScriptException {
|
||||
double value = this.doubleValue();
|
||||
if (Double.isNaN(value)) {
|
||||
return 0.0;
|
||||
} else if ((value == 0.0) ||
|
||||
Double.isInfinite(value)) {
|
||||
return value;
|
||||
} else {
|
||||
return (double)((long) value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the 32 bit integer, as defined in 9.5
|
||||
*
|
||||
* @return The signed 32 bit integer
|
||||
* @exception EcmaScriptException Not thrown
|
||||
*/
|
||||
public int toInt32() throws EcmaScriptException {
|
||||
double value = this.toInteger();
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returned the unsigned 32 bit integer (9.6). Currently
|
||||
* implemented as toInt32 !
|
||||
*
|
||||
* @return The integer
|
||||
* @exception EcmaScriptException Not thrown
|
||||
*/
|
||||
public int toUInt32() throws EcmaScriptException {
|
||||
double value = this.toInteger();
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the unsigned 16 bit integer (9.7). Currently
|
||||
* ignore the sign issue.
|
||||
*
|
||||
* @return The unsigned as a short
|
||||
* @exception EcmaScriptException Not thrown
|
||||
*/
|
||||
public short toUInt16() throws EcmaScriptException {
|
||||
double value = this.toInteger();
|
||||
return (short) value;
|
||||
}
|
||||
|
||||
|
||||
// Convertion to EcmaScript primitive type - rebuild the primitive type based
|
||||
// on the convertion to the Java primitive type. May be overriden by a subclass
|
||||
// for efficiency purpose (especially if it does not require a conversion).
|
||||
|
||||
// In fact on toESNumber is used (to implement the operator +), and this
|
||||
// is a very minor performance enhancement - so the routine could be
|
||||
// easily supressed
|
||||
|
||||
/**
|
||||
* Convert the value to an EcmaScript boolean (9.2) if possible
|
||||
*
|
||||
* @return The EcmaScript boolean value
|
||||
* @exception EcmaScriptException Not thrown
|
||||
*/
|
||||
public ESValue toESBoolean() throws EcmaScriptException {
|
||||
return ESBoolean.makeBoolean(this.booleanValue());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert the value to an EcmaScript string (9.8) if possible
|
||||
*
|
||||
* @return The EcmaScript string value (there is always one!)
|
||||
*/
|
||||
public ESValue toESString() {
|
||||
return new ESString(this.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the value to an EcmaScript number (9.3) if possible
|
||||
*
|
||||
* @return The EcmaScript number value
|
||||
* @exception EcmaScriptException From doubleValue
|
||||
*/
|
||||
public ESValue toESNumber() throws EcmaScriptException {
|
||||
double d = this.doubleValue();
|
||||
return new ESNumber(d);
|
||||
}
|
||||
|
||||
|
||||
// Provide support to easily distinguish primitive values from other, and
|
||||
// to convert values to primitive value. If the desired type is known
|
||||
// the direct conversion routines are prefered.
|
||||
|
||||
|
||||
/**
|
||||
* Return true if the value is a built-in primitive
|
||||
*
|
||||
* @return true if a primitive
|
||||
*/
|
||||
abstract public boolean isPrimitive();
|
||||
|
||||
/**
|
||||
* Transform to a primitive as described in 9.1
|
||||
*
|
||||
* @return A primitive value
|
||||
* @exception EcmaScriptException If conversion is impossible
|
||||
*/
|
||||
abstract public ESValue toESPrimitive() throws EcmaScriptException;
|
||||
|
||||
/**
|
||||
* Transform to a primitive as described in 9.1, with a specified hint
|
||||
*
|
||||
* @param preferedType the prefered type to return
|
||||
* @return a primitive value
|
||||
* @exception EcmaScriptException If conversion is impossible
|
||||
*/
|
||||
abstract public ESValue toESPrimitive(int preferedType) throws EcmaScriptException;
|
||||
|
||||
|
||||
|
||||
|
||||
// [[Call]] support (to ease check of type)
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
throw new EcmaScriptException("Function called on non object: " + this);
|
||||
}
|
||||
|
||||
// [[Construct]] support (to ease check of type)
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
throw new EcmaScriptException("'new' called on non object: " + this);
|
||||
}
|
||||
|
||||
// abstract public ESValue doNewObject();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Information routine to check if a value is a number (for array indexing)
|
||||
* if true, must implement conversions to double and int without evaluator.
|
||||
* @return true if a number.
|
||||
*/
|
||||
public boolean isNumberValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Information routine to check if a value is a string
|
||||
* if true, must implement toString without a evaluator.
|
||||
* @return true if a String (ESString or StringPrototype).
|
||||
*/
|
||||
public boolean isStringValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Information routine to check if a value is a boolean
|
||||
* if true, must implement booleanValue without a evaluator.
|
||||
* @return true if a boolean (ESBoolean or BooleanPrototype).
|
||||
*/
|
||||
public boolean isBooleanValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a code indicating the type of the object for the implementation
|
||||
* of the "==" operator.
|
||||
*
|
||||
* @return A type code
|
||||
*/
|
||||
public abstract int getTypeOf();
|
||||
|
||||
/**
|
||||
* Return the name of the type of the object for the typeof operator
|
||||
*
|
||||
* @return The name of the type as a String
|
||||
*/
|
||||
public abstract String getTypeofString();
|
||||
|
||||
// Support to list description of objects
|
||||
|
||||
/**
|
||||
* Return true if the value is composite (even if not an
|
||||
* object). A composite value can be examined by getAllDescriptions.
|
||||
* A composite value may have no component!
|
||||
*
|
||||
* @return true if composite
|
||||
*/
|
||||
abstract public boolean isComposite();
|
||||
|
||||
/**
|
||||
* Return an enumeration of all description of elements of this
|
||||
* value (for example properties of an object).
|
||||
*
|
||||
* @return Enumerator of all components or NULL.
|
||||
*/
|
||||
public Enumeration getAllDescriptions() {return null;}
|
||||
|
||||
/**
|
||||
* Returns a full description of the value, with the specified name.
|
||||
*
|
||||
* @param name The name of the value to describe
|
||||
*
|
||||
* @return the description of this value
|
||||
*/
|
||||
abstract public ValueDescription getDescription(String name);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a full description of the unnamed value.
|
||||
*
|
||||
* @return the description of this value
|
||||
*/
|
||||
public ValueDescription getDescription() {
|
||||
return getDescription(null);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,153 +0,0 @@
|
|||
// FunctionObject.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Parser.*;
|
||||
import FESI.AST.*;
|
||||
import java.util.Vector;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.Evaluator;
|
||||
import FESI.Interpreter.StringEvaluationSource;
|
||||
import FESI.Interpreter.FunctionEvaluationSource;
|
||||
import FESI.Interpreter.EcmaScriptVariableVisitor;
|
||||
|
||||
|
||||
/**
|
||||
* Implements the EcmaScript Function singleton
|
||||
*/
|
||||
public class FunctionObject extends BuiltinFunctionObject
|
||||
implements EcmaScriptTreeConstants {
|
||||
|
||||
static boolean debugParse = false;
|
||||
|
||||
FunctionObject(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator, "Function", 1);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getESClassName() {
|
||||
return "Function";
|
||||
}
|
||||
|
||||
// overrides - call and new have the same effect
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
return doConstruct(thisObject, arguments);
|
||||
}
|
||||
|
||||
|
||||
// overrides - build a new function
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESObject fp = evaluator.getFunctionPrototype();
|
||||
ConstructedFunctionObject theFunction = null;
|
||||
ASTFormalParameterList fpl = null;
|
||||
ASTStatementList sl = null;
|
||||
|
||||
StringBuffer parameters = new StringBuffer();
|
||||
int nArgs = arguments.length;
|
||||
int i;
|
||||
for (i=0; i<(nArgs-1); i++) {
|
||||
if (i>0) {parameters.append(",");}
|
||||
String arg = arguments[i].toString();
|
||||
parameters.append(arg);
|
||||
}
|
||||
String body = arguments[i].toString();
|
||||
|
||||
//System.out.println("P:'"+parameters+"'");
|
||||
//System.out.println("B:'"+body+"'");
|
||||
|
||||
String trimedParams = parameters.toString().trim();
|
||||
|
||||
String fullFunctionText = "function anonymous (" +
|
||||
trimedParams +
|
||||
") {" +
|
||||
body.toString() +
|
||||
"}";
|
||||
|
||||
java.io.StringReader is;
|
||||
EcmaScript parser;
|
||||
|
||||
// Special case for empty parameters
|
||||
if (trimedParams.length()==0) {
|
||||
fpl = new ASTFormalParameterList(JJTFORMALPARAMETERLIST);
|
||||
} else {
|
||||
is =
|
||||
new java.io.StringReader(trimedParams);
|
||||
parser = new EcmaScript(is);
|
||||
try {
|
||||
fpl = (ASTFormalParameterList) parser.FormalParameterList();
|
||||
is.close();
|
||||
} catch (ParseException e) {
|
||||
if (debugParse) {
|
||||
System.out.println("[[PARSING ERROR DETECTED: (debugParse true)]]");
|
||||
System.out.println(e.getMessage());
|
||||
System.out.println("[[BY ROUTINE:]]");
|
||||
e.printStackTrace();
|
||||
System.out.println();
|
||||
}
|
||||
throw new EcmaScriptParseException(e,
|
||||
new StringEvaluationSource(fullFunctionText,
|
||||
null)
|
||||
);
|
||||
}
|
||||
}
|
||||
is = new java.io.StringReader(body.toString());
|
||||
parser = new EcmaScript(is);
|
||||
try {
|
||||
sl = (ASTStatementList) parser.StatementList();
|
||||
is.close();
|
||||
} catch (ParseException e) {
|
||||
if (debugParse) {
|
||||
System.out.println("[[PARSING ERROR DETECTED: (debugParse true)]]");
|
||||
System.out.println(e.getMessage());
|
||||
System.out.println("[[BY ROUTINE:]]");
|
||||
e.printStackTrace();
|
||||
System.out.println();
|
||||
}
|
||||
throw new EcmaScriptParseException(e,
|
||||
new StringEvaluationSource(fullFunctionText, null));
|
||||
}
|
||||
|
||||
FunctionEvaluationSource fes =
|
||||
new FunctionEvaluationSource(
|
||||
new StringEvaluationSource(fullFunctionText,null),
|
||||
"<anonymous function>");
|
||||
EcmaScriptVariableVisitor varDeclarationVisitor = evaluator.getVarDeclarationVisitor();
|
||||
Vector variableNames = varDeclarationVisitor.processVariableDeclarations(sl, fes);
|
||||
|
||||
theFunction = ConstructedFunctionObject.makeNewConstructedFunction(
|
||||
evaluator,
|
||||
"anonymous",
|
||||
fes,
|
||||
fullFunctionText,
|
||||
fpl.getArguments(),
|
||||
variableNames,
|
||||
sl);
|
||||
|
||||
return theFunction;
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return "<Function>";
|
||||
}
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
// FunctionPrototype.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.Evaluator;
|
||||
import FESI.Interpreter.ScopeChain;
|
||||
|
||||
/**
|
||||
* Implements the prototype and is the class of all Function objects
|
||||
*/
|
||||
public class FunctionPrototype extends ESObject {
|
||||
|
||||
private String functionName = null;
|
||||
private int length = 0;
|
||||
|
||||
private static final String LENGTHstring = ("length").intern();
|
||||
private static final int LENGTHhash = LENGTHstring.hashCode();
|
||||
|
||||
FunctionPrototype(ESObject prototype, Evaluator evaluator, String functionName, int length) {
|
||||
super(prototype, evaluator);
|
||||
this.functionName = functionName;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
FunctionPrototype(ESObject prototype, Evaluator evaluator, int length) {
|
||||
super(prototype, evaluator);
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getESClassName() {
|
||||
return "Function";
|
||||
}
|
||||
|
||||
public String getFunctionName() {
|
||||
if (functionName == null) {
|
||||
return "anonymous";
|
||||
} else {
|
||||
return functionName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the string defining the function
|
||||
* @return a String indicating that this is the function prototype
|
||||
*/
|
||||
public String getFunctionImplementationString() {
|
||||
return "{<FunctionPrototype (" + this.getClass().getName() + ")>}";
|
||||
}
|
||||
|
||||
/**
|
||||
* get the string defining the function
|
||||
* @return a string indicating that the function prototype has no argument
|
||||
*/
|
||||
public String getFunctionParametersString() {
|
||||
return "()";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of arguments property
|
||||
*/
|
||||
public int getLengthProperty() {
|
||||
return length;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getPropertyInScope(String propertyName, ScopeChain previousScope, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (hash==LENGTHhash && propertyName.equals(LENGTHstring)) {
|
||||
return new ESNumber(length);
|
||||
}
|
||||
return super.getPropertyInScope(propertyName, previousScope, hash);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue getProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (hash==LENGTHhash && propertyName.equals(LENGTHstring)) {
|
||||
return new ESNumber(length);
|
||||
} else {
|
||||
return super.getProperty(propertyName, hash);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean hasProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (hash==LENGTHhash && propertyName.equals(LENGTHstring)) {
|
||||
return true;
|
||||
} else {
|
||||
return super.hasProperty(propertyName, hash);
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public void putProperty(String propertyName, ESValue propertyValue, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (!(hash==LENGTHhash && propertyName.equals(LENGTHstring))) {
|
||||
super.putProperty(propertyName,propertyValue, hash);
|
||||
} // Allowed via putHiddenProperty, used internally !
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public String[] getSpecialPropertyNames() {
|
||||
String [] ns = {LENGTHstring};
|
||||
return ns;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
return ESUndefined.theUndefined;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getTypeofString() {
|
||||
return "function";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return "<" + getESClassName() + ":" + this.getFunctionName() +">";
|
||||
}
|
||||
}
|
|
@ -1,455 +0,0 @@
|
|||
// GlobalObject.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.Evaluator;
|
||||
|
||||
/**
|
||||
* Implements the EmcaScript 'global' object
|
||||
*/
|
||||
public class GlobalObject extends ObjectPrototype {
|
||||
|
||||
static private final String VALUEstring = ("value").intern();
|
||||
static private final int VALUEhash = VALUEstring.hashCode();
|
||||
static private final String ERRORstring = ("error").intern();
|
||||
static private final int ERRORhash = ERRORstring.hashCode();
|
||||
|
||||
private GlobalObject(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the single global object
|
||||
* @param evaluator theEvaluator
|
||||
* @return the 'global' singleton
|
||||
*/
|
||||
static public GlobalObject makeGlobalObject(Evaluator evaluator) {
|
||||
|
||||
GlobalObject go = null;
|
||||
try {
|
||||
|
||||
// For objectPrototype
|
||||
class ObjectPrototypeToString extends BuiltinFunctionObject {
|
||||
ObjectPrototypeToString(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
String result = "[object " + thisObject.getESClassName() +"]";
|
||||
return new ESString(result);
|
||||
}
|
||||
}
|
||||
class ObjectPrototypeValueOf extends BuiltinFunctionObject {
|
||||
ObjectPrototypeValueOf(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
return thisObject;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// For functionPrototype
|
||||
class FunctionPrototypeToString extends BuiltinFunctionObject {
|
||||
FunctionPrototypeToString(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
String s = "function " +
|
||||
((FunctionPrototype) thisObject).getFunctionName() +
|
||||
((FunctionPrototype) thisObject).getFunctionParametersString() +
|
||||
((FunctionPrototype) thisObject).getFunctionImplementationString() ;
|
||||
return new ESString(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// For GlobalObject
|
||||
class GlobalObjectThrowError extends BuiltinFunctionObject {
|
||||
GlobalObjectThrowError(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESObject result = ObjectObject.createObject(this.evaluator);
|
||||
if (arguments.length<1) {
|
||||
throw new EcmaScriptException("Exception thrown by throwError");
|
||||
}
|
||||
if (arguments[0] instanceof ESWrapper) {
|
||||
Object o = ((ESWrapper) arguments[0]).getJavaObject();
|
||||
if (o instanceof Throwable) {
|
||||
throw new EcmaScriptException(o.toString(), (Throwable) o);
|
||||
} else {
|
||||
throw new EcmaScriptException(o.toString());
|
||||
}
|
||||
}
|
||||
String text = arguments[0].toString();
|
||||
throw new EcmaScriptException(text);
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalObjectTryEval extends BuiltinFunctionObject {
|
||||
GlobalObjectTryEval(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESObject result = ObjectObject.createObject(this.evaluator);
|
||||
if (arguments.length<1) {
|
||||
result.putProperty(ERRORstring,ESNull.theNull,ERRORhash);
|
||||
return result;
|
||||
}
|
||||
if (!(arguments[0] instanceof ESString)) {
|
||||
result.putProperty(VALUEstring,arguments[0],VALUEhash);
|
||||
result.putProperty(ERRORstring,ESNull.theNull,ERRORhash);
|
||||
return result;
|
||||
}
|
||||
String program = arguments[0].toString();
|
||||
ESValue value = ESUndefined.theUndefined;
|
||||
try {
|
||||
value = this.evaluator.evaluateEvalString(program);
|
||||
} catch (EcmaScriptParseException e) {
|
||||
e.setNeverIncomplete();
|
||||
if (arguments.length>1) {
|
||||
result.putProperty(VALUEstring,arguments[1],VALUEhash);
|
||||
}
|
||||
result.putProperty(ERRORstring,
|
||||
ESLoader.normalizeValue(e,this.evaluator),
|
||||
ERRORhash);
|
||||
return result;
|
||||
} catch (EcmaScriptException e) {
|
||||
if (arguments.length>1) {
|
||||
result.putProperty(VALUEstring,arguments[1],VALUEhash);
|
||||
}
|
||||
result.putProperty(ERRORstring,
|
||||
ESLoader.normalizeValue(e,this.evaluator),
|
||||
ERRORhash);
|
||||
return result;
|
||||
}
|
||||
result.putProperty(VALUEstring,value,VALUEhash);
|
||||
result.putProperty(ERRORstring,ESNull.theNull,ERRORhash);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalObjectEval extends BuiltinFunctionObject {
|
||||
GlobalObjectEval(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (arguments.length<1) return ESUndefined.theUndefined;
|
||||
if (!(arguments[0] instanceof ESString)) return arguments[0];
|
||||
String program = arguments[0].toString();
|
||||
ESValue value = ESUndefined.theUndefined;
|
||||
try {
|
||||
value = this.evaluator.evaluateEvalString(program);
|
||||
} catch (EcmaScriptParseException e) {
|
||||
e.setNeverIncomplete();
|
||||
throw e;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalObjectParseInt extends BuiltinFunctionObject {
|
||||
GlobalObjectParseInt(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 2);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (arguments.length<1) return ESUndefined.theUndefined;
|
||||
int radix = 10;
|
||||
String s = arguments[0].toString().trim();
|
||||
if (arguments.length>1) {
|
||||
radix = arguments[1].toInt32();
|
||||
if (radix<2 || radix>36) return new ESNumber(Double.NaN);
|
||||
if (radix == 16) {
|
||||
if (s.startsWith("0x") || s.startsWith("0X")) {
|
||||
s=s.substring(2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (s.startsWith("0x") || s.startsWith("0X")) {
|
||||
s=s.substring(2);
|
||||
radix = 16;
|
||||
} else if (s.startsWith("0")) {
|
||||
radix = 8;
|
||||
}
|
||||
}
|
||||
double d = Double.NaN;
|
||||
int k = -1;
|
||||
for (int i=0; i<s.length() && k == -1; i++) {
|
||||
char c= s.charAt(i);
|
||||
switch (radix) {
|
||||
case 2:
|
||||
if (c<'0' || '1'<c) k=i;
|
||||
break;
|
||||
case 8:
|
||||
if (c<'0' || '7'<c) k=i;
|
||||
break;
|
||||
case 10:
|
||||
if (c<'0' || '9'<c) k=i;
|
||||
break;
|
||||
case 16:
|
||||
if ((c<'0' || '9'<c) && (c<'a' || 'f'<c) && (c<'A' || 'F'<c)) k=i;
|
||||
break;
|
||||
default:
|
||||
throw new EcmaScriptException("Only radix 2,8,10 and 16 supported");
|
||||
}
|
||||
}
|
||||
if (k>0) s = s.substring(0,k);
|
||||
if (s.length()>0) {
|
||||
try {d = (double) Long.parseLong(s,radix);} catch (NumberFormatException e) {};
|
||||
}
|
||||
return new ESNumber(d);
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalObjectParseFloat extends BuiltinFunctionObject {
|
||||
GlobalObjectParseFloat(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (arguments.length<1) return ESUndefined.theUndefined;
|
||||
String s = arguments[0].toString().trim();
|
||||
Double d = new Double(Double.NaN);
|
||||
int i; // approximate look for a prefix
|
||||
boolean efound = false;
|
||||
boolean dotfound = false;
|
||||
for (i=0; i<s.length(); i++) {
|
||||
char c = s.charAt(i);
|
||||
if ('0'<=c && c<='9') continue;
|
||||
if (c=='+' || c=='-') continue; // accept sequences of signs...
|
||||
if (c=='e' || c=='E') {
|
||||
if (efound) break;
|
||||
efound = true;
|
||||
continue;
|
||||
}
|
||||
if (c=='.') {
|
||||
if (dotfound || efound) break;
|
||||
dotfound = true;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// System.out.println("i="+i+", s="+s);
|
||||
s = s.substring(0,i);
|
||||
try {d = Double.valueOf(s); } catch (NumberFormatException e) {};
|
||||
return new ESNumber(d.doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalObjectEscape extends BuiltinFunctionObject {
|
||||
GlobalObjectEscape(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (arguments.length<=0) {
|
||||
return ESUndefined.theUndefined;
|
||||
} else {
|
||||
StringBuffer dst = new StringBuffer();
|
||||
String src = arguments[0].toString();
|
||||
for (int i =0; i<src.length(); i++) {
|
||||
char c = src.charAt(i);
|
||||
if (('a'<=c && c<='z') ||
|
||||
('A'<=c && c<='Z') ||
|
||||
('0'<=c && c<='9') ||
|
||||
c=='@' || c =='*' ||
|
||||
c=='_' || c =='+' ||
|
||||
c=='-' || c =='.' ||
|
||||
c=='/') {
|
||||
dst.append(c);
|
||||
} else if (c<= (char) 0xF) {
|
||||
dst.append("%0" + Integer.toHexString(c));
|
||||
} else if (c<= (char) 0xFF) {
|
||||
dst.append("%" + Integer.toHexString(c));
|
||||
} else if (c<= (char) 0xFFF) {
|
||||
dst.append("%u0" + Integer.toHexString(c));
|
||||
} else {
|
||||
dst.append("%u" + Integer.toHexString(c));
|
||||
}
|
||||
}
|
||||
return new ESString(dst.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class GlobalObjectUnescape extends BuiltinFunctionObject {
|
||||
GlobalObjectUnescape(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (arguments.length<=0) {
|
||||
return ESUndefined.theUndefined;
|
||||
} else {
|
||||
StringBuffer dst = new StringBuffer();
|
||||
String src = arguments[0].toString();
|
||||
for (int i =0; i<src.length(); i++) {
|
||||
char c = src.charAt(i);
|
||||
if (c == '%') {
|
||||
StringBuffer d = new StringBuffer();
|
||||
c = src.charAt(++i); // May raise exception
|
||||
if (c == 'u' || c == 'U') {
|
||||
d.append(src.charAt(++i)); // May raise exception
|
||||
d.append(src.charAt(++i)); // May raise exception
|
||||
d.append(src.charAt(++i)); // May raise exception
|
||||
d.append(src.charAt(++i)); // May raise exception
|
||||
} else {
|
||||
d.append(src.charAt(i)); // May raise exception
|
||||
d.append(src.charAt(++i)); // May raise exception
|
||||
}
|
||||
c = (char) Integer.parseInt(d.toString(), 16);
|
||||
|
||||
}
|
||||
dst.append(c);
|
||||
}
|
||||
return new ESString(dst.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalObjectIsNaN extends BuiltinFunctionObject {
|
||||
GlobalObjectIsNaN(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (arguments.length<1) return ESUndefined.theUndefined;
|
||||
double d = arguments[0].doubleValue();
|
||||
return ESBoolean.makeBoolean(Double.isNaN(d));
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalObjectIsFinite extends BuiltinFunctionObject {
|
||||
GlobalObjectIsFinite(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (arguments.length<1) return ESUndefined.theUndefined;
|
||||
double d = arguments[0].doubleValue();
|
||||
return ESBoolean.makeBoolean(!Double.isInfinite(d));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Create object (not yet usable!) in right order for
|
||||
// property chain
|
||||
ObjectPrototype objectPrototype = new ObjectPrototype(null, evaluator);
|
||||
FunctionPrototype functionPrototype = new FunctionPrototype(objectPrototype, evaluator, "[Function Prototype]", 0);
|
||||
ObjectObject objectObject = new ObjectObject(functionPrototype, evaluator);
|
||||
FunctionObject functionObject = new FunctionObject(functionPrototype, evaluator);
|
||||
|
||||
StringObject stringObject =
|
||||
StringObject.makeStringObject(evaluator, objectPrototype, functionPrototype);
|
||||
NumberObject numberObject =
|
||||
NumberObject.makeNumberObject(evaluator, objectPrototype, functionPrototype);
|
||||
BooleanObject booleanObject =
|
||||
BooleanObject.makeBooleanObject(evaluator, objectPrototype, functionPrototype);
|
||||
ArrayObject arrayObject =
|
||||
ArrayObject.makeArrayObject(evaluator, objectPrototype, functionPrototype);
|
||||
DateObject dateObject =
|
||||
DateObject.makeDateObject(evaluator, objectPrototype, functionPrototype);
|
||||
|
||||
go = new GlobalObject(objectPrototype, evaluator);
|
||||
|
||||
// Set built-in properties
|
||||
objectObject.putHiddenProperty("prototype",objectPrototype);
|
||||
|
||||
objectPrototype.putHiddenProperty("constructor",objectObject);
|
||||
objectPrototype.putHiddenProperty("toString",
|
||||
new ObjectPrototypeToString("toString", evaluator, functionPrototype));
|
||||
objectPrototype.putHiddenProperty("valueOf",
|
||||
new ObjectPrototypeValueOf("valueOf", evaluator, functionPrototype));
|
||||
|
||||
functionPrototype.putHiddenProperty("constructor",functionObject);
|
||||
functionPrototype.putHiddenProperty("toString",
|
||||
new FunctionPrototypeToString("toString", evaluator, functionPrototype));
|
||||
|
||||
functionObject.putHiddenProperty("prototype",functionPrototype);
|
||||
functionObject.putHiddenProperty("length",new ESNumber(1));
|
||||
|
||||
|
||||
// Save system object so that they can be quickly found
|
||||
evaluator.setObjectPrototype(objectPrototype);
|
||||
evaluator.setFunctionPrototype(functionPrototype);
|
||||
evaluator.setFunctionObject(functionObject);
|
||||
|
||||
// Populate the global object
|
||||
go.putHiddenProperty("throwError",
|
||||
new GlobalObjectThrowError("throwError", evaluator, functionPrototype));
|
||||
go.putHiddenProperty("tryEval",
|
||||
new GlobalObjectTryEval("tryEval", evaluator, functionPrototype));
|
||||
go.putHiddenProperty("eval",
|
||||
new GlobalObjectEval("eval", evaluator, functionPrototype));
|
||||
go.putHiddenProperty("parseInt",
|
||||
new GlobalObjectParseInt("parseInt", evaluator, functionPrototype));
|
||||
go.putHiddenProperty("parseFloat",
|
||||
new GlobalObjectParseFloat("parseFloat", evaluator, functionPrototype));
|
||||
go.putHiddenProperty("escape",
|
||||
new GlobalObjectEscape("escape", evaluator, functionPrototype));
|
||||
go.putHiddenProperty("unescape",
|
||||
new GlobalObjectUnescape("unescape", evaluator, functionPrototype));
|
||||
go.putHiddenProperty("isNaN",
|
||||
new GlobalObjectIsNaN("isNaN", evaluator, functionPrototype));
|
||||
go.putHiddenProperty("isFinite",
|
||||
new GlobalObjectIsFinite("isFinite", evaluator, functionPrototype));
|
||||
|
||||
go.putHiddenProperty("Object", objectObject);
|
||||
go.putHiddenProperty("Function", functionObject);
|
||||
go.putHiddenProperty("String", stringObject);
|
||||
go.putHiddenProperty("Number", numberObject);
|
||||
go.putHiddenProperty("Boolean", booleanObject);
|
||||
go.putHiddenProperty("Array", arrayObject);
|
||||
go.putHiddenProperty("Date", dateObject);
|
||||
|
||||
go.putHiddenProperty("NaN", new ESNumber(Double.NaN));
|
||||
go.putHiddenProperty("Infinity", new ESNumber(Double.POSITIVE_INFINITY));
|
||||
go.putHiddenProperty("Array", ArrayObject.makeArrayObject(evaluator, objectPrototype, functionPrototype));
|
||||
go.putHiddenProperty("Math", MathObject.makeMathObject(evaluator, objectPrototype, functionPrototype));
|
||||
|
||||
} catch (EcmaScriptException e) {
|
||||
e.printStackTrace();
|
||||
throw new ProgrammingError(e.getMessage());
|
||||
}
|
||||
return go;
|
||||
}
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
// JSGlobalWrapper.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.jslib.*;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Extensions.Extension;
|
||||
import FESI.Interpreter.Evaluator;
|
||||
|
||||
/**
|
||||
* Package an EcmaScript object as a JSObject for use by the
|
||||
* Netscape like interface. Specialled for the global object.
|
||||
*/
|
||||
public class JSGlobalWrapper extends JSWrapper implements JSGlobalObject {
|
||||
|
||||
/**
|
||||
* Create a JSGlobalWrapper object over the global object
|
||||
* @param go the EcmaScript global object
|
||||
* @param evaluator the Evaluator
|
||||
*/
|
||||
|
||||
public JSGlobalWrapper(GlobalObject go, Evaluator evaluator) {
|
||||
super(go, evaluator);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Package any object as an EcmaScript object, allowing to use
|
||||
* it for example with an "eval" function, where it becomes the
|
||||
* 'this' object.
|
||||
*
|
||||
* @param object The object to wrap.
|
||||
*/
|
||||
public JSObject makeObjectWrapper(Object object) {
|
||||
synchronized (evaluator) {
|
||||
if (object instanceof JSWrapper) {
|
||||
return (JSWrapper) object; // Already a JSObject
|
||||
}
|
||||
if (object instanceof ESWrapper) {
|
||||
// A java object wrapped as an ecmascript object
|
||||
ESWrapper eswrapper = (ESWrapper) object;
|
||||
// Just wrap it for the JS interface
|
||||
return new JSWrapper(eswrapper,evaluator);
|
||||
}
|
||||
// Any native java object - make it an internal ES object, then wrap it
|
||||
// for the public interface
|
||||
ESWrapper eswrapper = new ESWrapper(object, evaluator);
|
||||
return new JSWrapper(eswrapper,evaluator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mark an object as a bean, restricting its access by FESI scripts
|
||||
* to the public bean methods and properties.
|
||||
*
|
||||
* @param object The object to wrap as a bean.
|
||||
*/
|
||||
public Object makeBeanWrapper(Object object) {
|
||||
synchronized (evaluator) {
|
||||
if (object instanceof ESWrapper) {
|
||||
ESWrapper eswrapper = (ESWrapper) object;
|
||||
if (eswrapper.isBean()) {
|
||||
return eswrapper;
|
||||
} else {
|
||||
return new ESWrapper(eswrapper.getJavaObject(), eswrapper.getEvaluator(), true);
|
||||
}
|
||||
} else {
|
||||
return new ESWrapper(object, evaluator, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make a new object based on a given prototype (which may be null).
|
||||
* The object is of class Object and has initially no property.
|
||||
*
|
||||
* @return A new object
|
||||
*/
|
||||
public JSObject makeJSObject() {
|
||||
return makeJSObject(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a new object based the object prototype object.
|
||||
* The object is of class Object and has initially no property.
|
||||
*
|
||||
* @param prototype An object to use as prototype for this object
|
||||
* @return A new object
|
||||
*/
|
||||
public JSObject makeJSObject(JSObject prototype) {
|
||||
synchronized (evaluator) {
|
||||
ESObject op = evaluator.getObjectPrototype();
|
||||
if (prototype != null) {
|
||||
Evaluator otherEvaluator = ((JSWrapper) prototype).evaluator;
|
||||
if (otherEvaluator != evaluator) throw new ProgrammingError("Evaluator mismatch");
|
||||
op = (ESObject) ((JSWrapper) prototype).getESObject();
|
||||
}
|
||||
ESObject object = new ObjectPrototype((ESObject) op, evaluator);
|
||||
return new JSWrapper(object, evaluator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a new array object.
|
||||
* The object is of class Array and is empty (length 0).
|
||||
*
|
||||
* @return A new object
|
||||
*/
|
||||
public JSObject makeJSArrayObject() {
|
||||
synchronized (evaluator) {
|
||||
ESObject ap = evaluator.getArrayPrototype();
|
||||
ArrayPrototype theArray = new ArrayPrototype(ap, evaluator);
|
||||
return new JSWrapper(theArray, evaluator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Display the string value of the contained object
|
||||
* @return The string value
|
||||
*/
|
||||
public String toString() {
|
||||
return object.toString();
|
||||
}
|
||||
}
|
|
@ -1,505 +0,0 @@
|
|||
// JSRWrapper.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.jslib.*;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Extensions.Extension;
|
||||
import FESI.Interpreter.Evaluator;
|
||||
import FESI.Interpreter.UserEvaluationSource;
|
||||
|
||||
import java.io.Reader;
|
||||
|
||||
/**
|
||||
* Package an EcmaScript object as a JSObject for use by the
|
||||
* Netscape like interface.
|
||||
*/
|
||||
public class JSWrapper implements JSObject {
|
||||
|
||||
protected Evaluator evaluator;
|
||||
protected ESObject object;
|
||||
|
||||
/**
|
||||
* Create a JSWraper for an EcmaScript object
|
||||
* @param object the EcmaScript object
|
||||
* @param evaluator theEvaluator
|
||||
*/
|
||||
public JSWrapper(ESObject object, Evaluator evaluator) {
|
||||
super();
|
||||
this.object = object;
|
||||
this.evaluator = evaluator;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESObject getESObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the global object attached to this object
|
||||
* @return the global object
|
||||
*/
|
||||
public JSGlobalObject getGlobalObject() {
|
||||
return new JSGlobalWrapper(evaluator.getGlobalObject(), evaluator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the call the specified EcmaScript method of this object
|
||||
*
|
||||
* @param methodName The name of the method to call
|
||||
* @param args An array of parameters.
|
||||
* @return The result of the evaluation
|
||||
* @exception JSException For any error during interpretation
|
||||
*/
|
||||
public Object call(String methodName,Object args[]) throws JSException {
|
||||
Object obj = null;
|
||||
synchronized (evaluator) {
|
||||
try {
|
||||
ESValue function = object.getProperty(methodName, methodName.hashCode());
|
||||
ESValue[] esargs = null;
|
||||
if (args == null) {
|
||||
esargs = new ESValue[0];
|
||||
} else {
|
||||
esargs = new ESValue[args.length];
|
||||
for (int i=0; i<args.length; i++) {
|
||||
esargs[i] = ESLoader.normalizeValue(args[i], evaluator);
|
||||
}
|
||||
}
|
||||
ESValue value = function.callFunction(object, esargs); // should never return null
|
||||
obj = value.toJavaObject();
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the evaluation of a string with this object as the 'this' object.
|
||||
* The string is considered a main program (top level return is not allowed)
|
||||
*
|
||||
* @param s The string to evaluate
|
||||
* @return The result of the evaluation (null if no value returned)
|
||||
* @exception JSException For any error during interpretation
|
||||
*/
|
||||
public Object eval(String s) throws JSException {
|
||||
Object obj = null;
|
||||
synchronized (evaluator) {
|
||||
try {
|
||||
ESValue value = evaluator.evaluate(s, object, false); // Can return null !
|
||||
if (value != null) obj = value.toJavaObject();
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Evaluate a Reader stream with this object as the 'this' object.
|
||||
* Consider the stream being a main program, not allowing the
|
||||
* return statement.
|
||||
*
|
||||
* @param r The Reader stream to evaluate
|
||||
* @param d A description of the Reader for error messages
|
||||
* @return The result of the evaluation (null if no value returned)
|
||||
* @exception JSException For any error during interpretation
|
||||
*/
|
||||
public Object eval(Reader r, String d) throws JSException {
|
||||
Object obj = null;
|
||||
synchronized (evaluator) {
|
||||
try {
|
||||
UserEvaluationSource ses;
|
||||
if (d==null) {
|
||||
ses = new UserEvaluationSource("<Anonymous stream>", null);
|
||||
} else {
|
||||
ses = new UserEvaluationSource(d, null);
|
||||
}
|
||||
ESValue value =
|
||||
evaluator.evaluate(r,
|
||||
object,
|
||||
ses,
|
||||
false);
|
||||
if (value != null) obj = value.toJavaObject();
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate a Reader stream with this object as the 'this' object.
|
||||
* Consider the stream being a function program, allowing the
|
||||
* return statement.
|
||||
*
|
||||
* @param r The Reader stream to evaluate
|
||||
* @param d A description of the Reader for error messages
|
||||
* @return The result of the evaluation (null if no value returned)
|
||||
* @exception JSException For any error during interpretation
|
||||
*/
|
||||
public Object evalAsFunction(Reader r, String d) throws JSException {
|
||||
Object obj = null;
|
||||
synchronized (evaluator) {
|
||||
try {
|
||||
UserEvaluationSource ses;
|
||||
if (d==null) {
|
||||
ses = new UserEvaluationSource("<Anonymous stream>", null);
|
||||
} else {
|
||||
ses = new UserEvaluationSource(d, null);
|
||||
}
|
||||
ESValue value =
|
||||
evaluator.evaluate(r,
|
||||
object,
|
||||
ses,
|
||||
true);
|
||||
if (value != null) obj = value.toJavaObject();
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the evaluation of a string with this object as the 'this' object.
|
||||
* The string is considered a function (top level return are allowed)
|
||||
* Passing the specified parameters (names and values must have the same length)
|
||||
*
|
||||
* @param s The string to evaluate
|
||||
* @return The result of the evaluation (null if no value returned)
|
||||
* @exception JSException For any error during interpretation
|
||||
*/
|
||||
public Object evalAsFunction(String s) throws JSException {
|
||||
|
||||
Object obj = null;
|
||||
synchronized (evaluator) {
|
||||
try {
|
||||
ESValue value = evaluator.evaluate(s, object, true); // Can return null !
|
||||
if (value != null) obj = value.toJavaObject();
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
/*
|
||||
// This work but is less efficient
|
||||
evalAsFunction(s, null, null);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Evaluate a Reader stream with this object as the 'this' object.
|
||||
* Consider the stream being a function program, allowing the
|
||||
* return statement.
|
||||
* Passing the specified parameters (names and values must have the same length)
|
||||
*
|
||||
* @param r The Reader stream to evaluate
|
||||
* @param d A description of the Reader for error messages
|
||||
* @param names the names of the parameters
|
||||
* @param values the values of the parameters
|
||||
* @return The result of the evaluation (null if no value returned)
|
||||
* @exception JSException For any error during interpretation
|
||||
*/
|
||||
public Object evalAsFunction(Reader r, String d, String [] names, Object values[]) throws JSException {
|
||||
Object obj = null;
|
||||
throw new ProgrammingError("NOT IMPLEMENTED");
|
||||
/*
|
||||
synchronized (evaluator) {
|
||||
try {
|
||||
UserEvaluationSource ses;
|
||||
if (d==null) {
|
||||
ses = new UserEvaluationSource("<Anonymous stream>", null);
|
||||
} else {
|
||||
ses = new UserEvaluationSource(d, null);
|
||||
}
|
||||
ESValue value =
|
||||
evaluator.evaluate(r,
|
||||
object,
|
||||
ses,
|
||||
true);
|
||||
if (value != null) obj = value.toJavaObject();
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the evaluation of a string with this object as the 'this' object.
|
||||
* The string is considered a function (top level return are allowed)
|
||||
*
|
||||
* @param body The string to evaluate
|
||||
* @param names the names of the parameters
|
||||
* @param values the values of the parameters
|
||||
* @return The result of the evaluation (null if no value returned)
|
||||
* @exception JSException For any error during interpretation
|
||||
*/
|
||||
public Object evalAsFunction(String body, String [] names, Object values[]) throws JSException {
|
||||
Object obj = null;
|
||||
synchronized (evaluator) {
|
||||
try {
|
||||
// Create function
|
||||
int argLength = (names==null ? 0 : names.length);
|
||||
int checkLength = (values==null ? 0 : names.length);
|
||||
if (argLength!=checkLength) {
|
||||
throw new JSException("argument names and values arrays must have the same length, now: " +
|
||||
argLength + ", " + checkLength);
|
||||
}
|
||||
ESValue esArgs[] = new ESValue[argLength+1]; // space for body
|
||||
for (int i=0; i<argLength; i++) {
|
||||
esArgs[i] = new ESString(names[i]);
|
||||
}
|
||||
esArgs[argLength] = new ESString(body); // body is the last value
|
||||
ESObject fo = evaluator.getFunctionObject();
|
||||
ESObject theFunction = fo.doConstruct(null, esArgs);
|
||||
// Now call function
|
||||
esArgs = new ESValue[argLength]; // just what is needed
|
||||
for (int i=0; i<argLength; i++) {
|
||||
esArgs[i] = ESLoader.normalizeValue(values[i], this.evaluator);
|
||||
}
|
||||
ESValue value = theFunction.callFunction(object, esArgs);
|
||||
if (value != null) obj = value.toJavaObject();
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements the get named property of this object.
|
||||
*
|
||||
* @param name The name of the property to get
|
||||
* @return The value of the property
|
||||
* @exception JSException For any error during interpretation
|
||||
*/
|
||||
public Object getMember(String name) throws JSException {
|
||||
Object obj = null;
|
||||
synchronized (evaluator) {
|
||||
try {
|
||||
ESValue value = object.getProperty(name, name.hashCode());
|
||||
obj = value.toJavaObject();
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement the get indexed property of this object (useful for arrays).
|
||||
*
|
||||
* @param index The index value of the property (converted
|
||||
* to string if not an array)
|
||||
* @return The value of the property
|
||||
* @exception JSException For any error during interpretation
|
||||
*/
|
||||
public Object getSlot(int index) throws JSException {
|
||||
Object obj = null;
|
||||
synchronized (evaluator) {
|
||||
try {
|
||||
ESValue value = object.getProperty(index);
|
||||
obj = value.toJavaObject();
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
// This Netscape function is not implemented
|
||||
// public static JSObject getWindow(Applet applet) throws JSException;
|
||||
|
||||
/**
|
||||
* Implement the deletion of a named property of this object
|
||||
*
|
||||
* @param name The name of the property to delete
|
||||
* @exception JSException For any error during interpretation
|
||||
*/
|
||||
public void removeMember(String name) throws JSException {
|
||||
synchronized (evaluator) {
|
||||
try {
|
||||
object.deleteProperty(name, name.hashCode());
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
// return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the set value of a named property of this object
|
||||
*
|
||||
* @param name The name of the property to set
|
||||
* @param value The value to set the property to.
|
||||
* @exception JSException For any error during interpretation
|
||||
*/
|
||||
public void setMember(String name, Object value) throws JSException {
|
||||
synchronized (evaluator) {
|
||||
try {
|
||||
ESValue esvalue = ESLoader.normalizeValue(value, evaluator);
|
||||
object.putProperty(name, esvalue, name.hashCode());
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement the set property by index value. Useful for arrays.
|
||||
*
|
||||
* @param index The index of the property in the array.
|
||||
* @param value The value to set the property to.
|
||||
* @exception JSException For any error during interpretation
|
||||
*/
|
||||
public void setSlot(int index, Object value) throws JSException {
|
||||
synchronized (evaluator) {
|
||||
try {
|
||||
ESValue esvalue = ESLoader.normalizeValue(value, evaluator);
|
||||
object.putProperty(index, esvalue);
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Implement the creation of a new evaluator, with no extension loaded.
|
||||
*
|
||||
* @return The global object of the created evaluator.
|
||||
* @exception JSException For any error during initialization
|
||||
*/
|
||||
static public JSGlobalObject makeEvaluator() throws JSException {
|
||||
Evaluator evaluator = new Evaluator();
|
||||
GlobalObject go = evaluator.getGlobalObject();
|
||||
return new JSGlobalWrapper(go,evaluator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement the creation of a new evaluator, with specfied extensions loaded.
|
||||
*
|
||||
* @param extensions The class name of the extensions to load.
|
||||
* @return The global object of the created evaluator.
|
||||
* @exception JSException For any error during initialization
|
||||
*/
|
||||
static public JSGlobalObject makeEvaluator(String [] extensions) throws JSException {
|
||||
Evaluator evaluator = new Evaluator();
|
||||
GlobalObject go = evaluator.getGlobalObject();
|
||||
try {
|
||||
if (extensions != null) {
|
||||
for (int i =0; i<extensions.length; i++) {
|
||||
Object e = evaluator.addMandatoryExtension(extensions[i]);
|
||||
if (e==null) { // Should never happens
|
||||
throw new JSException ("Could not load extension '" + extensions[i] + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
return new JSGlobalWrapper(go,evaluator);
|
||||
} catch (EcmaScriptException e) {
|
||||
throw new JSException (e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a built-in function object from a JSFunction object, so that
|
||||
* it can be called as a standard function by native objects.
|
||||
* Parameters are transformed in JSobjects if possible Java primitives are
|
||||
* are left unhacnged and FESI primitives are transformed to Java primitives.
|
||||
* @param evaluator the Evaluator
|
||||
* @param jsf The function to wrap
|
||||
*/
|
||||
static public ESObject wrapJSFunction(Evaluator evaluator, JSFunction jsf) {
|
||||
synchronized (evaluator) {
|
||||
final JSFunction theFunction = jsf;
|
||||
class WrapedJSFunction extends BuiltinFunctionObject {
|
||||
WrapedJSFunction(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESValue value = ESUndefined.theUndefined;
|
||||
Object jsArguments[] = new Object[arguments.length];
|
||||
for (int i =0; i<arguments.length; i++) {
|
||||
if (arguments[i] instanceof ESWrapper) {
|
||||
jsArguments[i] = ((ESWrapper)arguments[i]).getJavaObject();
|
||||
} else if (arguments[i] instanceof ESObject) {
|
||||
jsArguments[i] = new JSWrapper((ESObject) arguments[i], this.evaluator);
|
||||
} else {
|
||||
jsArguments[i] = arguments[i].toJavaObject();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Object result = theFunction.doCall(
|
||||
new JSWrapper(thisObject, this.evaluator), jsArguments);
|
||||
value = ESLoader.normalizeValue(result, this.evaluator);
|
||||
} catch (JSException e) {
|
||||
throw new EcmaScriptException(e.getMessage());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESObject value = null;
|
||||
Object jsArguments[] = new Object[arguments.length];
|
||||
for (int i =0; i<arguments.length; i++) {
|
||||
if (arguments[i] instanceof ESWrapper) {
|
||||
jsArguments[i] = ((ESWrapper)arguments[i]).getJavaObject();
|
||||
} else if (arguments[i] instanceof ESObject) {
|
||||
jsArguments[i] = new JSWrapper((ESObject) arguments[i], this.evaluator);
|
||||
} else {
|
||||
jsArguments[i] = arguments[i].toJavaObject();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Object result = theFunction.doNew(
|
||||
new JSWrapper(thisObject, this.evaluator), jsArguments);
|
||||
value = ESLoader.normalizeObject(result, this.evaluator);
|
||||
} catch (JSException e) {
|
||||
throw new EcmaScriptException(e.getMessage());
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return new WrapedJSFunction(jsf.toString(),
|
||||
evaluator,
|
||||
(FunctionPrototype) evaluator.getFunctionPrototype());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the string value of the contained object
|
||||
* @return The string value
|
||||
*/
|
||||
public String toString() {
|
||||
return object.toString();
|
||||
}
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
// MathObject.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
/**
|
||||
* Implemements the EcmaScript Math singleton.
|
||||
*/
|
||||
public class MathObject extends ObjectPrototype {
|
||||
|
||||
private FunctionPrototype fp;
|
||||
|
||||
private MathObject(ESObject prototype, Evaluator evaluator, FunctionPrototype functionPrototype)
|
||||
throws EcmaScriptException {
|
||||
super(prototype, evaluator);
|
||||
|
||||
// Initialization used to be in makeMathObject, but this caused
|
||||
// some problemsto the users of JBuilder. So it is moved in
|
||||
// the constructor
|
||||
|
||||
putHiddenProperty("E", new ESNumber(Math.E));
|
||||
putHiddenProperty("LN10", new ESNumber(Math.log(10.0d)));
|
||||
putHiddenProperty("LN2", new ESNumber(Math.log(2.0d)));
|
||||
putHiddenProperty("LOG2E", new ESNumber(1.0d/Math.log(2.0d)));
|
||||
putHiddenProperty("LOG10E", new ESNumber(1.0d/Math.log(10.0d)));
|
||||
putHiddenProperty("PI", new ESNumber(Math.PI));
|
||||
putHiddenProperty("SQRT1_2", new ESNumber(1.0d/Math.sqrt(2.0d)));
|
||||
putHiddenProperty("SQRT2", new ESNumber(Math.sqrt(2.0d)));
|
||||
|
||||
putHiddenProperty("abs",
|
||||
new BuiltinMathFunctionOne("abs", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.abs(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("acos",
|
||||
new BuiltinMathFunctionOne("acos", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.acos(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("asin",
|
||||
new BuiltinMathFunctionOne("asin", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.asin(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("atan",
|
||||
new BuiltinMathFunctionOne("atan", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.atan(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("atan2",
|
||||
new BuiltinMathFunctionTwo("atan2", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg1, double arg2) {
|
||||
return Math.atan2(arg1,arg2);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("ceil",
|
||||
new BuiltinMathFunctionOne("ceil", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.ceil(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("cos",
|
||||
new BuiltinMathFunctionOne("cos", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.cos(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("exp",
|
||||
new BuiltinMathFunctionOne("exp", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.exp(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("floor",
|
||||
new BuiltinMathFunctionOne("floor", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.floor(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("log",
|
||||
new BuiltinMathFunctionOne("log", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.log(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("max",
|
||||
new BuiltinMathFunctionTwo("max", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg1, double arg2) {
|
||||
return Math.max(arg1,arg2);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("min",
|
||||
new BuiltinMathFunctionTwo("min", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg1, double arg2) {
|
||||
return Math.min(arg1,arg2);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("pow",
|
||||
new BuiltinMathFunctionTwo("pow", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg1, double arg2) {
|
||||
double d = Double.NaN;
|
||||
try {
|
||||
d = Math.pow(arg1,arg2);
|
||||
} catch (ArithmeticException e) {
|
||||
// return NaN
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("random",
|
||||
new BuiltinMathFunctionZero("random", evaluator, functionPrototype) {
|
||||
public double applyMathFunction() {
|
||||
return Math.random();
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("round",
|
||||
new BuiltinMathFunctionOne("round", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.round(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("sin",
|
||||
new BuiltinMathFunctionOne("sin", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.sin(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("sqrt",
|
||||
new BuiltinMathFunctionOne("sqrt", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.sqrt(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
putHiddenProperty("tan",
|
||||
new BuiltinMathFunctionOne("tan", evaluator, functionPrototype) {
|
||||
public double applyMathFunction(double arg) {
|
||||
return Math.tan(arg);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getESClassName() {
|
||||
return "Math";
|
||||
}
|
||||
|
||||
// class of nilary functions
|
||||
abstract class BuiltinMathFunctionZero extends BuiltinFunctionObject {
|
||||
BuiltinMathFunctionZero(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 0);
|
||||
}
|
||||
abstract double applyMathFunction();
|
||||
public ESValue callFunction(ESObject thisObject, ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
return new ESNumber(applyMathFunction());
|
||||
}
|
||||
}
|
||||
|
||||
// class of unary functions
|
||||
abstract class BuiltinMathFunctionOne extends BuiltinFunctionObject {
|
||||
BuiltinMathFunctionOne(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
abstract double applyMathFunction(double arg);
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
double arg = (arguments.length>0) ?
|
||||
arguments[0].doubleValue() :
|
||||
Double.NaN;
|
||||
if (Double.isNaN(arg)) {
|
||||
return new ESNumber(Double.NaN);
|
||||
}
|
||||
return new ESNumber(applyMathFunction(arg));
|
||||
}
|
||||
}
|
||||
|
||||
// class of dyadic functions
|
||||
abstract class BuiltinMathFunctionTwo extends BuiltinFunctionObject {
|
||||
BuiltinMathFunctionTwo(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 2);
|
||||
}
|
||||
abstract double applyMathFunction(double arg1, double arg2);
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (arguments.length<2) {
|
||||
throw new EcmaScriptException("Missing parameter in function " + this);
|
||||
}
|
||||
double arg1 = (arguments.length>0) ?
|
||||
arguments[0].doubleValue() :
|
||||
Double.NaN;
|
||||
double arg2 = (arguments.length>01) ?
|
||||
arguments[1].doubleValue() :
|
||||
Double.NaN;
|
||||
if (Double.isNaN(arg1) || Double.isNaN(arg2)) {
|
||||
return new ESNumber(Double.NaN);
|
||||
}
|
||||
return new ESNumber(applyMathFunction(arg1, arg2));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to create the Math single object
|
||||
*
|
||||
* @param evaluator the Evaluator
|
||||
* @param objectPrototype The Object prototype attached to the evaluator
|
||||
* @param functionPrototype The Function prototype attached to the evaluator
|
||||
*
|
||||
* @return the Math singleton
|
||||
*/
|
||||
static public ESObject makeMathObject (Evaluator evaluator,
|
||||
ObjectPrototype prototype,
|
||||
FunctionPrototype functionPrototype) {
|
||||
try {
|
||||
MathObject mo = new MathObject(prototype, evaluator, functionPrototype);
|
||||
return mo;
|
||||
} catch (EcmaScriptException e) {
|
||||
e.printStackTrace();
|
||||
throw new ProgrammingError(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
// NumberObject.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
|
||||
/**
|
||||
* Implemements the EcmaScript Number singleton.
|
||||
*/
|
||||
public class NumberObject extends BuiltinFunctionObject {
|
||||
|
||||
|
||||
private NumberObject(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator, "Number", 1);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return "<Number>";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (arguments.length==0) {
|
||||
return new ESNumber(0.0);
|
||||
} else {
|
||||
return new ESNumber(arguments[0].doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
NumberPrototype theObject = null;
|
||||
ESObject np = evaluator.getNumberPrototype();
|
||||
theObject= new NumberPrototype(np, evaluator);
|
||||
if (arguments.length>0) {
|
||||
theObject.value = new ESNumber(arguments[0].doubleValue());
|
||||
} else {
|
||||
theObject.value = new ESNumber(0.0);
|
||||
}
|
||||
return theObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to create the single Number object
|
||||
*
|
||||
* @param evaluator the Evaluator
|
||||
* @param objectPrototype The Object prototype attached to the evaluator
|
||||
* @param functionPrototype The Function prototype attached to the evaluator
|
||||
*
|
||||
* @return the Number singleton
|
||||
*/
|
||||
public static NumberObject makeNumberObject(Evaluator evaluator,
|
||||
ObjectPrototype objectPrototype,
|
||||
FunctionPrototype functionPrototype) {
|
||||
|
||||
|
||||
NumberPrototype numberPrototype = new NumberPrototype(objectPrototype, evaluator);
|
||||
NumberObject numberObject = new NumberObject(functionPrototype, evaluator);
|
||||
|
||||
try {
|
||||
|
||||
// For numberPrototype
|
||||
class NumberPrototypeToString extends BuiltinFunctionObject {
|
||||
NumberPrototypeToString(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESValue v = ((NumberPrototype) thisObject).value;
|
||||
String s = v.toString();
|
||||
if (arguments.length>0) {
|
||||
double d = arguments[0].doubleValue();
|
||||
if (!Double.isNaN(d)) {
|
||||
s = Long.toString(((long)v.doubleValue()),(int)d);
|
||||
}
|
||||
}
|
||||
return new ESString(s);
|
||||
}
|
||||
}
|
||||
class NumberPrototypeValueOf extends BuiltinFunctionObject {
|
||||
NumberPrototypeValueOf(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
return ((NumberPrototype) thisObject).value;
|
||||
}
|
||||
}
|
||||
|
||||
numberObject.putHiddenProperty("prototype",numberPrototype);
|
||||
numberObject.putHiddenProperty("length",new ESNumber(1));
|
||||
numberObject.putHiddenProperty("MAX_VALUE",new ESNumber(Double.MAX_VALUE));
|
||||
numberObject.putHiddenProperty("MIN_VALUE",new ESNumber(Double.MIN_VALUE));
|
||||
numberObject.putHiddenProperty("NaN",new ESNumber(Double.NaN));
|
||||
numberObject.putHiddenProperty("NEGATIVE_INFINITY",new ESNumber(Double.NEGATIVE_INFINITY));
|
||||
numberObject.putHiddenProperty("POSITIVE_INFINITY",new ESNumber(Double.POSITIVE_INFINITY));
|
||||
|
||||
numberPrototype.putHiddenProperty("constructor",numberObject);
|
||||
numberPrototype.putHiddenProperty("toString",
|
||||
new NumberPrototypeToString("toString", evaluator, functionPrototype));
|
||||
numberPrototype.putHiddenProperty("valueOf",
|
||||
new NumberPrototypeValueOf("valueOf", evaluator, functionPrototype));
|
||||
} catch (EcmaScriptException e) {
|
||||
e.printStackTrace();
|
||||
throw new ProgrammingError(e.getMessage());
|
||||
}
|
||||
|
||||
evaluator.setNumberPrototype(numberPrototype);
|
||||
|
||||
return numberObject;
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
// NumberPrototype.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
|
||||
/**
|
||||
* Implements the prototype and is the class of all Number objects
|
||||
*/
|
||||
class NumberPrototype extends ESObject {
|
||||
|
||||
// The value
|
||||
protected ESNumber value = new ESNumber(0.0);
|
||||
|
||||
/**
|
||||
* Create a new un-initialzed Number
|
||||
*/
|
||||
NumberPrototype(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String getESClassName() {
|
||||
return "Number";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean isNumberValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public double doubleValue() {
|
||||
return value.doubleValue();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public boolean booleanValue() {
|
||||
return value.booleanValue();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue toESNumber() throws EcmaScriptException {
|
||||
return value;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public Object toJavaObject() {
|
||||
return new Double(value.doubleValue());
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toDetailString() {
|
||||
return "ES:[Object: builtin " + this.getClass().getName() + ":" +
|
||||
((value == null) ? "null" : value.toString()) + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
// ObjectObject.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
/**
|
||||
* Implemements the EcmaScript Object singleton.
|
||||
*/
|
||||
public class ObjectObject extends BuiltinFunctionObject {
|
||||
|
||||
public ObjectObject(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator, "Object", 1);
|
||||
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return "<Object>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an EcmaScript Object for a specified evaluator
|
||||
* @param evaluator the Evaluator
|
||||
* @return the new object
|
||||
*/
|
||||
static public ObjectPrototype createObject(Evaluator evaluator) {
|
||||
ESObject op = evaluator.getObjectPrototype();
|
||||
return new ObjectPrototype(op, evaluator);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESValue theValue;
|
||||
if (arguments.length==0) {
|
||||
theValue = createObject(evaluator);
|
||||
} else {
|
||||
if (arguments[0] == ESNull.theNull ||
|
||||
arguments[0] == ESUndefined.theUndefined) {
|
||||
theValue = createObject(evaluator);
|
||||
} else {
|
||||
theValue = arguments[0].toESObject(evaluator);
|
||||
}
|
||||
}
|
||||
return (ESObject) theValue;
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue callFunction( ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESValue theValue;
|
||||
if (arguments.length==0) {
|
||||
theValue = createObject(evaluator);
|
||||
} else {
|
||||
if (arguments[0] == ESNull.theNull ||
|
||||
arguments[0] == ESUndefined.theUndefined) {
|
||||
theValue = createObject(evaluator);
|
||||
} else {
|
||||
theValue = arguments[0].toESObject(evaluator);
|
||||
}
|
||||
}
|
||||
return theValue;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
// ObjectPrototype.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Interpreter.Evaluator;
|
||||
import FESI.Exceptions.*;
|
||||
|
||||
/**
|
||||
* Implements the prototype and is the class of all Object objects.
|
||||
* <P>All functionality of objects is implemented in the superclass
|
||||
* ESObject.
|
||||
*/
|
||||
public class ObjectPrototype extends ESObject {
|
||||
|
||||
/**
|
||||
* Create a new Object with a specific prototype. This should be used
|
||||
* by routine implementing object with another prototype than Object.
|
||||
* To create an EcmaScript Object use ObjectObject.createObject()
|
||||
*
|
||||
* @param prototype the prototype of the new object
|
||||
* @param evaluator The evaluator
|
||||
*/
|
||||
public ObjectPrototype(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator);
|
||||
}
|
||||
}
|
|
@ -1,340 +0,0 @@
|
|||
// StringObject.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
/**
|
||||
* Implemements the EcmaScript String singleton.
|
||||
*/
|
||||
public class StringObject extends BuiltinFunctionObject {
|
||||
|
||||
|
||||
private StringObject(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator, "String", 1);
|
||||
}
|
||||
|
||||
// overrides
|
||||
public String toString() {
|
||||
return "<String>";
|
||||
}
|
||||
|
||||
// overrides
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
if (arguments.length==0) {
|
||||
return new ESString("");
|
||||
} else {
|
||||
return new ESString(arguments[0].toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// overrides
|
||||
public ESObject doConstruct(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
StringPrototype theObject = null;
|
||||
ESObject sp = evaluator.getStringPrototype();
|
||||
theObject= new StringPrototype(sp, evaluator);
|
||||
if (arguments.length>0) {
|
||||
theObject.value = new ESString(arguments[0].toString());
|
||||
} else {
|
||||
theObject.value = new ESString("");
|
||||
}
|
||||
return theObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to create the single String object
|
||||
*
|
||||
* @param evaluator the Evaluator
|
||||
* @param objectPrototype The Object prototype attached to the evaluator
|
||||
* @param functionPrototype The Function prototype attached to the evaluator
|
||||
*
|
||||
* @return the String singleton
|
||||
*/
|
||||
public static StringObject makeStringObject(Evaluator evaluator,
|
||||
ObjectPrototype objectPrototype,
|
||||
FunctionPrototype functionPrototype) {
|
||||
|
||||
StringPrototype stringPrototype = new StringPrototype(objectPrototype, evaluator);
|
||||
StringObject stringObject = new StringObject(functionPrototype, evaluator);
|
||||
|
||||
try {
|
||||
// For stringPrototype
|
||||
class StringPrototypeToString extends BuiltinFunctionObject {
|
||||
StringPrototypeToString(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
return ((StringPrototype) thisObject).value;
|
||||
}
|
||||
}
|
||||
|
||||
class StringPrototypeValueOf extends BuiltinFunctionObject {
|
||||
StringPrototypeValueOf(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
return ((StringPrototype) thisObject).value;
|
||||
}
|
||||
}
|
||||
|
||||
class StringPrototypeCharAt extends BuiltinFunctionObject {
|
||||
StringPrototypeCharAt(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
String str = thisObject.toString();
|
||||
int pos = 0;
|
||||
if (arguments.length>0) {
|
||||
pos = arguments[0].toInt32();
|
||||
}
|
||||
if (pos>=0 && pos <str.length()) {
|
||||
char c[] = {str.charAt(pos)};
|
||||
return new ESString(new String(c));
|
||||
} else {
|
||||
return new ESString("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class StringPrototypeCharCodeAt extends BuiltinFunctionObject {
|
||||
StringPrototypeCharCodeAt(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
String str = thisObject.toString();
|
||||
int pos = 0;
|
||||
if (arguments.length>0) {
|
||||
pos = arguments[0].toInt32();
|
||||
}
|
||||
if (pos>=0 && pos <str.length()) {
|
||||
char c = str.charAt(pos);
|
||||
return new ESNumber((double) c);
|
||||
} else {
|
||||
return new ESNumber(Double.NaN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class StringPrototypeIndexOf extends BuiltinFunctionObject {
|
||||
StringPrototypeIndexOf(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
String str = thisObject.toString();
|
||||
int pos = 0;
|
||||
if (arguments.length<=0) {
|
||||
return new ESNumber(-1);
|
||||
}
|
||||
String searched = arguments[0].toString();
|
||||
if (arguments.length>1) {
|
||||
pos = arguments[1].toInt32();
|
||||
}
|
||||
int res = str.indexOf(searched, pos);
|
||||
return new ESNumber(res);
|
||||
}
|
||||
}
|
||||
|
||||
class StringPrototypeLastIndexOf extends BuiltinFunctionObject {
|
||||
StringPrototypeLastIndexOf(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
String str = thisObject.toString();
|
||||
int pos = str.length();
|
||||
if (arguments.length<=0) {
|
||||
return new ESNumber(-1);
|
||||
}
|
||||
String searched = arguments[0].toString();
|
||||
if (arguments.length>1) {
|
||||
double p = arguments[1].doubleValue();
|
||||
if (!Double.isNaN(p)) pos = arguments[1].toInt32();
|
||||
}
|
||||
int res = str.lastIndexOf(searched, pos);
|
||||
return new ESNumber(res);
|
||||
}
|
||||
}
|
||||
|
||||
// This code is replaced by the ReegExp variant when RegExp is loaded
|
||||
class StringPrototypeSplit extends BuiltinFunctionObject {
|
||||
StringPrototypeSplit(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
String str = thisObject.toString();
|
||||
ESObject ap = this.evaluator.getArrayPrototype();
|
||||
ArrayPrototype theArray = new ArrayPrototype(ap, this.evaluator);
|
||||
if (arguments.length<=0) {
|
||||
theArray.setSize(1);
|
||||
theArray.setElementAt(thisObject, 0);
|
||||
} else {
|
||||
String sep = arguments[0].toString();
|
||||
if (sep.length()==0) {
|
||||
int l = str.length();
|
||||
theArray.setSize(l);
|
||||
for (int i=0; i<l; i++) {
|
||||
theArray.setElementAt(
|
||||
new ESString(str.substring(i,i+1)), i);
|
||||
}
|
||||
} else {
|
||||
int i = 0;
|
||||
int start = 0;
|
||||
while (start<str.length()) {
|
||||
int pos = str.indexOf(sep, start);
|
||||
if (pos<0) pos = str.length();
|
||||
// System.out.println("start: " + start + ", pos: " + pos);
|
||||
theArray.setSize(i+1);
|
||||
theArray.setElementAt(
|
||||
new ESString(str.substring(start, pos)),i);
|
||||
start = pos + sep.length();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return theArray;
|
||||
}
|
||||
}
|
||||
|
||||
class StringPrototypeSubstring extends BuiltinFunctionObject {
|
||||
StringPrototypeSubstring(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
String str = thisObject.toString();
|
||||
int start = 0;
|
||||
int end = str.length();
|
||||
if (arguments.length>0) {
|
||||
start = arguments[0].toInt32();
|
||||
}
|
||||
if (start<0) start = 0;
|
||||
else if (start>str.length()) start = str.length();
|
||||
if (arguments.length>1) {
|
||||
end = arguments[1].toInt32();
|
||||
if (end<0) end = 0;
|
||||
else if (end>str.length()) end = str.length();
|
||||
}
|
||||
if (start>end) {
|
||||
int x = start; start = end; end = x;
|
||||
}
|
||||
return new ESString(str.substring(start, end));
|
||||
}
|
||||
}
|
||||
|
||||
class StringPrototypeToLowerCase extends BuiltinFunctionObject {
|
||||
StringPrototypeToLowerCase(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
String str = thisObject.toString();
|
||||
|
||||
return new ESString(str.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
class StringPrototypeToUpperCase extends BuiltinFunctionObject {
|
||||
StringPrototypeToUpperCase(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
String str = thisObject.toString();
|
||||
|
||||
return new ESString(str.toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
// For stringObject
|
||||
class StringObjectFromCharCode extends BuiltinFunctionObject {
|
||||
StringObjectFromCharCode(String name, Evaluator evaluator, FunctionPrototype fp) {
|
||||
super(fp, evaluator, name, 1);
|
||||
}
|
||||
public ESValue callFunction(ESObject thisObject,
|
||||
ESValue[] arguments)
|
||||
throws EcmaScriptException {
|
||||
ESObject sp = this.evaluator.getStringPrototype();
|
||||
StringPrototype theObject= new StringPrototype(sp, this.evaluator);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i =0; i<arguments.length; i++) {
|
||||
char c = (char)(arguments[i].toUInt16());
|
||||
sb.append(c);
|
||||
}
|
||||
theObject.value = new ESString(sb.toString());
|
||||
return theObject;
|
||||
}
|
||||
}
|
||||
|
||||
stringObject.putHiddenProperty("prototype",stringPrototype);
|
||||
stringObject.putHiddenProperty("length",new ESNumber(1));
|
||||
stringObject.putHiddenProperty("fromCharCode",
|
||||
new StringObjectFromCharCode("fromCharCode", evaluator, functionPrototype));
|
||||
|
||||
stringPrototype.putHiddenProperty("constructor",stringObject);
|
||||
stringPrototype.putHiddenProperty("toString",
|
||||
new StringPrototypeToString("toString", evaluator, functionPrototype));
|
||||
stringPrototype.putHiddenProperty("valueOf",
|
||||
new StringPrototypeValueOf("valueOf", evaluator, functionPrototype));
|
||||
stringPrototype.putHiddenProperty("charAt",
|
||||
new StringPrototypeCharAt("charAt", evaluator, functionPrototype));
|
||||
stringPrototype.putHiddenProperty("charCodeAt",
|
||||
new StringPrototypeCharCodeAt("charCodeAt", evaluator, functionPrototype));
|
||||
stringPrototype.putHiddenProperty("indexOf",
|
||||
new StringPrototypeIndexOf("indexOf", evaluator, functionPrototype));
|
||||
stringPrototype.putHiddenProperty("lastIndexOf",
|
||||
new StringPrototypeLastIndexOf("lastIndexOf", evaluator, functionPrototype));
|
||||
stringPrototype.putHiddenProperty("split",
|
||||
new StringPrototypeSplit("split", evaluator, functionPrototype));
|
||||
stringPrototype.putHiddenProperty("substring",
|
||||
new StringPrototypeSubstring("substring", evaluator, functionPrototype));
|
||||
stringPrototype.putHiddenProperty("toLowerCase",
|
||||
new StringPrototypeToLowerCase("toLowerCase", evaluator, functionPrototype));
|
||||
stringPrototype.putHiddenProperty("toUpperCase",
|
||||
new StringPrototypeToUpperCase("toUpperCase", evaluator, functionPrototype));
|
||||
} catch (EcmaScriptException e) {
|
||||
e.printStackTrace();
|
||||
throw new ProgrammingError(e.getMessage());
|
||||
}
|
||||
|
||||
evaluator.setStringPrototype(stringPrototype);
|
||||
|
||||
return stringObject;
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
// StringPrototype.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
import FESI.Exceptions.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
class StringPrototype extends ESObject {
|
||||
|
||||
private static final String LENGTHstring = ("length").intern();
|
||||
private static final int LENGTHhash = LENGTHstring.hashCode();
|
||||
|
||||
ESString value = new ESString("");
|
||||
|
||||
StringPrototype(ESObject prototype, Evaluator evaluator) {
|
||||
super(prototype, evaluator);
|
||||
}
|
||||
public String getESClassName() {
|
||||
return "String";
|
||||
}
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
public ESValue toESString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public boolean booleanValue() throws EcmaScriptException {
|
||||
return value.booleanValue();
|
||||
}
|
||||
|
||||
public double doubleValue() throws EcmaScriptException {
|
||||
return value.doubleValue();
|
||||
}
|
||||
|
||||
public ESValue getPropertyInScope(String propertyName, ScopeChain previousScope, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (hash==LENGTHhash && propertyName.equals(LENGTHstring)) {
|
||||
return new ESNumber(value.getStringLength());
|
||||
}
|
||||
return super.getPropertyInScope(propertyName, previousScope, hash);
|
||||
}
|
||||
|
||||
public ESValue getProperty(String propertyName, int hash)
|
||||
throws EcmaScriptException {
|
||||
if (hash==LENGTHhash && propertyName.equals(LENGTHstring)) {
|
||||
return new ESNumber(value.getStringLength());
|
||||
} else {
|
||||
return super.getProperty(propertyName, hash);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String[] getSpecialPropertyNames() {
|
||||
String [] ns = {LENGTHstring};
|
||||
return ns;
|
||||
}
|
||||
|
||||
public Object toJavaObject() {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
public String toDetailString() {
|
||||
return "ES:[Object: builtin " + this.getClass().getName() + ":" +
|
||||
((value == null) ? "null" : value.toString()) + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Information routine to check if a value is a string
|
||||
* if true, must implement toString without a evaluator.
|
||||
* @return true
|
||||
*/
|
||||
public boolean isStringValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
// ValueDescription.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Data;
|
||||
|
||||
/**
|
||||
* A ValueDescription is used to describe the property or field of
|
||||
* an object (for debugging tools).
|
||||
*/
|
||||
public class ValueDescription {
|
||||
|
||||
private static String eol = System.getProperty("line.separator", "\n");
|
||||
|
||||
/**
|
||||
* The name of this value (for example the property name
|
||||
* if it is a property), null if not known or irrelevant.
|
||||
*/
|
||||
public String name = null;
|
||||
|
||||
|
||||
/**
|
||||
* The string describing the type of this value.
|
||||
*/
|
||||
public String type;
|
||||
|
||||
/**
|
||||
* The string describing the value.
|
||||
*/
|
||||
public String value;
|
||||
|
||||
|
||||
/**
|
||||
* Build a value descriptor for an unknown name
|
||||
*/
|
||||
public ValueDescription (String type, String value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a value descriptor for a specified name
|
||||
*/
|
||||
public ValueDescription (String name, String type, String value) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String propertyValue = value;
|
||||
// Remove leading eol
|
||||
while (propertyValue.indexOf("\n")==0) {
|
||||
propertyValue = propertyValue.substring(1);
|
||||
}
|
||||
while (propertyValue.indexOf(eol)==0) {
|
||||
propertyValue = propertyValue.substring(eol.length());
|
||||
}
|
||||
// limit size
|
||||
if (propertyValue.length()>250) {
|
||||
propertyValue = propertyValue.substring(0,250) + "...";
|
||||
}
|
||||
// keep only first line
|
||||
int ieol = propertyValue.indexOf(eol);
|
||||
if (ieol==-1) ieol = propertyValue.indexOf("\n");
|
||||
if (ieol!=-1) {
|
||||
propertyValue = propertyValue.substring(0,ieol) + "...";
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
return type + ": " + propertyValue;
|
||||
} else {
|
||||
return name + ": [" + type + "]: " + propertyValue;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,184 +0,0 @@
|
|||
// EcmaScriptException.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Exceptions;
|
||||
|
||||
import java.util.Vector;
|
||||
import FESI.Interpreter.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Superclass of all common exceptions used by the FESI system
|
||||
*/
|
||||
public class EcmaScriptException extends Exception {
|
||||
|
||||
/**
|
||||
* The end of line string for this machine.
|
||||
*/
|
||||
static protected String eol = System.getProperty("line.separator", "\n");
|
||||
|
||||
|
||||
/**
|
||||
* The list of EcmaScript evaluation sources at this error
|
||||
* @serial EcmaScritp sources callback
|
||||
*/
|
||||
protected Vector evaluationSources = new Vector();
|
||||
|
||||
/**
|
||||
* @serial The original exception which trigerred this exception
|
||||
*/
|
||||
private Throwable originatingException = null; // If the exception package another one
|
||||
|
||||
|
||||
/**
|
||||
* Create a generic exception with cause "reason"
|
||||
*
|
||||
* @param reason the reason of the exception
|
||||
*/
|
||||
public EcmaScriptException(String reason) {
|
||||
super(reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a generic exception with cause "reason", originially caused
|
||||
* by the originatingException
|
||||
*
|
||||
* @param reason the reason of the exception
|
||||
* @param originatingException the original exception creating this exception
|
||||
*/
|
||||
public EcmaScriptException(String reason, Throwable originatingException) {
|
||||
super(reason);
|
||||
this.originatingException = originatingException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the originating exception (if any) or null
|
||||
*
|
||||
* @return originating exception or null.
|
||||
*/
|
||||
public Throwable getOriginatingException() {
|
||||
return originatingException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append an evaluation source to the list of evaluation sources
|
||||
*
|
||||
* @param es The evaluation source to add
|
||||
*/
|
||||
public void appendEvaluationSource(EvaluationSource es) {
|
||||
evaluationSources.addElement(es);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line number of the error if possible
|
||||
*/
|
||||
public int getLineNumber() {
|
||||
|
||||
if (evaluationSources.size()>0) {
|
||||
EvaluationSource es = (EvaluationSource) evaluationSources.elementAt(0);
|
||||
return es.getLineNumber();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the message, the originating exception and the
|
||||
* EmcaScript callback chain.
|
||||
* <P>If cause by another exception displays its callback chain
|
||||
*/
|
||||
public String getMessage() {
|
||||
String msg = super.getMessage();
|
||||
if (originatingException!=null) {
|
||||
msg += eol + "Caused by exception: " + eol + " " + originatingException.getMessage();
|
||||
}
|
||||
if (originatingException != null) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
originatingException.printStackTrace(pw);
|
||||
msg += eol;
|
||||
pw.close();
|
||||
/*
|
||||
// THIS WAS NOT NEEDED AND IS AN INCOMPATIBILITY
|
||||
// BETWEEN JDK 1.1/.2
|
||||
try {
|
||||
sw.close();
|
||||
if (false) throw new IOException(); // to make JDK 1.1 Happy
|
||||
} catch (IOException ignore) {
|
||||
; // To make JDK 1.2 happy
|
||||
}
|
||||
*/
|
||||
msg += sw.toString();
|
||||
}
|
||||
for (int i = 0; i<evaluationSources.size(); i++) {
|
||||
EvaluationSource es = (EvaluationSource) evaluationSources.elementAt(i);
|
||||
msg += eol + (i==0 ? "detected " : "called ") + es;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* If true would the the parser error detected when a statement is incomplete.
|
||||
*/
|
||||
public boolean isIncomplete() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints this <code>Throwable</code> and its backtrace to the
|
||||
* standard error stream.
|
||||
*/
|
||||
public void printStackTrace() {
|
||||
// System.err.println(this);
|
||||
printStackTrace0(new PrintWriter(System.err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints this <code>Throwable</code> and its backtrace to the
|
||||
* specified print stream.
|
||||
*/
|
||||
public void printStackTrace(java.io.PrintStream s) {
|
||||
s.println(this);
|
||||
PrintWriter w = new PrintWriter(s);
|
||||
printStackTrace0(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints this <code>Throwable</code> and its backtrace to the specified
|
||||
* print writer.
|
||||
*/
|
||||
public void printStackTrace(java.io.PrintWriter w) {
|
||||
w.println(this);
|
||||
printStackTrace0(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the stack trace to a stream, with the backtrace of
|
||||
* the originating exception if any.
|
||||
*/
|
||||
private void printStackTrace0(PrintWriter w) {
|
||||
super.printStackTrace(w);
|
||||
|
||||
if (originatingException != null) {
|
||||
w.println("due to:");
|
||||
originatingException.printStackTrace(w);
|
||||
}
|
||||
w.flush();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
// EcmaScriptLexicalException.java
|
||||
// FESI Copyright (c) Jean-Marc Lugrin, 1999
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package FESI.Exceptions;
|
||||
|
||||
import FESI.Parser.*;
|
||||
import FESI.Interpreter.*;
|
||||
|
||||
/**
|
||||
* Exception used to signal lexical error during parsing
|
||||
*/
|
||||
public class EcmaScriptLexicalException extends EcmaScriptException
|
||||
implements EcmaScriptConstants {
|
||||
|
||||
/** @serial Token creating the error */
|
||||
private TokenMgrError tokenMgrError;
|
||||
|
||||
/** @serial Identification of source creating the error */
|
||||
private EvaluationSource evaluationSource;
|
||||
|
||||
/**
|
||||
* Create a new lexical exception
|
||||
*
|
||||
* @param e The error from the token manager
|
||||
* @param s The evaluation source location of the error
|
||||
*/
|
||||
public EcmaScriptLexicalException(TokenMgrError e, EvaluationSource s) {
|
||||
super("Lexical error");
|
||||
tokenMgrError = e;
|
||||
evaluationSource = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line number of the error if possible
|
||||
*/
|
||||
public int getLineNumber() {
|
||||
|
||||
if (evaluationSource != null) {
|
||||
return evaluationSource.getLineNumber();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the text of the token error and the location
|
||||
*/
|
||||
public String getMessage() {
|
||||
String retval = tokenMgrError.getMessage();
|
||||
retval += eol + evaluationSource;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true in case of unclosed comment, as in this case
|
||||
* the statement is not complete and the user may be prompted
|
||||
* to complete the statement.
|
||||
*/
|
||||
public boolean isIncomplete() {
|
||||
String s = tokenMgrError.getMessage();
|
||||
return s.indexOf(". Probably unclosed comment.")!= -1;
|
||||
// See TokenMgrError
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue