Loading src/main/java/tfm/exec/PDGLog.java +2 −1 Original line number Diff line number Diff line Loading @@ -31,8 +31,9 @@ public class PDGLog extends GraphLog<PDG> { Logger.log(graph.vertexSet().stream() .sorted(Comparator.comparingInt(GraphNode::getId)) .map(node -> String.format("GraphNode { id: %s, declared: %s, defined: %s, used: %s }", String.format("GraphNode { id: %s, instruction: %s, declared: %s, defined: %s, used: %s }", node.getId(), node.getInstruction(), node.getDeclaredVariables(), node.getDefinedVariables(), node.getUsedVariables()) Loading src/main/java/tfm/graphs/Graph.java +2 −2 Original line number Diff line number Diff line package tfm.graphs; import com.github.javaparser.ast.Node; import org.jgrapht.graph.DefaultDirectedGraph; import org.jgrapht.graph.DirectedPseudograph; import org.jgrapht.io.DOTExporter; import tfm.arcs.Arc; import tfm.nodes.GraphNode; Loading @@ -14,7 +14,7 @@ import java.util.stream.Collectors; /** * * */ public abstract class Graph extends DefaultDirectedGraph<GraphNode<?>, Arc> { public abstract class Graph extends DirectedPseudograph<GraphNode<?>, Arc> { protected static final int DEFAULT_VERTEX_START_ID = 0; Loading src/main/java/tfm/graphs/cfg/CFG.java +3 −3 Original line number Diff line number Diff line Loading @@ -37,10 +37,10 @@ public class CFG extends GraphWithRootNode<MethodDeclaration> { public Set<GraphNode<?>> findLastDefinitionsFrom(GraphNode<?> startNode, String variable) { if (!this.containsVertex(startNode)) throw new NodeNotFoundException(startNode, this); return findLastDefinitionsFrom(new HashSet<>(), startNode, startNode, variable); return findLastDefinitionsFrom(new HashSet<>(), startNode.getId(), startNode, variable); } private Set<GraphNode<?>> findLastDefinitionsFrom(Set<Integer> visited, GraphNode<?> startNode, GraphNode<?> currentNode, String variable) { private Set<GraphNode<?>> findLastDefinitionsFrom(Set<Integer> visited, int startNode, GraphNode<?> currentNode, String variable) { visited.add(currentNode.getId()); Set<GraphNode<?>> res = new HashSet<>(); Loading @@ -50,7 +50,7 @@ public class CFG extends GraphWithRootNode<MethodDeclaration> { continue; GraphNode<?> from = getEdgeSource(arc); if (!Objects.equals(startNode, from) && visited.contains(from.getId())) { if (!Objects.equals(startNode, from.getId()) && visited.contains(from.getId())) { continue; } Loading src/main/java/tfm/nodes/GraphNode.java +5 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull; import tfm.graphs.cfg.CFG; import tfm.graphs.pdg.PDG; import tfm.graphs.sdg.SDG; import tfm.utils.ASTUtils; import tfm.utils.Utils; import tfm.variables.VariableExtractor; Loading Loading @@ -117,6 +118,10 @@ public class GraphNode<N extends Node> implements Comparable<GraphNode<?>> { && Objects.equals(astNode, other.astNode); } public boolean equalsWithASTNodeRange(Object o) { return equals(o) && ASTUtils.equalsWithRange(((GraphNode<?>) o).astNode, astNode); } @Override public int hashCode() { return Objects.hash(getId(), getInstruction(), getAstNode()); Loading src/main/java/tfm/utils/ASTUtils.java +5 −0 Original line number Diff line number Diff line Loading @@ -77,4 +77,9 @@ public class ASTUtils { || node instanceof TryStmt || node instanceof CatchClause; } public static boolean equalsWithRange(Node n1, Node n2) { return Objects.equals(n1.getRange(), n2.getRange()) && Objects.equals(n1, n2); } } Loading
src/main/java/tfm/exec/PDGLog.java +2 −1 Original line number Diff line number Diff line Loading @@ -31,8 +31,9 @@ public class PDGLog extends GraphLog<PDG> { Logger.log(graph.vertexSet().stream() .sorted(Comparator.comparingInt(GraphNode::getId)) .map(node -> String.format("GraphNode { id: %s, declared: %s, defined: %s, used: %s }", String.format("GraphNode { id: %s, instruction: %s, declared: %s, defined: %s, used: %s }", node.getId(), node.getInstruction(), node.getDeclaredVariables(), node.getDefinedVariables(), node.getUsedVariables()) Loading
src/main/java/tfm/graphs/Graph.java +2 −2 Original line number Diff line number Diff line package tfm.graphs; import com.github.javaparser.ast.Node; import org.jgrapht.graph.DefaultDirectedGraph; import org.jgrapht.graph.DirectedPseudograph; import org.jgrapht.io.DOTExporter; import tfm.arcs.Arc; import tfm.nodes.GraphNode; Loading @@ -14,7 +14,7 @@ import java.util.stream.Collectors; /** * * */ public abstract class Graph extends DefaultDirectedGraph<GraphNode<?>, Arc> { public abstract class Graph extends DirectedPseudograph<GraphNode<?>, Arc> { protected static final int DEFAULT_VERTEX_START_ID = 0; Loading
src/main/java/tfm/graphs/cfg/CFG.java +3 −3 Original line number Diff line number Diff line Loading @@ -37,10 +37,10 @@ public class CFG extends GraphWithRootNode<MethodDeclaration> { public Set<GraphNode<?>> findLastDefinitionsFrom(GraphNode<?> startNode, String variable) { if (!this.containsVertex(startNode)) throw new NodeNotFoundException(startNode, this); return findLastDefinitionsFrom(new HashSet<>(), startNode, startNode, variable); return findLastDefinitionsFrom(new HashSet<>(), startNode.getId(), startNode, variable); } private Set<GraphNode<?>> findLastDefinitionsFrom(Set<Integer> visited, GraphNode<?> startNode, GraphNode<?> currentNode, String variable) { private Set<GraphNode<?>> findLastDefinitionsFrom(Set<Integer> visited, int startNode, GraphNode<?> currentNode, String variable) { visited.add(currentNode.getId()); Set<GraphNode<?>> res = new HashSet<>(); Loading @@ -50,7 +50,7 @@ public class CFG extends GraphWithRootNode<MethodDeclaration> { continue; GraphNode<?> from = getEdgeSource(arc); if (!Objects.equals(startNode, from) && visited.contains(from.getId())) { if (!Objects.equals(startNode, from.getId()) && visited.contains(from.getId())) { continue; } Loading
src/main/java/tfm/nodes/GraphNode.java +5 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull; import tfm.graphs.cfg.CFG; import tfm.graphs.pdg.PDG; import tfm.graphs.sdg.SDG; import tfm.utils.ASTUtils; import tfm.utils.Utils; import tfm.variables.VariableExtractor; Loading Loading @@ -117,6 +118,10 @@ public class GraphNode<N extends Node> implements Comparable<GraphNode<?>> { && Objects.equals(astNode, other.astNode); } public boolean equalsWithASTNodeRange(Object o) { return equals(o) && ASTUtils.equalsWithRange(((GraphNode<?>) o).astNode, astNode); } @Override public int hashCode() { return Objects.hash(getId(), getInstruction(), getAstNode()); Loading
src/main/java/tfm/utils/ASTUtils.java +5 −0 Original line number Diff line number Diff line Loading @@ -77,4 +77,9 @@ public class ASTUtils { || node instanceof TryStmt || node instanceof CatchClause; } public static boolean equalsWithRange(Node n1, Node n2) { return Objects.equals(n1.getRange(), n2.getRange()) && Objects.equals(n1, n2); } }