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 /** Represents a field declaration. */
024
025 public class FieldDecl extends GenericVarDecl implements TypeDeclElem
026 {
027 //@ invariant hasParent ==> parent != null;
028 public TypeDecl parent;
029
030 public VarInit init;
031
032
033 // The "locAssignOp" field is used only if "init" is non-null
034 public int locAssignOp;
035
036
037 private void postCheck() {
038 // Check invariants on modifiers...
039 // should be liberal...
040 }
041
042 public TypeDecl getParent() { return parent; }
043 public void setParent(/*@non_null*/ TypeDecl p) { parent = p; }
044 public ModifierPragmaVec getPModifiers() { return null; }
045
046 public /*@ pure @*/ int getEndLoc() {
047 if (init == null)
048 return super.getEndLoc();
049
050 return init.getEndLoc();
051 }
052 protected FieldDecl(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ Identifier id, /*@ non_null @*/ Type type, VarInit init)
053 {
054 super(modifiers, pmodifiers, id, type);
055 this.init = init;
056 this.locAssignOp = Location.NULL;
057 }
058
059 //@ requires (type instanceof PrimitiveType);
060 public static FieldDecl makeInternal(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ Identifier id, /*@ non_null @*/ Type type, VarInit init) {
061 FieldDecl result = new FieldDecl(modifiers, pmodifiers, id, type, init);
062 return result;
063 }
064
065
066 // Generated boilerplate constructors:
067
068 //@ ensures this.modifiers == modifiers;
069 //@ ensures this.pmodifiers == pmodifiers;
070 //@ ensures this.id == id;
071 //@ ensures this.type == type;
072 //@ ensures this.locId == locId;
073 //@ ensures this.init == init;
074 //@ ensures this.locAssignOp == locAssignOp;
075 protected FieldDecl(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ Identifier id, /*@ non_null @*/ Type type, int locId, VarInit init, int locAssignOp) {
076 super(modifiers, pmodifiers, id, type, locId);
077 this.init = init;
078 this.locAssignOp = locAssignOp;
079 }
080
081 // Generated boilerplate methods:
082
083 public final int childCount() {
084 int sz = 0;
085 if (this.pmodifiers != null) sz += this.pmodifiers.size();
086 return sz + 3;
087 }
088
089 public final Object childAt(int index) {
090 /*throws IndexOutOfBoundsException*/
091 if (index < 0)
092 throw new IndexOutOfBoundsException("AST child index " + index);
093 int indexPre = index;
094
095 int sz;
096
097 sz = (this.pmodifiers == null ? 0 : this.pmodifiers.size());
098 if (0 <= index && index < sz)
099 return this.pmodifiers.elementAt(index);
100 else index -= sz;
101
102 if (index == 0) return this.id;
103 else index--;
104
105 if (index == 0) return this.type;
106 else index--;
107
108 if (index == 0) return this.init;
109 else index--;
110
111 throw new IndexOutOfBoundsException("AST child index " + indexPre);
112 } //@ nowarn Exception;
113
114 public final /*@non_null*/String toString() {
115 return "[FieldDecl"
116 + " modifiers = " + this.modifiers
117 + " pmodifiers = " + this.pmodifiers
118 + " id = " + this.id
119 + " type = " + this.type
120 + " locId = " + this.locId
121 + " init = " + this.init
122 + " locAssignOp = " + this.locAssignOp
123 + "]";
124 }
125
126 public final int getTag() {
127 return TagConstants.FIELDDECL;
128 }
129
130 public final void accept(Visitor v) { v.visitFieldDecl(this); }
131
132 public final Object accept(VisitorArgResult v, Object o) {return v.visitFieldDecl(this, o); }
133
134 public void check() {
135 super.check();
136 if (this.pmodifiers != null)
137 for(int i = 0; i < this.pmodifiers.size(); i++)
138 this.pmodifiers.elementAt(i).check();
139 if (this.id == null) throw new RuntimeException();
140 this.type.check();
141 if (this.init != null)
142 this.init.check();
143 postCheck();
144 }
145
146 //@ ensures \result != null;
147 public static FieldDecl make(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ Identifier id, /*@ non_null @*/ Type type, int locId, VarInit init, int locAssignOp) {
148 FieldDecl result = new FieldDecl(modifiers, pmodifiers, id, type, locId, init, locAssignOp);
149 return result;
150 }
151 }