Loading src/main/java/tfm/arcs/Arc.java +21 −3 Original line number Diff line number Diff line package tfm.arcs; import tfm.arcs.data.ArcData; import org.jgrapht.graph.DefaultEdge; import org.jgrapht.io.Attribute; import tfm.arcs.cfg.ControlFlowArc; import tfm.arcs.pdg.ControlDependencyArc; import tfm.arcs.pdg.DataDependencyArc; import tfm.arcs.sdg.CallArc; import tfm.nodes.GraphNode; import java.util.Objects; Loading Loading @@ -37,8 +42,21 @@ public abstract class Arc<D extends ArcData> extends edg.graphlib.Arrow<String, ); } public GraphNode<?> getFromNode() { return (GraphNode<?>) super.getFrom(); /** @see CallArc */ public final boolean isCallArc() { return this instanceof CallArc; } public final CallArc asCallArc() { if (isCallArc()) return (CallArc) this; throw new UnsupportedOperationException("Not a CallArc"); } @Override public String toString() { return String.format("%s{%d -> %d}", getClass().getName(), ((GraphNode<?>) getSource()).getId(), ((GraphNode<?>) getTarget()).getId()); } public GraphNode<?> getToNode() { Loading src/main/java/tfm/arcs/sdg/CallArc.java 0 → 100644 +16 −0 Original line number Diff line number Diff line package tfm.arcs.sdg; import org.jgrapht.io.Attribute; import org.jgrapht.io.DefaultAttribute; import tfm.arcs.Arc; import java.util.Map; public class CallArc extends Arc { @Override public Map<String, Attribute> getDotAttributes() { Map<String, Attribute> map = super.getDotAttributes(); map.put("style", DefaultAttribute.createAttribute("dashed")); return map; } } src/main/java/tfm/arcs/sdg/ParameterInOutArc.java 0 → 100644 +16 −0 Original line number Diff line number Diff line package tfm.arcs.sdg; import org.jgrapht.io.Attribute; import org.jgrapht.io.DefaultAttribute; import tfm.arcs.Arc; import java.util.Map; public class ParameterInOutArc extends Arc { @Override public Map<String, Attribute> getDotAttributes() { Map<String, Attribute> map = super.getDotAttributes(); map.put("style", DefaultAttribute.createAttribute("dashed")); return map; } } src/main/java/tfm/exec/Main.java +4 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package tfm.exec; import com.github.javaparser.JavaParser; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.MethodDeclaration; import tfm.utils.Logger; import tfm.utils.Utils; Loading Loading @@ -63,8 +64,9 @@ public class Main { graphLog = new PDGLog(); break; case GraphLog.SDG: graphLog = new SDGLog(); break; SDG sdg = new SDG(); sdg.build(new NodeList<>(method.findCompilationUnit().get())); return sdg; default: Logger.log("Unkown graph type"); System.exit(1); Loading src/main/java/tfm/graphs/GraphWithRootNode.java 0 → 100644 +53 −0 Original line number Diff line number Diff line package tfm.graphs; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.MethodDeclaration; import tfm.nodes.GraphNode; import tfm.nodes.NodeFactory; import java.util.Objects; import java.util.Optional; public abstract class GraphWithRootNode<ASTRootNode extends Node> extends Graph implements Buildable<MethodDeclaration> { protected final int ROOT_NODE_ID = 0; protected GraphNode<ASTRootNode> rootNode; public GraphWithRootNode() { super(1); } /** * Builds the root node with the given instruction and AST node. * If the root node already exists, just returns false * * @param instruction the instruction string * @param rootNodeAst the AST node * @return true if the root node is created, false otherwise */ public boolean buildRootNode(String instruction, ASTRootNode rootNodeAst) { if (rootNode != null) { return false; } GraphNode<ASTRootNode> root = NodeFactory.graphNode(ROOT_NODE_ID, instruction, rootNodeAst); this.rootNode = root; this.addVertex(root); return true; } public Optional<GraphNode<ASTRootNode>> getRootNode() { return Optional.ofNullable(rootNode); } @Override public boolean removeVertex(GraphNode<?> graphNode) { if (Objects.equals(graphNode, rootNode)) { return false; } return super.removeVertex(graphNode); } } Loading
src/main/java/tfm/arcs/Arc.java +21 −3 Original line number Diff line number Diff line package tfm.arcs; import tfm.arcs.data.ArcData; import org.jgrapht.graph.DefaultEdge; import org.jgrapht.io.Attribute; import tfm.arcs.cfg.ControlFlowArc; import tfm.arcs.pdg.ControlDependencyArc; import tfm.arcs.pdg.DataDependencyArc; import tfm.arcs.sdg.CallArc; import tfm.nodes.GraphNode; import java.util.Objects; Loading Loading @@ -37,8 +42,21 @@ public abstract class Arc<D extends ArcData> extends edg.graphlib.Arrow<String, ); } public GraphNode<?> getFromNode() { return (GraphNode<?>) super.getFrom(); /** @see CallArc */ public final boolean isCallArc() { return this instanceof CallArc; } public final CallArc asCallArc() { if (isCallArc()) return (CallArc) this; throw new UnsupportedOperationException("Not a CallArc"); } @Override public String toString() { return String.format("%s{%d -> %d}", getClass().getName(), ((GraphNode<?>) getSource()).getId(), ((GraphNode<?>) getTarget()).getId()); } public GraphNode<?> getToNode() { Loading
src/main/java/tfm/arcs/sdg/CallArc.java 0 → 100644 +16 −0 Original line number Diff line number Diff line package tfm.arcs.sdg; import org.jgrapht.io.Attribute; import org.jgrapht.io.DefaultAttribute; import tfm.arcs.Arc; import java.util.Map; public class CallArc extends Arc { @Override public Map<String, Attribute> getDotAttributes() { Map<String, Attribute> map = super.getDotAttributes(); map.put("style", DefaultAttribute.createAttribute("dashed")); return map; } }
src/main/java/tfm/arcs/sdg/ParameterInOutArc.java 0 → 100644 +16 −0 Original line number Diff line number Diff line package tfm.arcs.sdg; import org.jgrapht.io.Attribute; import org.jgrapht.io.DefaultAttribute; import tfm.arcs.Arc; import java.util.Map; public class ParameterInOutArc extends Arc { @Override public Map<String, Attribute> getDotAttributes() { Map<String, Attribute> map = super.getDotAttributes(); map.put("style", DefaultAttribute.createAttribute("dashed")); return map; } }
src/main/java/tfm/exec/Main.java +4 −2 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ package tfm.exec; import com.github.javaparser.JavaParser; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.MethodDeclaration; import tfm.utils.Logger; import tfm.utils.Utils; Loading Loading @@ -63,8 +64,9 @@ public class Main { graphLog = new PDGLog(); break; case GraphLog.SDG: graphLog = new SDGLog(); break; SDG sdg = new SDG(); sdg.build(new NodeList<>(method.findCompilationUnit().get())); return sdg; default: Logger.log("Unkown graph type"); System.exit(1); Loading
src/main/java/tfm/graphs/GraphWithRootNode.java 0 → 100644 +53 −0 Original line number Diff line number Diff line package tfm.graphs; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.MethodDeclaration; import tfm.nodes.GraphNode; import tfm.nodes.NodeFactory; import java.util.Objects; import java.util.Optional; public abstract class GraphWithRootNode<ASTRootNode extends Node> extends Graph implements Buildable<MethodDeclaration> { protected final int ROOT_NODE_ID = 0; protected GraphNode<ASTRootNode> rootNode; public GraphWithRootNode() { super(1); } /** * Builds the root node with the given instruction and AST node. * If the root node already exists, just returns false * * @param instruction the instruction string * @param rootNodeAst the AST node * @return true if the root node is created, false otherwise */ public boolean buildRootNode(String instruction, ASTRootNode rootNodeAst) { if (rootNode != null) { return false; } GraphNode<ASTRootNode> root = NodeFactory.graphNode(ROOT_NODE_ID, instruction, rootNodeAst); this.rootNode = root; this.addVertex(root); return true; } public Optional<GraphNode<ASTRootNode>> getRootNode() { return Optional.ofNullable(rootNode); } @Override public boolean removeVertex(GraphNode<?> graphNode) { if (Objects.equals(graphNode, rootNode)) { return false; } return super.removeVertex(graphNode); } }