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    public class ArrayRefExpr extends Expr
024    {
025      public /*@ non_null @*/ Expr array;
026    
027      public /*@ non_null @*/ Expr index;
028    
029      //@ invariant locOpenBracket != javafe.util.Location.NULL;
030      public int locOpenBracket;
031    
032      //@ invariant locCloseBracket != javafe.util.Location.NULL;
033      public int locCloseBracket;
034    
035    
036      //@ public represents startLoc <- array.getStartLoc();
037      public /*@ pure @*/ int getStartLoc() { return array.getStartLoc(); }
038      //@ also public normal_behavior
039      //@ ensures \result == locCloseBracket;
040      public /*@ pure @*/ int getEndLoc() { return locCloseBracket; }
041    
042    
043    // Generated boilerplate constructors:
044    
045      //@ ensures this.array == array;
046      //@ ensures this.index == index;
047      //@ ensures this.locOpenBracket == locOpenBracket;
048      //@ ensures this.locCloseBracket == locCloseBracket;
049      protected ArrayRefExpr(/*@ non_null @*/ Expr array, /*@ non_null @*/ Expr index, int locOpenBracket, int locCloseBracket) {
050         super();
051         this.array = array;
052         this.index = index;
053         this.locOpenBracket = locOpenBracket;
054         this.locCloseBracket = locCloseBracket;
055      }
056    
057    // Generated boilerplate methods:
058    
059      public final int childCount() {
060         return 2;
061      }
062    
063      public final Object childAt(int index) {
064              /*throws IndexOutOfBoundsException*/
065         if (index < 0)
066            throw new IndexOutOfBoundsException("AST child index " + index);
067         int indexPre = index;
068    
069         int sz;
070    
071         if (index == 0) return this.array;
072         else index--;
073    
074         if (index == 0) return this.index;
075         else index--;
076    
077         throw new IndexOutOfBoundsException("AST child index " + indexPre);
078      }   //@ nowarn Exception;
079    
080      public final /*@non_null*/String toString() {
081         return "[ArrayRefExpr"
082            + " array = " + this.array
083            + " index = " + this.index
084            + " locOpenBracket = " + this.locOpenBracket
085            + " locCloseBracket = " + this.locCloseBracket
086            + "]";
087      }
088    
089      public final int getTag() {
090         return TagConstants.ARRAYREFEXPR;
091      }
092    
093      public final void accept(Visitor v) { v.visitArrayRefExpr(this); }
094    
095      public final Object accept(VisitorArgResult v, Object o) {return v.visitArrayRefExpr(this, o); }
096    
097      public void check() {
098         super.check();
099         this.array.check();
100         this.index.check();
101      }
102    
103      //@ requires locOpenBracket != javafe.util.Location.NULL;
104      //@ requires locCloseBracket != javafe.util.Location.NULL;
105      //@ ensures \result != null;
106      public static ArrayRefExpr make(/*@ non_null @*/ Expr array, /*@ non_null @*/ Expr index, int locOpenBracket, int locCloseBracket) {
107         ArrayRefExpr result = new ArrayRefExpr(array, index, locOpenBracket, locCloseBracket);
108         return result;
109      }
110    }