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

DecompilerStmtSwitch.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.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 /**
00043  * DecompilerStmtSwitch is a recursive analyzer for statements.
00044  * The methods are basically each case possible for statements.
00045  * See DecompilerSwitch for details.
00046  * @author <a href="mailto:robbyjo@cis.ksu.edu">Roby Joehanes</a>
00047  * @version 0.4.21
00048 **/
00049 public class DecompilerStmtSwitch implements StmtSwitch {
00050     private static DecompilerStmtSwitch walker = new DecompilerStmtSwitch();
00051     private Vector result = new Vector();
00052 /**
00053  * SlabsStmtSwitch constructor comment.
00054  */
00055 public DecompilerStmtSwitch()
00056 {
00057     result = new Vector();
00058 }
00059 /**
00060  * caseAssignStmt method comment.
00061  */
00062 public void caseAssignStmt(AssignStmt stmt)
00063 {
00064     Value leftOp = stmt.getLeftOp();
00065     Value rightOp = stmt.getRightOp();
00066     boolean isBool = DecompilerInfo.isBool(leftOp) || leftOp.getType().toString().trim().equals("boolean");
00067     String rightValue = rightOp.toString().trim();
00068 
00069     if (DecompilerInfo.qvDef(leftOp) == 0)  // haven't been defined yet
00070     {
00071         result.add(leftOp.getType().toString());
00072         result.add(" ");
00073     }
00074 
00075     DecompilerInfo.putVarInfo(leftOp,rightOp);
00076     result.addAll(DecompilerValueSwitch.evaluate(leftOp));
00077     DecompilerValueSwitch.reset();
00078     result.add(" ");
00079     result.add("=");
00080     result.add(" ");
00081     if (isBool)
00082     {
00083         if (rightValue.equals("0")) result.add("false");
00084             else if (rightValue.equals("1")) result.add("true");
00085                 else result.addAll(DecompilerValueSwitch.evaluate(rightOp));
00086     } else 
00087      result.addAll(DecompilerValueSwitch.evaluate(rightOp));
00088     DecompilerValueSwitch.reset();
00089 }
00090 /**
00091  * caseBreakpointStmt method comment.
00092  */
00093 public void caseBreakpointStmt(BreakpointStmt stmt)
00094 {
00095     // Unused
00096 }
00097 /**
00098  * caseEnterMonitorStmt method comment.
00099  */
00100 public void caseEnterMonitorStmt(EnterMonitorStmt stmt)
00101 {
00102     result.add("synchronized");
00103     result.add(" ");
00104     result.add("(");
00105     result.addAll(DecompilerValueSwitch.evaluate(stmt.getOp()));
00106     DecompilerValueSwitch.reset();
00107     result.add(")");
00108 }
00109 /**
00110  * caseExitMonitorStmt method comment.
00111  */
00112 public void caseExitMonitorStmt(ExitMonitorStmt stmt)
00113 {
00114     // What's the op for ?
00115     //result.add("}");
00116 }
00117 /**
00118  * caseGotoStmt method comment.
00119  */
00120 public void caseGotoStmt(GotoStmt stmt) {
00121     result.add(DecompilerUtil.gotoStr);
00122     result.add(" ");
00123     result.add(DecompilerGotoMapper.mapStmt((Stmt) stmt.getTarget()));
00124 }
00125 /**
00126  * caseIdentityStmt method comment.
00127  */
00128 public void caseIdentityStmt(IdentityStmt stmt)
00129 {
00130     result.addAll(DecompilerValueSwitch.evaluate(stmt.getLeftOp()));
00131     DecompilerValueSwitch.reset();
00132     result.add(" ");
00133     result.add(":=");
00134     result.add(" ");
00135     result.addAll(DecompilerValueSwitch.evaluate(stmt.getRightOp()));
00136     DecompilerValueSwitch.reset();
00137 }
00138 /**
00139  * caseIfStmt method comment.
00140  */
00141 public void caseIfStmt(IfStmt stmt)
00142 {
00143     result.add("if");
00144     result.add(" ");
00145     result.add("(");
00146     result.addAll(DecompilerValueSwitch.evaluate(stmt.getCondition()));
00147     DecompilerValueSwitch.reset();
00148     result.add(")");
00149     result.add(" ");
00150     result.add(DecompilerUtil.gotoStr);
00151     result.add(" ");
00152     result.add(DecompilerGotoMapper.mapStmt(stmt.getTarget()));
00153 }
00154 /**
00155  * caseInvokeStmt method comment.
00156  */
00157 public void caseInvokeStmt(InvokeStmt stmt)
00158 {
00159     result.addAll(DecompilerValueSwitch.evaluate(stmt.getInvokeExpr()));
00160     DecompilerValueSwitch.reset();
00161 }
00162 /**
00163  * caseLookupSwitchStmt method comment.
00164  */
00165 public void caseLookupSwitchStmt(LookupSwitchStmt stmt)
00166 {
00167     result.add("switch");
00168     result.add(" ");
00169     result.add("(");
00170     result.addAll(DecompilerValueSwitch.evaluate(stmt.getKey()));
00171     result.add(")");
00172     DecompilerValueSwitch.reset();
00173 
00174 
00175 /*  
00176 // We won't need this at this moment
00177     result.add("{");
00178 
00179     // process the cases
00180     int max = stmt.getLookupValues().size();
00181     for (int i = 0; i<max; i++)
00182     {
00183         int cases = stmt.getLookupValue(i);
00184         result.add("case"+String.valueOf(cases)+":");
00185         result.add(SlabsUtil.gotoStr);
00186         result.add(""); // stmtToName?
00187     }
00188     Stmt def = (Stmt) stmt.getDefaultTarget();
00189     if (def!=null)
00190     {
00191         result.add("default:");
00192         result.add(SlabsUtil.gotoStr);
00193         result.add(""); // stmtToName?
00194     }
00195 */
00196 
00197 }
00198 /**
00199  * caseNopStmt method comment.
00200  */
00201 public void caseNopStmt(NopStmt stmt)
00202 {
00203     // Basically nothing...
00204     // result.add("nop");
00205 }
00206 /**
00207  * caseRetStmt method comment.
00208  */
00209 public void caseRetStmt(RetStmt stmt)
00210 {
00211     // Unused
00212 }
00213 /**
00214  * caseReturnStmt method comment.
00215  */
00216 public void caseReturnStmt(ReturnStmt stmt)
00217 {
00218     result.add("return");
00219     result.add(" ");
00220     result.addAll(DecompilerValueSwitch.evaluate(stmt.getReturnValue()));
00221     DecompilerValueSwitch.reset();
00222 }
00223 /**
00224  * caseReturnVoidStmt method comment.
00225  */
00226 public void caseReturnVoidStmt(ReturnVoidStmt stmt)
00227 {
00228     result.add("return");
00229 }
00230 /**
00231  * caseTableSwitchStmt method comment.
00232  */
00233 public void caseTableSwitchStmt(TableSwitchStmt stmt)
00234 {
00235     // Unused
00236 }
00237 /**
00238  * caseThrowStmt method comment.
00239  */
00240 public void caseThrowStmt(ThrowStmt stmt)
00241 {
00242     result.add("throw");
00243     result.add(" ");
00244     result.addAll(DecompilerValueSwitch.evaluate(stmt.getOp()));
00245     DecompilerValueSwitch.reset();
00246 }
00247 /**
00248  * defaultCase method comment.
00249  */
00250 public void defaultCase(Object obj)
00251 {
00252     // Unused basically
00253 }
00254 public static Vector evaluate(Stmt stmt)
00255 {
00256     if (stmt==null) return new Vector();
00257     stmt.apply(walker);
00258     return walker.getResult();
00259 }
00260 private Vector getResult()
00261 {
00262     return result;
00263 }
00264 public static void reset()
00265 {
00266     walker.result = new Vector();
00267 }
00268 }

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