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:21
027     * @production SuperConstructorAccess : {@link ConstructorAccess};
028    
029     */
030    public class SuperConstructorAccess extends ConstructorAccess implements Cloneable {
031      /**
032       * @aspect TypeHierarchyCheck
033       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:94
034       */
035      public void nameCheck() {
036        super.nameCheck();
037        // JLS 5?: 8.8.5.1
038        // JLS 7: 8.8.7.1
039        TypeDecl c = hostType();
040        TypeDecl s = c.isClassDecl() ? ((ClassDecl) c).superclass() : unknownType();
041        if (isQualified()) {
042          if (!s.isInnerType() || s.inStaticContext()) {
043            errorf("the super type %s of %s is not an inner class", s.typeName(), c.typeName());
044          } else if (!qualifier().type().instanceOf(s.enclosingType())) {
045            errorf("The type of this primary expression, %s is not enclosing the super type, %s, of %s",
046                qualifier().type().typeName(), s.typeName(), c.typeName());
047          }
048        }
049        if (!isQualified() && s.isInnerType()) {
050          if (!c.isInnerType()) {
051            errorf("no enclosing instance for %s when accessed in %s", s.typeName(), this.prettyPrint());
052          }
053        }
054        if (s.isInnerType() && hostType().instanceOf(s.enclosingType())) {
055          error("cannot reference 'this' before supertype constructor has been called");
056        }
057      }
058      /**
059       * @aspect CreateBCode
060       * @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:715
061       */
062      public void createBCode(CodeGeneration gen) {
063        ConstructorDecl c = decl();
064    
065        // this
066        gen.emit(Bytecode.ALOAD_0);
067    
068        if (c.needsEnclosing()) {
069          if (hasPrevExpr() && !prevExpr().isTypeAccess()) {
070            prevExpr().createBCode(gen);
071            gen.emitDup();
072            int index = gen.constantPool().addMethodref("java/lang/Object", "getClass", "()Ljava/lang/Class;");
073            gen.emit(Bytecode.INVOKEVIRTUAL, 0).add2(index);
074            gen.emitPop();
075          } else {
076            if (hostType().needsSuperEnclosing()) {
077              if (hostType().needsEnclosing()) {
078                gen.emit(Bytecode.ALOAD_2);
079              } else {
080                gen.emit(Bytecode.ALOAD_1);
081              }
082            } else {
083              emitThis(gen, superConstructorQualifier(c.hostType().enclosingType()));
084            }
085          }
086        }
087    
088        // args
089        for (int i = 0; i < getNumArg(); ++i) {
090          getArg(i).createBCode(gen);
091          getArg(i).type().emitCastTo(gen, decl().getParameter(i).type()); // MethodInvocationConversion
092        }
093        if (decl().isPrivate() && decl().hostType() != hostType()) {
094          gen.emit(Bytecode.ACONST_NULL);
095          decl().createAccessor().emitInvokeConstructor(gen);
096        } else {
097          decl().emitInvokeConstructor(gen);
098        }
099      }
100      /**
101       * @aspect Transformations
102       * @declaredat /home/jesper/git/extendj/java4/backend/Transformations.jrag:143
103       */
104      public void transformation() {
105        // this$val
106        addEnclosingVariables();
107        // touch accessorIndex to force creation of private constructorAccessor
108        if (decl().isPrivate() && decl().hostType() != hostType()) {
109          decl().createAccessor();
110        }
111        super.transformation();
112      }
113      /**
114       * @declaredat ASTNode:1
115       */
116      public SuperConstructorAccess() {
117        super();
118      }
119      /**
120       * Initializes the child array to the correct size.
121       * Initializes List and Opt nta children.
122       * @apilevel internal
123       * @ast method
124       * @declaredat ASTNode:10
125       */
126      public void init$Children() {
127        children = new ASTNode[1];
128        setChild(new List(), 0);
129      }
130      /**
131       * @declaredat ASTNode:14
132       */
133      public SuperConstructorAccess(String p0, List<Expr> p1) {
134        setID(p0);
135        setChild(p1, 0);
136      }
137      /**
138       * @declaredat ASTNode:18
139       */
140      public SuperConstructorAccess(beaver.Symbol p0, List<Expr> p1) {
141        setID(p0);
142        setChild(p1, 0);
143      }
144      /**
145       * @apilevel low-level
146       * @declaredat ASTNode:25
147       */
148      protected int numChildren() {
149        return 1;
150      }
151      /**
152       * @apilevel internal
153       * @declaredat ASTNode:31
154       */
155      public boolean mayHaveRewrite() {
156        return false;
157      }
158      /**
159       * @apilevel internal
160       * @declaredat ASTNode:37
161       */
162      public void flushAttrCache() {
163        super.flushAttrCache();
164        decls_reset();
165      }
166      /**
167       * @apilevel internal
168       * @declaredat ASTNode:44
169       */
170      public void flushCollectionCache() {
171        super.flushCollectionCache();
172      }
173      /**
174       * @apilevel internal
175       * @declaredat ASTNode:50
176       */
177      public void flushRewriteCache() {
178        super.flushRewriteCache();
179      }
180      /**
181       * @apilevel internal
182       * @declaredat ASTNode:56
183       */
184      public SuperConstructorAccess clone() throws CloneNotSupportedException {
185        SuperConstructorAccess node = (SuperConstructorAccess) super.clone();
186        return node;
187      }
188      /**
189       * @apilevel internal
190       * @declaredat ASTNode:63
191       */
192      public SuperConstructorAccess copy() {
193        try {
194          SuperConstructorAccess node = (SuperConstructorAccess) clone();
195          node.parent = null;
196          if (children != null) {
197            node.children = (ASTNode[]) children.clone();
198          }
199          return node;
200        } catch (CloneNotSupportedException e) {
201          throw new Error("Error: clone not supported for " + getClass().getName());
202        }
203      }
204      /**
205       * Create a deep copy of the AST subtree at this node.
206       * The copy is dangling, i.e. has no parent.
207       * @return dangling copy of the subtree at this node
208       * @apilevel low-level
209       * @deprecated Please use treeCopy or treeCopyNoTransform instead
210       * @declaredat ASTNode:82
211       */
212      @Deprecated
213      public SuperConstructorAccess fullCopy() {
214        return treeCopyNoTransform();
215      }
216      /**
217       * Create a deep copy of the AST subtree at this node.
218       * The copy is dangling, i.e. has no parent.
219       * @return dangling copy of the subtree at this node
220       * @apilevel low-level
221       * @declaredat ASTNode:92
222       */
223      public SuperConstructorAccess treeCopyNoTransform() {
224        SuperConstructorAccess tree = (SuperConstructorAccess) copy();
225        if (children != null) {
226          for (int i = 0; i < children.length; ++i) {
227            ASTNode child = (ASTNode) children[i];
228            if (child != null) {
229              child = child.treeCopyNoTransform();
230              tree.setChild(child, i);
231            }
232          }
233        }
234        return tree;
235      }
236      /**
237       * Create a deep copy of the AST subtree at this node.
238       * The subtree of this node is traversed to trigger rewrites before copy.
239       * The copy is dangling, i.e. has no parent.
240       * @return dangling copy of the subtree at this node
241       * @apilevel low-level
242       * @declaredat ASTNode:112
243       */
244      public SuperConstructorAccess treeCopy() {
245        doFullTraversal();
246        return treeCopyNoTransform();
247      }
248      /**
249       * @apilevel internal
250       * @declaredat ASTNode:119
251       */
252      protected boolean is$Equal(ASTNode node) {
253        return super.is$Equal(node) && (tokenString_ID == ((SuperConstructorAccess)node).tokenString_ID);    
254      }
255      /**
256       * Replaces the lexeme ID.
257       * @param value The new value for the lexeme ID.
258       * @apilevel high-level
259       */
260      public void setID(String value) {
261        tokenString_ID = value;
262      }
263      /**
264       * JastAdd-internal setter for lexeme ID using the Beaver parser.
265       * @param symbol Symbol containing the new value for the lexeme ID
266       * @apilevel internal
267       */
268      public void setID(beaver.Symbol symbol) {
269        if (symbol.value != null && !(symbol.value instanceof String))
270        throw new UnsupportedOperationException("setID is only valid for String lexemes");
271        tokenString_ID = (String)symbol.value;
272        IDstart = symbol.getStart();
273        IDend = symbol.getEnd();
274      }
275      /**
276       * Retrieves the value for the lexeme ID.
277       * @return The value for the lexeme ID.
278       * @apilevel high-level
279       */
280      @ASTNodeAnnotation.Token(name="ID")
281      public String getID() {
282        return tokenString_ID != null ? tokenString_ID : "";
283      }
284      /**
285       * Replaces the Arg list.
286       * @param list The new list node to be used as the Arg list.
287       * @apilevel high-level
288       */
289      public void setArgList(List<Expr> list) {
290        setChild(list, 0);
291      }
292      /**
293       * Retrieves the number of children in the Arg list.
294       * @return Number of children in the Arg list.
295       * @apilevel high-level
296       */
297      public int getNumArg() {
298        return getArgList().getNumChild();
299      }
300      /**
301       * Retrieves the number of children in the Arg list.
302       * Calling this method will not trigger rewrites.
303       * @return Number of children in the Arg list.
304       * @apilevel low-level
305       */
306      public int getNumArgNoTransform() {
307        return getArgListNoTransform().getNumChildNoTransform();
308      }
309      /**
310       * Retrieves the element at index {@code i} in the Arg list.
311       * @param i Index of the element to return.
312       * @return The element at position {@code i} in the Arg list.
313       * @apilevel high-level
314       */
315      public Expr getArg(int i) {
316        return (Expr) getArgList().getChild(i);
317      }
318      /**
319       * Check whether the Arg list has any children.
320       * @return {@code true} if it has at least one child, {@code false} otherwise.
321       * @apilevel high-level
322       */
323      public boolean hasArg() {
324        return getArgList().getNumChild() != 0;
325      }
326      /**
327       * Append an element to the Arg list.
328       * @param node The element to append to the Arg list.
329       * @apilevel high-level
330       */
331      public void addArg(Expr node) {
332        List<Expr> list = (parent == null) ? getArgListNoTransform() : getArgList();
333        list.addChild(node);
334      }
335      /**
336       * @apilevel low-level
337       */
338      public void addArgNoTransform(Expr node) {
339        List<Expr> list = getArgListNoTransform();
340        list.addChild(node);
341      }
342      /**
343       * Replaces the Arg list element at index {@code i} with the new node {@code node}.
344       * @param node The new node to replace the old list element.
345       * @param i The list index of the node to be replaced.
346       * @apilevel high-level
347       */
348      public void setArg(Expr node, int i) {
349        List<Expr> list = getArgList();
350        list.setChild(node, i);
351      }
352      /**
353       * Retrieves the Arg list.
354       * @return The node representing the Arg list.
355       * @apilevel high-level
356       */
357      @ASTNodeAnnotation.ListChild(name="Arg")
358      public List<Expr> getArgList() {
359        List<Expr> list = (List<Expr>) getChild(0);
360        return list;
361      }
362      /**
363       * Retrieves the Arg list.
364       * <p><em>This method does not invoke AST transformations.</em></p>
365       * @return The node representing the Arg list.
366       * @apilevel low-level
367       */
368      public List<Expr> getArgListNoTransform() {
369        return (List<Expr>) getChildNoTransform(0);
370      }
371      /**
372       * Retrieves the Arg list.
373       * @return The node representing the Arg list.
374       * @apilevel high-level
375       */
376      public List<Expr> getArgs() {
377        return getArgList();
378      }
379      /**
380       * Retrieves the Arg list.
381       * <p><em>This method does not invoke AST transformations.</em></p>
382       * @return The node representing the Arg list.
383       * @apilevel low-level
384       */
385      public List<Expr> getArgsNoTransform() {
386        return getArgListNoTransform();
387      }
388      /**
389       * @attribute syn
390       * @aspect DA
391       * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:259
392       */
393      @ASTNodeAnnotation.Attribute
394      public boolean isDAafter(Variable v) {
395        boolean isDAafter_Variable_value = isDAbefore(v);
396    
397        return isDAafter_Variable_value;
398      }
399      /**
400       * @attribute syn
401       * @aspect DU
402       * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:783
403       */
404      @ASTNodeAnnotation.Attribute
405      public boolean isDUafter(Variable v) {
406        boolean isDUafter_Variable_value = isDUbefore(v);
407    
408        return isDUafter_Variable_value;
409      }
410      /**
411       * @apilevel internal
412       */
413      protected boolean decls_computed = false;
414      /**
415       * @apilevel internal
416       */
417      protected SimpleSet decls_value;
418      /**
419       * @apilevel internal
420       */
421      private void decls_reset() {
422        decls_computed = false;
423        decls_value = null;
424      }
425      /**
426       * @attribute syn
427       * @aspect ConstructScope
428       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupConstructor.jrag:84
429       */
430      @ASTNodeAnnotation.Attribute
431      public SimpleSet decls() {
432        ASTNode$State state = state();
433        if (decls_computed) {
434          return decls_value;
435        }
436        boolean intermediate = state.INTERMEDIATE_VALUE;
437        state.INTERMEDIATE_VALUE = false;
438        int num = state.boundariesCrossed;
439        boolean isFinal = this.is$Final();
440        decls_value = decls_compute();
441        if (isFinal && num == state().boundariesCrossed) {
442          decls_computed = true;
443        } else {
444        }
445        state.INTERMEDIATE_VALUE |= intermediate;
446    
447        return decls_value;
448      }
449      /**
450       * @apilevel internal
451       */
452      private SimpleSet decls_compute() {
453          Collection c = hasPrevExpr() && !prevExpr().isTypeAccess()
454              ? hostType().lookupSuperConstructor()
455              : lookupSuperConstructor();
456          return chooseConstructor(c, getArgList());
457        }
458      /**
459       * @attribute syn
460       * @aspect Names
461       * @declaredat /home/jesper/git/extendj/java4/frontend/QualifiedNames.jrag:39
462       */
463      @ASTNodeAnnotation.Attribute
464      public String name() {
465        String name_value = "super";
466    
467        return name_value;
468      }
469      /**
470       * @attribute syn
471       * @aspect AccessTypes
472       * @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:71
473       */
474      @ASTNodeAnnotation.Attribute
475      public boolean isSuperConstructorAccess() {
476        boolean isSuperConstructorAccess_value = true;
477    
478        return isSuperConstructorAccess_value;
479      }
480      /**
481       * Defines the expected kind of name for the left hand side in a qualified
482       * expression.
483       * @attribute syn
484       * @aspect SyntacticClassification
485       * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:58
486       */
487      @ASTNodeAnnotation.Attribute
488      public NameType predNameType() {
489        NameType predNameType_value = NameType.EXPRESSION_NAME;
490    
491        return predNameType_value;
492      }
493      /**
494       * @attribute inh
495       * @aspect ConstructScope
496       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupConstructor.jrag:40
497       */
498      /**
499       * @attribute inh
500       * @aspect ConstructScope
501       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupConstructor.jrag:40
502       */
503      @ASTNodeAnnotation.Attribute
504      public Collection lookupSuperConstructor() {
505        Collection lookupSuperConstructor_value = getParent().Define_lookupSuperConstructor(this, null);
506    
507        return lookupSuperConstructor_value;
508      }
509      /**
510       * @attribute inh
511       * @aspect TypeCheck
512       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:584
513       */
514      /**
515       * @attribute inh
516       * @aspect TypeCheck
517       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:584
518       */
519      @ASTNodeAnnotation.Attribute
520      public TypeDecl enclosingInstance() {
521        TypeDecl enclosingInstance_value = getParent().Define_enclosingInstance(this, null);
522    
523        return enclosingInstance_value;
524      }
525      /**
526       * @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:115
527       * @apilevel internal
528       */
529      public boolean Define_hasPackage(ASTNode caller, ASTNode child, String packageName) {
530        if (caller == getArgListNoTransform()) {
531          // @declaredat /home/jesper/git/extendj/java4/frontend/LookupType.jrag:120
532          int childIndex = caller.getIndexOfChild(child);
533          return unqualifiedScope().hasPackage(packageName);
534        }
535        else {
536          return super.Define_hasPackage(caller, child, packageName);
537        }
538      }
539      protected boolean canDefine_hasPackage(ASTNode caller, ASTNode child, String packageName) {
540        return true;
541      }
542      /**
543       * @declaredat /home/jesper/git/extendj/java8/frontend/LookupVariable.jrag:30
544       * @apilevel internal
545       */
546      public SimpleSet Define_lookupVariable(ASTNode caller, ASTNode child, String name) {
547        if (caller == getArgListNoTransform()) {
548          // @declaredat /home/jesper/git/extendj/java4/frontend/LookupVariable.jrag:221
549          int childIndex = caller.getIndexOfChild(child);
550          return unqualifiedScope().lookupVariable(name);
551        }
552        else {
553          return super.Define_lookupVariable(caller, child, name);
554        }
555      }
556      protected boolean canDefine_lookupVariable(ASTNode caller, ASTNode child, String name) {
557        return true;
558      }
559      /**
560       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:165
561       * @apilevel internal
562       */
563      public boolean Define_inExplicitConstructorInvocation(ASTNode caller, ASTNode child) {
564        if (caller == getArgListNoTransform()) {
565          // @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:169
566          int childIndex = caller.getIndexOfChild(child);
567          return true;
568        }
569        else {
570          return super.Define_inExplicitConstructorInvocation(caller, child);
571        }
572      }
573      protected boolean canDefine_inExplicitConstructorInvocation(ASTNode caller, ASTNode child) {
574        return true;
575      }
576      /**
577       * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:173
578       * @apilevel internal
579       */
580      public TypeDecl Define_enclosingExplicitConstructorHostType(ASTNode caller, ASTNode child) {
581        if (caller == getArgListNoTransform()) {
582          // @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:178
583          int childIndex = caller.getIndexOfChild(child);
584          return hostType();
585        }
586        else {
587          return super.Define_enclosingExplicitConstructorHostType(caller, child);
588        }
589      }
590      protected boolean canDefine_enclosingExplicitConstructorHostType(ASTNode caller, ASTNode child) {
591        return true;
592      }
593      /**
594       * @apilevel internal
595       */
596      public ASTNode rewriteTo() {
597        return super.rewriteTo();
598      }
599    }