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     * @production ArrayInit : {@link Expr} ::= <span class="component">Init:{@link Expr}*</span>;
015     * @ast node
016     * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/java.ast:93
017     */
018    public class ArrayInit extends Expr implements Cloneable {
019      /**
020       * @apilevel low-level
021       */
022      public void flushCache() {
023      }
024      /**
025       * @apilevel internal
026       */
027      public void flushCollectionCache() {
028      }
029      /**
030       * @apilevel internal
031       */
032      @SuppressWarnings({"unchecked", "cast"})
033      public ArrayInit clone() throws CloneNotSupportedException {
034        ArrayInit node = (ArrayInit)super.clone();
035        node.computeDABefore_int_Variable_values = null;
036        node.computeDUbefore_int_Variable_values = null;
037        node.type_computed = false;
038        node.type_value = null;
039        node.declType_computed = false;
040        node.declType_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 ArrayInit copy() {
050      
051      try {
052        ArrayInit node = (ArrayInit) 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 ArrayInit fullCopy() {
070      
071      ArrayInit tree = (ArrayInit) 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 PrettyPrint
087       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/PrettyPrint.jadd:221
088       */
089      public void toString(StringBuffer s) {
090        s.append("{ ");
091        if(getNumInit() > 0) {
092          getInit(0).toString(s);
093          for(int i = 1; i < getNumInit(); i++) {
094            s.append(", ");
095            getInit(i).toString(s);
096          }
097        }
098        s.append(" } ");
099      }
100      /**
101       * @ast method 
102       * @aspect TypeCheck
103       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeCheck.jrag:144
104       */
105      public void typeCheck() {
106        TypeDecl initializerType = declType().componentType();
107        if(initializerType.isUnknown())
108          error("the dimension of the initializer is larger than the expected dimension");
109        for(int i = 0; i < getNumInit(); i++) {
110          Expr e = getInit(i);
111          if(!e.type().assignConversionTo(initializerType, e))
112            error("the type " + e.type().name() + " of the initializer is not compatible with " + initializerType.name()); 
113        }
114      }
115      /**
116       * @ast method 
117       * 
118       */
119      public ArrayInit() {
120        super();
121    
122    
123      }
124      /**
125       * Initializes the child array to the correct size.
126       * Initializes List and Opt nta children.
127       * @apilevel internal
128       * @ast method
129       * @ast method 
130       * 
131       */
132      public void init$Children() {
133        children = new ASTNode[1];
134        setChild(new List(), 0);
135      }
136      /**
137       * @ast method 
138       * 
139       */
140      public ArrayInit(List<Expr> p0) {
141        setChild(p0, 0);
142      }
143      /**
144       * @apilevel low-level
145       * @ast method 
146       * 
147       */
148      protected int numChildren() {
149        return 1;
150      }
151      /**
152       * @apilevel internal
153       * @ast method 
154       * 
155       */
156      public boolean mayHaveRewrite() {
157        return false;
158      }
159      /**
160       * Replaces the Init list.
161       * @param list The new list node to be used as the Init list.
162       * @apilevel high-level
163       * @ast method 
164       * 
165       */
166      public void setInitList(List<Expr> list) {
167        setChild(list, 0);
168      }
169      /**
170       * Retrieves the number of children in the Init list.
171       * @return Number of children in the Init list.
172       * @apilevel high-level
173       * @ast method 
174       * 
175       */
176      public int getNumInit() {
177        return getInitList().getNumChild();
178      }
179      /**
180       * Retrieves the number of children in the Init list.
181       * Calling this method will not trigger rewrites..
182       * @return Number of children in the Init list.
183       * @apilevel low-level
184       * @ast method 
185       * 
186       */
187      public int getNumInitNoTransform() {
188        return getInitListNoTransform().getNumChildNoTransform();
189      }
190      /**
191       * Retrieves the element at index {@code i} in the Init list..
192       * @param i Index of the element to return.
193       * @return The element at position {@code i} in the Init list.
194       * @apilevel high-level
195       * @ast method 
196       * 
197       */
198      @SuppressWarnings({"unchecked", "cast"})
199      public Expr getInit(int i) {
200        return (Expr)getInitList().getChild(i);
201      }
202      /**
203       * Append an element to the Init list.
204       * @param node The element to append to the Init list.
205       * @apilevel high-level
206       * @ast method 
207       * 
208       */
209      public void addInit(Expr node) {
210        List<Expr> list = (parent == null || state == null) ? getInitListNoTransform() : getInitList();
211        list.addChild(node);
212      }
213      /**
214       * @apilevel low-level
215       * @ast method 
216       * 
217       */
218      public void addInitNoTransform(Expr node) {
219        List<Expr> list = getInitListNoTransform();
220        list.addChild(node);
221      }
222      /**
223       * Replaces the Init list element at index {@code i} with the new node {@code node}.
224       * @param node The new node to replace the old list element.
225       * @param i The list index of the node to be replaced.
226       * @apilevel high-level
227       * @ast method 
228       * 
229       */
230      public void setInit(Expr node, int i) {
231        List<Expr> list = getInitList();
232        list.setChild(node, i);
233      }
234      /**
235       * Retrieves the Init list.
236       * @return The node representing the Init list.
237       * @apilevel high-level
238       * @ast method 
239       * 
240       */
241      public List<Expr> getInits() {
242        return getInitList();
243      }
244      /**
245       * Retrieves the Init list.
246       * <p><em>This method does not invoke AST transformations.</em></p>
247       * @return The node representing the Init list.
248       * @apilevel low-level
249       * @ast method 
250       * 
251       */
252      public List<Expr> getInitsNoTransform() {
253        return getInitListNoTransform();
254      }
255      /**
256       * Retrieves the Init list.
257       * @return The node representing the Init list.
258       * @apilevel high-level
259       * @ast method 
260       * 
261       */
262      @SuppressWarnings({"unchecked", "cast"})
263      public List<Expr> getInitList() {
264        List<Expr> list = (List<Expr>)getChild(0);
265        list.getNumChild();
266        return list;
267      }
268      /**
269       * Retrieves the Init list.
270       * <p><em>This method does not invoke AST transformations.</em></p>
271       * @return The node representing the Init list.
272       * @apilevel low-level
273       * @ast method 
274       * 
275       */
276      @SuppressWarnings({"unchecked", "cast"})
277      public List<Expr> getInitListNoTransform() {
278        return (List<Expr>)getChildNoTransform(0);
279      }
280      /**
281       * @ast method 
282       * @aspect AutoBoxingCodegen
283       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Backend/AutoBoxingCodegen.jrag:266
284       */
285        public void createBCode(CodeGeneration gen) {
286        IntegerLiteral.push(gen, getNumInit());
287        if(type().componentType().isPrimitive() && !type().componentType().isReferenceType()) {
288          gen.emit(Bytecode.NEWARRAY).add(type().componentType().arrayPrimitiveTypeDescriptor());
289        } 
290        else {
291          String n = type().componentType().arrayTypeDescriptor();
292          int index = gen.constantPool().addClass(n);
293          gen.emit(Bytecode.ANEWARRAY).add2(index);
294        }
295        for(int i = 0; i < getNumInit(); i++) {
296          gen.emitDup();
297          IntegerLiteral.push(gen, i);
298          getInit(i).createBCode(gen);
299          if(getInit(i) instanceof ArrayInit)
300            gen.emit(Bytecode.AASTORE);
301          else {
302            getInit(i).type().emitAssignConvTo(gen, expectedType()); // AssignConversion
303            gen.emit(expectedType().arrayStore());
304          }
305        }
306      }
307      /* 
308       * representableIn(T) is true if and only if the the expression is a 
309       * compile-time constant of type byte, char, short or int, and the value  
310       * of the expression can be represented (by an expression) in the type T
311       * where T must be byte, char or short.
312       * @attribute syn
313       * @aspect ConstantExpression
314       * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/ConstantExpression.jrag:308
315       */
316      public boolean representableIn(TypeDecl t) {
317        ASTNode$State state = state();
318        try {
319        for(int i = 0; i < getNumInit(); i++)
320          if(!getInit(i).representableIn(t))
321            return false;
322        return true;
323      }
324        finally {
325        }
326      }
327      /**
328       * @attribute syn
329       * @aspect DA
330       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:235
331       */
332      public boolean isDAafter(Variable v) {
333        ASTNode$State state = state();
334        try {  return getNumInit() == 0 ? isDAbefore(v) : getInit(getNumInit()-1).isDAafter(v);  }
335        finally {
336        }
337      }
338      protected java.util.Map computeDABefore_int_Variable_values;
339      /**
340       * @attribute syn
341       * @aspect DA
342       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:502
343       */
344      @SuppressWarnings({"unchecked", "cast"})
345      public boolean computeDABefore(int childIndex, Variable v) {
346        java.util.List _parameters = new java.util.ArrayList(2);
347        _parameters.add(Integer.valueOf(childIndex));
348        _parameters.add(v);
349        if(computeDABefore_int_Variable_values == null) computeDABefore_int_Variable_values = new java.util.HashMap(4);
350        if(computeDABefore_int_Variable_values.containsKey(_parameters)) {
351          return ((Boolean)computeDABefore_int_Variable_values.get(_parameters)).booleanValue();
352        }
353          ASTNode$State state = state();
354      int num = state.boundariesCrossed;
355      boolean isFinal = this.is$Final();
356        boolean computeDABefore_int_Variable_value = computeDABefore_compute(childIndex, v);
357      if(isFinal && num == state().boundariesCrossed){ computeDABefore_int_Variable_values.put(_parameters, Boolean.valueOf(computeDABefore_int_Variable_value)); }
358            return computeDABefore_int_Variable_value;
359      }
360      /**
361       * @apilevel internal
362       */
363      private boolean computeDABefore_compute(int childIndex, Variable v) {
364        if(childIndex == 0) return isDAbefore(v);
365        int index = childIndex-1;
366        while(index > 0 && getInit(index).isConstant())
367          index--;
368        return getInit(childIndex-1).isDAafter(v);
369      }
370      /**
371       * @attribute syn
372       * @aspect DU
373       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:694
374       */
375      public boolean isDUafter(Variable v) {
376        ASTNode$State state = state();
377        try {  return getNumInit() == 0 ? isDUbefore(v) : getInit(getNumInit()-1).isDUafter(v);  }
378        finally {
379        }
380      }
381      protected java.util.Map computeDUbefore_int_Variable_values;
382      /**
383       * @attribute syn
384       * @aspect DU
385       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:885
386       */
387      @SuppressWarnings({"unchecked", "cast"})
388      public boolean computeDUbefore(int childIndex, Variable v) {
389        java.util.List _parameters = new java.util.ArrayList(2);
390        _parameters.add(Integer.valueOf(childIndex));
391        _parameters.add(v);
392        if(computeDUbefore_int_Variable_values == null) computeDUbefore_int_Variable_values = new java.util.HashMap(4);
393        if(computeDUbefore_int_Variable_values.containsKey(_parameters)) {
394          return ((Boolean)computeDUbefore_int_Variable_values.get(_parameters)).booleanValue();
395        }
396          ASTNode$State state = state();
397      int num = state.boundariesCrossed;
398      boolean isFinal = this.is$Final();
399        boolean computeDUbefore_int_Variable_value = computeDUbefore_compute(childIndex, v);
400      if(isFinal && num == state().boundariesCrossed){ computeDUbefore_int_Variable_values.put(_parameters, Boolean.valueOf(computeDUbefore_int_Variable_value)); }
401            return computeDUbefore_int_Variable_value;
402      }
403      /**
404       * @apilevel internal
405       */
406      private boolean computeDUbefore_compute(int childIndex, Variable v) {
407        if(childIndex == 0) return isDUbefore(v);
408        int index = childIndex-1;
409        while(index > 0 && getInit(index).isConstant())
410          index--;
411        return getInit(childIndex-1).isDUafter(v);
412      }
413      /**
414       * @apilevel internal
415       */
416      protected boolean type_computed = false;
417      /**
418       * @apilevel internal
419       */
420      protected TypeDecl type_value;
421      /**
422       * @attribute syn
423       * @aspect TypeAnalysis
424       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeAnalysis.jrag:265
425       */
426      @SuppressWarnings({"unchecked", "cast"})
427      public TypeDecl type() {
428        if(type_computed) {
429          return type_value;
430        }
431          ASTNode$State state = state();
432      int num = state.boundariesCrossed;
433      boolean isFinal = this.is$Final();
434        type_value = type_compute();
435      if(isFinal && num == state().boundariesCrossed){ type_computed = true; }
436            return type_value;
437      }
438      /**
439       * @apilevel internal
440       */
441      private TypeDecl type_compute() {  return declType();  }
442      /**
443       * @apilevel internal
444       */
445      protected boolean declType_computed = false;
446      /**
447       * @apilevel internal
448       */
449      protected TypeDecl declType_value;
450      /**
451       * @attribute inh
452       * @aspect TypeAnalysis
453       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeAnalysis.jrag:255
454       */
455      @SuppressWarnings({"unchecked", "cast"})
456      public TypeDecl declType() {
457        if(declType_computed) {
458          return declType_value;
459        }
460          ASTNode$State state = state();
461      int num = state.boundariesCrossed;
462      boolean isFinal = this.is$Final();
463        declType_value = getParent().Define_TypeDecl_declType(this, null);
464      if(isFinal && num == state().boundariesCrossed){ declType_computed = true; }
465            return declType_value;
466      }
467      /**
468       * @attribute inh
469       * @aspect InnerClasses
470       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/InnerClasses.jrag:61
471       */
472      @SuppressWarnings({"unchecked", "cast"})
473      public TypeDecl expectedType() {
474          ASTNode$State state = state();
475        TypeDecl expectedType_value = getParent().Define_TypeDecl_expectedType(this, null);
476            return expectedType_value;
477      }
478      /**
479       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:42
480       * @apilevel internal
481       */
482      public boolean Define_boolean_isSource(ASTNode caller, ASTNode child) {
483        if(caller == getInitListNoTransform())  {
484        int childIndex = caller.getIndexOfChild(child);
485        return true;
486      }
487        else {      return getParent().Define_boolean_isSource(this, caller);
488        }
489      }
490      /**
491       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:500
492       * @apilevel internal
493       */
494      public boolean Define_boolean_isDAbefore(ASTNode caller, ASTNode child, Variable v) {
495        if(caller == getInitListNoTransform())  {
496        int childIndex = caller.getIndexOfChild(child);
497        return computeDABefore(childIndex, v);
498      }
499        else {      return getParent().Define_boolean_isDAbefore(this, caller, v);
500        }
501      }
502      /**
503       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:883
504       * @apilevel internal
505       */
506      public boolean Define_boolean_isDUbefore(ASTNode caller, ASTNode child, Variable v) {
507        if(caller == getInitListNoTransform())  {
508        int childIndex = caller.getIndexOfChild(child);
509        return computeDUbefore(childIndex, v);
510      }
511        else {      return getParent().Define_boolean_isDUbefore(this, caller, v);
512        }
513      }
514      /**
515       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeAnalysis.jrag:263
516       * @apilevel internal
517       */
518      public TypeDecl Define_TypeDecl_declType(ASTNode caller, ASTNode child) {
519        if(caller == getInitListNoTransform())  {
520        int childIndex = caller.getIndexOfChild(child);
521        return declType().componentType();
522      }
523        else {      return getParent().Define_TypeDecl_declType(this, caller);
524        }
525      }
526      /**
527       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/InnerClasses.jrag:70
528       * @apilevel internal
529       */
530      public TypeDecl Define_TypeDecl_expectedType(ASTNode caller, ASTNode child) {
531        if(caller == getInitListNoTransform())  {
532        int childIndex = caller.getIndexOfChild(child);
533        return expectedType().componentType();
534      }
535        else {      return getParent().Define_TypeDecl_expectedType(this, caller);
536        }
537      }
538      /**
539       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/GenericMethodsInference.jrag:37
540       * @apilevel internal
541       */
542      public TypeDecl Define_TypeDecl_assignConvertedType(ASTNode caller, ASTNode child) {
543        if(caller == getInitListNoTransform())  {
544        int childIndex = caller.getIndexOfChild(child);
545        return declType().componentType();
546      }
547        else {      return getParent().Define_TypeDecl_assignConvertedType(this, caller);
548        }
549      }
550      /**
551       * @apilevel internal
552       */
553      public ASTNode rewriteTo() {
554        return super.rewriteTo();
555      }
556    }