001    // -*- mode: java -*-
002    /* Copyright 2000, 2001, Compaq Computer Corporation */
003    
004    /* IF THIS IS A JAVA FILE, DO NOT EDIT IT!  
005    
006       Most Java files in this directory which are part of the Javafe AST
007       are automatically generated using the astgen comment (see
008       ESCTools/Javafe/astgen) from the input file 'hierarchy.h'.  If you
009       wish to modify AST classes or introduce new ones, modify
010       'hierarchy.j.'
011     */
012    
013    package javafe.ast;
014    
015    import javafe.util.Assert;
016    import javafe.util.Location;
017    import javafe.util.ErrorSet;
018    
019    // Convention: unless otherwise noted, integer fields named "loc" refer
020    // to the location of the first character of the syntactic unit
021    
022    
023    /**
024     * Represents an ExplicitConstructorInvocation. 
025     * <p> Only occurs as the first Stmt in a ConstructorDecl. 
026     * <p> Name resolution sets the decl field to the callee.
027     */
028    
029    public class ConstructorInvocation extends Stmt
030    {
031      /**
032       * superCall is true implies call is "super(...)",
033       * superCall is false implies call is "this(...)".
034       */
035      public boolean superCall;
036    
037    
038      /**
039       * The enclosing instance is the object expression before a super
040       * call ( <enclosingInstance>.super(...) ).  This field may be null
041       * if there is no such expression.
042       *
043       * @note If the supertype in question is an inner class, then the
044       * type checker will infer a [<C>.]this expression if no expression
045       * is present and place it in this slot.  (See ThisExpr for how to
046       * distinguish inferred this expressions.)<p>
047       */
048      public Expr enclosingInstance;
049    
050    
051      //@ invariant enclosingInstance != null && superCall ==> locDot != Location.NULL;
052      public int locDot;
053    
054    
055      //@ invariant locKeyword != javafe.util.Location.NULL;
056      public int locKeyword;
057    
058      //@ invariant locOpenParen != javafe.util.Location.NULL;
059      public int locOpenParen;
060    
061    
062      public /*@ non_null @*/ ExprVec args;
063    
064    
065      public ConstructorDecl decl;
066    
067      private void postCheck() {
068        if (decl != null) {
069          // Any invariants here...???
070        }
071      }
072    
073      /*@ public represents startLoc <- (enclosingInstance == null) 
074        @           ? locKeyword : enclosingInstance.getStartLoc();
075        @*/
076      public /*@ pure @*/ int getStartLoc() {
077        if (enclosingInstance == null) return locKeyword;
078        else return enclosingInstance.getStartLoc();
079      }
080    
081      public /*@ pure @*/ int getEndLoc() { 
082        if (args.size()<1)
083          return super.getEndLoc();
084    
085        return args.elementAt(args.size()-1).getEndLoc();
086      }
087    
088      //@ requires superCall ==> locDot != Location.NULL;
089      //@ requires locKeyword != javafe.util.Location.NULL;
090      //@ requires locOpenParen != javafe.util.Location.NULL;
091      public static /*@non_null*/ ConstructorInvocation make(boolean superCall, 
092                                               /*@non_null*/ Expr enclosingInstance, 
093                                               int locDot, 
094                                               int locKeyword, 
095                                               int locOpenParen, 
096                                               /*@ non_null @*/ ExprVec args) {
097         ConstructorInvocation result = new ConstructorInvocation(
098                                              superCall,
099                                              enclosingInstance,
100                                              locDot,
101                                              locKeyword,
102                                              locOpenParen,
103                                              args);
104         return result;
105      }
106    
107    
108    // Generated boilerplate constructors:
109    
110      //@ ensures this.superCall == superCall;
111      //@ ensures this.enclosingInstance == enclosingInstance;
112      //@ ensures this.locDot == locDot;
113      //@ ensures this.locKeyword == locKeyword;
114      //@ ensures this.locOpenParen == locOpenParen;
115      //@ ensures this.args == args;
116      protected ConstructorInvocation(boolean superCall, Expr enclosingInstance, int locDot, int locKeyword, int locOpenParen, /*@ non_null @*/ ExprVec args) {
117         super();
118         this.superCall = superCall;
119         this.enclosingInstance = enclosingInstance;
120         this.locDot = locDot;
121         this.locKeyword = locKeyword;
122         this.locOpenParen = locOpenParen;
123         this.args = args;
124      }
125    
126    // Generated boilerplate methods:
127    
128      public final int childCount() {
129         int sz = 0;
130         if (this.args != null) sz += this.args.size();
131         return sz + 1;
132      }
133    
134      public final Object childAt(int index) {
135              /*throws IndexOutOfBoundsException*/
136         if (index < 0)
137            throw new IndexOutOfBoundsException("AST child index " + index);
138         int indexPre = index;
139    
140         int sz;
141    
142         if (index == 0) return this.enclosingInstance;
143         else index--;
144    
145         sz = (this.args == null ? 0 : this.args.size());
146         if (0 <= index && index < sz)
147            return this.args.elementAt(index);
148         else index -= sz;
149    
150         throw new IndexOutOfBoundsException("AST child index " + indexPre);
151      }   //@ nowarn Exception;
152    
153      public final /*@non_null*/String toString() {
154         return "[ConstructorInvocation"
155            + " superCall = " + this.superCall
156            + " enclosingInstance = " + this.enclosingInstance
157            + " locDot = " + this.locDot
158            + " locKeyword = " + this.locKeyword
159            + " locOpenParen = " + this.locOpenParen
160            + " args = " + this.args
161            + "]";
162      }
163    
164      public final int getTag() {
165         return TagConstants.CONSTRUCTORINVOCATION;
166      }
167    
168      public final void accept(Visitor v) { v.visitConstructorInvocation(this); }
169    
170      public final Object accept(VisitorArgResult v, Object o) {return v.visitConstructorInvocation(this, o); }
171    
172      public void check() {
173         super.check();
174         if (this.enclosingInstance != null)
175            this.enclosingInstance.check();
176         for(int i = 0; i < this.args.size(); i++)
177            this.args.elementAt(i).check();
178         postCheck();
179      }
180    
181    }