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

JimpleStore.java

00001 package edu.ksu.cis.bandera.birc;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 1998, 1999   James Corbett (corbett@hawaii.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.SootField;
00036 import ca.mcgill.sable.soot.SootMethod;
00037 import ca.mcgill.sable.soot.SootClass;
00038 import ca.mcgill.sable.soot.jimple.Local;
00039 
00040 import edu.ksu.cis.bandera.bir.*;
00041 
00042 import java.util.*;
00043 
00044 /**
00045  * A Jimple store (encode the values of the variables at a given state)
00046  */
00047 
00048 public class JimpleStore implements BirConstants {
00049 
00050     Vector variables = new Vector();  // Variables (Local or SootField)
00051     Hashtable values =      // Map variable --> JimpleLiteral
00052     new Hashtable();
00053     JimpleLiteralPrinter printer;
00054     String output;
00055     TransSystem system;
00056     BirState state;
00057  
00058     JimpleStore(BirState state) { 
00059     this.state = state;
00060     this.output = state.getOutput();
00061     this.system = state.getSystem();
00062 
00063     // For each state variable, translate the BIR value of 
00064     // that variable into a Jimple literal and store it
00065     // with the Jimple variable that the state variable represents.
00066     JimpleStoreBuilder builder = new JimpleStoreBuilder(state);
00067     StateVarVector vars = system.getStateVars();
00068     for (int i = 0; i < vars.size(); i++) {
00069         StateVar var = vars.elementAt(i);
00070         if (! var.getType().isKind(COLLECTION)) {
00071         Object jvar = system.getSource(var);
00072         variables.addElement(jvar);
00073         var.getType().apply(builder,var);
00074         JimpleLiteral jvalue = (JimpleLiteral) builder.getResult();
00075         values.put(jvar,jvalue);
00076         }
00077     }
00078     }
00079     /**
00080      * Get value of Jimple local variable
00081      * @param method Soot method containing local
00082      * @param local Local representing variable
00083      */
00084 
00085     public JimpleLiteral getLocalValue(SootMethod method, Local local) {
00086     String key = ExprExtractor.localKey(method,local);
00087     return (JimpleLiteral) values.get(key);
00088     }
00089     /**
00090      * Get output at state (this is a String containing the concatenation
00091      * of all Bandera.print() statements up to this point in the trace).
00092      */
00093 
00094     public String getOuput() {
00095     return output;
00096     }
00097     /**
00098      * Get value of Jimple static field
00099      * @param Soot field (must be static)
00100      */
00101 
00102     public JimpleLiteral getStaticFieldValue(SootField field) {
00103     return (JimpleLiteral) values.get(field);
00104     }
00105     /**
00106      * Get Vector of SootMethods representing threads
00107      */
00108 
00109     public Vector getThreads() {
00110     Vector methods = new Vector();
00111     ThreadVector threads = system.getThreads();
00112     for (int i = 0; i < threads.size(); i++) {
00113         BirThread thread = threads.elementAt(i);
00114         SootMethod method = (SootMethod) system.getSource(thread);
00115         methods.addElement(method);
00116     }
00117     return methods;
00118     }
00119     /**
00120      * Is thread active?
00121      * @param method Soot method representing thread body
00122      */
00123 
00124     public boolean isActive(SootMethod method) {
00125     BirThread thread = system.threadOfKey(method);
00126     if (thread == null)
00127         throw new RuntimeException("Thread not found for: " + method);
00128     return state.isActive(thread);
00129     }
00130     /**
00131      * Print store
00132      */
00133 
00134     public void print() {
00135     printer = new JimpleLiteralPrinter("  ");
00136     System.out.println("Jimple Store:");
00137     Vector threadMethods = getThreads();
00138     for (int i = 0; i < threadMethods.size(); i++) {
00139         SootMethod method = (SootMethod)threadMethods.elementAt(i);
00140         if (isActive(method))
00141         System.out.println("  Thread " + 
00142                    method.getDeclaringClass().getName());
00143     }
00144     for (int i = 0; i < variables.size(); i++) {
00145         System.out.print("  " + variables.elementAt(i) + " = ");
00146         JimpleLiteral value = 
00147         (JimpleLiteral) values.get(variables.elementAt(i));
00148         value.apply(printer);
00149         System.out.println();
00150     }
00151     printer.flush();
00152     }
00153 }

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