    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     * We represent [C.]this.
    024     *
    025     * <p> classPrefix holds C if present, and null otherwise.
    026     *
    027     * @note classPrefix will hold a <em>**TypeSig**</em> instead of a
    028     * TypeName if we have been inferred.  (The inferred field specifies
    029     * whether or not we have been inferred.)
    030     */
    031
    032    public class ThisExpr extends Expr
    033    {
    034      public Type classPrefix;
    035
    036
    037      //@ invariant loc != javafe.util.Location.NULL;
    038      public int loc;
    039
    040
    041      //* Were we inferred by the disambiguation code?
    042      public boolean inferred = false;
    043
    044        public int getStartLoc() {
    045            if (classPrefix != null && classPrefix instanceof TypeName)
    046                return classPrefix.getStartLoc();
    047            return loc;
    048        }
    049
    050      public int getEndLoc() { return Location.inc(loc, 3); }
    051
    052
    053    // Generated boilerplate constructors:
    054
    055      /**
    056       * Construct a raw ThisExpr 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 ThisExpr() {}    //@ nowarn Invariant,NonNullInit;
    063
    064
    065    // Generated boilerplate methods:
    066
    067      public final int childCount() {
    068         return 1;
    069      }
    070
    071      public final Object childAt(int index) {
    072              /*throws IndexOutOfBoundsException*/
    073         if (index < 0)
    074            throw new IndexOutOfBoundsException("AST child index " + index);
    075         int indexPre = index;
    076
    077         int sz;
    078
    079         if (index == 0) return this.classPrefix;
    080         else index--;
    081
    082         throw new IndexOutOfBoundsException("AST child index " + indexPre);
    083      }   //@ nowarn Exception;
    084
    085      public final String toString() {
    086         return "[ThisExpr"
    087            + " classPrefix = " + this.classPrefix
    088            + " loc = " + this.loc
    089            + "]";
    090      }
    091
    092      public final int getTag() {
    093         return TagConstants.THISEXPR;
    094      }
    095
    096      public final void accept(Visitor v) { v.visitThisExpr(this); }
    097
    098      public final Object accept(VisitorArgResult v, Object o) {return v.visitThisExpr(this, o); }
    099
    100      public void check() {
    101         super.check();
    102         if (this.classPrefix != null)
    103            this.classPrefix.check();
    104      }
    105
    106      //@ requires loc != javafe.util.Location.NULL;
    107      //@ ensures \result != null;
    108      public static ThisExpr make(Type classPrefix, int loc) {
    109         //@ set I_will_establish_invariants_afterwards = true;
    110         ThisExpr result = new ThisExpr();
    111         result.classPrefix = classPrefix;
    112         result.loc = loc;
    113         return result;
    114      }
    115    }