tint: Add new methods to semantic Switch nodes
• Add sem::SwitchStatement::Cases()
• Add sem::CaseStatement::Selectors()
• Add ast::SwitchStatement -> sem::SwitchStatement mapping
Removes a bunch of hopping between the AST and SEM to get at this data.
Change-Id: If48d78e7a386aa0b34c6d00ad9af1d53cb236f12
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91024
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc
index cc45490..d9be7f8 100644
--- a/src/tint/resolver/resolver.cc
+++ b/src/tint/resolver/resolver.cc
@@ -870,10 +870,13 @@
auto* sem =
builder_->create<sem::CaseStatement>(stmt, current_compound_statement_, current_function_);
return StatementScope(stmt, sem, [&] {
+ sem->Selectors().reserve(stmt->selectors.size());
for (auto* sel : stmt->selectors) {
- if (!Expression(sel)) {
+ auto* expr = Expression(sel);
+ if (!expr) {
return false;
}
+ sem->Selectors().emplace_back(expr);
}
Mark(stmt->body);
auto* body = BlockStatement(stmt->body);
@@ -2140,6 +2143,7 @@
return false;
}
behaviors.Add(c->Behaviors());
+ sem->Cases().emplace_back(c);
}
if (behaviors.Contains(sem::Behavior::kBreak)) {