public TranslationResult run() {
Map<String,String> namespaces = findNamespaces();
config.modifyNamespaces(namespaces);
Map<String,Origin> schemas = findSchemas();
FlowGraph graph = new FlowGraph(schemas, namespaces);
TranslatorContext context = new TranslatorContext(graph, errors);
Translator translator = new Translator(context, config);
// create methods and parse field annotations
for (SootClass c : Scene.v().getApplicationClasses()) {
for (SootMethod m : c.getMethods()) {
Origin origin = new Origin(c.getName() + "." + m.getName(), 0, 0);
Statement methodentry, methodexit;
Variable returnVar;
Variable[] parameters = new Variable[m.getParameterCount()];
if (m.isConcrete()) {
// entry
methodentry = new NopStm(origin, "method entry");
graph.addNode(methodentry);
// exit
methodexit = new NopStm(origin, "method exit");
graph.addNode(methodexit);
// parameters
for (int i=0; i<m.getParameterCount(); i++) {
parameters[i] = new Variable(context.getNextVarID(), false);
}
// return var
returnVar = new Variable(context.getNextVarID(), false);
// externally callable
if (config.isExternallyCallable(m)) {
graph.addEntry(methodentry);
}
} else {
// non-concrete method. it must still be created for annotations to
// be visible.
methodentry = methodexit = null;
returnVar = null;
}
// parse annotations
SchemaType returnType;
if (context.isAnnotatableType(m.getReturnType())) {
returnType = context.parseSchemaType(config.getMethodReturnType(m, context.getTypeAnnotation(m)), origin);
} else {
returnType = null;
}
SchemaType[] paramTypes = new SchemaType[m.getParameterCount()];
for (int i=0; i<m.getParameterCount(); i++) {
if (context.isAnnotatableType(m.getParameterType(i))) {
paramTypes[i] = context.parseSchemaType(config.getMethodParameterType(m, i, context.getTypeAnnotationForParameter(m, i)), origin);
}
}
// make the method
Method method = new Method(m.getName(), methodentry, methodexit, parameters, returnVar, returnType, paramTypes);
context.setMethod(m, method);
}
for (SootField f : c.getFields()) {
// parse annotations
if (context.isAnnotatableType(f.getType())) {
Origin origin = new Origin(c.getName() + "." + f.getName(), 0, 0);
context.setFieldSchemaType(f, context.parseSchemaType(config.getFieldType(f, context.getTypeAnnotation(f)), origin));
}
}
}
// translate!
for (SootClass c : Scene.v().getApplicationClasses()) {
context.setCurrentClass(c);
for (SootMethod m : c.getMethods()) {
if (!m.isConcrete())
continue;
context.setCurrentSootMethod(m);
CompleteUnitGraph unitgraph = new CompleteUnitGraph(m.retrieveActiveBody());
context.setNullness(new NullnessAnalysis(unitgraph));
context.setStringConstants(new StringConstantAnalysis(unitgraph));
context.setArrayConstants(new ArrayConstantAnalysis(unitgraph));
Method method = context.getMethod(m);
Map<Unit,StatementPair> translated = new HashMap<Unit,StatementPair>();
for (Unit stmt : m.getActiveBody().getUnits()) {
context.setCurrentUnit(stmt);
context.setCurrentLine(getLineNumber(stmt));
translated.put(stmt, translator.translateStmt((Stmt)stmt));
}
for (Map.Entry<Unit, StatementPair> entry : translated.entrySet()) {
Unit stmt = entry.getKey();
StatementPair translation = entry.getValue();
// add successors
for (Unit next : unitgraph.getSuccsOf(stmt)) {
StatementPair nextt = translated.get(next);
graph.addEdge(translation.last, nextt.first, new VariableFilter());
}
// add (exceptional) return edge
graph.addEdge(translation.last, method.getExit(), new VariableFilter());
}
// add entry edges
for (Unit head : unitgraph.getHeads()) {
graph.addEdge(method.getEntry(), translated.get(head).first, new VariableFilter(true, VariableFilter.Kind.ENTRY));
}
}
}
// run string analysis