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

JimpleValueCloner.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 
00039 public class JimpleValueCloner extends AbstractJimpleValueSwitch {
00040     private static Jimple jimple = Jimple.v();
00041     private static JimpleValueCloner cloner = new JimpleValueCloner();
00042     private static JimpleBody body;
00043     private static String postfixName = "$clone";
00044 /**
00045  * 
00046  */
00047 private JimpleValueCloner() {
00048 }
00049 public void caseAddExpr(AddExpr v) {
00050     setResult(jimple.newAddExpr(JimpleValueCloner.clone(v.getOp1()),
00051             JimpleValueCloner.clone(v.getOp2())));
00052 }
00053 public void caseAndExpr(AndExpr v) {
00054     setResult(jimple.newAndExpr(JimpleValueCloner.clone(v.getOp1()),
00055             JimpleValueCloner.clone(v.getOp2())));
00056 }
00057 public void caseArrayRef(ArrayRef v) {
00058     setResult(jimple.newArrayRef(JimpleValueCloner.clone(v.getBase()),
00059             JimpleValueCloner.clone(v.getIndex())));
00060 }
00061 public void caseCastExpr(CastExpr v) {
00062     setResult(jimple.newCastExpr(JimpleValueCloner.clone(v.getOp()),
00063             v.getType()));
00064 }
00065 public void caseCaughtExceptionRef(CaughtExceptionRef v) {
00066     setResult(jimple.newCaughtExceptionRef(body));
00067 }
00068 public void caseCmpExpr(CmpExpr v) {
00069     setResult(jimple.newCmpExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2()))); 
00070 }
00071 public void caseCmpgExpr(CmpgExpr v) {
00072     setResult(jimple.newCmpgExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2())));    
00073 }
00074 public void caseCmplExpr(CmplExpr v) {
00075     setResult(jimple.newCmplExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2())));    
00076 }
00077 public void caseDivExpr(DivExpr v) {
00078     setResult(jimple.newDivExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2()))); 
00079 }
00080 public void caseDoubleConstant(DoubleConstant v) {
00081     setResult(DoubleConstant.v(v.value));
00082 }
00083 public void caseEqExpr(EqExpr v) {
00084     setResult(jimple.newEqExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2())));  
00085 }
00086 public void caseFloatConstant(FloatConstant v) {
00087     setResult(FloatConstant.v(v.value));
00088 }
00089 public void caseGeExpr(GeExpr v) {
00090     setResult(jimple.newGeExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2())));  
00091 }
00092 public void caseGtExpr(GtExpr v) {
00093     setResult(jimple.newGtExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2())));  
00094 }
00095 public void caseInstanceFieldRef(InstanceFieldRef v) {
00096     setResult(jimple.newInstanceFieldRef(JimpleValueCloner.clone(v.getBase()),
00097             v.getField()));
00098 }
00099 public void caseInstanceOfExpr(InstanceOfExpr v) {
00100     setResult(jimple.newInstanceOfExpr(JimpleValueCloner.clone(v.getOp()), v.getCheckType()));  
00101 }
00102 public void caseIntConstant(IntConstant v) {
00103     setResult(IntConstant.v(v.value));
00104 }
00105 public void caseInterfaceInvokeExpr(InterfaceInvokeExpr v) {
00106     LinkedList args = new LinkedList();
00107 
00108     for (int i = 0; i < v.getArgCount(); i++) {
00109         args.addLast(JimpleValueCloner.clone(v.getArg(i)));
00110     }
00111     
00112     setResult(jimple.newInterfaceInvokeExpr((Local) JimpleValueCloner.clone(v.getBase()), v.getMethod(), args));    
00113 }
00114 public void caseLeExpr(LeExpr v) {
00115     setResult(jimple.newLeExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2())));  
00116 }
00117 public void caseLengthExpr(LengthExpr v) {
00118     setResult(jimple.newLengthExpr(JimpleValueCloner.clone(v.getOp())));    
00119 }
00120 public void caseLocal(Local v) {
00121     String name = v.getName().trim() + postfixName;
00122     try {
00123         setResult(body.getLocal(name));
00124     } catch (NoSuchLocalException nsle) {
00125         Local lcl = jimple.newLocal(name, v.getType());
00126         body.addLocal(lcl);
00127         setResult(lcl);
00128     }
00129 }
00130 public void caseLongConstant(LongConstant v) {
00131     setResult(LongConstant.v(v.value));
00132 }
00133 public void caseLtExpr(LtExpr v) {
00134     setResult(jimple.newLtExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2())));  
00135 }
00136 public void caseMulExpr(MulExpr v) {
00137     setResult(jimple.newMulExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2()))); 
00138 }
00139 public void caseNeExpr(NeExpr v) {
00140     setResult(jimple.newNeExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2())));  
00141 }
00142 public void caseNegExpr(NegExpr v) {
00143     setResult(jimple.newNegExpr(JimpleValueCloner.clone(v.getOp())));   
00144 }
00145 public void caseNewArrayExpr(NewArrayExpr v) {
00146     setResult(jimple.newNewArrayExpr(v.getBaseType(), JimpleValueCloner.clone(v.getSize())));   
00147 }
00148 public void caseNewExpr(NewExpr v) {
00149     setResult(jimple.newNewExpr(v.getBaseType()));
00150 }
00151 public void caseNewMultiArrayExpr(NewMultiArrayExpr v) {
00152     LinkedList sizes = new LinkedList();
00153 
00154     for (int i = 0; i < v.getSizeCount(); i++) {
00155         sizes.addLast(JimpleValueCloner.clone(v.getSize(i)));
00156     }
00157 
00158     setResult(jimple.newNewMultiArrayExpr(v.getBaseType(), sizes));
00159 }
00160 public void caseNullConstant(NullConstant v) {
00161     setResult(NullConstant.v());
00162 }
00163 public void caseOrExpr(OrExpr v) {
00164     setResult(jimple.newOrExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2())));  
00165 }
00166 public void caseParameterRef(ParameterRef v) {
00167     setResult(jimple.newParameterRef(v.getMethod(), v.getIndex()));
00168 }
00169 public void caseRemExpr(RemExpr v) {
00170     setResult(jimple.newRemExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2()))); 
00171 }
00172 public void caseShlExpr(ShlExpr v) {
00173     setResult(jimple.newShlExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2()))); 
00174 }
00175 public void caseShrExpr(ShrExpr v) {
00176     setResult(jimple.newShrExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2()))); 
00177 }
00178 public void caseSpecialInvokeExpr(SpecialInvokeExpr v) {
00179     LinkedList args = new LinkedList();
00180 
00181     for (int i = 0; i < v.getArgCount(); i++) {
00182         args.addLast(JimpleValueCloner.clone(v.getArg(i)));
00183     }
00184 
00185     setResult(jimple.newSpecialInvokeExpr((Local) JimpleValueCloner.clone(v.getBase()), v.getMethod(), args));
00186 }
00187 public void caseStaticFieldRef(StaticFieldRef v) {
00188     setResult(jimple.newStaticFieldRef(v.getField()));
00189 }
00190 public void caseStaticInvokeExpr(StaticInvokeExpr v) {
00191     LinkedList args = new LinkedList();
00192 
00193     for (int i = 0; i < v.getArgCount(); i++) {
00194         args.addLast(JimpleValueCloner.clone(v.getArg(i)));
00195     }
00196 
00197     setResult(jimple.newStaticInvokeExpr(v.getMethod(), args));
00198 }
00199 public void caseStringConstant(StringConstant v) {
00200     setResult(StringConstant.v(v.value));
00201 }
00202 public void caseSubExpr(SubExpr v) {
00203     setResult(jimple.newSubExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2()))); 
00204 }
00205 public void caseThisRef(ThisRef v) {
00206     setResult(jimple.newThisRef(body.getMethod().getDeclaringClass()));
00207 }
00208 public void caseUshrExpr(UshrExpr v) {
00209     setResult(jimple.newUshrExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2())));    
00210 }
00211 public void caseVirtualInvokeExpr(VirtualInvokeExpr v) {
00212     LinkedList args = new LinkedList();
00213 
00214     for (int i = 0; i < v.getArgCount(); i++) {
00215         args.addLast(JimpleValueCloner.clone(v.getArg(i)));
00216     }
00217     
00218     setResult(jimple.newVirtualInvokeExpr((Local) JimpleValueCloner.clone(v.getBase()), v.getMethod(), args));  
00219 }
00220 public void caseXorExpr(XorExpr v) {
00221     setResult(jimple.newXorExpr(JimpleValueCloner.clone(v.getOp1()), JimpleValueCloner.clone(v.getOp2()))); 
00222 }
00223 /**
00224  * 
00225  * @return ca.mcgill.sable.soot.jimple.Value
00226  * @param value ca.mcgill.sable.soot.jimple.Value
00227  */
00228 public static Value clone(Value value) {
00229     value.apply(cloner);
00230     return (Value) cloner.getResult();
00231 }
00232     public void defaultCase(Object v)
00233     {
00234         setResult(null);
00235     }
00236 /**
00237  * 
00238  * @param body ca.mcgill.sable.soot.jimple.JimpleBody
00239  */
00240 public static void setBody(JimpleBody b) {
00241     body = b;
00242 }
00243 /**
00244  * 
00245  * @param name java.lang.String
00246  */
00247 public void setPostfixName(String name) {
00248     postfixName = name;
00249 }
00250 }

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