diff options
author | patriot1burke <patriot1burke@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2003-04-22 13:47:06 +0000 |
---|---|---|
committer | patriot1burke <patriot1burke@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2003-04-22 13:47:06 +0000 |
commit | 069bceaf72fd0d6ffad14ce4e3e00ca91a280bde (patch) | |
tree | b8230a15d3061c64d5a64bf9efa654d0d6311ff2 /src/main/javassist/compiler/ast | |
parent | f610083ba0adbcb3fe92a504015fb26fb5a42530 (diff) | |
download | javassist-069bceaf72fd0d6ffad14ce4e3e00ca91a280bde.tar.gz javassist-069bceaf72fd0d6ffad14ce4e3e00ca91a280bde.zip |
This commit was generated by cvs2svn to compensate for changes in r2, which
included commits to RCS files with non-trunk default branches.
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@6 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/compiler/ast')
22 files changed, 1399 insertions, 0 deletions
diff --git a/src/main/javassist/compiler/ast/ASTList.java b/src/main/javassist/compiler/ast/ASTList.java new file mode 100644 index 00000000..887a528a --- /dev/null +++ b/src/main/javassist/compiler/ast/ASTList.java @@ -0,0 +1,169 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * A linked list. + * The right subtree must be an ASTList object or null. + */ +public class ASTList extends ASTree { + private ASTree left; + private ASTList right; + + public ASTList(ASTree _head, ASTList _tail) { + left = _head; + right = _tail; + } + + public ASTList(ASTree _head) { + left = _head; + right = null; + } + + public static ASTList make(ASTree e1, ASTree e2, ASTree e3) { + return new ASTList(e1, new ASTList(e2, new ASTList(e3))); + } + + public ASTree getLeft() { return left; } + + public ASTree getRight() { return right; } + + public void setLeft(ASTree _left) { left = _left; } + + public void setRight(ASTree _right) { + right = (ASTList)_right; + } + + /** + * Returns the car part of the list. + */ + public ASTree head() { return left; } + + public void setHead(ASTree _head) { + left = _head; + } + + /** + * Returns the cdr part of the list. + */ + public ASTList tail() { return right; } + + public void setTail(ASTList _tail) { + right = _tail; + } + + public void accept(Visitor v) throws CompileError { v.atASTList(this); } + + public String toString() { + StringBuffer sbuf = new StringBuffer(); + sbuf.append("(<"); + sbuf.append(getTag()); + sbuf.append('>'); + ASTList list = this; + while (list != null) { + sbuf.append(' '); + ASTree a = list.left; + sbuf.append(a == null ? "<null>" : a.toString()); + list = list.right; + } + + sbuf.append(')'); + return sbuf.toString(); + } + + /** + * Returns the number of the elements in this list. + */ + public int length() { + return length(this); + } + + public static int length(ASTList list) { + if (list == null) + return 0; + + int n = 0; + while (list != null) { + list = list.right; + ++n; + } + + return n; + } + + /** + * Returns a sub list of the list. The sub list begins with the + * n-th element of the list. + * + * @param nth zero or more than zero. + */ + public ASTList sublist(int nth) { + ASTList list = this; + while (nth-- > 0) + list = list.right; + + return list; + } + + /** + * Substitutes <code>newObj</code> for <code>oldObj</code> in the + * list. + */ + public boolean subst(ASTree newObj, ASTree oldObj) { + for (ASTList list = this; list != null; list = list.right) + if (list.left == oldObj) { + list.left = newObj; + return true; + } + + return false; + } + + /** + * Appends an object to a list. + */ + public static ASTList append(ASTList a, ASTree b) { + return concat(a, new ASTList(b)); + } + + /** + * Concatenates two lists. + */ + public static ASTList concat(ASTList a, ASTList b) { + if (a == null) + return b; + else { + ASTList list = a; + while (list.right != null) + list = list.right; + + list.right = b; + return a; + } + } +} diff --git a/src/main/javassist/compiler/ast/ASTree.java b/src/main/javassist/compiler/ast/ASTree.java new file mode 100644 index 00000000..72825142 --- /dev/null +++ b/src/main/javassist/compiler/ast/ASTree.java @@ -0,0 +1,68 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import java.io.Serializable; +import javassist.compiler.CompileError; + +/** + * Abstract Syntax Tree. An ASTree object represents a node of + * a binary tree. If the node is a leaf node, both <code>getLeft()</code> + * and <code>getRight()</code> returns null. + */ +public abstract class ASTree implements Serializable { + public ASTree getLeft() { return null; } + + public ASTree getRight() { return null; } + + public void setLeft(ASTree _left) {} + + public void setRight(ASTree _right) {} + + /** + * Is a method for the visitor pattern. It calls + * <code>atXXX()</code> on the given visitor, where + * <code>XXX</code> is the class name of the node object. + */ + public abstract void accept(Visitor v) throws CompileError; + + public String toString() { + StringBuffer sbuf = new StringBuffer(); + sbuf.append('<'); + sbuf.append(getTag()); + sbuf.append('>'); + return sbuf.toString(); + } + + /** + * Returns the type of this node. This method is used by + * <code>toString()</code>. + */ + protected String getTag() { + String name = getClass().getName(); + return name.substring(name.lastIndexOf('.') + 1); + } +} diff --git a/src/main/javassist/compiler/ast/AssignExpr.java b/src/main/javassist/compiler/ast/AssignExpr.java new file mode 100644 index 00000000..0a062d46 --- /dev/null +++ b/src/main/javassist/compiler/ast/AssignExpr.java @@ -0,0 +1,50 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * Assignment expression. + */ +public class AssignExpr extends Expr { + /* operator must be either of: + * =, %=, &=, *=, +=, -=, /=, ^=, |=, <<=, >>=, >>>= + */ + + public AssignExpr(int op, ASTree _head, ASTList _tail) { + super(op, _head, _tail); + } + + public static AssignExpr makeAssign(int op, ASTree oprand1, + ASTree oprand2) { + return new AssignExpr(op, oprand1, new ASTList(oprand2)); + } + + public void accept(Visitor v) throws CompileError { + v.atAssignExpr(this); + } +} diff --git a/src/main/javassist/compiler/ast/BinExpr.java b/src/main/javassist/compiler/ast/BinExpr.java new file mode 100644 index 00000000..a8fdeb62 --- /dev/null +++ b/src/main/javassist/compiler/ast/BinExpr.java @@ -0,0 +1,48 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * Binary expression. + */ +public class BinExpr extends Expr { + /* operator must be either of: + * ||, &&, |, ^, &, ==, !=, <=, >=, <, >, + * <<, >>, >>>, +, -, *, /, % + */ + + public BinExpr(int op, ASTree _head, ASTList _tail) { + super(op, _head, _tail); + } + + public static BinExpr makeBin(int op, ASTree oprand1, ASTree oprand2) { + return new BinExpr(op, oprand1, new ASTList(oprand2)); + } + + public void accept(Visitor v) throws CompileError { v.atBinExpr(this); } +} diff --git a/src/main/javassist/compiler/ast/CastExpr.java b/src/main/javassist/compiler/ast/CastExpr.java new file mode 100644 index 00000000..7f8775cb --- /dev/null +++ b/src/main/javassist/compiler/ast/CastExpr.java @@ -0,0 +1,63 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.TokenId; +import javassist.compiler.CompileError; + +/** + * Cast expression. + */ +public class CastExpr extends ASTList implements TokenId { + protected int castType; + protected int arrayDim; + + public CastExpr(ASTList className, int dim, ASTree expr) { + super(className, new ASTList(expr)); + castType = CLASS; + arrayDim = dim; + } + + public CastExpr(int type, int dim, ASTree expr) { + super(null, new ASTList(expr)); + castType = type; + arrayDim = dim; + } + + /* Returns CLASS, BOOLEAN, INT, or ... + */ + public int getType() { return castType; } + + public int getArrayDim() { return arrayDim; } + + public ASTList getClassName() { return (ASTList)getLeft(); } + + public ASTree getOprand() { return getRight().getLeft(); } + + public String getTag() { return "cast:" + castType + ":" + arrayDim; } + + public void accept(Visitor v) throws CompileError { v.atCastExpr(this); } +} diff --git a/src/main/javassist/compiler/ast/CondExpr.java b/src/main/javassist/compiler/ast/CondExpr.java new file mode 100644 index 00000000..d4a8a108 --- /dev/null +++ b/src/main/javassist/compiler/ast/CondExpr.java @@ -0,0 +1,47 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * Conditional expression. + */ +public class CondExpr extends ASTList { + public CondExpr(ASTree cond, ASTree thenp, ASTree elsep) { + super(cond, new ASTList(thenp, new ASTList(elsep))); + } + + public ASTree condExpr() { return head(); } + + public ASTree thenExpr() { return tail().head(); } + + public ASTree elseExpr() { return tail().tail().head(); } + + public String getTag() { return "?:"; } + + public void accept(Visitor v) throws CompileError { v.atCondExpr(this); } +} diff --git a/src/main/javassist/compiler/ast/Declarator.java b/src/main/javassist/compiler/ast/Declarator.java new file mode 100644 index 00000000..edeb839d --- /dev/null +++ b/src/main/javassist/compiler/ast/Declarator.java @@ -0,0 +1,128 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.TokenId; +import javassist.compiler.CompileError; + +/** + * Variable declarator. + */ +public class Declarator extends ASTList implements TokenId { + protected int varType; + protected int arrayDim; + protected int localVar; + protected String qualifiedClass; // JVM-internal representation + + public Declarator(int type, int dim) { + super(null); + varType = type; + arrayDim = dim; + localVar = -1; + qualifiedClass = null; + } + + public Declarator(ASTList className, int dim) { + super(null); + varType = CLASS; + arrayDim = dim; + localVar = -1; + qualifiedClass = astToClassName(className, '/'); + } + + /* For declaring a pre-defined? local variable. + */ + public Declarator(int type, String jvmClassName, int dim, + int var, Symbol sym) { + super(null); + varType = type; + arrayDim = dim; + localVar = var; + qualifiedClass = jvmClassName; + setLeft(sym); + append(this, null); // initializer + } + + public Declarator make(Symbol sym, int dim, ASTree init) { + Declarator d = new Declarator(this.varType, this.arrayDim + dim); + d.qualifiedClass = this.qualifiedClass; + d.setLeft(sym); + d.append(d, init); + return d; + } + + /* Returns CLASS, BOOLEAN, BYTE, CHAR, SHORT, INT, LONG, FLOAT, + * or DOUBLE (or VOID) + */ + public int getType() { return varType; } + + public int getArrayDim() { return arrayDim; } + + public void addArrayDim(int d) { arrayDim += d; } + + public String getClassName() { return qualifiedClass; } + + public void setClassName(String s) { qualifiedClass = s; } + + public Symbol getVariable() { return (Symbol)getLeft(); } + + public void setVariable(Symbol sym) { setLeft(sym); } + + public ASTree getInitializer() { + ASTList t = tail(); + if (t != null) + return t.head(); + else + return null; + } + + public void setLocalVar(int n) { localVar = n; } + + public int getLocalVar() { return localVar; } + + public String getTag() { return "decl"; } + + public void accept(Visitor v) throws CompileError { + v.atDeclarator(this); + } + + public static String astToClassName(ASTList name, char sep) { + if (name == null) + return null; + + StringBuffer sbuf = new StringBuffer(); + for (;;) { + sbuf.append(((Symbol)name.head()).get()); + name = name.tail(); + if (name == null) + break; + + sbuf.append(sep); + } + + return sbuf.toString(); + } +} diff --git a/src/main/javassist/compiler/ast/DoubleConst.java b/src/main/javassist/compiler/ast/DoubleConst.java new file mode 100644 index 00000000..459f030f --- /dev/null +++ b/src/main/javassist/compiler/ast/DoubleConst.java @@ -0,0 +1,50 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * Double constant. + */ +public class DoubleConst extends ASTree { + protected double value; + protected int type; + + public DoubleConst(double v, int tokenId) { value = v; type = tokenId; } + + public double get() { return value; } + + /* Returns DoubleConstant or FloatConstant + */ + public int getType() { return type; } + + public String toString() { return Double.toString(value); } + + public void accept(Visitor v) throws CompileError { + v.atDoubleConst(this); + } +} diff --git a/src/main/javassist/compiler/ast/Expr.java b/src/main/javassist/compiler/ast/Expr.java new file mode 100644 index 00000000..1fecc9ce --- /dev/null +++ b/src/main/javassist/compiler/ast/Expr.java @@ -0,0 +1,80 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.TokenId; +import javassist.compiler.CompileError; + +/** + * Expression. + */ +public class Expr extends ASTList implements TokenId { + /* operator must be either of: + * (unary) +, (unary) -, ++, --, !, ~, + * CALL, ARRAY, . (dot), MEMBER (static member access). + * Otherwise, the object should be an instance of a subclass. + */ + + protected int operatorId; + + public Expr(int op, ASTree _head, ASTList _tail) { + super(_head, _tail); + operatorId = op; + } + + public Expr(int op, ASTree _head) { + super(_head); + operatorId = op; + } + + public static Expr make(int op, ASTree oprand1, ASTree oprand2) { + return new Expr(op, oprand1, new ASTList(oprand2)); + } + + public int getOperator() { return operatorId; } + + public ASTree oprand1() { return getLeft(); } + + public ASTree oprand2() { return getRight().getLeft(); } + + public void accept(Visitor v) throws CompileError { v.atExpr(this); } + + public String getName() { + int id = operatorId; + if (id < 128) + return String.valueOf((char)id); + else if (NEQ <= id && id <= ARSHIFT_E) + return opNames[id - NEQ]; + else if (id == INSTANCEOF) + return "instanceof"; + else + return String.valueOf(id); + } + + protected String getTag() { + return "op:" + getName(); + } +} diff --git a/src/main/javassist/compiler/ast/FieldDecl.java b/src/main/javassist/compiler/ast/FieldDecl.java new file mode 100644 index 00000000..d57dd632 --- /dev/null +++ b/src/main/javassist/compiler/ast/FieldDecl.java @@ -0,0 +1,44 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +public class FieldDecl extends ASTList { + public FieldDecl(ASTree _head, ASTList _tail) { + super(_head, _tail); + } + + public ASTList getModifiers() { return (ASTList)getLeft(); } + + public Declarator getDeclarator() { return (Declarator)tail().head(); } + + public ASTree getInit() { return (ASTree)sublist(2).head(); } + + public void accept(Visitor v) throws CompileError { + v.atFieldDecl(this); + } +} diff --git a/src/main/javassist/compiler/ast/InstanceOfExpr.java b/src/main/javassist/compiler/ast/InstanceOfExpr.java new file mode 100644 index 00000000..03d6bc1f --- /dev/null +++ b/src/main/javassist/compiler/ast/InstanceOfExpr.java @@ -0,0 +1,49 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * Instanceof expression. + */ +public class InstanceOfExpr extends CastExpr { + public InstanceOfExpr(ASTList className, int dim, ASTree expr) { + super(className, dim, expr); + } + + public InstanceOfExpr(int type, int dim, ASTree expr) { + super(type, dim, expr); + } + + public String getTag() { + return "instanceof:" + castType + ":" + arrayDim; + } + + public void accept(Visitor v) throws CompileError { + v.atInstanceOfExpr(this); + } +} diff --git a/src/main/javassist/compiler/ast/IntConst.java b/src/main/javassist/compiler/ast/IntConst.java new file mode 100644 index 00000000..63ce70cb --- /dev/null +++ b/src/main/javassist/compiler/ast/IntConst.java @@ -0,0 +1,50 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * Integer constant. + */ +public class IntConst extends ASTree { + protected long value; + protected int type; + + public IntConst(long v, int tokenId) { value = v; type = tokenId; } + + public long get() { return value; } + + /* Returns IntConstant, CharConstant, or LongConstant. + */ + public int getType() { return type; } + + public String toString() { return Long.toString(value); } + + public void accept(Visitor v) throws CompileError { + v.atIntConst(this); + } +} diff --git a/src/main/javassist/compiler/ast/Keyword.java b/src/main/javassist/compiler/ast/Keyword.java new file mode 100644 index 00000000..9e1798ec --- /dev/null +++ b/src/main/javassist/compiler/ast/Keyword.java @@ -0,0 +1,45 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * Keyword. + */ +public class Keyword extends ASTree { + protected int tokenId; + + public Keyword(int token) { + tokenId = token; + } + + public int get() { return tokenId; } + + public String toString() { return "id:" + tokenId; } + + public void accept(Visitor v) throws CompileError { v.atKeyword(this); } +} diff --git a/src/main/javassist/compiler/ast/Member.java b/src/main/javassist/compiler/ast/Member.java new file mode 100644 index 00000000..a4825874 --- /dev/null +++ b/src/main/javassist/compiler/ast/Member.java @@ -0,0 +1,39 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * Member name. + */ +public class Member extends Symbol { + public Member(String name) { + super(name); + } + + public void accept(Visitor v) throws CompileError { v.atMember(this); } +} diff --git a/src/main/javassist/compiler/ast/MethodDecl.java b/src/main/javassist/compiler/ast/MethodDecl.java new file mode 100644 index 00000000..3c529014 --- /dev/null +++ b/src/main/javassist/compiler/ast/MethodDecl.java @@ -0,0 +1,55 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +public class MethodDecl extends ASTList { + public static final String initName = "<init>"; + + public MethodDecl(ASTree _head, ASTList _tail) { + super(_head, _tail); + } + + public boolean isConstructor() { + Symbol sym = getReturn().getVariable(); + return sym != null && initName.equals(sym.get()); + } + + public ASTList getModifiers() { return (ASTList)getLeft(); } + + public Declarator getReturn() { return (Declarator)tail().head(); } + + public ASTList getParams() { return (ASTList)sublist(2).head(); } + + public ASTList getThrows() { return (ASTList)sublist(3).head(); } + + public Stmnt getBody() { return (Stmnt)sublist(4).head(); } + + public void accept(Visitor v) throws CompileError { + v.atMethodDecl(this); + } +} diff --git a/src/main/javassist/compiler/ast/NewExpr.java b/src/main/javassist/compiler/ast/NewExpr.java new file mode 100644 index 00000000..33c721ed --- /dev/null +++ b/src/main/javassist/compiler/ast/NewExpr.java @@ -0,0 +1,87 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.TokenId; +import javassist.compiler.CompileError; + +/** + * New Expression. + */ +public class NewExpr extends ASTList implements TokenId { + protected boolean newArray; + protected int arrayType; + + public NewExpr(ASTList className, ASTList args) { + super(className, new ASTList(args)); + newArray = false; + arrayType = CLASS; + } + + public NewExpr(int type, ASTList arraySize, ASTree init) { + super(null, new ASTList(arraySize)); + newArray = true; + arrayType = type; + if (init != null) + append(this, init); + } + + public static NewExpr makeObjectArray(ASTList className, + ASTList arraySize, ASTree init) { + NewExpr e = new NewExpr(className, arraySize); + e.newArray = true; + if (init != null) + append(e, init); + + return e; + } + + public boolean isArray() { return newArray; } + + /* TokenId.CLASS, TokenId.INT, ... + */ + public int getArrayType() { return arrayType; } + + public ASTList getClassName() { return (ASTList)getLeft(); } + + public ASTList getArguments() { return (ASTList)getRight().getLeft(); } + + public ASTList getArraySize() { return getArguments(); } + + public ASTree getInitializer() { + ASTree t = getRight().getRight(); + if (t == null) + return null; + else + return t.getLeft(); + } + + public void accept(Visitor v) throws CompileError { v.atNewExpr(this); } + + protected String getTag() { + return newArray ? "new[]" : "new"; + } +} diff --git a/src/main/javassist/compiler/ast/Pair.java b/src/main/javassist/compiler/ast/Pair.java new file mode 100644 index 00000000..520207a8 --- /dev/null +++ b/src/main/javassist/compiler/ast/Pair.java @@ -0,0 +1,61 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * A node of a a binary tree. This class provides concrete methods + * overriding abstract methods in ASTree. + */ +public class Pair extends ASTree { + protected ASTree left, right; + + public Pair(ASTree _left, ASTree _right) { + left = _left; + right = _right; + } + + public void accept(Visitor v) throws CompileError { v.atPair(this); } + + public String toString() { + StringBuffer sbuf = new StringBuffer(); + sbuf.append("(<Pair> "); + sbuf.append(left == null ? "<null>" : left.toString()); + sbuf.append(" . "); + sbuf.append(right == null ? "<null>" : right.toString()); + sbuf.append(')'); + return sbuf.toString(); + } + + public ASTree getLeft() { return left; } + + public ASTree getRight() { return right; } + + public void setLeft(ASTree _left) { left = _left; } + + public void setRight(ASTree _right) { right = _right; } +} diff --git a/src/main/javassist/compiler/ast/Stmnt.java b/src/main/javassist/compiler/ast/Stmnt.java new file mode 100644 index 00000000..c6b9a97e --- /dev/null +++ b/src/main/javassist/compiler/ast/Stmnt.java @@ -0,0 +1,69 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.TokenId; +import javassist.compiler.CompileError; + +/** + * Statement. + */ +public class Stmnt extends ASTList implements TokenId { + protected int operatorId; + + public Stmnt(int op, ASTree _head, ASTList _tail) { + super(_head, _tail); + operatorId = op; + } + + public Stmnt(int op, ASTree _head) { + super(_head); + operatorId = op; + } + + public Stmnt(int op) { + this(op, null); + } + + public static Stmnt make(int op, ASTree oprand1, ASTree oprand2) { + return new Stmnt(op, oprand1, new ASTList(oprand2)); + } + + public static Stmnt make(int op, ASTree op1, ASTree op2, ASTree op3) { + return new Stmnt(op, op1, new ASTList(op2, new ASTList(op3))); + } + + public void accept(Visitor v) throws CompileError { v.atStmnt(this); } + + public int getOperator() { return operatorId; } + + protected String getTag() { + if (operatorId < 128) + return "stmnt:" + (char)operatorId; + else + return "stmnt:" + operatorId; + } +} diff --git a/src/main/javassist/compiler/ast/StringL.java b/src/main/javassist/compiler/ast/StringL.java new file mode 100644 index 00000000..5f173f50 --- /dev/null +++ b/src/main/javassist/compiler/ast/StringL.java @@ -0,0 +1,45 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * String literal. + */ +public class StringL extends ASTree { + protected String text; + + public StringL(String t) { + text = t; + } + + public String get() { return text; } + + public String toString() { return "\"" + text + "\""; } + + public void accept(Visitor v) throws CompileError { v.atStringL(this); } +} diff --git a/src/main/javassist/compiler/ast/Symbol.java b/src/main/javassist/compiler/ast/Symbol.java new file mode 100644 index 00000000..c8e753bf --- /dev/null +++ b/src/main/javassist/compiler/ast/Symbol.java @@ -0,0 +1,45 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * Identifier. + */ +public class Symbol extends ASTree { + protected String identifier; + + public Symbol(String sym) { + identifier = sym; + } + + public String get() { return identifier; } + + public String toString() { return identifier; } + + public void accept(Visitor v) throws CompileError { v.atSymbol(this); } +} diff --git a/src/main/javassist/compiler/ast/Variable.java b/src/main/javassist/compiler/ast/Variable.java new file mode 100644 index 00000000..16112a99 --- /dev/null +++ b/src/main/javassist/compiler/ast/Variable.java @@ -0,0 +1,48 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * Variable. + */ +public class Variable extends Symbol { + protected Declarator declarator; + + public Variable(String sym, Declarator d) { + super(sym); + declarator = d; + } + + public Declarator getDeclarator() { return declarator; } + + public String toString() { + return identifier + ":" + declarator.getType(); + } + + public void accept(Visitor v) throws CompileError { v.atVariable(this); } +} diff --git a/src/main/javassist/compiler/ast/Visitor.java b/src/main/javassist/compiler/ast/Visitor.java new file mode 100644 index 00000000..685713de --- /dev/null +++ b/src/main/javassist/compiler/ast/Visitor.java @@ -0,0 +1,59 @@ +/* + * This file is part of the Javassist toolkit. + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * either http://www.mozilla.org/MPL/. + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Javassist. + * + * The Initial Developer of the Original Code is Shigeru Chiba. Portions + * created by Shigeru Chiba are Copyright (C) 1999-2003 Shigeru Chiba. + * All Rights Reserved. + * + * Contributor(s): + * + * The development of this software is supported in part by the PRESTO + * program (Sakigake Kenkyu 21) of Japan Science and Technology Corporation. + */ + +package javassist.compiler.ast; + +import javassist.compiler.CompileError; + +/** + * The visitor pattern. + * + * @see ast.ASTree#accept(Visitor) + */ +public class Visitor { + public void atASTList(ASTList n) throws CompileError {} + public void atPair(Pair n) throws CompileError {} + + public void atFieldDecl(FieldDecl n) throws CompileError {} + public void atMethodDecl(MethodDecl n) throws CompileError {} + public void atStmnt(Stmnt n) throws CompileError {} + public void atDeclarator(Declarator n) throws CompileError {} + + public void atAssignExpr(AssignExpr n) throws CompileError {} + public void atCondExpr(CondExpr n) throws CompileError {} + public void atBinExpr(BinExpr n) throws CompileError {} + public void atExpr(Expr n) throws CompileError {} + public void atCastExpr(CastExpr n) throws CompileError {} + public void atInstanceOfExpr(InstanceOfExpr n) throws CompileError {} + public void atNewExpr(NewExpr n) throws CompileError {} + + public void atSymbol(Symbol n) throws CompileError {} + public void atMember(Member n) throws CompileError {} + public void atVariable(Variable n) throws CompileError {} + public void atKeyword(Keyword n) throws CompileError {} + public void atStringL(StringL n) throws CompileError {} + public void atIntConst(IntConst n) throws CompileError {} + public void atDoubleConst(DoubleConst n) throws CompileError {} +} |