00001 package edu.ksu.cis.bandera.birc;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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
00046
00047
00048 public class JimpleStore implements BirConstants {
00049
00050 Vector variables = new Vector();
00051 Hashtable values =
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
00064
00065
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
00081
00082
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
00091
00092
00093
00094 public String getOuput() {
00095 return output;
00096 }
00097
00098
00099
00100
00101
00102 public JimpleLiteral getStaticFieldValue(SootField field) {
00103 return (JimpleLiteral) values.get(field);
00104 }
00105
00106
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
00121
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
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 }