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 ATransformation extends PTransformation
00040 {
00041 private TWhen _when_;
00042 private PExpr _expr_;
00043 private TDo _do_;
00044 private TInvisible _invisible_;
00045 private TLbrace _lbrace_;
00046 private final LinkedList _actions_ = new TypedLinkedList(new Actions_Cast());
00047 private TRbrace _rbrace_;
00048 private TGoto _goto_;
00049 private TId _id_;
00050 private TSemicolon _semicolon_;
00051
00052 private class Actions_Cast implements Cast
00053 {
00054 public Object cast(Object o)
00055 {
00056 PAction node = (PAction) o;
00057
00058 if((node.parent() != null) &&
00059 (node.parent() != ATransformation.this))
00060 {
00061 node.parent().removeChild(node);
00062 }
00063
00064 if((node.parent() == null) ||
00065 (node.parent() != ATransformation.this))
00066 {
00067 node.parent(ATransformation.this);
00068 }
00069
00070 return node;
00071 }
00072 }
00073 public ATransformation()
00074 {
00075 }
00076 public ATransformation(
00077 TWhen _when_,
00078 PExpr _expr_,
00079 TDo _do_,
00080 TInvisible _invisible_,
00081 TLbrace _lbrace_,
00082 List _actions_,
00083 TRbrace _rbrace_,
00084 TGoto _goto_,
00085 TId _id_,
00086 TSemicolon _semicolon_)
00087 {
00088 setWhen(_when_);
00089
00090 setExpr(_expr_);
00091
00092 setDo(_do_);
00093
00094 setInvisible(_invisible_);
00095
00096 setLbrace(_lbrace_);
00097
00098 {
00099 Object temp[] = _actions_.toArray();
00100 for(int i = 0; i < temp.length; i++)
00101 {
00102 this._actions_.add(temp[i]);
00103 }
00104 }
00105
00106 setRbrace(_rbrace_);
00107
00108 setGoto(_goto_);
00109
00110 setId(_id_);
00111
00112 setSemicolon(_semicolon_);
00113
00114 }
00115 public ATransformation(
00116 TWhen _when_,
00117 PExpr _expr_,
00118 TDo _do_,
00119 TInvisible _invisible_,
00120 TLbrace _lbrace_,
00121 XPAction _actions_,
00122 TRbrace _rbrace_,
00123 TGoto _goto_,
00124 TId _id_,
00125 TSemicolon _semicolon_)
00126 {
00127 setWhen(_when_);
00128
00129 setExpr(_expr_);
00130
00131 setDo(_do_);
00132
00133 setInvisible(_invisible_);
00134
00135 setLbrace(_lbrace_);
00136
00137 if(_actions_ != null)
00138 {
00139 while(_actions_ instanceof X1PAction)
00140 {
00141 this._actions_.addFirst(((X1PAction) _actions_).getPAction());
00142 _actions_ = ((X1PAction) _actions_).getXPAction();
00143 }
00144 this._actions_.addFirst(((X2PAction) _actions_).getPAction());
00145 }
00146
00147 setRbrace(_rbrace_);
00148
00149 setGoto(_goto_);
00150
00151 setId(_id_);
00152
00153 setSemicolon(_semicolon_);
00154
00155 }
00156 public void apply(Switch sw)
00157 {
00158 ((Analysis) sw).caseATransformation(this);
00159 }
00160 public Object clone()
00161 {
00162 return new ATransformation(
00163 (TWhen) cloneNode(_when_),
00164 (PExpr) cloneNode(_expr_),
00165 (TDo) cloneNode(_do_),
00166 (TInvisible) cloneNode(_invisible_),
00167 (TLbrace) cloneNode(_lbrace_),
00168 cloneList(_actions_),
00169 (TRbrace) cloneNode(_rbrace_),
00170 (TGoto) cloneNode(_goto_),
00171 (TId) cloneNode(_id_),
00172 (TSemicolon) cloneNode(_semicolon_));
00173 }
00174 public LinkedList getActions()
00175 {
00176 return _actions_;
00177 }
00178 public TDo getDo()
00179 {
00180 return _do_;
00181 }
00182 public PExpr getExpr()
00183 {
00184 return _expr_;
00185 }
00186 public TGoto getGoto()
00187 {
00188 return _goto_;
00189 }
00190 public TId getId()
00191 {
00192 return _id_;
00193 }
00194 public TInvisible getInvisible()
00195 {
00196 return _invisible_;
00197 }
00198 public TLbrace getLbrace()
00199 {
00200 return _lbrace_;
00201 }
00202 public TRbrace getRbrace()
00203 {
00204 return _rbrace_;
00205 }
00206 public TSemicolon getSemicolon()
00207 {
00208 return _semicolon_;
00209 }
00210 public TWhen getWhen()
00211 {
00212 return _when_;
00213 }
00214 void removeChild(Node child)
00215 {
00216 if(_when_ == child)
00217 {
00218 _when_ = null;
00219 return;
00220 }
00221
00222 if(_expr_ == child)
00223 {
00224 _expr_ = null;
00225 return;
00226 }
00227
00228 if(_do_ == child)
00229 {
00230 _do_ = null;
00231 return;
00232 }
00233
00234 if(_invisible_ == child)
00235 {
00236 _invisible_ = null;
00237 return;
00238 }
00239
00240 if(_lbrace_ == child)
00241 {
00242 _lbrace_ = null;
00243 return;
00244 }
00245
00246 if(_actions_.remove(child))
00247 {
00248 return;
00249 }
00250
00251 if(_rbrace_ == child)
00252 {
00253 _rbrace_ = null;
00254 return;
00255 }
00256
00257 if(_goto_ == child)
00258 {
00259 _goto_ = null;
00260 return;
00261 }
00262
00263 if(_id_ == child)
00264 {
00265 _id_ = null;
00266 return;
00267 }
00268
00269 if(_semicolon_ == child)
00270 {
00271 _semicolon_ = null;
00272 return;
00273 }
00274
00275 }
00276 void replaceChild(Node oldChild, Node newChild)
00277 {
00278 if(_when_ == oldChild)
00279 {
00280 setWhen((TWhen) newChild);
00281 return;
00282 }
00283
00284 if(_expr_ == oldChild)
00285 {
00286 setExpr((PExpr) newChild);
00287 return;
00288 }
00289
00290 if(_do_ == oldChild)
00291 {
00292 setDo((TDo) newChild);
00293 return;
00294 }
00295
00296 if(_invisible_ == oldChild)
00297 {
00298 setInvisible((TInvisible) newChild);
00299 return;
00300 }
00301
00302 if(_lbrace_ == oldChild)
00303 {
00304 setLbrace((TLbrace) newChild);
00305 return;
00306 }
00307
00308 for(ListIterator i = _actions_.listIterator(); i.hasNext();)
00309 {
00310 if(i.next() == oldChild)
00311 {
00312 if(newChild != null)
00313 {
00314 i.set(newChild);
00315 oldChild.parent(null);
00316 return;
00317 }
00318
00319 i.remove();
00320 oldChild.parent(null);
00321 return;
00322 }
00323 }
00324
00325 if(_rbrace_ == oldChild)
00326 {
00327 setRbrace((TRbrace) newChild);
00328 return;
00329 }
00330
00331 if(_goto_ == oldChild)
00332 {
00333 setGoto((TGoto) newChild);
00334 return;
00335 }
00336
00337 if(_id_ == oldChild)
00338 {
00339 setId((TId) newChild);
00340 return;
00341 }
00342
00343 if(_semicolon_ == oldChild)
00344 {
00345 setSemicolon((TSemicolon) newChild);
00346 return;
00347 }
00348
00349 }
00350 public void setActions(List list)
00351 {
00352 Object temp[] = list.toArray();
00353 for(int i = 0; i < temp.length; i++)
00354 {
00355 _actions_.add(temp[i]);
00356 }
00357 }
00358 public void setDo(TDo node)
00359 {
00360 if(_do_ != null)
00361 {
00362 _do_.parent(null);
00363 }
00364
00365 if(node != null)
00366 {
00367 if(node.parent() != null)
00368 {
00369 node.parent().removeChild(node);
00370 }
00371
00372 node.parent(this);
00373 }
00374
00375 _do_ = node;
00376 }
00377 public void setExpr(PExpr node)
00378 {
00379 if(_expr_ != null)
00380 {
00381 _expr_.parent(null);
00382 }
00383
00384 if(node != null)
00385 {
00386 if(node.parent() != null)
00387 {
00388 node.parent().removeChild(node);
00389 }
00390
00391 node.parent(this);
00392 }
00393
00394 _expr_ = node;
00395 }
00396 public void setGoto(TGoto node)
00397 {
00398 if(_goto_ != null)
00399 {
00400 _goto_.parent(null);
00401 }
00402
00403 if(node != null)
00404 {
00405 if(node.parent() != null)
00406 {
00407 node.parent().removeChild(node);
00408 }
00409
00410 node.parent(this);
00411 }
00412
00413 _goto_ = node;
00414 }
00415 public void setId(TId node)
00416 {
00417 if(_id_ != null)
00418 {
00419 _id_.parent(null);
00420 }
00421
00422 if(node != null)
00423 {
00424 if(node.parent() != null)
00425 {
00426 node.parent().removeChild(node);
00427 }
00428
00429 node.parent(this);
00430 }
00431
00432 _id_ = node;
00433 }
00434 public void setInvisible(TInvisible node)
00435 {
00436 if(_invisible_ != null)
00437 {
00438 _invisible_.parent(null);
00439 }
00440
00441 if(node != null)
00442 {
00443 if(node.parent() != null)
00444 {
00445 node.parent().removeChild(node);
00446 }
00447
00448 node.parent(this);
00449 }
00450
00451 _invisible_ = node;
00452 }
00453 public void setLbrace(TLbrace node)
00454 {
00455 if(_lbrace_ != null)
00456 {
00457 _lbrace_.parent(null);
00458 }
00459
00460 if(node != null)
00461 {
00462 if(node.parent() != null)
00463 {
00464 node.parent().removeChild(node);
00465 }
00466
00467 node.parent(this);
00468 }
00469
00470 _lbrace_ = node;
00471 }
00472 public void setRbrace(TRbrace node)
00473 {
00474 if(_rbrace_ != null)
00475 {
00476 _rbrace_.parent(null);
00477 }
00478
00479 if(node != null)
00480 {
00481 if(node.parent() != null)
00482 {
00483 node.parent().removeChild(node);
00484 }
00485
00486 node.parent(this);
00487 }
00488
00489 _rbrace_ = node;
00490 }
00491 public void setSemicolon(TSemicolon node)
00492 {
00493 if(_semicolon_ != null)
00494 {
00495 _semicolon_.parent(null);
00496 }
00497
00498 if(node != null)
00499 {
00500 if(node.parent() != null)
00501 {
00502 node.parent().removeChild(node);
00503 }
00504
00505 node.parent(this);
00506 }
00507
00508 _semicolon_ = node;
00509 }
00510 public void setWhen(TWhen node)
00511 {
00512 if(_when_ != null)
00513 {
00514 _when_.parent(null);
00515 }
00516
00517 if(node != null)
00518 {
00519 if(node.parent() != null)
00520 {
00521 node.parent().removeChild(node);
00522 }
00523
00524 node.parent(this);
00525 }
00526
00527 _when_ = node;
00528 }
00529 public String toString()
00530 {
00531 return ""
00532 + toString(_when_)
00533 + toString(_expr_)
00534 + toString(_do_)
00535 + toString(_invisible_)
00536 + toString(_lbrace_)
00537 + toString(_actions_)
00538 + toString(_rbrace_)
00539 + toString(_goto_)
00540 + toString(_id_)
00541 + toString(_semicolon_);
00542 }
00543 }