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

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

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