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 javafe.ast; 013 014 import javafe.util.Assert; 015 import javafe.util.Location; 016 import javafe.util.ErrorSet; 017 018 // Convention: unless otherwise noted, integer fields named "loc" refer 019 // to the location of the first character of the syntactic unit 020 021 022 /** 023 * Represents a MethodInvocation. 024 */ 025 026 public class MethodInvocation extends Expr 027 { 028 public /*@ non_null @*/ ObjectDesignator od; 029 030 public /*@ non_null @*/ Identifier id; 031 032 public TypeModifierPragmaVec tmodifiers; 033 034 //@ invariant locId != javafe.util.Location.NULL; 035 public int locId; 036 037 //@ invariant locOpenParen != javafe.util.Location.NULL; 038 public int locOpenParen; 039 040 public /*@ non_null @*/ ExprVec args; 041 042 043 //@ invariant decl == null || decl.id==id; 044 public MethodDecl decl; 045 046 private void postCheck() { 047 if (decl != null) { 048 Assert.notFalse(id == decl.id); 049 // Any other invariants here...??? 050 } 051 } 052 public int getStartLoc() { 053 int loc = od.getStartLoc(); 054 if (loc != Location.NULL) 055 return loc; 056 else 057 return locId; 058 } 059 public int getEndLoc() { 060 if (args.size()<1) 061 return locId; 062 063 return args.elementAt(args.size()-1).getEndLoc(); 064 } 065 066 //@ requires locId != javafe.util.Location.NULL; 067 //@ requires locOpenParen != javafe.util.Location.NULL; 068 //@ ensures \result != null; 069 public static MethodInvocation make(/*@ non_null @*/ ObjectDesignator od, 070 /*@ non_null @*/ Identifier id, 071 TypeModifierPragmaVec tmodifiers, 072 int locId, 073 int locOpenParen, 074 /*@ non_null @*/ ExprVec args) { 075 //@ set I_will_establish_invariants_afterwards = true; 076 MethodInvocation result = new MethodInvocation(); 077 result.od = od; 078 result.id = id; 079 result.locId = locId; 080 result.locOpenParen = locOpenParen; 081 result.args = args; 082 result.decl = null; // Easier than puting an ensures on constructor 083 result.tmodifiers = tmodifiers; 084 return result; 085 } 086 087 088 // Generated boilerplate constructors: 089 090 /** 091 * Construct a raw MethodInvocation whose class invariant(s) have not 092 * yet been established. It is the caller's job to 093 * initialize the returned node's fields so that any 094 * class invariants hold. 095 */ 096 //@ requires I_will_establish_invariants_afterwards; 097 protected MethodInvocation() {} //@ nowarn Invariant,NonNullInit; 098 099 100 // Generated boilerplate methods: 101 102 public final int childCount() { 103 int sz = 0; 104 if (this.tmodifiers != null) sz += this.tmodifiers.size(); 105 if (this.args != null) sz += this.args.size(); 106 return sz + 2; 107 } 108 109 public final Object childAt(int index) { 110 /*throws IndexOutOfBoundsException*/ 111 if (index < 0) 112 throw new IndexOutOfBoundsException("AST child index " + index); 113 int indexPre = index; 114 115 int sz; 116 117 if (index == 0) return this.od; 118 else index--; 119 120 if (index == 0) return this.id; 121 else index--; 122 123 sz = (this.tmodifiers == null ? 0 : this.tmodifiers.size()); 124 if (0 <= index && index < sz) 125 return this.tmodifiers.elementAt(index); 126 else index -= sz; 127 128 sz = (this.args == null ? 0 : this.args.size()); 129 if (0 <= index && index < sz) 130 return this.args.elementAt(index); 131 else index -= sz; 132 133 throw new IndexOutOfBoundsException("AST child index " + indexPre); 134 } //@ nowarn Exception; 135 136 public final String toString() { 137 return "[MethodInvocation" 138 + " od = " + this.od 139 + " id = " + this.id 140 + " tmodifiers = " + this.tmodifiers 141 + " locId = " + this.locId 142 + " locOpenParen = " + this.locOpenParen 143 + " args = " + this.args 144 + "]"; 145 } 146 147 public final int getTag() { 148 return TagConstants.METHODINVOCATION; 149 } 150 151 public final void accept(Visitor v) { v.visitMethodInvocation(this); } 152 153 public final Object accept(VisitorArgResult v, Object o) {return v.visitMethodInvocation(this, o); } 154 155 public void check() { 156 super.check(); 157 this.od.check(); 158 if (this.id == null) throw new RuntimeException(); 159 if (this.tmodifiers != null) 160 for(int i = 0; i < this.tmodifiers.size(); i++) 161 this.tmodifiers.elementAt(i).check(); 162 for(int i = 0; i < this.args.size(); i++) 163 this.args.elementAt(i).check(); 164 postCheck(); 165 } 166 167 }