00001 package edu.ksu.cis.bandera.report;
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 java.io.*;
00036 import java.util.*;
00037 import ca.mcgill.sable.soot.*;
00038 import ca.mcgill.sable.soot.jimple.*;
00039 import edu.ksu.cis.bandera.abstraction.typeinference.*;
00040 public class SLABSReport implements Report {
00041 private String typeInfo;
00042
00043
00044
00045 public String getFilename() {
00046 return "slabs.report";
00047 }
00048
00049
00050
00051 public String getTextRepresentation() {
00052 return typeInfo;
00053 }
00054
00055
00056
00057
00058 public void setTypeTable(TypeTable t) {
00059 StringWriter sw = new StringWriter();
00060 PrintWriter pw = new PrintWriter(sw);
00061
00062 pw.println("SLABS Report");
00063 pw.println("============");
00064 pw.println("");
00065 pw.println("");
00066 pw.println("");
00067
00068 pw.println("Type Info");
00069 pw.println("---------");
00070 pw.println("");
00071
00072 Hashtable h = edu.ksu.cis.bandera.jjjc.CompilationManager.getCompiledClasses();
00073
00074 TreeSet classNames = new TreeSet();
00075 for (Enumeration e = h.keys(); e.hasMoreElements();) {
00076 classNames.add(e.nextElement());
00077 }
00078
00079 for (Iterator i = classNames.iterator(); i.hasNext();) {
00080 String className = (String) i.next();
00081 pw.println("class " + className + " {");
00082
00083 SootClass sc = (SootClass) h.get(className);
00084
00085 TreeSet fieldNames = new TreeSet();
00086 Object[] sootFields = sc.getFields().toArray();
00087 for (int j = 0; j < sootFields.length; j++) {
00088 fieldNames.add(((SootField) sootFields[j]).getName());
00089 }
00090
00091 for (Iterator j = fieldNames.iterator(); j.hasNext();) {
00092 String fieldName = (String) j.next();
00093 SootField sf = sc.getField(fieldName);
00094 pw.println(" " + sf.getName() + " : " + t.get(sf));
00095 }
00096
00097 TreeSet methodSignatures = new TreeSet();
00098 Hashtable methodTable = new Hashtable();
00099 Object[] sootMethods = sc.getMethods().toArray();
00100 for (int j = 0; j < sootMethods.length; j++) {
00101 SootMethod sm = (SootMethod) sootMethods[j];
00102 String methodSignature = sm.toString();
00103 methodSignatures.add(methodSignature);
00104 methodTable.put(methodSignature, sm);
00105 }
00106
00107 for (Iterator j = methodSignatures.iterator(); j.hasNext();) {
00108 String methodSignature = (String) j.next();
00109
00110 pw.println(" " + methodSignature + " {");
00111
00112 SootMethod sm = (SootMethod) methodTable.get(methodSignature);
00113 JimpleBody jb = (JimpleBody) sm.getBody(Jimple.v());
00114
00115 TreeSet localNames = new TreeSet();
00116 Object[] locals = jb.getLocals().toArray();
00117
00118 for (int k = 0; k < locals.length; k++) {
00119 localNames.add(((Local) locals[k]).getName());
00120 }
00121
00122 for (Iterator k = localNames.iterator(); k.hasNext();) {
00123 String localName = (String) k.next();
00124 Local l = jb.getLocal(localName);
00125 pw.println(" " + localName + " : " + t.get(l));
00126 }
00127
00128 pw.println(" }");
00129 }
00130
00131 pw.println("}");
00132 pw.println("");
00133 }
00134
00135 typeInfo = sw.toString();
00136 }
00137 }