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

ASwitchBlockStmtGroup.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 ASwitchBlockStmtGroup extends PSwitchBlockStmtGroup
00040 {
00041     private final LinkedList _switchLabel_ = new TypedLinkedList(new SwitchLabel_Cast());
00042     private final LinkedList _blockedStmt_ = new TypedLinkedList(new BlockedStmt_Cast());
00043 
00044     private class SwitchLabel_Cast implements Cast
00045     {
00046         public Object cast(Object o)
00047         {
00048             PSwitchLabel node = (PSwitchLabel) o;
00049 
00050             if((node.parent() != null) &&
00051                 (node.parent() != ASwitchBlockStmtGroup.this))
00052             {
00053                 node.parent().removeChild(node);
00054             }
00055 
00056             if((node.parent() == null) ||
00057                 (node.parent() != ASwitchBlockStmtGroup.this))
00058             {
00059                 node.parent(ASwitchBlockStmtGroup.this);
00060             }
00061 
00062             return node;
00063         }
00064     }
00065 
00066     private class BlockedStmt_Cast implements Cast
00067     {
00068         public Object cast(Object o)
00069         {
00070             PBlockedStmt node = (PBlockedStmt) o;
00071 
00072             if((node.parent() != null) &&
00073                 (node.parent() != ASwitchBlockStmtGroup.this))
00074             {
00075                 node.parent().removeChild(node);
00076             }
00077 
00078             if((node.parent() == null) ||
00079                 (node.parent() != ASwitchBlockStmtGroup.this))
00080             {
00081                 node.parent(ASwitchBlockStmtGroup.this);
00082             }
00083 
00084             return node;
00085         }
00086     }
00087     public ASwitchBlockStmtGroup()
00088     {
00089     }
00090     public ASwitchBlockStmtGroup(
00091         List _switchLabel_,
00092         List _blockedStmt_)
00093     {
00094         {
00095             Object temp[] = _switchLabel_.toArray();
00096             for(int i = 0; i < temp.length; i++)
00097             {
00098                 this._switchLabel_.add(temp[i]);
00099             }
00100         }
00101 
00102         {
00103             Object temp[] = _blockedStmt_.toArray();
00104             for(int i = 0; i < temp.length; i++)
00105             {
00106                 this._blockedStmt_.add(temp[i]);
00107             }
00108         }
00109 
00110     }
00111     public ASwitchBlockStmtGroup(
00112         XPSwitchLabel _switchLabel_,
00113         XPBlockedStmt _blockedStmt_)
00114     {
00115         if(_switchLabel_ != null)
00116         {
00117             while(_switchLabel_ instanceof X1PSwitchLabel)
00118             {
00119                 this._switchLabel_.addFirst(((X1PSwitchLabel) _switchLabel_).getPSwitchLabel());
00120                 _switchLabel_ = ((X1PSwitchLabel) _switchLabel_).getXPSwitchLabel();
00121             }
00122             this._switchLabel_.addFirst(((X2PSwitchLabel) _switchLabel_).getPSwitchLabel());
00123         }
00124 
00125         if(_blockedStmt_ != null)
00126         {
00127             while(_blockedStmt_ instanceof X1PBlockedStmt)
00128             {
00129                 this._blockedStmt_.addFirst(((X1PBlockedStmt) _blockedStmt_).getPBlockedStmt());
00130                 _blockedStmt_ = ((X1PBlockedStmt) _blockedStmt_).getXPBlockedStmt();
00131             }
00132             this._blockedStmt_.addFirst(((X2PBlockedStmt) _blockedStmt_).getPBlockedStmt());
00133         }
00134 
00135     }
00136     public void apply(Switch sw)
00137     {
00138         ((Analysis) sw).caseASwitchBlockStmtGroup(this);
00139     }
00140     public Object clone()
00141     {
00142         return new ASwitchBlockStmtGroup(
00143             cloneList(_switchLabel_),
00144             cloneList(_blockedStmt_));
00145     }
00146     public LinkedList getBlockedStmt()
00147     {
00148         return _blockedStmt_;
00149     }
00150     public LinkedList getSwitchLabel()
00151     {
00152         return _switchLabel_;
00153     }
00154     void removeChild(Node child)
00155     {
00156         if(_switchLabel_.remove(child))
00157         {
00158             return;
00159         }
00160 
00161         if(_blockedStmt_.remove(child))
00162         {
00163             return;
00164         }
00165 
00166     }
00167     void replaceChild(Node oldChild, Node newChild)
00168     {
00169         for(ListIterator i = _switchLabel_.listIterator(); i.hasNext();)
00170         {
00171             if(i.next() == oldChild)
00172             {
00173                 if(newChild != null)
00174                 {
00175                     i.set(newChild);
00176                     oldChild.parent(null);
00177                     return;
00178                 }
00179 
00180                 i.remove();
00181                 oldChild.parent(null);
00182                 return;
00183             }
00184         }
00185 
00186         for(ListIterator i = _blockedStmt_.listIterator(); i.hasNext();)
00187         {
00188             if(i.next() == oldChild)
00189             {
00190                 if(newChild != null)
00191                 {
00192                     i.set(newChild);
00193                     oldChild.parent(null);
00194                     return;
00195                 }
00196 
00197                 i.remove();
00198                 oldChild.parent(null);
00199                 return;
00200             }
00201         }
00202 
00203     }
00204     public void setBlockedStmt(List list)
00205     {
00206         Object temp[] = list.toArray();
00207         for(int i = 0; i < temp.length; i++)
00208         {
00209             _blockedStmt_.add(temp[i]);
00210         }
00211     }
00212     public void setSwitchLabel(List list)
00213     {
00214         Object temp[] = list.toArray();
00215         for(int i = 0; i < temp.length; i++)
00216         {
00217             _switchLabel_.add(temp[i]);
00218         }
00219     }
00220     public String toString()
00221     {
00222         return ""
00223             + toString(_switchLabel_)
00224             + toString(_blockedStmt_);
00225     }
00226 }

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