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:141 027 * @production CastExpr : {@link Expr} ::= <span class="component">TypeAccess:{@link Access}</span> <span class="component">{@link Expr}</span>; 028 029 */ 030 public class CastExpr extends Expr implements Cloneable { 031 /** 032 * @aspect Java4PrettyPrint 033 * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:400 034 */ 035 public void prettyPrint(PrettyPrinter out) { 036 out.print("("); 037 out.print(getTypeAccess()); 038 out.print(") "); 039 out.print(getExpr()); 040 } 041 /** 042 * @aspect TypeCheck 043 * @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:297 044 */ 045 public void typeCheck() { 046 TypeDecl expr = getExpr().type(); 047 TypeDecl type = getTypeAccess().type(); 048 if (!expr.isUnknown()) { 049 if (!expr.castingConversionTo(type)) { 050 errorf("%s can not be cast into %s", expr.typeName(), type.typeName()); 051 } 052 if (!getTypeAccess().isTypeAccess()) { 053 errorf("%s is not a type access in cast expression", getTypeAccess().prettyPrint()); 054 } 055 } 056 } 057 /** 058 * @aspect CreateBCode 059 * @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:920 060 */ 061 public void createBCode(CodeGeneration gen) { 062 getExpr().createBCode(gen); 063 getExpr().type().emitCastTo(gen, type()); 064 } 065 /** 066 * @aspect UncheckedConversion 067 * @declaredat /home/jesper/git/extendj/java7/frontend/UncheckedConversion.jrag:59 068 */ 069 public void checkWarnings() { 070 if (!withinSuppressWarnings("unchecked")) { 071 checkUncheckedConversion(getExpr().type(), getTypeAccess().type()); 072 } 073 } 074 /** 075 * @declaredat ASTNode:1 076 */ 077 public CastExpr() { 078 super(); 079 } 080 /** 081 * Initializes the child array to the correct size. 082 * Initializes List and Opt nta children. 083 * @apilevel internal 084 * @ast method 085 * @declaredat ASTNode:10 086 */ 087 public void init$Children() { 088 children = new ASTNode[2]; 089 } 090 /** 091 * @declaredat ASTNode:13 092 */ 093 public CastExpr(Access p0, Expr p1) { 094 setChild(p0, 0); 095 setChild(p1, 1); 096 } 097 /** 098 * @apilevel low-level 099 * @declaredat ASTNode:20 100 */ 101 protected int numChildren() { 102 return 2; 103 } 104 /** 105 * @apilevel internal 106 * @declaredat ASTNode:26 107 */ 108 public boolean mayHaveRewrite() { 109 return false; 110 } 111 /** 112 * @apilevel internal 113 * @declaredat ASTNode:32 114 */ 115 public void flushAttrCache() { 116 super.flushAttrCache(); 117 type_reset(); 118 } 119 /** 120 * @apilevel internal 121 * @declaredat ASTNode:39 122 */ 123 public void flushCollectionCache() { 124 super.flushCollectionCache(); 125 } 126 /** 127 * @apilevel internal 128 * @declaredat ASTNode:45 129 */ 130 public void flushRewriteCache() { 131 super.flushRewriteCache(); 132 } 133 /** 134 * @apilevel internal 135 * @declaredat ASTNode:51 136 */ 137 public CastExpr clone() throws CloneNotSupportedException { 138 CastExpr node = (CastExpr) super.clone(); 139 return node; 140 } 141 /** 142 * @apilevel internal 143 * @declaredat ASTNode:58 144 */ 145 public CastExpr copy() { 146 try { 147 CastExpr node = (CastExpr) clone(); 148 node.parent = null; 149 if (children != null) { 150 node.children = (ASTNode[]) children.clone(); 151 } 152 return node; 153 } catch (CloneNotSupportedException e) { 154 throw new Error("Error: clone not supported for " + getClass().getName()); 155 } 156 } 157 /** 158 * Create a deep copy of the AST subtree at this node. 159 * The copy is dangling, i.e. has no parent. 160 * @return dangling copy of the subtree at this node 161 * @apilevel low-level 162 * @deprecated Please use treeCopy or treeCopyNoTransform instead 163 * @declaredat ASTNode:77 164 */ 165 @Deprecated 166 public CastExpr fullCopy() { 167 return treeCopyNoTransform(); 168 } 169 /** 170 * Create a deep copy of the AST subtree at this node. 171 * The copy is dangling, i.e. has no parent. 172 * @return dangling copy of the subtree at this node 173 * @apilevel low-level 174 * @declaredat ASTNode:87 175 */ 176 public CastExpr treeCopyNoTransform() { 177 CastExpr tree = (CastExpr) copy(); 178 if (children != null) { 179 for (int i = 0; i < children.length; ++i) { 180 ASTNode child = (ASTNode) children[i]; 181 if (child != null) { 182 child = child.treeCopyNoTransform(); 183 tree.setChild(child, i); 184 } 185 } 186 } 187 return tree; 188 } 189 /** 190 * Create a deep copy of the AST subtree at this node. 191 * The subtree of this node is traversed to trigger rewrites before copy. 192 * The copy is dangling, i.e. has no parent. 193 * @return dangling copy of the subtree at this node 194 * @apilevel low-level 195 * @declaredat ASTNode:107 196 */ 197 public CastExpr treeCopy() { 198 doFullTraversal(); 199 return treeCopyNoTransform(); 200 } 201 /** 202 * @apilevel internal 203 * @declaredat ASTNode:114 204 */ 205 protected boolean is$Equal(ASTNode node) { 206 return super.is$Equal(node); 207 } 208 /** 209 * Replaces the TypeAccess child. 210 * @param node The new node to replace the TypeAccess child. 211 * @apilevel high-level 212 */ 213 public void setTypeAccess(Access node) { 214 setChild(node, 0); 215 } 216 /** 217 * Retrieves the TypeAccess child. 218 * @return The current node used as the TypeAccess child. 219 * @apilevel high-level 220 */ 221 @ASTNodeAnnotation.Child(name="TypeAccess") 222 public Access getTypeAccess() { 223 return (Access) getChild(0); 224 } 225 /** 226 * Retrieves the TypeAccess child. 227 * <p><em>This method does not invoke AST transformations.</em></p> 228 * @return The current node used as the TypeAccess child. 229 * @apilevel low-level 230 */ 231 public Access getTypeAccessNoTransform() { 232 return (Access) getChildNoTransform(0); 233 } 234 /** 235 * Replaces the Expr child. 236 * @param node The new node to replace the Expr child. 237 * @apilevel high-level 238 */ 239 public void setExpr(Expr node) { 240 setChild(node, 1); 241 } 242 /** 243 * Retrieves the Expr child. 244 * @return The current node used as the Expr child. 245 * @apilevel high-level 246 */ 247 @ASTNodeAnnotation.Child(name="Expr") 248 public Expr getExpr() { 249 return (Expr) getChild(1); 250 } 251 /** 252 * Retrieves the Expr child. 253 * <p><em>This method does not invoke AST transformations.</em></p> 254 * @return The current node used as the Expr child. 255 * @apilevel low-level 256 */ 257 public Expr getExprNoTransform() { 258 return (Expr) getChildNoTransform(1); 259 } 260 /** 261 * @attribute syn 262 * @aspect ConstantExpression 263 * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:32 264 */ 265 @ASTNodeAnnotation.Attribute 266 public Constant constant() { 267 Constant constant_value = type().cast(getExpr().constant()); 268 269 return constant_value; 270 } 271 /** 272 * @attribute syn 273 * @aspect ConstantExpression 274 * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:254 275 */ 276 @ASTNodeAnnotation.Attribute 277 public boolean isConstant() { 278 boolean isConstant_value = getExpr().isConstant() && 279 (getTypeAccess().type().isPrimitive() || getTypeAccess().type().isString()); 280 281 return isConstant_value; 282 } 283 /** 284 * @attribute syn 285 * @aspect DA 286 * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:259 287 */ 288 @ASTNodeAnnotation.Attribute 289 public boolean isDAafter(Variable v) { 290 boolean isDAafter_Variable_value = getExpr().isDAafter(v); 291 292 return isDAafter_Variable_value; 293 } 294 /** 295 * @attribute syn 296 * @aspect DU 297 * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:783 298 */ 299 @ASTNodeAnnotation.Attribute 300 public boolean isDUafter(Variable v) { 301 boolean isDUafter_Variable_value = getExpr().isDUafter(v); 302 303 return isDUafter_Variable_value; 304 } 305 /** 306 * @attribute syn 307 * @aspect AccessTypes 308 * @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:47 309 */ 310 @ASTNodeAnnotation.Attribute 311 public boolean isSuperAccess() { 312 boolean isSuperAccess_value = getExpr().isSuperAccess(); 313 314 return isSuperAccess_value; 315 } 316 /** 317 * @attribute syn 318 * @aspect AccessTypes 319 * @declaredat /home/jesper/git/extendj/java4/frontend/ResolveAmbiguousNames.jrag:53 320 */ 321 @ASTNodeAnnotation.Attribute 322 public boolean isThisAccess() { 323 boolean isThisAccess_value = getExpr().isThisAccess(); 324 325 return isThisAccess_value; 326 } 327 /** 328 * @apilevel internal 329 */ 330 protected boolean type_computed = false; 331 /** 332 * @apilevel internal 333 */ 334 protected TypeDecl type_value; 335 /** 336 * @apilevel internal 337 */ 338 private void type_reset() { 339 type_computed = false; 340 type_value = null; 341 } 342 /** 343 * @attribute syn 344 * @aspect TypeAnalysis 345 * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:302 346 */ 347 @ASTNodeAnnotation.Attribute 348 public TypeDecl type() { 349 ASTNode$State state = state(); 350 if (type_computed) { 351 return type_value; 352 } 353 boolean intermediate = state.INTERMEDIATE_VALUE; 354 state.INTERMEDIATE_VALUE = false; 355 int num = state.boundariesCrossed; 356 boolean isFinal = this.is$Final(); 357 type_value = getTypeAccess().type(); 358 if (isFinal && num == state().boundariesCrossed) { 359 type_computed = true; 360 } else { 361 } 362 state.INTERMEDIATE_VALUE |= intermediate; 363 364 return type_value; 365 } 366 /** 367 * @attribute syn 368 * @aspect TypeHierarchyCheck 369 * @declaredat /home/jesper/git/extendj/java4/frontend/TypeHierarchyCheck.jrag:199 370 */ 371 @ASTNodeAnnotation.Attribute 372 public boolean staticContextQualifier() { 373 boolean staticContextQualifier_value = getExpr().staticContextQualifier(); 374 375 return staticContextQualifier_value; 376 } 377 /** 378 * @attribute syn 379 * @aspect CreateBCode 380 * @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1022 381 */ 382 @ASTNodeAnnotation.Attribute 383 public boolean canBeTrue() { 384 boolean canBeTrue_value = getExpr().canBeTrue(); 385 386 return canBeTrue_value; 387 } 388 /** 389 * @attribute syn 390 * @aspect CreateBCode 391 * @declaredat /home/jesper/git/extendj/java4/backend/CreateBCode.jrag:1034 392 */ 393 @ASTNodeAnnotation.Attribute 394 public boolean canBeFalse() { 395 boolean canBeFalse_value = getExpr().canBeFalse(); 396 397 return canBeFalse_value; 398 } 399 /** 400 * @attribute syn 401 * @aspect PreciseRethrow 402 * @declaredat /home/jesper/git/extendj/java7/frontend/PreciseRethrow.jrag:149 403 */ 404 @ASTNodeAnnotation.Attribute 405 public boolean modifiedInScope(Variable var) { 406 boolean modifiedInScope_Variable_value = getExpr().modifiedInScope(var); 407 408 return modifiedInScope_Variable_value; 409 } 410 /** 411 * @attribute inh 412 * @aspect SuppressWarnings 413 * @declaredat /home/jesper/git/extendj/java7/frontend/SuppressWarnings.jrag:38 414 */ 415 /** 416 * @attribute inh 417 * @aspect SuppressWarnings 418 * @declaredat /home/jesper/git/extendj/java7/frontend/SuppressWarnings.jrag:38 419 */ 420 @ASTNodeAnnotation.Attribute 421 public boolean withinSuppressWarnings(String annot) { 422 boolean withinSuppressWarnings_String_value = getParent().Define_withinSuppressWarnings(this, null, annot); 423 424 return withinSuppressWarnings_String_value; 425 } 426 /** 427 * @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:36 428 * @apilevel internal 429 */ 430 public NameType Define_nameType(ASTNode caller, ASTNode child) { 431 if (caller == getTypeAccessNoTransform()) { 432 // @declaredat /home/jesper/git/extendj/java4/frontend/SyntacticClassification.jrag:115 433 return NameType.TYPE_NAME; 434 } 435 else { 436 return getParent().Define_nameType(this, caller); 437 } 438 } 439 protected boolean canDefine_nameType(ASTNode caller, ASTNode child) { 440 return true; 441 } 442 /** 443 * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:30 444 * @apilevel internal 445 */ 446 public TypeDecl Define_targetType(ASTNode caller, ASTNode child) { 447 if (caller == getExprNoTransform()) { 448 // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:42 449 return type(); 450 } 451 else { 452 return getParent().Define_targetType(this, caller); 453 } 454 } 455 protected boolean canDefine_targetType(ASTNode caller, ASTNode child) { 456 return true; 457 } 458 /** 459 * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:196 460 * @apilevel internal 461 */ 462 public boolean Define_assignmentContext(ASTNode caller, ASTNode child) { 463 if (caller == getExprNoTransform()) { 464 // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:307 465 return false; 466 } 467 else { 468 return getParent().Define_assignmentContext(this, caller); 469 } 470 } 471 protected boolean canDefine_assignmentContext(ASTNode caller, ASTNode child) { 472 return true; 473 } 474 /** 475 * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:197 476 * @apilevel internal 477 */ 478 public boolean Define_invocationContext(ASTNode caller, ASTNode child) { 479 if (caller == getExprNoTransform()) { 480 // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:308 481 return false; 482 } 483 else { 484 return getParent().Define_invocationContext(this, caller); 485 } 486 } 487 protected boolean canDefine_invocationContext(ASTNode caller, ASTNode child) { 488 return true; 489 } 490 /** 491 * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:198 492 * @apilevel internal 493 */ 494 public boolean Define_castContext(ASTNode caller, ASTNode child) { 495 if (caller == getExprNoTransform()) { 496 // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:309 497 return true; 498 } 499 else { 500 return getParent().Define_castContext(this, caller); 501 } 502 } 503 protected boolean canDefine_castContext(ASTNode caller, ASTNode child) { 504 return true; 505 } 506 /** 507 * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:199 508 * @apilevel internal 509 */ 510 public boolean Define_stringContext(ASTNode caller, ASTNode child) { 511 if (caller == getExprNoTransform()) { 512 // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:310 513 return false; 514 } 515 else { 516 return getParent().Define_stringContext(this, caller); 517 } 518 } 519 protected boolean canDefine_stringContext(ASTNode caller, ASTNode child) { 520 return true; 521 } 522 /** 523 * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:200 524 * @apilevel internal 525 */ 526 public boolean Define_numericContext(ASTNode caller, ASTNode child) { 527 if (caller == getExprNoTransform()) { 528 // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:311 529 return false; 530 } 531 else { 532 return getParent().Define_numericContext(this, caller); 533 } 534 } 535 protected boolean canDefine_numericContext(ASTNode caller, ASTNode child) { 536 return true; 537 } 538 /** 539 * @apilevel internal 540 */ 541 public ASTNode rewriteTo() { 542 return super.rewriteTo(); 543 } 544 }