001 /* Copyright 2000, 2001, Compaq Computer Corporation */ 002 003 /* IF THIS IS A JAVA FILE, DO NOT EDIT IT! 004 005 Most Java files in this directory which are part of the Javafe AST 006 are automatically generated using the astgen comment (see 007 ESCTools/Javafe/astgen) from the input file 'hierarchy.h'. If you 008 wish to modify AST classes or introduce new ones, modify 009 'hierarchy.j.' 010 */ 011 012 package escjava.ast; 013 014 import java.util.Hashtable; 015 import java.util.Set; 016 import java.util.ArrayList; 017 018 import javafe.ast.*; 019 import javafe.util.Assert; 020 import javafe.util.Location; 021 import escjava.ParsedRoutineSpecs; 022 023 // Convention: unless otherwise noted, integer fields named "loc" refer 024 // to the location of the first character of the syntactic unit 025 026 //# TagBase javafe.tc.TagConstants.LAST_TAG + 1 027 //# VisitorRoot javafe.ast.Visitor 028 029 030 public class DefPred extends ASTNode 031 { 032 public /*@ non_null @*/ Identifier predId; 033 034 public /*@ non_null @*/ GenericVarDeclVec args; 035 036 public /*@ non_null @*/ Expr body; 037 038 039 public int getStartLoc() { return body.getStartLoc(); } 040 041 042 // Generated boilerplate constructors: 043 044 /** 045 * Construct a raw DefPred whose class invariant(s) have not 046 * yet been established. It is the caller's job to 047 * initialize the returned node's fields so that any 048 * class invariants hold. 049 */ 050 //@ requires I_will_establish_invariants_afterwards; 051 protected DefPred() {} //@ nowarn Invariant,NonNullInit; 052 053 054 // Generated boilerplate methods: 055 056 public final int childCount() { 057 int sz = 0; 058 if (this.args != null) sz += this.args.size(); 059 return sz + 2; 060 } 061 062 public final Object childAt(int index) { 063 /*throws IndexOutOfBoundsException*/ 064 if (index < 0) 065 throw new IndexOutOfBoundsException("AST child index " + index); 066 int indexPre = index; 067 068 int sz; 069 070 if (index == 0) return this.predId; 071 else index--; 072 073 sz = (this.args == null ? 0 : this.args.size()); 074 if (0 <= index && index < sz) 075 return this.args.elementAt(index); 076 else index -= sz; 077 078 if (index == 0) return this.body; 079 else index--; 080 081 throw new IndexOutOfBoundsException("AST child index " + indexPre); 082 } //@ nowarn Exception; 083 084 public final String toString() { 085 return "[DefPred" 086 + " predId = " + this.predId 087 + " args = " + this.args 088 + " body = " + this.body 089 + "]"; 090 } 091 092 public final int getTag() { 093 return TagConstants.DEFPRED; 094 } 095 096 public final void accept(javafe.ast.Visitor v) { 097 if (v instanceof Visitor) ((Visitor)v).visitDefPred(this); 098 } 099 100 public final Object accept(javafe.ast.VisitorArgResult v, Object o) { 101 if (v instanceof VisitorArgResult) return ((VisitorArgResult)v).visitDefPred(this, o); else return null; 102 } 103 104 public void check() { 105 this.predId.check(); 106 for(int i = 0; i < this.args.size(); i++) 107 this.args.elementAt(i).check(); 108 this.body.check(); 109 } 110 111 //@ ensures \result != null; 112 public static DefPred make(/*@ non_null @*/ Identifier predId, /*@ non_null @*/ GenericVarDeclVec args, /*@ non_null @*/ Expr body) { 113 //@ set I_will_establish_invariants_afterwards = true; 114 DefPred result = new DefPred(); 115 result.predId = predId; 116 result.args = args; 117 result.body = body; 118 return result; 119 } 120 }