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 IfStmt extends Stmt
024 {
025 public /*@ non_null @*/ Expr expr;
026
027 public /*@ non_null @*/ Stmt thn;
028
029 public /*@ non_null @*/ Stmt els;
030
031 //@ invariant loc != javafe.util.Location.NULL;
032 public int loc;
033
034
035 private void postCheck() {
036 int t = thn.getTag();
037 Assert.notFalse(t != TagConstants.SWITCHLABEL //@ nowarn Pre;
038 && t != TagConstants.CONSTRUCTORINVOCATION
039 && t != TagConstants.VARDECLSTMT);
040 t = els.getTag();
041 Assert.notFalse(t != TagConstants.SWITCHLABEL //@ nowarn Pre;
042 && t != TagConstants.CONSTRUCTORINVOCATION
043 && t != TagConstants.VARDECLSTMT);
044 }
045
046 //@ public represents startLoc <- loc;
047 public /*@ pure @*/ int getStartLoc() { return loc; }
048 public /*@ pure @*/ int getEndLoc() {
049 int thenL = thn.getEndLoc();
050 int elseL = els.getEndLoc();
051 return Math.max(thenL, elseL);
052 }
053
054
055 // Generated boilerplate constructors:
056
057 //@ ensures this.expr == expr;
058 //@ ensures this.thn == thn;
059 //@ ensures this.els == els;
060 //@ ensures this.loc == loc;
061 protected IfStmt(/*@ non_null @*/ Expr expr, /*@ non_null @*/ Stmt thn, /*@ non_null @*/ Stmt els, int loc) {
062 super();
063 this.expr = expr;
064 this.thn = thn;
065 this.els = els;
066 this.loc = loc;
067 }
068
069 // Generated boilerplate methods:
070
071 public final int childCount() {
072 return 3;
073 }
074
075 public final Object childAt(int index) {
076 /*throws IndexOutOfBoundsException*/
077 if (index < 0)
078 throw new IndexOutOfBoundsException("AST child index " + index);
079 int indexPre = index;
080
081 int sz;
082
083 if (index == 0) return this.expr;
084 else index--;
085
086 if (index == 0) return this.thn;
087 else index--;
088
089 if (index == 0) return this.els;
090 else index--;
091
092 throw new IndexOutOfBoundsException("AST child index " + indexPre);
093 } //@ nowarn Exception;
094
095 public final /*@non_null*/String toString() {
096 return "[IfStmt"
097 + " expr = " + this.expr
098 + " thn = " + this.thn
099 + " els = " + this.els
100 + " loc = " + this.loc
101 + "]";
102 }
103
104 public final int getTag() {
105 return TagConstants.IFSTMT;
106 }
107
108 public final void accept(Visitor v) { v.visitIfStmt(this); }
109
110 public final Object accept(VisitorArgResult v, Object o) {return v.visitIfStmt(this, o); }
111
112 public void check() {
113 super.check();
114 this.expr.check();
115 this.thn.check();
116 this.els.check();
117 postCheck();
118 }
119
120 //@ requires loc != javafe.util.Location.NULL;
121 //@ ensures \result != null;
122 public static IfStmt make(/*@ non_null @*/ Expr expr, /*@ non_null @*/ Stmt thn, /*@ non_null @*/ Stmt els, int loc) {
123 IfStmt result = new IfStmt(expr, thn, els, loc);
124 return result;
125 }
126 }