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     * Default Java integer literal. Should only be used for numbers
015     * that can be stored in 32 bits binary.
016     * @production IntegerLiteral : {@link NumericLiteral};
017     * @ast node
018     * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.ast:48
019     */
020    public class IntegerLiteral 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 IntegerLiteral clone() throws CloneNotSupportedException {
036        IntegerLiteral node = (IntegerLiteral)super.clone();
037        node.type_computed = false;
038        node.type_value = null;
039        node.constant_computed = false;
040        node.constant_value = null;
041        node.in$Circle(false);
042        node.is$Final(false);
043        return node;
044      }
045    /**
046     * @apilevel internal
047     */
048      @SuppressWarnings({"unchecked", "cast"})
049    public IntegerLiteral copy() {
050      
051      try {
052        IntegerLiteral node = (IntegerLiteral) clone();
053        node.parent = null;
054        if(children != null)
055          node.children = (ASTNode[]) children.clone();
056        
057        return node;
058      } catch (CloneNotSupportedException e) {
059        throw new Error("Error: clone not supported for " + getClass().getName());
060      }
061      
062    }/**
063     * Create a deep copy of the AST subtree at this node.
064     * The copy is dangling, i.e. has no parent.
065     * @return dangling copy of the subtree at this node
066     * @apilevel low-level
067     */
068      @SuppressWarnings({"unchecked", "cast"})
069    public IntegerLiteral fullCopy() {
070      
071      IntegerLiteral tree = (IntegerLiteral) copy();
072      if (children != null) {
073        for (int i = 0; i < children.length; ++i) {
074          
075          ASTNode child = (ASTNode) children[i];
076          if(child != null) {
077            child = child.fullCopy();
078            tree.setChild(child, i);
079          }
080        }
081      }
082      return tree;
083      
084    }  /**
085       * @ast method 
086       * @aspect NodeConstructors
087       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/NodeConstructors.jrag:48
088       */
089      public IntegerLiteral(int i) {
090        this(Integer.toString(i));
091      }
092      /*************************************************************
093       * Emit methods
094       ************************************************************* @ast method 
095       * @aspect CodeGeneration
096       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CodeGeneration.jrag:456
097       */
098      public static void push(CodeGeneration gen, int value) {
099        switch(value) {
100          case -1:
101            gen.emit(Bytecode.ICONST_M1);
102            break;
103          case 0:
104            gen.emit(Bytecode.ICONST_0);
105            break;
106          case 1:
107            gen.emit(Bytecode.ICONST_1);
108            break;
109          case 2:
110            gen.emit(Bytecode.ICONST_2);
111            break;
112          case 3:
113            gen.emit(Bytecode.ICONST_3);
114            break;
115          case 4:
116            gen.emit(Bytecode.ICONST_4);
117            break;
118          case 5:
119            gen.emit(Bytecode.ICONST_5);
120            break;
121          default:
122            if(value >= -128 && value <= 127) {
123              gen.emit(Bytecode.BIPUSH).add(value);
124            }
125            else if(value >= -32768 && value <= 32767) {
126              gen.emit(Bytecode.SIPUSH).add2(value);
127            }
128            else {
129              int index = gen.constantPool().addConstant(value);
130              if(index < 256)
131                gen.emit(Bytecode.LDC).add(index);
132              else 
133                gen.emit(Bytecode.LDC_W).add2(index);
134            }
135        }
136      }
137      /**
138       * @ast method 
139       * @aspect CodeGeneration
140       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CodeGeneration.jrag:554
141       */
142      public void emitPushConstant(CodeGeneration gen) {
143        type().emitPushConstant(gen, constant().intValue());
144      }
145      /**
146       * @ast method 
147       * 
148       */
149      public IntegerLiteral() {
150        super();
151    
152    
153      }
154      /**
155       * Initializes the child array to the correct size.
156       * Initializes List and Opt nta children.
157       * @apilevel internal
158       * @ast method
159       * @ast method 
160       * 
161       */
162      public void init$Children() {
163      }
164      /**
165       * @ast method 
166       * 
167       */
168      public IntegerLiteral(String p0) {
169        setLITERAL(p0);
170      }
171      /**
172       * @ast method 
173       * 
174       */
175      public IntegerLiteral(beaver.Symbol p0) {
176        setLITERAL(p0);
177      }
178      /**
179       * @apilevel low-level
180       * @ast method 
181       * 
182       */
183      protected int numChildren() {
184        return 0;
185      }
186      /**
187       * @apilevel internal
188       * @ast method 
189       * 
190       */
191      public boolean mayHaveRewrite() {
192        return true;
193      }
194      /**
195       * Replaces the lexeme LITERAL.
196       * @param value The new value for the lexeme LITERAL.
197       * @apilevel high-level
198       * @ast method 
199       * 
200       */
201      public void setLITERAL(String value) {
202        tokenString_LITERAL = value;
203      }
204      /**
205       * JastAdd-internal setter for lexeme LITERAL using the Beaver parser.
206       * @apilevel internal
207       * @ast method 
208       * 
209       */
210      public void setLITERAL(beaver.Symbol symbol) {
211        if(symbol.value != null && !(symbol.value instanceof String))
212          throw new UnsupportedOperationException("setLITERAL is only valid for String lexemes");
213        tokenString_LITERAL = (String)symbol.value;
214        LITERALstart = symbol.getStart();
215        LITERALend = symbol.getEnd();
216      }
217      /**
218       * Retrieves the value for the lexeme LITERAL.
219       * @return The value for the lexeme LITERAL.
220       * @apilevel high-level
221       * @ast method 
222       * 
223       */
224      public String getLITERAL() {
225        return tokenString_LITERAL != null ? tokenString_LITERAL : "";
226      }
227      /**
228        * Check for and report literal-out-of-bounds error.
229        * If the constant is error-marked, there exists a literal out of bounds error.
230        * @ast method 
231       * @aspect Literals
232       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.jrag:120
233       */
234        public void typeCheck() {
235               if (constant().error)
236                       error("The integer literal \""+getLITERAL()+"\" is too large for type int.");
237    
238       }
239      /*syn lazy boolean FloatingPointLiteral.isZero() {
240        String s = getLITERAL();
241        for(int i = 0; i < s.length(); i++) {
242          char c = s.charAt(i);
243          if(c == 'E'  || c == 'e')
244            break;
245          if(Character.isDigit(c) && c != '0') {
246            return false;
247          }
248        }
249        return true;
250      }
251      syn lazy boolean DoubleLiteral.isZero() {
252        String s = getLITERAL();
253        for(int i = 0; i < s.length(); i++) {
254          char c = s.charAt(i);
255          if(c == 'E'  || c == 'e')
256            break;
257          if(Character.isDigit(c) && c != '0') {
258            return false;
259          }
260        }
261        return true;
262      }* @attribute syn
263       * @aspect ConstantExpression
264       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/ConstantExpression.jrag:152
265       */
266      public boolean isPositive() {
267        ASTNode$State state = state();
268        try {  return !getLITERAL().startsWith("-");  }
269        finally {
270        }
271      }
272      /**
273       * @apilevel internal
274       */
275      protected boolean type_computed = false;
276      /**
277       * @apilevel internal
278       */
279      protected TypeDecl type_value;
280      /**
281       * @attribute syn
282       * @aspect TypeAnalysis
283       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeAnalysis.jrag:300
284       */
285      @SuppressWarnings({"unchecked", "cast"})
286      public TypeDecl type() {
287        if(type_computed) {
288          return type_value;
289        }
290          ASTNode$State state = state();
291      int num = state.boundariesCrossed;
292      boolean isFinal = this.is$Final();
293        type_value = type_compute();
294      if(isFinal && num == state().boundariesCrossed){ type_computed = true; }
295            return type_value;
296      }
297      /**
298       * @apilevel internal
299       */
300      private TypeDecl type_compute() {  return typeInt();  }
301      /**
302       * @apilevel internal
303       */
304      protected boolean constant_computed = false;
305      /**
306       * @apilevel internal
307       */
308      protected Constant constant_value;
309      /**
310        * Parse this literal and return a fresh Constant.
311        * @return a fresh Constant representing this IntegerLiteral
312        * @attribute syn
313       * @aspect Literals
314       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.jrag:139
315       */
316      @SuppressWarnings({"unchecked", "cast"})
317      public Constant constant() {
318        if(constant_computed) {
319          return constant_value;
320        }
321          ASTNode$State state = state();
322      int num = state.boundariesCrossed;
323      boolean isFinal = this.is$Final();
324        constant_value = constant_compute();
325      if(isFinal && num == state().boundariesCrossed){ constant_computed = true; }
326            return constant_value;
327      }
328      /**
329       * @apilevel internal
330       */
331      private Constant constant_compute() {
332               long l = 0;
333               try {
334                       l = parseLong();
335               } catch (NumberFormatException e) {
336                       Constant c = Constant.create(0L);
337                       c.error = true;
338                       return c;
339               }
340               Constant c = Constant.create((int)l);
341               if (l != (0xFFFFFFFFL & ((int) l)) &&
342                               l != ((long) ((int) l)) ) {
343                       c.error = true;
344                       //System.err.println("Can not cast to integer: "+l+" ("+((int)l)+")");
345               }
346               return c;
347       }
348      /**
349        * Utility attribute for literal rewriting.
350        * Any of the NumericLiteral subclasses have already
351        * been rewritten and/or parsed, and should not be
352        * rewritten again.
353        *
354        * @return true if this literal is a "raw", not-yet-parsed NumericLiteral
355        * @attribute syn
356       * @aspect Literals
357       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.jrag:334
358       */
359      public boolean needsRewrite() {
360        ASTNode$State state = state();
361        try {  return false;  }
362        finally {
363        }
364      }
365      /**
366       * @apilevel internal
367       */
368      public ASTNode rewriteTo() {
369        return super.rewriteTo();
370      }
371    }