00001 package edu.ksu.cis.bandera.abstraction.predicate.parser;
00002
00003
00004
00005
00006
00007
00008 import java.util.*;
00009 import ca.mcgill.sable.soot.*;
00010 import ca.mcgill.sable.soot.jimple.*;
00011 import ca.mcgill.sable.soot.grimp.*;
00012
00013 public class PredicateImpl implements Predicate {
00014 private String name;
00015 private Value v = null;
00016 private SootClass cls = null;
00017 private SootMethod method = null;
00018 private boolean global = false;
00019 private SimpleNode ast = null;
00020 private String methodName = null;
00021 private String className = null;
00022 private List args = null;
00023 public PredicateImpl() {}
00024
00025
00026
00027 public PredicateImpl(String n) {
00028 name = n;
00029 }
00030 public SootClass getClassContext()
00031 {
00032 if (cls == null) cls = PredicateProcessor.getSootClass(className);
00033 return cls;
00034 }
00035 public String getClassName() { return className; }
00036
00037
00038
00039
00040 public Value getExpr() {
00041 return v;
00042 }
00043 public SimpleNode getExprAST() { return ast; }
00044 public SootMethod getMethodContext()
00045 {
00046 if (method == null)
00047 {
00048 method = PredicateProcessor.getSootMethod(className, methodName, args);
00049 }
00050 return method;
00051 }
00052
00053
00054
00055
00056 public String getName() {
00057 return name;
00058 }
00059 public boolean isGlobal() { return global; }
00060 public void resolveArgs(PredicateProcessor v)
00061 {
00062 LinkedList ll = new LinkedList();
00063 for (Iterator i = args.iterator(); i.hasNext();)
00064 {
00065 ll.addLast(((ASTType) i.next()).jjtAccept(v, this));
00066 }
00067 args = ll;
00068 }
00069 public void setClassContext(String s)
00070 {
00071 className = s;
00072 }
00073 public void setContext(SootClass sc, SootMethod sm)
00074 {
00075 if (sc == null) throw new RuntimeException("Cannot set null context on predicates!");
00076 if (isGlobal())
00077 {
00078 if (sm == null)
00079 {
00080
00081 return;
00082 }
00083 if (method != null)
00084 throw new RuntimeException("Local access can't be brought into global scope! It's a bug!!");
00085
00086
00087
00088
00089
00090 global = false;
00091
00092
00093 cls = sc;
00094 method = sm;
00095 } else if (cls == null)
00096 {
00097 cls = sc;
00098 method = sm;
00099 } else
00100 {
00101 if (cls.getName().equals(sc.getName()))
00102 {
00103
00104 if (method == null)
00105 {
00106 method = sm;
00107 } else
00108 {
00109
00110
00111 if (sm != null && !sm.getName().equals(method))
00112 throw new RuntimeException("Cannot compare locals in different methods!");
00113 }
00114 } else
00115 {
00116
00117
00118
00119
00120
00121 if (sm != null && method != null)
00122 {
00123 if (!sm.getName().equals(method))
00124 {
00125 throw new RuntimeException("Cannot compare locals in different methods (and even worse: in different class)!");
00126 }
00127 } else if (method == null && sm != null)
00128 {
00129
00130
00131 method = sm;
00132 cls = sc;
00133 } else if (method != null && sm == null)
00134 {
00135
00136
00137 } else
00138 {
00139
00140 global = true;
00141 }
00142 }
00143 }
00144 }
00145
00146
00147
00148
00149 public void setExpr(Value newV) {
00150 v = newV;
00151 }
00152 public void setExprAST(SimpleNode n) { ast = n; }
00153 public void setMethodContext(String s, List a)
00154 {
00155 methodName = s; args = a;
00156 }
00157
00158
00159
00160
00161 public void setName(String newName) {
00162 name = newName;
00163 }
00164 public String toString() { return name; }
00165 }