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