Newer
Older
package tfm.exec;
import com.github.javaparser.JavaParser;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.MethodDeclaration;
import tfm.graphs.CFG;
import tfm.graphs.Graph;
import tfm.graphs.PDG;
import tfm.graphs.SDG;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
import java.util.Optional;
public class Main {
public static final String PROGRAM = Utils.PROGRAMS_FOLDER + "cfg/Eval_4.java";
public static void main(String[] args) throws IOException {
JavaParser.getStaticConfiguration().setAttributeComments(false);
// File
File file = new File(PROGRAM);
Node root = JavaParser.parse(file);
if (!METHOD.isEmpty()) {
Optional<MethodDeclaration> methodDeclarationOptional = root.findFirst(MethodDeclaration.class,
methodDeclaration -> Objects.equals(methodDeclaration.getNameAsString(), METHOD));
if (!methodDeclarationOptional.isPresent()) {
Logger.format("Method '%s' not found in '%s'. Exiting...", METHOD, PROGRAM);
return;
}
root = methodDeclarationOptional.get();
}
Graph graph = getBuiltGraph(args.length == 1 ? args[0] : GRAPH, (MethodDeclaration) root);
long tf = System.nanoTime();
long tt = tf - t0;
graphLog.log();
graphLog.openVisualRepresentation();
Logger.log();
Logger.format("Graph generated in %.2f ms", tt / 10e6);
}
private static Graph getBuiltGraph(String graph, MethodDeclaration method) {
CFG cfg = new CFG();
cfg.build(method);
return cfg;
PDG pdg = new PDG();
pdg.build(method);
return pdg;
Logger.log("Not yet considered!");
return new SDG();
default:
Logger.log("Unkown graph type");
System.exit(1);
private static GraphLog<?> getGraphLog(Graph graph) {
if (graph instanceof CFG)
return new CFGLog((CFG) graph);
else if (graph instanceof PDG)
return new PDGLog((PDG) graph);
else if (graph instanceof SDG)
return new SDGLog((SDG) graph);
Logger.log("Unknown graph type");
System.exit(1);
return null;