001    /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13-12-g880e696 */
002    package org.extendj.ast;
003    
004    import java.util.HashSet;
005    import java.io.File;
006    import java.util.Set;
007    import java.util.Collections;
008    import java.util.Collection;
009    import java.util.ArrayList;
010    import beaver.*;
011    import java.util.*;
012    import java.io.ByteArrayOutputStream;
013    import java.io.PrintStream;
014    import java.lang.reflect.InvocationTargetException;
015    import java.lang.reflect.Method;
016    import org.jastadd.util.*;
017    import java.util.zip.*;
018    import java.io.*;
019    import org.jastadd.util.PrettyPrintable;
020    import org.jastadd.util.PrettyPrinter;
021    import java.io.FileNotFoundException;
022    import java.io.BufferedInputStream;
023    import java.io.DataInputStream;
024    /**
025     * The abstract base class for all literals.
026     * @ast node
027     * @declaredat /home/jesper/git/extendj/java7/grammar/Literals.ast:4
028     * @production Literal : {@link PrimaryExpr} ::= <span class="component">&lt;LITERAL:String&gt;</span>;
029    
030     */
031    public abstract class Literal extends PrimaryExpr implements Cloneable {
032      /**
033       * @aspect BytecodeCONSTANT
034       * @declaredat /home/jesper/git/extendj/java4/frontend/BytecodeCONSTANT.jrag:98
035       */
036      public static Literal buildBooleanLiteral(boolean value) {
037        return new BooleanLiteral(value ? "true" : "false");
038      }
039      /**
040       * @aspect BytecodeCONSTANT
041       * @declaredat /home/jesper/git/extendj/java4/frontend/BytecodeCONSTANT.jrag:102
042       */
043      public static Literal buildStringLiteral(String value) {
044        return new StringLiteral(value);
045      }
046      /**
047       * @aspect Java4PrettyPrint
048       * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:184
049       */
050      public void prettyPrint(PrettyPrinter out) {
051        out.print(getLITERAL());
052      }
053      /**
054       * Escapes a string literal.
055       * @param s string to escape
056       * @return escaped string literal
057       * @aspect PrettyPrintUtil
058       * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrintUtil.jrag:323
059       */
060      protected static String escape(String s) {
061        StringBuffer result = new StringBuffer();
062        for (int i=0; i < s.length(); i++) {
063          switch(s.charAt(i)) {
064            case '\b':
065              result.append("\\b");
066              break;
067            case '\t':
068              result.append("\\t");
069              break;
070            case '\n':
071              result.append("\\n");
072              break;
073            case '\f':
074              result.append("\\f");
075              break;
076            case '\r':
077              result.append("\\r");
078              break;
079            case '\"':
080              result.append("\\\"");
081              break;
082            case '\'':
083              result.append("\\\'");
084              break;
085            case '\\':
086              result.append("\\\\");
087              break;
088            default:
089              int value = (int)s.charAt(i);
090              if (value < 0x20 || (value > 0x7e)) {
091                result.append(asEscape(value));
092              } else {
093                result.append(s.charAt(i));
094              }
095          }
096        }
097        return result.toString();
098      }
099      /**
100       * @aspect PrettyPrintUtil
101       * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrintUtil.jrag:363
102       */
103      protected static String asEscape(int value) {
104        StringBuffer s = new StringBuffer("\\u");
105        String hex = Integer.toHexString(value);
106        for (int i = 0; i < 4-hex.length(); i++) {
107          s.append("0");
108        }
109        s.append(hex);
110        return s.toString();
111      }
112      /**
113       * @aspect CodeGeneration
114       * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:177
115       */
116      public void emitPushConstant(CodeGeneration gen) {
117        System.err.println("ERROR: Tried to generate bytecode for: " + getClass().getName());
118      }
119      /**
120       * @aspect CreateBCode
121       * @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:238
122       */
123      public void createBCode(CodeGeneration gen) {
124        emitPushConstant(gen);
125      }
126      /**
127       * @declaredat ASTNode:1
128       */
129      public Literal() {
130        super();
131      }
132      /**
133       * Initializes the child array to the correct size.
134       * Initializes List and Opt nta children.
135       * @apilevel internal
136       * @ast method
137       * @declaredat ASTNode:10
138       */
139      public void init$Children() {
140      }
141      /**
142       * @declaredat ASTNode:12
143       */
144      public Literal(String p0) {
145        setLITERAL(p0);
146      }
147      /**
148       * @declaredat ASTNode:15
149       */
150      public Literal(beaver.Symbol p0) {
151        setLITERAL(p0);
152      }
153      /**
154       * @apilevel low-level
155       * @declaredat ASTNode:21
156       */
157      protected int numChildren() {
158        return 0;
159      }
160      /**
161       * @apilevel internal
162       * @declaredat ASTNode:27
163       */
164      public boolean mayHaveRewrite() {
165        return false;
166      }
167      /**
168       * @apilevel internal
169       * @declaredat ASTNode:33
170       */
171      public void flushAttrCache() {
172        super.flushAttrCache();
173        constant_reset();
174      }
175      /**
176       * @apilevel internal
177       * @declaredat ASTNode:40
178       */
179      public void flushCollectionCache() {
180        super.flushCollectionCache();
181      }
182      /**
183       * @apilevel internal
184       * @declaredat ASTNode:46
185       */
186      public void flushRewriteCache() {
187        super.flushRewriteCache();
188      }
189      /**
190       * @apilevel internal
191       * @declaredat ASTNode:52
192       */
193      public Literal clone() throws CloneNotSupportedException {
194        Literal node = (Literal) super.clone();
195        return node;
196      }
197      /**
198       * Create a deep copy of the AST subtree at this node.
199       * The copy is dangling, i.e. has no parent.
200       * @return dangling copy of the subtree at this node
201       * @apilevel low-level
202       * @deprecated Please use treeCopy or treeCopyNoTransform instead
203       * @declaredat ASTNode:63
204       */
205      @Deprecated
206      public abstract Literal fullCopy();
207      /**
208       * Create a deep copy of the AST subtree at this node.
209       * The copy is dangling, i.e. has no parent.
210       * @return dangling copy of the subtree at this node
211       * @apilevel low-level
212       * @declaredat ASTNode:71
213       */
214      public abstract Literal treeCopyNoTransform();
215      /**
216       * Create a deep copy of the AST subtree at this node.
217       * The subtree of this node is traversed to trigger rewrites before copy.
218       * The copy is dangling, i.e. has no parent.
219       * @return dangling copy of the subtree at this node
220       * @apilevel low-level
221       * @declaredat ASTNode:79
222       */
223      public abstract Literal treeCopy();
224      /**
225       * Replaces the lexeme LITERAL.
226       * @param value The new value for the lexeme LITERAL.
227       * @apilevel high-level
228       */
229      public void setLITERAL(String value) {
230        tokenString_LITERAL = value;
231      }
232      /**
233       * @apilevel internal
234       */
235      protected String tokenString_LITERAL;
236      /**
237       */
238      public int LITERALstart;
239      /**
240       */
241      public int LITERALend;
242      /**
243       * JastAdd-internal setter for lexeme LITERAL using the Beaver parser.
244       * @param symbol Symbol containing the new value for the lexeme LITERAL
245       * @apilevel internal
246       */
247      public void setLITERAL(beaver.Symbol symbol) {
248        if (symbol.value != null && !(symbol.value instanceof String))
249        throw new UnsupportedOperationException("setLITERAL is only valid for String lexemes");
250        tokenString_LITERAL = (String)symbol.value;
251        LITERALstart = symbol.getStart();
252        LITERALend = symbol.getEnd();
253      }
254      /**
255       * Retrieves the value for the lexeme LITERAL.
256       * @return The value for the lexeme LITERAL.
257       * @apilevel high-level
258       */
259      @ASTNodeAnnotation.Token(name="LITERAL")
260      public String getLITERAL() {
261        return tokenString_LITERAL != null ? tokenString_LITERAL : "";
262      }
263      /**
264       * @return a fresh double literal representing the given value
265       * @aspect Java7Literals
266       * @declaredat /home/jesper/git/extendj/java7/frontend/Literals.jrag:76
267       */
268        public static Literal buildDoubleLiteral(double value) {
269        String digits = Double.toString(value);
270        NumericLiteral lit = new DoubleLiteral(digits);
271        lit.setDigits(digits);
272        lit.setKind(NumericLiteral.DECIMAL);
273        return lit;
274      }
275      /**
276       * @return a fresh float literal representing the given value
277       * @aspect Java7Literals
278       * @declaredat /home/jesper/git/extendj/java7/frontend/Literals.jrag:88
279       */
280        public static Literal buildFloatLiteral(float value) {
281        String digits = Float.toString(value);
282        NumericLiteral lit = new FloatingPointLiteral(digits);
283        lit.setDigits(digits);
284        lit.setKind(NumericLiteral.DECIMAL);
285        return lit;
286      }
287      /**
288       * @return a fresh integer literal representing the given value
289       * @aspect Java7Literals
290       * @declaredat /home/jesper/git/extendj/java7/frontend/Literals.jrag:100
291       */
292        public static Literal buildIntegerLiteral(int value) {
293        String digits = Integer.toHexString(value);
294        NumericLiteral lit = new IntegerLiteral("0x" + digits);
295        lit.setDigits(digits.toLowerCase());
296        lit.setKind(NumericLiteral.HEXADECIMAL);
297        return lit;
298      }
299      /**
300       * @return a fresh long literal representing the given value
301       * @aspect Java7Literals
302       * @declaredat /home/jesper/git/extendj/java7/frontend/Literals.jrag:112
303       */
304        public static Literal buildLongLiteral(long value) {
305        String digits = Long.toHexString(value);
306        NumericLiteral lit = new LongLiteral("0x" + digits);
307        lit.setDigits(digits.toLowerCase());
308        lit.setKind(NumericLiteral.HEXADECIMAL);
309        return lit;
310      }
311      /**
312       * @apilevel internal
313       */
314      protected boolean constant_computed = false;
315      /**
316       * @apilevel internal
317       */
318      protected Constant constant_value;
319      /**
320       * @apilevel internal
321       */
322      private void constant_reset() {
323        constant_computed = false;
324        constant_value = null;
325      }
326      /**
327       * @attribute syn
328       * @aspect ConstantExpression
329       * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:37
330       */
331      @ASTNodeAnnotation.Attribute
332      public Constant constant() {
333        ASTNode$State state = state();
334        if (constant_computed) {
335          return constant_value;
336        }
337        boolean intermediate = state.INTERMEDIATE_VALUE;
338        state.INTERMEDIATE_VALUE = false;
339        int num = state.boundariesCrossed;
340        boolean isFinal = this.is$Final();
341        constant_value = constant_compute();
342        if (isFinal && num == state().boundariesCrossed) {
343          constant_computed = true;
344        } else {
345        }
346        state.INTERMEDIATE_VALUE |= intermediate;
347    
348        return constant_value;
349      }
350      /**
351       * @apilevel internal
352       */
353      private Constant constant_compute() {
354          throw new UnsupportedOperationException("ConstantExpression operation constant"
355              + " not supported for type " + getClass().getName());
356        }
357      /**
358       * @attribute syn
359       * @aspect ConstantExpression
360       * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:254
361       */
362      @ASTNodeAnnotation.Attribute
363      public boolean isConstant() {
364        boolean isConstant_value = true;
365    
366        return isConstant_value;
367      }
368      /**
369       * @attribute syn
370       * @aspect ConstantExpression
371       * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:283
372       */
373      @ASTNodeAnnotation.Attribute
374      public boolean isTrue() {
375        boolean isTrue_value = false;
376    
377        return isTrue_value;
378      }
379      /**
380       * @attribute syn
381       * @aspect ConstantExpression
382       * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:284
383       */
384      @ASTNodeAnnotation.Attribute
385      public boolean isFalse() {
386        boolean isFalse_value = false;
387    
388        return isFalse_value;
389      }
390      /**
391       * @apilevel internal
392       */
393      public ASTNode rewriteTo() {
394        return super.rewriteTo();
395      }
396    }