Emit 'else if' without nesting. No functional change intended. (#2944)
Instead of:
if (a) {
x;
} else {
if (b) {
y;
} else {
if (c) {
z;
} else {
w;
}
}
}
Emit:
if (a) {
x;
} else if (b) {
y;
} else if (c) {
z;
} else {
w;
}
This commit is contained in:
parent
267c6f6dce
commit
1a6378291a
|
|
@ -812,12 +812,20 @@ public:
|
||||||
if (!nodep->branchPred().unknown()) puts(")");
|
if (!nodep->branchPred().unknown()) puts(")");
|
||||||
puts(") {\n");
|
puts(") {\n");
|
||||||
iterateAndNextNull(nodep->ifsp());
|
iterateAndNextNull(nodep->ifsp());
|
||||||
if (nodep->elsesp()) {
|
puts("}");
|
||||||
puts("} else {\n");
|
if (!nodep->elsesp()) {
|
||||||
|
puts("\n");
|
||||||
|
} else {
|
||||||
|
if (VN_IS(nodep->elsesp(), NodeIf) && !nodep->elsesp()->nextp()) {
|
||||||
|
puts(" else ");
|
||||||
|
iterateAndNextNull(nodep->elsesp());
|
||||||
|
} else {
|
||||||
|
puts(" else {\n");
|
||||||
iterateAndNextNull(nodep->elsesp());
|
iterateAndNextNull(nodep->elsesp());
|
||||||
}
|
|
||||||
puts("}\n");
|
puts("}\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
virtual void visit(AstExprStmt* nodep) override {
|
virtual void visit(AstExprStmt* nodep) override {
|
||||||
// GCC allows compound statements in expressions, but this is not standard.
|
// GCC allows compound statements in expressions, but this is not standard.
|
||||||
// So we use an immediate-evaluation lambda and comma operator
|
// So we use an immediate-evaluation lambda and comma operator
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue