001 /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13-12-g880e696 */ 002 package org.extendj.ast; 003 004 import java.util.HashSet; 005 import java.io.File; 006 import java.util.Set; 007 import java.util.Collections; 008 import java.util.Collection; 009 import java.util.ArrayList; 010 import beaver.*; 011 import java.util.*; 012 import java.io.ByteArrayOutputStream; 013 import java.io.PrintStream; 014 import java.lang.reflect.InvocationTargetException; 015 import java.lang.reflect.Method; 016 import org.jastadd.util.*; 017 import java.util.zip.*; 018 import java.io.*; 019 import org.jastadd.util.PrettyPrintable; 020 import org.jastadd.util.PrettyPrinter; 021 import java.io.FileNotFoundException; 022 import java.io.BufferedInputStream; 023 import java.io.DataInputStream; 024 /** 025 * @ast node 026 * @declaredat /home/jesper/git/extendj/java4/grammar/Java.ast:130 027 * @production ArrayCreationExpr : {@link PrimaryExpr} ::= <span class="component">TypeAccess:{@link Access}</span> <span class="component">[{@link ArrayInit}]</span>; 028 029 */ 030 public class ArrayCreationExpr extends PrimaryExpr implements Cloneable { 031 /** 032 * @aspect Java4PrettyPrint 033 * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:589 034 */ 035 public void prettyPrint(PrettyPrinter out) { 036 out.print("new "); 037 out.print(getTypeAccess()); 038 if (hasArrayInit()) { 039 out.print(" "); 040 out.print(getArrayInit()); 041 } 042 } 043 /** 044 * @aspect GenericsTypeCheck 045 * @declaredat /home/jesper/git/extendj/java5/frontend/Generics.jrag:439 046 */ 047 public void typeCheck() { 048 super.typeCheck(); 049 050 if (!type().isReifiable()) { 051 error("can not create array with non-reifiable element type"); 052 } 053 } 054 /** 055 * @declaredat ASTNode:1 056 */ 057 public ArrayCreationExpr() { 058 super(); 059 } 060 /** 061 * Initializes the child array to the correct size. 062 * Initializes List and Opt nta children. 063 * @apilevel internal 064 * @ast method 065 * @declaredat ASTNode:10 066 */ 067 public void init$Children() { 068 children = new ASTNode[2]; 069 setChild(new Opt(), 1); 070 } 071 /** 072 * @declaredat ASTNode:14 073 */ 074 public ArrayCreationExpr(Access p0, Opt<ArrayInit> p1) { 075 setChild(p0, 0); 076 setChild(p1, 1); 077 } 078 /** 079 * @apilevel low-level 080 * @declaredat ASTNode:21 081 */ 082 protected int numChildren() { 083 return 2; 084 } 085 /** 086 * @apilevel internal 087 * @declaredat ASTNode:27 088 */ 089 public boolean mayHaveRewrite() { 090 return false; 091 } 092 /** 093 * @apilevel internal 094 * @declaredat ASTNode:33 095 */ 096 public void flushAttrCache() { 097 super.flushAttrCache(); 098 type_reset(); 099 numArrays_reset(); 100 } 101 /** 102 * @apilevel internal 103 * @declaredat ASTNode:41 104 */ 105 public void flushCollectionCache() { 106 super.flushCollectionCache(); 107 } 108 /** 109 * @apilevel internal 110 * @declaredat ASTNode:47 111 */ 112 public void flushRewriteCache() { 113 super.flushRewriteCache(); 114 } 115 /** 116 * @apilevel internal 117 * @declaredat ASTNode:53 118 */ 119 public ArrayCreationExpr clone() throws CloneNotSupportedException { 120 ArrayCreationExpr node = (ArrayCreationExpr) super.clone(); 121 return node; 122 } 123 /** 124 * @apilevel internal 125 * @declaredat ASTNode:60 126 */ 127 public ArrayCreationExpr copy() { 128 try { 129 ArrayCreationExpr node = (ArrayCreationExpr) clone(); 130 node.parent = null; 131 if (children != null) { 132 node.children = (ASTNode[]) children.clone(); 133 } 134 return node; 135 } catch (CloneNotSupportedException e) { 136 throw new Error("Error: clone not supported for " + getClass().getName()); 137 } 138 } 139 /** 140 * Create a deep copy of the AST subtree at this node. 141 * The copy is dangling, i.e. has no parent. 142 * @return dangling copy of the subtree at this node 143 * @apilevel low-level 144 * @deprecated Please use treeCopy or treeCopyNoTransform instead 145 * @declaredat ASTNode:79 146 */ 147 @Deprecated 148 public ArrayCreationExpr fullCopy() { 149 return treeCopyNoTransform(); 150 } 151 /** 152 * Create a deep copy of the AST subtree at this node. 153 * The copy is dangling, i.e. has no parent. 154 * @return dangling copy of the subtree at this node 155 * @apilevel low-level 156 * @declaredat ASTNode:89 157 */ 158 public ArrayCreationExpr treeCopyNoTransform() { 159 ArrayCreationExpr tree = (ArrayCreationExpr) copy(); 160 if (children != null) { 161 for (int i = 0; i < children.length; ++i) { 162 ASTNode child = (ASTNode) children[i]; 163 if (child != null) { 164 child = child.treeCopyNoTransform(); 165 tree.setChild(child, i); 166 } 167 } 168 } 169 return tree; 170 } 171 /** 172 * Create a deep copy of the AST subtree at this node. 173 * The subtree of this node is traversed to trigger rewrites before copy. 174 * The copy is dangling, i.e. has no parent. 175 * @return dangling copy of the subtree at this node 176 * @apilevel low-level 177 * @declaredat ASTNode:109 178 */ 179 public ArrayCreationExpr treeCopy() { 180 doFullTraversal(); 181 return treeCopyNoTransform(); 182 } 183 /** 184 * @apilevel internal 185 * @declaredat ASTNode:116 186 */ 187 protected boolean is$Equal(ASTNode node) { 188 return super.is$Equal(node); 189 } 190 /** 191 * Replaces the TypeAccess child. 192 * @param node The new node to replace the TypeAccess child. 193 * @apilevel high-level 194 */ 195 public void setTypeAccess(Access node) { 196 setChild(node, 0); 197 } 198 /** 199 * Retrieves the TypeAccess child. 200 * @return The current node used as the TypeAccess child. 201 * @apilevel high-level 202 */ 203 @ASTNodeAnnotation.Child(name="TypeAccess") 204 public Access getTypeAccess() { 205 return (Access) getChild(0); 206 } 207 /** 208 * Retrieves the TypeAccess child. 209 * <p><em>This method does not invoke AST transformations.</em></p> 210 * @return The current node used as the TypeAccess child. 211 * @apilevel low-level 212 */ 213 public Access getTypeAccessNoTransform() { 214 return (Access) getChildNoTransform(0); 215 } 216 /** 217 * Replaces the optional node for the ArrayInit child. This is the <code>Opt</code> 218 * node containing the child ArrayInit, not the actual child! 219 * @param opt The new node to be used as the optional node for the ArrayInit child. 220 * @apilevel low-level 221 */ 222 public void setArrayInitOpt(Opt<ArrayInit> opt) { 223 setChild(opt, 1); 224 } 225 /** 226 * Replaces the (optional) ArrayInit child. 227 * @param node The new node to be used as the ArrayInit child. 228 * @apilevel high-level 229 */ 230 public void setArrayInit(ArrayInit node) { 231 getArrayInitOpt().setChild(node, 0); 232 } 233 /** 234 * Check whether the optional ArrayInit child exists. 235 * @return {@code true} if the optional ArrayInit child exists, {@code false} if it does not. 236 * @apilevel high-level 237 */ 238 public boolean hasArrayInit() { 239 return getArrayInitOpt().getNumChild() != 0; 240 } 241 /** 242 * Retrieves the (optional) ArrayInit child. 243 * @return The ArrayInit child, if it exists. Returns {@code null} otherwise. 244 * @apilevel low-level 245 */ 246 public ArrayInit getArrayInit() { 247 return (ArrayInit) getArrayInitOpt().getChild(0); 248 } 249 /** 250 * Retrieves the optional node for the ArrayInit child. This is the <code>Opt</code> node containing the child ArrayInit, not the actual child! 251 * @return The optional node for child the ArrayInit child. 252 * @apilevel low-level 253 */ 254 @ASTNodeAnnotation.OptChild(name="ArrayInit") 255 public Opt<ArrayInit> getArrayInitOpt() { 256 return (Opt<ArrayInit>) getChild(1); 257 } 258 /** 259 * Retrieves the optional node for child ArrayInit. This is the <code>Opt</code> node containing the child ArrayInit, not the actual child! 260 * <p><em>This method does not invoke AST transformations.</em></p> 261 * @return The optional node for child ArrayInit. 262 * @apilevel low-level 263 */ 264 public Opt<ArrayInit> getArrayInitOptNoTransform() { 265 return (Opt<ArrayInit>) getChildNoTransform(1); 266 } 267 /** 268 * @aspect AutoBoxingCodegen 269 * @declaredat /home/jesper/git/extendj/java5/backend/AutoBoxingCodegen.jrag:288 270 */ 271 public void createBCode(CodeGeneration gen) { 272 if (hasArrayInit()){ 273 getArrayInit().createBCode(gen); 274 } else { 275 getTypeAccess().createBCode(gen); // push array sizes 276 if (type().componentType().isPrimitive() && !type().componentType().isReferenceType()) { 277 gen.emit(Bytecode.NEWARRAY).add(type().componentType().arrayPrimitiveTypeDescriptor()); 278 } else { 279 if (numArrays() == 1) { 280 String n = type().componentType().arrayTypeDescriptor(); 281 int index = gen.constantPool().addClass(n); 282 gen.emit(Bytecode.ANEWARRAY).add2(index); 283 } else { 284 String n = type().arrayTypeDescriptor(); 285 int index = gen.constantPool().addClass(n); 286 gen.emit(Bytecode.MULTIANEWARRAY, 1 - numArrays()).add2(index).add(numArrays()); 287 } 288 } 289 } 290 } 291 /** 292 * @attribute syn 293 * @aspect DA 294 * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:474 295 */ 296 @ASTNodeAnnotation.Attribute 297 public boolean isDAafterCreation(Variable v) { 298 boolean isDAafterCreation_Variable_value = getTypeAccess().isDAafter(v); 299 300 return isDAafterCreation_Variable_value; 301 } 302 /** 303 * @attribute syn 304 * @aspect DA 305 * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:259 306 */ 307 @ASTNodeAnnotation.Attribute 308 public boolean isDAafter(Variable v) { 309 boolean isDAafter_Variable_value = hasArrayInit() ? getArrayInit().isDAafter(v) : isDAafterCreation(v); 310 311 return isDAafter_Variable_value; 312 } 313 /** 314 * @attribute syn 315 * @aspect DU 316 * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:975 317 */ 318 @ASTNodeAnnotation.Attribute 319 public boolean isDUafterCreation(Variable v) { 320 boolean isDUafterCreation_Variable_value = getTypeAccess().isDUafter(v); 321 322 return isDUafterCreation_Variable_value; 323 } 324 /** 325 * @attribute syn 326 * @aspect DU 327 * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:783 328 */ 329 @ASTNodeAnnotation.Attribute 330 public boolean isDUafter(Variable v) { 331 boolean isDUafter_Variable_value = hasArrayInit() ? getArrayInit().isDUafter(v) : isDUafterCreation(v); 332 333 return isDUafter_Variable_value; 334 } 335 /** 336 * @apilevel internal 337 */ 338 protected boolean type_computed = false; 339 /** 340 * @apilevel internal 341 */ 342 protected TypeDecl type_value; 343 /** 344 * @apilevel internal 345 */ 346 private void type_reset() { 347 type_computed = false; 348 type_value = null; 349 } 350 /** 351 * @attribute syn 352 * @aspect TypeAnalysis 353 * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:302 354 */ 355 @ASTNodeAnnotation.Attribute 356 public TypeDecl type() { 357 ASTNode$State state = state(); 358 if (type_computed) { 359 return type_value; 360 } 361 boolean intermediate = state.INTERMEDIATE_VALUE; 362 state.INTERMEDIATE_VALUE = false; 363 int num = state.boundariesCrossed; 364 boolean isFinal = this.is$Final(); 365 type_value = getTypeAccess().type(); 366 if (isFinal && num == state().boundariesCrossed) { 367 type_computed = true; 368 } else { 369 } 370 state.INTERMEDIATE_VALUE |= intermediate; 371 372 return type_value; 373 } 374 /** 375 * @apilevel internal 376 */ 377 protected boolean numArrays_computed = false; 378 /** 379 * @apilevel internal 380 */ 381 protected int numArrays_value; 382 /** 383 * @apilevel internal 384 */ 385 private void numArrays_reset() { 386 numArrays_computed = false; 387 } 388 /** 389 * @attribute syn 390 * @aspect InnerClasses 391 * @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:103 392 */ 393 @ASTNodeAnnotation.Attribute 394 public int numArrays() { 395 ASTNode$State state = state(); 396 if (numArrays_computed) { 397 return numArrays_value; 398 } 399 boolean intermediate = state.INTERMEDIATE_VALUE; 400 state.INTERMEDIATE_VALUE = false; 401 int num = state.boundariesCrossed; 402 boolean isFinal = this.is$Final(); 403 numArrays_value = numArrays_compute(); 404 if (isFinal && num == state().boundariesCrossed) { 405 numArrays_computed = true; 406 } else { 407 } 408 state.INTERMEDIATE_VALUE |= intermediate; 409 410 return numArrays_value; 411 } 412 /** 413 * @apilevel internal 414 */ 415 private int numArrays_compute() { 416 int i = type().dimension(); 417 Access a = getTypeAccess(); 418 while (a instanceof ArrayTypeAccess && !(a instanceof ArrayTypeWithSizeAccess)) { 419 i--; 420 a = ((ArrayTypeAccess) a).getAccess(); 421 } 422 return i; 423 } 424 /** 425 * @attribute syn 426 * @aspect PreciseRethrow 427 * @declaredat /home/jesper/git/extendj/java7/frontend/PreciseRethrow.jrag:149 428 */ 429 @ASTNodeAnnotation.Attribute 430 public boolean modifiedInScope(Variable var) { 431 boolean modifiedInScope_Variable_value = hasArrayInit() && getArrayInit().modifiedInScope(var); 432 433 return modifiedInScope_Variable_value; 434 } 435 /** 436 * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:255 437 * @apilevel internal 438 */ 439 public boolean Define_isDAbefore(ASTNode caller, ASTNode child, Variable v) { 440 if (caller == getArrayInitOptNoTransform()) { 441 // @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:476 442 return isDAafterCreation(v); 443 } 444 else { 445 return getParent().Define_isDAbefore(this, caller, v); 446 } 447 } 448 protected boolean canDefine_isDAbefore(ASTNode caller, ASTNode child, Variable v) { 449 return true; 450 } 451 /** 452 * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:779 453 * @apilevel internal 454 */ 455 public boolean Define_isDUbefore(ASTNode caller, ASTNode child, Variable v) { 456 if (caller == getArrayInitOptNoTransform()) { 457 // @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:978 458 return isDUafterCreation(v); 459 } 460 else { 461 return getParent().Define_isDUbefore(this, caller, v); 462 } 463 } 464 protected boolean canDefine_isDUbefore(ASTNode caller, ASTNode child, Variable v) { 465 return true; 466 } 467 /** 468 * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36 469 * @apilevel internal 470 */ 471 public NameType Define_nameType(ASTNode caller, ASTNode child) { 472 if (caller == getTypeAccessNoTransform()) { 473 // @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:114 474 return NameType.TYPE_NAME; 475 } 476 else { 477 return getParent().Define_nameType(this, caller); 478 } 479 } 480 protected boolean canDefine_nameType(ASTNode caller, ASTNode child) { 481 return true; 482 } 483 /** 484 * @declaredat /home/jesper/git/extendj/java5/frontend/Annotations.jrag:601 485 * @apilevel internal 486 */ 487 public TypeDecl Define_declType(ASTNode caller, ASTNode child) { 488 if (caller == getArrayInitOptNoTransform()) { 489 // @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:288 490 return type(); 491 } 492 else { 493 return getParent().Define_declType(this, caller); 494 } 495 } 496 protected boolean canDefine_declType(ASTNode caller, ASTNode child) { 497 return true; 498 } 499 /** 500 * @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:93 501 * @apilevel internal 502 */ 503 public TypeDecl Define_expectedType(ASTNode caller, ASTNode child) { 504 if (caller == getArrayInitOptNoTransform()) { 505 // @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:97 506 return type().componentType(); 507 } 508 else { 509 return getParent().Define_expectedType(this, caller); 510 } 511 } 512 protected boolean canDefine_expectedType(ASTNode caller, ASTNode child) { 513 return true; 514 } 515 /** 516 * @apilevel internal 517 */ 518 public ASTNode rewriteTo() { 519 return super.rewriteTo(); 520 } 521 }