1 15 16 package javassist.compiler.ast; 17 18 import javassist.compiler.TokenId; 19 import javassist.compiler.CompileError; 20 21 24 public class Expr extends ASTList implements TokenId { 25 30 31 protected int operatorId; 32 33 Expr(int op, ASTree _head, ASTList _tail) { 34 super(_head, _tail); 35 operatorId = op; 36 } 37 38 Expr(int op, ASTree _head) { 39 super(_head); 40 operatorId = op; 41 } 42 43 public static Expr make(int op, ASTree oprand1, ASTree oprand2) { 44 return new Expr(op, oprand1, new ASTList(oprand2)); 45 } 46 47 public static Expr make(int op, ASTree oprand1) { 48 return new Expr(op, oprand1); 49 } 50 51 public int getOperator() { return operatorId; } 52 53 public void setOperator(int op) { operatorId = op; } 54 55 public ASTree oprand1() { return getLeft(); } 56 57 public void setOprand1(ASTree expr) { 58 setLeft(expr); 59 } 60 61 public ASTree oprand2() { return getRight().getLeft(); } 62 63 public void setOprand2(ASTree expr) { 64 getRight().setLeft(expr); 65 } 66 67 public void accept(Visitor v) throws CompileError { v.atExpr(this); } 68 69 public String getName() { 70 int id = operatorId; 71 if (id < 128) 72 return String.valueOf((char)id); 73 else if (NEQ <= id && id <= ARSHIFT_E) 74 return opNames[id - NEQ]; 75 else if (id == INSTANCEOF) 76 return "instanceof"; 77 else 78 return String.valueOf(id); 79 } 80 81 protected String getTag() { 82 return "op:" + getName(); 83 } 84 } 85 | Popular Tags |