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 javafe.ast;
013    
014    import javafe.util.Assert;
015    import javafe.util.Location;
016    import javafe.util.ErrorSet;
017    
018    // Convention: unless otherwise noted, integer fields named "loc" refer
019    // to the location of the first character of the syntactic unit
020    
021    
022    /**
023     * Represents a PrimitiveType syntactic unit. 
024     * The tag should be one of the *TYPE constants defined in TagConstants
025     * (e.g., INTTYPE).
026     *
027     * @warning This AST node has associated locations only if syntax is
028     * true.
029     */
030    
031    public class PrimitiveType extends Type
032    {
033    
034      /*@ invariant (tag == TagConstants.BOOLEANTYPE || tag == TagConstants.INTTYPE
035           || tag == TagConstants.LONGTYPE || tag == TagConstants.CHARTYPE
036           || tag == TagConstants.FLOATTYPE || tag == TagConstants.DOUBLETYPE
037           || tag == TagConstants.VOIDTYPE || tag == TagConstants.NULLTYPE
038           || tag == TagConstants.BYTETYPE || tag == TagConstants.SHORTTYPE); */
039      public int tag;
040    
041    
042      //@ invariant syntax ==> loc != Location.NULL;
043      public int loc;
044    
045    
046      public int getStartLoc() { return loc; }
047    
048      public final int getTag() { return this.tag; }
049    
050      /**
051       * Normal maker that produces syntax, but requires a non-NULL location.
052       */
053      /*@ requires (tag == TagConstants.BOOLEANTYPE || tag == TagConstants.INTTYPE
054           || tag == TagConstants.LONGTYPE || tag == TagConstants.CHARTYPE
055           || tag == TagConstants.FLOATTYPE || tag == TagConstants.DOUBLETYPE
056           || tag == TagConstants.VOIDTYPE || tag == TagConstants.NULLTYPE
057           || tag == TagConstants.BYTETYPE || tag == TagConstants.SHORTTYPE); */
058      //@ requires loc != javafe.util.Location.NULL;
059      //@ ensures \result.syntax;
060      //@ ensures \result != null;
061      public static PrimitiveType make(TypeModifierPragmaVec tmodifiers,
062                                       int tag, int loc) {
063         //@ set I_will_establish_invariants_afterwards = true;
064         PrimitiveType result = new PrimitiveType();
065         result.tag = tag;
066         result.loc = loc;
067         result.tmodifiers = tmodifiers;
068         //@ set result.syntax = true;
069         return result;
070      }
071    
072      /**
073       * Special maker for producing non-syntax, which does not require a
074       * location.
075       */
076      /*@ requires (tag == TagConstants.BOOLEANTYPE || tag == TagConstants.INTTYPE
077           || tag == TagConstants.LONGTYPE || tag == TagConstants.CHARTYPE
078           || tag == TagConstants.FLOATTYPE || tag == TagConstants.DOUBLETYPE
079           || tag == TagConstants.VOIDTYPE || tag == TagConstants.NULLTYPE
080           || tag == TagConstants.BYTETYPE || tag == TagConstants.SHORTTYPE); */
081      //@ ensures !\result.syntax;
082      //@ ensures \result != null;
083      public static PrimitiveType makeNonSyntax(int tag) {
084         //@ set I_will_establish_invariants_afterwards = true;
085         PrimitiveType result = new PrimitiveType();
086         result.tag = tag;
087         result.loc = Location.NULL;
088         result.tmodifiers = null;
089         //@ set result.syntax = false;
090         return result;
091      }
092    
093      private void postCheck() {
094        boolean goodtag =
095          (tag == TagConstants.BOOLEANTYPE || tag == TagConstants.INTTYPE
096           || tag == TagConstants.LONGTYPE || tag == TagConstants.CHARTYPE
097           || tag == TagConstants.FLOATTYPE || tag == TagConstants.DOUBLETYPE
098           || tag == TagConstants.VOIDTYPE || tag == TagConstants.NULLTYPE
099           || tag == TagConstants.BYTETYPE || tag == TagConstants.SHORTTYPE);
100        Assert.notFalse(goodtag); 
101      }
102     
103     
104      // manual override for backwards compatibility
105      /*@ requires (tag == TagConstants.BOOLEANTYPE || tag == TagConstants.INTTYPE
106           || tag == TagConstants.LONGTYPE || tag == TagConstants.CHARTYPE
107           || tag == TagConstants.FLOATTYPE || tag == TagConstants.DOUBLETYPE
108           || tag == TagConstants.VOIDTYPE || tag == TagConstants.NULLTYPE
109           || tag == TagConstants.BYTETYPE || tag == TagConstants.SHORTTYPE); */
110      //@ requires loc != javafe.util.Location.NULL;
111      //@ ensures \result.syntax;
112      //@ ensures \result != null;
113      static public PrimitiveType make(int tag, int loc) {
114        return PrimitiveType.make(null, tag, loc);
115      }
116    
117    
118    // Generated boilerplate constructors:
119    
120      /**
121       * Construct a raw PrimitiveType whose class invariant(s) have not
122       * yet been established.  It is the caller's job to
123       * initialize the returned node's fields so that any
124       * class invariants hold.
125       */
126      //@ requires I_will_establish_invariants_afterwards;
127      protected PrimitiveType() {}    //@ nowarn Invariant,NonNullInit;
128    
129    
130    // Generated boilerplate methods:
131    
132      public final int childCount() {
133         int sz = 0;
134         if (this.tmodifiers != null) sz += this.tmodifiers.size();
135         return sz + 0;
136      }
137    
138      public final Object childAt(int index) {
139              /*throws IndexOutOfBoundsException*/
140         if (index < 0)
141            throw new IndexOutOfBoundsException("AST child index " + index);
142         int indexPre = index;
143    
144         int sz;
145    
146         sz = (this.tmodifiers == null ? 0 : this.tmodifiers.size());
147         if (0 <= index && index < sz)
148            return this.tmodifiers.elementAt(index);
149         else index -= sz;
150    
151         throw new IndexOutOfBoundsException("AST child index " + indexPre);
152      }   //@ nowarn Exception;
153    
154      public final String toString() {
155         return "[PrimitiveType"
156            + " tmodifiers = " + this.tmodifiers
157            + " tag = " + this.tag
158            + " loc = " + this.loc
159            + "]";
160      }
161    
162      public final void accept(Visitor v) { v.visitPrimitiveType(this); }
163    
164      public final Object accept(VisitorArgResult v, Object o) {return v.visitPrimitiveType(this, o); }
165    
166      public void check() {
167         super.check();
168         if (this.tmodifiers != null)
169            for(int i = 0; i < this.tmodifiers.size(); i++)
170               this.tmodifiers.elementAt(i).check();
171         postCheck();
172      }
173    
174    }