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

TempExpr.java

00001 package edu.ksu.cis.bandera.bofa;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1999, 2000, 2001                                    *
00006  * Venkatesh Prasad Ranganath (rvprasad@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 ca.mcgill.sable.soot.*;
00038 import ca.mcgill.sable.soot.jimple.*;
00039 import ca.mcgill.sable.util.*;
00040 import edu.ksu.cis.bandera.jjjc.CompilationManager;
00041 import java.io.PrintWriter;
00042 import org.apache.log4j.Category;
00043 
00044 /**
00045  * A jimple expression walker.
00046  *
00047  * @author 
00048  * <a href="http://www.cis.ksu.edu/~rvprasad">Venkatesh Prasad Ranganath</a>
00049  *
00050  * @version $Name:  $($Revision: 1.1.1.1 $)
00051  */
00052 class TempExpr extends AbstractJimpleValueSwitch
00053 {
00054     /**
00055      * Method enclosing the expression being walked.
00056      *
00057      */
00058     private SootMethod sm;
00059 
00060     /**
00061      * The analyzer object.
00062      *
00063      */
00064     private Analysis analyser;
00065 
00066     /**
00067      * Creates a new <code>TempExpr</code> instance.
00068      *
00069      */
00070     TempExpr()
00071     {
00072         analyser = Analysis.init();
00073     }
00074     /**
00075      * Triggers the walk.
00076      *
00077      * @param v the expression to be walked on.
00078      */
00079     void build(Value v)
00080     {
00081         v.apply(this);
00082     }
00083     /**
00084      * Handles the case when <code>caseArrayRef</code>s are encountered.
00085      *
00086      * @param v object representing the array reference.
00087      */
00088     public void caseArrayRef(ArrayRef v)
00089     {
00090         print(v, "ARRAYREFERENCE");
00091     }
00092     /**
00093      * Handles the case when <code>caseInstanceFieldRef</code>s are encountered.
00094      *
00095      * @param v object representing the instance field reference.
00096      */
00097     public void caseInstanceFieldRef(InstanceFieldRef v)
00098     {
00099         print(v, "INSTANCEFIELDREFERENCE");
00100     }
00101     /**
00102      * Handles the case when <code>caseInterfaceInvokeExpr</code>s are
00103      * encountered. 
00104      *
00105      * @param v object representing a interface invoke expression.
00106      */
00107     public void caseInterfaceInvokeExpr(InterfaceInvokeExpr v)
00108     {
00109         print(v, "INTERFACEMETHODINVOCATION");
00110     }
00111     /**
00112      * Handles the case when <code>Local</code>s are encountered.
00113      *
00114      * @param v object representing the local.
00115      */
00116     public void caseLocal(Local v)
00117     {
00118         print(v, "LOCALREFERENCE");
00119     }
00120     /**
00121      * Handles the case when <code>caseParameterRef</code>s are encountered.
00122      *
00123      * @param v object representing parameter reference.
00124      */
00125     public void caseParameterRef(ParameterRef v)
00126     {
00127         print(v, "PARAMETERREFERENCE");
00128     }
00129     /**
00130      * Handles the case when <code>caseSpecialInvokeExpr</code>s are encountered.
00131      *
00132      * @param v object representing a special invoke expression.
00133      */
00134     public void caseSpecialInvokeExpr(SpecialInvokeExpr v)
00135     {
00136         print(v, "SPECIALMETHODINVOCATION");
00137     }
00138     /**
00139      * Handles the case when <code>caseStaticFieldRef</code>s are encountered.
00140      *
00141      * @param v object representing static field reference.
00142      */
00143     public void caseStaticFieldRef(StaticFieldRef v)
00144     {
00145         print(v, "STATICFIELDREFERENCE");
00146     }
00147     /**
00148      * Handles the case when <code>caseThisRef</code>s are encountered.
00149      *
00150      * @param v object representing a reference to <code>this</code> variable.
00151      */
00152     public void caseThisRef(ThisRef v)
00153     {
00154         print(v, "THISREFERENCE");
00155     }
00156     /**
00157      * Handles the case when <code>caseVirtualInvokeExpr</code>s are encountered.
00158      *
00159      * @param v object representing a virtual invoke expression.
00160      */
00161     public void caseVirtualInvokeExpr(VirtualInvokeExpr v)
00162     {
00163         print(v, "VIRTUALMETHODINVOCATION");
00164     }
00165     /**
00166      * Handles cases which we donot intend to handle at this time.
00167      *
00168      * @param obj object representing anything.
00169      */
00170     public void defaultCase(Object obj)
00171     {
00172         System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + 
00173                            "xxxxxxxxxxxxxxxxxxx");
00174         System.out.println("TEST: We donot handle " + obj + ".");
00175         System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + 
00176                            "xxxxxxxxxxxxxxxxxxx");
00177     }
00178     /**
00179      * Performs initialization before proceeding with walking.
00180      *
00181      * @param sm the method enclosing the expression being walked.
00182      */
00183     void init(SootMethod sm)
00184     {
00185         this.sm = sm;
00186     }
00187     /**
00188      * A generic method to print all information available from the analysis
00189      * about the given expression.
00190      *
00191      * @param v the expression of interest.
00192      * @param s a parameterizing string.  This just is printed along with the
00193      * other information.
00194      */
00195     void print(Value v, String s)
00196     {
00197         Collection values = null;
00198         boolean b = true;
00199         Analysis.StmtMethodPair smp = null;
00200         
00201         if (!(v instanceof InvokeExpr)) {
00202             b = analyser.nullReference(v, sm);
00203             values = analyser.referenceValueSet(v, sm);
00204         } // end of if (v instanceOf InvokeExpr)
00205         if (v instanceof NonStaticInvokeExpr) {
00206             values = analyser.invokeExprResolution((NonStaticInvokeExpr)v, sm);
00207         } // end of if (v instanceof NonStaticInvokeExpr)
00208         
00209         System.out.println("-------------------------------------" + 
00210                            "-----------------------");
00211         System.out.println(s + " expression:" + v);
00212         System.out.println("# VALUES :" + values.size());
00213         
00214         for (Iterator t = values.iterator(); t.hasNext();) {
00215             Object i = t.next();
00216             if (i instanceof Analysis.ExprStmtMethodTriple) {
00217                 Analysis.ExprStmtMethodTriple a = 
00218                     (Analysis.ExprStmtMethodTriple)i;
00219                 System.out.println("{VALUE: " + a.getExpr() + 
00220                                    ", STMT: " + 
00221                                    a.getStmtMethodPair().getStmt() +
00222                                    ", Method: " + 
00223                                    a.getStmtMethodPair().getSootMethod() + 
00224                                    //  ", TYPE: " + a.getExpr().getClass() + 
00225                                    "}");
00226             } else {
00227                 System.out.println("{VALUE: " + i + ", TYPE: " + i.getClass() + 
00228                                    "}"); 
00229             } // end of else
00230         } // end of for ()
00231         if (b) {
00232             System.out.println("NULLNESS: Maybe.");
00233         } // end of if ()
00234         else {
00235             System.out.println("NULLNESS: Never.");
00236         } // end of else
00237         
00238         if (v instanceof Local || v instanceof Ref) {
00239             System.out.println("DEFINE sites:");
00240             for (Iterator i = analyser.getDefs(v, sm).iterator(); 
00241                  i.hasNext();) {
00242                 smp = (Analysis.StmtMethodPair)i.next();
00243                 System.out.println(smp.getSootMethod()+ "{" + smp.getStmt() + "}");
00244             } // end of for
00245             System.out.println("USE sites:");
00246             for (Iterator i = analyser.getUses(v, sm).iterator(); 
00247                  i.hasNext();) {
00248                 smp = (Analysis.StmtMethodPair)i.next();
00249                 System.out.println(smp.getSootMethod() + "{" + smp.getStmt() + 
00250                                    "}"); 
00251             } // end of for
00252         } // end of if (v instanceof Local)
00253     }
00254 }

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