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

VInvokeCallBack.java

00001 package edu.ksu.cis.bandera.bofa;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1998, 1999                                          *
00006  * John Hatcliff (hatcliff@cis.ksu.edu)
00007  * All rights reserved.                                              *
00008  *                                                                   *
00009  * This work was done as a project in the SAnToS Laboratory,         *
00010  * Department of Computing and Information Sciences, Kansas State    *
00011  * University, USA (http://www.cis.ksu.edu/santos).                  *
00012  * It is understood that any modification not identified as such is  *
00013  * not covered by the preceding statement.                           *
00014  *                                                                   *
00015  * This work is free software; you can redistribute it and/or        *
00016  * modify it under the terms of the GNU Library General Public       *
00017  * License as published by the Free Software Foundation; either      *
00018  * version 2 of the License, or (at your option) any later version.  *
00019  *                                                                   *
00020  * This work is distributed in the hope that it will be useful,      *
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00023  * Library General Public License for more details.                  *
00024  *                                                                   *
00025  * You should have received a copy of the GNU Library General Public *
00026  * License along with this toolkit; if not, write to the             *
00027  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00028  * Boston, MA  02111-1307, USA.                                      *
00029  *                                                                   *
00030  * Java is a trademark of Sun Microsystems, Inc.                     *
00031  *                                                                   *
00032  * To submit a bug report, send a comment, or get the latest news on *
00033  * this project and other SAnToS projects, please visit the web-site *
00034  *                http://www.cis.ksu.edu/santos                      *
00035  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00036 
00037 import java.util.Collection;
00038 import java.util.List;
00039 
00040 import ca.mcgill.sable.soot.NoSuchMethodException;
00041 import ca.mcgill.sable.soot.SootClass;
00042 import ca.mcgill.sable.soot.SootMethod;
00043 import ca.mcgill.sable.soot.Type;
00044 import ca.mcgill.sable.soot.jimple.Expr;
00045 import ca.mcgill.sable.soot.jimple.Jimple;
00046 import ca.mcgill.sable.soot.jimple.Local;
00047 import ca.mcgill.sable.soot.jimple.VirtualInvokeExpr;
00048 import ca.mcgill.sable.util.VectorList;
00049 
00050 import org.apache.log4j.Category;
00051 
00052 /*
00053  * VInvokeCallBack.java
00054  * $Id: VInvokeCallBack.java,v 1.1.1.1 2002/01/24 03:42:08 pserver Exp $
00055  */
00056 
00057 /**
00058  *
00059  * This class provides the call back method to be invoked when method X is
00060  * encountered during the flow analysis.
00061  *
00062  * @author <a href="mailto:rvprasad@cis.ksu.edu">Venkatesh Prasad Ranganath</a>
00063  * @version $Name:  $($Revision: 1.1.1.1 $)
00064  */
00065 
00066 public class VInvokeCallBack implements CallBack {
00067     /**
00068      * <code>jimple</code> is used to create jimple expression AST nodes.
00069      *
00070      */
00071     static private Jimple jimple;
00072 
00073     /**
00074      * <code>declClass</code> is the class in which the method being registered 
00075      * should be declared in the class hierarchy for the callback to occur.
00076      */
00077     private final String declClass;
00078         
00079     /**
00080      * <code>mname</code> is the name of the method when encountered the new
00081      * method is plugged in.  By default it is "start".
00082      */
00083     private final String mname;
00084 
00085     /**
00086      * <code>pmname</code> is the name of the plug-in method.  By default it is
00087      * "run". 
00088      */
00089     private final String pmname;
00090 
00091     static {
00092         jimple = Jimple.v();
00093     }
00094 
00095     /**
00096      * Provides logging through log4j.
00097      *
00098      */
00099     private Category cat;
00100 
00101     /**
00102      * Creates a new <code>VInvokeCallBack</code> instance.
00103      */
00104     public VInvokeCallBack() {
00105         cat = Category.getInstance(getClass().getName());
00106         declClass = "java.lang.Thread";
00107         mname = "start";
00108         pmname = "run";
00109     }
00110     /**
00111      * Creates a new <code>VInvokeCallBack</code> instance.
00112      *
00113      * @param declClass Name of the class declaring the method
00114      * <code>mname</code>. 
00115      * @param mname Name of the method that will trigger the inclusion.
00116      * @param pmname Name of the method to be included into the flow graph.
00117      */
00118     public VInvokeCallBack(String declClass, String mname, String pmname) {
00119         cat = Category.getInstance(getClass().getName());
00120         this.declClass = declClass;
00121         this.mname = mname;
00122         this.pmname = pmname;
00123     }
00124     /**
00125      * <code>callback</code> will be called by BOFA when java.lang.Thread.start
00126      * method invocation is encountered during flow analysis.
00127      *
00128      * @param e <code>Expr</code> object respresenting the expression which
00129      * triggered the callback.
00130      * @param o <code>Object</code> object representing the FGExpr object which
00131      * was processing the expression. 
00132      * @throw <code>ca.mcgill.sable.soot.NoSuchMethodException</code> is thrown
00133      * when run method is undefined in the given hierarchy.
00134      */
00135     public void callback(Expr e, Object o) {
00136         
00137         VirtualInvokeExpr v = (VirtualInvokeExpr) e;
00138         SootMethod sm = v.getMethod();
00139 
00140         if (Util.isAncestorOf(sm.getDeclaringClass(), declClass) 
00141             && sm.getName().equals(mname)) {
00142             SootClass runClass = Util.getDeclaringClass(BOFA.sootClassManager
00143                                                         .getClass(v.getBase()
00144                                                                   .getType()
00145                                                                   .toString()),
00146                                                         pmname);
00147             VirtualInvokeExpr v1 = 
00148                 jimple.newVirtualInvokeExpr(
00149                    (ca.mcgill.sable.soot.jimple.Local)v.getBase(), 
00150                    runClass.getMethod(pmname), 
00151                    new VectorList());
00152             ((FGExpr)o).caseVirtualInvokeExpr(v1);
00153             cat.debug("Plugging a call to run method of class" 
00154                      + v.getBase().getType().toString() + ".");
00155         }
00156     }
00157 }// VInvokeCallBack

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