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 BlockStmt extends GenericBlockStmt
023    {
024      private void postCheck() {
025        for(int i = 0; i < stmts.size(); i++) {
026          int t = stmts.elementAt(i).getTag();
027          Assert.notFalse(t != TagConstants.SWITCHLABEL);   //@ nowarn Pre;
028          Assert.notFalse(i == 0                            //@ nowarn Pre;
029            || t != TagConstants.CONSTRUCTORINVOCATION);
030        }
031      }
032      public int getStartLoc() { return locOpenBrace; }
033    
034    
035    // Generated boilerplate constructors:
036    
037      /**
038       * Construct a raw BlockStmt whose class invariant(s) have not
039       * yet been established.  It is the caller's job to
040       * initialize the returned node's fields so that any
041       * class invariants hold.
042       */
043      //@ requires I_will_establish_invariants_afterwards;
044      protected BlockStmt() {}    //@ nowarn Invariant,NonNullInit;
045    
046    
047    // Generated boilerplate methods:
048    
049      public final int childCount() {
050         int sz = 0;
051         if (this.stmts != null) sz += this.stmts.size();
052         return sz + 0;
053      }
054    
055      public final Object childAt(int index) {
056              /*throws IndexOutOfBoundsException*/
057         if (index < 0)
058            throw new IndexOutOfBoundsException("AST child index " + index);
059         int indexPre = index;
060    
061         int sz;
062    
063         sz = (this.stmts == null ? 0 : this.stmts.size());
064         if (0 <= index && index < sz)
065            return this.stmts.elementAt(index);
066         else index -= sz;
067    
068         throw new IndexOutOfBoundsException("AST child index " + indexPre);
069      }   //@ nowarn Exception;
070    
071      public final String toString() {
072         return "[BlockStmt"
073            + " stmts = " + this.stmts
074            + " locOpenBrace = " + this.locOpenBrace
075            + " locCloseBrace = " + this.locCloseBrace
076            + "]";
077      }
078    
079      public final int getTag() {
080         return TagConstants.BLOCKSTMT;
081      }
082    
083      public final void accept(Visitor v) { v.visitBlockStmt(this); }
084    
085      public final Object accept(VisitorArgResult v, Object o) {return v.visitBlockStmt(this, o); }
086    
087      public void check() {
088         super.check();
089         for(int i = 0; i < this.stmts.size(); i++)
090            this.stmts.elementAt(i).check();
091         postCheck();
092      }
093    
094      //@ requires locOpenBrace != javafe.util.Location.NULL;
095      //@ requires locCloseBrace != javafe.util.Location.NULL;
096      //@ ensures \result != null;
097      public static BlockStmt make(/*@ non_null @*/ StmtVec stmts, int locOpenBrace, int locCloseBrace) {
098         //@ set I_will_establish_invariants_afterwards = true;
099         BlockStmt result = new BlockStmt();
100         result.stmts = stmts;
101         result.locOpenBrace = locOpenBrace;
102         result.locCloseBrace = locCloseBrace;
103         return result;
104      }
105    }