Fix tabbing.... Please fix your editors so they do tabbing correctly!!! (Spaces...
[IRC.git] / Robust / src / IR / Tree / TertiaryNode.java
1 package IR.Tree;
2 import IR.TypeDescriptor;
3
4 public class TertiaryNode extends ExpressionNode {
5   ExpressionNode cond;
6   ExpressionNode trueExpr;
7   ExpressionNode falseExpr;
8
9   public TertiaryNode(ExpressionNode cond,
10                       ExpressionNode trueExpr,
11                       ExpressionNode falseExpr) {
12     this.cond = cond;
13     this.trueExpr = trueExpr;
14     this.falseExpr = falseExpr;
15   }
16
17   public ExpressionNode getCond() {
18     return cond;
19   }
20
21   public ExpressionNode getTrueExpr() {
22     return trueExpr;
23   }
24
25   public ExpressionNode getFalseExpr() {
26     return falseExpr;
27   }
28
29   public String printNode(int indent) {
30     return cond.printNode(indent)+" ? "+trueExpr.printNode(indent)+" : "+falseExpr.printNode(indent);
31   }
32
33   public TypeDescriptor getType() {
34     return trueExpr.getType();
35   }
36
37   public int kind() {
38     return Kind.TertiaryNode;
39   }
40
41   public Long evaluate() {
42     eval = null;
43     Long c = this.cond.evaluate();
44     if(c != null) {
45       Long t = this.trueExpr.evaluate();
46       if(t != null) {
47         Long f = this.falseExpr.evaluate();
48         if(f != null) {
49           if(c.intValue() > 0) {
50             eval = t;
51           } else {
52             eval = f;
53           }
54         }
55       }
56     }
57     return eval;
58   }
59 }