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