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

RenameExpression.java

00001 package edu.ksu.cis.bandera.prog;
00002 
00003 import ca.mcgill.sable.soot.*;
00004 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00005  * Bandera, a Java(TM) analysis and transformation toolkit           *
00006  * Copyright (C) 1998-2001 SAnToS Laboratories (santos@cis.ksu.edu)  *
00007 
00008  * All rights reserved.                                              *
00009  *                                                                   *
00010  * This work was done as a project in the SAnToS Laboratory,         *
00011  * Department of Computing and Information Sciences, Kansas State    *
00012  * University, USA (http://www.cis.ksu.edu/santos).                  *
00013  * It is understood that any modification not identified as such is  *
00014  * not covered by the preceding statement.                           *
00015  *                                                                   *
00016  * This work is free software; you can redistribute it and/or        *
00017  * modify it under the terms of the GNU Library General Public       *
00018  * License as published by the Free Software Foundation; either      *
00019  * version 2 of the License, or (at your option) any later version.  *
00020  *                                                                   *
00021  * This work is distributed in the hope that it will be useful,      *
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00024  * Library General Public License for more details.                  *
00025  *                                                                   *
00026  * You should have received a copy of the GNU Library General Public *
00027  * License along with this toolkit; if not, write to the             *
00028  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00029  * Boston, MA  02111-1307, USA.                                      *
00030  *                                                                   *
00031  * Java is a trademark of Sun Microsystems, Inc.                     *
00032  *                                                                   *
00033  * To submit a bug report, send a comment, or get the latest news on *
00034  * this project and other SAnToS projects, please visit the web-site *
00035  *                http://www.cis.ksu.edu/santos                      *
00036  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00037 import ca.mcgill.sable.soot.SootMethod;
00038 import ca.mcgill.sable.soot.jimple.*;
00039 import java.util.*;
00040 import edu.ksu.cis.bandera.jext.*;
00041 import java.util.Hashtable;
00042 public class RenameExpression extends AbstractBanderaValueSwitch {
00043     static int count = 0;
00044     int id = ++count;
00045     String methodString;
00046     List parameters;
00047     Hashtable locals;
00048     public static List fields = new Vector();
00049     public ca.mcgill.sable.soot.SootMethod topMethod;
00050     protected ca.mcgill.sable.soot.SootMethod currentMethod;
00051     public static java.util.Hashtable newExpr2original = new Hashtable();
00052 public RenameExpression(String methodString, List parameters, Hashtable locals, SootMethod topMethod, SootMethod currentMethod) {
00053     this.methodString = methodString;
00054     this.parameters = parameters;
00055     this.locals = locals;
00056     this.topMethod = topMethod;
00057     this.currentMethod = currentMethod;
00058 }
00059 public void caseAddExpr(AddExpr v) {
00060     setResult(Jimple.v().newAddExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00061 }
00062 public void caseAndExpr(AndExpr v) {
00063     setResult(Jimple.v().newAndExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00064 }
00065 public void caseArrayRef(ArrayRef v) {
00066     setResult(Jimple.v().newArrayRef(renameExpr(v.getBase()), renameExpr(v.getIndex())));
00067 }
00068 public void caseCastExpr(CastExpr v) {
00069     setResult(Jimple.v().newCastExpr(renameExpr(v.getOp()), v.getCastType()));
00070 }
00071 /*
00072 public void caseNextNextStmtRef(NextNextStmtRef v)
00073 {
00074 defaultCase(v);
00075 }
00076   */
00077 
00078 public void caseCaughtExceptionRef(CaughtExceptionRef v) {
00079     setResult(v);
00080     //defaultCase(v);
00081 }
00082 /**
00083  * Insert the method's description here.
00084  * Creation date: (4/26/00 3:06:15 PM)
00085  */
00086 public void caseChooseExpr(ChooseExpr v) {
00087     setResult(v);
00088 }
00089 public void caseCmpExpr(CmpExpr v) {
00090     setResult(Jimple.v().newCmpExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00091 }
00092 public void caseCmpgExpr(CmpgExpr v) {
00093     setResult(Jimple.v().newCmpgExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00094 }
00095 public void caseCmplExpr(CmplExpr v) {
00096     setResult(Jimple.v().newCmplExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00097 }
00098 /**
00099  * 
00100  * @param expr edu.ksu.cis.bandera.jext.ComplementExpr
00101  */
00102 public void caseComplementExpr(ComplementExpr expr) {
00103     System.out.println("Don't know what to do.");
00104     setResult(expr);
00105 }
00106 public void caseDivExpr(DivExpr v) {
00107     setResult(Jimple.v().newDivExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00108 }
00109 public void caseDoubleConstant(DoubleConstant v) {
00110     setResult(DoubleConstant.v(v.value));
00111 }
00112 public void caseEqExpr(EqExpr v) {
00113     setResult(Jimple.v().newEqExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00114 }
00115 public void caseFloatConstant(FloatConstant v) {
00116     setResult(FloatConstant.v(v.value));
00117 }
00118 public void caseGeExpr(GeExpr v) {
00119     setResult(Jimple.v().newGeExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00120 }
00121 public void caseGtExpr(GtExpr v) {
00122     setResult(Jimple.v().newGtExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00123 }
00124 public void caseInstanceFieldRef(InstanceFieldRef v) {
00125     if (!fields.contains(v.getField())) {
00126         fields.add(v.getField());
00127     }
00128     Value base = renameExpr(v.getBase());
00129     //  v.setBase(base);
00130     //defaultCase(v);
00131     setResult(Jimple.v().newInstanceFieldRef(base, v.getField()));
00132 }
00133 public void caseInstanceOfExpr(InstanceOfExpr v) {
00134     RefType type = (RefType) v.getCheckType();
00135     setResult(Jimple.v().newInstanceOfExpr(renameExpr(v.getOp()), RefType.v(type.className)));
00136 }
00137 public void caseIntConstant(IntConstant v) {
00138     setResult(IntConstant.v(v.value));
00139 }
00140 public void caseInterfaceInvokeExpr(InterfaceInvokeExpr v) {
00141     defaultCase(v);
00142     //setResult(v);
00143 }
00144 public void caseLeExpr(LeExpr v) {
00145     setResult(Jimple.v().newLeExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00146 }
00147 public void caseLengthExpr(LengthExpr v) {
00148     setResult(Jimple.v().newLengthExpr(renameExpr(v.getOp())));
00149 }
00150 public void caseLocal(Local v) {
00151     if ((Inline.typeTable.size() > 0) && (Inline.typeTable.get(v) == null) && Inline.isMethodCompiled) {
00152         throw new RuntimeException("Cannot find abstraction for local <" + currentMethod + ", " + v + ">");
00153     }
00154     Local l;
00155     if ((l = (Local) locals.get(methodString + v.getName() /* + id*/)) == null) {
00156         if (methodString.equals(""))
00157             l = Jimple.v().newLocal(v.getName(), v.getType());
00158         else
00159             l = Jimple.v().newLocal(methodString /* + id + "_"*/ +v.getName(), v.getType());
00160         locals.put(methodString + v.getName() /* + id*/, l);
00161         Inline.newLocal2original.put(l, v);
00162         if ((Inline.typeTable.size() > 0) && Inline.isMethodCompiled)
00163             Inline.typeTable.put(l, Inline.typeTable.get(v));
00164         edu.ksu.cis.bandera.jjjc.CompilationManager.getAnnotationManager().putInlineLocal(new LocalExpr(topMethod, l), new LocalExpr(currentMethod, v));
00165     } else
00166         l = l;
00167     setResult(l);
00168 }
00169 /**
00170  * 
00171  * @param expr edu.ksu.cis.bandera.jext.LogicalAndExpr
00172  */
00173 public void caseLogicalAndExpr(LogicalAndExpr expr) {
00174     System.out.println("Don't know what to do.");
00175     setResult(expr);
00176 }
00177 /**
00178  * 
00179  * @param expr edu.ksu.cis.bandera.jext.LogicalOrExpr
00180  */
00181 public void caseLogicalOrExpr(LogicalOrExpr expr) {
00182     System.out.println("Don't know what to do.");
00183     setResult(expr);
00184 }
00185 public void caseLongConstant(LongConstant v) {
00186     setResult(LongConstant.v(v.value));
00187 }
00188 public void caseLtExpr(LtExpr v) {
00189     setResult(Jimple.v().newLtExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00190 }
00191 public void caseMulExpr(MulExpr v) {
00192     setResult(Jimple.v().newMulExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00193 }
00194 public void caseNeExpr(NeExpr v) {
00195     setResult(Jimple.v().newNeExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00196 }
00197 public void caseNegExpr(NegExpr v) {
00198     setResult(Jimple.v().newNegExpr(renameExpr(v.getOp())));
00199 }
00200 public void caseNewArrayExpr(NewArrayExpr v) {
00201     setResult(Jimple.v().newNewArrayExpr(v.getBaseType(), renameExpr(v.getSize())));
00202 }
00203 public void caseNewExpr(NewExpr v) {
00204     setResult(v);
00205 }
00206 public void caseNewMultiArrayExpr(NewMultiArrayExpr v) {
00207     defaultCase(v);
00208 }
00209 public void caseNullConstant(NullConstant v) {
00210     setResult(NullConstant.v());
00211 }
00212 public void caseOrExpr(OrExpr v) {
00213     setResult(Jimple.v().newOrExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00214 }
00215 public void caseParameterRef(ParameterRef v) {
00216     if (parameters == null || parameters.size() == 0)
00217         setResult(v);
00218     else {
00219         setResult((Value) parameters.get(0));
00220         parameters.remove(0);
00221     }
00222 }
00223 public void caseRemExpr(RemExpr v) {
00224     setResult(Jimple.v().newRemExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00225 }
00226 public void caseShlExpr(ShlExpr v) {
00227     setResult(Jimple.v().newShlExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00228 }
00229 public void caseShrExpr(ShrExpr v) {
00230     setResult(Jimple.v().newShrExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00231 }
00232 public void caseSpecialInvokeExpr(SpecialInvokeExpr v) {
00233     //System.out.println("Not inlining the special invoke until further notice.");
00234     ca.mcgill.sable.util.List l = new ca.mcgill.sable.util.VectorList();
00235     int i;
00236     for (i = 0; i < v.getArgCount(); i++)
00237         l.add(renameExpr(v.getArg(i)));
00238     setResult(Jimple.v().newSpecialInvokeExpr((Local) renameExpr(v.getBase()), v.getMethod(), l));
00239     //  setResult(v);
00240 }
00241 public void caseStaticFieldRef(StaticFieldRef v) {
00242     if (!fields.contains(v.getField())) {
00243         fields.add(v.getField());
00244     }
00245     setResult(v);
00246 }
00247 public void caseStaticInvokeExpr(StaticInvokeExpr v) {
00248     ca.mcgill.sable.util.List l = new ca.mcgill.sable.util.VectorList();
00249     int i;
00250     for (i = 0; i < v.getArgCount(); i++)
00251         l.add(renameExpr(v.getArg(i)));
00252     setResult(Jimple.v().newStaticInvokeExpr(v.getMethod(), l));
00253 }
00254 public void caseStringConstant(StringConstant v) {
00255     setResult(StringConstant.v(v.value));
00256 }
00257 public void caseSubExpr(SubExpr v) {
00258     setResult(Jimple.v().newSubExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00259 }
00260 public void caseThisRef(ThisRef v) {
00261     if (parameters == null || parameters.size() == 0)
00262         setResult(v);
00263     else {
00264         setResult((Value) parameters.get(0));
00265         parameters.remove(0);
00266     }
00267 }
00268 public void caseUshrExpr(UshrExpr v) {
00269     setResult(Jimple.v().newUshrExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00270 }
00271 public void caseVirtualInvokeExpr(VirtualInvokeExpr v) {
00272     Value base = renameExpr(v.getBase());
00273     //  v.setBase(base);
00274     //defaultCase(v);
00275     ca.mcgill.sable.util.List l = new ca.mcgill.sable.util.VectorList();
00276     for (int i = 0; i < v.getArgCount(); i++)
00277         l.add(renameExpr(v.getArg(i)));
00278     setResult(Jimple.v().newVirtualInvokeExpr((Local) base, v.getMethod(), l));
00279 }
00280 public void caseXorExpr(XorExpr v) {
00281     setResult(Jimple.v().newXorExpr(renameExpr(v.getOp1()), renameExpr(v.getOp2())));
00282 }
00283 public void defaultCase(Object v) {
00284     throw new RuntimeException("Unhandled expression in" + " inline " + v.getClass() + " " + v);
00285 }
00286 public Value renameExpr(Value v) {
00287     v.apply(this);
00288     newExpr2original.put(getResult(), v);
00289     return (Value) this.getResult();
00290 }
00291 public String toString() {
00292     return "RE " + id;
00293 }
00294 }

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