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 IfStmt : {@link Stmt} ::= <span class="component">Condition:{@link Expr}</span> <span class="component">Then:{@link Stmt}</span> <span class="component">[Else:{@link Stmt}]</span>; 015 * @ast node 016 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/java.ast:207 017 */ 018 public class IfStmt extends Stmt 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 IfStmt clone() throws CloneNotSupportedException { 034 IfStmt node = (IfStmt)super.clone(); 035 node.isDAafter_Variable_values = null; 036 node.isDUafter_Variable_values = null; 037 node.canCompleteNormally_computed = false; 038 node.else_branch_label_computed = false; 039 node.then_branch_label_computed = false; 040 node.in$Circle(false); 041 node.is$Final(false); 042 return node; 043 } 044 /** 045 * @apilevel internal 046 */ 047 @SuppressWarnings({"unchecked", "cast"}) 048 public IfStmt copy() { 049 050 try { 051 IfStmt node = (IfStmt) clone(); 052 node.parent = null; 053 if(children != null) 054 node.children = (ASTNode[]) children.clone(); 055 056 return node; 057 } catch (CloneNotSupportedException e) { 058 throw new Error("Error: clone not supported for " + getClass().getName()); 059 } 060 061 }/** 062 * Create a deep copy of the AST subtree at this node. 063 * The copy is dangling, i.e. has no parent. 064 * @return dangling copy of the subtree at this node 065 * @apilevel low-level 066 */ 067 @SuppressWarnings({"unchecked", "cast"}) 068 public IfStmt fullCopy() { 069 070 IfStmt tree = (IfStmt) copy(); 071 if (children != null) { 072 for (int i = 0; i < children.length; ++i) { 073 074 ASTNode child = (ASTNode) children[i]; 075 if(child != null) { 076 child = child.fullCopy(); 077 tree.setChild(child, i); 078 } 079 } 080 } 081 return tree; 082 083 } /** 084 * @ast method 085 * @aspect NodeConstructors 086 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/NodeConstructors.jrag:66 087 */ 088 public IfStmt(Expr cond, Stmt thenBranch) { 089 this(cond, thenBranch, new Opt()); 090 } 091 /** 092 * @ast method 093 * @aspect NodeConstructors 094 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/NodeConstructors.jrag:70 095 */ 096 public IfStmt(Expr cond, Stmt thenBranch, Stmt elseBranch) { 097 this(cond, thenBranch, new Opt(elseBranch)); 098 } 099 /** 100 * @ast method 101 * @aspect PrettyPrint 102 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/PrettyPrint.jadd:574 103 */ 104 public void toString(StringBuffer s) { 105 s.append(indent()); 106 s.append("if("); 107 getCondition().toString(s); 108 s.append(") "); 109 getThen().toString(s); 110 if(hasElse()) { 111 s.append(indent()); 112 s.append("else "); 113 getElse().toString(s); 114 } 115 } 116 /** 117 * @ast method 118 * @aspect TypeCheck 119 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/TypeCheck.jrag:316 120 */ 121 public void typeCheck() { 122 TypeDecl cond = getCondition().type(); 123 if(!cond.isBoolean()) { 124 error("the type of \"" + getCondition() + "\" is " + cond.name() + " which is not boolean"); 125 } 126 } 127 /** 128 * @ast method 129 * @aspect CreateBCode 130 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1324 131 */ 132 public void createBCode(CodeGeneration gen) { 133 super.createBCode(gen); 134 int elseBranch = else_branch_label(); 135 int thenBranch = then_branch_label(); 136 int endBranch = hostType().constantPool().newLabel(); 137 getCondition().emitEvalBranch(gen); 138 gen.addLabel(thenBranch); 139 //if(getCondition().canBeTrue()) { 140 getThen().createBCode(gen); 141 if(getThen().canCompleteNormally() && hasElse() /*&& getCondition().canBeFalse()*/) 142 gen.emitGoto(endBranch); 143 //} 144 gen.addLabel(elseBranch); 145 if(hasElse() /*&& getCondition().canBeFalse()*/) 146 getElse().createBCode(gen); 147 gen.addLabel(endBranch); 148 } 149 /** 150 * @ast method 151 * 152 */ 153 public IfStmt() { 154 super(); 155 156 157 } 158 /** 159 * Initializes the child array to the correct size. 160 * Initializes List and Opt nta children. 161 * @apilevel internal 162 * @ast method 163 * @ast method 164 * 165 */ 166 public void init$Children() { 167 children = new ASTNode[3]; 168 setChild(new Opt(), 2); 169 } 170 /** 171 * @ast method 172 * 173 */ 174 public IfStmt(Expr p0, Stmt p1, Opt<Stmt> p2) { 175 setChild(p0, 0); 176 setChild(p1, 1); 177 setChild(p2, 2); 178 } 179 /** 180 * @apilevel low-level 181 * @ast method 182 * 183 */ 184 protected int numChildren() { 185 return 3; 186 } 187 /** 188 * @apilevel internal 189 * @ast method 190 * 191 */ 192 public boolean mayHaveRewrite() { 193 return false; 194 } 195 /** 196 * Replaces the Condition child. 197 * @param node The new node to replace the Condition child. 198 * @apilevel high-level 199 * @ast method 200 * 201 */ 202 public void setCondition(Expr node) { 203 setChild(node, 0); 204 } 205 /** 206 * Retrieves the Condition child. 207 * @return The current node used as the Condition child. 208 * @apilevel high-level 209 * @ast method 210 * 211 */ 212 public Expr getCondition() { 213 return (Expr)getChild(0); 214 } 215 /** 216 * Retrieves the Condition child. 217 * <p><em>This method does not invoke AST transformations.</em></p> 218 * @return The current node used as the Condition child. 219 * @apilevel low-level 220 * @ast method 221 * 222 */ 223 public Expr getConditionNoTransform() { 224 return (Expr)getChildNoTransform(0); 225 } 226 /** 227 * Replaces the Then child. 228 * @param node The new node to replace the Then child. 229 * @apilevel high-level 230 * @ast method 231 * 232 */ 233 public void setThen(Stmt node) { 234 setChild(node, 1); 235 } 236 /** 237 * Retrieves the Then child. 238 * @return The current node used as the Then child. 239 * @apilevel high-level 240 * @ast method 241 * 242 */ 243 public Stmt getThen() { 244 return (Stmt)getChild(1); 245 } 246 /** 247 * Retrieves the Then child. 248 * <p><em>This method does not invoke AST transformations.</em></p> 249 * @return The current node used as the Then child. 250 * @apilevel low-level 251 * @ast method 252 * 253 */ 254 public Stmt getThenNoTransform() { 255 return (Stmt)getChildNoTransform(1); 256 } 257 /** 258 * Replaces the optional node for the Else child. This is the {@code Opt} node containing the child Else, not the actual child! 259 * @param opt The new node to be used as the optional node for the Else child. 260 * @apilevel low-level 261 * @ast method 262 * 263 */ 264 public void setElseOpt(Opt<Stmt> opt) { 265 setChild(opt, 2); 266 } 267 /** 268 * Check whether the optional Else child exists. 269 * @return {@code true} if the optional Else child exists, {@code false} if it does not. 270 * @apilevel high-level 271 * @ast method 272 * 273 */ 274 public boolean hasElse() { 275 return getElseOpt().getNumChild() != 0; 276 } 277 /** 278 * Retrieves the (optional) Else child. 279 * @return The Else child, if it exists. Returns {@code null} otherwise. 280 * @apilevel low-level 281 * @ast method 282 * 283 */ 284 @SuppressWarnings({"unchecked", "cast"}) 285 public Stmt getElse() { 286 return (Stmt)getElseOpt().getChild(0); 287 } 288 /** 289 * Replaces the (optional) Else child. 290 * @param node The new node to be used as the Else child. 291 * @apilevel high-level 292 * @ast method 293 * 294 */ 295 public void setElse(Stmt node) { 296 getElseOpt().setChild(node, 0); 297 } 298 /** 299 * @apilevel low-level 300 * @ast method 301 * 302 */ 303 @SuppressWarnings({"unchecked", "cast"}) 304 public Opt<Stmt> getElseOpt() { 305 return (Opt<Stmt>)getChild(2); 306 } 307 /** 308 * Retrieves the optional node for child Else. This is the {@code Opt} node containing the child Else, not the actual child! 309 * <p><em>This method does not invoke AST transformations.</em></p> 310 * @return The optional node for child Else. 311 * @apilevel low-level 312 * @ast method 313 * 314 */ 315 @SuppressWarnings({"unchecked", "cast"}) 316 public Opt<Stmt> getElseOptNoTransform() { 317 return (Opt<Stmt>)getChildNoTransform(2); 318 } 319 protected java.util.Map isDAafter_Variable_values; 320 /** 321 * @attribute syn 322 * @aspect DA 323 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:525 324 */ 325 @SuppressWarnings({"unchecked", "cast"}) 326 public boolean isDAafter(Variable v) { 327 Object _parameters = v; 328 if(isDAafter_Variable_values == null) isDAafter_Variable_values = new java.util.HashMap(4); 329 if(isDAafter_Variable_values.containsKey(_parameters)) { 330 return ((Boolean)isDAafter_Variable_values.get(_parameters)).booleanValue(); 331 } 332 ASTNode$State state = state(); 333 int num = state.boundariesCrossed; 334 boolean isFinal = this.is$Final(); 335 boolean isDAafter_Variable_value = isDAafter_compute(v); 336 if(isFinal && num == state().boundariesCrossed){ isDAafter_Variable_values.put(_parameters, Boolean.valueOf(isDAafter_Variable_value)); } 337 return isDAafter_Variable_value; 338 } 339 /** 340 * @apilevel internal 341 */ 342 private boolean isDAafter_compute(Variable v) { return hasElse() ? getThen().isDAafter(v) && getElse().isDAafter(v) : getThen().isDAafter(v) && getCondition().isDAafterFalse(v); } 343 protected java.util.Map isDUafter_Variable_values; 344 /** 345 * @attribute syn 346 * @aspect DU 347 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:994 348 */ 349 @SuppressWarnings({"unchecked", "cast"}) 350 public boolean isDUafter(Variable v) { 351 Object _parameters = v; 352 if(isDUafter_Variable_values == null) isDUafter_Variable_values = new java.util.HashMap(4); 353 if(isDUafter_Variable_values.containsKey(_parameters)) { 354 return ((Boolean)isDUafter_Variable_values.get(_parameters)).booleanValue(); 355 } 356 ASTNode$State state = state(); 357 int num = state.boundariesCrossed; 358 boolean isFinal = this.is$Final(); 359 boolean isDUafter_Variable_value = isDUafter_compute(v); 360 if(isFinal && num == state().boundariesCrossed){ isDUafter_Variable_values.put(_parameters, Boolean.valueOf(isDUafter_Variable_value)); } 361 return isDUafter_Variable_value; 362 } 363 /** 364 * @apilevel internal 365 */ 366 private boolean isDUafter_compute(Variable v) { return hasElse() ? getThen().isDUafter(v) && getElse().isDUafter(v) : getThen().isDUafter(v) && getCondition().isDUafterFalse(v); } 367 /** 368 * @apilevel internal 369 */ 370 protected boolean canCompleteNormally_computed = false; 371 /** 372 * @apilevel internal 373 */ 374 protected boolean canCompleteNormally_value; 375 /** 376 * @attribute syn 377 * @aspect UnreachableStatements 378 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/UnreachableStatements.jrag:141 379 */ 380 @SuppressWarnings({"unchecked", "cast"}) 381 public boolean canCompleteNormally() { 382 if(canCompleteNormally_computed) { 383 return canCompleteNormally_value; 384 } 385 ASTNode$State state = state(); 386 int num = state.boundariesCrossed; 387 boolean isFinal = this.is$Final(); 388 canCompleteNormally_value = canCompleteNormally_compute(); 389 if(isFinal && num == state().boundariesCrossed){ canCompleteNormally_computed = true; } 390 return canCompleteNormally_value; 391 } 392 /** 393 * @apilevel internal 394 */ 395 private boolean canCompleteNormally_compute() { return (reachable() && !hasElse()) || (getThen().canCompleteNormally() || 396 (hasElse() && getElse().canCompleteNormally())); } 397 /** 398 * @attribute syn 399 * @aspect CreateBCode 400 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:946 401 */ 402 public boolean definesLabel() { 403 ASTNode$State state = state(); 404 try { return true; } 405 finally { 406 } 407 } 408 /** 409 * @apilevel internal 410 */ 411 protected boolean else_branch_label_computed = false; 412 /** 413 * @apilevel internal 414 */ 415 protected int else_branch_label_value; 416 /** 417 * @attribute syn 418 * @aspect CreateBCode 419 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1322 420 */ 421 @SuppressWarnings({"unchecked", "cast"}) 422 public int else_branch_label() { 423 if(else_branch_label_computed) { 424 return else_branch_label_value; 425 } 426 ASTNode$State state = state(); 427 int num = state.boundariesCrossed; 428 boolean isFinal = this.is$Final(); 429 else_branch_label_value = else_branch_label_compute(); 430 if(isFinal && num == state().boundariesCrossed){ else_branch_label_computed = true; } 431 return else_branch_label_value; 432 } 433 /** 434 * @apilevel internal 435 */ 436 private int else_branch_label_compute() { return hostType().constantPool().newLabel(); } 437 /** 438 * @apilevel internal 439 */ 440 protected boolean then_branch_label_computed = false; 441 /** 442 * @apilevel internal 443 */ 444 protected int then_branch_label_value; 445 /** 446 * @attribute syn 447 * @aspect CreateBCode 448 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:1323 449 */ 450 @SuppressWarnings({"unchecked", "cast"}) 451 public int then_branch_label() { 452 if(then_branch_label_computed) { 453 return then_branch_label_value; 454 } 455 ASTNode$State state = state(); 456 int num = state.boundariesCrossed; 457 boolean isFinal = this.is$Final(); 458 then_branch_label_value = then_branch_label_compute(); 459 if(isFinal && num == state().boundariesCrossed){ then_branch_label_computed = true; } 460 return then_branch_label_value; 461 } 462 /** 463 * @apilevel internal 464 */ 465 private int then_branch_label_compute() { return hostType().constantPool().newLabel(); } 466 /** 467 * @attribute syn 468 * @aspect PreciseRethrow 469 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/PreciseRethrow.jrag:55 470 */ 471 public boolean modifiedInScope(Variable var) { 472 ASTNode$State state = state(); 473 try { 474 if (getThen().modifiedInScope(var)) 475 return true; 476 return hasElse() && getElse().modifiedInScope(var); 477 } 478 finally { 479 } 480 } 481 /** 482 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:528 483 * @apilevel internal 484 */ 485 public boolean Define_boolean_isDAbefore(ASTNode caller, ASTNode child, Variable v) { 486 if(caller == getElseOptNoTransform()) { 487 return getCondition().isDAafterFalse(v); 488 } 489 else if(caller == getThenNoTransform()) { 490 return getCondition().isDAafterTrue(v); 491 } 492 else if(caller == getConditionNoTransform()) { 493 return isDAbefore(v); 494 } 495 else { return getParent().Define_boolean_isDAbefore(this, caller, v); 496 } 497 } 498 /** 499 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/DefiniteAssignment.jrag:997 500 * @apilevel internal 501 */ 502 public boolean Define_boolean_isDUbefore(ASTNode caller, ASTNode child, Variable v) { 503 if(caller == getElseOptNoTransform()) { 504 return getCondition().isDUafterFalse(v); 505 } 506 else if(caller == getThenNoTransform()) { 507 return getCondition().isDUafterTrue(v); 508 } 509 else if(caller == getConditionNoTransform()) { 510 return isDUbefore(v); 511 } 512 else { return getParent().Define_boolean_isDUbefore(this, caller, v); 513 } 514 } 515 /** 516 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/UnreachableStatements.jrag:144 517 * @apilevel internal 518 */ 519 public boolean Define_boolean_reachable(ASTNode caller, ASTNode child) { 520 if(caller == getElseOptNoTransform()) { 521 return reachable(); 522 } 523 else if(caller == getThenNoTransform()) { 524 return reachable(); 525 } 526 else { return getParent().Define_boolean_reachable(this, caller); 527 } 528 } 529 /** 530 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/UnreachableStatements.jrag:150 531 * @apilevel internal 532 */ 533 public boolean Define_boolean_reportUnreachable(ASTNode caller, ASTNode child) { 534 if(caller == getElseOptNoTransform()) { 535 return reachable(); 536 } 537 else if(caller == getThenNoTransform()) { 538 return reachable(); 539 } 540 else { return getParent().Define_boolean_reportUnreachable(this, caller); 541 } 542 } 543 /** 544 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:963 545 * @apilevel internal 546 */ 547 public int Define_int_condition_false_label(ASTNode caller, ASTNode child) { 548 if(caller == getConditionNoTransform()) { 549 return else_branch_label(); 550 } 551 else { return getParent().Define_int_condition_false_label(this, caller); 552 } 553 } 554 /** 555 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:964 556 * @apilevel internal 557 */ 558 public int Define_int_condition_true_label(ASTNode caller, ASTNode child) { 559 if(caller == getConditionNoTransform()) { 560 return then_branch_label(); 561 } 562 else { return getParent().Define_int_condition_true_label(this, caller); 563 } 564 } 565 /** 566 * @apilevel internal 567 */ 568 public ASTNode rewriteTo() { 569 return super.rewriteTo(); 570 } 571 }