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/java8/grammar/ConstructorReference.ast:4 027 * @production ArrayReference : {@link ConstructorReference}; 028 029 */ 030 public class ArrayReference extends ConstructorReference implements Cloneable { 031 /** 032 * @aspect Java8NameCheck 033 * @declaredat /home/jesper/git/extendj/java8/frontend/NameCheck.jrag:539 034 */ 035 public void nameCheck() { 036 Access typeAccess = getTypeAccess(); 037 while (typeAccess instanceof ArrayTypeAccess) { 038 typeAccess = ((ArrayTypeAccess) typeAccess).getAccess(); 039 } 040 if (typeAccess instanceof ParTypeAccess) { 041 error("Cannot create array of generic type"); 042 } 043 } 044 /** 045 * @aspect Java8PrettyPrint 046 * @declaredat /home/jesper/git/extendj/java8/frontend/PrettyPrint.jadd:84 047 */ 048 public void prettyPrint(PrettyPrinter out) { 049 out.print(getTypeAccess()); 050 out.print("::new"); 051 } 052 /** 053 * @declaredat ASTNode:1 054 */ 055 public ArrayReference() { 056 super(); 057 } 058 /** 059 * Initializes the child array to the correct size. 060 * Initializes List and Opt nta children. 061 * @apilevel internal 062 * @ast method 063 * @declaredat ASTNode:10 064 */ 065 public void init$Children() { 066 children = new ASTNode[1]; 067 } 068 /** 069 * @declaredat ASTNode:13 070 */ 071 public ArrayReference(Access p0) { 072 setChild(p0, 0); 073 } 074 /** 075 * @apilevel low-level 076 * @declaredat ASTNode:19 077 */ 078 protected int numChildren() { 079 return 1; 080 } 081 /** 082 * @apilevel internal 083 * @declaredat ASTNode:25 084 */ 085 public boolean mayHaveRewrite() { 086 return false; 087 } 088 /** 089 * @apilevel internal 090 * @declaredat ASTNode:31 091 */ 092 public void flushAttrCache() { 093 super.flushAttrCache(); 094 congruentTo_FunctionDescriptor_reset(); 095 isExact_reset(); 096 potentiallyCompatible_TypeDecl_BodyDecl_reset(); 097 toBlock_reset(); 098 } 099 /** 100 * @apilevel internal 101 * @declaredat ASTNode:41 102 */ 103 public void flushCollectionCache() { 104 super.flushCollectionCache(); 105 } 106 /** 107 * @apilevel internal 108 * @declaredat ASTNode:47 109 */ 110 public void flushRewriteCache() { 111 super.flushRewriteCache(); 112 } 113 /** 114 * @apilevel internal 115 * @declaredat ASTNode:53 116 */ 117 public ArrayReference clone() throws CloneNotSupportedException { 118 ArrayReference node = (ArrayReference) super.clone(); 119 return node; 120 } 121 /** 122 * @apilevel internal 123 * @declaredat ASTNode:60 124 */ 125 public ArrayReference copy() { 126 try { 127 ArrayReference node = (ArrayReference) clone(); 128 node.parent = null; 129 if (children != null) { 130 node.children = (ASTNode[]) children.clone(); 131 } 132 return node; 133 } catch (CloneNotSupportedException e) { 134 throw new Error("Error: clone not supported for " + getClass().getName()); 135 } 136 } 137 /** 138 * Create a deep copy of the AST subtree at this node. 139 * The copy is dangling, i.e. has no parent. 140 * @return dangling copy of the subtree at this node 141 * @apilevel low-level 142 * @deprecated Please use treeCopy or treeCopyNoTransform instead 143 * @declaredat ASTNode:79 144 */ 145 @Deprecated 146 public ArrayReference fullCopy() { 147 return treeCopyNoTransform(); 148 } 149 /** 150 * Create a deep copy of the AST subtree at this node. 151 * The copy is dangling, i.e. has no parent. 152 * @return dangling copy of the subtree at this node 153 * @apilevel low-level 154 * @declaredat ASTNode:89 155 */ 156 public ArrayReference treeCopyNoTransform() { 157 ArrayReference tree = (ArrayReference) copy(); 158 if (children != null) { 159 for (int i = 0; i < children.length; ++i) { 160 ASTNode child = (ASTNode) children[i]; 161 if (child != null) { 162 child = child.treeCopyNoTransform(); 163 tree.setChild(child, i); 164 } 165 } 166 } 167 return tree; 168 } 169 /** 170 * Create a deep copy of the AST subtree at this node. 171 * The subtree of this node is traversed to trigger rewrites before copy. 172 * The copy is dangling, i.e. has no parent. 173 * @return dangling copy of the subtree at this node 174 * @apilevel low-level 175 * @declaredat ASTNode:109 176 */ 177 public ArrayReference treeCopy() { 178 doFullTraversal(); 179 return treeCopyNoTransform(); 180 } 181 /** 182 * @apilevel internal 183 * @declaredat ASTNode:116 184 */ 185 protected boolean is$Equal(ASTNode node) { 186 return super.is$Equal(node); 187 } 188 /** 189 * Replaces the TypeAccess child. 190 * @param node The new node to replace the TypeAccess child. 191 * @apilevel high-level 192 */ 193 public void setTypeAccess(Access node) { 194 setChild(node, 0); 195 } 196 /** 197 * Retrieves the TypeAccess child. 198 * @return The current node used as the TypeAccess child. 199 * @apilevel high-level 200 */ 201 @ASTNodeAnnotation.Child(name="TypeAccess") 202 public Access getTypeAccess() { 203 return (Access) getChild(0); 204 } 205 /** 206 * Retrieves the TypeAccess child. 207 * <p><em>This method does not invoke AST transformations.</em></p> 208 * @return The current node used as the TypeAccess child. 209 * @apilevel low-level 210 */ 211 public Access getTypeAccessNoTransform() { 212 return (Access) getChildNoTransform(0); 213 } 214 /** 215 * @apilevel internal 216 */ 217 protected java.util.Map congruentTo_FunctionDescriptor_values; 218 /** 219 * @apilevel internal 220 */ 221 private void congruentTo_FunctionDescriptor_reset() { 222 congruentTo_FunctionDescriptor_values = null; 223 } 224 /** 225 * @attribute syn 226 * @aspect ConstructorReference 227 * @declaredat /home/jesper/git/extendj/java8/frontend/ConstructorReference.jrag:68 228 */ 229 @ASTNodeAnnotation.Attribute 230 public boolean congruentTo(FunctionDescriptor f) { 231 Object _parameters = f; 232 if (congruentTo_FunctionDescriptor_values == null) congruentTo_FunctionDescriptor_values = new org.jastadd.util.RobustMap(new java.util.HashMap()); 233 ASTNode$State state = state(); 234 if (congruentTo_FunctionDescriptor_values.containsKey(_parameters)) { 235 return (Boolean) congruentTo_FunctionDescriptor_values.get(_parameters); 236 } 237 boolean intermediate = state.INTERMEDIATE_VALUE; 238 state.INTERMEDIATE_VALUE = false; 239 int num = state.boundariesCrossed; 240 boolean isFinal = this.is$Final(); 241 boolean congruentTo_FunctionDescriptor_value = congruentTo_compute(f); 242 if (isFinal && num == state().boundariesCrossed) { 243 congruentTo_FunctionDescriptor_values.put(_parameters, congruentTo_FunctionDescriptor_value); 244 } else { 245 } 246 state.INTERMEDIATE_VALUE |= intermediate; 247 248 return congruentTo_FunctionDescriptor_value; 249 } 250 /** 251 * @apilevel internal 252 */ 253 private boolean congruentTo_compute(FunctionDescriptor f) { 254 if (f.method.getNumParameter() != 1) { 255 return false; 256 } 257 if (!f.method.getParameter(0).type().assignConversionTo(f.fromInterface().typeInt(), null)) { 258 return false; 259 } 260 if (!f.method.type().isVoid()) { 261 if (!getTypeAccess().type().assignConversionTo(f.method.type(), null)) { 262 return false; 263 } 264 } 265 return true; 266 } 267 /** 268 * @apilevel internal 269 */ 270 protected boolean isExact_computed = false; 271 /** 272 * @apilevel internal 273 */ 274 protected boolean isExact_value; 275 /** 276 * @apilevel internal 277 */ 278 private void isExact_reset() { 279 isExact_computed = false; 280 } 281 /** 282 * @attribute syn 283 * @aspect ConstructorReference 284 * @declaredat /home/jesper/git/extendj/java8/frontend/ConstructorReference.jrag:127 285 */ 286 @ASTNodeAnnotation.Attribute 287 public boolean isExact() { 288 ASTNode$State state = state(); 289 if (isExact_computed) { 290 return isExact_value; 291 } 292 boolean intermediate = state.INTERMEDIATE_VALUE; 293 state.INTERMEDIATE_VALUE = false; 294 int num = state.boundariesCrossed; 295 boolean isFinal = this.is$Final(); 296 isExact_value = true; 297 if (isFinal && num == state().boundariesCrossed) { 298 isExact_computed = true; 299 } else { 300 } 301 state.INTERMEDIATE_VALUE |= intermediate; 302 303 return isExact_value; 304 } 305 /** 306 * @apilevel internal 307 */ 308 protected java.util.Map potentiallyCompatible_TypeDecl_BodyDecl_values; 309 /** 310 * @apilevel internal 311 */ 312 private void potentiallyCompatible_TypeDecl_BodyDecl_reset() { 313 potentiallyCompatible_TypeDecl_BodyDecl_values = null; 314 } 315 /** 316 * @attribute syn 317 * @aspect MethodSignature18 318 * @declaredat /home/jesper/git/extendj/java8/frontend/MethodSignature.jrag:466 319 */ 320 @ASTNodeAnnotation.Attribute 321 public boolean potentiallyCompatible(TypeDecl type, BodyDecl candidateDecl) { 322 java.util.List _parameters = new java.util.ArrayList(2); 323 _parameters.add(type); 324 _parameters.add(candidateDecl); 325 if (potentiallyCompatible_TypeDecl_BodyDecl_values == null) potentiallyCompatible_TypeDecl_BodyDecl_values = new org.jastadd.util.RobustMap(new java.util.HashMap()); 326 ASTNode$State state = state(); 327 if (potentiallyCompatible_TypeDecl_BodyDecl_values.containsKey(_parameters)) { 328 return (Boolean) potentiallyCompatible_TypeDecl_BodyDecl_values.get(_parameters); 329 } 330 boolean intermediate = state.INTERMEDIATE_VALUE; 331 state.INTERMEDIATE_VALUE = false; 332 int num = state.boundariesCrossed; 333 boolean isFinal = this.is$Final(); 334 boolean potentiallyCompatible_TypeDecl_BodyDecl_value = potentiallyCompatible_compute(type, candidateDecl); 335 if (isFinal && num == state().boundariesCrossed) { 336 potentiallyCompatible_TypeDecl_BodyDecl_values.put(_parameters, potentiallyCompatible_TypeDecl_BodyDecl_value); 337 } else { 338 } 339 state.INTERMEDIATE_VALUE |= intermediate; 340 341 return potentiallyCompatible_TypeDecl_BodyDecl_value; 342 } 343 /** 344 * @apilevel internal 345 */ 346 private boolean potentiallyCompatible_compute(TypeDecl type, BodyDecl candidateDecl) { 347 if (super.potentiallyCompatible(type, candidateDecl) && type.isTypeVariable()) { 348 return true; 349 } else if (!super.potentiallyCompatible(type, candidateDecl)) { 350 return false; 351 } 352 InterfaceDecl iDecl = (InterfaceDecl) type; 353 FunctionDescriptor f = iDecl.functionDescriptor(); 354 return f.method.arity() == 1; 355 } 356 /** 357 * @attribute syn 358 * @aspect ConstructorReferenceToClass 359 * @declaredat /home/jesper/git/extendj/java8/backend/ConstructorReferenceToClass.jrag:34 360 */ 361 @ASTNodeAnnotation.Attribute 362 public ArrayTypeAccess getArrayTypeWithSizeAccess(Expr expr) { 363 { 364 ArrayTypeAccess startAccess = (ArrayTypeAccess) getTypeAccess().treeCopyNoTransform(); 365 return recursiveArrayTypeWithSizeAccess(startAccess, (Expr) expr.treeCopyNoTransform()); 366 } 367 } 368 /** 369 * @attribute syn 370 * @aspect ConstructorReferenceToClass 371 * @declaredat /home/jesper/git/extendj/java8/backend/ConstructorReferenceToClass.jrag:39 372 */ 373 @ASTNodeAnnotation.Attribute 374 public ArrayTypeAccess recursiveArrayTypeWithSizeAccess(ArrayTypeAccess access, Expr expr) { 375 { 376 if (!(access.getAccess() instanceof ArrayTypeAccess)) { 377 return new ArrayTypeWithSizeAccess(access.getAccess(), expr); 378 } else { 379 return new ArrayTypeAccess(recursiveArrayTypeWithSizeAccess((ArrayTypeAccess) access.getAccess(), expr)); 380 } 381 } 382 } 383 /** 384 * @apilevel internal 385 */ 386 protected boolean toBlock_computed = false; 387 /** 388 * @apilevel internal 389 */ 390 protected Block toBlock_value; 391 /** 392 * @apilevel internal 393 */ 394 private void toBlock_reset() { 395 toBlock_computed = false; 396 toBlock_value = null; 397 } 398 /** 399 * @attribute syn 400 * @aspect ConstructorReferenceToClass 401 * @declaredat /home/jesper/git/extendj/java8/backend/ConstructorReferenceToClass.jrag:85 402 */ 403 @ASTNodeAnnotation.Attribute 404 public Block toBlock() { 405 ASTNode$State state = state(); 406 if (toBlock_computed) { 407 return toBlock_value; 408 } 409 boolean intermediate = state.INTERMEDIATE_VALUE; 410 state.INTERMEDIATE_VALUE = false; 411 int num = state.boundariesCrossed; 412 boolean isFinal = this.is$Final(); 413 toBlock_value = toBlock_compute(); 414 if (isFinal && num == state().boundariesCrossed) { 415 toBlock_computed = true; 416 } else { 417 } 418 state.INTERMEDIATE_VALUE |= intermediate; 419 420 return toBlock_value; 421 } 422 /** 423 * @apilevel internal 424 */ 425 private Block toBlock_compute() { 426 // First, build an ArrayCreationExpr used in the block 427 String paramName = targetInterface().functionDescriptor().method.getParameter(0).name(); 428 VarAccess paramAccess = new VarAccess(paramName); 429 ArrayCreationExpr arrayExpr = new ArrayCreationExpr(getArrayTypeWithSizeAccess(paramAccess), new Opt()); 430 431 // Next build actual block 432 Stmt blockStmt = null; 433 if (targetInterface().functionDescriptor().method.type().isVoid()) { 434 blockStmt = new ExprStmt(arrayExpr); 435 } else { 436 blockStmt = new ReturnStmt(arrayExpr); 437 } 438 List<Stmt> stmtList = new List<Stmt>(); 439 stmtList.add(blockStmt); 440 return new Block(stmtList); 441 } 442 /** 443 * @apilevel internal 444 */ 445 public ASTNode rewriteTo() { 446 return super.rewriteTo(); 447 } 448 }