01: /*
02: * Javassist, a Java-bytecode translator toolkit.
03: * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
04: *
05: * The contents of this file are subject to the Mozilla Public License Version
06: * 1.1 (the "License"); you may not use this file except in compliance with
07: * the License. Alternatively, the contents of this file may be used under
08: * the terms of the GNU Lesser General Public License Version 2.1 or later.
09: *
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:
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() {
52: return operatorId;
53: }
54:
55: public void setOperator(int op) {
56: operatorId = op;
57: }
58:
59: public ASTree oprand1() {
60: return getLeft();
61: }
62:
63: public void setOprand1(ASTree expr) {
64: setLeft(expr);
65: }
66:
67: public ASTree oprand2() {
68: return getRight().getLeft();
69: }
70:
71: public void setOprand2(ASTree expr) {
72: getRight().setLeft(expr);
73: }
74:
75: public void accept(Visitor v) throws CompileError {
76: v.atExpr(this );
77: }
78:
79: public String getName() {
80: int id = operatorId;
81: if (id < 128)
82: return String.valueOf((char) id);
83: else if (NEQ <= id && id <= ARSHIFT_E)
84: return opNames[id - NEQ];
85: else if (id == INSTANCEOF)
86: return "instanceof";
87: else
88: return String.valueOf(id);
89: }
90:
91: protected String getTag() {
92: return "op:" + getName();
93: }
94: }
|