Visitor: implemented any possible breakStmt

This commit is contained in:
Carlos Galindo 2019-04-04 17:14:14 +02:00
parent 47bff81942
commit 96847b7a8a
Signed by untrusted user who does not match committer: kauron
GPG key ID: 83E68706DEE119A3
3 changed files with 67 additions and 17 deletions

View file

@ -2,6 +2,7 @@ package grafos;
import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.expr.BooleanLiteralExpr;
import com.github.javaparser.ast.expr.SimpleName;
import com.github.javaparser.ast.stmt.*;
import java.util.*;
@ -14,6 +15,8 @@ public class CFG {
private final Node beginNode = new EmptyStmt(), endNode = new EmptyStmt();
private final LinkedList<Node> nodeList = new LinkedList<>();
private final Map<Node, String> labelMap = new HashMap<>();
private final Map<SimpleName, List<BreakStmt>> breakMap = new HashMap<>();
private final Stack<List<BreakStmt>> breakStack = new Stack<>();
private void registerNode(Node stmt) {
nodes.add(stmt);
@ -111,6 +114,32 @@ public class CFG {
return endNode;
}
public void beginBreakSection(SimpleName name) {
breakMap.put(name, new LinkedList<>());
}
public void beginBreakSection() {
breakStack.push(new LinkedList<>());
}
public void registerBreak(BreakStmt stmt) {
List<BreakStmt> list;
if (stmt.getLabel().isPresent()) {
list = breakMap.get(stmt.getLabel().get());
} else {
list = breakStack.peek();
}
list.add(stmt);
}
public void endBreakSection(SimpleName name) {
nodeList.addAll(breakMap.remove(name));
}
public void endBreakSection() {
nodeList.addAll(breakStack.pop());
}
public List<String> toStringList(GraphViz gv) {
List<String> res = new LinkedList<>();
res.add(gv.start_graph());