001    /* Copyright 2000, 2001, Compaq Computer Corporation */
002    
003    /* IF THIS IS A JAVA FILE, DO NOT EDIT IT!  
004    
005       Most Java files in this directory which are part of the Javafe AST
006       are automatically generated using the astgen comment (see
007       ESCTools/Javafe/astgen) from the input file 'hierarchy.h'.  If you
008       wish to modify AST classes or introduce new ones, modify
009       'hierarchy.j.'
010     */
011    
012    package escjava.ast;
013    
014    import java.util.Hashtable;
015    import java.util.Set;
016    import java.util.ArrayList;
017    
018    import javafe.ast.*;
019    import javafe.util.Assert;
020    import javafe.util.Location;
021    import escjava.ParsedRoutineSpecs;
022    
023    // Convention: unless otherwise noted, integer fields named "loc" refer
024    // to the location of the first character of the syntactic unit
025    
026    //# TagBase javafe.tc.TagConstants.LAST_TAG + 1
027    //# VisitorRoot javafe.ast.Visitor
028    
029    
030    public class NaryExpr extends GCExpr
031    {
032      public int op;
033    
034      public /*@ non_null @*/ Identifier methodName;
035    
036      public /*@ non_null @*/ ExprVec exprs;
037    
038    
039      public final int getTag() { return op; }
040    
041      private void postCheck() {
042        boolean goodtag = 
043          (
044           op == TagConstants.CLASSLITERALFUNC
045           || op == TagConstants.DTTFSA
046           || op == TagConstants.ELEMTYPE
047           || op == TagConstants.FRESH
048           || op == TagConstants.MAX
049           || op == TagConstants.NOWARN_OP
050           || op == TagConstants.TYPEOF
051           || op == TagConstants.WACK_BIGINT_MATH
052           || op == TagConstants.WACK_DURATION
053           || op == TagConstants.WACK_JAVA_MATH
054           || op == TagConstants.WACK_NOWARN
055           || op == TagConstants.WACK_SAFE_MATH
056           || op == TagConstants.WACK_WORKING_SPACE
057           || op == TagConstants.WARN
058           || op == TagConstants.WARN_OP
059           || (TagConstants.FIRSTFUNCTIONTAG <= op 
060               && op <= TagConstants.LASTFUNCTIONTAG)
061           );
062        Assert.notFalse(goodtag);
063      }
064    
065    
066    
067    // Generated boilerplate constructors:
068    
069      /**
070       * Construct a raw NaryExpr whose class invariant(s) have not
071       * yet been established.  It is the caller's job to
072       * initialize the returned node's fields so that any
073       * class invariants hold.
074       */
075      //@ requires I_will_establish_invariants_afterwards;
076      protected NaryExpr() {}    //@ nowarn Invariant,NonNullInit;
077    
078    
079    // Generated boilerplate methods:
080    
081      public final int childCount() {
082         int sz = 0;
083         if (this.exprs != null) sz += this.exprs.size();
084         return sz + 1;
085      }
086    
087      public final Object childAt(int index) {
088              /*throws IndexOutOfBoundsException*/
089         if (index < 0)
090            throw new IndexOutOfBoundsException("AST child index " + index);
091         int indexPre = index;
092    
093         int sz;
094    
095         if (index == 0) return this.methodName;
096         else index--;
097    
098         sz = (this.exprs == null ? 0 : this.exprs.size());
099         if (0 <= index && index < sz)
100            return this.exprs.elementAt(index);
101         else index -= sz;
102    
103         throw new IndexOutOfBoundsException("AST child index " + indexPre);
104      }   //@ nowarn Exception;
105    
106      public final String toString() {
107         return "[NaryExpr"
108            + " sloc = " + this.sloc
109            + " eloc = " + this.eloc
110            + " op = " + this.op
111            + " methodName = " + this.methodName
112            + " exprs = " + this.exprs
113            + "]";
114      }
115    
116      public final void accept(javafe.ast.Visitor v) { 
117        if (v instanceof Visitor) ((Visitor)v).visitNaryExpr(this);
118      }
119    
120      public final Object accept(javafe.ast.VisitorArgResult v, Object o) { 
121        if (v instanceof VisitorArgResult) return ((VisitorArgResult)v).visitNaryExpr(this, o); else return null;
122      }
123    
124      public void check() {
125         super.check();
126         this.methodName.check();
127         for(int i = 0; i < this.exprs.size(); i++)
128            this.exprs.elementAt(i).check();
129         postCheck();
130      }
131    
132      //@ ensures \result != null;
133      public static NaryExpr make(int sloc, int eloc, int op, /*@ non_null @*/ Identifier methodName, /*@ non_null @*/ ExprVec exprs) {
134         //@ set I_will_establish_invariants_afterwards = true;
135         NaryExpr result = new NaryExpr();
136         result.sloc = sloc;
137         result.eloc = eloc;
138         result.op = op;
139         result.methodName = methodName;
140         result.exprs = exprs;
141         return result;
142      }
143    }