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 double literal.
9    */
10  class JLiteralDouble extends JExpression {
11      // String representation of the literal.
12      private String text;
13  
14      /**
15       * Constructs an AST node for a double literal given its line number and string representation.
16       *
17       * @param line line in which the literal occurs in the source file.
18       * @param text string representation of the literal.
19       */
20      public JLiteralDouble(int line, String text) {
21          super(line);
22          this.text = text;
23      }
24  
25      /**
26       * Returns the literal as a double.
27       *
28       * @return the literal as a double.
29       */
30      public double toDouble() {
31          return Double.parseDouble(text);
32      }
33  
34      /**
35       * {@inheritDoc}
36       */
37      public JExpression analyze(Context context) {
38          // TODO
39          return this;
40      }
41  
42      /**
43       * {@inheritDoc}
44       */
45      public void codegen(CLEmitter output) {
46          // TODO
47      }
48  
49      /**
50       * {@inheritDoc}
51       */
52      public void toJSON(JSONElement json) {
53          JSONElement e = new JSONElement();
54          json.addChild("JLiteralDouble:" + line, e);
55          e.addAttribute("type", type == null ? "" : type.toString());
56          e.addAttribute("value", text);
57      }
58  }
59