Visitor: implemented any possible breakStmt
This commit is contained in:
parent
47bff81942
commit
96847b7a8a
3 changed files with 67 additions and 17 deletions
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue