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 simple name that is bound to a local variable declaration.
024     * Is created only by the name resolution code, not by the parser.
025     */
026    
027    public class VariableAccess extends Expr
028    {
029      public /*@ non_null @*/ Identifier id;
030    
031      //@ invariant loc != javafe.util.Location.NULL;
032      public int loc;
033    
034    
035      //@ invariant decl.id==id;
036      public /*@ non_null @*/ GenericVarDecl decl;
037    
038      private void postCheck() {
039          Assert.notNull(decl);
040          Assert.notFalse(id == decl.id);
041          // Any other invariants here...???
042      }
043      public int getStartLoc() { return loc; }
044    
045      //@ requires decl.id == id;
046      //
047      //@ requires loc != javafe.util.Location.NULL;
048      //@ ensures \result != null;
049      public static VariableAccess make(/*@ non_null @*/ Identifier id, 
050                                        int loc,
051                                        /*@ non_null @*/ GenericVarDecl decl) {
052            //@ set I_will_establish_invariants_afterwards = true;
053            VariableAccess result = new VariableAccess();
054            result.id = id;
055            result.loc = loc;
056            result.decl = decl;
057            return result;
058      }
059    
060    
061    // Generated boilerplate constructors:
062    
063      /**
064       * Construct a raw VariableAccess whose class invariant(s) have not
065       * yet been established.  It is the caller's job to
066       * initialize the returned node's fields so that any
067       * class invariants hold.
068       */
069      //@ requires I_will_establish_invariants_afterwards;
070      protected VariableAccess() {}    //@ nowarn Invariant,NonNullInit;
071    
072    
073    // Generated boilerplate methods:
074    
075      public final int childCount() {
076         return 1;
077      }
078    
079      public final Object childAt(int index) {
080              /*throws IndexOutOfBoundsException*/
081         if (index < 0)
082            throw new IndexOutOfBoundsException("AST child index " + index);
083         int indexPre = index;
084    
085         int sz;
086    
087         if (index == 0) return this.id;
088         else index--;
089    
090         throw new IndexOutOfBoundsException("AST child index " + indexPre);
091      }   //@ nowarn Exception;
092    
093      public final String toString() {
094         return "[VariableAccess"
095            + " id = " + this.id
096            + " loc = " + this.loc
097            + "]";
098      }
099    
100      public final int getTag() {
101         return TagConstants.VARIABLEACCESS;
102      }
103    
104      public final void accept(Visitor v) { v.visitVariableAccess(this); }
105    
106      public final Object accept(VisitorArgResult v, Object o) {return v.visitVariableAccess(this, o); }
107    
108      public void check() {
109         super.check();
110         if (this.id == null) throw new RuntimeException();
111         postCheck();
112      }
113    
114    }