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 /** Represents a LocalVariableDeclarationStatement. 023 * The modifiers field of LocalVarDecl allow for future extensibility. 024 */ 025 026 public class LocalVarDecl extends GenericVarDecl 027 { 028 public VarInit init; 029 030 031 // The "locAssignOp" field is used only if "init" is non-null 032 public int locAssignOp; 033 034 035 private void postCheck() { 036 // Check invariants on modifiers... 037 // should be liberal... 038 } 039 040 public int getEndLoc() { 041 if (init == null) 042 return super.getEndLoc(); 043 044 return init.getEndLoc(); 045 } 046 047 048 // Generated boilerplate constructors: 049 050 /** 051 * Construct a raw LocalVarDecl whose class invariant(s) have not 052 * yet been established. It is the caller's job to 053 * initialize the returned node's fields so that any 054 * class invariants hold. 055 */ 056 //@ requires I_will_establish_invariants_afterwards; 057 protected LocalVarDecl() {} //@ nowarn Invariant,NonNullInit; 058 059 060 // Generated boilerplate methods: 061 062 public final int childCount() { 063 int sz = 0; 064 if (this.pmodifiers != null) sz += this.pmodifiers.size(); 065 return sz + 3; 066 } 067 068 public final Object childAt(int index) { 069 /*throws IndexOutOfBoundsException*/ 070 if (index < 0) 071 throw new IndexOutOfBoundsException("AST child index " + index); 072 int indexPre = index; 073 074 int sz; 075 076 sz = (this.pmodifiers == null ? 0 : this.pmodifiers.size()); 077 if (0 <= index && index < sz) 078 return this.pmodifiers.elementAt(index); 079 else index -= sz; 080 081 if (index == 0) return this.id; 082 else index--; 083 084 if (index == 0) return this.type; 085 else index--; 086 087 if (index == 0) return this.init; 088 else index--; 089 090 throw new IndexOutOfBoundsException("AST child index " + indexPre); 091 } //@ nowarn Exception; 092 093 public final String toString() { 094 return "[LocalVarDecl" 095 + " modifiers = " + this.modifiers 096 + " pmodifiers = " + this.pmodifiers 097 + " id = " + this.id 098 + " type = " + this.type 099 + " locId = " + this.locId 100 + " init = " + this.init 101 + " locAssignOp = " + this.locAssignOp 102 + "]"; 103 } 104 105 public final int getTag() { 106 return TagConstants.LOCALVARDECL; 107 } 108 109 public final void accept(Visitor v) { v.visitLocalVarDecl(this); } 110 111 public final Object accept(VisitorArgResult v, Object o) {return v.visitLocalVarDecl(this, o); } 112 113 public void check() { 114 super.check(); 115 if (this.pmodifiers != null) 116 for(int i = 0; i < this.pmodifiers.size(); i++) 117 this.pmodifiers.elementAt(i).check(); 118 if (this.id == null) throw new RuntimeException(); 119 this.type.check(); 120 if (this.init != null) 121 this.init.check(); 122 postCheck(); 123 } 124 125 //@ requires type.syntax; 126 //@ requires locId != javafe.util.Location.NULL; 127 //@ ensures \result != null; 128 public static LocalVarDecl make(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ Identifier id, /*@ non_null @*/ Type type, int locId, VarInit init, int locAssignOp) { 129 //@ set I_will_establish_invariants_afterwards = true; 130 LocalVarDecl result = new LocalVarDecl(); 131 result.modifiers = modifiers; 132 result.pmodifiers = pmodifiers; 133 result.id = id; 134 result.type = type; 135 result.locId = locId; 136 result.init = init; 137 result.locAssignOp = locAssignOp; 138 return result; 139 } 140 }