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     * Represents a Java boolean; either "true" or "false".
026     * @ast node
027     * @declaredat /home/jesper/git/extendj/java7/grammar/Literals.ast:23
028     * @production BooleanLiteral : {@link Literal};
029    
030     */
031    public class BooleanLiteral extends Literal implements Cloneable {
032      /**
033       * @aspect NodeConstructors
034       * @declaredat /home/jesper/git/extendj/java4/frontend/NodeConstructors.jrag:63
035       */
036      public BooleanLiteral(boolean b) {
037        this(b ? "true" : "false");
038      }
039      /**
040       * @aspect CodeGeneration
041       * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:165
042       */
043      public static void push(CodeGeneration gen, boolean value) {
044        gen.emit(value ? Bytecode.ICONST_1 : Bytecode.ICONST_0);
045      }
046      /**
047       * @aspect CodeGeneration
048       * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:209
049       */
050      public void emitPushConstant(CodeGeneration gen) {
051        BooleanLiteral.push(gen, constant().booleanValue());
052      }
053      /**
054       * @declaredat ASTNode:1
055       */
056      public BooleanLiteral() {
057        super();
058      }
059      /**
060       * Initializes the child array to the correct size.
061       * Initializes List and Opt nta children.
062       * @apilevel internal
063       * @ast method
064       * @declaredat ASTNode:10
065       */
066      public void init$Children() {
067      }
068      /**
069       * @declaredat ASTNode:12
070       */
071      public BooleanLiteral(String p0) {
072        setLITERAL(p0);
073      }
074      /**
075       * @declaredat ASTNode:15
076       */
077      public BooleanLiteral(beaver.Symbol p0) {
078        setLITERAL(p0);
079      }
080      /**
081       * @apilevel low-level
082       * @declaredat ASTNode:21
083       */
084      protected int numChildren() {
085        return 0;
086      }
087      /**
088       * @apilevel internal
089       * @declaredat ASTNode:27
090       */
091      public boolean mayHaveRewrite() {
092        return false;
093      }
094      /**
095       * @apilevel internal
096       * @declaredat ASTNode:33
097       */
098      public void flushAttrCache() {
099        super.flushAttrCache();
100        constant_reset();
101        type_reset();
102      }
103      /**
104       * @apilevel internal
105       * @declaredat ASTNode:41
106       */
107      public void flushCollectionCache() {
108        super.flushCollectionCache();
109      }
110      /**
111       * @apilevel internal
112       * @declaredat ASTNode:47
113       */
114      public void flushRewriteCache() {
115        super.flushRewriteCache();
116      }
117      /**
118       * @apilevel internal
119       * @declaredat ASTNode:53
120       */
121      public BooleanLiteral clone() throws CloneNotSupportedException {
122        BooleanLiteral node = (BooleanLiteral) super.clone();
123        return node;
124      }
125      /**
126       * @apilevel internal
127       * @declaredat ASTNode:60
128       */
129      public BooleanLiteral copy() {
130        try {
131          BooleanLiteral node = (BooleanLiteral) clone();
132          node.parent = null;
133          if (children != null) {
134            node.children = (ASTNode[]) children.clone();
135          }
136          return node;
137        } catch (CloneNotSupportedException e) {
138          throw new Error("Error: clone not supported for " + getClass().getName());
139        }
140      }
141      /**
142       * Create a deep copy of the AST subtree at this node.
143       * The copy is dangling, i.e. has no parent.
144       * @return dangling copy of the subtree at this node
145       * @apilevel low-level
146       * @deprecated Please use treeCopy or treeCopyNoTransform instead
147       * @declaredat ASTNode:79
148       */
149      @Deprecated
150      public BooleanLiteral fullCopy() {
151        return treeCopyNoTransform();
152      }
153      /**
154       * Create a deep copy of the AST subtree at this node.
155       * The copy is dangling, i.e. has no parent.
156       * @return dangling copy of the subtree at this node
157       * @apilevel low-level
158       * @declaredat ASTNode:89
159       */
160      public BooleanLiteral treeCopyNoTransform() {
161        BooleanLiteral tree = (BooleanLiteral) copy();
162        if (children != null) {
163          for (int i = 0; i < children.length; ++i) {
164            ASTNode child = (ASTNode) children[i];
165            if (child != null) {
166              child = child.treeCopyNoTransform();
167              tree.setChild(child, i);
168            }
169          }
170        }
171        return tree;
172      }
173      /**
174       * Create a deep copy of the AST subtree at this node.
175       * The subtree of this node is traversed to trigger rewrites before copy.
176       * The copy is dangling, i.e. has no parent.
177       * @return dangling copy of the subtree at this node
178       * @apilevel low-level
179       * @declaredat ASTNode:109
180       */
181      public BooleanLiteral treeCopy() {
182        doFullTraversal();
183        return treeCopyNoTransform();
184      }
185      /**
186       * @apilevel internal
187       * @declaredat ASTNode:116
188       */
189      protected boolean is$Equal(ASTNode node) {
190        return super.is$Equal(node) && (tokenString_LITERAL == ((BooleanLiteral)node).tokenString_LITERAL);    
191      }
192      /**
193       * Replaces the lexeme LITERAL.
194       * @param value The new value for the lexeme LITERAL.
195       * @apilevel high-level
196       */
197      public void setLITERAL(String value) {
198        tokenString_LITERAL = value;
199      }
200      /**
201       * JastAdd-internal setter for lexeme LITERAL using the Beaver parser.
202       * @param symbol Symbol containing the new value for the lexeme LITERAL
203       * @apilevel internal
204       */
205      public void setLITERAL(beaver.Symbol symbol) {
206        if (symbol.value != null && !(symbol.value instanceof String))
207        throw new UnsupportedOperationException("setLITERAL is only valid for String lexemes");
208        tokenString_LITERAL = (String)symbol.value;
209        LITERALstart = symbol.getStart();
210        LITERALend = symbol.getEnd();
211      }
212      /**
213       * Retrieves the value for the lexeme LITERAL.
214       * @return The value for the lexeme LITERAL.
215       * @apilevel high-level
216       */
217      @ASTNodeAnnotation.Token(name="LITERAL")
218      public String getLITERAL() {
219        return tokenString_LITERAL != null ? tokenString_LITERAL : "";
220      }
221      /**
222       * @apilevel internal
223       */
224      protected boolean constant_computed = false;
225      /**
226       * @apilevel internal
227       */
228      protected Constant constant_value;
229      /**
230       * @apilevel internal
231       */
232      private void constant_reset() {
233        constant_computed = false;
234        constant_value = null;
235      }
236      /**
237       * @attribute syn
238       * @aspect ConstantExpression
239       * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:37
240       */
241      @ASTNodeAnnotation.Attribute
242      public Constant constant() {
243        ASTNode$State state = state();
244        if (constant_computed) {
245          return constant_value;
246        }
247        boolean intermediate = state.INTERMEDIATE_VALUE;
248        state.INTERMEDIATE_VALUE = false;
249        int num = state.boundariesCrossed;
250        boolean isFinal = this.is$Final();
251        constant_value = Constant.create(Boolean.valueOf(getLITERAL()).booleanValue());
252        if (isFinal && num == state().boundariesCrossed) {
253          constant_computed = true;
254        } else {
255        }
256        state.INTERMEDIATE_VALUE |= intermediate;
257    
258        return constant_value;
259      }
260      /**
261       * @attribute syn
262       * @aspect ConstantExpression
263       * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:283
264       */
265      @ASTNodeAnnotation.Attribute
266      public boolean isTrue() {
267        boolean isTrue_value = constant().booleanValue();
268    
269        return isTrue_value;
270      }
271      /**
272       * @attribute syn
273       * @aspect ConstantExpression
274       * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:284
275       */
276      @ASTNodeAnnotation.Attribute
277      public boolean isFalse() {
278        boolean isFalse_value = !constant().booleanValue();
279    
280        return isFalse_value;
281      }
282      /**
283       * @apilevel internal
284       */
285      protected boolean type_computed = false;
286      /**
287       * @apilevel internal
288       */
289      protected TypeDecl type_value;
290      /**
291       * @apilevel internal
292       */
293      private void type_reset() {
294        type_computed = false;
295        type_value = null;
296      }
297      /**
298       * @attribute syn
299       * @aspect TypeAnalysis
300       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:302
301       */
302      @ASTNodeAnnotation.Attribute
303      public TypeDecl type() {
304        ASTNode$State state = state();
305        if (type_computed) {
306          return type_value;
307        }
308        boolean intermediate = state.INTERMEDIATE_VALUE;
309        state.INTERMEDIATE_VALUE = false;
310        int num = state.boundariesCrossed;
311        boolean isFinal = this.is$Final();
312        type_value = typeBoolean();
313        if (isFinal && num == state().boundariesCrossed) {
314          type_computed = true;
315        } else {
316        }
317        state.INTERMEDIATE_VALUE |= intermediate;
318    
319        return type_value;
320      }
321      /**
322       * @apilevel internal
323       */
324      public ASTNode rewriteTo() {
325        return super.rewriteTo();
326      }
327    }