• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Javassist, a Java-bytecode translator toolkit.
3  * Copyright (C) 1999-2007 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  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  */
15 
16 package javassist.compiler.ast;
17 
18 import javassist.compiler.TokenId;
19 import javassist.compiler.CompileError;
20 
21 /**
22  * Expression.
23  */
24 public class Expr extends ASTList implements TokenId {
25     /* operator must be either of:
26      * (unary) +, (unary) -, ++, --, !, ~,
27      * ARRAY, . (dot), MEMBER (static member access).
28      * Otherwise, the object should be an instance of a subclass.
29      */
30 
31     protected int operatorId;
32 
Expr(int op, ASTree _head, ASTList _tail)33     Expr(int op, ASTree _head, ASTList _tail) {
34         super(_head, _tail);
35         operatorId = op;
36     }
37 
Expr(int op, ASTree _head)38     Expr(int op, ASTree _head) {
39         super(_head);
40         operatorId = op;
41     }
42 
make(int op, ASTree oprand1, ASTree oprand2)43     public static Expr make(int op, ASTree oprand1, ASTree oprand2) {
44         return new Expr(op, oprand1, new ASTList(oprand2));
45     }
46 
make(int op, ASTree oprand1)47     public static Expr make(int op, ASTree oprand1) {
48         return new Expr(op, oprand1);
49     }
50 
getOperator()51     public int getOperator() { return operatorId; }
52 
setOperator(int op)53     public void setOperator(int op) { operatorId = op; }
54 
oprand1()55     public ASTree oprand1() { return getLeft(); }
56 
setOprand1(ASTree expr)57     public void setOprand1(ASTree expr) {
58         setLeft(expr);
59     }
60 
oprand2()61     public ASTree oprand2() { return getRight().getLeft(); }
62 
setOprand2(ASTree expr)63     public void setOprand2(ASTree expr) {
64         getRight().setLeft(expr);
65     }
66 
accept(Visitor v)67     public void accept(Visitor v) throws CompileError { v.atExpr(this); }
68 
getName()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 
getTag()81     protected String getTag() {
82         return "op:" + getName();
83     }
84 }
85