tint: Refactor if-else statement representation
Instead of using an `if` node that has a list of `else` statements,
make each `if` statement have a single optional `else` statement,
which may itself be an `if` statement (or just a block statement).
This better matches the WGSL grammar (now that we have removed
`elseif`), and simplifies various pieces of code that handle these
statements.
Change-Id: Ie4272f1422224490ac598a03aa8b4dd00ba03010
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87940
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: James Price <jrprice@google.com>
diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc
index c34a1c6..c257989 100644
--- a/src/tint/writer/hlsl/generator_impl.cc
+++ b/src/tint/writer/hlsl/generator_impl.cc
@@ -2691,36 +2691,20 @@
return false;
}
- for (auto* e : stmt->else_statements) {
- if (e->condition) {
- line() << "} else {";
- increment_indent();
-
- {
- auto out = line();
- out << "if (";
- if (!EmitExpression(out, e->condition)) {
- return false;
- }
- out << ") {";
+ if (stmt->else_statement) {
+ line() << "} else {";
+ if (auto* block = stmt->else_statement->As<ast::BlockStatement>()) {
+ if (!EmitStatementsWithIndent(block->statements)) {
+ return false;
}
} else {
- line() << "} else {";
- }
-
- if (!EmitStatementsWithIndent(e->body->statements)) {
- return false;
+ if (!EmitStatementsWithIndent({stmt->else_statement})) {
+ return false;
+ }
}
}
-
line() << "}";
- for (auto* e : stmt->else_statements) {
- if (e->condition) {
- decrement_indent();
- line() << "}";
- }
- }
return true;
}