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