00001 package edu.ksu.cis.bandera.birp.node;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 import ca.mcgill.sable.util.*;
00037 import edu.ksu.cis.bandera.birp.analysis.*;
00038
00039 public final class AProcess extends PProcess
00040 {
00041 private TProcess _process_;
00042 private TId _startname_;
00043 private TLparen _lparen_;
00044 private TRparen _rparen_;
00045 private final LinkedList _definitions_ = new TypedLinkedList(new Definitions_Cast());
00046 private final LinkedList _globals_ = new TypedLinkedList(new Globals_Cast());
00047 private final LinkedList _threads_ = new TypedLinkedList(new Threads_Cast());
00048 private PPredicates _predicates_;
00049 private TEnd _end_;
00050 private TId _endname_;
00051 private TSemicolon _semicolon_;
00052
00053 private class Definitions_Cast implements Cast
00054 {
00055 public Object cast(Object o)
00056 {
00057 PDefinition node = (PDefinition) o;
00058
00059 if((node.parent() != null) &&
00060 (node.parent() != AProcess.this))
00061 {
00062 node.parent().removeChild(node);
00063 }
00064
00065 if((node.parent() == null) ||
00066 (node.parent() != AProcess.this))
00067 {
00068 node.parent(AProcess.this);
00069 }
00070
00071 return node;
00072 }
00073 }
00074
00075 private class Globals_Cast implements Cast
00076 {
00077 public Object cast(Object o)
00078 {
00079 PGlobal node = (PGlobal) o;
00080
00081 if((node.parent() != null) &&
00082 (node.parent() != AProcess.this))
00083 {
00084 node.parent().removeChild(node);
00085 }
00086
00087 if((node.parent() == null) ||
00088 (node.parent() != AProcess.this))
00089 {
00090 node.parent(AProcess.this);
00091 }
00092
00093 return node;
00094 }
00095 }
00096
00097 private class Threads_Cast implements Cast
00098 {
00099 public Object cast(Object o)
00100 {
00101 PThread node = (PThread) o;
00102
00103 if((node.parent() != null) &&
00104 (node.parent() != AProcess.this))
00105 {
00106 node.parent().removeChild(node);
00107 }
00108
00109 if((node.parent() == null) ||
00110 (node.parent() != AProcess.this))
00111 {
00112 node.parent(AProcess.this);
00113 }
00114
00115 return node;
00116 }
00117 }
00118 public AProcess()
00119 {
00120 }
00121 public AProcess(
00122 TProcess _process_,
00123 TId _startname_,
00124 TLparen _lparen_,
00125 TRparen _rparen_,
00126 List _definitions_,
00127 List _globals_,
00128 List _threads_,
00129 PPredicates _predicates_,
00130 TEnd _end_,
00131 TId _endname_,
00132 TSemicolon _semicolon_)
00133 {
00134 setProcess(_process_);
00135
00136 setStartname(_startname_);
00137
00138 setLparen(_lparen_);
00139
00140 setRparen(_rparen_);
00141
00142 {
00143 Object temp[] = _definitions_.toArray();
00144 for(int i = 0; i < temp.length; i++)
00145 {
00146 this._definitions_.add(temp[i]);
00147 }
00148 }
00149
00150 {
00151 Object temp[] = _globals_.toArray();
00152 for(int i = 0; i < temp.length; i++)
00153 {
00154 this._globals_.add(temp[i]);
00155 }
00156 }
00157
00158 {
00159 Object temp[] = _threads_.toArray();
00160 for(int i = 0; i < temp.length; i++)
00161 {
00162 this._threads_.add(temp[i]);
00163 }
00164 }
00165
00166 setPredicates(_predicates_);
00167
00168 setEnd(_end_);
00169
00170 setEndname(_endname_);
00171
00172 setSemicolon(_semicolon_);
00173
00174 }
00175 public AProcess(
00176 TProcess _process_,
00177 TId _startname_,
00178 TLparen _lparen_,
00179 TRparen _rparen_,
00180 XPDefinition _definitions_,
00181 XPGlobal _globals_,
00182 XPThread _threads_,
00183 PPredicates _predicates_,
00184 TEnd _end_,
00185 TId _endname_,
00186 TSemicolon _semicolon_)
00187 {
00188 setProcess(_process_);
00189
00190 setStartname(_startname_);
00191
00192 setLparen(_lparen_);
00193
00194 setRparen(_rparen_);
00195
00196 if(_definitions_ != null)
00197 {
00198 while(_definitions_ instanceof X1PDefinition)
00199 {
00200 this._definitions_.addFirst(((X1PDefinition) _definitions_).getPDefinition());
00201 _definitions_ = ((X1PDefinition) _definitions_).getXPDefinition();
00202 }
00203 this._definitions_.addFirst(((X2PDefinition) _definitions_).getPDefinition());
00204 }
00205
00206 if(_globals_ != null)
00207 {
00208 while(_globals_ instanceof X1PGlobal)
00209 {
00210 this._globals_.addFirst(((X1PGlobal) _globals_).getPGlobal());
00211 _globals_ = ((X1PGlobal) _globals_).getXPGlobal();
00212 }
00213 this._globals_.addFirst(((X2PGlobal) _globals_).getPGlobal());
00214 }
00215
00216 if(_threads_ != null)
00217 {
00218 while(_threads_ instanceof X1PThread)
00219 {
00220 this._threads_.addFirst(((X1PThread) _threads_).getPThread());
00221 _threads_ = ((X1PThread) _threads_).getXPThread();
00222 }
00223 this._threads_.addFirst(((X2PThread) _threads_).getPThread());
00224 }
00225
00226 setPredicates(_predicates_);
00227
00228 setEnd(_end_);
00229
00230 setEndname(_endname_);
00231
00232 setSemicolon(_semicolon_);
00233
00234 }
00235 public void apply(Switch sw)
00236 {
00237 ((Analysis) sw).caseAProcess(this);
00238 }
00239 public Object clone()
00240 {
00241 return new AProcess(
00242 (TProcess) cloneNode(_process_),
00243 (TId) cloneNode(_startname_),
00244 (TLparen) cloneNode(_lparen_),
00245 (TRparen) cloneNode(_rparen_),
00246 cloneList(_definitions_),
00247 cloneList(_globals_),
00248 cloneList(_threads_),
00249 (PPredicates) cloneNode(_predicates_),
00250 (TEnd) cloneNode(_end_),
00251 (TId) cloneNode(_endname_),
00252 (TSemicolon) cloneNode(_semicolon_));
00253 }
00254 public LinkedList getDefinitions()
00255 {
00256 return _definitions_;
00257 }
00258 public TEnd getEnd()
00259 {
00260 return _end_;
00261 }
00262 public TId getEndname()
00263 {
00264 return _endname_;
00265 }
00266 public LinkedList getGlobals()
00267 {
00268 return _globals_;
00269 }
00270 public TLparen getLparen()
00271 {
00272 return _lparen_;
00273 }
00274 public PPredicates getPredicates()
00275 {
00276 return _predicates_;
00277 }
00278 public TProcess getProcess()
00279 {
00280 return _process_;
00281 }
00282 public TRparen getRparen()
00283 {
00284 return _rparen_;
00285 }
00286 public TSemicolon getSemicolon()
00287 {
00288 return _semicolon_;
00289 }
00290 public TId getStartname()
00291 {
00292 return _startname_;
00293 }
00294 public LinkedList getThreads()
00295 {
00296 return _threads_;
00297 }
00298 void removeChild(Node child)
00299 {
00300 if(_process_ == child)
00301 {
00302 _process_ = null;
00303 return;
00304 }
00305
00306 if(_startname_ == child)
00307 {
00308 _startname_ = null;
00309 return;
00310 }
00311
00312 if(_lparen_ == child)
00313 {
00314 _lparen_ = null;
00315 return;
00316 }
00317
00318 if(_rparen_ == child)
00319 {
00320 _rparen_ = null;
00321 return;
00322 }
00323
00324 if(_definitions_.remove(child))
00325 {
00326 return;
00327 }
00328
00329 if(_globals_.remove(child))
00330 {
00331 return;
00332 }
00333
00334 if(_threads_.remove(child))
00335 {
00336 return;
00337 }
00338
00339 if(_predicates_ == child)
00340 {
00341 _predicates_ = null;
00342 return;
00343 }
00344
00345 if(_end_ == child)
00346 {
00347 _end_ = null;
00348 return;
00349 }
00350
00351 if(_endname_ == child)
00352 {
00353 _endname_ = null;
00354 return;
00355 }
00356
00357 if(_semicolon_ == child)
00358 {
00359 _semicolon_ = null;
00360 return;
00361 }
00362
00363 }
00364 void replaceChild(Node oldChild, Node newChild)
00365 {
00366 if(_process_ == oldChild)
00367 {
00368 setProcess((TProcess) newChild);
00369 return;
00370 }
00371
00372 if(_startname_ == oldChild)
00373 {
00374 setStartname((TId) newChild);
00375 return;
00376 }
00377
00378 if(_lparen_ == oldChild)
00379 {
00380 setLparen((TLparen) newChild);
00381 return;
00382 }
00383
00384 if(_rparen_ == oldChild)
00385 {
00386 setRparen((TRparen) newChild);
00387 return;
00388 }
00389
00390 for(ListIterator i = _definitions_.listIterator(); i.hasNext();)
00391 {
00392 if(i.next() == oldChild)
00393 {
00394 if(newChild != null)
00395 {
00396 i.set(newChild);
00397 oldChild.parent(null);
00398 return;
00399 }
00400
00401 i.remove();
00402 oldChild.parent(null);
00403 return;
00404 }
00405 }
00406
00407 for(ListIterator i = _globals_.listIterator(); i.hasNext();)
00408 {
00409 if(i.next() == oldChild)
00410 {
00411 if(newChild != null)
00412 {
00413 i.set(newChild);
00414 oldChild.parent(null);
00415 return;
00416 }
00417
00418 i.remove();
00419 oldChild.parent(null);
00420 return;
00421 }
00422 }
00423
00424 for(ListIterator i = _threads_.listIterator(); i.hasNext();)
00425 {
00426 if(i.next() == oldChild)
00427 {
00428 if(newChild != null)
00429 {
00430 i.set(newChild);
00431 oldChild.parent(null);
00432 return;
00433 }
00434
00435 i.remove();
00436 oldChild.parent(null);
00437 return;
00438 }
00439 }
00440
00441 if(_predicates_ == oldChild)
00442 {
00443 setPredicates((PPredicates) newChild);
00444 return;
00445 }
00446
00447 if(_end_ == oldChild)
00448 {
00449 setEnd((TEnd) newChild);
00450 return;
00451 }
00452
00453 if(_endname_ == oldChild)
00454 {
00455 setEndname((TId) newChild);
00456 return;
00457 }
00458
00459 if(_semicolon_ == oldChild)
00460 {
00461 setSemicolon((TSemicolon) newChild);
00462 return;
00463 }
00464
00465 }
00466 public void setDefinitions(List list)
00467 {
00468 Object temp[] = list.toArray();
00469 for(int i = 0; i < temp.length; i++)
00470 {
00471 _definitions_.add(temp[i]);
00472 }
00473 }
00474 public void setEnd(TEnd node)
00475 {
00476 if(_end_ != null)
00477 {
00478 _end_.parent(null);
00479 }
00480
00481 if(node != null)
00482 {
00483 if(node.parent() != null)
00484 {
00485 node.parent().removeChild(node);
00486 }
00487
00488 node.parent(this);
00489 }
00490
00491 _end_ = node;
00492 }
00493 public void setEndname(TId node)
00494 {
00495 if(_endname_ != null)
00496 {
00497 _endname_.parent(null);
00498 }
00499
00500 if(node != null)
00501 {
00502 if(node.parent() != null)
00503 {
00504 node.parent().removeChild(node);
00505 }
00506
00507 node.parent(this);
00508 }
00509
00510 _endname_ = node;
00511 }
00512 public void setGlobals(List list)
00513 {
00514 Object temp[] = list.toArray();
00515 for(int i = 0; i < temp.length; i++)
00516 {
00517 _globals_.add(temp[i]);
00518 }
00519 }
00520 public void setLparen(TLparen node)
00521 {
00522 if(_lparen_ != null)
00523 {
00524 _lparen_.parent(null);
00525 }
00526
00527 if(node != null)
00528 {
00529 if(node.parent() != null)
00530 {
00531 node.parent().removeChild(node);
00532 }
00533
00534 node.parent(this);
00535 }
00536
00537 _lparen_ = node;
00538 }
00539 public void setPredicates(PPredicates node)
00540 {
00541 if(_predicates_ != null)
00542 {
00543 _predicates_.parent(null);
00544 }
00545
00546 if(node != null)
00547 {
00548 if(node.parent() != null)
00549 {
00550 node.parent().removeChild(node);
00551 }
00552
00553 node.parent(this);
00554 }
00555
00556 _predicates_ = node;
00557 }
00558 public void setProcess(TProcess node)
00559 {
00560 if(_process_ != null)
00561 {
00562 _process_.parent(null);
00563 }
00564
00565 if(node != null)
00566 {
00567 if(node.parent() != null)
00568 {
00569 node.parent().removeChild(node);
00570 }
00571
00572 node.parent(this);
00573 }
00574
00575 _process_ = node;
00576 }
00577 public void setRparen(TRparen node)
00578 {
00579 if(_rparen_ != null)
00580 {
00581 _rparen_.parent(null);
00582 }
00583
00584 if(node != null)
00585 {
00586 if(node.parent() != null)
00587 {
00588 node.parent().removeChild(node);
00589 }
00590
00591 node.parent(this);
00592 }
00593
00594 _rparen_ = node;
00595 }
00596 public void setSemicolon(TSemicolon node)
00597 {
00598 if(_semicolon_ != null)
00599 {
00600 _semicolon_.parent(null);
00601 }
00602
00603 if(node != null)
00604 {
00605 if(node.parent() != null)
00606 {
00607 node.parent().removeChild(node);
00608 }
00609
00610 node.parent(this);
00611 }
00612
00613 _semicolon_ = node;
00614 }
00615 public void setStartname(TId node)
00616 {
00617 if(_startname_ != null)
00618 {
00619 _startname_.parent(null);
00620 }
00621
00622 if(node != null)
00623 {
00624 if(node.parent() != null)
00625 {
00626 node.parent().removeChild(node);
00627 }
00628
00629 node.parent(this);
00630 }
00631
00632 _startname_ = node;
00633 }
00634 public void setThreads(List list)
00635 {
00636 Object temp[] = list.toArray();
00637 for(int i = 0; i < temp.length; i++)
00638 {
00639 _threads_.add(temp[i]);
00640 }
00641 }
00642 public String toString()
00643 {
00644 return ""
00645 + toString(_process_)
00646 + toString(_startname_)
00647 + toString(_lparen_)
00648 + toString(_rparen_)
00649 + toString(_definitions_)
00650 + toString(_globals_)
00651 + toString(_threads_)
00652 + toString(_predicates_)
00653 + toString(_end_)
00654 + toString(_endname_)
00655 + toString(_semicolon_);
00656 }
00657 }