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