Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

AForStmt.java

00001 package edu.ksu.cis.bandera.jjjc.node;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1998-2001 SAnToS Laboratories (santos@cis.ksu.edu)  *
00006 
00007  * All rights reserved.                                              *
00008  *                                                                   *
00009  * This work was done as a project in the SAnToS Laboratory,         *
00010  * Department of Computing and Information Sciences, Kansas State    *
00011  * University, USA (http://www.cis.ksu.edu/santos).                  *
00012  * It is understood that any modification not identified as such is  *
00013  * not covered by the preceding statement.                           *
00014  *                                                                   *
00015  * This work is free software; you can redistribute it and/or        *
00016  * modify it under the terms of the GNU Library General Public       *
00017  * License as published by the Free Software Foundation; either      *
00018  * version 2 of the License, or (at your option) any later version.  *
00019  *                                                                   *
00020  * This work is distributed in the hope that it will be useful,      *
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00023  * Library General Public License for more details.                  *
00024  *                                                                   *
00025  * You should have received a copy of the GNU Library General Public *
00026  * License along with this toolkit; if not, write to the             *
00027  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00028  * Boston, MA  02111-1307, USA.                                      *
00029  *                                                                   *
00030  * Java is a trademark of Sun Microsystems, Inc.                     *
00031  *                                                                   *
00032  * To submit a bug report, send a comment, or get the latest news on *
00033  * this project and other SAnToS projects, please visit the web-site *
00034  *                http://www.cis.ksu.edu/santos                      *
00035  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00036 import ca.mcgill.sable.util.*;
00037 import edu.ksu.cis.bandera.jjjc.analysis.*;
00038 
00039 public final class AForStmt extends PStmt
00040 {
00041     private TFor _for_;
00042     private TLPar _lPar_;
00043     private PForInit _forInit_;
00044     private TSemicolon _semicolon1_;
00045     private PExp _exp_;
00046     private TSemicolon _semicolon2_;
00047     private final LinkedList _forUpdate_ = new TypedLinkedList(new ForUpdate_Cast());
00048     private TRPar _rPar_;
00049     private PBlock _block_;
00050 
00051     private class ForUpdate_Cast implements Cast
00052     {
00053         public Object cast(Object o)
00054         {
00055             PExp node = (PExp) o;
00056 
00057             if((node.parent() != null) &&
00058                 (node.parent() != AForStmt.this))
00059             {
00060                 node.parent().removeChild(node);
00061             }
00062 
00063             if((node.parent() == null) ||
00064                 (node.parent() != AForStmt.this))
00065             {
00066                 node.parent(AForStmt.this);
00067             }
00068 
00069             return node;
00070         }
00071     }
00072     public AForStmt()
00073     {
00074     }
00075     public AForStmt(
00076         TFor _for_,
00077         TLPar _lPar_,
00078         PForInit _forInit_,
00079         TSemicolon _semicolon1_,
00080         PExp _exp_,
00081         TSemicolon _semicolon2_,
00082         List _forUpdate_,
00083         TRPar _rPar_,
00084         PBlock _block_)
00085     {
00086         setFor(_for_);
00087 
00088         setLPar(_lPar_);
00089 
00090         setForInit(_forInit_);
00091 
00092         setSemicolon1(_semicolon1_);
00093 
00094         setExp(_exp_);
00095 
00096         setSemicolon2(_semicolon2_);
00097 
00098         {
00099             Object temp[] = _forUpdate_.toArray();
00100             for(int i = 0; i < temp.length; i++)
00101             {
00102                 this._forUpdate_.add(temp[i]);
00103             }
00104         }
00105 
00106         setRPar(_rPar_);
00107 
00108         setBlock(_block_);
00109 
00110     }
00111     public AForStmt(
00112         TFor _for_,
00113         TLPar _lPar_,
00114         PForInit _forInit_,
00115         TSemicolon _semicolon1_,
00116         PExp _exp_,
00117         TSemicolon _semicolon2_,
00118         XPExp _forUpdate_,
00119         TRPar _rPar_,
00120         PBlock _block_)
00121     {
00122         setFor(_for_);
00123 
00124         setLPar(_lPar_);
00125 
00126         setForInit(_forInit_);
00127 
00128         setSemicolon1(_semicolon1_);
00129 
00130         setExp(_exp_);
00131 
00132         setSemicolon2(_semicolon2_);
00133 
00134         if(_forUpdate_ != null)
00135         {
00136             while(_forUpdate_ instanceof X1PExp)
00137             {
00138                 this._forUpdate_.addFirst(((X1PExp) _forUpdate_).getPExp());
00139                 _forUpdate_ = ((X1PExp) _forUpdate_).getXPExp();
00140             }
00141             this._forUpdate_.addFirst(((X2PExp) _forUpdate_).getPExp());
00142         }
00143 
00144         setRPar(_rPar_);
00145 
00146         setBlock(_block_);
00147 
00148     }
00149     public void apply(Switch sw)
00150     {
00151         ((Analysis) sw).caseAForStmt(this);
00152     }
00153     public Object clone()
00154     {
00155         return new AForStmt(
00156             (TFor) cloneNode(_for_),
00157             (TLPar) cloneNode(_lPar_),
00158             (PForInit) cloneNode(_forInit_),
00159             (TSemicolon) cloneNode(_semicolon1_),
00160             (PExp) cloneNode(_exp_),
00161             (TSemicolon) cloneNode(_semicolon2_),
00162             cloneList(_forUpdate_),
00163             (TRPar) cloneNode(_rPar_),
00164             (PBlock) cloneNode(_block_));
00165     }
00166     public PBlock getBlock()
00167     {
00168         return _block_;
00169     }
00170     public PExp getExp()
00171     {
00172         return _exp_;
00173     }
00174     public TFor getFor()
00175     {
00176         return _for_;
00177     }
00178     public PForInit getForInit()
00179     {
00180         return _forInit_;
00181     }
00182     public LinkedList getForUpdate()
00183     {
00184         return _forUpdate_;
00185     }
00186     public TLPar getLPar()
00187     {
00188         return _lPar_;
00189     }
00190     public TRPar getRPar()
00191     {
00192         return _rPar_;
00193     }
00194     public TSemicolon getSemicolon1()
00195     {
00196         return _semicolon1_;
00197     }
00198     public TSemicolon getSemicolon2()
00199     {
00200         return _semicolon2_;
00201     }
00202     void removeChild(Node child)
00203     {
00204         if(_for_ == child)
00205         {
00206             _for_ = null;
00207             return;
00208         }
00209 
00210         if(_lPar_ == child)
00211         {
00212             _lPar_ = null;
00213             return;
00214         }
00215 
00216         if(_forInit_ == child)
00217         {
00218             _forInit_ = null;
00219             return;
00220         }
00221 
00222         if(_semicolon1_ == child)
00223         {
00224             _semicolon1_ = null;
00225             return;
00226         }
00227 
00228         if(_exp_ == child)
00229         {
00230             _exp_ = null;
00231             return;
00232         }
00233 
00234         if(_semicolon2_ == child)
00235         {
00236             _semicolon2_ = null;
00237             return;
00238         }
00239 
00240         if(_forUpdate_.remove(child))
00241         {
00242             return;
00243         }
00244 
00245         if(_rPar_ == child)
00246         {
00247             _rPar_ = null;
00248             return;
00249         }
00250 
00251         if(_block_ == child)
00252         {
00253             _block_ = null;
00254             return;
00255         }
00256 
00257     }
00258     void replaceChild(Node oldChild, Node newChild)
00259     {
00260         if(_for_ == oldChild)
00261         {
00262             setFor((TFor) newChild);
00263             return;
00264         }
00265 
00266         if(_lPar_ == oldChild)
00267         {
00268             setLPar((TLPar) newChild);
00269             return;
00270         }
00271 
00272         if(_forInit_ == oldChild)
00273         {
00274             setForInit((PForInit) newChild);
00275             return;
00276         }
00277 
00278         if(_semicolon1_ == oldChild)
00279         {
00280             setSemicolon1((TSemicolon) newChild);
00281             return;
00282         }
00283 
00284         if(_exp_ == oldChild)
00285         {
00286             setExp((PExp) newChild);
00287             return;
00288         }
00289 
00290         if(_semicolon2_ == oldChild)
00291         {
00292             setSemicolon2((TSemicolon) newChild);
00293             return;
00294         }
00295 
00296         for(ListIterator i = _forUpdate_.listIterator(); i.hasNext();)
00297         {
00298             if(i.next() == oldChild)
00299             {
00300                 if(newChild != null)
00301                 {
00302                     i.set(newChild);
00303                     oldChild.parent(null);
00304                     return;
00305                 }
00306 
00307                 i.remove();
00308                 oldChild.parent(null);
00309                 return;
00310             }
00311         }
00312 
00313         if(_rPar_ == oldChild)
00314         {
00315             setRPar((TRPar) newChild);
00316             return;
00317         }
00318 
00319         if(_block_ == oldChild)
00320         {
00321             setBlock((PBlock) newChild);
00322             return;
00323         }
00324 
00325     }
00326     public void setBlock(PBlock node)
00327     {
00328         if(_block_ != null)
00329         {
00330             _block_.parent(null);
00331         }
00332 
00333         if(node != null)
00334         {
00335             if(node.parent() != null)
00336             {
00337                 node.parent().removeChild(node);
00338             }
00339 
00340             node.parent(this);
00341         }
00342 
00343         _block_ = node;
00344     }
00345     public void setExp(PExp node)
00346     {
00347         if(_exp_ != null)
00348         {
00349             _exp_.parent(null);
00350         }
00351 
00352         if(node != null)
00353         {
00354             if(node.parent() != null)
00355             {
00356                 node.parent().removeChild(node);
00357             }
00358 
00359             node.parent(this);
00360         }
00361 
00362         _exp_ = node;
00363     }
00364     public void setFor(TFor node)
00365     {
00366         if(_for_ != null)
00367         {
00368             _for_.parent(null);
00369         }
00370 
00371         if(node != null)
00372         {
00373             if(node.parent() != null)
00374             {
00375                 node.parent().removeChild(node);
00376             }
00377 
00378             node.parent(this);
00379         }
00380 
00381         _for_ = node;
00382     }
00383     public void setForInit(PForInit node)
00384     {
00385         if(_forInit_ != null)
00386         {
00387             _forInit_.parent(null);
00388         }
00389 
00390         if(node != null)
00391         {
00392             if(node.parent() != null)
00393             {
00394                 node.parent().removeChild(node);
00395             }
00396 
00397             node.parent(this);
00398         }
00399 
00400         _forInit_ = node;
00401     }
00402     public void setForUpdate(List list)
00403     {
00404         Object temp[] = list.toArray();
00405         for(int i = 0; i < temp.length; i++)
00406         {
00407             _forUpdate_.add(temp[i]);
00408         }
00409     }
00410     public void setLPar(TLPar node)
00411     {
00412         if(_lPar_ != null)
00413         {
00414             _lPar_.parent(null);
00415         }
00416 
00417         if(node != null)
00418         {
00419             if(node.parent() != null)
00420             {
00421                 node.parent().removeChild(node);
00422             }
00423 
00424             node.parent(this);
00425         }
00426 
00427         _lPar_ = node;
00428     }
00429     public void setRPar(TRPar node)
00430     {
00431         if(_rPar_ != null)
00432         {
00433             _rPar_.parent(null);
00434         }
00435 
00436         if(node != null)
00437         {
00438             if(node.parent() != null)
00439             {
00440                 node.parent().removeChild(node);
00441             }
00442 
00443             node.parent(this);
00444         }
00445 
00446         _rPar_ = node;
00447     }
00448     public void setSemicolon1(TSemicolon node)
00449     {
00450         if(_semicolon1_ != null)
00451         {
00452             _semicolon1_.parent(null);
00453         }
00454 
00455         if(node != null)
00456         {
00457             if(node.parent() != null)
00458             {
00459                 node.parent().removeChild(node);
00460             }
00461 
00462             node.parent(this);
00463         }
00464 
00465         _semicolon1_ = node;
00466     }
00467     public void setSemicolon2(TSemicolon node)
00468     {
00469         if(_semicolon2_ != null)
00470         {
00471             _semicolon2_.parent(null);
00472         }
00473 
00474         if(node != null)
00475         {
00476             if(node.parent() != null)
00477             {
00478                 node.parent().removeChild(node);
00479             }
00480 
00481             node.parent(this);
00482         }
00483 
00484         _semicolon2_ = node;
00485     }
00486     public String toString()
00487     {
00488         return ""
00489             + toString(_for_)
00490             + toString(_lPar_)
00491             + toString(_forInit_)
00492             + toString(_semicolon1_)
00493             + toString(_exp_)
00494             + toString(_semicolon2_)
00495             + toString(_forUpdate_)
00496             + toString(_rPar_)
00497             + toString(_block_);
00498     }
00499 }

Generated at Thu Feb 7 06:37:24 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001