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