001    // -*- mode: java -*-
002    /* Copyright 2000, 2001, Compaq Computer Corporation */
003    
004    /* IF THIS IS A JAVA FILE, DO NOT EDIT IT!  
005    
006       Most Java files in this directory which are part of the Javafe AST
007       are automatically generated using the astgen comment (see
008       ESCTools/Javafe/astgen) from the input file 'hierarchy.h'.  If you
009       wish to modify AST classes or introduce new ones, modify
010       'hierarchy.j.'
011     */
012    
013    package javafe.ast;
014    
015    import javafe.util.Assert;
016    import javafe.util.Location;
017    import javafe.util.ErrorSet;
018    
019    // Convention: unless otherwise noted, integer fields named "loc" refer
020    // to the location of the first character of the syntactic unit
021    
022    
023    /**
024     * Represents a simple name that is bound to a local variable declaration.
025     * Is created only by the name resolution code, not by the parser.
026     */
027    
028    public class VariableAccess extends Expr
029    {
030      public /*@ non_null @*/ Identifier id;
031    
032      //@ invariant loc != javafe.util.Location.NULL;
033      public int loc;
034    
035    
036      //@ invariant decl.id==id;
037      public /*@ non_null @*/ GenericVarDecl decl;
038    
039      private void postCheck() {
040          Assert.notNull(decl);
041          Assert.notFalse(id == decl.id);
042          // Any other invariants here...???
043      }
044    
045      //@ public represents startLoc <- loc;
046      public /*@ pure @*/ int getStartLoc() { return loc; }
047    
048      //@ requires decl.id == id;
049      //
050      //@ requires loc != javafe.util.Location.NULL;
051      public static /*@non_null*/ VariableAccess make(/*@ non_null @*/ Identifier id, 
052                                        int loc,
053                                        /*@ non_null @*/ GenericVarDecl decl) {
054            VariableAccess result = new VariableAccess(id, loc);
055            result.decl=decl;
056            return result;
057      }
058    
059    
060    
061    // Generated boilerplate constructors:
062    
063      //@ ensures this.id == id;
064      //@ ensures this.loc == loc;
065      protected VariableAccess(/*@ non_null @*/ Identifier id, int loc) {
066         super();
067         this.id = id;
068         this.loc = loc;
069      }
070    
071    // Generated boilerplate methods:
072    
073      public final int childCount() {
074         return 1;
075      }
076    
077      public final Object childAt(int index) {
078              /*throws IndexOutOfBoundsException*/
079         if (index < 0)
080            throw new IndexOutOfBoundsException("AST child index " + index);
081         int indexPre = index;
082    
083         int sz;
084    
085         if (index == 0) return this.id;
086         else index--;
087    
088         throw new IndexOutOfBoundsException("AST child index " + indexPre);
089      }   //@ nowarn Exception;
090    
091      public final /*@non_null*/String toString() {
092         return "[VariableAccess"
093            + " id = " + this.id
094            + " loc = " + this.loc
095            + "]";
096      }
097    
098      public final int getTag() {
099         return TagConstants.VARIABLEACCESS;
100      }
101    
102      public final void accept(Visitor v) { v.visitVariableAccess(this); }
103    
104      public final Object accept(VisitorArgResult v, Object o) {return v.visitVariableAccess(this, o); }
105    
106      public void check() {
107         super.check();
108         if (this.id == null) throw new RuntimeException();
109         postCheck();
110      }
111    
112    }