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 escjava.ast;
014
015 import java.util.Hashtable;
016 import java.util.Set;
017 import java.util.ArrayList;
018
019 import javafe.ast.*;
020 import javafe.util.Assert;
021 import javafe.util.Location;
022 import escjava.ParsedRoutineSpecs;
023
024 // Convention: unless otherwise noted, integer fields named "loc" refer
025 // to the location of the first character of the syntactic unit
026
027 //# TagBase javafe.tc.TagConstants.LAST_TAG + 1
028 //# VisitorRoot javafe.ast.Visitor
029
030
031 public class GeneralizedQuantifiedExpr extends GCExpr
032 {
033 // Sum, Product, Max, Min
034 public int quantifier;
035
036 public /*@ non_null @*/ GenericVarDeclVec vars;
037
038 public /*@ non_null @*/ Expr expr;
039
040 public /*@ non_null @*/ Expr rangeExpr;
041
042 public ExprVec nopats;
043
044
045 //@ public represents startLoc <- sloc; //FIXME should not have to repeat this (because its in GCExpr)
046
047 public final int getTag() { return quantifier; }
048
049 private void postCheck() {
050 boolean goodtag =
051 (quantifier == TagConstants.MIN
052 || quantifier == TagConstants.PRODUCT
053 || quantifier == TagConstants.MAXQUANT
054 || quantifier == TagConstants.SUM);
055 Assert.notFalse(goodtag);
056 }
057
058
059 // Generated boilerplate constructors:
060
061 //@ ensures this.sloc == sloc;
062 //@ ensures this.eloc == eloc;
063 //@ ensures this.quantifier == quantifier;
064 //@ ensures this.vars == vars;
065 //@ ensures this.expr == expr;
066 //@ ensures this.rangeExpr == rangeExpr;
067 //@ ensures this.nopats == nopats;
068 protected GeneralizedQuantifiedExpr(int sloc, int eloc, int quantifier, /*@ non_null @*/ GenericVarDeclVec vars, /*@ non_null @*/ Expr expr, /*@ non_null @*/ Expr rangeExpr, ExprVec nopats) {
069 super(sloc, eloc);
070 this.quantifier = quantifier;
071 this.vars = vars;
072 this.expr = expr;
073 this.rangeExpr = rangeExpr;
074 this.nopats = nopats;
075 }
076
077 // Generated boilerplate methods:
078
079 public final int childCount() {
080 int sz = 0;
081 if (this.vars != null) sz += this.vars.size();
082 if (this.nopats != null) sz += this.nopats.size();
083 return sz + 2;
084 }
085
086 public final Object childAt(int index) {
087 /*throws IndexOutOfBoundsException*/
088 if (index < 0)
089 throw new IndexOutOfBoundsException("AST child index " + index);
090 int indexPre = index;
091
092 int sz;
093
094 sz = (this.vars == null ? 0 : this.vars.size());
095 if (0 <= index && index < sz)
096 return this.vars.elementAt(index);
097 else index -= sz;
098
099 if (index == 0) return this.expr;
100 else index--;
101
102 if (index == 0) return this.rangeExpr;
103 else index--;
104
105 sz = (this.nopats == null ? 0 : this.nopats.size());
106 if (0 <= index && index < sz)
107 return this.nopats.elementAt(index);
108 else index -= sz;
109
110 throw new IndexOutOfBoundsException("AST child index " + indexPre);
111 } //@ nowarn Exception;
112
113 public final /*@non_null*/String toString() {
114 return "[GeneralizedQuantifiedExpr"
115 + " sloc = " + this.sloc
116 + " eloc = " + this.eloc
117 + " quantifier = " + this.quantifier
118 + " vars = " + this.vars
119 + " expr = " + this.expr
120 + " rangeExpr = " + this.rangeExpr
121 + " nopats = " + this.nopats
122 + "]";
123 }
124
125 public final void accept(javafe.ast.Visitor v) {
126 if (v instanceof Visitor) ((Visitor)v).visitGeneralizedQuantifiedExpr(this);
127 }
128
129 public final Object accept(javafe.ast.VisitorArgResult v, Object o) {
130 if (v instanceof VisitorArgResult) return ((VisitorArgResult)v).visitGeneralizedQuantifiedExpr(this, o); else return null;
131 }
132
133 public void check() {
134 super.check();
135 for(int i = 0; i < this.vars.size(); i++)
136 this.vars.elementAt(i).check();
137 this.expr.check();
138 this.rangeExpr.check();
139 if (this.nopats != null)
140 for(int i = 0; i < this.nopats.size(); i++)
141 this.nopats.elementAt(i).check();
142 postCheck();
143 }
144
145 //@ ensures \result != null;
146 public static GeneralizedQuantifiedExpr make(int sloc, int eloc, int quantifier, /*@ non_null @*/ GenericVarDeclVec vars, /*@ non_null @*/ Expr expr, /*@ non_null @*/ Expr rangeExpr, ExprVec nopats) {
147 GeneralizedQuantifiedExpr result = new GeneralizedQuantifiedExpr(sloc, eloc, quantifier, vars, expr, rangeExpr, nopats);
148 return result;
149 }
150 }