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