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 a MethodInvocation. 
025     */
026    
027    public class MethodInvocation extends Expr
028    {
029      public /*@ non_null @*/ ObjectDesignator od;
030    
031      public /*@ non_null @*/ Identifier id;
032    
033      public TypeModifierPragmaVec tmodifiers;
034    
035      //@ invariant locId != javafe.util.Location.NULL;
036      public int locId;
037    
038      //@ invariant locOpenParen != javafe.util.Location.NULL;
039      public int locOpenParen;
040    
041      public /*@ non_null @*/ ExprVec args;
042    
043    
044      //@ invariant decl == null || decl.id==id;
045      public MethodDecl decl;
046    
047      private void postCheck() {
048        if (decl != null) {
049          Assert.notFalse(id == decl.id);
050          // Any other invariants here...???
051        }
052      }
053      //@ public represents startLoc <- (od.getStartLoc() == Location.NULL) ? locId : od.getStartLoc();
054      public /*@ pure @*/ int getStartLoc() {
055        int loc = od.getStartLoc();
056        if (loc != Location.NULL)
057          return loc;
058        else
059          return locId;
060      }
061      public /*@ pure @*/ int getEndLoc() { 
062        if (args.size()<1)
063          return locId;
064    
065        return args.elementAt(args.size()-1).getEndLoc();
066      }
067    
068      //@ requires locId != javafe.util.Location.NULL;
069      //@ requires locOpenParen != javafe.util.Location.NULL;
070      public static /*@non_null*/ MethodInvocation make(/*@ non_null @*/ ObjectDesignator od, 
071                                          /*@ non_null @*/ Identifier id, 
072                                          TypeModifierPragmaVec tmodifiers, 
073                                          int locId, 
074                                          int locOpenParen, 
075                                          /*@ non_null @*/ ExprVec args) {
076         MethodInvocation result = new MethodInvocation(
077                                       od,
078                                       id,
079                                       tmodifiers,
080                                       locId,
081                                       locOpenParen,
082                                       args);
083         result.decl = null;  // Easier than puting an ensures on constructor
084         return result;
085      }
086    
087    
088    // Generated boilerplate constructors:
089    
090      //@ ensures this.od == od;
091      //@ ensures this.id == id;
092      //@ ensures this.tmodifiers == tmodifiers;
093      //@ ensures this.locId == locId;
094      //@ ensures this.locOpenParen == locOpenParen;
095      //@ ensures this.args == args;
096      protected MethodInvocation(/*@ non_null @*/ ObjectDesignator od, /*@ non_null @*/ Identifier id, TypeModifierPragmaVec tmodifiers, int locId, int locOpenParen, /*@ non_null @*/ ExprVec args) {
097         super();
098         this.od = od;
099         this.id = id;
100         this.tmodifiers = tmodifiers;
101         this.locId = locId;
102         this.locOpenParen = locOpenParen;
103         this.args = args;
104      }
105    
106    // Generated boilerplate methods:
107    
108      public final int childCount() {
109         int sz = 0;
110         if (this.tmodifiers != null) sz += this.tmodifiers.size();
111         if (this.args != null) sz += this.args.size();
112         return sz + 2;
113      }
114    
115      public final Object childAt(int index) {
116              /*throws IndexOutOfBoundsException*/
117         if (index < 0)
118            throw new IndexOutOfBoundsException("AST child index " + index);
119         int indexPre = index;
120    
121         int sz;
122    
123         if (index == 0) return this.od;
124         else index--;
125    
126         if (index == 0) return this.id;
127         else index--;
128    
129         sz = (this.tmodifiers == null ? 0 : this.tmodifiers.size());
130         if (0 <= index && index < sz)
131            return this.tmodifiers.elementAt(index);
132         else index -= sz;
133    
134         sz = (this.args == null ? 0 : this.args.size());
135         if (0 <= index && index < sz)
136            return this.args.elementAt(index);
137         else index -= sz;
138    
139         throw new IndexOutOfBoundsException("AST child index " + indexPre);
140      }   //@ nowarn Exception;
141    
142      public final /*@non_null*/String toString() {
143         return "[MethodInvocation"
144            + " od = " + this.od
145            + " id = " + this.id
146            + " tmodifiers = " + this.tmodifiers
147            + " locId = " + this.locId
148            + " locOpenParen = " + this.locOpenParen
149            + " args = " + this.args
150            + "]";
151      }
152    
153      public final int getTag() {
154         return TagConstants.METHODINVOCATION;
155      }
156    
157      public final void accept(Visitor v) { v.visitMethodInvocation(this); }
158    
159      public final Object accept(VisitorArgResult v, Object o) {return v.visitMethodInvocation(this, o); }
160    
161      public void check() {
162         super.check();
163         this.od.check();
164         if (this.id == null) throw new RuntimeException();
165         if (this.tmodifiers != null)
166            for(int i = 0; i < this.tmodifiers.size(); i++)
167               this.tmodifiers.elementAt(i).check();
168         for(int i = 0; i < this.args.size(); i++)
169            this.args.elementAt(i).check();
170         postCheck();
171      }
172    
173    }