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.*;
00036 import edu.ksu.cis.bandera.jjjc.symboltable.*;
00037 import edu.ksu.cis.bandera.jjjc.symboltable.Package;
00038 import java.io.*;
00039 import java.util.*;
00040 import edu.ksu.cis.bandera.jjjc.doc.*;
00041 import edu.ksu.cis.bandera.specification.predicate.parser.*;
00042 import edu.ksu.cis.bandera.specification.predicate.lexer.*;
00043 import edu.ksu.cis.bandera.specification.predicate.node.*;
00044 import edu.ksu.cis.bandera.specification.predicate.ast.*;
00045 import edu.ksu.cis.bandera.specification.predicate.datastructure.*;
00046 import edu.ksu.cis.bandera.annotation.*;
00047 import ca.mcgill.sable.soot.*;
00048 public class PredicateExtractor {
00049 private static AnnotationManager am;
00050 private static SootClassManager scm;
00051
00052
00053
00054
00055
00056
00057 public static void extract(SootClass sc, SootMethod sm, Vector tags) {
00058 scm = CompilationManager.getSootClassManager();
00059 am = CompilationManager.getAnnotationManager();
00060 for (Iterator i = tags.iterator(); i.hasNext();) {
00061 String tag = (String) i.next();
00062 if ("@observable".equals(new StringTokenizer(tag).nextToken())) {
00063 try {
00064 process(parse(tag.substring(12)), sc, sm);
00065 } catch (Exception e) {
00066 e.printStackTrace();
00067 }
00068 }
00069 }
00070 }
00071
00072
00073
00074
00075 public static void main(String[] args) throws Exception {
00076 String s = "predset1\n"
00077 + "// hi\n"
00078 + "\n"
00079 + "RETURN a: (test..test.test.test..test.i > 0)\n"
00080 + "// this does this...\n";
00081 try {
00082 System.out.println(new Parser(new Lexer(new PushbackReader(new StringReader(s)))).parse());
00083 } catch (Exception e) {
00084 e.printStackTrace();
00085 }
00086 }
00087
00088
00089
00090
00091
00092 private static Node parse(String text) throws Exception {
00093 Simplifier.reset();
00094 Node node = Simplifier.simplify(new Parser(new Lexer(new PushbackReader(new StringReader(text)))).parse());
00095 if (Simplifier.getExceptions().size() > 0) {
00096 for (Enumeration e = Simplifier.getExceptions().elements(); e.hasMoreElements();) {
00097 System.out.println(e.nextElement());
00098 }
00099 }
00100
00101
00102 return node;
00103 }
00104
00105
00106
00107
00108
00109
00110 private static void process(Node node, SootClass sc, SootMethod sm) {
00111 ClassOrInterfaceType classOrInterfaceType = null;
00112 SymbolTable symbolTable = null;
00113 try {
00114 classOrInterfaceType = Package.getClassOrInterfaceType(new Name(sc.getName()));
00115 symbolTable = classOrInterfaceType.getSymbolTable();
00116 } catch (Exception e) {
00117 }
00118 TypeChecker typeChecker;
00119 if (sm == null) {
00120 typeChecker = new TypeChecker(node, symbolTable, classOrInterfaceType, null);
00121 } else {
00122 typeChecker = new TypeChecker(node, symbolTable, classOrInterfaceType, am.getAnnotation(sc, sm));
00123 }
00124 typeChecker.check();
00125 }
00126 }