1 /* 2 * Javassist, a Java-bytecode translator toolkit. 3 * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved. 4 * 5 * The contents of this file are subject to the Mozilla Public License Version 6 * 1.1 (the "License"); you may not use this file except in compliance with 7 * the License. Alternatively, the contents of this file may be used under 8 * the terms of the GNU Lesser General Public License Version 2.1 or later, 9 * or the Apache License Version 2.0. 10 * 11 * Software distributed under the License is distributed on an "AS IS" basis, 12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 * for the specific language governing rights and limitations under the 14 * License. 15 */ 16 17 package javassist.compiler.ast; 18 19 import javassist.compiler.CompileError; 20 import javassist.compiler.TokenId; 21 22 /** 23 * Expression. 24 */ 25 public class Expr extends ASTList implements TokenId { 26 /* operator must be either of: 27 * (unary) +, (unary) -, ++, --, !, ~, 28 * ARRAY, . (dot), MEMBER (static member access). 29 * Otherwise, the object should be an instance of a subclass. 30 */ 31 32 /** default serialVersionUID */ 33 private static final long serialVersionUID = 1L; 34 protected int operatorId; 35 Expr(int op, ASTree _head, ASTList _tail)36 Expr(int op, ASTree _head, ASTList _tail) { 37 super(_head, _tail); 38 operatorId = op; 39 } 40 Expr(int op, ASTree _head)41 Expr(int op, ASTree _head) { 42 super(_head); 43 operatorId = op; 44 } 45 make(int op, ASTree oprand1, ASTree oprand2)46 public static Expr make(int op, ASTree oprand1, ASTree oprand2) { 47 return new Expr(op, oprand1, new ASTList(oprand2)); 48 } 49 make(int op, ASTree oprand1)50 public static Expr make(int op, ASTree oprand1) { 51 return new Expr(op, oprand1); 52 } 53 getOperator()54 public int getOperator() { return operatorId; } 55 setOperator(int op)56 public void setOperator(int op) { operatorId = op; } 57 oprand1()58 public ASTree oprand1() { return getLeft(); } 59 setOprand1(ASTree expr)60 public void setOprand1(ASTree expr) { 61 setLeft(expr); 62 } 63 oprand2()64 public ASTree oprand2() { return getRight().getLeft(); } 65 setOprand2(ASTree expr)66 public void setOprand2(ASTree expr) { 67 getRight().setLeft(expr); 68 } 69 70 @Override accept(Visitor v)71 public void accept(Visitor v) throws CompileError { v.atExpr(this); } 72 getName()73 public String getName() { 74 int id = operatorId; 75 if (id < 128) 76 return String.valueOf((char)id); 77 else if (NEQ <= id && id <= ARSHIFT_E) 78 return opNames[id - NEQ]; 79 else if (id == INSTANCEOF) 80 return "instanceof"; 81 else 82 return String.valueOf(id); 83 } 84 85 @Override getTag()86 protected String getTag() { 87 return "op:" + getName(); 88 } 89 } 90