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:
Geza Lore 2021-05-10 22:15:12 +01:00 committed by GitHub
parent 267c6f6dce
commit 1a6378291a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -812,11 +812,19 @@ public:
if (!nodep->branchPred().unknown()) puts(")");
puts(") {\n");
iterateAndNextNull(nodep->ifsp());
if (nodep->elsesp()) {
puts("} else {\n");
iterateAndNextNull(nodep->elsesp());
puts("}");
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());
puts("}\n");
}
}
puts("}\n");
}
virtual void visit(AstExprStmt* nodep) override {
// GCC allows compound statements in expressions, but this is not standard.