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

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

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