Skip to content

Commit

Permalink
Режим ацикличности при построении графа
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilBeaver committed Aug 26, 2021
1 parent 0eaf82c commit bf6fcc2
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class CfgBuildingParseTreeVisitor extends BSLParserBaseVisitor<ParseTree>
private ControlFlowGraph graph;
private Map<String, LabelVertex> jumpLabels;

private boolean produceLoopIterationsEnabled = true;

public ControlFlowGraph buildGraph(BSLParser.CodeBlockContext block) {

blocks = new StatementsBlockWriter();
Expand Down Expand Up @@ -66,6 +68,10 @@ public ControlFlowGraph buildGraph(BSLParser.CodeBlockContext block) {
return graph;
}

public void produceLoopIterations(boolean flag) {
produceLoopIterationsEnabled = flag;
}

@Override
public ParseTree visitCallStatement(BSLParser.CallStatementContext ctx) {
blocks.addStatement(ctx);
Expand Down Expand Up @@ -473,7 +479,8 @@ private void buildLoopSubgraph(BSLParser.CodeBlockContext ctx, LoopVertex loopSt

graph.addEdge(loopStart, body.begin(), CfgEdgeType.TRUE_BRANCH);
graph.addEdge(loopStart, blocks.getCurrentBlock().end(), CfgEdgeType.FALSE_BRANCH);
graph.addEdge(body.end(), loopStart, CfgEdgeType.LOOP_ITERATION);
if (produceLoopIterationsEnabled)
graph.addEdge(body.end(), loopStart, CfgEdgeType.LOOP_ITERATION);
}

private void connectGraphTail(StatementsBlockWriter.StatementsBlockRecord currentBlock, CfgVertex vertex) {
Expand Down

0 comments on commit bf6fcc2

Please sign in to comment.