    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 various kinds of field access expressions.
    024     * The FieldDecl is filled in by the name resolution code.
    025     */
    026
    027    public class FieldAccess extends Expr
    028    {
    029      public /*@ non_null @*/ ObjectDesignator od;
    030
    031      public /*@ non_null @*/ Identifier id;
    032
    033      //@ invariant locId != javafe.util.Location.NULL;
    034      public int locId;
    035
    036
    037      //@ invariant decl == null || decl.id==id;
    038      public FieldDecl decl;
    039
    040      private void postCheck() {
    041        if (decl != null) {
    042          Assert.notFalse(id == decl.id);
    043          // Any other invariants here...???
    044        }
    045      }
    046      public int getStartLoc() {
    047        int locOd = od.getStartLoc();
    048        if (locOd == Location.NULL)
    049          return locId;
    050        else
    051          return locOd;
    052      }
    053      public int getEndLoc() { return locId; }
    054
    055      //@ requires locId != javafe.util.Location.NULL;
    056      //@ ensures \result != null;
    057      public static FieldAccess make(/*@ non_null @*/ ObjectDesignator od,
    058                                     /*@ non_null @*/ Identifier id,
    059                                     int locId) {
    060         //@ set I_will_establish_invariants_afterwards = true;
    061         FieldAccess result = new FieldAccess();
    062         result.od = od;
    063         result.id = id;
    064         result.locId = locId;
    065         result.decl = null;  // Easier than puting an ensures on constructor
    066         return result;
    067      }
    068
    069
    070    // Generated boilerplate constructors:
    071
    072      /**
    073       * Construct a raw FieldAccess whose class invariant(s) have not
    074       * yet been established.  It is the caller's job to
    075       * initialize the returned node's fields so that any
    076       * class invariants hold.
    077       */
    078      //@ requires I_will_establish_invariants_afterwards;
    079      protected FieldAccess() {}    //@ nowarn Invariant,NonNullInit;
    080
    081
    082    // Generated boilerplate methods:
    083
    084      public final int childCount() {
    085         return 2;
    086      }
    087
    088      public final Object childAt(int index) {
    089              /*throws IndexOutOfBoundsException*/
    090         if (index < 0)
    091            throw new IndexOutOfBoundsException("AST child index " + index);
    092         int indexPre = index;
    093
    094         int sz;
    095
    096         if (index == 0) return this.od;
    097         else index--;
    098
    099         if (index == 0) return this.id;
    100         else index--;
    101
    102         throw new IndexOutOfBoundsException("AST child index " + indexPre);
    103      }   //@ nowarn Exception;
    104
    105      public final String toString() {
    106         return "[FieldAccess"
    107            + " od = " + this.od
    108            + " id = " + this.id
    109            + " locId = " + this.locId
    110            + "]";
    111      }
    112
    113      public final int getTag() {
    114         return TagConstants.FIELDACCESS;
    115      }
    116
    117      public final void accept(Visitor v) { v.visitFieldAccess(this); }
    118
    119      public final Object accept(VisitorArgResult v, Object o) {return v.visitFieldAccess(this, o); }
    120
    121      public void check() {
    122         super.check();
    123         this.od.check();
    124         if (this.id == null) throw new RuntimeException();
    125         postCheck();
    126      }
    127
    128    }