00001 package edu.ksu.cis.bandera.specification.predicate;
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 edu.ksu.cis.bandera.jjjc.symboltable.*;
00036 import edu.ksu.cis.bandera.pdgslicer.datastructure.*;
00037 import edu.ksu.cis.bandera.annotation.*;
00038 import edu.ksu.cis.bandera.jjjc.*;
00039 import ca.mcgill.sable.soot.*;
00040 import ca.mcgill.sable.soot.jimple.*;
00041 import java.util.*;
00042 import edu.ksu.cis.bandera.specification.predicate.datastructure.*;
00043
00044 public class PredicateSliceInterestCollector {
00045 private static HashSet sliceInterests;
00046
00047
00048
00049
00050
00051 public static Collection collect(Collection predicates) {
00052 Jimple jimple = Jimple.v();
00053 sliceInterests = new HashSet();
00054 for (Iterator i = predicates.iterator(); i.hasNext();) {
00055 Predicate p = (Predicate) i.next();
00056
00057 try {
00058 Annotation a = p.getAnnotation();
00059 if (a instanceof LabeledStmtAnnotation) {
00060 a = CompilationManager.getAnnotationManager().getMethodAnnotationContainingAnnotation(a);
00061 }
00062 SootClass sc = CompilationManager.getSootClassManager().getClass(p.getType().getName().toString());
00063 SootMethod sm = null;
00064 if (a != null) {
00065 Stmt[] stmts = p.getAnnotation().getStatements();
00066 sm = (a instanceof MethodDeclarationAnnotation) ?
00067 ((MethodDeclarationAnnotation) a).getSootMethod() :
00068 ((ConstructorDeclarationAnnotation) a).getSootMethod();
00069 if (p instanceof ReturnPredicate) {
00070 for (int k = 0; k < stmts.length; k++) {
00071 if ((stmts[k] instanceof ReturnStmt) || ((stmts[k] instanceof ReturnVoidStmt))) {
00072 int sind = SlicePoint.getStmtIndex(sm,(Stmt) stmts[k]);
00073 sliceInterests.add(new SlicePoint(sc, sm, stmts[k],sind));
00074 if (((ReturnPredicate) p).hasRet()) {
00075 sliceInterests.add(new SliceLocal(sc, sm, (Local) ((ReturnStmt) stmts[k]).getReturnValue()));
00076 }
00077 }
00078 }
00079 } else {
00080 int sind = SlicePoint.getStmtIndex(sm,(Stmt) stmts[0]);
00081 sliceInterests.add(new SlicePoint(sc, sm, stmts[0],sind));
00082 }
00083 }
00084 if (p.getConstraint() != null) {
00085 for (Enumeration e = p.getVariablesUsed().elements(); e.hasMoreElements();) {
00086 Object o = e.nextElement();
00087 if (o instanceof Local) {
00088 sliceInterests.add(new SliceLocal(sc, sm, (Local) o));
00089 } else if (o instanceof Field) {
00090 try {
00091 SootClass sootClass = CompilationManager.getSootClassManager().getClass(((Field) o).getDeclaringClassOrInterface().getName().toString());
00092 SootField sf = sootClass.getField(((Field) o).getName().toString());
00093 sliceInterests.add(new SliceField(sootClass, sf));
00094 } catch (Exception ex) {}
00095 } else if ("this".equals(o)) {
00096 if (sm != null) {
00097 try {
00098 Local l = ((JimpleBody) sm.getBody(jimple)).getLocal("JJJCTEMP$0");
00099 sliceInterests.add(new SliceLocal(sc, sm, l));
00100 } catch (Exception ex) {}
00101 }
00102 }
00103 }
00104 }
00105 } catch (Exception exc) {}
00106 }
00107 return sliceInterests;
00108 }
00109 }