1 19 20 package soot.javaToJimple; 21 import polyglot.main.*; 22 import polyglot.frontend.*; 23 import polyglot.util.*; 24 import polyglot.visit.*; 25 import polyglot.ast.*; 26 27 import java.util.*; 28 import java.io.*; 29 30 public class JavaToJimple { 31 32 public static final polyglot.frontend.Pass.ID CAST_INSERTION = new polyglot.frontend.Pass.ID("cast-insertion"); 33 public static final polyglot.frontend.Pass.ID STRICTFP_PROP = new polyglot.frontend.Pass.ID("strictfp-prop"); 34 public static final polyglot.frontend.Pass.ID ANON_CONSTR_FINDER = new polyglot.frontend.Pass.ID("anon-constr-finder"); 35 public static final polyglot.frontend.Pass.ID SAVE_AST = new polyglot.frontend.Pass.ID("save-ast"); 36 37 40 public polyglot.frontend.ExtensionInfo initExtInfo(String fileName, List sourceLocations){ 41 42 Set source = new HashSet(); 43 ExtensionInfo extInfo = new soot.javaToJimple.jj.ExtensionInfo() { 44 public List passes(Job job) { 45 List passes = super.passes(job); 46 beforePass(passes, Pass.EXIT_CHECK, new VisitorPass(CAST_INSERTION, job, new CastInsertionVisitor(job, ts, nf))); 48 beforePass(passes, Pass.EXIT_CHECK, new VisitorPass(STRICTFP_PROP, job, new StrictFPPropagator(false))); 49 beforePass(passes, Pass.EXIT_CHECK, new VisitorPass(ANON_CONSTR_FINDER, job, new AnonConstructorFinder(job, ts, nf))); 50 afterPass(passes, Pass.PRE_OUTPUT_ALL, new SaveASTVisitor(SAVE_AST, job, this)); 51 removePass(passes, Pass.OUTPUT); 52 return passes; 53 } 54 55 }; 56 polyglot.main.Options options = extInfo.getOptions(); 57 58 options.assertions = true; 59 options.source_path = new LinkedList(); 60 Iterator it = sourceLocations.iterator(); 61 while (it.hasNext()){ 62 Object next = it.next(); 63 options.source_path.add(new File(next.toString())); 65 } 66 67 options.source_ext = new String []{"java"}; 68 options.serialize_type_info = false; 69 70 source.add(fileName); 71 72 options.source_path.add(new File(fileName).getParentFile()); 73 74 polyglot.main.Options.global = options; 75 76 return extInfo; 77 } 78 79 82 public polyglot.ast.Node compile(polyglot.frontend.Compiler compiler, String fileName, polyglot.frontend.ExtensionInfo extInfo){ 83 SourceLoader source_loader = compiler.sourceExtension().sourceLoader(); 84 85 try { 86 FileSource source = new FileSource(new File(fileName)); 87 if(false) throw new IOException("Bogus exception"); 91 92 SourceJob job = null; 93 94 if (compiler.sourceExtension() instanceof soot.javaToJimple.jj.ExtensionInfo){ 95 soot.javaToJimple.jj.ExtensionInfo jjInfo = (soot.javaToJimple.jj.ExtensionInfo)compiler.sourceExtension(); 96 if (jjInfo.sourceJobMap() != null){ 97 job = (SourceJob)jjInfo.sourceJobMap().get(source); 98 } 99 } 100 if (job == null){ 101 job = compiler.sourceExtension().addJob(source); 102 } 103 104 boolean result = false; 105 result = compiler.sourceExtension().runToCompletion(); 106 107 if (!result) { 108 109 throw new soot.CompilationDeathException(0, "Could not compile"); 110 } 111 112 113 114 polyglot.ast.Node node = job.ast(); 115 116 return node; 117 118 } 119 catch (IOException e){ 120 return null; 121 } 122 123 } 124 125 } 126
| Popular Tags
|