001 /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.3 */ 002 package AST; 003 004 import java.util.Collection; 005 import java.util.ArrayList; 006 import java.util.HashSet; 007 /** 008 * @ast node 009 * @declaredat /home/csz-naf/examples/PicoJavaMethods/spec/picojava-method.ast:5 010 * @production MethodUse : {@link Use} ::= <span class="component">Arg:{@link Exp}*</span>; 011 012 */ 013 public class MethodUse extends Use implements Cloneable { 014 /** 015 * @apilevel internal 016 */ 017 public MethodUse clone() throws CloneNotSupportedException { 018 MethodUse node = (MethodUse) super.clone(); 019 node.decl_visited = -1; 020 node.decl_computed = false; 021 node.decl_value = null; 022 node.isValue_visited = -1; 023 node.lookupMethod_String_List_visited = null; 024 node.in$Circle(false); 025 node.is$Final(false); 026 return node; 027 } 028 /** 029 * @apilevel internal 030 */ 031 public MethodUse copy() { 032 try { 033 MethodUse node = (MethodUse) clone(); 034 node.parent = null; 035 if(children != null) { 036 node.children = (ASTNode[]) children.clone(); 037 } 038 return node; 039 } catch (CloneNotSupportedException e) { 040 throw new Error("Error: clone not supported for " + getClass().getName()); 041 } 042 } 043 /** 044 * Create a deep copy of the AST subtree at this node. 045 * The copy is dangling, i.e. has no parent. 046 * @return dangling copy of the subtree at this node 047 * @apilevel low-level 048 */ 049 public MethodUse fullCopy() { 050 MethodUse tree = (MethodUse) copy(); 051 if (children != null) { 052 for (int i = 0; i < children.length; ++i) { 053 ASTNode child = (ASTNode) children[i]; 054 if(child != null) { 055 child = child.fullCopy(); 056 tree.setChild(child, i); 057 } 058 } 059 } 060 return tree; 061 } 062 /** 063 * @aspect ErrorCheck 064 * @declaredat /home/csz-naf/examples/PicoJavaMethods/spec/ErrorCheck.jrag:18 065 */ 066 public void collectErrors(Collection c) { 067 super.collectErrors(c); 068 if (decl() == null) { 069 StringBuffer buf = new StringBuffer(); 070 buf.append(getName() + "("); 071 for (int i = 0; i < getNumArg(); i++) { 072 buf.append(getArg(i).type()); 073 if (i < getNumArg() - 1) 074 buf.append(","); { 075 } 076 } 077 buf.append(")"); 078 error(c, "Unknown method " + buf); 079 } 080 } 081 /** 082 * Expressions 083 * @aspect PrettyPrint 084 * @declaredat /home/csz-naf/examples/PicoJavaMethods/spec/PrettyPrint.jadd:23 085 */ 086 public String toString() { 087 StringBuilder sb = new StringBuilder(); 088 sb.append(getName()).append("("); 089 boolean first = true; 090 for (Exp e: getArgs()) { 091 if (!first) { 092 sb.append(", "); 093 } 094 sb.append(e); 095 first = false; 096 } 097 sb.append(")"); 098 return sb.toString(); 099 } 100 /** 101 */ 102 public MethodUse() { 103 super(); 104 } 105 /** 106 * Initializes the child array to the correct size. 107 * Initializes List and Opt nta children. 108 * @apilevel internal 109 * @ast method 110 */ 111 public void init$Children() { 112 children = new ASTNode[1]; 113 setChild(new List(), 0); 114 } 115 /** 116 */ 117 public MethodUse(String p0, List<Exp> p1) { 118 setName(p0); 119 setChild(p1, 0); 120 } 121 /** 122 * @apilevel low-level 123 */ 124 protected int numChildren() { 125 return 1; 126 } 127 /** 128 * @apilevel internal 129 */ 130 public boolean mayHaveRewrite() { 131 return true; 132 } 133 /** 134 * @apilevel low-level 135 */ 136 public void flushCache() { 137 super.flushCache(); 138 decl_visited = -1; 139 decl_computed = false; 140 decl_value = null; 141 isValue_visited = -1; 142 lookupMethod_String_List_visited = null; 143 } 144 /** 145 * @apilevel internal 146 */ 147 public void flushCollectionCache() { 148 super.flushCollectionCache(); 149 } 150 /** 151 * Replaces the lexeme Name. 152 * @param value The new value for the lexeme Name. 153 * @apilevel high-level 154 */ 155 public void setName(String value) { 156 tokenString_Name = value; 157 } 158 /** 159 * Retrieves the value for the lexeme Name. 160 * @return The value for the lexeme Name. 161 * @apilevel high-level 162 */ 163 public String getName() { 164 return tokenString_Name != null ? tokenString_Name : ""; 165 } 166 /** 167 * Replaces the Arg list. 168 * @param list The new list node to be used as the Arg list. 169 * @apilevel high-level 170 */ 171 public void setArgList(List<Exp> list) { 172 setChild(list, 0); 173 } 174 /** 175 * Retrieves the number of children in the Arg list. 176 * @return Number of children in the Arg list. 177 * @apilevel high-level 178 */ 179 public int getNumArg() { 180 return getArgList().getNumChild(); 181 } 182 /** 183 * Retrieves the number of children in the Arg list. 184 * Calling this method will not trigger rewrites. 185 * @return Number of children in the Arg list. 186 * @apilevel low-level 187 */ 188 public int getNumArgNoTransform() { 189 return getArgListNoTransform().getNumChildNoTransform(); 190 } 191 /** 192 * Retrieves the element at index {@code i} in the Arg list. 193 * @param i Index of the element to return. 194 * @return The element at position {@code i} in the Arg list. 195 * @apilevel high-level 196 */ 197 public Exp getArg(int i) { 198 return (Exp) getArgList().getChild(i); 199 } 200 /** 201 * Check whether the Arg list has any children. 202 * @return {@code true} if it has at least one child, {@code false} otherwise. 203 * @apilevel high-level 204 */ 205 public boolean hasArg() { 206 return getArgList().getNumChild() != 0; 207 } 208 /** 209 * Append an element to the Arg list. 210 * @param node The element to append to the Arg list. 211 * @apilevel high-level 212 */ 213 public void addArg(Exp node) { 214 List<Exp> list = (parent == null || state == null) ? getArgListNoTransform() : getArgList(); 215 list.addChild(node); 216 } 217 /** 218 * @apilevel low-level 219 */ 220 public void addArgNoTransform(Exp node) { 221 List<Exp> list = getArgListNoTransform(); 222 list.addChild(node); 223 } 224 /** 225 * Replaces the Arg list element at index {@code i} with the new node {@code node}. 226 * @param node The new node to replace the old list element. 227 * @param i The list index of the node to be replaced. 228 * @apilevel high-level 229 */ 230 public void setArg(Exp node, int i) { 231 List<Exp> list = getArgList(); 232 list.setChild(node, i); 233 } 234 /** 235 * Retrieves the Arg list. 236 * @return The node representing the Arg list. 237 * @apilevel high-level 238 */ 239 public List<Exp> getArgList() { 240 List<Exp> list = (List<Exp>) getChild(0); 241 list.getNumChild(); 242 return list; 243 } 244 /** 245 * Retrieves the Arg list. 246 * <p><em>This method does not invoke AST transformations.</em></p> 247 * @return The node representing the Arg list. 248 * @apilevel low-level 249 */ 250 public List<Exp> getArgListNoTransform() { 251 return (List<Exp>) getChildNoTransform(0); 252 } 253 /** 254 * Retrieves the Arg list. 255 * @return The node representing the Arg list. 256 * @apilevel high-level 257 */ 258 public List<Exp> getArgs() { 259 return getArgList(); 260 } 261 /** 262 * Retrieves the Arg list. 263 * <p><em>This method does not invoke AST transformations.</em></p> 264 * @return The node representing the Arg list. 265 * @apilevel low-level 266 */ 267 public List<Exp> getArgsNoTransform() { 268 return getArgListNoTransform(); 269 } 270 /** 271 * @apilevel internal 272 */ 273 protected int decl_visited = -1; 274 /** 275 * @apilevel internal 276 */ 277 protected boolean decl_computed = false; 278 /** 279 * @apilevel internal 280 */ 281 protected Decl decl_value; 282 /** 283 * @attribute syn 284 * @aspect NameResolution 285 * @declaredat /home/csz-naf/examples/PicoJavaMethods/spec/NameResolution.jrag:4 286 */ 287 public Decl decl() { 288 if(decl_computed) { 289 return decl_value; 290 } 291 ASTNode$State state = state(); 292 if (decl_visited == state().boundariesCrossed) { 293 throw new RuntimeException("Circular definition of attr: decl in class: org.jastadd.ast.AST.SynDecl"); 294 } 295 decl_visited = state().boundariesCrossed; 296 int num = state.boundariesCrossed; 297 boolean isFinal = this.is$Final(); 298 decl_value = decl_compute(); 299 if(isFinal && num == state().boundariesCrossed) { 300 decl_computed = true; 301 } else { 302 } 303 304 decl_visited = -1; 305 return decl_value; 306 } 307 /** 308 * @apilevel internal 309 */ 310 private Decl decl_compute() { return lookupMethod(getName(), getArgList()); } 311 /** 312 * @apilevel internal 313 */ 314 protected int isValue_visited = -1; 315 /** 316 * @attribute syn 317 * @aspect TypeAnalysis 318 * @declaredat /home/csz-naf/examples/PicoJava/spec/TypeAnalysis.jrag:18 319 */ 320 public boolean isValue() { 321 ASTNode$State state = state(); 322 if (isValue_visited == state().boundariesCrossed) { 323 throw new RuntimeException("Circular definition of attr: isValue in class: org.jastadd.ast.AST.SynDecl"); 324 } 325 isValue_visited = state().boundariesCrossed; 326 try { return true; } 327 finally { 328 isValue_visited = -1; 329 } 330 } 331 /** 332 * @attribute inh 333 * @aspect NameResolution 334 * @declaredat /home/csz-naf/examples/PicoJavaMethods/spec/NameResolution.jrag:6 335 */ 336 public Decl lookupMethod(String name, List argList) { 337 java.util.List _parameters = new java.util.ArrayList(2); 338 _parameters.add(name); 339 _parameters.add(argList); 340 if(lookupMethod_String_List_visited == null) lookupMethod_String_List_visited = new java.util.HashMap(4); 341 ASTNode$State state = state(); 342 if (Integer.valueOf(state().boundariesCrossed).equals(lookupMethod_String_List_visited.get(_parameters))) { 343 throw new RuntimeException("Circular definition of attr: lookupMethod in class: org.jastadd.ast.AST.InhDecl"); 344 } 345 lookupMethod_String_List_visited.put(_parameters, Integer.valueOf(state().boundariesCrossed)); 346 Decl lookupMethod_String_List_value = getParent().Define_Decl_lookupMethod(this, null, name, argList); 347 348 lookupMethod_String_List_visited.remove(_parameters); 349 return lookupMethod_String_List_value; 350 } 351 /** 352 * @apilevel internal 353 */ 354 protected java.util.Map lookupMethod_String_List_visited; 355 /** 356 * @declaredat /home/csz-naf/examples/PicoJavaMethods/spec/NameResolution.jrag:27 357 * @apilevel internal 358 */ 359 public Decl Define_Decl_lookupMethod(ASTNode caller, ASTNode child, String name, List argList) { 360 if (caller == getArgListNoTransform()) { 361 int index = caller.getIndexOfChild(child); 362 return lookupMethod(name, argList); 363 } 364 else { 365 return getParent().Define_Decl_lookupMethod(this, caller, name, argList); 366 } 367 } 368 /** 369 * @apilevel internal 370 */ 371 public ASTNode rewriteTo() { return super.rewriteTo(); 372 }}