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 LocalVariableDeclarationStatement.
024     *  The modifiers field of LocalVarDecl allow for future extensibility.
025     */
026    
027    public class LocalVarDecl extends GenericVarDecl
028    {
029      public VarInit init;
030    
031      //@ invariant !isInternal();
032    
033      // The "locAssignOp" field is used only if "init" is non-null
034      public int locAssignOp;
035    
036    
037      private void postCheck() {
038        // Check invariants on modifiers...
039        // should be liberal...
040      }
041    
042      public /*@ pure @*/ int getEndLoc() {
043        if (init == null)
044          return super.getEndLoc();
045    
046        return init.getEndLoc();
047      }
048    
049    
050    // Generated boilerplate constructors:
051    
052      //@ ensures this.modifiers == modifiers;
053      //@ ensures this.pmodifiers == pmodifiers;
054      //@ ensures this.id == id;
055      //@ ensures this.type == type;
056      //@ ensures this.locId == locId;
057      //@ ensures this.init == init;
058      //@ ensures this.locAssignOp == locAssignOp;
059      protected LocalVarDecl(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ Identifier id, /*@ non_null @*/ Type type, int locId, VarInit init, int locAssignOp) {
060         super(modifiers, pmodifiers, id, type, locId);
061         this.init = init;
062         this.locAssignOp = locAssignOp;
063      }
064    
065    // Generated boilerplate methods:
066    
067      public final int childCount() {
068         int sz = 0;
069         if (this.pmodifiers != null) sz += this.pmodifiers.size();
070         return sz + 3;
071      }
072    
073      public final Object childAt(int index) {
074              /*throws IndexOutOfBoundsException*/
075         if (index < 0)
076            throw new IndexOutOfBoundsException("AST child index " + index);
077         int indexPre = index;
078    
079         int sz;
080    
081         sz = (this.pmodifiers == null ? 0 : this.pmodifiers.size());
082         if (0 <= index && index < sz)
083            return this.pmodifiers.elementAt(index);
084         else index -= sz;
085    
086         if (index == 0) return this.id;
087         else index--;
088    
089         if (index == 0) return this.type;
090         else index--;
091    
092         if (index == 0) return this.init;
093         else index--;
094    
095         throw new IndexOutOfBoundsException("AST child index " + indexPre);
096      }   //@ nowarn Exception;
097    
098      public final /*@non_null*/String toString() {
099         return "[LocalVarDecl"
100            + " modifiers = " + this.modifiers
101            + " pmodifiers = " + this.pmodifiers
102            + " id = " + this.id
103            + " type = " + this.type
104            + " locId = " + this.locId
105            + " init = " + this.init
106            + " locAssignOp = " + this.locAssignOp
107            + "]";
108      }
109    
110      public final int getTag() {
111         return TagConstants.LOCALVARDECL;
112      }
113    
114      public final void accept(Visitor v) { v.visitLocalVarDecl(this); }
115    
116      public final Object accept(VisitorArgResult v, Object o) {return v.visitLocalVarDecl(this, o); }
117    
118      public void check() {
119         super.check();
120         if (this.pmodifiers != null)
121            for(int i = 0; i < this.pmodifiers.size(); i++)
122               this.pmodifiers.elementAt(i).check();
123         if (this.id == null) throw new RuntimeException();
124         this.type.check();
125         if (this.init != null)
126            this.init.check();
127         postCheck();
128      }
129    
130      //@ ensures \result != null;
131      public static LocalVarDecl make(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ Identifier id, /*@ non_null @*/ Type type, int locId, VarInit init, int locAssignOp) {
132         LocalVarDecl result = new LocalVarDecl(modifiers, pmodifiers, id, type, locId, init, locAssignOp);
133         return result;
134      }
135    }