3 import IR.TypeDescriptor;
5 public class OpNode extends ExpressionNode {
10 TypeDescriptor lefttype;
11 TypeDescriptor righttype;
13 public OpNode(ExpressionNode l, ExpressionNode r, Operation o) {
19 public OpNode(ExpressionNode l, Operation o) {
25 public ExpressionNode getLeft() {
29 public ExpressionNode getRight() {
33 public Operation getOp() {
37 public String printNode(int indent) {
39 return op.toString()+"("+left.printNode(indent)+")";
41 return left.printNode(indent)+" "+op.toString()+" "+right.printNode(indent);
44 public void setLeftType(TypeDescriptor argtype) {
45 this.lefttype=argtype;
48 public TypeDescriptor getLeftType() {
52 public void setRightType(TypeDescriptor argtype) {
53 this.righttype=argtype;
56 public TypeDescriptor getRightType() {
60 public TypeDescriptor getType() {
64 public void setType(TypeDescriptor td) {
72 public Long evaluate() {
74 Long l = this.left.evaluate();
76 if (this.op.getOp() == Operation.LOGIC_NOT)
77 eval = Long.valueOf(l.longValue() > 0 ? 0 : 1);
78 else if (this.op.getOp() == Operation.COMP)
79 eval = Long.valueOf((long)(~l.longValue()));
80 else if (this.op.getOp() == Operation.UNARYMINUS)
81 eval = Long.valueOf(-l.longValue() );
82 else if (this.op.getOp() == Operation.UNARYPLUS)
83 eval = Long.valueOf(+l.longValue());
85 Long r = this.right.evaluate();
87 //if (this.op.getOp() == Operation.LOGIC_OR)
88 // return Long.valueOf((long)(l.longValue() || r.longValue()));
89 //else if (this.op.getOp() == Operation.LOGIC_AND)
90 // return Long.valueOf((long)(l.longValue() && r.longValue()));
91 /*else */if (this.op.getOp() == Operation.BIT_OR)
92 eval = Long.valueOf(l.longValue() | r.longValue());
93 else if (this.op.getOp() == Operation.BIT_XOR)
94 eval = Long.valueOf(l.longValue() ^ r.longValue());
95 else if (this.op.getOp() == Operation.BIT_AND)
96 eval = Long.valueOf(l.longValue() & r.longValue());
97 else if (this.op.getOp() == Operation.EQUAL)
98 eval = Long.valueOf((l.longValue() == r.longValue())?1:0);
99 else if (this.op.getOp() == Operation.NOTEQUAL)
100 eval = Long.valueOf((l.longValue() != r.longValue())?1:0);
101 else if (this.op.getOp() == Operation.LT)
102 eval = Long.valueOf((l.longValue() < r.longValue())?1:0);
103 else if (this.op.getOp() == Operation.GT)
104 eval = Long.valueOf((l.longValue() > r.longValue())?1:0);
105 else if (this.op.getOp() == Operation.LTE)
106 eval = Long.valueOf((l.longValue() <= r.longValue())?1:0);
107 else if (this.op.getOp() == Operation.GTE)
108 eval = Long.valueOf((l.longValue() >= r.longValue())?1:0);
109 else if (this.op.getOp() == Operation.LEFTSHIFT)
110 eval = Long.valueOf(l.longValue() << r.longValue());
111 else if (this.op.getOp() == Operation.RIGHTSHIFT)
112 eval = Long.valueOf(l.longValue() >> r.longValue());
113 else if (this.op.getOp() == Operation.URIGHTSHIFT)
114 eval = Long.valueOf(l.longValue() >>> r.longValue());
115 else if (this.op.getOp() == Operation.SUB)
116 eval = Long.valueOf(l.longValue() - r.longValue());
117 else if (this.op.getOp() == Operation.ADD)
118 eval = Long.valueOf(l.longValue() + r.longValue());
119 else if (this.op.getOp() == Operation.MULT)
120 eval = Long.valueOf(l.longValue() * r.longValue());
121 else if (this.op.getOp() == Operation.DIV)
122 eval = Long.valueOf(l.longValue() / r.longValue());
123 else if (this.op.getOp() == Operation.MOD)
124 eval = Long.valueOf(l.longValue() % r.longValue());
125 else if (this.op.getOp() == Operation.ASSIGN)
126 eval = Long.valueOf(r.longValue());