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 /* ---------------------------------------------------------------------- */
024
025 /**
026 * Represents a TypeDeclaration.
027 * Common fields of ClassDeclarations and InterfaceDeclarations are here.
028 */
029
030 public abstract class TypeDecl extends ASTNode implements TypeDeclElem
031 {
032 /**
033 * If specOnly is true, then this is only a spec. In particular,
034 * methods do not have non-empty bodies, no initializers are present
035 * for fields, and no static bodies are present.
036 */
037 public boolean specOnly = false;
038
039 public int modifiers;
040
041 public ModifierPragmaVec pmodifiers;
042
043 public /*@ non_null @*/ Identifier id;
044
045 public /*@ non_null @*/ TypeNameVec superInterfaces;
046
047
048 public TypeModifierPragmaVec tmodifiers;
049
050
051 //* "invariant" elems.<each element>.hasParent is true
052 public /*@ non_null @*/ TypeDeclElemVec elems;
053
054
055 //@ invariant loc != javafe.util.Location.NULL;
056 public int loc;
057
058 //@ invariant locId != javafe.util.Location.NULL;
059 public int locId;
060
061 //@ invariant locOpenBrace != javafe.util.Location.NULL;
062 public int locOpenBrace;
063
064 //@ invariant locCloseBrace != javafe.util.Location.NULL;
065 public int locCloseBrace;
066
067
068 //@ invariant hasParent ==> parent != null;
069 public TypeDecl parent;
070
071 public TypeDecl getParent() { return parent; }
072 public void setParent(/*@non_null*/ TypeDecl p) { parent = p; }
073
074 public int getModifiers() { return modifiers; }
075 public void setModifiers(int m) { modifiers = m; }
076 public ModifierPragmaVec getPModifiers() { return pmodifiers; }
077
078 private void postCheck() {
079 // check invariants on modifiers...
080 for(int i = 0; i < elems.size(); i++) {
081 Assert.notFalse(elems.elementAt(i).getParent() == this); //@ nowarn Pre;
082 for(int j = i+1; j < elems.size(); j++)
083 Assert.notFalse(elems.elementAt(i) != elems.elementAt(j)); //@ nowarn Pre;
084 }
085 }
086
087 /**
088 * @return true iff this TypeDecl was created from a .class
089 * file.
090 *
091 * precondition: We have already been associated with a TypeSig.
092 */
093 public boolean isBinary() {
094 javafe.tc.TypeSig sig = javafe.tc.TypeSig.getSig(this);
095 CompilationUnit cu = sig.getCompilationUnit();
096
097 return cu.isBinary();
098 }
099
100 //@ public represents startLoc <- loc;
101
102 public /*@ pure @*/ int getStartLoc() { return loc; }
103 //@ also public normal_behavior
104 //@ ensures \result == locCloseBrace;
105 public /*@ pure @*/ int getEndLoc() { return locCloseBrace; }
106
107
108 // Generated boilerplate constructors:
109
110 //@ ensures this.modifiers == modifiers;
111 //@ ensures this.pmodifiers == pmodifiers;
112 //@ ensures this.id == id;
113 //@ ensures this.superInterfaces == superInterfaces;
114 //@ ensures this.tmodifiers == tmodifiers;
115 //@ ensures this.elems == elems;
116 //@ ensures this.loc == loc;
117 //@ ensures this.locId == locId;
118 //@ ensures this.locOpenBrace == locOpenBrace;
119 //@ ensures this.locCloseBrace == locCloseBrace;
120 protected TypeDecl(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) {
121 super();
122 this.modifiers = modifiers;
123 this.pmodifiers = pmodifiers;
124 this.id = id;
125 this.superInterfaces = superInterfaces;
126 this.tmodifiers = tmodifiers;
127 this.elems = elems;
128 this.loc = loc;
129 this.locId = locId;
130 this.locOpenBrace = locOpenBrace;
131 this.locCloseBrace = locCloseBrace;
132 }
133 public void check() {
134 super.check();
135 if (this.pmodifiers != null)
136 for(int i = 0; i < this.pmodifiers.size(); i++)
137 this.pmodifiers.elementAt(i).check();
138 if (this.id == null) throw new RuntimeException();
139 for(int i = 0; i < this.superInterfaces.size(); i++)
140 this.superInterfaces.elementAt(i).check();
141 if (this.tmodifiers != null)
142 for(int i = 0; i < this.tmodifiers.size(); i++)
143 this.tmodifiers.elementAt(i).check();
144 if (this.elems == null) throw new RuntimeException();
145 postCheck();
146 }
147
148 }