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    /** Represents a ConstructorDeclaration.
024     *
025     *  The first Stmt in the body field should be a ConstructorInvocation. If
026     *  the source code does not contain a constructor invocation, it is
027     *  inserted by the parser.
028     */
029    
030    public class ConstructorDecl extends RoutineDecl
031    {
032    
033      public Identifier id() { return parent != null ? parent.id : Identifier.intern("<constructor>"); }
034    
035    
036    // Generated boilerplate constructors:
037    
038      //@ ensures this.modifiers == modifiers;
039      //@ ensures this.pmodifiers == pmodifiers;
040      //@ ensures this.tmodifiers == tmodifiers;
041      //@ ensures this.args == args;
042      //@ ensures this.raises == raises;
043      //@ ensures this.body == body;
044      //@ ensures this.locOpenBrace == locOpenBrace;
045      //@ ensures this.loc == loc;
046      //@ ensures this.locId == locId;
047      //@ ensures this.locThrowsKeyword == locThrowsKeyword;
048      protected ConstructorDecl(int modifiers, ModifierPragmaVec pmodifiers, TypeModifierPragmaVec tmodifiers, /*@ non_null @*/ FormalParaDeclVec args, /*@ non_null @*/ TypeNameVec raises, BlockStmt body, int locOpenBrace, int loc, int locId, int locThrowsKeyword) {
049         super(modifiers, pmodifiers, tmodifiers, args, raises, body, locOpenBrace, loc, locId, locThrowsKeyword);
050      }
051    
052    // Generated boilerplate methods:
053    
054      public final int childCount() {
055         int sz = 0;
056         if (this.pmodifiers != null) sz += this.pmodifiers.size();
057         if (this.tmodifiers != null) sz += this.tmodifiers.size();
058         if (this.args != null) sz += this.args.size();
059         if (this.raises != null) sz += this.raises.size();
060         return sz + 1;
061      }
062    
063      public final Object childAt(int index) {
064              /*throws IndexOutOfBoundsException*/
065         if (index < 0)
066            throw new IndexOutOfBoundsException("AST child index " + index);
067         int indexPre = index;
068    
069         int sz;
070    
071         sz = (this.pmodifiers == null ? 0 : this.pmodifiers.size());
072         if (0 <= index && index < sz)
073            return this.pmodifiers.elementAt(index);
074         else index -= sz;
075    
076         sz = (this.tmodifiers == null ? 0 : this.tmodifiers.size());
077         if (0 <= index && index < sz)
078            return this.tmodifiers.elementAt(index);
079         else index -= sz;
080    
081         sz = (this.args == null ? 0 : this.args.size());
082         if (0 <= index && index < sz)
083            return this.args.elementAt(index);
084         else index -= sz;
085    
086         sz = (this.raises == null ? 0 : this.raises.size());
087         if (0 <= index && index < sz)
088            return this.raises.elementAt(index);
089         else index -= sz;
090    
091         if (index == 0) return this.body;
092         else index--;
093    
094         throw new IndexOutOfBoundsException("AST child index " + indexPre);
095      }   //@ nowarn Exception;
096    
097      public final /*@non_null*/String toString() {
098         return "[ConstructorDecl"
099            + " modifiers = " + this.modifiers
100            + " pmodifiers = " + this.pmodifiers
101            + " tmodifiers = " + this.tmodifiers
102            + " args = " + this.args
103            + " raises = " + this.raises
104            + " body = " + this.body
105            + " locOpenBrace = " + this.locOpenBrace
106            + " loc = " + this.loc
107            + " locId = " + this.locId
108            + " locThrowsKeyword = " + this.locThrowsKeyword
109            + "]";
110      }
111    
112      public final int getTag() {
113         return TagConstants.CONSTRUCTORDECL;
114      }
115    
116      public final void accept(Visitor v) { v.visitConstructorDecl(this); }
117    
118      public final Object accept(VisitorArgResult v, Object o) {return v.visitConstructorDecl(this, o); }
119    
120      public void check() {
121         super.check();
122         if (this.pmodifiers != null)
123            for(int i = 0; i < this.pmodifiers.size(); i++)
124               this.pmodifiers.elementAt(i).check();
125         if (this.tmodifiers != null)
126            for(int i = 0; i < this.tmodifiers.size(); i++)
127               this.tmodifiers.elementAt(i).check();
128         for(int i = 0; i < this.args.size(); i++)
129            this.args.elementAt(i).check();
130         for(int i = 0; i < this.raises.size(); i++)
131            this.raises.elementAt(i).check();
132         if (this.body != null)
133            this.body.check();
134      }
135    
136      //@ requires loc != javafe.util.Location.NULL;
137      //@ requires locId != javafe.util.Location.NULL;
138      //@ requires body != null ==> locOpenBrace != Location.NULL;
139      //@ ensures \result != null;
140      public static ConstructorDecl 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) {
141         ConstructorDecl result = new ConstructorDecl(modifiers, pmodifiers, tmodifiers, args, raises, body, locOpenBrace, loc, locId, locThrowsKeyword);
142         return result;
143      }
144    }