CFG: improved numbering system and removed connect(int, int)

This commit is contained in:
Carlos Galindo 2019-03-27 11:57:18 +01:00
parent 64395b31a0
commit 63c312589a
Signed by untrusted user who does not match committer: kauron
GPG key ID: 83E68706DEE119A3

View file

@ -6,7 +6,7 @@ import com.github.javaparser.ast.stmt.EmptyStmt;
import java.util.*; import java.util.*;
public class CFG { public class CFG {
private final List<Node> nodes = new ArrayList<Node>(); private final List<Node> nodes = new ArrayList<>();
private final List<Map.Entry<Node, Node>> edges = new LinkedList<>(); private final List<Map.Entry<Node, Node>> edges = new LinkedList<>();
private Node beginNode, endNode; private Node beginNode, endNode;
@ -15,10 +15,6 @@ public class CFG {
System.out.println("NODO: " + node2str(stmt)); System.out.println("NODO: " + node2str(stmt));
} }
public void connect(int begin, int end) {
connect(nodes.get(begin), nodes.get(end));
}
public void connect(Node begin, Node end) { public void connect(Node begin, Node end) {
edges.add(new HashMap.SimpleEntry<>(begin, end)); edges.add(new HashMap.SimpleEntry<>(begin, end));
} }
@ -31,7 +27,6 @@ public class CFG {
public Node beginNode() { public Node beginNode() {
if (beginNode == null) { if (beginNode == null) {
beginNode = new EmptyStmt(); beginNode = new EmptyStmt();
nodes.add(beginNode);
} }
return beginNode; return beginNode;
} }
@ -39,7 +34,6 @@ public class CFG {
public Node endNode() { public Node endNode() {
if (endNode == null) { if (endNode == null) {
endNode = new EmptyStmt(); endNode = new EmptyStmt();
nodes.add(endNode);
} }
return endNode; return endNode;
} }
@ -70,7 +64,7 @@ public class CFG {
} }
if (index == -1) if (index == -1)
throw new RuntimeException("Internal error, can't find node"); throw new RuntimeException("Internal error, can't find node");
return "\"(" + index + ", " + s.getRange().get().begin.line + ") " return "\"(" + (index + 1) + ", " + s.getRange().get().begin.line + ") "
+ s.toString().replace("\"", "\\\"") + "\""; + s.toString().replace("\"", "\\\"") + "\"";
} }
} }