diff --git a/src/ast/access_decoration.cc b/src/ast/access_decoration.cc index ae0fdef6d6..3f7252a19a 100644 --- a/src/ast/access_decoration.cc +++ b/src/ast/access_decoration.cc @@ -20,10 +20,14 @@ namespace ast { constexpr const DecorationKind AccessDecoration::Kind; AccessDecoration::AccessDecoration(AccessControl val, const Source& source) - : TypeDecoration(Kind, source), value_(val) {} + : TypeDecoration(source), value_(val) {} AccessDecoration::~AccessDecoration() = default; +DecorationKind AccessDecoration::GetKind() const { + return Kind; +} + bool AccessDecoration::IsKind(DecorationKind kind) const { return kind == Kind || TypeDecoration::IsKind(kind); } diff --git a/src/ast/access_decoration.h b/src/ast/access_decoration.h index 69a7244e28..3be11d55e5 100644 --- a/src/ast/access_decoration.h +++ b/src/ast/access_decoration.h @@ -35,6 +35,9 @@ class AccessDecoration : public TypeDecoration { explicit AccessDecoration(AccessControl value, const Source& source); ~AccessDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. diff --git a/src/ast/array_decoration.cc b/src/ast/array_decoration.cc index d7f22f3935..7832e9be8c 100644 --- a/src/ast/array_decoration.cc +++ b/src/ast/array_decoration.cc @@ -23,11 +23,14 @@ namespace ast { constexpr const DecorationKind ArrayDecoration::Kind; -ArrayDecoration::ArrayDecoration(DecorationKind kind, const Source& source) - : Decoration(kind, source) {} +ArrayDecoration::ArrayDecoration(const Source& source) : Decoration(source) {} ArrayDecoration::~ArrayDecoration() = default; +DecorationKind ArrayDecoration::GetKind() const { + return Kind; +} + bool ArrayDecoration::IsKind(DecorationKind kind) const { return kind == Kind; } diff --git a/src/ast/array_decoration.h b/src/ast/array_decoration.h index 77b616459c..f1a953bbaf 100644 --- a/src/ast/array_decoration.h +++ b/src/ast/array_decoration.h @@ -34,6 +34,9 @@ class ArrayDecoration : public Decoration { ~ArrayDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. @@ -47,9 +50,8 @@ class ArrayDecoration : public Decoration { protected: /// Constructor - /// @param kind the decoration kind /// @param source the source of this decoration - ArrayDecoration(DecorationKind kind, const Source& source); + explicit ArrayDecoration(const Source& source); }; /// A list of array decorations diff --git a/src/ast/binding_decoration.cc b/src/ast/binding_decoration.cc index d0c5063886..2af35d903e 100644 --- a/src/ast/binding_decoration.cc +++ b/src/ast/binding_decoration.cc @@ -20,10 +20,14 @@ namespace ast { constexpr const DecorationKind BindingDecoration::Kind; BindingDecoration::BindingDecoration(uint32_t val, const Source& source) - : VariableDecoration(Kind, source), value_(val) {} + : VariableDecoration(source), value_(val) {} BindingDecoration::~BindingDecoration() = default; +DecorationKind BindingDecoration::GetKind() const { + return Kind; +} + bool BindingDecoration::IsKind(DecorationKind kind) const { return kind == Kind || VariableDecoration::IsKind(kind); } diff --git a/src/ast/binding_decoration.h b/src/ast/binding_decoration.h index 4f65eabfd0..8e40626bc6 100644 --- a/src/ast/binding_decoration.h +++ b/src/ast/binding_decoration.h @@ -34,6 +34,9 @@ class BindingDecoration : public VariableDecoration { BindingDecoration(uint32_t value, const Source& source); ~BindingDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. diff --git a/src/ast/builtin_decoration.cc b/src/ast/builtin_decoration.cc index 7cb49c73f3..28108d3536 100644 --- a/src/ast/builtin_decoration.cc +++ b/src/ast/builtin_decoration.cc @@ -20,10 +20,14 @@ namespace ast { constexpr const DecorationKind BuiltinDecoration::Kind; BuiltinDecoration::BuiltinDecoration(Builtin builtin, const Source& source) - : VariableDecoration(Kind, source), builtin_(builtin) {} + : VariableDecoration(source), builtin_(builtin) {} BuiltinDecoration::~BuiltinDecoration() = default; +DecorationKind BuiltinDecoration::GetKind() const { + return Kind; +} + bool BuiltinDecoration::IsKind(DecorationKind kind) const { return kind == Kind || VariableDecoration::IsKind(kind); } diff --git a/src/ast/builtin_decoration.h b/src/ast/builtin_decoration.h index 75d40a5c95..07dedfe029 100644 --- a/src/ast/builtin_decoration.h +++ b/src/ast/builtin_decoration.h @@ -33,6 +33,9 @@ class BuiltinDecoration : public VariableDecoration { BuiltinDecoration(Builtin builtin, const Source& source); ~BuiltinDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. diff --git a/src/ast/constant_id_decoration.cc b/src/ast/constant_id_decoration.cc index 145b80d572..3cd219da0f 100644 --- a/src/ast/constant_id_decoration.cc +++ b/src/ast/constant_id_decoration.cc @@ -20,10 +20,14 @@ namespace ast { constexpr const DecorationKind ConstantIdDecoration::Kind; ConstantIdDecoration::ConstantIdDecoration(uint32_t val, const Source& source) - : VariableDecoration(Kind, source), value_(val) {} + : VariableDecoration(source), value_(val) {} ConstantIdDecoration::~ConstantIdDecoration() = default; +DecorationKind ConstantIdDecoration::GetKind() const { + return Kind; +} + bool ConstantIdDecoration::IsKind(DecorationKind kind) const { return kind == Kind || VariableDecoration::IsKind(kind); } diff --git a/src/ast/constant_id_decoration.h b/src/ast/constant_id_decoration.h index 3fb8ef8fb6..b2776fd33d 100644 --- a/src/ast/constant_id_decoration.h +++ b/src/ast/constant_id_decoration.h @@ -33,6 +33,9 @@ class ConstantIdDecoration : public VariableDecoration { ConstantIdDecoration(uint32_t val, const Source& source); ~ConstantIdDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. diff --git a/src/ast/decoration.h b/src/ast/decoration.h index 61c4cff8d2..c7dffdb449 100644 --- a/src/ast/decoration.h +++ b/src/ast/decoration.h @@ -51,6 +51,9 @@ class Decoration : public Node { public: ~Decoration() override; + /// @return the decoration kind + virtual DecorationKind GetKind() const = 0; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. @@ -62,21 +65,13 @@ class Decoration : public Node { return IsKind(TO::Kind); } - /// @return the decoration kind - DecorationKind GetKind() const { return kind_; } - /// @returns true if the node is valid bool IsValid() const override; protected: /// Constructor - /// @param kind represents the derived type /// @param source the source of this decoration - Decoration(DecorationKind kind, const Source& source) - : Node(source), kind_(kind) {} - - private: - DecorationKind const kind_; + explicit Decoration(const Source& source) : Node(source) {} }; /// As dynamically casts |deco| to the target type |TO|. diff --git a/src/ast/function_decoration.cc b/src/ast/function_decoration.cc index fc1409ab32..2d11714b21 100644 --- a/src/ast/function_decoration.cc +++ b/src/ast/function_decoration.cc @@ -24,12 +24,15 @@ namespace ast { constexpr const DecorationKind FunctionDecoration::Kind; -FunctionDecoration::FunctionDecoration(DecorationKind kind, - const Source& source) - : Decoration(kind, source) {} +FunctionDecoration::FunctionDecoration(const Source& source) + : Decoration(source) {} FunctionDecoration::~FunctionDecoration() = default; +DecorationKind FunctionDecoration::GetKind() const { + return Kind; +} + bool FunctionDecoration::IsKind(DecorationKind kind) const { return kind == Kind; } diff --git a/src/ast/function_decoration.h b/src/ast/function_decoration.h index 1d778faaf5..86b951420a 100644 --- a/src/ast/function_decoration.h +++ b/src/ast/function_decoration.h @@ -35,6 +35,9 @@ class FunctionDecoration : public Decoration { ~FunctionDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. @@ -52,9 +55,8 @@ class FunctionDecoration : public Decoration { protected: /// Constructor - /// @param kind the decoration kind /// @param source the source of this decoration - FunctionDecoration(DecorationKind kind, const Source& source); + explicit FunctionDecoration(const Source& source); }; /// A list of function decorations diff --git a/src/ast/location_decoration.cc b/src/ast/location_decoration.cc index 0aa7f1aa54..51737d99ef 100644 --- a/src/ast/location_decoration.cc +++ b/src/ast/location_decoration.cc @@ -20,10 +20,14 @@ namespace ast { constexpr const DecorationKind LocationDecoration::Kind; LocationDecoration::LocationDecoration(uint32_t val, const Source& source) - : VariableDecoration(Kind, source), value_(val) {} + : VariableDecoration(source), value_(val) {} LocationDecoration::~LocationDecoration() = default; +DecorationKind LocationDecoration::GetKind() const { + return Kind; +} + bool LocationDecoration::IsKind(DecorationKind kind) const { return kind == Kind || VariableDecoration::IsKind(kind); } diff --git a/src/ast/location_decoration.h b/src/ast/location_decoration.h index abbfefe0d3..ae7aed151b 100644 --- a/src/ast/location_decoration.h +++ b/src/ast/location_decoration.h @@ -34,6 +34,9 @@ class LocationDecoration : public VariableDecoration { explicit LocationDecoration(uint32_t value, const Source& source); ~LocationDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. diff --git a/src/ast/set_decoration.cc b/src/ast/set_decoration.cc index 9d1d502c8c..08d5312afc 100644 --- a/src/ast/set_decoration.cc +++ b/src/ast/set_decoration.cc @@ -18,7 +18,7 @@ namespace tint { namespace ast { SetDecoration::SetDecoration(uint32_t val, const Source& source) - : VariableDecoration(Kind, source), value_(val) {} + : VariableDecoration(source), value_(val) {} SetDecoration::~SetDecoration() = default; diff --git a/src/ast/stage_decoration.cc b/src/ast/stage_decoration.cc index d1f20a2ff4..ae996c8fef 100644 --- a/src/ast/stage_decoration.cc +++ b/src/ast/stage_decoration.cc @@ -20,10 +20,14 @@ namespace ast { constexpr const DecorationKind StageDecoration::Kind; StageDecoration::StageDecoration(ast::PipelineStage stage, const Source& source) - : FunctionDecoration(Kind, source), stage_(stage) {} + : FunctionDecoration(source), stage_(stage) {} StageDecoration::~StageDecoration() = default; +DecorationKind StageDecoration::GetKind() const { + return Kind; +} + bool StageDecoration::IsKind(DecorationKind kind) const { return kind == Kind || FunctionDecoration::IsKind(kind); } diff --git a/src/ast/stage_decoration.h b/src/ast/stage_decoration.h index b7aa3b85fb..0b7e94a71b 100644 --- a/src/ast/stage_decoration.h +++ b/src/ast/stage_decoration.h @@ -33,6 +33,9 @@ class StageDecoration : public FunctionDecoration { StageDecoration(ast::PipelineStage stage, const Source& source); ~StageDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. diff --git a/src/ast/stride_decoration.cc b/src/ast/stride_decoration.cc index 58ac1a5245..d92bf58175 100644 --- a/src/ast/stride_decoration.cc +++ b/src/ast/stride_decoration.cc @@ -20,7 +20,11 @@ namespace ast { constexpr const DecorationKind StrideDecoration::Kind; StrideDecoration::StrideDecoration(uint32_t stride, const Source& source) - : ArrayDecoration(Kind, source), stride_(stride) {} + : ArrayDecoration(source), stride_(stride) {} + +DecorationKind StrideDecoration::GetKind() const { + return Kind; +} bool StrideDecoration::IsKind(DecorationKind kind) const { return kind == Kind || ArrayDecoration::IsKind(kind); diff --git a/src/ast/stride_decoration.h b/src/ast/stride_decoration.h index 9b00563919..f97734ee49 100644 --- a/src/ast/stride_decoration.h +++ b/src/ast/stride_decoration.h @@ -36,6 +36,9 @@ class StrideDecoration : public ArrayDecoration { StrideDecoration(uint32_t stride, const Source& source); ~StrideDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. diff --git a/src/ast/struct_block_decoration.cc b/src/ast/struct_block_decoration.cc index b95299e3ae..585646d0c4 100644 --- a/src/ast/struct_block_decoration.cc +++ b/src/ast/struct_block_decoration.cc @@ -18,7 +18,7 @@ namespace tint { namespace ast { StructBlockDecoration::StructBlockDecoration(const Source& source) - : StructDecoration(Kind, source) {} + : StructDecoration(source) {} StructBlockDecoration::~StructBlockDecoration() = default; diff --git a/src/ast/struct_decoration.cc b/src/ast/struct_decoration.cc index 340ac1447f..5b93b909a3 100644 --- a/src/ast/struct_decoration.cc +++ b/src/ast/struct_decoration.cc @@ -19,11 +19,14 @@ namespace ast { constexpr const DecorationKind StructDecoration::Kind; -StructDecoration::StructDecoration(DecorationKind kind, const Source& source) - : Decoration(kind, source) {} +StructDecoration::StructDecoration(const Source& source) : Decoration(source) {} StructDecoration::~StructDecoration() = default; +DecorationKind StructDecoration::GetKind() const { + return Kind; +} + bool StructDecoration::IsKind(DecorationKind kind) const { return kind == Kind; } diff --git a/src/ast/struct_decoration.h b/src/ast/struct_decoration.h index 26b1901106..727ba7da84 100644 --- a/src/ast/struct_decoration.h +++ b/src/ast/struct_decoration.h @@ -32,6 +32,9 @@ class StructDecoration : public Decoration { ~StructDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. @@ -42,9 +45,8 @@ class StructDecoration : public Decoration { protected: /// Constructor - /// @param kind the decoration kind /// @param source the source of this decoration - explicit StructDecoration(DecorationKind kind, const Source& source); + explicit StructDecoration(const Source& source); }; /// List of struct decorations diff --git a/src/ast/struct_member_decoration.cc b/src/ast/struct_member_decoration.cc index efbae62db9..8573bc727e 100644 --- a/src/ast/struct_member_decoration.cc +++ b/src/ast/struct_member_decoration.cc @@ -23,12 +23,15 @@ namespace ast { constexpr const DecorationKind StructMemberDecoration::Kind; -StructMemberDecoration::StructMemberDecoration(DecorationKind kind, - const Source& source) - : Decoration(kind, source) {} +StructMemberDecoration::StructMemberDecoration(const Source& source) + : Decoration(source) {} StructMemberDecoration::~StructMemberDecoration() = default; +DecorationKind StructMemberDecoration::GetKind() const { + return Kind; +} + bool StructMemberDecoration::IsKind(DecorationKind kind) const { return kind == Kind; } diff --git a/src/ast/struct_member_decoration.h b/src/ast/struct_member_decoration.h index 188c77751f..1652df3341 100644 --- a/src/ast/struct_member_decoration.h +++ b/src/ast/struct_member_decoration.h @@ -34,6 +34,9 @@ class StructMemberDecoration : public Decoration { ~StructMemberDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. @@ -47,9 +50,8 @@ class StructMemberDecoration : public Decoration { protected: /// Constructor - /// @param kind the decoration kind /// @param source the source of this decoration - explicit StructMemberDecoration(DecorationKind kind, const Source& source); + explicit StructMemberDecoration(const Source& source); }; /// A list of struct member decorations diff --git a/src/ast/struct_member_offset_decoration.cc b/src/ast/struct_member_offset_decoration.cc index b2ad2b494f..c211c5bb2c 100644 --- a/src/ast/struct_member_offset_decoration.cc +++ b/src/ast/struct_member_offset_decoration.cc @@ -21,7 +21,11 @@ constexpr const DecorationKind StructMemberOffsetDecoration::Kind; StructMemberOffsetDecoration::StructMemberOffsetDecoration(uint32_t offset, const Source& source) - : StructMemberDecoration(Kind, source), offset_(offset) {} + : StructMemberDecoration(source), offset_(offset) {} + +DecorationKind StructMemberOffsetDecoration::GetKind() const { + return Kind; +} bool StructMemberOffsetDecoration::IsKind(DecorationKind kind) const { return kind == Kind || StructMemberDecoration::IsKind(kind); diff --git a/src/ast/struct_member_offset_decoration.h b/src/ast/struct_member_offset_decoration.h index 6e5a5a690d..60a206851b 100644 --- a/src/ast/struct_member_offset_decoration.h +++ b/src/ast/struct_member_offset_decoration.h @@ -37,6 +37,9 @@ class StructMemberOffsetDecoration : public StructMemberDecoration { StructMemberOffsetDecoration(uint32_t offset, const Source& source); ~StructMemberOffsetDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. diff --git a/src/ast/type_decoration.cc b/src/ast/type_decoration.cc index 3f13343bbf..763d24cfcc 100644 --- a/src/ast/type_decoration.cc +++ b/src/ast/type_decoration.cc @@ -23,11 +23,14 @@ namespace ast { constexpr const DecorationKind TypeDecoration::Kind; -TypeDecoration::TypeDecoration(DecorationKind kind, const Source& source) - : Decoration(kind, source) {} +TypeDecoration::TypeDecoration(const Source& source) : Decoration(source) {} TypeDecoration::~TypeDecoration() = default; +DecorationKind TypeDecoration::GetKind() const { + return Kind; +} + bool TypeDecoration::IsKind(DecorationKind kind) const { return kind == Kind; } diff --git a/src/ast/type_decoration.h b/src/ast/type_decoration.h index f457e39706..f515a4b663 100644 --- a/src/ast/type_decoration.h +++ b/src/ast/type_decoration.h @@ -35,6 +35,9 @@ class TypeDecoration : public Decoration { ~TypeDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. @@ -48,9 +51,8 @@ class TypeDecoration : public Decoration { protected: /// Constructor - /// @param kind the decoration kind /// @param source the source of this decoration - explicit TypeDecoration(DecorationKind kind, const Source& source); + explicit TypeDecoration(const Source& source); }; /// A list of type decorations diff --git a/src/ast/variable_decoration.cc b/src/ast/variable_decoration.cc index e37d5bde46..9b7d2c0a71 100644 --- a/src/ast/variable_decoration.cc +++ b/src/ast/variable_decoration.cc @@ -27,12 +27,15 @@ namespace ast { constexpr const DecorationKind VariableDecoration::Kind; -VariableDecoration::VariableDecoration(DecorationKind kind, - const Source& source) - : Decoration(kind, source) {} +VariableDecoration::VariableDecoration(const Source& source) + : Decoration(source) {} VariableDecoration::~VariableDecoration() = default; +DecorationKind VariableDecoration::GetKind() const { + return Kind; +} + bool VariableDecoration::IsKind(DecorationKind kind) const { return kind == Kind; } diff --git a/src/ast/variable_decoration.h b/src/ast/variable_decoration.h index 6c44242903..e5c18fd782 100644 --- a/src/ast/variable_decoration.h +++ b/src/ast/variable_decoration.h @@ -39,6 +39,9 @@ class VariableDecoration : public Decoration { ~VariableDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind. @@ -68,9 +71,8 @@ class VariableDecoration : public Decoration { protected: /// Constructor - /// @param kind the decoration kind /// @param source the source of this decoration - VariableDecoration(DecorationKind kind, const Source& source); + explicit VariableDecoration(const Source& source); }; /// A list of variable decorations diff --git a/src/ast/workgroup_decoration.cc b/src/ast/workgroup_decoration.cc index e9ecab6ccf..1c4c58b704 100644 --- a/src/ast/workgroup_decoration.cc +++ b/src/ast/workgroup_decoration.cc @@ -20,21 +20,25 @@ namespace ast { constexpr const DecorationKind WorkgroupDecoration::Kind; WorkgroupDecoration::WorkgroupDecoration(uint32_t x, const Source& source) - : FunctionDecoration(Kind, source), x_(x) {} + : FunctionDecoration(source), x_(x) {} WorkgroupDecoration::WorkgroupDecoration(uint32_t x, uint32_t y, const Source& source) - : FunctionDecoration(Kind, source), x_(x), y_(y) {} + : FunctionDecoration(source), x_(x), y_(y) {} WorkgroupDecoration::WorkgroupDecoration(uint32_t x, uint32_t y, uint32_t z, const Source& source) - : FunctionDecoration(Kind, source), x_(x), y_(y), z_(z) {} + : FunctionDecoration(source), x_(x), y_(y), z_(z) {} WorkgroupDecoration::~WorkgroupDecoration() = default; +DecorationKind WorkgroupDecoration::GetKind() const { + return Kind; +} + bool WorkgroupDecoration::IsKind(DecorationKind kind) const { return kind == Kind || FunctionDecoration::IsKind(kind); } diff --git a/src/ast/workgroup_decoration.h b/src/ast/workgroup_decoration.h index cbfb5aafcb..fbdbf06e5c 100644 --- a/src/ast/workgroup_decoration.h +++ b/src/ast/workgroup_decoration.h @@ -47,6 +47,9 @@ class WorkgroupDecoration : public FunctionDecoration { WorkgroupDecoration(uint32_t x, uint32_t y, uint32_t z, const Source& source); ~WorkgroupDecoration() override; + /// @return the decoration kind + DecorationKind GetKind() const override; + /// @param kind the decoration kind /// @return true if this Decoration is of the (or derives from) the given /// kind.