001    /* This file was generated with JastAdd2 (http://jastadd.org) version R20130213 */
002    package AST;
003    
004    import java.util.HashSet;
005    import java.io.File;
006    import java.util.*;
007    import beaver.*;
008    import java.util.ArrayList;
009    import java.util.zip.*;
010    import java.io.*;
011    import java.io.FileNotFoundException;
012    import java.util.Collection;
013    /**
014     * Java floating point literal. Can store any value representable as an
015     * IEEE 754 32-bit single-precision floating point number.
016     * @production FloatingPointLiteral : {@link NumericLiteral};
017     * @ast node
018     * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.ast:60
019     */
020    public class FloatingPointLiteral extends NumericLiteral implements Cloneable {
021      /**
022       * @apilevel low-level
023       */
024      public void flushCache() {
025      }
026      /**
027       * @apilevel internal
028       */
029      public void flushCollectionCache() {
030      }
031      /**
032       * @apilevel internal
033       */
034      @SuppressWarnings({"unchecked", "cast"})
035      public FloatingPointLiteral clone() throws CloneNotSupportedException {
036        FloatingPointLiteral node = (FloatingPointLiteral)super.clone();
037        node.type_computed = false;
038        node.type_value = null;
039        node.isZero_computed = false;
040        node.constant_computed = false;
041        node.constant_value = null;
042        node.in$Circle(false);
043        node.is$Final(false);
044        return node;
045      }
046    /**
047     * @apilevel internal
048     */
049      @SuppressWarnings({"unchecked", "cast"})
050    public FloatingPointLiteral copy() {
051      
052      try {
053        FloatingPointLiteral node = (FloatingPointLiteral) clone();
054        node.parent = null;
055        if(children != null)
056          node.children = (ASTNode[]) children.clone();
057        
058        return node;
059      } catch (CloneNotSupportedException e) {
060        throw new Error("Error: clone not supported for " + getClass().getName());
061      }
062      
063    }/**
064     * Create a deep copy of the AST subtree at this node.
065     * The copy is dangling, i.e. has no parent.
066     * @return dangling copy of the subtree at this node
067     * @apilevel low-level
068     */
069      @SuppressWarnings({"unchecked", "cast"})
070    public FloatingPointLiteral fullCopy() {
071      
072      FloatingPointLiteral tree = (FloatingPointLiteral) copy();
073      if (children != null) {
074        for (int i = 0; i < children.length; ++i) {
075          
076          ASTNode child = (ASTNode) children[i];
077          if(child != null) {
078            child = child.fullCopy();
079            tree.setChild(child, i);
080          }
081        }
082      }
083      return tree;
084      
085    }  /**
086       * @ast method 
087       * @aspect TypeCheck
088       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeCheck.jrag:581
089       */
090      public void typeCheck() {
091       if(!isZero() && constant().floatValue() == 0.0f)
092         error("It is an error for nonzero floating-point " + getLITERAL() + " to round to zero");
093       if(constant().floatValue() == Float.NEGATIVE_INFINITY || constant().floatValue() == Float.POSITIVE_INFINITY)
094         error("It is an error for floating-point " + getLITERAL() + " to round to an infinity");
095         
096     }
097      /**
098       * @ast method 
099       * @aspect CodeGeneration
100       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CodeGeneration.jrag:515
101       */
102      public static void push(CodeGeneration gen, float value) {
103        if(value == 0)
104          gen.emit(Bytecode.FCONST_0);
105        else if(value == 1)
106          gen.emit(Bytecode.FCONST_1);
107        else if(value == 2)
108          gen.emit(Bytecode.FCONST_2);
109        else {
110          int index = gen.constantPool().addConstant(value);
111          if(index < 256)
112            gen.emit(Bytecode.LDC).add(index);
113          else
114            gen.emit(Bytecode.LDC_W).add2(index);
115        }
116      }
117      /**
118       * @ast method 
119       * @aspect CodeGeneration
120       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CodeGeneration.jrag:562
121       */
122      public void emitPushConstant(CodeGeneration gen) {
123        FloatingPointLiteral.push(gen, constant().floatValue());
124      }
125      /**
126       * @ast method 
127       * 
128       */
129      public FloatingPointLiteral() {
130        super();
131    
132    
133      }
134      /**
135       * Initializes the child array to the correct size.
136       * Initializes List and Opt nta children.
137       * @apilevel internal
138       * @ast method
139       * @ast method 
140       * 
141       */
142      public void init$Children() {
143      }
144      /**
145       * @ast method 
146       * 
147       */
148      public FloatingPointLiteral(String p0) {
149        setLITERAL(p0);
150      }
151      /**
152       * @ast method 
153       * 
154       */
155      public FloatingPointLiteral(beaver.Symbol p0) {
156        setLITERAL(p0);
157      }
158      /**
159       * @apilevel low-level
160       * @ast method 
161       * 
162       */
163      protected int numChildren() {
164        return 0;
165      }
166      /**
167       * @apilevel internal
168       * @ast method 
169       * 
170       */
171      public boolean mayHaveRewrite() {
172        return true;
173      }
174      /**
175       * Replaces the lexeme LITERAL.
176       * @param value The new value for the lexeme LITERAL.
177       * @apilevel high-level
178       * @ast method 
179       * 
180       */
181      public void setLITERAL(String value) {
182        tokenString_LITERAL = value;
183      }
184      /**
185       * JastAdd-internal setter for lexeme LITERAL using the Beaver parser.
186       * @apilevel internal
187       * @ast method 
188       * 
189       */
190      public void setLITERAL(beaver.Symbol symbol) {
191        if(symbol.value != null && !(symbol.value instanceof String))
192          throw new UnsupportedOperationException("setLITERAL is only valid for String lexemes");
193        tokenString_LITERAL = (String)symbol.value;
194        LITERALstart = symbol.getStart();
195        LITERALend = symbol.getEnd();
196      }
197      /**
198       * Retrieves the value for the lexeme LITERAL.
199       * @return The value for the lexeme LITERAL.
200       * @apilevel high-level
201       * @ast method 
202       * 
203       */
204      public String getLITERAL() {
205        return tokenString_LITERAL != null ? tokenString_LITERAL : "";
206      }
207      /**
208        * Defer pretty printing to superclass.
209        * @ast method 
210       * @aspect Literals
211       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.jrag:105
212       */
213        public void toString(StringBuffer s) {
214               super.toString(s);
215       }
216      /**
217       * @apilevel internal
218       */
219      protected boolean type_computed = false;
220      /**
221       * @apilevel internal
222       */
223      protected TypeDecl type_value;
224      /**
225       * @attribute syn
226       * @aspect TypeAnalysis
227       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeAnalysis.jrag:302
228       */
229      @SuppressWarnings({"unchecked", "cast"})
230      public TypeDecl type() {
231        if(type_computed) {
232          return type_value;
233        }
234          ASTNode$State state = state();
235      int num = state.boundariesCrossed;
236      boolean isFinal = this.is$Final();
237        type_value = type_compute();
238      if(isFinal && num == state().boundariesCrossed){ type_computed = true; }
239            return type_value;
240      }
241      /**
242       * @apilevel internal
243       */
244      private TypeDecl type_compute() {  return typeFloat();  }
245      /**
246       * @apilevel internal
247       */
248      protected boolean isZero_computed = false;
249      /**
250       * @apilevel internal
251       */
252      protected boolean isZero_value;
253      /**
254        * @return true if this floating point literal is equivalent to a zero literal
255        * @attribute syn
256       * @aspect Literals
257       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.jrag:22
258       */
259      @SuppressWarnings({"unchecked", "cast"})
260      public boolean isZero() {
261        if(isZero_computed) {
262          return isZero_value;
263        }
264          ASTNode$State state = state();
265      int num = state.boundariesCrossed;
266      boolean isFinal = this.is$Final();
267        isZero_value = isZero_compute();
268      if(isFinal && num == state().boundariesCrossed){ isZero_computed = true; }
269            return isZero_value;
270      }
271      /**
272       * @apilevel internal
273       */
274      private boolean isZero_compute() {
275               for(int i = 0; i < digits.length(); i++) {
276                       char c = digits.charAt(i);
277                       if (c == 'e' || c == 'p') break;
278                       if (c != '0' && c != '.') {
279                               return false;
280                       }
281               }
282               return true;
283       }
284      /**
285       * @apilevel internal
286       */
287      protected boolean constant_computed = false;
288      /**
289       * @apilevel internal
290       */
291      protected Constant constant_value;
292      /**
293        * Parse this literal and return a fresh Constant.
294        * @return a fresh Constant representing this FloatingPointLiteral
295        * @attribute syn
296       * @aspect Literals
297       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.jrag:175
298       */
299      @SuppressWarnings({"unchecked", "cast"})
300      public Constant constant() {
301        if(constant_computed) {
302          return constant_value;
303        }
304          ASTNode$State state = state();
305      int num = state.boundariesCrossed;
306      boolean isFinal = this.is$Final();
307        constant_value = constant_compute();
308      if(isFinal && num == state().boundariesCrossed){ constant_computed = true; }
309            return constant_value;
310      }
311      /**
312       * @apilevel internal
313       */
314      private Constant constant_compute() {
315               try {
316                       return Constant.create(Float.parseFloat(getDigits()));
317               }
318               catch (NumberFormatException e) {
319                       Constant c = Constant.create(0.0f);
320                       c.error = true;
321                       return c;
322               }
323       }
324      /**
325        * Utility attribute for literal rewriting.
326        * Any of the NumericLiteral subclasses have already
327        * been rewritten and/or parsed, and should not be
328        * rewritten again.
329        *
330        * @return true if this literal is a "raw", not-yet-parsed NumericLiteral
331        * @attribute syn
332       * @aspect Literals
333       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.jrag:334
334       */
335      public boolean needsRewrite() {
336        ASTNode$State state = state();
337        try {  return false;  }
338        finally {
339        }
340      }
341      /**
342       * @apilevel internal
343       */
344      public ASTNode rewriteTo() {
345        return super.rewriteTo();
346      }
347    }