mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-15 20:01:22 +00:00
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>
1.7 KiB
1.7 KiB
Compound Statements
Compound statements are statements that can hold other statements.
This document maps the WGSL compound statements to their semantic tree representations.
if statement
WGSL:
if (condition_a) {
statement_a;
} else if (condition_b) {
statement_b;
} else {
statement_c;
}
Semantic tree:
sem::IfStatement {
condition_a
sem::BlockStatement {
statement_a
}
sem::IfStatement {
condition_b
sem::BlockStatement {
statement_b
}
sem::BlockStatement {
statement_c
}
}
}
for loop
WGSL:
for (initializer; condition; continuing) {
statement;
}
Semantic tree:
sem::ForLoopStatement {
sem::Statement initializer
sem::Expression condition
sem::Statement continuing
sem::LoopBlockStatement {
sem::Statement statement
}
}
loop
WGSL:
loop (condition) {
statement_a;
continuing {
statement_b;
}
}
Semantic tree:
sem::LoopStatement {
sem::Expression condition
sem::LoopBlockStatement {
sem::Statement statement_a
sem::LoopContinuingBlockStatement {
sem::Statement statement_b
}
}
}
switch statement
WGSL:
switch (condition) {
case literal_a, literal_b: {
statement_a;
}
default {
statement_b;
}
}
Semantic tree:
sem::SwitchStatement {
sem::Expression condition
sem::CaseStatement {
sem::BlockStatement {
sem::Statement statement_a
}
}
sem::CaseStatement {
sem::BlockStatement {
sem::Statement statement_b
}
}
}