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