    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    /** Represents a field declaration. */
    023
    024    public class FieldDecl extends GenericVarDecl implements TypeDeclElem
    025    {
    026      //@ invariant hasParent ==> parent != null;
    027      public TypeDecl parent;
    028
    029      public VarInit init;
    030
    031
    032      // The "locAssignOp" field is used only if "init" is non-null
    033      public int locAssignOp;
    034
    035
    036      private void postCheck() {
    037        // Check invariants on modifiers...
    038        // should be liberal...
    039      }
    040
    041      public TypeDecl getParent() { return parent; }
    042      public void setParent(TypeDecl p) { parent = p; }
    043      public ModifierPragmaVec getPModifiers() { return null; }
    044
    045      public int getEndLoc() {
    046        if (init == null)
    047          return super.getEndLoc();
    048
    049        return init.getEndLoc();
    050      }
    051
    052
    053    // Generated boilerplate constructors:
    054
    055      /**
    056       * Construct a raw FieldDecl whose class invariant(s) have not
    057       * yet been established.  It is the caller's job to
    058       * initialize the returned node's fields so that any
    059       * class invariants hold.
    060       */
    061      //@ requires I_will_establish_invariants_afterwards;
    062      protected FieldDecl() {}    //@ nowarn Invariant,NonNullInit;
    063
    064
    065    // Generated boilerplate methods:
    066
    067      public final int childCount() {
    068         int sz = 0;
    069         if (this.pmodifiers != null) sz += this.pmodifiers.size();
    070         return sz + 3;
    071      }
    072
    073      public final Object childAt(int index) {
    074              /*throws IndexOutOfBoundsException*/
    075         if (index < 0)
    076            throw new IndexOutOfBoundsException("AST child index " + index);
    077         int indexPre = index;
    078
    079         int sz;
    080
    081         sz = (this.pmodifiers == null ? 0 : this.pmodifiers.size());
    082         if (0 <= index && index < sz)
    083            return this.pmodifiers.elementAt(index);
    084         else index -= sz;
    085
    086         if (index == 0) return this.id;
    087         else index--;
    088
    089         if (index == 0) return this.type;
    090         else index--;
    091
    092         if (index == 0) return this.init;
    093         else index--;
    094
    095         throw new IndexOutOfBoundsException("AST child index " + indexPre);
    096      }   //@ nowarn Exception;
    097
    098      public final String toString() {
    099         return "[FieldDecl"
    100            + " modifiers = " + this.modifiers
    101            + " pmodifiers = " + this.pmodifiers
    102            + " id = " + this.id
    103            + " type = " + this.type
    104            + " locId = " + this.locId
    105            + " init = " + this.init
    106            + " locAssignOp = " + this.locAssignOp
    107            + "]";
    108      }
    109
    110      public final int getTag() {
    111         return TagConstants.FIELDDECL;
    112      }
    113
    114      public final void accept(Visitor v) { v.visitFieldDecl(this); }
    115
    116      public final Object accept(VisitorArgResult v, Object o) {return v.visitFieldDecl(this, o); }
    117
    118      public void check() {
    119         super.check();
    120         if (this.pmodifiers != null)
    121            for(int i = 0; i < this.pmodifiers.size(); i++)
    122               this.pmodifiers.elementAt(i).check();
    123         if (this.id == null) throw new RuntimeException();
    124         this.type.check();
    125         if (this.init != null)
    126            this.init.check();
    127         postCheck();
    128      }
    129
    130      //@ requires type.syntax;
    131      //@ requires locId != javafe.util.Location.NULL;
    132      //@ ensures \result != null;
    133      public static FieldDecl make(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ Identifier id, /*@ non_null @*/ Type type, int locId, VarInit init, int locAssignOp) {
    134         //@ set I_will_establish_invariants_afterwards = true;
    135         FieldDecl result = new FieldDecl();
    136         result.modifiers = modifiers;
    137         result.pmodifiers = pmodifiers;
    138         result.id = id;
    139         result.type = type;
    140         result.locId = locId;
    141         result.init = init;
    142         result.locAssignOp = locAssignOp;
    143         return result;
    144      }
    145    }