00001 package edu.ksu.cis.bandera.jjjc.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.jjjc.analysis.*;
00038
00039 public final class AOneSwitchStmt extends POneSwitchStmt
00040 {
00041 private TSwitch _switch_;
00042 private TLPar _lPar_;
00043 private PExp _exp_;
00044 private TRPar _rPar_;
00045 private TLBrace _lBrace_;
00046 private final LinkedList _switchBlockStmtGroup_ = new TypedLinkedList(new SwitchBlockStmtGroup_Cast());
00047 private final LinkedList _switchLabel_ = new TypedLinkedList(new SwitchLabel_Cast());
00048 private TRBrace _rBrace_;
00049
00050 private class SwitchBlockStmtGroup_Cast implements Cast
00051 {
00052 public Object cast(Object o)
00053 {
00054 PSwitchBlockStmtGroup node = (PSwitchBlockStmtGroup) o;
00055
00056 if((node.parent() != null) &&
00057 (node.parent() != AOneSwitchStmt.this))
00058 {
00059 node.parent().removeChild(node);
00060 }
00061
00062 if((node.parent() == null) ||
00063 (node.parent() != AOneSwitchStmt.this))
00064 {
00065 node.parent(AOneSwitchStmt.this);
00066 }
00067
00068 return node;
00069 }
00070 }
00071
00072 private class SwitchLabel_Cast implements Cast
00073 {
00074 public Object cast(Object o)
00075 {
00076 PSwitchLabel node = (PSwitchLabel) o;
00077
00078 if((node.parent() != null) &&
00079 (node.parent() != AOneSwitchStmt.this))
00080 {
00081 node.parent().removeChild(node);
00082 }
00083
00084 if((node.parent() == null) ||
00085 (node.parent() != AOneSwitchStmt.this))
00086 {
00087 node.parent(AOneSwitchStmt.this);
00088 }
00089
00090 return node;
00091 }
00092 }
00093 public AOneSwitchStmt()
00094 {
00095 }
00096 public AOneSwitchStmt(
00097 TSwitch _switch_,
00098 TLPar _lPar_,
00099 PExp _exp_,
00100 TRPar _rPar_,
00101 TLBrace _lBrace_,
00102 List _switchBlockStmtGroup_,
00103 List _switchLabel_,
00104 TRBrace _rBrace_)
00105 {
00106 setSwitch(_switch_);
00107
00108 setLPar(_lPar_);
00109
00110 setExp(_exp_);
00111
00112 setRPar(_rPar_);
00113
00114 setLBrace(_lBrace_);
00115
00116 {
00117 Object temp[] = _switchBlockStmtGroup_.toArray();
00118 for(int i = 0; i < temp.length; i++)
00119 {
00120 this._switchBlockStmtGroup_.add(temp[i]);
00121 }
00122 }
00123
00124 {
00125 Object temp[] = _switchLabel_.toArray();
00126 for(int i = 0; i < temp.length; i++)
00127 {
00128 this._switchLabel_.add(temp[i]);
00129 }
00130 }
00131
00132 setRBrace(_rBrace_);
00133
00134 }
00135 public AOneSwitchStmt(
00136 TSwitch _switch_,
00137 TLPar _lPar_,
00138 PExp _exp_,
00139 TRPar _rPar_,
00140 TLBrace _lBrace_,
00141 XPSwitchBlockStmtGroup _switchBlockStmtGroup_,
00142 XPSwitchLabel _switchLabel_,
00143 TRBrace _rBrace_)
00144 {
00145 setSwitch(_switch_);
00146
00147 setLPar(_lPar_);
00148
00149 setExp(_exp_);
00150
00151 setRPar(_rPar_);
00152
00153 setLBrace(_lBrace_);
00154
00155 if(_switchBlockStmtGroup_ != null)
00156 {
00157 while(_switchBlockStmtGroup_ instanceof X1PSwitchBlockStmtGroup)
00158 {
00159 this._switchBlockStmtGroup_.addFirst(((X1PSwitchBlockStmtGroup) _switchBlockStmtGroup_).getPSwitchBlockStmtGroup());
00160 _switchBlockStmtGroup_ = ((X1PSwitchBlockStmtGroup) _switchBlockStmtGroup_).getXPSwitchBlockStmtGroup();
00161 }
00162 this._switchBlockStmtGroup_.addFirst(((X2PSwitchBlockStmtGroup) _switchBlockStmtGroup_).getPSwitchBlockStmtGroup());
00163 }
00164
00165 if(_switchLabel_ != null)
00166 {
00167 while(_switchLabel_ instanceof X1PSwitchLabel)
00168 {
00169 this._switchLabel_.addFirst(((X1PSwitchLabel) _switchLabel_).getPSwitchLabel());
00170 _switchLabel_ = ((X1PSwitchLabel) _switchLabel_).getXPSwitchLabel();
00171 }
00172 this._switchLabel_.addFirst(((X2PSwitchLabel) _switchLabel_).getPSwitchLabel());
00173 }
00174
00175 setRBrace(_rBrace_);
00176
00177 }
00178 public void apply(Switch sw)
00179 {
00180 ((Analysis) sw).caseAOneSwitchStmt(this);
00181 }
00182 public Object clone()
00183 {
00184 return new AOneSwitchStmt(
00185 (TSwitch) cloneNode(_switch_),
00186 (TLPar) cloneNode(_lPar_),
00187 (PExp) cloneNode(_exp_),
00188 (TRPar) cloneNode(_rPar_),
00189 (TLBrace) cloneNode(_lBrace_),
00190 cloneList(_switchBlockStmtGroup_),
00191 cloneList(_switchLabel_),
00192 (TRBrace) cloneNode(_rBrace_));
00193 }
00194 public PExp getExp()
00195 {
00196 return _exp_;
00197 }
00198 public TLBrace getLBrace()
00199 {
00200 return _lBrace_;
00201 }
00202 public TLPar getLPar()
00203 {
00204 return _lPar_;
00205 }
00206 public TRBrace getRBrace()
00207 {
00208 return _rBrace_;
00209 }
00210 public TRPar getRPar()
00211 {
00212 return _rPar_;
00213 }
00214 public TSwitch getSwitch()
00215 {
00216 return _switch_;
00217 }
00218 public LinkedList getSwitchBlockStmtGroup()
00219 {
00220 return _switchBlockStmtGroup_;
00221 }
00222 public LinkedList getSwitchLabel()
00223 {
00224 return _switchLabel_;
00225 }
00226 void removeChild(Node child)
00227 {
00228 if(_switch_ == child)
00229 {
00230 _switch_ = null;
00231 return;
00232 }
00233
00234 if(_lPar_ == child)
00235 {
00236 _lPar_ = null;
00237 return;
00238 }
00239
00240 if(_exp_ == child)
00241 {
00242 _exp_ = null;
00243 return;
00244 }
00245
00246 if(_rPar_ == child)
00247 {
00248 _rPar_ = null;
00249 return;
00250 }
00251
00252 if(_lBrace_ == child)
00253 {
00254 _lBrace_ = null;
00255 return;
00256 }
00257
00258 if(_switchBlockStmtGroup_.remove(child))
00259 {
00260 return;
00261 }
00262
00263 if(_switchLabel_.remove(child))
00264 {
00265 return;
00266 }
00267
00268 if(_rBrace_ == child)
00269 {
00270 _rBrace_ = null;
00271 return;
00272 }
00273
00274 }
00275 void replaceChild(Node oldChild, Node newChild)
00276 {
00277 if(_switch_ == oldChild)
00278 {
00279 setSwitch((TSwitch) newChild);
00280 return;
00281 }
00282
00283 if(_lPar_ == oldChild)
00284 {
00285 setLPar((TLPar) newChild);
00286 return;
00287 }
00288
00289 if(_exp_ == oldChild)
00290 {
00291 setExp((PExp) newChild);
00292 return;
00293 }
00294
00295 if(_rPar_ == oldChild)
00296 {
00297 setRPar((TRPar) newChild);
00298 return;
00299 }
00300
00301 if(_lBrace_ == oldChild)
00302 {
00303 setLBrace((TLBrace) newChild);
00304 return;
00305 }
00306
00307 for(ListIterator i = _switchBlockStmtGroup_.listIterator(); i.hasNext();)
00308 {
00309 if(i.next() == oldChild)
00310 {
00311 if(newChild != null)
00312 {
00313 i.set(newChild);
00314 oldChild.parent(null);
00315 return;
00316 }
00317
00318 i.remove();
00319 oldChild.parent(null);
00320 return;
00321 }
00322 }
00323
00324 for(ListIterator i = _switchLabel_.listIterator(); i.hasNext();)
00325 {
00326 if(i.next() == oldChild)
00327 {
00328 if(newChild != null)
00329 {
00330 i.set(newChild);
00331 oldChild.parent(null);
00332 return;
00333 }
00334
00335 i.remove();
00336 oldChild.parent(null);
00337 return;
00338 }
00339 }
00340
00341 if(_rBrace_ == oldChild)
00342 {
00343 setRBrace((TRBrace) newChild);
00344 return;
00345 }
00346
00347 }
00348 public void setExp(PExp node)
00349 {
00350 if(_exp_ != null)
00351 {
00352 _exp_.parent(null);
00353 }
00354
00355 if(node != null)
00356 {
00357 if(node.parent() != null)
00358 {
00359 node.parent().removeChild(node);
00360 }
00361
00362 node.parent(this);
00363 }
00364
00365 _exp_ = node;
00366 }
00367 public void setLBrace(TLBrace node)
00368 {
00369 if(_lBrace_ != null)
00370 {
00371 _lBrace_.parent(null);
00372 }
00373
00374 if(node != null)
00375 {
00376 if(node.parent() != null)
00377 {
00378 node.parent().removeChild(node);
00379 }
00380
00381 node.parent(this);
00382 }
00383
00384 _lBrace_ = node;
00385 }
00386 public void setLPar(TLPar node)
00387 {
00388 if(_lPar_ != null)
00389 {
00390 _lPar_.parent(null);
00391 }
00392
00393 if(node != null)
00394 {
00395 if(node.parent() != null)
00396 {
00397 node.parent().removeChild(node);
00398 }
00399
00400 node.parent(this);
00401 }
00402
00403 _lPar_ = node;
00404 }
00405 public void setRBrace(TRBrace node)
00406 {
00407 if(_rBrace_ != null)
00408 {
00409 _rBrace_.parent(null);
00410 }
00411
00412 if(node != null)
00413 {
00414 if(node.parent() != null)
00415 {
00416 node.parent().removeChild(node);
00417 }
00418
00419 node.parent(this);
00420 }
00421
00422 _rBrace_ = node;
00423 }
00424 public void setRPar(TRPar node)
00425 {
00426 if(_rPar_ != null)
00427 {
00428 _rPar_.parent(null);
00429 }
00430
00431 if(node != null)
00432 {
00433 if(node.parent() != null)
00434 {
00435 node.parent().removeChild(node);
00436 }
00437
00438 node.parent(this);
00439 }
00440
00441 _rPar_ = node;
00442 }
00443 public void setSwitch(TSwitch node)
00444 {
00445 if(_switch_ != null)
00446 {
00447 _switch_.parent(null);
00448 }
00449
00450 if(node != null)
00451 {
00452 if(node.parent() != null)
00453 {
00454 node.parent().removeChild(node);
00455 }
00456
00457 node.parent(this);
00458 }
00459
00460 _switch_ = node;
00461 }
00462 public void setSwitchBlockStmtGroup(List list)
00463 {
00464 Object temp[] = list.toArray();
00465 for(int i = 0; i < temp.length; i++)
00466 {
00467 _switchBlockStmtGroup_.add(temp[i]);
00468 }
00469 }
00470 public void setSwitchLabel(List list)
00471 {
00472 Object temp[] = list.toArray();
00473 for(int i = 0; i < temp.length; i++)
00474 {
00475 _switchLabel_.add(temp[i]);
00476 }
00477 }
00478 public String toString()
00479 {
00480 return ""
00481 + toString(_switch_)
00482 + toString(_lPar_)
00483 + toString(_exp_)
00484 + toString(_rPar_)
00485 + toString(_lBrace_)
00486 + toString(_switchBlockStmtGroup_)
00487 + toString(_switchLabel_)
00488 + toString(_rBrace_);
00489 }
00490 }