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 ArrayAccess : {@link Access} ::= <span class="component">{@link Expr}</span>;
015     * @ast node
016     * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/java.ast:31
017     */
018    public class ArrayAccess extends Access 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 ArrayAccess clone() throws CloneNotSupportedException {
034        ArrayAccess node = (ArrayAccess)super.clone();
035        node.type_computed = false;
036        node.type_value = null;
037        node.in$Circle(false);
038        node.is$Final(false);
039        return node;
040      }
041    /**
042     * @apilevel internal
043     */
044      @SuppressWarnings({"unchecked", "cast"})
045    public ArrayAccess copy() {
046      
047      try {
048        ArrayAccess node = (ArrayAccess) clone();
049        node.parent = null;
050        if(children != null)
051          node.children = (ASTNode[]) children.clone();
052        
053        return node;
054      } catch (CloneNotSupportedException e) {
055        throw new Error("Error: clone not supported for " + getClass().getName());
056      }
057      
058    }/**
059     * Create a deep copy of the AST subtree at this node.
060     * The copy is dangling, i.e. has no parent.
061     * @return dangling copy of the subtree at this node
062     * @apilevel low-level
063     */
064      @SuppressWarnings({"unchecked", "cast"})
065    public ArrayAccess fullCopy() {
066      
067      ArrayAccess tree = (ArrayAccess) copy();
068      if (children != null) {
069        for (int i = 0; i < children.length; ++i) {
070          
071          ASTNode child = (ASTNode) children[i];
072          if(child != null) {
073            child = child.fullCopy();
074            tree.setChild(child, i);
075          }
076        }
077      }
078      return tree;
079      
080    }  /**
081       * @ast method 
082       * @aspect PrettyPrint
083       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/PrettyPrint.jadd:514
084       */
085      public void toString(StringBuffer s) {
086        s.append("[");
087        getExpr().toString(s);
088        s.append("]");
089      }
090      /**
091       * @ast method 
092       * @aspect TypeCheck
093       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeCheck.jrag:137
094       */
095      public void typeCheck() {
096        if(isQualified() && !qualifier().type().isArrayDecl() && !qualifier().type().isUnknown())
097          error("the type " + qualifier().type().name() + " of the indexed element is not an array");
098        if(!getExpr().type().unaryNumericPromotion().isInt() || !getExpr().type().isIntegralType())
099          error("array index must be int after unary numeric promotion which " + getExpr().type().typeName() + " is not");
100      }
101      /**
102       * @ast method 
103       * @aspect CodeGeneration
104       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CodeGeneration.jrag:720
105       */
106      public void emitStore(CodeGeneration gen) {
107        gen.emit(type().arrayStore());
108      }
109      /**
110       * @ast method 
111       * @aspect CreateBCode
112       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:379
113       */
114      public void createPushAssignmentResult(CodeGeneration gen) {
115        type().emitDup_x2(gen);
116      }
117      /**
118       * @ast method 
119       * 
120       */
121      public ArrayAccess() {
122        super();
123    
124    
125      }
126      /**
127       * Initializes the child array to the correct size.
128       * Initializes List and Opt nta children.
129       * @apilevel internal
130       * @ast method
131       * @ast method 
132       * 
133       */
134      public void init$Children() {
135        children = new ASTNode[1];
136      }
137      /**
138       * @ast method 
139       * 
140       */
141      public ArrayAccess(Expr p0) {
142        setChild(p0, 0);
143      }
144      /**
145       * @apilevel low-level
146       * @ast method 
147       * 
148       */
149      protected int numChildren() {
150        return 1;
151      }
152      /**
153       * @apilevel internal
154       * @ast method 
155       * 
156       */
157      public boolean mayHaveRewrite() {
158        return false;
159      }
160      /**
161       * Replaces the Expr child.
162       * @param node The new node to replace the Expr child.
163       * @apilevel high-level
164       * @ast method 
165       * 
166       */
167      public void setExpr(Expr node) {
168        setChild(node, 0);
169      }
170      /**
171       * Retrieves the Expr child.
172       * @return The current node used as the Expr child.
173       * @apilevel high-level
174       * @ast method 
175       * 
176       */
177      public Expr getExpr() {
178        return (Expr)getChild(0);
179      }
180      /**
181       * Retrieves the Expr child.
182       * <p><em>This method does not invoke AST transformations.</em></p>
183       * @return The current node used as the Expr child.
184       * @apilevel low-level
185       * @ast method 
186       * 
187       */
188      public Expr getExprNoTransform() {
189        return (Expr)getChildNoTransform(0);
190      }
191      /**
192       * @ast method 
193       * @aspect AutoBoxingCodegen
194       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Backend/AutoBoxingCodegen.jrag:370
195       */
196        public void createAssignSimpleLoadDest(CodeGeneration gen) {
197        prevExpr().createBCode(gen);
198        getExpr().createBCode(gen);
199        getExpr().type().emitCastTo(gen, typeInt());
200      }
201      /**
202       * @ast method 
203       * @aspect AutoBoxingCodegen
204       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Backend/AutoBoxingCodegen.jrag:376
205       */
206        public void createAssignLoadDest(CodeGeneration gen) {
207        prevExpr().createBCode(gen);
208        gen.emitDup();
209        getExpr().createBCode(gen);
210        getExpr().type().emitCastTo(gen, typeInt());
211        typeInt().emitDup_x1(gen);
212        gen.emit(type().arrayLoad());
213      }
214      /**
215       * @ast method 
216       * @aspect AutoBoxingCodegen
217       * @declaredat /home/jesper/svn/JastAddJ/Java1.5Backend/AutoBoxingCodegen.jrag:363
218       */
219        public void createBCode(CodeGeneration gen) {
220        prevExpr().createBCode(gen);
221        getExpr().createBCode(gen);
222        getExpr().type().emitCastTo(gen, typeInt());
223        gen.emit(type().arrayLoad());
224      }
225      /**
226       * @attribute syn
227       * @aspect DA
228       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:235
229       */
230      public boolean isDAafter(Variable v) {
231        ASTNode$State state = state();
232        try {  return getExpr().isDAafter(v);  }
233        finally {
234        }
235      }
236      /**
237       * @attribute syn
238       * @aspect DU
239       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:694
240       */
241      public boolean isDUafter(Variable v) {
242        ASTNode$State state = state();
243        try {  return getExpr().isDUafter(v);  }
244        finally {
245        }
246      }
247      /**
248       * @attribute syn
249       * @aspect AccessTypes
250       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/ResolveAmbiguousNames.jrag:41
251       */
252      public boolean isArrayAccess() {
253        ASTNode$State state = state();
254        try {  return true;  }
255        finally {
256        }
257      }
258      /**
259       * @attribute syn
260       * @aspect SyntacticClassification
261       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/SyntacticClassification.jrag:56
262       */
263      public NameType predNameType() {
264        ASTNode$State state = state();
265        try {  return NameType.EXPRESSION_NAME;  }
266        finally {
267        }
268      }
269      /**
270       * @apilevel internal
271       */
272      protected boolean type_computed = false;
273      /**
274       * @apilevel internal
275       */
276      protected TypeDecl type_value;
277      /**
278       * @attribute syn
279       * @aspect TypeAnalysis
280       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeAnalysis.jrag:280
281       */
282      @SuppressWarnings({"unchecked", "cast"})
283      public TypeDecl type() {
284        if(type_computed) {
285          return type_value;
286        }
287          ASTNode$State state = state();
288      int num = state.boundariesCrossed;
289      boolean isFinal = this.is$Final();
290        type_value = type_compute();
291      if(isFinal && num == state().boundariesCrossed){ type_computed = true; }
292            return type_value;
293      }
294      /**
295       * @apilevel internal
296       */
297      private TypeDecl type_compute() {  return isQualified() ? qualifier().type().componentType() : unknownType();  }
298      /**
299       * @attribute syn
300       * @aspect TypeCheck
301       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeCheck.jrag:15
302       */
303      public boolean isVariable() {
304        ASTNode$State state = state();
305        try {  return true;  }
306        finally {
307        }
308      }
309      /**
310       * @attribute inh
311       * @aspect TypeAnalysis
312       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeAnalysis.jrag:281
313       */
314      @SuppressWarnings({"unchecked", "cast"})
315      public TypeDecl unknownType() {
316          ASTNode$State state = state();
317        TypeDecl unknownType_value = getParent().Define_TypeDecl_unknownType(this, null);
318            return unknownType_value;
319      }
320      /**
321       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:34
322       * @apilevel internal
323       */
324      public boolean Define_boolean_isDest(ASTNode caller, ASTNode child) {
325        if(caller == getExprNoTransform()) {
326          return false;
327        }
328        else {      return getParent().Define_boolean_isDest(this, caller);
329        }
330      }
331      /**
332       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:35
333       * @apilevel internal
334       */
335      public boolean Define_boolean_isSource(ASTNode caller, ASTNode child) {
336        if(caller == getExprNoTransform()) {
337          return true;
338        }
339        else {      return getParent().Define_boolean_isSource(this, caller);
340        }
341      }
342      /**
343       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/LookupMethod.jrag:30
344       * @apilevel internal
345       */
346      public Collection Define_Collection_lookupMethod(ASTNode caller, ASTNode child, String name) {
347        if(caller == getExprNoTransform()) {
348          return unqualifiedScope().lookupMethod(name);
349        }
350        else {      return getParent().Define_Collection_lookupMethod(this, caller, name);
351        }
352      }
353      /**
354       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/LookupType.jrag:90
355       * @apilevel internal
356       */
357      public boolean Define_boolean_hasPackage(ASTNode caller, ASTNode child, String packageName) {
358        if(caller == getExprNoTransform()) {
359          return unqualifiedScope().hasPackage(packageName);
360        }
361        else {      return getParent().Define_boolean_hasPackage(this, caller, packageName);
362        }
363      }
364      /**
365       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/LookupType.jrag:255
366       * @apilevel internal
367       */
368      public SimpleSet Define_SimpleSet_lookupType(ASTNode caller, ASTNode child, String name) {
369        if(caller == getExprNoTransform()) {
370          return unqualifiedScope().lookupType(name);
371        }
372        else {      return getParent().Define_SimpleSet_lookupType(this, caller, name);
373        }
374      }
375      /**
376       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/LookupVariable.jrag:135
377       * @apilevel internal
378       */
379      public SimpleSet Define_SimpleSet_lookupVariable(ASTNode caller, ASTNode child, String name) {
380        if(caller == getExprNoTransform()) {
381          return unqualifiedScope().lookupVariable(name);
382        }
383        else {      return getParent().Define_SimpleSet_lookupVariable(this, caller, name);
384        }
385      }
386      /**
387       * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/SyntacticClassification.jrag:122
388       * @apilevel internal
389       */
390      public NameType Define_NameType_nameType(ASTNode caller, ASTNode child) {
391        if(caller == getExprNoTransform()) {
392          return NameType.EXPRESSION_NAME;
393        }
394        else {      return getParent().Define_NameType_nameType(this, caller);
395        }
396      }
397      /**
398       * @apilevel internal
399       */
400      public ASTNode rewriteTo() {
401        return super.rewriteTo();
402      }
403    }