Loading src/main/java/tfm/Main.java +8 −5 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import tfm.nodes.PDGNode; import tfm.scopes.ScopeHolder; import tfm.utils.Logger; import tfm.visitors.CFGVisitor; import tfm.visitors.PDGCFGVisitor; import tfm.visitors.PDGVisitor; import java.io.*; Loading @@ -26,12 +27,12 @@ public class Main { private static long t0; public static void main(String[] args) throws IOException, InterruptedException { File file = new File("/home/jacosro/IdeaProjects/TFM/src/main/java/tfm/programs/cfg/Eval_1.java"); File file = new File("/home/jacosro/IdeaProjects/TFM/src/main/java/tfm/programs/pdg/Example1.java"); CompilationUnit compilationUnit = JavaParser.parse(file); t0 = System.nanoTime(); Graph<?> graph = cfg(file, compilationUnit); Graph<?> graph = pdg(file, compilationUnit); long tt = System.nanoTime(); Loading Loading @@ -88,10 +89,12 @@ public class Main { } }; ScopeHolder<PDGNode> scopeHolder = new ScopeHolder<>(pdgGraph.getRootNode()); PDGVisitor visitor = new PDGVisitor(pdgGraph, scopeHolder); // ScopeHolder<PDGNode> scopeHolder = new ScopeHolder<>(pdgGraph.getRootNode()); // PDGVisitor visitor = new PDGVisitor(pdgGraph, scopeHolder); cu.accept(visitor, scopeHolder); PDGCFGVisitor visitor = new PDGCFGVisitor(pdgGraph); cu.accept(visitor, pdgGraph.getRootNode()); return pdgGraph; } Loading src/main/java/tfm/arcs/Arc.java +8 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,14 @@ public abstract class Arc<D extends ArcData> extends edg.graphlib.Arrow<String, ); } public Node getFromNode() { return (Node) super.getFrom(); } public Node getToNode() { return (Node) super.getTo(); } @Override public int hashCode() { return Objects.hashCode(getData()) + getFrom().hashCode() + getTo().hashCode(); Loading src/main/java/tfm/graphs/CFGGraph.java +2 −2 Original line number Diff line number Diff line Loading @@ -16,12 +16,12 @@ public abstract class CFGGraph extends Graph<CFGNode> { public CFGGraph() { super(); setRootVertex(new CFGNode(NodeId.getVertexId(), getRootNodeData(), new EmptyStmt())); setRootVertex(new CFGNode(getNextVertexId(), getRootNodeData(), new EmptyStmt())); } @Override public CFGNode addNode(String instruction, Statement statement) { CFGNode vertex = new CFGNode(NodeId.getVertexId(), instruction, statement); CFGNode vertex = new CFGNode(getNextVertexId(), instruction, statement); this.addVertex(vertex); return vertex; Loading src/main/java/tfm/graphs/Graph.java +38 −22 Original line number Diff line number Diff line Loading @@ -15,28 +15,30 @@ import java.util.stream.Collectors; * */ public abstract class Graph<NodeType extends Node> extends edg.graphlib.Graph<String, ArcData> { public final static class NodeId { private static int nextVertexId = 0; private int id; private NodeId(int id) { this.id = id; } static synchronized NodeId getVertexId() { return new NodeId(nextVertexId++); } public int getId() { return id; } @Override public String toString() { return String.valueOf(id); } } private int nextVertexId = 0; // public final static class NodeId { // private static int nextVertexId = 0; // // private int id; // // private NodeId(int id) { // this.id = id; // } // // static synchronized NodeId getVertexId() { // return new NodeId(nextVertexId++); // } // // public int getId() { // return id; // } // // @Override // public String toString() { // return String.valueOf(id); // } // } public Graph() { super(); Loading Loading @@ -91,6 +93,16 @@ public abstract class Graph<NodeType extends Node> extends edg.graphlib.Graph<St .findFirst(); } public Optional<NodeType> findNodeById(int id) { return findNodeById(String.valueOf(id)); } public Optional<NodeType> findNodeById(String id) { return getNodes().stream() .filter(node -> Objects.equals(node.getName(), id)) .findFirst(); } @SuppressWarnings("unchecked") public Set<NodeType> getNodes() { return getVerticies().stream() Loading @@ -113,4 +125,8 @@ public abstract class Graph<NodeType extends Node> extends edg.graphlib.Graph<St public abstract String toGraphvizRepresentation(); protected synchronized int getNextVertexId() { return nextVertexId++; } } src/main/java/tfm/graphs/PDGGraph.java +9 −2 Original line number Diff line number Diff line Loading @@ -23,14 +23,21 @@ import java.util.stream.Stream; public abstract class PDGGraph extends Graph<PDGNode> { public PDGGraph() { setRootVertex(new PDGNode(NodeId.getVertexId(), getRootNodeData(), new EmptyStmt())); setRootVertex(new PDGNode(getNextVertexId(), getRootNodeData(), new EmptyStmt())); } protected abstract String getRootNodeData(); public <N extends Node> PDGNode addNode(N node) { PDGNode vertex = new PDGNode(getNextVertexId(), node); super.addVertex(vertex); return vertex; } @Override public PDGNode addNode(String instruction, Statement statement) { PDGNode vertex = new PDGNode(NodeId.getVertexId(), instruction, statement); PDGNode vertex = new PDGNode(getNextVertexId(), instruction, statement); super.addVertex(vertex); return vertex; Loading Loading
src/main/java/tfm/Main.java +8 −5 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import tfm.nodes.PDGNode; import tfm.scopes.ScopeHolder; import tfm.utils.Logger; import tfm.visitors.CFGVisitor; import tfm.visitors.PDGCFGVisitor; import tfm.visitors.PDGVisitor; import java.io.*; Loading @@ -26,12 +27,12 @@ public class Main { private static long t0; public static void main(String[] args) throws IOException, InterruptedException { File file = new File("/home/jacosro/IdeaProjects/TFM/src/main/java/tfm/programs/cfg/Eval_1.java"); File file = new File("/home/jacosro/IdeaProjects/TFM/src/main/java/tfm/programs/pdg/Example1.java"); CompilationUnit compilationUnit = JavaParser.parse(file); t0 = System.nanoTime(); Graph<?> graph = cfg(file, compilationUnit); Graph<?> graph = pdg(file, compilationUnit); long tt = System.nanoTime(); Loading Loading @@ -88,10 +89,12 @@ public class Main { } }; ScopeHolder<PDGNode> scopeHolder = new ScopeHolder<>(pdgGraph.getRootNode()); PDGVisitor visitor = new PDGVisitor(pdgGraph, scopeHolder); // ScopeHolder<PDGNode> scopeHolder = new ScopeHolder<>(pdgGraph.getRootNode()); // PDGVisitor visitor = new PDGVisitor(pdgGraph, scopeHolder); cu.accept(visitor, scopeHolder); PDGCFGVisitor visitor = new PDGCFGVisitor(pdgGraph); cu.accept(visitor, pdgGraph.getRootNode()); return pdgGraph; } Loading
src/main/java/tfm/arcs/Arc.java +8 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,14 @@ public abstract class Arc<D extends ArcData> extends edg.graphlib.Arrow<String, ); } public Node getFromNode() { return (Node) super.getFrom(); } public Node getToNode() { return (Node) super.getTo(); } @Override public int hashCode() { return Objects.hashCode(getData()) + getFrom().hashCode() + getTo().hashCode(); Loading
src/main/java/tfm/graphs/CFGGraph.java +2 −2 Original line number Diff line number Diff line Loading @@ -16,12 +16,12 @@ public abstract class CFGGraph extends Graph<CFGNode> { public CFGGraph() { super(); setRootVertex(new CFGNode(NodeId.getVertexId(), getRootNodeData(), new EmptyStmt())); setRootVertex(new CFGNode(getNextVertexId(), getRootNodeData(), new EmptyStmt())); } @Override public CFGNode addNode(String instruction, Statement statement) { CFGNode vertex = new CFGNode(NodeId.getVertexId(), instruction, statement); CFGNode vertex = new CFGNode(getNextVertexId(), instruction, statement); this.addVertex(vertex); return vertex; Loading
src/main/java/tfm/graphs/Graph.java +38 −22 Original line number Diff line number Diff line Loading @@ -15,28 +15,30 @@ import java.util.stream.Collectors; * */ public abstract class Graph<NodeType extends Node> extends edg.graphlib.Graph<String, ArcData> { public final static class NodeId { private static int nextVertexId = 0; private int id; private NodeId(int id) { this.id = id; } static synchronized NodeId getVertexId() { return new NodeId(nextVertexId++); } public int getId() { return id; } @Override public String toString() { return String.valueOf(id); } } private int nextVertexId = 0; // public final static class NodeId { // private static int nextVertexId = 0; // // private int id; // // private NodeId(int id) { // this.id = id; // } // // static synchronized NodeId getVertexId() { // return new NodeId(nextVertexId++); // } // // public int getId() { // return id; // } // // @Override // public String toString() { // return String.valueOf(id); // } // } public Graph() { super(); Loading Loading @@ -91,6 +93,16 @@ public abstract class Graph<NodeType extends Node> extends edg.graphlib.Graph<St .findFirst(); } public Optional<NodeType> findNodeById(int id) { return findNodeById(String.valueOf(id)); } public Optional<NodeType> findNodeById(String id) { return getNodes().stream() .filter(node -> Objects.equals(node.getName(), id)) .findFirst(); } @SuppressWarnings("unchecked") public Set<NodeType> getNodes() { return getVerticies().stream() Loading @@ -113,4 +125,8 @@ public abstract class Graph<NodeType extends Node> extends edg.graphlib.Graph<St public abstract String toGraphvizRepresentation(); protected synchronized int getNextVertexId() { return nextVertexId++; } }
src/main/java/tfm/graphs/PDGGraph.java +9 −2 Original line number Diff line number Diff line Loading @@ -23,14 +23,21 @@ import java.util.stream.Stream; public abstract class PDGGraph extends Graph<PDGNode> { public PDGGraph() { setRootVertex(new PDGNode(NodeId.getVertexId(), getRootNodeData(), new EmptyStmt())); setRootVertex(new PDGNode(getNextVertexId(), getRootNodeData(), new EmptyStmt())); } protected abstract String getRootNodeData(); public <N extends Node> PDGNode addNode(N node) { PDGNode vertex = new PDGNode(getNextVertexId(), node); super.addVertex(vertex); return vertex; } @Override public PDGNode addNode(String instruction, Statement statement) { PDGNode vertex = new PDGNode(NodeId.getVertexId(), instruction, statement); PDGNode vertex = new PDGNode(getNextVertexId(), instruction, statement); super.addVertex(vertex); return vertex; Loading