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>
This commit is contained in:
Ben Clayton
2022-05-20 12:28:00 +00:00
committed by Dawn LUCI CQ
parent a2ce4ecc8b
commit 43581f1fb6
5 changed files with 43 additions and 5 deletions

View File

@@ -15,6 +15,8 @@
#ifndef SRC_TINT_SEM_SWITCH_STATEMENT_H_
#define SRC_TINT_SEM_SWITCH_STATEMENT_H_
#include <vector>
#include "src/tint/sem/block_statement.h"
// Forward declarations
@@ -22,6 +24,10 @@ namespace tint::ast {
class CaseStatement;
class SwitchStatement;
} // namespace tint::ast
namespace tint::sem {
class CaseStatement;
class Expression;
} // namespace tint::sem
namespace tint::sem {
@@ -41,6 +47,15 @@ class SwitchStatement final : public Castable<SwitchStatement, CompoundStatement
/// @return the AST node for this statement
const ast::SwitchStatement* Declaration() const;
/// @returns the case statements for this switch
std::vector<const CaseStatement*>& Cases() { return cases_; }
/// @returns the case statements for this switch
const std::vector<const CaseStatement*>& Cases() const { return cases_; }
private:
std::vector<const CaseStatement*> cases_;
};
/// Holds semantic information about a switch case statement
@@ -66,8 +81,15 @@ class CaseStatement final : public Castable<CaseStatement, CompoundStatement> {
/// @returns the case body block statement
const BlockStatement* Body() const { return body_; }
/// @returns the selectors for the case
std::vector<const Expression*>& Selectors() { return selectors_; }
/// @returns the selectors for the case
const std::vector<const Expression*>& Selectors() const { return selectors_; }
private:
const BlockStatement* body_ = nullptr;
std::vector<const Expression*> selectors_;
};
} // namespace tint::sem

View File

@@ -30,6 +30,7 @@ class Node;
class Statement;
class Struct;
class StructMember;
class SwitchStatement;
class Type;
class TypeDecl;
class Variable;
@@ -46,6 +47,7 @@ class Node;
class Statement;
class Struct;
class StructMember;
class SwitchStatement;
class Type;
class Variable;
} // namespace tint::sem
@@ -68,6 +70,7 @@ struct TypeMappings {
Statement* operator()(ast::Statement*);
Struct* operator()(ast::Struct*);
StructMember* operator()(ast::StructMember*);
SwitchStatement* operator()(ast::SwitchStatement*);
Type* operator()(ast::Type*);
Type* operator()(ast::TypeDecl*);
Variable* operator()(ast::Variable*);