refactor block-visitor
@@ -57,31 +57,18 @@ public class OCLBlockVisitor implements ControlFlowGraph.RecursiveVisitor<Block>
switchClosed = new HashSet<>();
}
- @Override
- public Block enter(Block b) {
-
- boolean isMerge = b.getBeginNode() instanceof MergeNode;
- if (isMerge) {
- asm.eolOn();
- merges.add(b);
- }
-
- if (b.isLoopHeader()) {
- resBuilder.emitLoopHeader(b);
- asm.beginScope();
- } else {
- final Block dom = b.getDominator();
-
- if (dom != null && !isMerge && !dom.isLoopHeader() && isIfBlock(dom)) {
+ private void emitBeginBlockForElseStatement(Block dom, Block block) {
final IfNode ifNode = (IfNode) dom.getEndNode();
- if (ifNode.falseSuccessor() == b.getBeginNode()) {
+ if (ifNode.falseSuccessor() == block.getBeginNode()) {
asm.indent();
asm.elseStmt();
asm.eol();
}
asm.beginScope();
asm.eolOn();
- } else if (dom != null && !isMerge && !dom.isLoopHeader() && isSwitchBlock(dom)) {
+ }
+
+ private void emitBeginBlockForSwitchStatements(Block dom, Block b) {
final IntegerSwitchNode switchNode = (IntegerSwitchNode) dom.getEndNode();
asm.indent();
Node beginNode = b.getBeginNode();
@@ -109,13 +96,30 @@ public class OCLBlockVisitor implements ControlFlowGraph.RecursiveVisitor<Block>
asm.emit(keyAt.toValueString());
asm.emit(OCLAssemblerConstants.COLON);
}
-
- //asm.eol();
}
- resBuilder.emitBlock(b);
+ @Override
+ public Block enter(Block block) {
+
+ boolean isMerge = block.getBeginNode() instanceof MergeNode;
+ if (isMerge) {
+ asm.eolOn();
+ merges.add(block);
}
+ if (block.isLoopHeader()) {
+ resBuilder.emitLoopHeader(block);
+ asm.beginScope();
+ } else {
+ // Emit either a Else statement or a switch statement
+ final Block dom = block.getDominator();
+ if (dom != null && !isMerge && !dom.isLoopHeader() && isIfBlock(dom)) {
+ emitBeginBlockForElseStatement(dom, block);
+ } else if (dom != null && !isMerge && !dom.isLoopHeader() && isSwitchBlock(dom)) {
+ emitBeginBlockForSwitchStatements(dom, block);
+ }
+ resBuilder.emitBlock(block);
+ }
return null;
}
@@ -127,9 +131,7 @@ public class OCLBlockVisitor implements ControlFlowGraph.RecursiveVisitor<Block>
}
if (b.getPostdominator() != null) {
Block pdom = b.getPostdominator();
- //AbstractBeginNode beginNode = pdom.getBeginNode();
if (!merges.contains(pdom) && isMergeBlock(pdom) && !switches.contains(b)) {
- //asm.eolOff();
//asm.emitLine(String.format("// block %d merges control flow -> pdom = %d depth=%d",b.getId(), pdom.getId(), pdom.getDominatorDepth()));
asm.endScope();
} else if (!merges.contains(pdom) && isMergeBlock(pdom) && switches.contains(b) && isSwitchBlock(b.getDominator())) {
