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    /** Represents both MethodDeclarations and ConstructorDeclarations.
026     */
027    
028    public abstract class RoutineDecl extends ASTNode implements TypeDeclElem
029    {
030      //@ invariant hasParent ==> parent != null;
031      public TypeDecl parent;
032    
033      public boolean binaryArgNames = false; // true if the ids of formal
034            // arguments are binary manufactured names instead of source code names
035    
036      public boolean implicit = false;
037      public TypeNameVec originalRaises = null;
038    
039      public int modifiers;
040    
041      public ModifierPragmaVec pmodifiers;
042    
043      public TypeModifierPragmaVec tmodifiers;
044    
045      public /*@ non_null @*/ FormalParaDeclVec args;
046    
047      public /*@ non_null @*/ TypeNameVec raises;
048    
049      public BlockStmt body;
050    
051      public int locOpenBrace;
052    
053      //@ invariant body != null ==> locOpenBrace != Location.NULL;
054      //@ invariant loc != javafe.util.Location.NULL;
055      public int loc;
056    
057      //@ invariant locId != javafe.util.Location.NULL;
058      public int locId;
059    
060    
061      // The "locThrowsKeyword" field should be used only if "raises" denotes
062      // a nonempty list, in which case "locThrowsKeyword" is not "Location.NULL"
063      public int locThrowsKeyword;
064    
065    
066      private void postCheck() {
067        // Check invariants on modifiers...
068    
069        for(int i = 0; i < args.size(); i++)
070          // Check invariants on modifiers...
071          /*skip*/;
072      }
073    
074      public TypeDecl getParent() { return parent; }
075      public void setParent(/*@non_null*/ TypeDecl p) { parent = p; }
076    
077      public int getModifiers() { return modifiers; }
078      public void setModifiers(int m) { modifiers = m; }
079      public ModifierPragmaVec getPModifiers() { return pmodifiers; }
080    
081      //@ public represents startLoc <- loc;
082      public /*@ pure @*/ int getStartLoc() { return loc; }
083    
084      abstract public Identifier id();
085    
086      public /*@ pure @*/ int getEndLoc() { 
087          if (body == null)
088              return super.getEndLoc();
089    
090          return body.getEndLoc();
091      }
092      private Type[] argtypes = null;
093      public Type[] argTypes() {
094            if (argtypes != null) return argtypes;
095            argtypes = new Type[args.size()];
096            for (int i=0; i<args.size(); ++i) {
097                    argtypes[i] = args.elementAt(i).type;
098            }
099            return argtypes;
100      }
101    
102    
103    // Generated boilerplate constructors:
104    
105      //@ ensures this.modifiers == modifiers;
106      //@ ensures this.pmodifiers == pmodifiers;
107      //@ ensures this.tmodifiers == tmodifiers;
108      //@ ensures this.args == args;
109      //@ ensures this.raises == raises;
110      //@ ensures this.body == body;
111      //@ ensures this.locOpenBrace == locOpenBrace;
112      //@ ensures this.loc == loc;
113      //@ ensures this.locId == locId;
114      //@ ensures this.locThrowsKeyword == locThrowsKeyword;
115      protected RoutineDecl(int modifiers, ModifierPragmaVec pmodifiers, TypeModifierPragmaVec tmodifiers, /*@ non_null @*/ FormalParaDeclVec args, /*@ non_null @*/ TypeNameVec raises, BlockStmt body, int locOpenBrace, int loc, int locId, int locThrowsKeyword) {
116         super();
117         this.modifiers = modifiers;
118         this.pmodifiers = pmodifiers;
119         this.tmodifiers = tmodifiers;
120         this.args = args;
121         this.raises = raises;
122         this.body = body;
123         this.locOpenBrace = locOpenBrace;
124         this.loc = loc;
125         this.locId = locId;
126         this.locThrowsKeyword = locThrowsKeyword;
127      }
128      public void check() {
129         super.check();
130         if (this.pmodifiers != null)
131            for(int i = 0; i < this.pmodifiers.size(); i++)
132               this.pmodifiers.elementAt(i).check();
133         if (this.tmodifiers != null)
134            for(int i = 0; i < this.tmodifiers.size(); i++)
135               this.tmodifiers.elementAt(i).check();
136         for(int i = 0; i < this.args.size(); i++)
137            this.args.elementAt(i).check();
138         for(int i = 0; i < this.raises.size(); i++)
139            this.raises.elementAt(i).check();
140         if (this.body != null)
141            this.body.check();
142         postCheck();
143      }
144    
145    }