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

DecompilerChanger.java

00001 package edu.ksu.cis.bandera.jjjc.decompiler;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 2000 Roby Joehanes (robbyjo@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.grimp.*;
00037 import ca.mcgill.sable.soot.jimple.*;
00038 import java.util.*;
00039 
00040 public class DecompilerChanger extends AbstractJimpleValueSwitch {
00041     private static DecompilerChanger walker = new DecompilerChanger();
00042     private static Hashtable tempToType  = new Hashtable();
00043     private static Hashtable tempToValue = new Hashtable();
00044     private static Grimp grimp = Grimp.v();
00045 public void caseAddExpr(AddExpr v)
00046 {
00047     Value v1 = change(v.getOp1());
00048     Value v2 = change(v.getOp2());
00049     setResult(grimp.newAddExpr(v1, v2));
00050 }
00051 public void caseAndExpr(AndExpr v)
00052 {
00053     Value v1 = change(v.getOp1());
00054     Value v2 = change(v.getOp2());
00055     setResult(grimp.newAndExpr(v1, v2));
00056 }
00057 public void caseArrayRef(ArrayRef v)
00058 {
00059     Value v1 = change(v.getBase());
00060     Value v2 = change(v.getIndex());
00061     setResult(grimp.newArrayRef(v1, v2));
00062 }
00063 public void caseCastExpr(CastExpr v)
00064 {
00065     setResult(grimp.newCastExpr(change(v.getOp()), v.getType()));
00066 }
00067 public void caseCaughtExceptionRef(CaughtExceptionRef v)
00068 {
00069     setResult(v);
00070 }
00071 public void caseCmpExpr(CmpExpr v)
00072 {
00073 }
00074 public void caseCmpgExpr(CmpgExpr v)
00075 {
00076 }
00077 public void caseCmplExpr(CmplExpr v)
00078 {
00079 }
00080 public void caseDivExpr(DivExpr v)
00081 {
00082     Value v1 = change(v.getOp1());
00083     Value v2 = change(v.getOp2());
00084     setResult(grimp.newDivExpr(v1, v2));
00085 }
00086 public void caseDoubleConstant(DoubleConstant v)
00087 {
00088     setResult(v);
00089 }
00090 public void caseEqExpr(EqExpr v)
00091 {
00092     Value v1 = change(v.getOp1());
00093     Value v2 = change(v.getOp2());
00094     setResult(grimp.newEqExpr(v1, v2));
00095 }
00096 public void caseFloatConstant(FloatConstant v)
00097 {
00098     setResult(v);
00099 }
00100 public void caseGeExpr(GeExpr v)
00101 {
00102     Value v1 = change(v.getOp1());
00103     Value v2 = change(v.getOp2());
00104     setResult(grimp.newGeExpr(v1, v2));
00105 }
00106 public void caseGtExpr(GtExpr v)
00107 {
00108     Value v1 = change(v.getOp1());
00109     Value v2 = change(v.getOp2());
00110     setResult(grimp.newGtExpr(v1, v2));
00111 }
00112 public void caseInstanceFieldRef(InstanceFieldRef v)
00113 {
00114     setResult(grimp.newInstanceFieldRef(change(v.getBase()), v.getField()));
00115 }
00116 public void caseInstanceOfExpr(InstanceOfExpr v)
00117 {
00118     setResult(grimp.newInstanceOfExpr(change(v.getOp()),v.getType()));
00119 }
00120 public void caseIntConstant(IntConstant v)
00121 {
00122     setResult(v);
00123 }
00124 public void caseInterfaceInvokeExpr(InterfaceInvokeExpr v)
00125 {
00126     Value base = change(v.getBase());
00127     //setResult(grimp.newInterfaceInvokeExpr(base,v.getMethod(),processArgs(v)));
00128 }
00129 public void caseLeExpr(LeExpr v)
00130 {
00131     Value v1 = change(v.getOp1());
00132     Value v2 = change(v.getOp2());
00133     setResult(grimp.newLeExpr(v1, v2));
00134 }
00135 public void caseLengthExpr(LengthExpr v)
00136 {
00137     setResult(grimp.newLengthExpr(change(v.getOp())));
00138 }
00139 public void caseLocal(Local v)
00140 {
00141     //res.add(v.getName().trim());
00142 }
00143 public void caseLongConstant(LongConstant v)
00144 {
00145     setResult(v);
00146 }
00147 public void caseLtExpr(LtExpr v)
00148 {
00149     Value v1 = change(v.getOp1());
00150     Value v2 = change(v.getOp2());
00151     setResult(grimp.newLtExpr(v1, v2));
00152 }
00153 public void caseMulExpr(MulExpr v)
00154 {
00155     Value v1 = change(v.getOp1());
00156     Value v2 = change(v.getOp2());
00157     setResult(grimp.newMulExpr(v1, v2));
00158 }
00159 public void caseNeExpr(NeExpr v)
00160 {
00161     Value v1 = change(v.getOp1());
00162     Value v2 = change(v.getOp2());
00163     setResult(grimp.newNeExpr(v1, v2));
00164 }
00165 public void caseNegExpr(NegExpr v)
00166 {
00167     setResult(grimp.newNegExpr(change(v.getOp())));
00168 }
00169 public void caseNewArrayExpr(NewArrayExpr v)
00170 {
00171     setResult(grimp.newNewArrayExpr(v.getType(),change(v.getSize())));
00172 }
00173 public void caseNewExpr(NewExpr v)
00174 {
00175     setResult(v);
00176 }
00177 public void caseNewInvokeExpr(NewInvokeExpr v)
00178 {
00179     setResult(grimp.newNewInvokeExpr(v.getBaseType(),v.getMethod(),processArgs(v)));
00180 }
00181 public void caseNewMultiArrayExpr(NewMultiArrayExpr v)
00182 {
00183     ca.mcgill.sable.util.LinkedList l = new ca.mcgill.sable.util.LinkedList();
00184     int max = v.getSizeCount();
00185 
00186     // Get all sizes of the array
00187     for (int i=0; i<max; i++)
00188     {
00189         l.addLast(change(v.getSize(i)));
00190     }
00191     setResult(grimp.newNewMultiArrayExpr(v.getBaseType(),l));
00192 }
00193 public void caseNullConstant(NullConstant v)
00194 {
00195     setResult(v);
00196 }
00197 public void caseOrExpr(OrExpr v)
00198 {
00199     Value v1 = change(v.getOp1());
00200     Value v2 = change(v.getOp2());
00201     setResult(grimp.newOrExpr(v1, v2));
00202 }
00203 public void caseParameterRef(ParameterRef v)
00204 {
00205     setResult(v);
00206 }
00207 public void caseRemExpr(RemExpr v)
00208 {
00209     Value v1 = change(v.getOp1());
00210     Value v2 = change(v.getOp2());
00211     setResult(grimp.newRemExpr(v1, v2));
00212 }
00213 public void caseShlExpr(ShlExpr v)
00214 {
00215     Value v1 = change(v.getOp1());
00216     Value v2 = change(v.getOp2());
00217     setResult(grimp.newShlExpr(v1, v2));
00218 }
00219 public void caseShrExpr(ShrExpr v)
00220 {
00221     Value v1 = change(v.getOp1());
00222     Value v2 = change(v.getOp2());
00223     setResult(grimp.newShrExpr(v1, v2));
00224 }
00225 public void caseSpecialInvokeExpr(SpecialInvokeExpr v)
00226 {
00227     //caseNonStaticInvokeExpr(v);
00228 }
00229 public void caseStaticFieldRef(StaticFieldRef v)
00230 {
00231     setResult(v);
00232 }
00233 public void caseStaticInvokeExpr(StaticInvokeExpr v)
00234 {
00235     setResult(grimp.newStaticInvokeExpr(v.getMethod(),processArgs(v)));
00236 }
00237 public void caseStringConstant(StringConstant v)
00238 {
00239     setResult(v);
00240 }
00241 public void caseSubExpr(SubExpr v)
00242 {
00243     Value v1 = change(v.getOp1());
00244     Value v2 = change(v.getOp2());
00245     setResult(grimp.newSubExpr(v1, v2));
00246 }
00247 public void caseThisRef(ThisRef v)
00248 {
00249     setResult(v);
00250 }
00251 public void caseUshrExpr(UshrExpr v)
00252 {
00253     Value v1 = change(v.getOp1());
00254     Value v2 = change(v.getOp2());
00255     setResult(grimp.newUshrExpr(v1, v2));
00256 }
00257 public void caseVirtualInvokeExpr(VirtualInvokeExpr v)
00258 {
00259     //caseNonStaticInvokeExpr(v);
00260 }
00261 public void caseXorExpr(XorExpr v)
00262 {
00263     Value v1 = change(v.getOp1());
00264     Value v2 = change(v.getOp2());
00265     setResult(grimp.newXorExpr(v1, v2));
00266 }
00267 public static Value change(Value v)
00268 {
00269     walker.setResult(v);
00270 
00271     if (v != null) v.apply(walker);
00272     return (Value) walker.getResult();
00273 }
00274 public void defaultCase(Object v)
00275 {
00276     // Nothing... probably some error
00277 }
00278 public static boolean isJimpleValue(Value v)
00279 {
00280     String s = v.toString().trim();
00281     return (v instanceof Local) && ((s.startsWith("JJJCTEMP$")) || (s.startsWith("$ret")));
00282 }
00283 private ca.mcgill.sable.util.LinkedList processArgs(InvokeExpr v)
00284 {
00285     ca.mcgill.sable.util.LinkedList l = new ca.mcgill.sable.util.LinkedList();
00286     int param = v.getArgCount();
00287 
00288     for (int i=0; i<param; i++)
00289     {
00290         l.addLast(change(v.getArg(i)));
00291     }
00292     return l;
00293 }
00294 public static void put (Value lhs, Value rhs)
00295 {
00296     if (isJimpleValue(lhs))
00297     {
00298         tempToType.put(lhs,rhs.getType());
00299         tempToValue.put(lhs,rhs);
00300     }
00301 }
00302 public static void reset()
00303 {
00304     tempToType = new Hashtable();
00305     tempToValue = new Hashtable();
00306 }
00307 }

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