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 ClassDecl extends TypeDecl
024 {
025 public TypeName superClass;
026
027
028
029 /** Set the parent pointer of the <code>TypeDeclElem</code>s
030 inside the <code>this</code>. */
031 private void postMake() {
032 for(int i = 0; i < elems.size(); i++)
033 elems.elementAt(i).setParent(this);
034 }
035
036
037 // Generated boilerplate constructors:
038
039 //@ ensures this.modifiers == modifiers;
040 //@ ensures this.pmodifiers == pmodifiers;
041 //@ ensures this.id == id;
042 //@ ensures this.superInterfaces == superInterfaces;
043 //@ ensures this.tmodifiers == tmodifiers;
044 //@ ensures this.elems == elems;
045 //@ ensures this.loc == loc;
046 //@ ensures this.locId == locId;
047 //@ ensures this.locOpenBrace == locOpenBrace;
048 //@ ensures this.locCloseBrace == locCloseBrace;
049 //@ ensures this.superClass == superClass;
050 protected ClassDecl(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ Identifier id, /*@ non_null @*/ TypeNameVec superInterfaces, TypeModifierPragmaVec tmodifiers, /*@ non_null @*/ TypeDeclElemVec elems, int loc, int locId, int locOpenBrace, int locCloseBrace, TypeName superClass) {
051 super(modifiers, pmodifiers, id, superInterfaces, tmodifiers, elems, loc, locId, locOpenBrace, locCloseBrace);
052 this.superClass = superClass;
053 }
054
055 // Generated boilerplate methods:
056
057 public final int childCount() {
058 int sz = 0;
059 if (this.pmodifiers != null) sz += this.pmodifiers.size();
060 if (this.superInterfaces != null) sz += this.superInterfaces.size();
061 if (this.tmodifiers != null) sz += this.tmodifiers.size();
062 if (this.elems != null) sz += this.elems.size();
063 return sz + 2;
064 }
065
066 public final Object childAt(int index) {
067 /*throws IndexOutOfBoundsException*/
068 if (index < 0)
069 throw new IndexOutOfBoundsException("AST child index " + index);
070 int indexPre = index;
071
072 int sz;
073
074 sz = (this.pmodifiers == null ? 0 : this.pmodifiers.size());
075 if (0 <= index && index < sz)
076 return this.pmodifiers.elementAt(index);
077 else index -= sz;
078
079 if (index == 0) return this.id;
080 else index--;
081
082 sz = (this.superInterfaces == null ? 0 : this.superInterfaces.size());
083 if (0 <= index && index < sz)
084 return this.superInterfaces.elementAt(index);
085 else index -= sz;
086
087 sz = (this.tmodifiers == null ? 0 : this.tmodifiers.size());
088 if (0 <= index && index < sz)
089 return this.tmodifiers.elementAt(index);
090 else index -= sz;
091
092 sz = (this.elems == null ? 0 : this.elems.size());
093 if (0 <= index && index < sz)
094 return this.elems.elementAt(index);
095 else index -= sz;
096
097 if (index == 0) return this.superClass;
098 else index--;
099
100 throw new IndexOutOfBoundsException("AST child index " + indexPre);
101 } //@ nowarn Exception;
102
103 public final /*@non_null*/String toString() {
104 return "[ClassDecl"
105 + " modifiers = " + this.modifiers
106 + " pmodifiers = " + this.pmodifiers
107 + " id = " + this.id
108 + " superInterfaces = " + this.superInterfaces
109 + " tmodifiers = " + this.tmodifiers
110 + " elems = " + this.elems
111 + " loc = " + this.loc
112 + " locId = " + this.locId
113 + " locOpenBrace = " + this.locOpenBrace
114 + " locCloseBrace = " + this.locCloseBrace
115 + " superClass = " + this.superClass
116 + "]";
117 }
118
119 public final int getTag() {
120 return TagConstants.CLASSDECL;
121 }
122
123 public final void accept(Visitor v) { v.visitClassDecl(this); }
124
125 public final Object accept(VisitorArgResult v, Object o) {return v.visitClassDecl(this, o); }
126
127 public void check() {
128 super.check();
129 if (this.pmodifiers != null)
130 for(int i = 0; i < this.pmodifiers.size(); i++)
131 this.pmodifiers.elementAt(i).check();
132 if (this.id == null) throw new RuntimeException();
133 for(int i = 0; i < this.superInterfaces.size(); i++)
134 this.superInterfaces.elementAt(i).check();
135 if (this.tmodifiers != null)
136 for(int i = 0; i < this.tmodifiers.size(); i++)
137 this.tmodifiers.elementAt(i).check();
138 if (this.elems == null) throw new RuntimeException();
139 if (this.superClass != null)
140 this.superClass.check();
141 }
142
143 //@ requires loc != javafe.util.Location.NULL;
144 //@ requires locId != javafe.util.Location.NULL;
145 //@ requires locOpenBrace != javafe.util.Location.NULL;
146 //@ requires locCloseBrace != javafe.util.Location.NULL;
147 //@ ensures \result != null;
148 public static ClassDecl make(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ Identifier id, /*@ non_null @*/ TypeNameVec superInterfaces, TypeModifierPragmaVec tmodifiers, /*@ non_null @*/ TypeDeclElemVec elems, int loc, int locId, int locOpenBrace, int locCloseBrace, TypeName superClass) {
149 ClassDecl result = new ClassDecl(modifiers, pmodifiers, id, superInterfaces, tmodifiers, elems, loc, locId, locOpenBrace, locCloseBrace, superClass);
150 result.postMake();
151 return result;
152 }
153 }