[WGSL] Allow default as a case selector

This CL updates the WGSL parser to parse `default` as a case selector
value.

Bug: tint:1633
Change-Id: I57661d25924e36bec5c03f96399c557fb7bbf760
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/106382
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair
2022-10-19 15:55:02 +00:00
committed by Dawn LUCI CQ
parent d27151d333
commit f148f0891b
62 changed files with 1212 additions and 367 deletions

View File

@@ -17,6 +17,7 @@
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::sem::CaseStatement);
TINT_INSTANTIATE_TYPEINFO(tint::sem::CaseSelector);
TINT_INSTANTIATE_TYPEINFO(tint::sem::SwitchStatement);
namespace tint::sem {
@@ -48,4 +49,13 @@ const ast::CaseStatement* CaseStatement::Declaration() const {
return static_cast<const ast::CaseStatement*>(Base::Declaration());
}
CaseSelector::CaseSelector(const ast::CaseSelector* decl, const Constant* val)
: Base(), decl_(decl), val_(val) {}
CaseSelector::~CaseSelector() = default;
const ast::CaseSelector* CaseSelector::Declaration() const {
return decl_;
}
} // namespace tint::sem

View File

@@ -22,10 +22,12 @@
// Forward declarations
namespace tint::ast {
class CaseStatement;
class CaseSelector;
class SwitchStatement;
} // namespace tint::ast
namespace tint::sem {
class CaseStatement;
class CaseSelector;
class Constant;
class Expression;
} // namespace tint::sem
@@ -83,14 +85,39 @@ class CaseStatement final : public Castable<CaseStatement, CompoundStatement> {
const BlockStatement* Body() const { return body_; }
/// @returns the selectors for the case
std::vector<const Constant*>& Selectors() { return selectors_; }
std::vector<const CaseSelector*>& Selectors() { return selectors_; }
/// @returns the selectors for the case
const std::vector<const Constant*>& Selectors() const { return selectors_; }
const std::vector<const CaseSelector*>& Selectors() const { return selectors_; }
private:
const BlockStatement* body_ = nullptr;
std::vector<const Constant*> selectors_;
std::vector<const CaseSelector*> selectors_;
};
/// Holds semantic information about a switch case selector
class CaseSelector final : public Castable<CaseSelector, Node> {
public:
/// Constructor
/// @param decl the selector declaration
/// @param val the case selector value, nullptr for a default selector
explicit CaseSelector(const ast::CaseSelector* decl, const Constant* val = nullptr);
/// Destructor
~CaseSelector() override;
/// @returns true if this is a default selector
bool IsDefault() const { return val_ == nullptr; }
/// @returns the case selector declaration
const ast::CaseSelector* Declaration() const;
/// @returns the selector constant value, or nullptr if this is the default selector
const Constant* Value() const { return val_; }
private:
const ast::CaseSelector* const decl_;
const Constant* const val_;
};
} // namespace tint::sem