    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    /** Represents an initializing block of code as a class member
    023     *
    024     *  We include modifiers for later extensibility to JDK 1.1, where both
    025     *  static and dynamic initializer blocks are allowed.
    026     */
    027
    028    public class InitBlock extends ASTNode implements TypeDeclElem
    029    {
    030      //@ invariant hasParent ==> parent != null;
    031      public TypeDecl parent;
    032
    033      public int modifiers;
    034
    035      public ModifierPragmaVec pmodifiers;
    036
    037      public /*@ non_null @*/ BlockStmt block;
    038
    039
    040      public TypeDecl getParent() { return parent; }
    041      public void setParent(TypeDecl p) { parent = p; }
    042
    043      public int getModifiers() { return modifiers; }
    044      public void setModifiers(int m) { modifiers = m; }
    045      public ModifierPragmaVec getPModifiers() { return pmodifiers; }
    046      public int getStartLoc() { return block.getStartLoc(); }
    047      public int getEndLoc() { return block.getEndLoc(); }
    048
    049
    050    // Generated boilerplate constructors:
    051
    052      /**
    053       * Construct a raw InitBlock whose class invariant(s) have not
    054       * yet been established.  It is the caller's job to
    055       * initialize the returned node's fields so that any
    056       * class invariants hold.
    057       */
    058      //@ requires I_will_establish_invariants_afterwards;
    059      protected InitBlock() {}    //@ nowarn Invariant,NonNullInit;
    060
    061
    062    // Generated boilerplate methods:
    063
    064      public final int childCount() {
    065         int sz = 0;
    066         if (this.pmodifiers != null) sz += this.pmodifiers.size();
    067         return sz + 1;
    068      }
    069
    070      public final Object childAt(int index) {
    071              /*throws IndexOutOfBoundsException*/
    072         if (index < 0)
    073            throw new IndexOutOfBoundsException("AST child index " + index);
    074         int indexPre = index;
    075
    076         int sz;
    077
    078         sz = (this.pmodifiers == null ? 0 : this.pmodifiers.size());
    079         if (0 <= index && index < sz)
    080            return this.pmodifiers.elementAt(index);
    081         else index -= sz;
    082
    083         if (index == 0) return this.block;
    084         else index--;
    085
    086         throw new IndexOutOfBoundsException("AST child index " + indexPre);
    087      }   //@ nowarn Exception;
    088
    089      public final String toString() {
    090         return "[InitBlock"
    091            + " modifiers = " + this.modifiers
    092            + " pmodifiers = " + this.pmodifiers
    093            + " block = " + this.block
    094            + "]";
    095      }
    096
    097      public final int getTag() {
    098         return TagConstants.INITBLOCK;
    099      }
    100
    101      public final void accept(Visitor v) { v.visitInitBlock(this); }
    102
    103      public final Object accept(VisitorArgResult v, Object o) {return v.visitInitBlock(this, o); }
    104
    105      public void check() {
    106         super.check();
    107         if (this.pmodifiers != null)
    108            for(int i = 0; i < this.pmodifiers.size(); i++)
    109               this.pmodifiers.elementAt(i).check();
    110         this.block.check();
    111      }
    112
    113      //@ ensures \result != null;
    114      public static InitBlock make(int modifiers, ModifierPragmaVec pmodifiers, /*@ non_null @*/ BlockStmt block) {
    115         //@ set I_will_establish_invariants_afterwards = true;
    116         InitBlock result = new InitBlock();
    117         result.modifiers = modifiers;
    118         result.pmodifiers = pmodifiers;
    119         result.block = block;
    120         return result;
    121      }
    122    }