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

AChoice.java

00001 package edu.ksu.cis.bandera.birp.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.birp.analysis.*;
00038 
00039 public final class AChoice extends PChoice
00040 {
00041     private PLhs _lhs_;
00042     private TAssign _assign_;
00043     private TChoose _choose_;
00044     private TLparen _lparen_;
00045     private PValue _value_;
00046     private final LinkedList _rest_ = new TypedLinkedList(new Rest_Cast());
00047     private TRparen _rparen_;
00048     private TSemicolon _semicolon_;
00049 
00050     private class Rest_Cast implements Cast
00051     {
00052         public Object cast(Object o)
00053         {
00054             PChoicetail node = (PChoicetail) o;
00055 
00056             if((node.parent() != null) &&
00057                 (node.parent() != AChoice.this))
00058             {
00059                 node.parent().removeChild(node);
00060             }
00061 
00062             if((node.parent() == null) ||
00063                 (node.parent() != AChoice.this))
00064             {
00065                 node.parent(AChoice.this);
00066             }
00067 
00068             return node;
00069         }
00070     }
00071     public AChoice()
00072     {
00073     }
00074     public AChoice(
00075         PLhs _lhs_,
00076         TAssign _assign_,
00077         TChoose _choose_,
00078         TLparen _lparen_,
00079         PValue _value_,
00080         List _rest_,
00081         TRparen _rparen_,
00082         TSemicolon _semicolon_)
00083     {
00084         setLhs(_lhs_);
00085 
00086         setAssign(_assign_);
00087 
00088         setChoose(_choose_);
00089 
00090         setLparen(_lparen_);
00091 
00092         setValue(_value_);
00093 
00094         {
00095             Object temp[] = _rest_.toArray();
00096             for(int i = 0; i < temp.length; i++)
00097             {
00098                 this._rest_.add(temp[i]);
00099             }
00100         }
00101 
00102         setRparen(_rparen_);
00103 
00104         setSemicolon(_semicolon_);
00105 
00106     }
00107     public AChoice(
00108         PLhs _lhs_,
00109         TAssign _assign_,
00110         TChoose _choose_,
00111         TLparen _lparen_,
00112         PValue _value_,
00113         XPChoicetail _rest_,
00114         TRparen _rparen_,
00115         TSemicolon _semicolon_)
00116     {
00117         setLhs(_lhs_);
00118 
00119         setAssign(_assign_);
00120 
00121         setChoose(_choose_);
00122 
00123         setLparen(_lparen_);
00124 
00125         setValue(_value_);
00126 
00127         if(_rest_ != null)
00128         {
00129             while(_rest_ instanceof X1PChoicetail)
00130             {
00131                 this._rest_.addFirst(((X1PChoicetail) _rest_).getPChoicetail());
00132                 _rest_ = ((X1PChoicetail) _rest_).getXPChoicetail();
00133             }
00134             this._rest_.addFirst(((X2PChoicetail) _rest_).getPChoicetail());
00135         }
00136 
00137         setRparen(_rparen_);
00138 
00139         setSemicolon(_semicolon_);
00140 
00141     }
00142     public void apply(Switch sw)
00143     {
00144         ((Analysis) sw).caseAChoice(this);
00145     }
00146     public Object clone()
00147     {
00148         return new AChoice(
00149             (PLhs) cloneNode(_lhs_),
00150             (TAssign) cloneNode(_assign_),
00151             (TChoose) cloneNode(_choose_),
00152             (TLparen) cloneNode(_lparen_),
00153             (PValue) cloneNode(_value_),
00154             cloneList(_rest_),
00155             (TRparen) cloneNode(_rparen_),
00156             (TSemicolon) cloneNode(_semicolon_));
00157     }
00158     public TAssign getAssign()
00159     {
00160         return _assign_;
00161     }
00162     public TChoose getChoose()
00163     {
00164         return _choose_;
00165     }
00166     public PLhs getLhs()
00167     {
00168         return _lhs_;
00169     }
00170     public TLparen getLparen()
00171     {
00172         return _lparen_;
00173     }
00174     public LinkedList getRest()
00175     {
00176         return _rest_;
00177     }
00178     public TRparen getRparen()
00179     {
00180         return _rparen_;
00181     }
00182     public TSemicolon getSemicolon()
00183     {
00184         return _semicolon_;
00185     }
00186     public PValue getValue()
00187     {
00188         return _value_;
00189     }
00190     void removeChild(Node child)
00191     {
00192         if(_lhs_ == child)
00193         {
00194             _lhs_ = null;
00195             return;
00196         }
00197 
00198         if(_assign_ == child)
00199         {
00200             _assign_ = null;
00201             return;
00202         }
00203 
00204         if(_choose_ == child)
00205         {
00206             _choose_ = null;
00207             return;
00208         }
00209 
00210         if(_lparen_ == child)
00211         {
00212             _lparen_ = null;
00213             return;
00214         }
00215 
00216         if(_value_ == child)
00217         {
00218             _value_ = null;
00219             return;
00220         }
00221 
00222         if(_rest_.remove(child))
00223         {
00224             return;
00225         }
00226 
00227         if(_rparen_ == child)
00228         {
00229             _rparen_ = null;
00230             return;
00231         }
00232 
00233         if(_semicolon_ == child)
00234         {
00235             _semicolon_ = null;
00236             return;
00237         }
00238 
00239     }
00240     void replaceChild(Node oldChild, Node newChild)
00241     {
00242         if(_lhs_ == oldChild)
00243         {
00244             setLhs((PLhs) newChild);
00245             return;
00246         }
00247 
00248         if(_assign_ == oldChild)
00249         {
00250             setAssign((TAssign) newChild);
00251             return;
00252         }
00253 
00254         if(_choose_ == oldChild)
00255         {
00256             setChoose((TChoose) newChild);
00257             return;
00258         }
00259 
00260         if(_lparen_ == oldChild)
00261         {
00262             setLparen((TLparen) newChild);
00263             return;
00264         }
00265 
00266         if(_value_ == oldChild)
00267         {
00268             setValue((PValue) newChild);
00269             return;
00270         }
00271 
00272         for(ListIterator i = _rest_.listIterator(); i.hasNext();)
00273         {
00274             if(i.next() == oldChild)
00275             {
00276                 if(newChild != null)
00277                 {
00278                     i.set(newChild);
00279                     oldChild.parent(null);
00280                     return;
00281                 }
00282 
00283                 i.remove();
00284                 oldChild.parent(null);
00285                 return;
00286             }
00287         }
00288 
00289         if(_rparen_ == oldChild)
00290         {
00291             setRparen((TRparen) newChild);
00292             return;
00293         }
00294 
00295         if(_semicolon_ == oldChild)
00296         {
00297             setSemicolon((TSemicolon) newChild);
00298             return;
00299         }
00300 
00301     }
00302     public void setAssign(TAssign node)
00303     {
00304         if(_assign_ != null)
00305         {
00306             _assign_.parent(null);
00307         }
00308 
00309         if(node != null)
00310         {
00311             if(node.parent() != null)
00312             {
00313                 node.parent().removeChild(node);
00314             }
00315 
00316             node.parent(this);
00317         }
00318 
00319         _assign_ = node;
00320     }
00321     public void setChoose(TChoose node)
00322     {
00323         if(_choose_ != null)
00324         {
00325             _choose_.parent(null);
00326         }
00327 
00328         if(node != null)
00329         {
00330             if(node.parent() != null)
00331             {
00332                 node.parent().removeChild(node);
00333             }
00334 
00335             node.parent(this);
00336         }
00337 
00338         _choose_ = node;
00339     }
00340     public void setLhs(PLhs node)
00341     {
00342         if(_lhs_ != null)
00343         {
00344             _lhs_.parent(null);
00345         }
00346 
00347         if(node != null)
00348         {
00349             if(node.parent() != null)
00350             {
00351                 node.parent().removeChild(node);
00352             }
00353 
00354             node.parent(this);
00355         }
00356 
00357         _lhs_ = node;
00358     }
00359     public void setLparen(TLparen node)
00360     {
00361         if(_lparen_ != null)
00362         {
00363             _lparen_.parent(null);
00364         }
00365 
00366         if(node != null)
00367         {
00368             if(node.parent() != null)
00369             {
00370                 node.parent().removeChild(node);
00371             }
00372 
00373             node.parent(this);
00374         }
00375 
00376         _lparen_ = node;
00377     }
00378     public void setRest(List list)
00379     {
00380         Object temp[] = list.toArray();
00381         for(int i = 0; i < temp.length; i++)
00382         {
00383             _rest_.add(temp[i]);
00384         }
00385     }
00386     public void setRparen(TRparen node)
00387     {
00388         if(_rparen_ != null)
00389         {
00390             _rparen_.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         _rparen_ = node;
00404     }
00405     public void setSemicolon(TSemicolon node)
00406     {
00407         if(_semicolon_ != null)
00408         {
00409             _semicolon_.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         _semicolon_ = node;
00423     }
00424     public void setValue(PValue node)
00425     {
00426         if(_value_ != null)
00427         {
00428             _value_.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         _value_ = node;
00442     }
00443     public String toString()
00444     {
00445         return ""
00446             + toString(_lhs_)
00447             + toString(_assign_)
00448             + toString(_choose_)
00449             + toString(_lparen_)
00450             + toString(_value_)
00451             + toString(_rest_)
00452             + toString(_rparen_)
00453             + toString(_semicolon_);
00454     }
00455 }

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