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    /* ---------------------------------------------------------------------- */
023    
024    /** Represents a TypeDeclaration.
025     *  Common fields of ClassDeclarations and InterfaceDeclarations are here.
026     */
027    
028    public abstract class TypeDecl extends ASTNode implements TypeDeclElem
029    {
030      /**
031       * If specOnly is true, then this is only a spec.  In particular,
032       * methods do not have non-empty bodies, no initializers are present
033       * for fields, and no static bodies are present.
034       */
035      public boolean specOnly = false;
036    
037      public int modifiers;
038    
039      public ModifierPragmaVec pmodifiers;
040    
041      public /*@ non_null @*/ Identifier id;
042    
043      public /*@ non_null @*/ TypeNameVec superInterfaces;
044    
045    
046      public TypeModifierPragmaVec tmodifiers;
047    
048    
049      //* "invariant" elems.<each element>.hasParent is true
050      public /*@ non_null @*/ TypeDeclElemVec elems;
051    
052    
053      //@ invariant loc != javafe.util.Location.NULL;
054      public int loc;
055    
056      //@ invariant locId != javafe.util.Location.NULL;
057      public int locId;
058    
059      //@ invariant locOpenBrace != javafe.util.Location.NULL;
060      public int locOpenBrace;
061    
062      //@ invariant locCloseBrace != javafe.util.Location.NULL;
063      public int locCloseBrace;
064    
065    
066      //@ invariant hasParent ==> parent != null;
067      public TypeDecl parent;
068    
069      public TypeDecl getParent() { return parent; }
070      public void setParent(TypeDecl p) { parent = p; }
071    
072      public int getModifiers() { return modifiers; }
073      public void setModifiers(int m) { modifiers = m; }
074      public ModifierPragmaVec getPModifiers() { return pmodifiers; }
075    
076      private void postCheck() {
077        // check invariants on modifiers...
078        for(int i = 0; i < elems.size(); i++) {
079          Assert.notFalse(elems.elementAt(i).getParent() == this);  //@ nowarn Pre;
080          for(int j = i+1; j < elems.size(); j++)
081            Assert.notFalse(elems.elementAt(i) != elems.elementAt(j));  //@ nowarn Pre;
082        }
083      }
084    
085        /**
086         * @return true iff this TypeDecl was created from a .class
087         * file.
088         *
089         * precondition: We have already been associated with a TypeSig.
090         */
091        public boolean isBinary() {
092            javafe.tc.TypeSig sig = javafe.tc.TypeSig.getSig(this);
093            CompilationUnit cu = sig.getCompilationUnit();
094    
095            return cu.isBinary();
096        }
097    
098      public int getStartLoc() { return loc; }
099      public int getEndLoc() { return locCloseBrace; }
100    
101    
102    // Generated boilerplate constructors:
103    
104      /**
105       * Construct a raw TypeDecl whose class invariant(s) have not
106       * yet been established.  It is the caller's job to
107       * initialize the returned node's fields so that any
108       * class invariants hold.
109       */
110      //@ requires I_will_establish_invariants_afterwards;
111      protected TypeDecl() {}    //@ nowarn Invariant,NonNullInit;
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         for(int i = 0; i < this.superInterfaces.size(); i++)
120            this.superInterfaces.elementAt(i).check();
121         if (this.tmodifiers != null)
122            for(int i = 0; i < this.tmodifiers.size(); i++)
123               this.tmodifiers.elementAt(i).check();
124         if (this.elems == null) throw new RuntimeException();
125         postCheck();
126      }
127    
128    }