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 an initializing block of code as a class member
024     *
025     *  We include modifiers for later extensibility to JDK 1.1, where both
026     *  static and dynamic initializer blocks are allowed.
027     */
028    
029    public class InitBlock extends ASTNode implements TypeDeclElem
030    {
031      //@ invariant hasParent ==> parent != null;
032      public TypeDecl parent;
033    
034      public int modifiers;
035    
036      public ModifierPragmaVec pmodifiers;
037    
038      public /*@ non_null @*/ BlockStmt block;
039    
040    
041      public TypeDecl getParent() { return parent; }
042      public void setParent(/*@non_null*/ TypeDecl p) { parent = p; }
043    
044      public int getModifiers() { return modifiers; }
045      public void setModifiers(int m) { modifiers = m; }
046      public ModifierPragmaVec getPModifiers() { return pmodifiers; }
047    
048      //@ public represents startLoc <- block.getStartLoc();
049      public /*@ pure @*/ int getStartLoc() { return block.getStartLoc(); }
050      public /*@ pure @*/ int getEndLoc() { return block.getEndLoc(); }
051    
052    
053    // Generated boilerplate constructors:
054    
055      //@ ensures this.modifiers == modifiers;
056      //@ ensures this.pmodifiers == pmodifiers;
057      //@ ensures this.block == block;
058      protected InitBlock(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ BlockStmt block) {
059         super();
060         this.modifiers = modifiers;
061         this.pmodifiers = pmodifiers;
062         this.block = block;
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 + 1;
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.block;
087         else index--;
088    
089         throw new IndexOutOfBoundsException("AST child index " + indexPre);
090      }   //@ nowarn Exception;
091    
092      public final /*@non_null*/String toString() {
093         return "[InitBlock"
094            + " modifiers = " + this.modifiers
095            + " pmodifiers = " + this.pmodifiers
096            + " block = " + this.block
097            + "]";
098      }
099    
100      public final int getTag() {
101         return TagConstants.INITBLOCK;
102      }
103    
104      public final void accept(Visitor v) { v.visitInitBlock(this); }
105    
106      public final Object accept(VisitorArgResult v, Object o) {return v.visitInitBlock(this, o); }
107    
108      public void check() {
109         super.check();
110         if (this.pmodifiers != null)
111            for(int i = 0; i < this.pmodifiers.size(); i++)
112               this.pmodifiers.elementAt(i).check();
113         this.block.check();
114      }
115    
116      //@ ensures \result != null;
117      public static InitBlock make(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ BlockStmt block) {
118         InitBlock result = new InitBlock(modifiers, pmodifiers, block);
119         return result;
120      }
121    }