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

JimpleStmtCloner.java

00001 package edu.ksu.cis.bandera.jjjc.util;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1999, 2000   Robby (robby@cis.ksu.edu)              *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project in the SAnToS Laboratory,         *
00009  * Department of Computing and Information Sciences, Kansas State    *
00010  * University, USA (http://www.cis.ksu.edu/santos).                  *
00011  * It is understood that any modification not identified as such is  *
00012  * not covered by the preceding statement.                           *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this toolkit; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other SAnToS projects, please visit the web-site *
00033  *                http://www.cis.ksu.edu/santos                      *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 import ca.mcgill.sable.soot.*;
00036 import ca.mcgill.sable.soot.jimple.*;
00037 import ca.mcgill.sable.util.*;
00038 import java.util.*;
00039 import ca.mcgill.sable.util.Iterator;
00040 import ca.mcgill.sable.util.LinkedList;
00041 
00042 public class JimpleStmtCloner implements StmtSwitch {
00043     private static JimpleStmtCloner cloner = new JimpleStmtCloner();
00044     private static Jimple jimple = Jimple.v();
00045     private static Hashtable targets = new Hashtable();
00046     private static JimpleBody body;
00047     private Stmt result = null;
00048 /**
00049  * 
00050  */
00051 private JimpleStmtCloner() {
00052 }
00053 /**
00054  * caseAssignStmt method comment.
00055  */
00056 public void caseAssignStmt(AssignStmt stmt) {
00057     result = jimple.newAssignStmt(JimpleValueCloner.clone(stmt.getLeftOp()),
00058             JimpleValueCloner.clone(stmt.getRightOp()));
00059 }
00060 /**
00061  * caseBreakpointStmt method comment.
00062  */
00063 public void caseBreakpointStmt(BreakpointStmt stmt) {
00064     result = jimple.newBreakpointStmt();
00065 }
00066 /**
00067  * caseEnterMonitorStmt method comment.
00068  */
00069 public void caseEnterMonitorStmt(EnterMonitorStmt stmt) {
00070     result = jimple.newEnterMonitorStmt(JimpleValueCloner.clone(stmt.getOp()));
00071 }
00072 /**
00073  * caseExitMonitorStmt method comment.
00074  */
00075 public void caseExitMonitorStmt(ExitMonitorStmt stmt) {
00076     result = jimple.newExitMonitorStmt(JimpleValueCloner.clone(stmt.getOp()));
00077 }
00078 /**
00079  * caseGotoStmt method comment.
00080  */
00081 public void caseGotoStmt(GotoStmt stmt) {
00082     result = jimple.newGotoStmt(JimpleStmtCloner.clone((Stmt) stmt.getTarget()));
00083 }
00084 /**
00085  * caseIdentityStmt method comment.
00086  */
00087 public void caseIdentityStmt(IdentityStmt stmt) {
00088     result = jimple.newIdentityStmt(JimpleValueCloner.clone(stmt.getLeftOp()),
00089             JimpleValueCloner.clone(stmt.getRightOp()));
00090 }
00091 /**
00092  * caseIfStmt method comment.
00093  */
00094 public void caseIfStmt(IfStmt stmt) {
00095     result = jimple.newIfStmt(JimpleValueCloner.clone(stmt.getCondition()),
00096             JimpleStmtCloner.clone(stmt.getTarget()));
00097 }
00098 /**
00099  * caseInvokeStmt method comment.
00100  */
00101 public void caseInvokeStmt(InvokeStmt stmt) {
00102     result = jimple.newInvokeStmt(JimpleValueCloner.clone(stmt.getInvokeExpr()));
00103 }
00104 /**
00105  * caseLookupSwitchStmt method comment.
00106  */
00107 public void caseLookupSwitchStmt(LookupSwitchStmt stmt) {
00108     Stmt defaultTarget = JimpleStmtCloner.clone((Stmt) stmt.getDefaultTarget());
00109     LinkedList newTargets = new LinkedList();
00110     LinkedList newValues = new LinkedList();
00111 
00112     for (Iterator i = stmt.getTargets().iterator(); i.hasNext();) {
00113         newTargets.addLast(JimpleStmtCloner.clone((Stmt) i.next()));
00114     }
00115 
00116     for (Iterator i = stmt.getLookupValues().iterator(); i.hasNext();) {
00117         newValues.addLast(JimpleValueCloner.clone((Value) i.next()));
00118     }
00119 
00120     result = jimple.newLookupSwitchStmt(JimpleValueCloner.clone(stmt.getKey()), newValues,
00121                 newTargets, defaultTarget);
00122 }
00123 /**
00124  * caseNopStmt method comment.
00125  */
00126 public void caseNopStmt(NopStmt stmt) {
00127     result = jimple.newNopStmt();
00128 }
00129 /**
00130  * caseRetStmt method comment.
00131  */
00132 public void caseRetStmt(RetStmt stmt) {
00133     result = jimple.newRetStmt(JimpleValueCloner.clone(stmt.getStmtAddress()));
00134 }
00135 /**
00136  * caseReturnStmt method comment.
00137  */
00138 public void caseReturnStmt(ReturnStmt stmt) {
00139     result = jimple.newReturnStmt(JimpleValueCloner.clone(stmt.getReturnValue()));
00140 }
00141 /**
00142  * caseReturnVoidStmt method comment.
00143  */
00144 public void caseReturnVoidStmt(ReturnVoidStmt stmt) {
00145     result = jimple.newReturnVoidStmt();
00146 }
00147 /**
00148  * caseTableSwitchStmt method comment.
00149  */
00150 public void caseTableSwitchStmt(TableSwitchStmt stmt) {
00151     Stmt defaultTarget = JimpleStmtCloner.clone((Stmt) stmt.getDefaultTarget());
00152     LinkedList newTargets = new LinkedList();
00153 
00154     for (Iterator i = stmt.getTargets().iterator(); i.hasNext();) {
00155         newTargets.addLast(JimpleStmtCloner.clone((Stmt) i.next()));
00156     }
00157 
00158     result = jimple.newTableSwitchStmt(JimpleValueCloner.clone(stmt.getKey()), stmt.getLowIndex(),
00159                 stmt.getHighIndex(), newTargets, defaultTarget);
00160 }
00161 /**
00162  * caseThrowStmt method comment.
00163  */
00164 public void caseThrowStmt(ThrowStmt stmt) {
00165     result = jimple.newThrowStmt(JimpleValueCloner.clone(stmt.getOp()));
00166 }
00167 /**
00168  * 
00169  * @return ca.mcgill.sable.soot.jimple.Stmt
00170  * @param stmt ca.mcgill.sable.soot.jimple.Stmt
00171  */
00172 public static Stmt clone(Stmt stmt) {
00173     if (targets.get(stmt) != null) return (Stmt) targets.get(stmt);
00174     
00175     stmt.apply(cloner);
00176     Stmt result = cloner.getResult();
00177     targets.put(stmt, result);
00178     
00179     return result;
00180 }
00181 /**
00182  * 
00183  * @param body ca.mcgill.sable.soot.jimple.JimpleBody
00184  */
00185 public static void copyTrap(JimpleBody body) {
00186     for (Iterator i = body.getTraps().iterator(); i.hasNext();) {
00187         JTrap trap = (JTrap) i.next();
00188         Stmt begin = (Stmt) targets.get(trap.getBeginUnit());
00189         Stmt end = (Stmt) targets.get(trap.getEndUnit());
00190         Stmt handler = (Stmt) targets.get(trap.getHandlerUnit());
00191         if ((begin != null) && (end != null) && (handler != null)) {
00192             JimpleStmtCloner.body.addTrap(jimple.newTrap(trap.getException(), begin, end, handler));
00193         }
00194     }
00195 }
00196 /**
00197  * defaultCase method comment.
00198  */
00199 public void defaultCase(Object obj) {
00200     result = null;
00201 }
00202 /**
00203  * 
00204  * @return ca.mcgill.sable.soot.jimple.Stmt
00205  */
00206 private Stmt getResult() {
00207     return result;
00208 }
00209 /**
00210  * 
00211  */
00212 public static void reset() {
00213     targets = new Hashtable();
00214 }
00215 /**
00216  * 
00217  * @param body ca.mcgill.sable.soot.jimple.JimpleBody
00218  */
00219 public static void setBody(JimpleBody b) {
00220     body = b;
00221     JimpleValueCloner.setBody(b);
00222 }
00223 }

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