Added support for any continue statements, fixed empty for loops (set condition to true if empty)

This commit is contained in:
Carlos Galindo 2019-04-04 18:00:16 +02:00
parent 96847b7a8a
commit daa1c2d90a
Signed by untrusted user who does not match committer: kauron
GPG key ID: 83E68706DEE119A3
3 changed files with 82 additions and 20 deletions

View file

@ -17,6 +17,10 @@ public class CFG {
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 final Map<SimpleName, Node> continueMap = new HashMap<>();
private final Stack<Node> continueStack = new Stack<>();
private SimpleName lastLabel;
private void registerNode(Node stmt) {
nodes.add(stmt);
@ -122,14 +126,14 @@ public class CFG {
breakStack.push(new LinkedList<>());
}
public void registerBreak(BreakStmt stmt) {
List<BreakStmt> list;
public void connectBreak(BreakStmt stmt) {
connectTo(stmt);
if (stmt.getLabel().isPresent()) {
list = breakMap.get(stmt.getLabel().get());
breakMap.get(stmt.getLabel().get()).add(stmt);
} else {
list = breakStack.peek();
breakStack.peek().add(stmt);
}
list.add(stmt);
clearNode();
}
public void endBreakSection(SimpleName name) {
@ -140,6 +144,38 @@ public class CFG {
nodeList.addAll(breakStack.pop());
}
public void beginContinueSection(SimpleName name) {
assert lastLabel == null;
lastLabel = name;
}
public void beginContinueSection(Node node) {
continueStack.push(node);
if (lastLabel != null) {
assert !continueMap.containsKey(lastLabel);
continueMap.put(lastLabel, node);
lastLabel = null;
}
}
public void connectContinue(ContinueStmt stmt) {
connectTo(stmt);
if (stmt.getLabel().isPresent()) {
connectTo(continueMap.get(stmt.getLabel().get()));
} else {
connectTo(continueStack.peek());
}
clearNode();
}
public void endContinueSection(SimpleName name) {
continueMap.remove(name);
}
public void endContinueSection() {
continueStack.pop();
}
public List<String> toStringList(GraphViz gv) {
List<String> res = new LinkedList<>();
res.add(gv.start_graph());