001 /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.3 */ 002 package AST; 003 004 import java.util.*; 005 /** 006 * @ast node 007 * @declaredat /home/csz-naf/examples/StateMachine/spec/StateMachine.ast:6 008 * @production StateMachine : {@link ASTNode} ::= <span class="component">{@link Declaration}*</span>; 009 010 */ 011 public class StateMachine extends ASTNode<ASTNode> implements Cloneable { 012 /** 013 * @apilevel internal 014 */ 015 public StateMachine clone() throws CloneNotSupportedException { 016 StateMachine node = (StateMachine) super.clone(); 017 node.numberOfTransitions_visited = false; 018 return node; 019 } 020 /** 021 * @apilevel internal 022 */ 023 public StateMachine copy() { 024 try { 025 StateMachine node = (StateMachine) clone(); 026 node.parent = null; 027 if(children != null) { 028 node.children = (ASTNode[]) children.clone(); 029 } 030 return node; 031 } catch (CloneNotSupportedException e) { 032 throw new Error("Error: clone not supported for " + getClass().getName()); 033 } 034 } 035 /** 036 * Create a deep copy of the AST subtree at this node. 037 * The copy is dangling, i.e. has no parent. 038 * @return dangling copy of the subtree at this node 039 * @apilevel low-level 040 */ 041 public StateMachine fullCopy() { 042 StateMachine tree = (StateMachine) copy(); 043 if (children != null) { 044 for (int i = 0; i < children.length; ++i) { 045 ASTNode child = (ASTNode) children[i]; 046 if(child != null) { 047 child = child.fullCopy(); 048 tree.setChild(child, i); 049 } 050 } 051 } 052 return tree; 053 } 054 /** 055 * @aspect PrettyPrint 056 * @declaredat /home/csz-naf/examples/StateMachine/spec/PrettyPrint.jrag:6 057 */ 058 public void pp() { 059 for (Declaration d:getDeclarationList()) { 060 d.pp(); 061 } 062 } 063 /** 064 * @aspect PrintInfoAboutCycles 065 * @declaredat /home/csz-naf/examples/StateMachine/spec/PrintInfoAboutCycles.jrag:4 066 */ 067 public void printInfoAboutCycles() { 068 for (Declaration d : getDeclarationList()) { 069 d.printInfoAboutCycles(); 070 } 071 } 072 /** 073 * @aspect PrintReachable 074 * @declaredat /home/csz-naf/examples/StateMachine/spec/PrintReachable.jrag:4 075 */ 076 public void printReachable() { 077 for (Declaration d : getDeclarations()) d.printReachable(); 078 } 079 /** 080 */ 081 public StateMachine() { 082 super(); 083 } 084 /** 085 * Initializes the child array to the correct size. 086 * Initializes List and Opt nta children. 087 * @apilevel internal 088 * @ast method 089 */ 090 public void init$Children() { 091 children = new ASTNode[1]; 092 setChild(new List(), 0); 093 } 094 /** 095 */ 096 public StateMachine(List<Declaration> p0) { 097 setChild(p0, 0); 098 } 099 /** 100 * @apilevel low-level 101 */ 102 protected int numChildren() { 103 return 1; 104 } 105 /** 106 * @apilevel low-level 107 */ 108 public void flushCache() { 109 super.flushCache(); 110 numberOfTransitions_visited = false; 111 StateMachine_numberOfTransitionsColl_visited = false; 112 StateMachine_numberOfTransitionsColl_computed = false; 113 StateMachine_numberOfTransitionsColl_value = null; 114 StateMachine_numberOfTransitionsColl_contributors = null; 115 StateMachine_errors_visited = false; 116 StateMachine_errors_computed = false; 117 StateMachine_errors_value = null; 118 StateMachine_errors_contributors = null; 119 collect_contributors_StateMachine_numberOfTransitionsColl = false; 120 collect_contributors_StateMachine_errors = false; 121 collect_contributors_State_altSuccessors = false; 122 collect_contributors_State_predecessors = false; 123 collect_contributors_State_altReachable = false; 124 collecting_contributors_State_altReachable = false; 125 collect_contributors_State_transitions = false; 126 } 127 /** 128 * @apilevel internal 129 */ 130 public void flushCollectionCache() { 131 super.flushCollectionCache(); 132 StateMachine_numberOfTransitionsColl_visited = false; 133 StateMachine_numberOfTransitionsColl_computed = false; 134 StateMachine_numberOfTransitionsColl_value = null; 135 StateMachine_numberOfTransitionsColl_contributors = null; 136 StateMachine_errors_visited = false; 137 StateMachine_errors_computed = false; 138 StateMachine_errors_value = null; 139 StateMachine_errors_contributors = null; 140 collect_contributors_StateMachine_numberOfTransitionsColl = false; 141 collect_contributors_StateMachine_errors = false; 142 collect_contributors_State_altSuccessors = false; 143 collect_contributors_State_predecessors = false; 144 collect_contributors_State_altReachable = false; 145 collecting_contributors_State_altReachable = false; 146 collect_contributors_State_transitions = false; 147 } 148 /** 149 * Replaces the Declaration list. 150 * @param list The new list node to be used as the Declaration list. 151 * @apilevel high-level 152 */ 153 public void setDeclarationList(List<Declaration> list) { 154 setChild(list, 0); 155 } 156 /** 157 * Retrieves the number of children in the Declaration list. 158 * @return Number of children in the Declaration list. 159 * @apilevel high-level 160 */ 161 public int getNumDeclaration() { 162 return getDeclarationList().getNumChild(); 163 } 164 /** 165 * Retrieves the number of children in the Declaration list. 166 * Calling this method will not trigger rewrites. 167 * @return Number of children in the Declaration list. 168 * @apilevel low-level 169 */ 170 public int getNumDeclarationNoTransform() { 171 return getDeclarationListNoTransform().getNumChildNoTransform(); 172 } 173 /** 174 * Retrieves the element at index {@code i} in the Declaration list. 175 * @param i Index of the element to return. 176 * @return The element at position {@code i} in the Declaration list. 177 * @apilevel high-level 178 */ 179 public Declaration getDeclaration(int i) { 180 return (Declaration) getDeclarationList().getChild(i); 181 } 182 /** 183 * Check whether the Declaration list has any children. 184 * @return {@code true} if it has at least one child, {@code false} otherwise. 185 * @apilevel high-level 186 */ 187 public boolean hasDeclaration() { 188 return getDeclarationList().getNumChild() != 0; 189 } 190 /** 191 * Append an element to the Declaration list. 192 * @param node The element to append to the Declaration list. 193 * @apilevel high-level 194 */ 195 public void addDeclaration(Declaration node) { 196 List<Declaration> list = (parent == null || state == null) ? getDeclarationListNoTransform() : getDeclarationList(); 197 list.addChild(node); 198 } 199 /** 200 * @apilevel low-level 201 */ 202 public void addDeclarationNoTransform(Declaration node) { 203 List<Declaration> list = getDeclarationListNoTransform(); 204 list.addChild(node); 205 } 206 /** 207 * Replaces the Declaration list element at index {@code i} with the new node {@code node}. 208 * @param node The new node to replace the old list element. 209 * @param i The list index of the node to be replaced. 210 * @apilevel high-level 211 */ 212 public void setDeclaration(Declaration node, int i) { 213 List<Declaration> list = getDeclarationList(); 214 list.setChild(node, i); 215 } 216 /** 217 * Retrieves the Declaration list. 218 * @return The node representing the Declaration list. 219 * @apilevel high-level 220 */ 221 public List<Declaration> getDeclarationList() { 222 List<Declaration> list = (List<Declaration>) getChild(0); 223 list.getNumChild(); 224 return list; 225 } 226 /** 227 * Retrieves the Declaration list. 228 * <p><em>This method does not invoke AST transformations.</em></p> 229 * @return The node representing the Declaration list. 230 * @apilevel low-level 231 */ 232 public List<Declaration> getDeclarationListNoTransform() { 233 return (List<Declaration>) getChildNoTransform(0); 234 } 235 /** 236 * Retrieves the Declaration list. 237 * @return The node representing the Declaration list. 238 * @apilevel high-level 239 */ 240 public List<Declaration> getDeclarations() { 241 return getDeclarationList(); 242 } 243 /** 244 * Retrieves the Declaration list. 245 * <p><em>This method does not invoke AST transformations.</em></p> 246 * @return The node representing the Declaration list. 247 * @apilevel low-level 248 */ 249 public List<Declaration> getDeclarationsNoTransform() { 250 return getDeclarationListNoTransform(); 251 } 252 /** 253 * @aspect <NoAspect> 254 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:66 255 */ 256 private boolean collect_contributors_StateMachine_numberOfTransitionsColl = false; 257 protected void collect_contributors_StateMachine_numberOfTransitionsColl() { 258 if(collect_contributors_StateMachine_numberOfTransitionsColl) return; 259 super.collect_contributors_StateMachine_numberOfTransitionsColl(); 260 collect_contributors_StateMachine_numberOfTransitionsColl = true; 261 } 262 263 /** 264 * @aspect <NoAspect> 265 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:83 266 */ 267 private boolean collect_contributors_StateMachine_errors = false; 268 protected void collect_contributors_StateMachine_errors() { 269 if(collect_contributors_StateMachine_errors) return; 270 super.collect_contributors_StateMachine_errors(); 271 collect_contributors_StateMachine_errors = true; 272 } 273 274 /** 275 * @aspect <NoAspect> 276 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:48 277 */ 278 private boolean collect_contributors_State_altSuccessors = false; 279 protected void collect_contributors_State_altSuccessors() { 280 if(collect_contributors_State_altSuccessors) return; 281 super.collect_contributors_State_altSuccessors(); 282 collect_contributors_State_altSuccessors = true; 283 } 284 285 /** 286 * @aspect <NoAspect> 287 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:57 288 */ 289 private boolean collect_contributors_State_predecessors = false; 290 protected void collect_contributors_State_predecessors() { 291 if(collect_contributors_State_predecessors) return; 292 super.collect_contributors_State_predecessors(); 293 collect_contributors_State_predecessors = true; 294 } 295 296 /** 297 * @aspect <NoAspect> 298 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:102 299 */ 300 private boolean collect_contributors_State_altReachable = false; 301 302 public boolean collecting_contributors_State_altReachable = false; 303 304 protected void collect_contributors_State_altReachable() { 305 if (!collect_contributors_State_altReachable) { 306 collecting_contributors_State_altReachable = true; 307 super.collect_contributors_State_altReachable(); 308 collecting_contributors_State_altReachable = false; 309 collect_contributors_State_altReachable = true; 310 } 311 } 312 313 /** 314 * @aspect <NoAspect> 315 * @declaredat /home/csz-naf/examples/StateMachine/spec/Graph.jrag:6 316 */ 317 private boolean collect_contributors_State_transitions = false; 318 protected void collect_contributors_State_transitions() { 319 if(collect_contributors_State_transitions) return; 320 super.collect_contributors_State_transitions(); 321 collect_contributors_State_transitions = true; 322 } 323 324 /** 325 * @apilevel internal 326 */ 327 protected boolean numberOfTransitions_visited = false; 328 /** 329 * @attribute syn 330 * @aspect Exercises 331 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:64 332 */ 333 public int numberOfTransitions() { 334 if (numberOfTransitions_visited) { 335 throw new RuntimeException("Circular definition of attr: numberOfTransitions in class: org.jastadd.ast.AST.SynDecl"); 336 } 337 numberOfTransitions_visited = true; 338 try { return numberOfTransitionsColl().value(); } 339 finally { 340 numberOfTransitions_visited = false; 341 } 342 } 343 /** 344 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:17 345 * @apilevel internal 346 */ 347 public State Define_State_lookupForward(ASTNode caller, ASTNode child, String label) { 348 if (caller == getDeclarationListNoTransform()) { 349 int i = caller.getIndexOfChild(child); 350 { 351 for (int k = i+1; k<getNumDeclaration(); k++) { 352 Declaration d = getDeclaration(k); 353 State match = d.localLookup(label); 354 if (match != null) return match; 355 } 356 return null; 357 } 358 } 359 else { 360 return getParent().Define_State_lookupForward(this, caller, label); 361 } 362 } 363 /** 364 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:30 365 * @apilevel internal 366 */ 367 public Set<Transition> Define_Set_Transition__transitionsOf(ASTNode caller, ASTNode child, State s) { 368 if (caller == getDeclarationListNoTransform()) { 369 int i = caller.getIndexOfChild(child); 370 { 371 HashSet<Transition> result = new HashSet<Transition>(); 372 for (Declaration d : getDeclarationList()) { 373 Transition t = d.transitionOf(s); 374 if (t != null) result.add(t); 375 } 376 return result; 377 } 378 } 379 else { 380 return getParent().Define_Set_Transition__transitionsOf(this, caller, s); 381 } 382 } 383 /** 384 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:73 385 * @apilevel internal 386 */ 387 public StateMachine Define_StateMachine_theMachine(ASTNode caller, ASTNode child) { 388 if (caller == getDeclarationListNoTransform()) { 389 int i = caller.getIndexOfChild(child); 390 return this; 391 } 392 else { 393 return getParent().Define_StateMachine_theMachine(this, caller); 394 } 395 } 396 /** 397 * @declaredat /home/csz-naf/examples/StateMachine/spec/NameAnalysis.jrag:10 398 * @apilevel internal 399 */ 400 public State Define_State_lookup(ASTNode caller, ASTNode child, String label) { 401 if (caller == getDeclarationListNoTransform()) { 402 int i = caller.getIndexOfChild(child); 403 { // R4 404 for (Declaration d : getDeclarationList()) { 405 State match = d.localLookup(label); 406 if (match != null) return match; 407 } 408 return null; 409 } 410 } 411 else { 412 return getParent().Define_State_lookup(this, caller, label); 413 } 414 } 415 /** 416 * @attribute coll 417 * @aspect Exercises 418 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:66 419 */ 420 public Counter numberOfTransitionsColl() { 421 if(StateMachine_numberOfTransitionsColl_computed) { 422 return StateMachine_numberOfTransitionsColl_value; 423 } 424 if (StateMachine_numberOfTransitionsColl_visited) { 425 throw new RuntimeException("Circular definition of attr: numberOfTransitionsColl in class: org.jastadd.ast.AST.CollDecl"); 426 } 427 StateMachine_numberOfTransitionsColl_visited = true; 428 StateMachine_numberOfTransitionsColl_value = numberOfTransitionsColl_compute(); 429 if(true) { 430 StateMachine_numberOfTransitionsColl_computed = true; 431 } else { 432 } 433 434 StateMachine_numberOfTransitionsColl_visited = false; 435 return StateMachine_numberOfTransitionsColl_value; 436 } 437 java.util.Set StateMachine_numberOfTransitionsColl_contributors; 438 439 /** 440 * @apilevel internal 441 * @return the contributor set for numberOfTransitionsColl 442 */ 443 public java.util.Set StateMachine_numberOfTransitionsColl_contributors() { 444 if(StateMachine_numberOfTransitionsColl_contributors == null) 445 StateMachine_numberOfTransitionsColl_contributors = new ASTNode$State.IdentityHashSet(4); 446 return StateMachine_numberOfTransitionsColl_contributors; 447 } 448 449 /** 450 * @apilevel internal 451 */ 452 private Counter numberOfTransitionsColl_compute() { 453 ASTNode node = this; 454 while(node.getParent() != null && !(node instanceof StateMachine)) { 455 node = node.getParent(); 456 } 457 StateMachine root = (StateMachine) node; 458 root.collect_contributors_StateMachine_numberOfTransitionsColl(); 459 StateMachine_numberOfTransitionsColl_value = new Counter(); 460 if(StateMachine_numberOfTransitionsColl_contributors != null) 461 for (java.util.Iterator iter = StateMachine_numberOfTransitionsColl_contributors.iterator(); iter.hasNext(); ) { 462 ASTNode contributor = (ASTNode) iter.next(); 463 contributor.contributeTo_StateMachine_StateMachine_numberOfTransitionsColl(StateMachine_numberOfTransitionsColl_value); 464 } 465 // TODO: disabled temporarily since collections may not be cached 466 //StateMachine_numberOfTransitionsColl_contributors = null; 467 return StateMachine_numberOfTransitionsColl_value; 468 } 469 /** 470 * @apilevel internal 471 */ 472 protected boolean StateMachine_numberOfTransitionsColl_visited = false; 473 /** 474 * @apilevel internal 475 */ 476 protected boolean StateMachine_numberOfTransitionsColl_computed = false; 477 /** 478 * @apilevel internal 479 */ 480 protected Counter StateMachine_numberOfTransitionsColl_value; 481 /** 482 * @attribute coll 483 * @aspect Exercises 484 * @declaredat /home/csz-naf/examples/StateMachine/spec/Exercises.jrag:83 485 */ 486 public Set<String> errors() { 487 if(StateMachine_errors_computed) { 488 return StateMachine_errors_value; 489 } 490 if (StateMachine_errors_visited) { 491 throw new RuntimeException("Circular definition of attr: errors in class: org.jastadd.ast.AST.CollDecl"); 492 } 493 StateMachine_errors_visited = true; 494 StateMachine_errors_value = errors_compute(); 495 if(true) { 496 StateMachine_errors_computed = true; 497 } else { 498 } 499 500 StateMachine_errors_visited = false; 501 return StateMachine_errors_value; 502 } 503 java.util.Set StateMachine_errors_contributors; 504 505 /** 506 * @apilevel internal 507 * @return the contributor set for errors 508 */ 509 public java.util.Set StateMachine_errors_contributors() { 510 if(StateMachine_errors_contributors == null) 511 StateMachine_errors_contributors = new ASTNode$State.IdentityHashSet(4); 512 return StateMachine_errors_contributors; 513 } 514 515 /** 516 * @apilevel internal 517 */ 518 private Set<String> errors_compute() { 519 ASTNode node = this; 520 while(node.getParent() != null && !(node instanceof StateMachine)) { 521 node = node.getParent(); 522 } 523 StateMachine root = (StateMachine) node; 524 root.collect_contributors_StateMachine_errors(); 525 StateMachine_errors_value = new HashSet<String>(); 526 if(StateMachine_errors_contributors != null) 527 for (java.util.Iterator iter = StateMachine_errors_contributors.iterator(); iter.hasNext(); ) { 528 ASTNode contributor = (ASTNode) iter.next(); 529 contributor.contributeTo_StateMachine_StateMachine_errors(StateMachine_errors_value); 530 } 531 // TODO: disabled temporarily since collections may not be cached 532 //StateMachine_errors_contributors = null; 533 return StateMachine_errors_value; 534 } 535 /** 536 * @apilevel internal 537 */ 538 protected boolean StateMachine_errors_visited = false; 539 /** 540 * @apilevel internal 541 */ 542 protected boolean StateMachine_errors_computed = false; 543 /** 544 * @apilevel internal 545 */ 546 protected Set<String> StateMachine_errors_value; 547 }