001 /* This file was generated with JastAdd2 (http://jastadd.org) version R20130213 */ 002 package AST; 003 004 import java.util.HashSet; 005 import java.io.File; 006 import java.util.*; 007 import beaver.*; 008 import java.util.ArrayList; 009 import java.util.zip.*; 010 import java.io.*; 011 import java.io.FileNotFoundException; 012 import java.util.Collection; 013 /** 014 * @production ArrayCreationExpr : {@link PrimaryExpr} ::= <span class="component">TypeAccess:{@link Access}</span> <span class="component">[{@link ArrayInit}]</span>; 015 * @ast node 016 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/java.ast:133 017 */ 018 public class ArrayCreationExpr extends PrimaryExpr implements Cloneable { 019 /** 020 * @apilevel low-level 021 */ 022 public void flushCache() { 023 } 024 /** 025 * @apilevel internal 026 */ 027 public void flushCollectionCache() { 028 } 029 /** 030 * @apilevel internal 031 */ 032 @SuppressWarnings({"unchecked", "cast"}) 033 public ArrayCreationExpr clone() throws CloneNotSupportedException { 034 ArrayCreationExpr node = (ArrayCreationExpr)super.clone(); 035 node.type_computed = false; 036 node.type_value = null; 037 node.numArrays_computed = false; 038 node.in$Circle(false); 039 node.is$Final(false); 040 return node; 041 } 042 /** 043 * @apilevel internal 044 */ 045 @SuppressWarnings({"unchecked", "cast"}) 046 public ArrayCreationExpr copy() { 047 048 try { 049 ArrayCreationExpr node = (ArrayCreationExpr) clone(); 050 node.parent = null; 051 if(children != null) 052 node.children = (ASTNode[]) children.clone(); 053 054 return node; 055 } catch (CloneNotSupportedException e) { 056 throw new Error("Error: clone not supported for " + getClass().getName()); 057 } 058 059 }/** 060 * Create a deep copy of the AST subtree at this node. 061 * The copy is dangling, i.e. has no parent. 062 * @return dangling copy of the subtree at this node 063 * @apilevel low-level 064 */ 065 @SuppressWarnings({"unchecked", "cast"}) 066 public ArrayCreationExpr fullCopy() { 067 068 ArrayCreationExpr tree = (ArrayCreationExpr) copy(); 069 if (children != null) { 070 for (int i = 0; i < children.length; ++i) { 071 072 ASTNode child = (ASTNode) children[i]; 073 if(child != null) { 074 child = child.fullCopy(); 075 tree.setChild(child, i); 076 } 077 } 078 } 079 return tree; 080 081 } /** 082 * @ast method 083 * @aspect PrettyPrint 084 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/PrettyPrint.jadd:356 085 */ 086 public void toString(StringBuffer s) { 087 s.append("new "); 088 getTypeAccess().toString(s); 089 if(hasArrayInit()) { 090 getArrayInit().toString(s); 091 } 092 } 093 /** 094 * @ast method 095 * 096 */ 097 public ArrayCreationExpr() { 098 super(); 099 100 101 } 102 /** 103 * Initializes the child array to the correct size. 104 * Initializes List and Opt nta children. 105 * @apilevel internal 106 * @ast method 107 * @ast method 108 * 109 */ 110 public void init$Children() { 111 children = new ASTNode[2]; 112 setChild(new Opt(), 1); 113 } 114 /** 115 * @ast method 116 * 117 */ 118 public ArrayCreationExpr(Access p0, Opt<ArrayInit> p1) { 119 setChild(p0, 0); 120 setChild(p1, 1); 121 } 122 /** 123 * @apilevel low-level 124 * @ast method 125 * 126 */ 127 protected int numChildren() { 128 return 2; 129 } 130 /** 131 * @apilevel internal 132 * @ast method 133 * 134 */ 135 public boolean mayHaveRewrite() { 136 return false; 137 } 138 /** 139 * Replaces the TypeAccess child. 140 * @param node The new node to replace the TypeAccess child. 141 * @apilevel high-level 142 * @ast method 143 * 144 */ 145 public void setTypeAccess(Access node) { 146 setChild(node, 0); 147 } 148 /** 149 * Retrieves the TypeAccess child. 150 * @return The current node used as the TypeAccess child. 151 * @apilevel high-level 152 * @ast method 153 * 154 */ 155 public Access getTypeAccess() { 156 return (Access)getChild(0); 157 } 158 /** 159 * Retrieves the TypeAccess child. 160 * <p><em>This method does not invoke AST transformations.</em></p> 161 * @return The current node used as the TypeAccess child. 162 * @apilevel low-level 163 * @ast method 164 * 165 */ 166 public Access getTypeAccessNoTransform() { 167 return (Access)getChildNoTransform(0); 168 } 169 /** 170 * Replaces the optional node for the ArrayInit child. This is the {@code Opt} node containing the child ArrayInit, not the actual child! 171 * @param opt The new node to be used as the optional node for the ArrayInit child. 172 * @apilevel low-level 173 * @ast method 174 * 175 */ 176 public void setArrayInitOpt(Opt<ArrayInit> opt) { 177 setChild(opt, 1); 178 } 179 /** 180 * Check whether the optional ArrayInit child exists. 181 * @return {@code true} if the optional ArrayInit child exists, {@code false} if it does not. 182 * @apilevel high-level 183 * @ast method 184 * 185 */ 186 public boolean hasArrayInit() { 187 return getArrayInitOpt().getNumChild() != 0; 188 } 189 /** 190 * Retrieves the (optional) ArrayInit child. 191 * @return The ArrayInit child, if it exists. Returns {@code null} otherwise. 192 * @apilevel low-level 193 * @ast method 194 * 195 */ 196 @SuppressWarnings({"unchecked", "cast"}) 197 public ArrayInit getArrayInit() { 198 return (ArrayInit)getArrayInitOpt().getChild(0); 199 } 200 /** 201 * Replaces the (optional) ArrayInit child. 202 * @param node The new node to be used as the ArrayInit child. 203 * @apilevel high-level 204 * @ast method 205 * 206 */ 207 public void setArrayInit(ArrayInit node) { 208 getArrayInitOpt().setChild(node, 0); 209 } 210 /** 211 * @apilevel low-level 212 * @ast method 213 * 214 */ 215 @SuppressWarnings({"unchecked", "cast"}) 216 public Opt<ArrayInit> getArrayInitOpt() { 217 return (Opt<ArrayInit>)getChild(1); 218 } 219 /** 220 * Retrieves the optional node for child ArrayInit. This is the {@code Opt} node containing the child ArrayInit, not the actual child! 221 * <p><em>This method does not invoke AST transformations.</em></p> 222 * @return The optional node for child ArrayInit. 223 * @apilevel low-level 224 * @ast method 225 * 226 */ 227 @SuppressWarnings({"unchecked", "cast"}) 228 public Opt<ArrayInit> getArrayInitOptNoTransform() { 229 return (Opt<ArrayInit>)getChildNoTransform(1); 230 } 231 /** 232 * @ast method 233 * @aspect AutoBoxingCodegen 234 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Backend/AutoBoxingCodegen.jrag:235 235 */ 236 public void createBCode(CodeGeneration gen) { 237 if(hasArrayInit()){ 238 getArrayInit().createBCode(gen); 239 } 240 else { 241 getTypeAccess().createBCode(gen); // push array sizes 242 if(type().componentType().isPrimitive() && !type().componentType().isReferenceType()) { 243 gen.emit(Bytecode.NEWARRAY).add(type().componentType().arrayPrimitiveTypeDescriptor()); 244 } 245 else { 246 if(numArrays() == 1) { 247 String n = type().componentType().arrayTypeDescriptor(); 248 int index = gen.constantPool().addClass(n); 249 gen.emit(Bytecode.ANEWARRAY).add2(index); 250 } 251 else { 252 String n = type().arrayTypeDescriptor(); 253 int index = gen.constantPool().addClass(n); 254 gen.emit(Bytecode.MULTIANEWARRAY, 1 - numArrays()).add2(index).add(numArrays()); 255 } 256 } 257 } 258 } 259 /** 260 * @attribute syn 261 * @aspect DA 262 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:432 263 */ 264 public boolean isDAafterCreation(Variable v) { 265 ASTNode$State state = state(); 266 try { return getTypeAccess().isDAafter(v); } 267 finally { 268 } 269 } 270 /** 271 * @attribute syn 272 * @aspect DA 273 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:235 274 */ 275 public boolean isDAafter(Variable v) { 276 ASTNode$State state = state(); 277 try { return hasArrayInit() ? getArrayInit().isDAafter(v) : isDAafterCreation(v); } 278 finally { 279 } 280 } 281 /** 282 * @attribute syn 283 * @aspect DU 284 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:860 285 */ 286 public boolean isDUafterCreation(Variable v) { 287 ASTNode$State state = state(); 288 try { return getTypeAccess().isDUafter(v); } 289 finally { 290 } 291 } 292 /** 293 * @attribute syn 294 * @aspect DU 295 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:694 296 */ 297 public boolean isDUafter(Variable v) { 298 ASTNode$State state = state(); 299 try { return hasArrayInit() ? getArrayInit().isDUafter(v) : isDUafterCreation(v); } 300 finally { 301 } 302 } 303 /** 304 * @apilevel internal 305 */ 306 protected boolean type_computed = false; 307 /** 308 * @apilevel internal 309 */ 310 protected TypeDecl type_value; 311 /** 312 * @attribute syn 313 * @aspect TypeAnalysis 314 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeAnalysis.jrag:312 315 */ 316 @SuppressWarnings({"unchecked", "cast"}) 317 public TypeDecl type() { 318 if(type_computed) { 319 return type_value; 320 } 321 ASTNode$State state = state(); 322 int num = state.boundariesCrossed; 323 boolean isFinal = this.is$Final(); 324 type_value = type_compute(); 325 if(isFinal && num == state().boundariesCrossed){ type_computed = true; } 326 return type_value; 327 } 328 /** 329 * @apilevel internal 330 */ 331 private TypeDecl type_compute() { return getTypeAccess().type(); } 332 /** 333 * @apilevel internal 334 */ 335 protected boolean numArrays_computed = false; 336 /** 337 * @apilevel internal 338 */ 339 protected int numArrays_value; 340 /** 341 * @attribute syn 342 * @aspect InnerClasses 343 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/InnerClasses.jrag:72 344 */ 345 @SuppressWarnings({"unchecked", "cast"}) 346 public int numArrays() { 347 if(numArrays_computed) { 348 return numArrays_value; 349 } 350 ASTNode$State state = state(); 351 int num = state.boundariesCrossed; 352 boolean isFinal = this.is$Final(); 353 numArrays_value = numArrays_compute(); 354 if(isFinal && num == state().boundariesCrossed){ numArrays_computed = true; } 355 return numArrays_value; 356 } 357 /** 358 * @apilevel internal 359 */ 360 private int numArrays_compute() { 361 int i = type().dimension(); 362 Access a = getTypeAccess(); 363 while(a instanceof ArrayTypeAccess && !(a instanceof ArrayTypeWithSizeAccess)) { 364 i--; 365 a = ((ArrayTypeAccess)a).getAccess(); 366 } 367 return i; 368 } 369 /** 370 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:434 371 * @apilevel internal 372 */ 373 public boolean Define_boolean_isDAbefore(ASTNode caller, ASTNode child, Variable v) { 374 if(caller == getArrayInitOptNoTransform()) { 375 return isDAafterCreation(v); 376 } 377 else { return getParent().Define_boolean_isDAbefore(this, caller, v); 378 } 379 } 380 /** 381 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:863 382 * @apilevel internal 383 */ 384 public boolean Define_boolean_isDUbefore(ASTNode caller, ASTNode child, Variable v) { 385 if(caller == getArrayInitOptNoTransform()) { 386 return isDUafterCreation(v); 387 } 388 else { return getParent().Define_boolean_isDUbefore(this, caller, v); 389 } 390 } 391 /** 392 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/SyntacticClassification.jrag:87 393 * @apilevel internal 394 */ 395 public NameType Define_NameType_nameType(ASTNode caller, ASTNode child) { 396 if(caller == getTypeAccessNoTransform()) { 397 return NameType.TYPE_NAME; 398 } 399 else { return getParent().Define_NameType_nameType(this, caller); 400 } 401 } 402 /** 403 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeAnalysis.jrag:262 404 * @apilevel internal 405 */ 406 public TypeDecl Define_TypeDecl_declType(ASTNode caller, ASTNode child) { 407 if(caller == getArrayInitOptNoTransform()) { 408 return type(); 409 } 410 else { return getParent().Define_TypeDecl_declType(this, caller); 411 } 412 } 413 /** 414 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/InnerClasses.jrag:66 415 * @apilevel internal 416 */ 417 public TypeDecl Define_TypeDecl_expectedType(ASTNode caller, ASTNode child) { 418 if(caller == getArrayInitOptNoTransform()) { 419 return type().componentType(); 420 } 421 else { return getParent().Define_TypeDecl_expectedType(this, caller); 422 } 423 } 424 /** 425 * @apilevel internal 426 */ 427 public ASTNode rewriteTo() { 428 return super.rewriteTo(); 429 } 430 }