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

InlinerChooseFixer.java

00001 package edu.ksu.cis.bandera.prog;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 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 java.util.Vector;
00036 import ca.mcgill.sable.soot.*;
00037 import ca.mcgill.sable.soot.jimple.*;
00038 import ca.mcgill.sable.util.*;
00039 import edu.ksu.cis.bandera.jext.*;
00040 import edu.ksu.cis.bandera.abstraction.*;
00041 public class InlinerChooseFixer implements StmtSwitch {
00042     private static InlinerChooseFixer fixer = new InlinerChooseFixer();
00043     private static Jimple jimple = Jimple.v();
00044 /**
00045  * AbstractionChooseFixer constructor comment.
00046  */
00047 private InlinerChooseFixer() {
00048 }
00049 /**
00050  * caseAssignStmt method comment.
00051  */
00052 public void caseAssignStmt(AssignStmt stmt) {
00053     Value rightOp = stmt.getRightOp();
00054     if (rightOp instanceof StaticInvokeExpr) {
00055         StaticInvokeExpr sie = (StaticInvokeExpr) rightOp;
00056         SootMethod sm = sie.getMethod();
00057         if ("edu.ksu.cis.bandera.abstraction.Abstraction".equals(sm.getDeclaringClass().getName())
00058                 && "choose".equals(sm.getName().trim())) {
00059             int argCount = sie.getArgCount();
00060             Vector args = new Vector();
00061             if (argCount == 0) {
00062                 args.add(IntConstant.v(0));
00063                 args.add(IntConstant.v(1));
00064             } else if (argCount == 1) {
00065                 int constant = ((IntConstant) sie.getArg(0)).value;
00066                 if (constant == 0) {
00067                     System.out.println("*** Error: Choose with zero value ***");
00068                     return;
00069                 }
00070                 int val = 0;
00071                 do {
00072                     if ((constant & 1) == 1) {
00073                         args.add(IntConstant.v(val));
00074                     }
00075                     val++;
00076                     constant >>= 1;
00077                 } while (constant != 0);
00078             } else {
00079                 throw new RuntimeException("AbstractionChooseFixer class is not updated!!!");
00080             }
00081             Value chooseExpr = new ChooseExpr(args);
00082             stmt.setRightOp(chooseExpr);
00083             if (Inline.typeTable.size() > 0)
00084                 Inline.typeTable.put(chooseExpr, ConcreteIntegralAbstraction.v());
00085         } else if ("Bandera".equals(sm.getDeclaringClass().getName())
00086                 && "choose".equals(sm.getName().trim())) {
00087             LinkedList args = new LinkedList();
00088             args.add(IntConstant.v(0));
00089             args.add(IntConstant.v(1));
00090             Value chooseExpr = new ChooseExpr(args);
00091             stmt.setRightOp(chooseExpr);
00092             if (Inline.typeTable.size() > 0)
00093                 Inline.typeTable.put(chooseExpr, ConcreteIntegralAbstraction.v());
00094         }
00095     }
00096 }
00097 /**
00098  * caseBreakpointStmt method comment.
00099  */
00100 public void caseBreakpointStmt(BreakpointStmt stmt) {}
00101 /**
00102  * caseEnterMonitorStmt method comment.
00103  */
00104 public void caseEnterMonitorStmt(EnterMonitorStmt stmt) {}
00105 /**
00106  * caseExitMonitorStmt method comment.
00107  */
00108 public void caseExitMonitorStmt(ExitMonitorStmt stmt) {}
00109 /**
00110  * caseGotoStmt method comment.
00111  */
00112 public void caseGotoStmt(GotoStmt stmt) {}
00113 /**
00114  * caseIdentityStmt method comment.
00115  */
00116 public void caseIdentityStmt(IdentityStmt stmt) {}
00117 /**
00118  * caseIfStmt method comment.
00119  */
00120 public void caseIfStmt(IfStmt stmt) {}
00121 /**
00122  * caseInvokeStmt method comment.
00123  */
00124 public void caseInvokeStmt(InvokeStmt stmt) {}
00125 /**
00126  * caseLookupSwitchStmt method comment.
00127  */
00128 public void caseLookupSwitchStmt(LookupSwitchStmt stmt) {}
00129 /**
00130  * caseNopStmt method comment.
00131  */
00132 public void caseNopStmt(NopStmt stmt) {}
00133 /**
00134  * caseRetStmt method comment.
00135  */
00136 public void caseRetStmt(RetStmt stmt) {}
00137 /**
00138  * caseReturnStmt method comment.
00139  */
00140 public void caseReturnStmt(ReturnStmt stmt) {}
00141 /**
00142  * caseReturnVoidStmt method comment.
00143  */
00144 public void caseReturnVoidStmt(ReturnVoidStmt stmt) {}
00145 /**
00146  * caseTableSwitchStmt method comment.
00147  */
00148 public void caseTableSwitchStmt(TableSwitchStmt stmt) {}
00149 /**
00150  * caseThrowStmt method comment.
00151  */
00152 public void caseThrowStmt(ThrowStmt stmt) {}
00153 /**
00154  * defaultCase method comment.
00155  */
00156 public void defaultCase(Object obj) {}
00157 /**
00158  * 
00159  * @param s ca.mcgill.sable.soot.jimple.Stmt
00160  */
00161 public static void fix(Stmt s) {
00162     s.apply(fixer);
00163 }
00164 /**
00165  * 
00166  * @param sc ca.mcgill.sable.soot.SootClass
00167  */
00168 public static void fix(SootClass sc) {
00169     for (Iterator i = sc.getMethods().iterator(); i.hasNext(); ) {
00170         fix((SootMethod) i.next());
00171     }
00172 }
00173 /**
00174  * 
00175  * @param sm ca.mcgill.sable.soot.SootMethod
00176  */
00177 public static void fix(SootMethod sm) {
00178     for (Iterator i = ((JimpleBody) sm.getBody(jimple)).getStmtList().iterator(); i.hasNext();) {
00179         fix((Stmt) i.next());
00180     }
00181 }
00182 }

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