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 NaryExpr extends GCExpr
032 {
033 public int op;
034
035 public /*@ non_null @*/ Identifier methodName;
036
037 public /*@ non_null @*/ ExprVec exprs;
038
039
040 //@ public represents startLoc <- sloc; //FIXME should not have to repeat this (because its in GCExpr)
041
042 public final int getTag() { return op; }
043
044 private void postCheck() {
045 boolean goodtag =
046 (
047 op == TagConstants.CLASSLITERALFUNC
048 || op == TagConstants.DTTFSA
049 || op == TagConstants.ELEMTYPE
050 || op == TagConstants.FRESH
051 || op == TagConstants.MAX
052 || op == TagConstants.NOWARN_OP
053 || op == TagConstants.TYPEOF
054 || op == TagConstants.WACK_BIGINT_MATH
055 || op == TagConstants.WACK_DURATION
056 || op == TagConstants.WACK_JAVA_MATH
057 || op == TagConstants.WACK_NOWARN
058 || op == TagConstants.WACK_SAFE_MATH
059 || op == TagConstants.WACK_WORKING_SPACE
060 || op == TagConstants.WARN
061 || op == TagConstants.WARN_OP
062 || (TagConstants.FIRSTFUNCTIONTAG <= op
063 && op <= TagConstants.LASTFUNCTIONTAG)
064 );
065 Assert.notFalse(goodtag);
066 }
067
068
069
070 // Generated boilerplate constructors:
071
072 //@ ensures this.sloc == sloc;
073 //@ ensures this.eloc == eloc;
074 //@ ensures this.op == op;
075 //@ ensures this.methodName == methodName;
076 //@ ensures this.exprs == exprs;
077 protected NaryExpr(int sloc, int eloc, int op, /*@ non_null @*/ Identifier methodName, /*@ non_null @*/ ExprVec exprs) {
078 super(sloc, eloc);
079 this.op = op;
080 this.methodName = methodName;
081 this.exprs = exprs;
082 }
083
084 // Generated boilerplate methods:
085
086 public final int childCount() {
087 int sz = 0;
088 if (this.exprs != null) sz += this.exprs.size();
089 return sz + 1;
090 }
091
092 public final Object childAt(int index) {
093 /*throws IndexOutOfBoundsException*/
094 if (index < 0)
095 throw new IndexOutOfBoundsException("AST child index " + index);
096 int indexPre = index;
097
098 int sz;
099
100 if (index == 0) return this.methodName;
101 else index--;
102
103 sz = (this.exprs == null ? 0 : this.exprs.size());
104 if (0 <= index && index < sz)
105 return this.exprs.elementAt(index);
106 else index -= sz;
107
108 throw new IndexOutOfBoundsException("AST child index " + indexPre);
109 } //@ nowarn Exception;
110
111 public final /*@non_null*/String toString() {
112 return "[NaryExpr"
113 + " sloc = " + this.sloc
114 + " eloc = " + this.eloc
115 + " op = " + this.op
116 + " methodName = " + this.methodName
117 + " exprs = " + this.exprs
118 + "]";
119 }
120
121 public final void accept(javafe.ast.Visitor v) {
122 if (v instanceof Visitor) ((Visitor)v).visitNaryExpr(this);
123 }
124
125 public final Object accept(javafe.ast.VisitorArgResult v, Object o) {
126 if (v instanceof VisitorArgResult) return ((VisitorArgResult)v).visitNaryExpr(this, o); else return null;
127 }
128
129 public void check() {
130 super.check();
131 this.methodName.check();
132 for(int i = 0; i < this.exprs.size(); i++)
133 this.exprs.elementAt(i).check();
134 postCheck();
135 }
136
137 //@ ensures \result != null;
138 public static NaryExpr make(int sloc, int eloc, int op, /*@ non_null @*/ Identifier methodName, /*@ non_null @*/ ExprVec exprs) {
139 NaryExpr result = new NaryExpr(sloc, eloc, op, methodName, exprs);
140 return result;
141 }
142 }