/Users/lyon/j4p/src/javassist/compiler/ast/Expr.java
|
1 /*
2 * Javassist, a Java-bytecode translator toolkit.
3 * Copyright (C) 1999-2003 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 * CALL, ARRAY, . (dot), MEMBER (static member access).
28 * Otherwise, the object should be an instance of a subclass.
29 */
30
31 protected int operatorId;
32
33 public Expr(int op, ASTree _head, ASTList _tail) {
34 super(_head, _tail);
35 operatorId = op;
36 }
37
38 public 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 int getOperator() {
48 return operatorId;
49 }
50
51 public ASTree oprand1() {
52 return getLeft();
53 }
54
55 public ASTree oprand2() {
56 return getRight().getLeft();
57 }
58
59 public void accept(Visitor v) throws CompileError {
60 v.atExpr(this);
61 }
62
63 public String getName() {
64 int id = operatorId;
65 if (id < 128)
66 return String.valueOf((char) id);
67 else if (NEQ <= id && id <= ARSHIFT_E)
68 return opNames[id - NEQ];
69 else if (id == INSTANCEOF)
70 return "instanceof";
71 else
72 return String.valueOf(id);
73 }
74
75 protected String getTag() {
76 return "op:" + getName();
77 }
78 }
79