Fix tabbing.... Please fix your editors so they do tabbing correctly!!! (Spaces...
[IRC.git] / Robust / src / IR / Tree / TertiaryNode.java
index 099828651eb6d6278f81d0b5af241d5f8285496e..a63214ba2f751de55a7a02b6391016fe499c4c94 100644 (file)
@@ -6,9 +6,9 @@ public class TertiaryNode extends ExpressionNode {
   ExpressionNode trueExpr;
   ExpressionNode falseExpr;
 
-  public TertiaryNode( ExpressionNode cond,
-                      ExpressionNode trueExpr,
-                      ExpressionNode falseExpr ) {
+  public TertiaryNode(ExpressionNode cond,
+                      ExpressionNode trueExpr,
+                      ExpressionNode falseExpr) {
     this.cond = cond;
     this.trueExpr = trueExpr;
     this.falseExpr = falseExpr;
@@ -25,7 +25,7 @@ public class TertiaryNode extends ExpressionNode {
   public ExpressionNode getFalseExpr() {
     return falseExpr;
   }
-  
+
   public String printNode(int indent) {
     return cond.printNode(indent)+" ? "+trueExpr.printNode(indent)+" : "+falseExpr.printNode(indent);
   }
@@ -37,4 +37,23 @@ public class TertiaryNode extends ExpressionNode {
   public int kind() {
     return Kind.TertiaryNode;
   }
+
+  public Long evaluate() {
+    eval = null;
+    Long c = this.cond.evaluate();
+    if(c != null) {
+      Long t = this.trueExpr.evaluate();
+      if(t != null) {
+       Long f = this.falseExpr.evaluate();
+       if(f != null) {
+         if(c.intValue() > 0) {
+           eval = t;
+         } else {
+           eval = f;
+         }
+       }
+      }
+    }
+    return eval;
+  }
 }
\ No newline at end of file