1   // Copyright 2012- Bill Campbell, Swami Iyer and Bahar Akbal-Delibas
2   
3   package jminusminus;
4   
5   import static jminusminus.CLConstants.*;
6   
7   /**
8    * The AST node for a conditional expression.
9    */
10  class JConditionalExpression extends JExpression {
11      // Test expression.
12      private JExpression condition;
13  
14      // Then part.
15      private JExpression thenPart;
16  
17      // Else part.
18      private JExpression elsePart;
19  
20      /**
21       * Constructs an AST node for a conditional expression.
22       *
23       * @param line      line in which the conditional expression occurs in the source file.
24       * @param condition test expression.
25       * @param thenPart  then part.
26       * @param elsePart  else part.
27       */
28      public JConditionalExpression(int line, JExpression condition, JExpression thenPart,
29                                    JExpression elsePart) {
30          super(line);
31          this.condition = condition;
32          this.thenPart = thenPart;
33          this.elsePart = elsePart;
34      }
35  
36      /**
37       * {@inheritDoc}
38       */
39      public JExpression analyze(Context context) {
40          // TODO
41          return this;
42      }
43  
44      /**
45       * {@inheritDoc}
46       */
47      public void codegen(CLEmitter output) {
48          // TODO
49      }
50  
51      /**
52       * {@inheritDoc}
53       */
54      public void toJSON(JSONElement json) {
55          JSONElement e = new JSONElement();
56          json.addChild("JConditionalExpression:" + line, e);
57          JSONElement e1 = new JSONElement();
58          e.addChild("Condition", e1);
59          condition.toJSON(e1);
60          JSONElement e2 = new JSONElement();
61          e.addChild("ThenPart", e2);
62          thenPart.toJSON(e2);
63          JSONElement e3 = new JSONElement();
64          e.addChild("ElsePart", e3);
65          elsePart.toJSON(e3);
66      }
67  }
68