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     * @ast node
026     * @declaredat /home/jesper/git/extendj/java4/grammar/Java.ast:54
027     * @production ShortType : {@link IntegralType};
028    
029     */
030    public class ShortType extends IntegralType implements Cloneable {
031      /**
032       * @aspect Java4PrettyPrint
033       * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:478
034       */
035      public void prettyPrint(PrettyPrinter out) {
036        out.print("short");
037      }
038      /**
039       * @aspect CodeGenerationConversions
040       * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:586
041       */
042      void emitCastTo(CodeGeneration gen, TypeDecl type)    { type.shortToThis(gen); }
043      /**
044       * @aspect CodeGenerationConversions
045       * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:598
046       */
047      void intToThis(CodeGeneration gen)  { gen.emit(Bytecode.I2S); }
048      /**
049       * @aspect CodeGenerationConversions
050       * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:603
051       */
052      void floatToThis(CodeGeneration gen)  { gen.emit(Bytecode.F2I).emit(Bytecode.I2S); }
053      /**
054       * @aspect CodeGenerationConversions
055       * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:612
056       */
057      void doubleToThis(CodeGeneration gen)  { gen.emit(Bytecode.D2I).emit(Bytecode.I2S); }
058      /**
059       * @aspect CodeGenerationConversions
060       * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:621
061       */
062      void longToThis(CodeGeneration gen)  { gen.emit(Bytecode.L2I).emit(Bytecode.I2S); }
063      /**
064       * @aspect CodeGenerationConversions
065       * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:637
066       */
067      void charToThis(CodeGeneration gen)    { gen.emit(Bytecode.I2S); }
068      /**
069       * @declaredat ASTNode:1
070       */
071      public ShortType() {
072        super();
073      }
074      /**
075       * Initializes the child array to the correct size.
076       * Initializes List and Opt nta children.
077       * @apilevel internal
078       * @ast method
079       * @declaredat ASTNode:10
080       */
081      public void init$Children() {
082        children = new ASTNode[3];
083        setChild(new Opt(), 1);
084        setChild(new List(), 2);
085      }
086      /**
087       * @declaredat ASTNode:15
088       */
089      public ShortType(Modifiers p0, String p1, Opt<Access> p2, List<BodyDecl> p3) {
090        setChild(p0, 0);
091        setID(p1);
092        setChild(p2, 1);
093        setChild(p3, 2);
094      }
095      /**
096       * @declaredat ASTNode:21
097       */
098      public ShortType(Modifiers p0, beaver.Symbol p1, Opt<Access> p2, List<BodyDecl> p3) {
099        setChild(p0, 0);
100        setID(p1);
101        setChild(p2, 1);
102        setChild(p3, 2);
103      }
104      /**
105       * @apilevel low-level
106       * @declaredat ASTNode:30
107       */
108      protected int numChildren() {
109        return 3;
110      }
111      /**
112       * @apilevel internal
113       * @declaredat ASTNode:36
114       */
115      public boolean mayHaveRewrite() {
116        return false;
117      }
118      /**
119       * @apilevel internal
120       * @declaredat ASTNode:42
121       */
122      public void flushAttrCache() {
123        super.flushAttrCache();
124        narrowingConversionTo_TypeDecl_reset();
125        unaryNumericPromotion_reset();
126        typeDescriptor_reset();
127        jvmName_reset();
128        boxed_reset();
129      }
130      /**
131       * @apilevel internal
132       * @declaredat ASTNode:53
133       */
134      public void flushCollectionCache() {
135        super.flushCollectionCache();
136      }
137      /**
138       * @apilevel internal
139       * @declaredat ASTNode:59
140       */
141      public void flushRewriteCache() {
142        super.flushRewriteCache();
143      }
144      /**
145       * @apilevel internal
146       * @declaredat ASTNode:65
147       */
148      public ShortType clone() throws CloneNotSupportedException {
149        ShortType node = (ShortType) super.clone();
150        return node;
151      }
152      /**
153       * @apilevel internal
154       * @declaredat ASTNode:72
155       */
156      public ShortType copy() {
157        try {
158          ShortType node = (ShortType) clone();
159          node.parent = null;
160          if (children != null) {
161            node.children = (ASTNode[]) children.clone();
162          }
163          return node;
164        } catch (CloneNotSupportedException e) {
165          throw new Error("Error: clone not supported for " + getClass().getName());
166        }
167      }
168      /**
169       * Create a deep copy of the AST subtree at this node.
170       * The copy is dangling, i.e. has no parent.
171       * @return dangling copy of the subtree at this node
172       * @apilevel low-level
173       * @deprecated Please use treeCopy or treeCopyNoTransform instead
174       * @declaredat ASTNode:91
175       */
176      @Deprecated
177      public ShortType fullCopy() {
178        return treeCopyNoTransform();
179      }
180      /**
181       * Create a deep copy of the AST subtree at this node.
182       * The copy is dangling, i.e. has no parent.
183       * @return dangling copy of the subtree at this node
184       * @apilevel low-level
185       * @declaredat ASTNode:101
186       */
187      public ShortType treeCopyNoTransform() {
188        ShortType tree = (ShortType) copy();
189        if (children != null) {
190          for (int i = 0; i < children.length; ++i) {
191            ASTNode child = (ASTNode) children[i];
192            if (child != null) {
193              child = child.treeCopyNoTransform();
194              tree.setChild(child, i);
195            }
196          }
197        }
198        return tree;
199      }
200      /**
201       * Create a deep copy of the AST subtree at this node.
202       * The subtree of this node is traversed to trigger rewrites before copy.
203       * The copy is dangling, i.e. has no parent.
204       * @return dangling copy of the subtree at this node
205       * @apilevel low-level
206       * @declaredat ASTNode:121
207       */
208      public ShortType treeCopy() {
209        doFullTraversal();
210        return treeCopyNoTransform();
211      }
212      /**
213       * @apilevel internal
214       * @declaredat ASTNode:128
215       */
216      protected boolean is$Equal(ASTNode node) {
217        return super.is$Equal(node) && (tokenString_ID == ((ShortType)node).tokenString_ID);    
218      }
219      /**
220       * Replaces the Modifiers child.
221       * @param node The new node to replace the Modifiers child.
222       * @apilevel high-level
223       */
224      public void setModifiers(Modifiers node) {
225        setChild(node, 0);
226      }
227      /**
228       * Retrieves the Modifiers child.
229       * @return The current node used as the Modifiers child.
230       * @apilevel high-level
231       */
232      @ASTNodeAnnotation.Child(name="Modifiers")
233      public Modifiers getModifiers() {
234        return (Modifiers) getChild(0);
235      }
236      /**
237       * Retrieves the Modifiers child.
238       * <p><em>This method does not invoke AST transformations.</em></p>
239       * @return The current node used as the Modifiers child.
240       * @apilevel low-level
241       */
242      public Modifiers getModifiersNoTransform() {
243        return (Modifiers) getChildNoTransform(0);
244      }
245      /**
246       * Replaces the lexeme ID.
247       * @param value The new value for the lexeme ID.
248       * @apilevel high-level
249       */
250      public void setID(String value) {
251        tokenString_ID = value;
252      }
253      /**
254       * JastAdd-internal setter for lexeme ID using the Beaver parser.
255       * @param symbol Symbol containing the new value for the lexeme ID
256       * @apilevel internal
257       */
258      public void setID(beaver.Symbol symbol) {
259        if (symbol.value != null && !(symbol.value instanceof String))
260        throw new UnsupportedOperationException("setID is only valid for String lexemes");
261        tokenString_ID = (String)symbol.value;
262        IDstart = symbol.getStart();
263        IDend = symbol.getEnd();
264      }
265      /**
266       * Retrieves the value for the lexeme ID.
267       * @return The value for the lexeme ID.
268       * @apilevel high-level
269       */
270      @ASTNodeAnnotation.Token(name="ID")
271      public String getID() {
272        return tokenString_ID != null ? tokenString_ID : "";
273      }
274      /**
275       * Replaces the optional node for the SuperClass child. This is the <code>Opt</code>
276       * node containing the child SuperClass, not the actual child!
277       * @param opt The new node to be used as the optional node for the SuperClass child.
278       * @apilevel low-level
279       */
280      public void setSuperClassOpt(Opt<Access> opt) {
281        setChild(opt, 1);
282      }
283      /**
284       * Replaces the (optional) SuperClass child.
285       * @param node The new node to be used as the SuperClass child.
286       * @apilevel high-level
287       */
288      public void setSuperClass(Access node) {
289        getSuperClassOpt().setChild(node, 0);
290      }
291      /**
292       * Check whether the optional SuperClass child exists.
293       * @return {@code true} if the optional SuperClass child exists, {@code false} if it does not.
294       * @apilevel high-level
295       */
296      public boolean hasSuperClass() {
297        return getSuperClassOpt().getNumChild() != 0;
298      }
299      /**
300       * Retrieves the (optional) SuperClass child.
301       * @return The SuperClass child, if it exists. Returns {@code null} otherwise.
302       * @apilevel low-level
303       */
304      public Access getSuperClass() {
305        return (Access) getSuperClassOpt().getChild(0);
306      }
307      /**
308       * Retrieves the optional node for the SuperClass child. This is the <code>Opt</code> node containing the child SuperClass, not the actual child!
309       * @return The optional node for child the SuperClass child.
310       * @apilevel low-level
311       */
312      @ASTNodeAnnotation.OptChild(name="SuperClass")
313      public Opt<Access> getSuperClassOpt() {
314        return (Opt<Access>) getChild(1);
315      }
316      /**
317       * Retrieves the optional node for child SuperClass. This is the <code>Opt</code> node containing the child SuperClass, not the actual child!
318       * <p><em>This method does not invoke AST transformations.</em></p>
319       * @return The optional node for child SuperClass.
320       * @apilevel low-level
321       */
322      public Opt<Access> getSuperClassOptNoTransform() {
323        return (Opt<Access>) getChildNoTransform(1);
324      }
325      /**
326       * Replaces the BodyDecl list.
327       * @param list The new list node to be used as the BodyDecl list.
328       * @apilevel high-level
329       */
330      public void setBodyDeclList(List<BodyDecl> list) {
331        setChild(list, 2);
332      }
333      /**
334       * Retrieves the number of children in the BodyDecl list.
335       * @return Number of children in the BodyDecl list.
336       * @apilevel high-level
337       */
338      public int getNumBodyDecl() {
339        return getBodyDeclList().getNumChild();
340      }
341      /**
342       * Retrieves the number of children in the BodyDecl list.
343       * Calling this method will not trigger rewrites.
344       * @return Number of children in the BodyDecl list.
345       * @apilevel low-level
346       */
347      public int getNumBodyDeclNoTransform() {
348        return getBodyDeclListNoTransform().getNumChildNoTransform();
349      }
350      /**
351       * Retrieves the element at index {@code i} in the BodyDecl list.
352       * @param i Index of the element to return.
353       * @return The element at position {@code i} in the BodyDecl list.
354       * @apilevel high-level
355       */
356      public BodyDecl getBodyDecl(int i) {
357        return (BodyDecl) getBodyDeclList().getChild(i);
358      }
359      /**
360       * Check whether the BodyDecl list has any children.
361       * @return {@code true} if it has at least one child, {@code false} otherwise.
362       * @apilevel high-level
363       */
364      public boolean hasBodyDecl() {
365        return getBodyDeclList().getNumChild() != 0;
366      }
367      /**
368       * Append an element to the BodyDecl list.
369       * @param node The element to append to the BodyDecl list.
370       * @apilevel high-level
371       */
372      public void addBodyDecl(BodyDecl node) {
373        List<BodyDecl> list = (parent == null) ? getBodyDeclListNoTransform() : getBodyDeclList();
374        list.addChild(node);
375      }
376      /**
377       * @apilevel low-level
378       */
379      public void addBodyDeclNoTransform(BodyDecl node) {
380        List<BodyDecl> list = getBodyDeclListNoTransform();
381        list.addChild(node);
382      }
383      /**
384       * Replaces the BodyDecl list element at index {@code i} with the new node {@code node}.
385       * @param node The new node to replace the old list element.
386       * @param i The list index of the node to be replaced.
387       * @apilevel high-level
388       */
389      public void setBodyDecl(BodyDecl node, int i) {
390        List<BodyDecl> list = getBodyDeclList();
391        list.setChild(node, i);
392      }
393      /**
394       * Retrieves the BodyDecl list.
395       * @return The node representing the BodyDecl list.
396       * @apilevel high-level
397       */
398      @ASTNodeAnnotation.ListChild(name="BodyDecl")
399      public List<BodyDecl> getBodyDeclList() {
400        List<BodyDecl> list = (List<BodyDecl>) getChild(2);
401        return list;
402      }
403      /**
404       * Retrieves the BodyDecl list.
405       * <p><em>This method does not invoke AST transformations.</em></p>
406       * @return The node representing the BodyDecl list.
407       * @apilevel low-level
408       */
409      public List<BodyDecl> getBodyDeclListNoTransform() {
410        return (List<BodyDecl>) getChildNoTransform(2);
411      }
412      /**
413       * Retrieves the BodyDecl list.
414       * @return The node representing the BodyDecl list.
415       * @apilevel high-level
416       */
417      public List<BodyDecl> getBodyDecls() {
418        return getBodyDeclList();
419      }
420      /**
421       * Retrieves the BodyDecl list.
422       * <p><em>This method does not invoke AST transformations.</em></p>
423       * @return The node representing the BodyDecl list.
424       * @apilevel low-level
425       */
426      public List<BodyDecl> getBodyDeclsNoTransform() {
427        return getBodyDeclListNoTransform();
428      }
429      /**
430       * @attribute syn
431       * @aspect ConstantExpression
432       * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:72
433       */
434      @ASTNodeAnnotation.Attribute
435      public Constant cast(Constant c) {
436        Constant cast_Constant_value = Constant.create((short) c.intValue());
437    
438        return cast_Constant_value;
439      }
440      /**
441       * @apilevel internal
442       */
443      protected java.util.Map narrowingConversionTo_TypeDecl_values;
444      /**
445       * @apilevel internal
446       */
447      private void narrowingConversionTo_TypeDecl_reset() {
448        narrowingConversionTo_TypeDecl_values = null;
449      }
450      /**
451       * @attribute syn
452       * @aspect TypeConversion
453       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:39
454       */
455      @ASTNodeAnnotation.Attribute
456      public boolean narrowingConversionTo(TypeDecl type) {
457        Object _parameters = type;
458        if (narrowingConversionTo_TypeDecl_values == null) narrowingConversionTo_TypeDecl_values = new org.jastadd.util.RobustMap(new java.util.HashMap());
459        ASTNode$State state = state();
460        if (narrowingConversionTo_TypeDecl_values.containsKey(_parameters)) {
461          return (Boolean) narrowingConversionTo_TypeDecl_values.get(_parameters);
462        }
463        boolean intermediate = state.INTERMEDIATE_VALUE;
464        state.INTERMEDIATE_VALUE = false;
465        int num = state.boundariesCrossed;
466        boolean isFinal = this.is$Final();
467        boolean narrowingConversionTo_TypeDecl_value = type.isByte() || type.isChar();
468        if (isFinal && num == state().boundariesCrossed) {
469          narrowingConversionTo_TypeDecl_values.put(_parameters, narrowingConversionTo_TypeDecl_value);
470        } else {
471        }
472        state.INTERMEDIATE_VALUE |= intermediate;
473    
474        return narrowingConversionTo_TypeDecl_value;
475      }
476      /**
477       * @apilevel internal
478       */
479      protected boolean unaryNumericPromotion_computed = false;
480      /**
481       * @apilevel internal
482       */
483      protected TypeDecl unaryNumericPromotion_value;
484      /**
485       * @apilevel internal
486       */
487      private void unaryNumericPromotion_reset() {
488        unaryNumericPromotion_computed = false;
489        unaryNumericPromotion_value = null;
490      }
491      /**
492       * @attribute syn
493       * @aspect NumericPromotion
494       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:169
495       */
496      @ASTNodeAnnotation.Attribute
497      public TypeDecl unaryNumericPromotion() {
498        ASTNode$State state = state();
499        if (unaryNumericPromotion_computed) {
500          return unaryNumericPromotion_value;
501        }
502        boolean intermediate = state.INTERMEDIATE_VALUE;
503        state.INTERMEDIATE_VALUE = false;
504        int num = state.boundariesCrossed;
505        boolean isFinal = this.is$Final();
506        unaryNumericPromotion_value = typeInt();
507        if (isFinal && num == state().boundariesCrossed) {
508          unaryNumericPromotion_computed = true;
509        } else {
510        }
511        state.INTERMEDIATE_VALUE |= intermediate;
512    
513        return unaryNumericPromotion_value;
514      }
515      /**
516       * @attribute syn
517       * @aspect TypeAnalysis
518       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:211
519       */
520      @ASTNodeAnnotation.Attribute
521      public boolean isShort() {
522        boolean isShort_value = true;
523    
524        return isShort_value;
525      }
526      /**
527       * @attribute syn
528       * @aspect CodeGeneration
529       * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:249
530       */
531      @ASTNodeAnnotation.Attribute
532      public byte arrayLoad() {
533        byte arrayLoad_value = Bytecode.SALOAD;
534    
535        return arrayLoad_value;
536      }
537      /**
538       * @attribute syn
539       * @aspect CodeGeneration
540       * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:380
541       */
542      @ASTNodeAnnotation.Attribute
543      public byte arrayStore() {
544        byte arrayStore_value = Bytecode.SASTORE;
545    
546        return arrayStore_value;
547      }
548      /**
549       * @apilevel internal
550       */
551      protected boolean typeDescriptor_computed = false;
552      /**
553       * @apilevel internal
554       */
555      protected String typeDescriptor_value;
556      /**
557       * @apilevel internal
558       */
559      private void typeDescriptor_reset() {
560        typeDescriptor_computed = false;
561        typeDescriptor_value = null;
562      }
563      /**
564       * @attribute syn
565       * @aspect ConstantPoolNames
566       * @declaredat /home/jesper/git/extendj/java4/backend/ConstantPoolNames.jrag:77
567       */
568      @ASTNodeAnnotation.Attribute
569      public String typeDescriptor() {
570        ASTNode$State state = state();
571        if (typeDescriptor_computed) {
572          return typeDescriptor_value;
573        }
574        boolean intermediate = state.INTERMEDIATE_VALUE;
575        state.INTERMEDIATE_VALUE = false;
576        int num = state.boundariesCrossed;
577        boolean isFinal = this.is$Final();
578        typeDescriptor_value = "S";
579        if (isFinal && num == state().boundariesCrossed) {
580          typeDescriptor_computed = true;
581        } else {
582        }
583        state.INTERMEDIATE_VALUE |= intermediate;
584    
585        return typeDescriptor_value;
586      }
587      /**
588       * @attribute syn
589       * @aspect CreateBCode
590       * @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:905
591       */
592      @ASTNodeAnnotation.Attribute
593      public int arrayPrimitiveTypeDescriptor() {
594        int arrayPrimitiveTypeDescriptor_value = 9;
595    
596        return arrayPrimitiveTypeDescriptor_value;
597      }
598      /**
599       * @attribute syn
600       * @aspect InnerClasses
601       * @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:113
602       */
603      @ASTNodeAnnotation.Attribute
604      public TypeDecl stringPromotion() {
605        TypeDecl stringPromotion_value = typeInt();
606    
607        return stringPromotion_value;
608      }
609      /**
610       * @apilevel internal
611       */
612      protected boolean jvmName_computed = false;
613      /**
614       * @apilevel internal
615       */
616      protected String jvmName_value;
617      /**
618       * @apilevel internal
619       */
620      private void jvmName_reset() {
621        jvmName_computed = false;
622        jvmName_value = null;
623      }
624      /**
625       * @attribute syn
626       * @aspect Java2Rewrites
627       * @declaredat /home/jesper/git/extendj/java4/backend/Java2Rewrites.jrag:36
628       */
629      @ASTNodeAnnotation.Attribute
630      public String jvmName() {
631        ASTNode$State state = state();
632        if (jvmName_computed) {
633          return jvmName_value;
634        }
635        boolean intermediate = state.INTERMEDIATE_VALUE;
636        state.INTERMEDIATE_VALUE = false;
637        int num = state.boundariesCrossed;
638        boolean isFinal = this.is$Final();
639        jvmName_value = "S";
640        if (isFinal && num == state().boundariesCrossed) {
641          jvmName_computed = true;
642        } else {
643        }
644        state.INTERMEDIATE_VALUE |= intermediate;
645    
646        return jvmName_value;
647      }
648      /**
649       * @attribute syn
650       * @aspect Java2Rewrites
651       * @declaredat /home/jesper/git/extendj/java4/backend/Java2Rewrites.jrag:68
652       */
653      @ASTNodeAnnotation.Attribute
654      public String primitiveClassName() {
655        String primitiveClassName_value = "Short";
656    
657        return primitiveClassName_value;
658      }
659      /**
660       * @apilevel internal
661       */
662      protected boolean boxed_computed = false;
663      /**
664       * @apilevel internal
665       */
666      protected TypeDecl boxed_value;
667      /**
668       * @apilevel internal
669       */
670      private void boxed_reset() {
671        boxed_computed = false;
672        boxed_value = null;
673      }
674      /**
675       * @attribute syn
676       * @aspect AutoBoxing
677       * @declaredat /home/jesper/git/extendj/java5/frontend/AutoBoxing.jrag:56
678       */
679      @ASTNodeAnnotation.Attribute
680      public TypeDecl boxed() {
681        ASTNode$State state = state();
682        if (boxed_computed) {
683          return boxed_value;
684        }
685        boolean intermediate = state.INTERMEDIATE_VALUE;
686        state.INTERMEDIATE_VALUE = false;
687        int num = state.boundariesCrossed;
688        boolean isFinal = this.is$Final();
689        boxed_value = lookupType("java.lang", "Short");
690        if (isFinal && num == state().boundariesCrossed) {
691          boxed_computed = true;
692        } else {
693        }
694        state.INTERMEDIATE_VALUE |= intermediate;
695    
696        return boxed_value;
697      }
698      /**
699       * @apilevel internal
700       */
701      public ASTNode rewriteTo() {
702        return super.rewriteTo();
703      }
704    }