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 DefPred extends ASTNode
032    {
033        public /*@ non_null @*/ Identifier predId;
034    
035        public /*@ non_null @*/ GenericVarDeclVec args;
036    
037        public /*@ non_null @*/ Expr body;
038    
039    
040        //@ public represents startLoc <- body.getStartLoc();
041        public /*@ pure @*/ int getStartLoc() { return body.getStartLoc(); }
042    
043    
044    // Generated boilerplate constructors:
045    
046        //@ ensures this.predId == predId;
047        //@ ensures this.args == args;
048        //@ ensures this.body == body;
049        protected DefPred(/*@ non_null @*/ Identifier predId, /*@ non_null @*/ GenericVarDeclVec args, /*@ non_null @*/ Expr body) {
050           this.predId = predId;
051           this.args = args;
052           this.body = body;
053        }
054    
055    // Generated boilerplate methods:
056    
057        public final int childCount() {
058           int sz = 0;
059           if (this.args != null) sz += this.args.size();
060           return sz + 2;
061        }
062    
063        public final Object childAt(int index) {
064                /*throws IndexOutOfBoundsException*/
065           if (index < 0)
066              throw new IndexOutOfBoundsException("AST child index " + index);
067           int indexPre = index;
068    
069           int sz;
070    
071           if (index == 0) return this.predId;
072           else index--;
073    
074           sz = (this.args == null ? 0 : this.args.size());
075           if (0 <= index && index < sz)
076              return this.args.elementAt(index);
077           else index -= sz;
078    
079           if (index == 0) return this.body;
080           else index--;
081    
082           throw new IndexOutOfBoundsException("AST child index " + indexPre);
083        }   //@ nowarn Exception;
084    
085        public final /*@non_null*/String toString() {
086           return "[DefPred"
087              + " predId = " + this.predId
088              + " args = " + this.args
089              + " body = " + this.body
090              + "]";
091        }
092    
093        public final int getTag() {
094           return TagConstants.DEFPRED;
095        }
096    
097        public final void accept(javafe.ast.Visitor v) { 
098            if (v instanceof Visitor) ((Visitor)v).visitDefPred(this);
099        }
100    
101        public final Object accept(javafe.ast.VisitorArgResult v, Object o) { 
102            if (v instanceof VisitorArgResult) return ((VisitorArgResult)v).visitDefPred(this, o); else return null;
103        }
104    
105        public void check() {
106           this.predId.check();
107           for(int i = 0; i < this.args.size(); i++)
108              this.args.elementAt(i).check();
109           this.body.check();
110        }
111    
112        //@ ensures \result != null;
113        public static DefPred make(/*@ non_null @*/ Identifier predId, /*@ non_null @*/ GenericVarDeclVec args, /*@ non_null @*/ Expr body) {
114           DefPred result = new DefPred(predId, args, body);
115           return result;
116        }
117    }