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
1 changed files with 2 additions and 8 deletions

View File

@ -6,7 +6,7 @@ import com.github.javaparser.ast.stmt.EmptyStmt;
import java.util.*;
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 Node beginNode, endNode;
@ -15,10 +15,6 @@ public class CFG {
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) {
edges.add(new HashMap.SimpleEntry<>(begin, end));
}
@ -31,7 +27,6 @@ public class CFG {
public Node beginNode() {
if (beginNode == null) {
beginNode = new EmptyStmt();
nodes.add(beginNode);
}
return beginNode;
}
@ -39,7 +34,6 @@ public class CFG {
public Node endNode() {
if (endNode == null) {
endNode = new EmptyStmt();
nodes.add(endNode);
}
return endNode;
}
@ -70,7 +64,7 @@ public class CFG {
}
if (index == -1)
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("\"", "\\\"") + "\"";
}
}