diff options
Diffstat (limited to 'src/main/javassist/compiler/ast')
23 files changed, 112 insertions, 88 deletions
diff --git a/src/main/javassist/compiler/ast/ASTList.java b/src/main/javassist/compiler/ast/ASTList.java index d9232ca0..786957f5 100644 --- a/src/main/javassist/compiler/ast/ASTList.java +++ b/src/main/javassist/compiler/ast/ASTList.java @@ -28,18 +28,18 @@ public class ASTList extends ASTree { private ASTree left; private ASTList right; - public ASTList(ASTree _head, ASTList _tail) { + public ASTList(ASTree _head, ASTList _tail, int lineNumber) { + super(lineNumber); left = _head; right = _tail; } - public ASTList(ASTree _head) { - left = _head; - right = null; + public ASTList(ASTree _head, int lineNumber) { + this(_head, null, lineNumber); } - public static ASTList make(ASTree e1, ASTree e2, ASTree e3) { - return new ASTList(e1, new ASTList(e2, new ASTList(e3))); + public static ASTList make(ASTree e1, ASTree e2, ASTree e3 , int lineNumber) { + return new ASTList(e1, new ASTList(e2, new ASTList(e3, lineNumber), lineNumber), lineNumber); } @Override @@ -146,8 +146,8 @@ public class ASTList extends ASTree { /** * Appends an object to a list. */ - public static ASTList append(ASTList a, ASTree b) { - return concat(a, new ASTList(b)); + public static ASTList append(ASTList a, ASTree b, int lineNumber) { + return concat(a, new ASTList(b, lineNumber)); } /** diff --git a/src/main/javassist/compiler/ast/ASTree.java b/src/main/javassist/compiler/ast/ASTree.java index 3d4dd842..f155fa87 100644 --- a/src/main/javassist/compiler/ast/ASTree.java +++ b/src/main/javassist/compiler/ast/ASTree.java @@ -29,6 +29,12 @@ public abstract class ASTree implements Serializable { /** default serialVersionUID */ private static final long serialVersionUID = 1L; + private final int lineNumber; + + public ASTree(int lineNumber) { + this.lineNumber = lineNumber; + } + public ASTree getLeft() { return null; } public ASTree getRight() { return null; } @@ -61,4 +67,8 @@ public abstract class ASTree implements Serializable { String name = getClass().getName(); return name.substring(name.lastIndexOf('.') + 1); } + + public int getLineNumber() { + return lineNumber; + } } diff --git a/src/main/javassist/compiler/ast/ArrayInit.java b/src/main/javassist/compiler/ast/ArrayInit.java index 0b87200e..bc3f06ea 100644 --- a/src/main/javassist/compiler/ast/ArrayInit.java +++ b/src/main/javassist/compiler/ast/ArrayInit.java @@ -27,10 +27,12 @@ public class ArrayInit extends ASTList { /** * Constructs an object. - * @param firstElement maybe null when the initializer is <code>{}</code> (empty). + * + * @param firstElement maybe null when the initializer is <code>{}</code> (empty). + * @param lineNumber */ - public ArrayInit(ASTree firstElement) { - super(firstElement); + public ArrayInit(ASTree firstElement, int lineNumber) { + super(firstElement, lineNumber); } /** diff --git a/src/main/javassist/compiler/ast/AssignExpr.java b/src/main/javassist/compiler/ast/AssignExpr.java index a5e1857d..97dfc6e7 100644 --- a/src/main/javassist/compiler/ast/AssignExpr.java +++ b/src/main/javassist/compiler/ast/AssignExpr.java @@ -29,13 +29,13 @@ public class AssignExpr extends Expr { /** default serialVersionUID */ private static final long serialVersionUID = 1L; - private AssignExpr(int op, ASTree _head, ASTList _tail) { - super(op, _head, _tail); + private AssignExpr(int op, ASTree _head, ASTList _tail, int lineNumber) { + super(op, _head, _tail, lineNumber); } public static AssignExpr makeAssign(int op, ASTree oprand1, - ASTree oprand2) { - return new AssignExpr(op, oprand1, new ASTList(oprand2)); + ASTree oprand2, int lineNumber) { + return new AssignExpr(op, oprand1, new ASTList(oprand2, lineNumber), lineNumber); } @Override diff --git a/src/main/javassist/compiler/ast/BinExpr.java b/src/main/javassist/compiler/ast/BinExpr.java index 9630ada9..789312ec 100644 --- a/src/main/javassist/compiler/ast/BinExpr.java +++ b/src/main/javassist/compiler/ast/BinExpr.java @@ -33,12 +33,12 @@ public class BinExpr extends Expr { /** default serialVersionUID */ private static final long serialVersionUID = 1L; - private BinExpr(int op, ASTree _head, ASTList _tail) { - super(op, _head, _tail); + private BinExpr(int op, ASTree _head, ASTList _tail, int lineNumber) { + super(op, _head, _tail, lineNumber); } - public static BinExpr makeBin(int op, ASTree oprand1, ASTree oprand2) { - return new BinExpr(op, oprand1, new ASTList(oprand2)); + public static BinExpr makeBin(int op, ASTree oprand1, ASTree oprand2, int lineNumber) { + return new BinExpr(op, oprand1, new ASTList(oprand2, lineNumber), lineNumber); } @Override diff --git a/src/main/javassist/compiler/ast/CallExpr.java b/src/main/javassist/compiler/ast/CallExpr.java index 395915ed..72a3ca51 100644 --- a/src/main/javassist/compiler/ast/CallExpr.java +++ b/src/main/javassist/compiler/ast/CallExpr.java @@ -28,8 +28,8 @@ public class CallExpr extends Expr { private static final long serialVersionUID = 1L; private MemberResolver.Method method; // cached result of lookupMethod() - private CallExpr(ASTree _head, ASTList _tail) { - super(TokenId.CALL, _head, _tail); + private CallExpr(ASTree _head, ASTList _tail, int lineNumber) { + super(TokenId.CALL, _head, _tail, lineNumber); method = null; } @@ -41,8 +41,8 @@ public class CallExpr extends Expr { return method; } - public static CallExpr makeCall(ASTree target, ASTree args) { - return new CallExpr(target, new ASTList(args)); + public static CallExpr makeCall(ASTree target, ASTree args, int lineNumber) { + return new CallExpr(target, new ASTList(args, lineNumber), lineNumber); } @Override diff --git a/src/main/javassist/compiler/ast/CastExpr.java b/src/main/javassist/compiler/ast/CastExpr.java index 903e5bbd..d3938078 100644 --- a/src/main/javassist/compiler/ast/CastExpr.java +++ b/src/main/javassist/compiler/ast/CastExpr.java @@ -28,14 +28,14 @@ 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)); + public CastExpr(ASTList className, int dim, ASTree expr, int lineNumber) { + super(className, new ASTList(expr, lineNumber), lineNumber); castType = CLASS; arrayDim = dim; } - public CastExpr(int type, int dim, ASTree expr) { - super(null, new ASTList(expr)); + public CastExpr(int type, int dim, ASTree expr, int lineNumber) { + super(null, new ASTList(expr, lineNumber), lineNumber); castType = type; arrayDim = dim; } diff --git a/src/main/javassist/compiler/ast/CondExpr.java b/src/main/javassist/compiler/ast/CondExpr.java index 46435012..e4b6e07b 100644 --- a/src/main/javassist/compiler/ast/CondExpr.java +++ b/src/main/javassist/compiler/ast/CondExpr.java @@ -25,8 +25,8 @@ public class CondExpr extends ASTList { /** default serialVersionUID */ private static final long serialVersionUID = 1L; - public CondExpr(ASTree cond, ASTree thenp, ASTree elsep) { - super(cond, new ASTList(thenp, new ASTList(elsep))); + public CondExpr(ASTree cond, ASTree thenp, ASTree elsep, int lineNumber) { + super(cond, new ASTList(thenp, new ASTList(elsep, lineNumber), lineNumber), lineNumber); } public ASTree condExpr() { return head(); } diff --git a/src/main/javassist/compiler/ast/Declarator.java b/src/main/javassist/compiler/ast/Declarator.java index c29f6740..1713d908 100644 --- a/src/main/javassist/compiler/ast/Declarator.java +++ b/src/main/javassist/compiler/ast/Declarator.java @@ -30,16 +30,16 @@ public class Declarator extends ASTList implements TokenId { protected int localVar; protected String qualifiedClass; // JVM-internal representation - public Declarator(int type, int dim) { - super(null); + public Declarator(int type, int dim, int lineNumber) { + super(null, lineNumber); varType = type; arrayDim = dim; localVar = -1; qualifiedClass = null; } - public Declarator(ASTList className, int dim) { - super(null); + public Declarator(ASTList className, int dim, int lineNumber) { + super(null, lineNumber); varType = CLASS; arrayDim = dim; localVar = -1; @@ -49,21 +49,21 @@ public class Declarator extends ASTList implements TokenId { /* For declaring a pre-defined? local variable. */ public Declarator(int type, String jvmClassName, int dim, - int var, Symbol sym) { - super(null); + int var, Symbol sym, int lineNumber) { + super(null, lineNumber); varType = type; arrayDim = dim; localVar = var; qualifiedClass = jvmClassName; setLeft(sym); - append(this, null); // initializer + append(this, null, lineNumber); // initializer } - public Declarator make(Symbol sym, int dim, ASTree init) { - Declarator d = new Declarator(this.varType, this.arrayDim + dim); + public Declarator make(Symbol sym, int dim, ASTree init, int lineNumber) { + Declarator d = new Declarator(this.varType, this.arrayDim + dim, lineNumber); d.qualifiedClass = this.qualifiedClass; d.setLeft(sym); - append(d, init); + append(d, init, lineNumber); return d; } diff --git a/src/main/javassist/compiler/ast/DoubleConst.java b/src/main/javassist/compiler/ast/DoubleConst.java index f8d0afde..d55821f0 100644 --- a/src/main/javassist/compiler/ast/DoubleConst.java +++ b/src/main/javassist/compiler/ast/DoubleConst.java @@ -28,7 +28,11 @@ public class DoubleConst extends ASTree { protected double value; protected int type; - public DoubleConst(double v, int tokenId) { value = v; type = tokenId; } + public DoubleConst(double v, int tokenId, int lineNumber) { + super(lineNumber); + value = v; + type = tokenId; + } public double get() { return value; } @@ -63,15 +67,15 @@ public class DoubleConst extends ASTree { else newType = TokenId.FloatConstant; - return compute(op, this.value, right.value, newType); + return compute(op, this.value, right.value, newType, getLineNumber()); } private DoubleConst compute0(int op, IntConst right) { - return compute(op, this.value, right.value, this.type); + return compute(op, this.value, right.value, this.type, getLineNumber()); } private static DoubleConst compute(int op, double value1, double value2, - int newType) + int newType, int lineNumber) { double newValue; switch (op) { @@ -94,6 +98,6 @@ public class DoubleConst extends ASTree { return null; } - return new DoubleConst(newValue, newType); + return new DoubleConst(newValue, newType, lineNumber); } } diff --git a/src/main/javassist/compiler/ast/Expr.java b/src/main/javassist/compiler/ast/Expr.java index ed5cb60b..4d2ce1a0 100644 --- a/src/main/javassist/compiler/ast/Expr.java +++ b/src/main/javassist/compiler/ast/Expr.java @@ -33,22 +33,22 @@ public class Expr extends ASTList implements TokenId { private static final long serialVersionUID = 1L; protected int operatorId; - Expr(int op, ASTree _head, ASTList _tail) { - super(_head, _tail); + Expr(int op, ASTree _head, ASTList _tail, int lineNumber) { + super(_head, _tail, lineNumber); operatorId = op; } - Expr(int op, ASTree _head) { - super(_head); + Expr(int op, ASTree _head, int lineNumber) { + super(_head, lineNumber); operatorId = op; } - public static Expr make(int op, ASTree oprand1, ASTree oprand2) { - return new Expr(op, oprand1, new ASTList(oprand2)); + public static Expr make(int op, ASTree oprand1, ASTree oprand2, int lineNumber) { + return new Expr(op, oprand1, new ASTList(oprand2, lineNumber), lineNumber); } - public static Expr make(int op, ASTree oprand1) { - return new Expr(op, oprand1); + public static Expr make(int op, ASTree oprand1, int lineNumber) { + return new Expr(op, oprand1, lineNumber); } public int getOperator() { return operatorId; } diff --git a/src/main/javassist/compiler/ast/FieldDecl.java b/src/main/javassist/compiler/ast/FieldDecl.java index e2a066e9..44df192e 100644 --- a/src/main/javassist/compiler/ast/FieldDecl.java +++ b/src/main/javassist/compiler/ast/FieldDecl.java @@ -22,8 +22,8 @@ public class FieldDecl extends ASTList { /** default serialVersionUID */ private static final long serialVersionUID = 1L; - public FieldDecl(ASTree _head, ASTList _tail) { - super(_head, _tail); + public FieldDecl(ASTree _head, ASTList _tail, int lineNumber) { + super(_head, _tail, lineNumber); } public ASTList getModifiers() { return (ASTList)getLeft(); } diff --git a/src/main/javassist/compiler/ast/InstanceOfExpr.java b/src/main/javassist/compiler/ast/InstanceOfExpr.java index ddf07bd2..e012defe 100644 --- a/src/main/javassist/compiler/ast/InstanceOfExpr.java +++ b/src/main/javassist/compiler/ast/InstanceOfExpr.java @@ -25,12 +25,12 @@ public class InstanceOfExpr extends CastExpr { /** default serialVersionUID */ private static final long serialVersionUID = 1L; - public InstanceOfExpr(ASTList className, int dim, ASTree expr) { - super(className, dim, expr); + public InstanceOfExpr(ASTList className, int dim, ASTree expr, int lineNumber) { + super(className, dim, expr, lineNumber); } - public InstanceOfExpr(int type, int dim, ASTree expr) { - super(type, dim, expr); + public InstanceOfExpr(int type, int dim, ASTree expr, int lineNumber) { + super(type, dim, expr, lineNumber); } @Override diff --git a/src/main/javassist/compiler/ast/IntConst.java b/src/main/javassist/compiler/ast/IntConst.java index 7040b0c9..8ffce479 100644 --- a/src/main/javassist/compiler/ast/IntConst.java +++ b/src/main/javassist/compiler/ast/IntConst.java @@ -28,7 +28,11 @@ public class IntConst extends ASTree { protected long value; protected int type; - public IntConst(long v, int tokenId) { value = v; type = tokenId; } + public IntConst(long v, int tokenId, int lineNumber) { + super(lineNumber); + value = v; + type = tokenId; + } public long get() { return value; } @@ -111,7 +115,7 @@ public class IntConst extends ASTree { return null; } - return new IntConst(newValue, newType); + return new IntConst(newValue, newType, right.getLineNumber()); } private DoubleConst compute0(int op, DoubleConst right) { @@ -138,6 +142,6 @@ public class IntConst extends ASTree { return null; } - return new DoubleConst(newValue, right.type); + return new DoubleConst(newValue, right.type, right.getLineNumber()); } } diff --git a/src/main/javassist/compiler/ast/Keyword.java b/src/main/javassist/compiler/ast/Keyword.java index b509375c..858316d5 100644 --- a/src/main/javassist/compiler/ast/Keyword.java +++ b/src/main/javassist/compiler/ast/Keyword.java @@ -26,7 +26,8 @@ public class Keyword extends ASTree { private static final long serialVersionUID = 1L; protected int tokenId; - public Keyword(int token) { + public Keyword(int token, int lineNumber) { + super(lineNumber); tokenId = token; } diff --git a/src/main/javassist/compiler/ast/Member.java b/src/main/javassist/compiler/ast/Member.java index 192c9ef3..279e2516 100644 --- a/src/main/javassist/compiler/ast/Member.java +++ b/src/main/javassist/compiler/ast/Member.java @@ -29,8 +29,8 @@ public class Member extends Symbol { // this is used to obtain the value of a static final field. private CtField field; - public Member(String name) { - super(name); + public Member(String name, int lineNumber) { + super(name, lineNumber); field = null; } diff --git a/src/main/javassist/compiler/ast/MethodDecl.java b/src/main/javassist/compiler/ast/MethodDecl.java index d96e3d4d..263775b0 100644 --- a/src/main/javassist/compiler/ast/MethodDecl.java +++ b/src/main/javassist/compiler/ast/MethodDecl.java @@ -23,8 +23,8 @@ public class MethodDecl extends ASTList { private static final long serialVersionUID = 1L; public static final String initName = "<init>"; - public MethodDecl(ASTree _head, ASTList _tail) { - super(_head, _tail); + public MethodDecl(ASTree _head, ASTList _tail, int lineNumber) { + super(_head, _tail, lineNumber); } public boolean isConstructor() { diff --git a/src/main/javassist/compiler/ast/NewExpr.java b/src/main/javassist/compiler/ast/NewExpr.java index 44b264c0..d4f7f475 100644 --- a/src/main/javassist/compiler/ast/NewExpr.java +++ b/src/main/javassist/compiler/ast/NewExpr.java @@ -28,26 +28,26 @@ public class NewExpr extends ASTList implements TokenId { protected boolean newArray; protected int arrayType; - public NewExpr(ASTList className, ASTList args) { - super(className, new ASTList(args)); + public NewExpr(ASTList className, ASTList args, int lineNumber) { + super(className, new ASTList(args, lineNumber), lineNumber); newArray = false; arrayType = CLASS; } - public NewExpr(int type, ASTList arraySize, ArrayInit init) { - super(null, new ASTList(arraySize)); + public NewExpr(int type, ASTList arraySize, ArrayInit init, int lineNumber) { + super(null, new ASTList(arraySize, lineNumber), lineNumber); newArray = true; arrayType = type; if (init != null) - append(this, init); + append(this, init, lineNumber); } public static NewExpr makeObjectArray(ASTList className, - ASTList arraySize, ArrayInit init) { - NewExpr e = new NewExpr(className, arraySize); + ASTList arraySize, ArrayInit init, int lineNumber) { + NewExpr e = new NewExpr(className, arraySize, lineNumber); e.newArray = true; if (init != null) - append(e, init); + append(e, init, lineNumber); return e; } diff --git a/src/main/javassist/compiler/ast/Pair.java b/src/main/javassist/compiler/ast/Pair.java index 949028a4..44411b8d 100644 --- a/src/main/javassist/compiler/ast/Pair.java +++ b/src/main/javassist/compiler/ast/Pair.java @@ -28,6 +28,7 @@ public class Pair extends ASTree { protected ASTree left, right; public Pair(ASTree _left, ASTree _right) { + super(_left.getLineNumber()); left = _left; right = _right; } diff --git a/src/main/javassist/compiler/ast/Stmnt.java b/src/main/javassist/compiler/ast/Stmnt.java index c5aa5df3..7333d026 100644 --- a/src/main/javassist/compiler/ast/Stmnt.java +++ b/src/main/javassist/compiler/ast/Stmnt.java @@ -27,26 +27,26 @@ public class Stmnt extends ASTList implements TokenId { private static final long serialVersionUID = 1L; protected int operatorId; - public Stmnt(int op, ASTree _head, ASTList _tail) { - super(_head, _tail); + public Stmnt(int op, ASTree _head, ASTList _tail, int lineNumber) { + super(_head, _tail, lineNumber); operatorId = op; } - public Stmnt(int op, ASTree _head) { - super(_head); + public Stmnt(int op, ASTree _head, int lineNumber) { + super(_head, lineNumber); operatorId = op; } - public Stmnt(int op) { - this(op, null); + public Stmnt(int op, int lineNumber) { + this(op, null, lineNumber); } - 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 oprand1, ASTree oprand2, int lineNumber) { + return new Stmnt(op, oprand1, new ASTList(oprand2, lineNumber), lineNumber); } - public static Stmnt make(int op, ASTree op1, ASTree op2, ASTree op3) { - return new Stmnt(op, op1, new ASTList(op2, new ASTList(op3))); + public static Stmnt make(int op, ASTree op1, ASTree op2, ASTree op3, int lineNumber) { + return new Stmnt(op, op1, new ASTList(op2, new ASTList(op3, lineNumber), lineNumber), lineNumber); } @Override diff --git a/src/main/javassist/compiler/ast/StringL.java b/src/main/javassist/compiler/ast/StringL.java index 7c7e00c3..063bb5ed 100644 --- a/src/main/javassist/compiler/ast/StringL.java +++ b/src/main/javassist/compiler/ast/StringL.java @@ -26,7 +26,8 @@ public class StringL extends ASTree { private static final long serialVersionUID = 1L; protected String text; - public StringL(String t) { + public StringL(String t, int lineNumber) { + super(lineNumber); text = t; } diff --git a/src/main/javassist/compiler/ast/Symbol.java b/src/main/javassist/compiler/ast/Symbol.java index 2b66207a..64c598eb 100644 --- a/src/main/javassist/compiler/ast/Symbol.java +++ b/src/main/javassist/compiler/ast/Symbol.java @@ -26,7 +26,8 @@ public class Symbol extends ASTree { private static final long serialVersionUID = 1L; protected String identifier; - public Symbol(String sym) { + public Symbol(String sym, int lineNumber) { + super(lineNumber); identifier = sym; } diff --git a/src/main/javassist/compiler/ast/Variable.java b/src/main/javassist/compiler/ast/Variable.java index c9224a7a..2e186950 100644 --- a/src/main/javassist/compiler/ast/Variable.java +++ b/src/main/javassist/compiler/ast/Variable.java @@ -26,8 +26,8 @@ public class Variable extends Symbol { private static final long serialVersionUID = 1L; protected Declarator declarator; - public Variable(String sym, Declarator d) { - super(sym); + public Variable(String sym, Declarator d, int lineNumber) { + super(sym, lineNumber); declarator = d; } |