From e319d7f0e91238dd3fe2dd7b435d3dbc6c643847 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 30 Nov 2020 23:30:58 +0000 Subject: [PATCH] Derive all ast::Node from Castable The hand-rolled `AsBlah()`, `IsBlah()` methods will be migrated in future changes. Change-Id: I078c100b561b50018771cc38c1cac4379c393424 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34301 Reviewed-by: dan sinclair --- src/ast/access_decoration.cc | 4 ++-- src/ast/access_decoration.h | 2 +- src/ast/array_accessor_expression.cc | 6 +++--- src/ast/array_accessor_expression.h | 3 ++- src/ast/array_decoration.cc | 2 +- src/ast/array_decoration.h | 2 +- src/ast/assignment_statement.cc | 6 +++--- src/ast/assignment_statement.h | 2 +- src/ast/binary_expression.cc | 6 +++--- src/ast/binary_expression.h | 2 +- src/ast/binding_decoration.cc | 4 ++-- src/ast/binding_decoration.h | 3 ++- src/ast/bitcast_expression.cc | 6 +++--- src/ast/bitcast_expression.h | 2 +- src/ast/block_statement.cc | 4 ++-- src/ast/block_statement.h | 2 +- src/ast/bool_literal.cc | 2 +- src/ast/bool_literal.h | 2 +- src/ast/break_statement.cc | 4 ++-- src/ast/break_statement.h | 2 +- src/ast/builtin_decoration.cc | 4 ++-- src/ast/builtin_decoration.h | 3 ++- src/ast/call_expression.cc | 6 +++--- src/ast/call_expression.h | 2 +- src/ast/call_statement.cc | 4 ++-- src/ast/call_statement.h | 2 +- src/ast/case_statement.cc | 6 +++--- src/ast/case_statement.h | 2 +- src/ast/constant_id_decoration.cc | 4 ++-- src/ast/constant_id_decoration.h | 3 ++- src/ast/constructor_expression.cc | 4 +++- src/ast/constructor_expression.h | 5 +++-- src/ast/continue_statement.cc | 5 ++--- src/ast/continue_statement.h | 2 +- src/ast/decorated_variable.cc | 2 +- src/ast/decorated_variable.h | 2 +- src/ast/decoration.h | 10 ++-------- src/ast/decoration_test.cc | 2 +- src/ast/discard_statement.cc | 6 ++++-- src/ast/discard_statement.h | 4 ++-- src/ast/else_statement.cc | 8 ++++---- src/ast/else_statement.h | 2 +- src/ast/expression.cc | 4 +++- src/ast/expression.h | 4 ++-- src/ast/fallthrough_statement.cc | 6 ++++-- src/ast/fallthrough_statement.h | 4 ++-- src/ast/float_literal.cc | 2 +- src/ast/float_literal.h | 2 +- src/ast/function.cc | 4 ++-- src/ast/function.h | 2 +- src/ast/function_decoration.cc | 3 +-- src/ast/function_decoration.h | 2 +- src/ast/identifier_expression.cc | 4 ++-- src/ast/identifier_expression.h | 2 +- src/ast/if_statement.cc | 4 ++-- src/ast/if_statement.h | 2 +- src/ast/int_literal.cc | 2 +- src/ast/int_literal.h | 2 +- src/ast/literal.h | 2 +- src/ast/location_decoration.cc | 4 ++-- src/ast/location_decoration.h | 3 ++- src/ast/loop_statement.cc | 4 ++-- src/ast/loop_statement.h | 2 +- src/ast/member_accessor_expression.cc | 4 ++-- src/ast/member_accessor_expression.h | 3 ++- src/ast/node.cc | 2 ++ src/ast/node.h | 7 ++++--- src/ast/null_literal.cc | 2 +- src/ast/null_literal.h | 2 +- src/ast/return_statement.cc | 9 ++++----- src/ast/return_statement.h | 2 +- src/ast/scalar_constructor_expression.cc | 5 ++--- src/ast/scalar_constructor_expression.h | 3 ++- src/ast/set_decoration.cc | 2 +- src/ast/set_decoration.h | 2 +- src/ast/sint_literal.cc | 2 +- src/ast/sint_literal.h | 2 +- src/ast/stage_decoration.cc | 4 ++-- src/ast/stage_decoration.h | 2 +- src/ast/statement.cc | 2 +- src/ast/statement.h | 2 +- src/ast/stride_decoration.cc | 4 ++-- src/ast/stride_decoration.h | 2 +- src/ast/struct.cc | 10 +++++----- src/ast/struct.h | 2 +- src/ast/struct_block_decoration.cc | 2 +- src/ast/struct_block_decoration.h | 3 ++- src/ast/struct_decoration.cc | 2 +- src/ast/struct_decoration.h | 2 +- src/ast/struct_member.cc | 4 ++-- src/ast/struct_member.h | 2 +- src/ast/struct_member_decoration.cc | 2 +- src/ast/struct_member_decoration.h | 3 ++- src/ast/struct_member_offset_decoration.cc | 4 ++-- src/ast/struct_member_offset_decoration.h | 3 ++- src/ast/switch_statement.cc | 4 ++-- src/ast/switch_statement.h | 2 +- src/ast/type_constructor_expression.cc | 7 +++---- src/ast/type_constructor_expression.h | 3 ++- src/ast/type_decoration.cc | 2 +- src/ast/type_decoration.h | 2 +- src/ast/uint_literal.cc | 2 +- src/ast/uint_literal.h | 2 +- src/ast/unary_op_expression.cc | 6 +++--- src/ast/unary_op_expression.h | 2 +- src/ast/variable.cc | 4 ++-- src/ast/variable.h | 2 +- src/ast/variable_decl_statement.cc | 6 +++--- src/ast/variable_decl_statement.h | 3 ++- src/ast/variable_decoration.cc | 3 +-- src/ast/variable_decoration.h | 2 +- src/ast/workgroup_decoration.cc | 8 ++++---- src/ast/workgroup_decoration.h | 3 ++- 113 files changed, 198 insertions(+), 185 deletions(-) diff --git a/src/ast/access_decoration.cc b/src/ast/access_decoration.cc index 3f7252a19a..18d0d6e06b 100644 --- a/src/ast/access_decoration.cc +++ b/src/ast/access_decoration.cc @@ -20,7 +20,7 @@ namespace ast { constexpr const DecorationKind AccessDecoration::Kind; AccessDecoration::AccessDecoration(AccessControl val, const Source& source) - : TypeDecoration(source), value_(val) {} + : Base(source), value_(val) {} AccessDecoration::~AccessDecoration() = default; @@ -29,7 +29,7 @@ DecorationKind AccessDecoration::GetKind() const { } bool AccessDecoration::IsKind(DecorationKind kind) const { - return kind == Kind || TypeDecoration::IsKind(kind); + return kind == Kind || Base::IsKind(kind); } bool AccessDecoration::IsAccess() const { diff --git a/src/ast/access_decoration.h b/src/ast/access_decoration.h index 3be11d55e5..489c0e9bbe 100644 --- a/src/ast/access_decoration.h +++ b/src/ast/access_decoration.h @@ -24,7 +24,7 @@ namespace tint { namespace ast { /// An access decoration -class AccessDecoration : public TypeDecoration { +class AccessDecoration : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kAccess; diff --git a/src/ast/array_accessor_expression.cc b/src/ast/array_accessor_expression.cc index e8eea8aa9a..1891f4f1a7 100644 --- a/src/ast/array_accessor_expression.cc +++ b/src/ast/array_accessor_expression.cc @@ -17,16 +17,16 @@ namespace tint { namespace ast { -ArrayAccessorExpression::ArrayAccessorExpression() : Expression() {} +ArrayAccessorExpression::ArrayAccessorExpression() : Base() {} ArrayAccessorExpression::ArrayAccessorExpression(Expression* array, Expression* idx_expr) - : Expression(), array_(array), idx_expr_(idx_expr) {} + : Base(), array_(array), idx_expr_(idx_expr) {} ArrayAccessorExpression::ArrayAccessorExpression(const Source& source, Expression* array, Expression* idx_expr) - : Expression(source), array_(array), idx_expr_(idx_expr) {} + : Base(source), array_(array), idx_expr_(idx_expr) {} ArrayAccessorExpression::ArrayAccessorExpression(ArrayAccessorExpression&&) = default; diff --git a/src/ast/array_accessor_expression.h b/src/ast/array_accessor_expression.h index bb716ec970..f7e5192aab 100644 --- a/src/ast/array_accessor_expression.h +++ b/src/ast/array_accessor_expression.h @@ -25,7 +25,8 @@ namespace tint { namespace ast { /// An array accessor expression -class ArrayAccessorExpression : public Expression { +class ArrayAccessorExpression + : public Castable { public: /// Constructor ArrayAccessorExpression(); diff --git a/src/ast/array_decoration.cc b/src/ast/array_decoration.cc index 7832e9be8c..088a87f474 100644 --- a/src/ast/array_decoration.cc +++ b/src/ast/array_decoration.cc @@ -23,7 +23,7 @@ namespace ast { constexpr const DecorationKind ArrayDecoration::Kind; -ArrayDecoration::ArrayDecoration(const Source& source) : Decoration(source) {} +ArrayDecoration::ArrayDecoration(const Source& source) : Base(source) {} ArrayDecoration::~ArrayDecoration() = default; diff --git a/src/ast/array_decoration.h b/src/ast/array_decoration.h index f1a953bbaf..92cb00282e 100644 --- a/src/ast/array_decoration.h +++ b/src/ast/array_decoration.h @@ -27,7 +27,7 @@ namespace ast { class StrideDecoration; /// A decoration attached to an array -class ArrayDecoration : public Decoration { +class ArrayDecoration : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kArray; diff --git a/src/ast/assignment_statement.cc b/src/ast/assignment_statement.cc index 04306243c0..cfad841e67 100644 --- a/src/ast/assignment_statement.cc +++ b/src/ast/assignment_statement.cc @@ -17,15 +17,15 @@ namespace tint { namespace ast { -AssignmentStatement::AssignmentStatement() : Statement() {} +AssignmentStatement::AssignmentStatement() : Base() {} AssignmentStatement::AssignmentStatement(Expression* lhs, Expression* rhs) - : Statement(), lhs_(lhs), rhs_(rhs) {} + : Base(), lhs_(lhs), rhs_(rhs) {} AssignmentStatement::AssignmentStatement(const Source& source, Expression* lhs, Expression* rhs) - : Statement(source), lhs_(lhs), rhs_(rhs) {} + : Base(source), lhs_(lhs), rhs_(rhs) {} AssignmentStatement::AssignmentStatement(AssignmentStatement&&) = default; diff --git a/src/ast/assignment_statement.h b/src/ast/assignment_statement.h index 0a2c37903f..dd68ca0759 100644 --- a/src/ast/assignment_statement.h +++ b/src/ast/assignment_statement.h @@ -26,7 +26,7 @@ namespace tint { namespace ast { /// An assignment statement -class AssignmentStatement : public Statement { +class AssignmentStatement : public Castable { public: /// Constructor AssignmentStatement(); diff --git a/src/ast/binary_expression.cc b/src/ast/binary_expression.cc index 25d7fb7c33..d43caeb594 100644 --- a/src/ast/binary_expression.cc +++ b/src/ast/binary_expression.cc @@ -17,18 +17,18 @@ namespace tint { namespace ast { -BinaryExpression::BinaryExpression() : Expression() {} +BinaryExpression::BinaryExpression() : Base() {} BinaryExpression::BinaryExpression(BinaryOp op, Expression* lhs, Expression* rhs) - : Expression(), op_(op), lhs_(lhs), rhs_(rhs) {} + : Base(), op_(op), lhs_(lhs), rhs_(rhs) {} BinaryExpression::BinaryExpression(const Source& source, BinaryOp op, Expression* lhs, Expression* rhs) - : Expression(source), op_(op), lhs_(lhs), rhs_(rhs) {} + : Base(source), op_(op), lhs_(lhs), rhs_(rhs) {} BinaryExpression::BinaryExpression(BinaryExpression&&) = default; diff --git a/src/ast/binary_expression.h b/src/ast/binary_expression.h index 4ef24d8709..e96d8dac16 100644 --- a/src/ast/binary_expression.h +++ b/src/ast/binary_expression.h @@ -48,7 +48,7 @@ enum class BinaryOp { }; /// An binary expression -class BinaryExpression : public Expression { +class BinaryExpression : public Castable { public: /// Constructor BinaryExpression(); diff --git a/src/ast/binding_decoration.cc b/src/ast/binding_decoration.cc index 2af35d903e..671e319d3b 100644 --- a/src/ast/binding_decoration.cc +++ b/src/ast/binding_decoration.cc @@ -20,7 +20,7 @@ namespace ast { constexpr const DecorationKind BindingDecoration::Kind; BindingDecoration::BindingDecoration(uint32_t val, const Source& source) - : VariableDecoration(source), value_(val) {} + : Base(source), value_(val) {} BindingDecoration::~BindingDecoration() = default; @@ -29,7 +29,7 @@ DecorationKind BindingDecoration::GetKind() const { } bool BindingDecoration::IsKind(DecorationKind kind) const { - return kind == Kind || VariableDecoration::IsKind(kind); + return kind == Kind || Base::IsKind(kind); } bool BindingDecoration::IsBinding() const { diff --git a/src/ast/binding_decoration.h b/src/ast/binding_decoration.h index 8e40626bc6..e747edc7fd 100644 --- a/src/ast/binding_decoration.h +++ b/src/ast/binding_decoration.h @@ -23,7 +23,8 @@ namespace tint { namespace ast { /// A binding decoration -class BindingDecoration : public VariableDecoration { +class BindingDecoration + : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kBinding; diff --git a/src/ast/bitcast_expression.cc b/src/ast/bitcast_expression.cc index 693c4ba3e2..6d52a2b24a 100644 --- a/src/ast/bitcast_expression.cc +++ b/src/ast/bitcast_expression.cc @@ -17,15 +17,15 @@ namespace tint { namespace ast { -BitcastExpression::BitcastExpression() : Expression() {} +BitcastExpression::BitcastExpression() : Base() {} BitcastExpression::BitcastExpression(type::Type* type, Expression* expr) - : Expression(), type_(type), expr_(expr) {} + : Base(), type_(type), expr_(expr) {} BitcastExpression::BitcastExpression(const Source& source, type::Type* type, Expression* expr) - : Expression(source), type_(type), expr_(expr) {} + : Base(source), type_(type), expr_(expr) {} BitcastExpression::BitcastExpression(BitcastExpression&&) = default; BitcastExpression::~BitcastExpression() = default; diff --git a/src/ast/bitcast_expression.h b/src/ast/bitcast_expression.h index 014787fb85..7a30c9e6ad 100644 --- a/src/ast/bitcast_expression.h +++ b/src/ast/bitcast_expression.h @@ -26,7 +26,7 @@ namespace tint { namespace ast { /// A bitcast expression -class BitcastExpression : public Expression { +class BitcastExpression : public Castable { public: /// Constructor BitcastExpression(); diff --git a/src/ast/block_statement.cc b/src/ast/block_statement.cc index 7934d02666..a5aa5a9fe5 100644 --- a/src/ast/block_statement.cc +++ b/src/ast/block_statement.cc @@ -17,9 +17,9 @@ namespace tint { namespace ast { -BlockStatement::BlockStatement() : Statement() {} +BlockStatement::BlockStatement() : Base() {} -BlockStatement::BlockStatement(const Source& source) : Statement(source) {} +BlockStatement::BlockStatement(const Source& source) : Base(source) {} BlockStatement::BlockStatement(BlockStatement&&) = default; diff --git a/src/ast/block_statement.h b/src/ast/block_statement.h index eee8f7c82f..07189c7a95 100644 --- a/src/ast/block_statement.h +++ b/src/ast/block_statement.h @@ -25,7 +25,7 @@ namespace tint { namespace ast { /// A block statement -class BlockStatement : public Statement { +class BlockStatement : public Castable { public: /// Constructor BlockStatement(); diff --git a/src/ast/bool_literal.cc b/src/ast/bool_literal.cc index 7e11015120..3fba92d0d0 100644 --- a/src/ast/bool_literal.cc +++ b/src/ast/bool_literal.cc @@ -18,7 +18,7 @@ namespace tint { namespace ast { BoolLiteral::BoolLiteral(ast::type::Type* type, bool value) - : Literal(type), value_(value) {} + : Base(type), value_(value) {} BoolLiteral::~BoolLiteral() = default; diff --git a/src/ast/bool_literal.h b/src/ast/bool_literal.h index fbb18680a3..95914708d4 100644 --- a/src/ast/bool_literal.h +++ b/src/ast/bool_literal.h @@ -23,7 +23,7 @@ namespace tint { namespace ast { /// A boolean literal -class BoolLiteral : public Literal { +class BoolLiteral : public Castable { public: /// Constructor /// @param type the type of the literal diff --git a/src/ast/break_statement.cc b/src/ast/break_statement.cc index db543d39de..ed708401a7 100644 --- a/src/ast/break_statement.cc +++ b/src/ast/break_statement.cc @@ -17,9 +17,9 @@ namespace tint { namespace ast { -BreakStatement::BreakStatement() : Statement() {} +BreakStatement::BreakStatement() : Base() {} -BreakStatement::BreakStatement(const Source& source) : Statement(source) {} +BreakStatement::BreakStatement(const Source& source) : Base(source) {} BreakStatement::BreakStatement(BreakStatement&&) = default; diff --git a/src/ast/break_statement.h b/src/ast/break_statement.h index f29d5fcdda..13a7d57813 100644 --- a/src/ast/break_statement.h +++ b/src/ast/break_statement.h @@ -21,7 +21,7 @@ namespace tint { namespace ast { /// An break statement -class BreakStatement : public Statement { +class BreakStatement : public Castable { public: /// Constructor BreakStatement(); diff --git a/src/ast/builtin_decoration.cc b/src/ast/builtin_decoration.cc index 28108d3536..e59b592f14 100644 --- a/src/ast/builtin_decoration.cc +++ b/src/ast/builtin_decoration.cc @@ -20,7 +20,7 @@ namespace ast { constexpr const DecorationKind BuiltinDecoration::Kind; BuiltinDecoration::BuiltinDecoration(Builtin builtin, const Source& source) - : VariableDecoration(source), builtin_(builtin) {} + : Base(source), builtin_(builtin) {} BuiltinDecoration::~BuiltinDecoration() = default; @@ -29,7 +29,7 @@ DecorationKind BuiltinDecoration::GetKind() const { } bool BuiltinDecoration::IsKind(DecorationKind kind) const { - return kind == Kind || VariableDecoration::IsKind(kind); + return kind == Kind || Base::IsKind(kind); } bool BuiltinDecoration::IsBuiltin() const { diff --git a/src/ast/builtin_decoration.h b/src/ast/builtin_decoration.h index 07dedfe029..cc0dc6d5ab 100644 --- a/src/ast/builtin_decoration.h +++ b/src/ast/builtin_decoration.h @@ -22,7 +22,8 @@ namespace tint { namespace ast { /// A builtin decoration -class BuiltinDecoration : public VariableDecoration { +class BuiltinDecoration + : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kBuiltin; diff --git a/src/ast/call_expression.cc b/src/ast/call_expression.cc index c3d7d8306d..13c5efcc48 100644 --- a/src/ast/call_expression.cc +++ b/src/ast/call_expression.cc @@ -17,15 +17,15 @@ namespace tint { namespace ast { -CallExpression::CallExpression() : Expression() {} +CallExpression::CallExpression() : Base() {} CallExpression::CallExpression(Expression* func, ExpressionList params) - : Expression(), func_(func), params_(params) {} + : Base(), func_(func), params_(params) {} CallExpression::CallExpression(const Source& source, Expression* func, ExpressionList params) - : Expression(source), func_(func), params_(params) {} + : Base(source), func_(func), params_(params) {} CallExpression::CallExpression(CallExpression&&) = default; diff --git a/src/ast/call_expression.h b/src/ast/call_expression.h index cae3f9c0da..c79dffdeb7 100644 --- a/src/ast/call_expression.h +++ b/src/ast/call_expression.h @@ -25,7 +25,7 @@ namespace tint { namespace ast { /// A call expression -class CallExpression : public Expression { +class CallExpression : public Castable { public: /// Constructor CallExpression(); diff --git a/src/ast/call_statement.cc b/src/ast/call_statement.cc index 7c43049d1e..0ff5188d57 100644 --- a/src/ast/call_statement.cc +++ b/src/ast/call_statement.cc @@ -19,9 +19,9 @@ namespace tint { namespace ast { -CallStatement::CallStatement() : Statement() {} +CallStatement::CallStatement() : Base() {} -CallStatement::CallStatement(CallExpression* call) : Statement(), call_(call) {} +CallStatement::CallStatement(CallExpression* call) : Base(), call_(call) {} CallStatement::CallStatement(CallStatement&&) = default; diff --git a/src/ast/call_statement.h b/src/ast/call_statement.h index c4cee4da9d..c74f15628b 100644 --- a/src/ast/call_statement.h +++ b/src/ast/call_statement.h @@ -25,7 +25,7 @@ namespace tint { namespace ast { /// A call expression -class CallStatement : public Statement { +class CallStatement : public Castable { public: /// Constructor CallStatement(); diff --git a/src/ast/case_statement.cc b/src/ast/case_statement.cc index 667390ce95..84cda9414c 100644 --- a/src/ast/case_statement.cc +++ b/src/ast/case_statement.cc @@ -17,15 +17,15 @@ namespace tint { namespace ast { -CaseStatement::CaseStatement(BlockStatement* body) : Statement(), body_(body) {} +CaseStatement::CaseStatement(BlockStatement* body) : Base(), body_(body) {} CaseStatement::CaseStatement(CaseSelectorList selectors, BlockStatement* body) - : Statement(), selectors_(selectors), body_(body) {} + : Base(), selectors_(selectors), body_(body) {} CaseStatement::CaseStatement(const Source& source, CaseSelectorList selectors, BlockStatement* body) - : Statement(source), selectors_(selectors), body_(body) {} + : Base(source), selectors_(selectors), body_(body) {} CaseStatement::CaseStatement(CaseStatement&&) = default; diff --git a/src/ast/case_statement.h b/src/ast/case_statement.h index 73844fd07f..aacd2f0ff8 100644 --- a/src/ast/case_statement.h +++ b/src/ast/case_statement.h @@ -31,7 +31,7 @@ namespace ast { using CaseSelectorList = std::vector; /// A case statement -class CaseStatement : public Statement { +class CaseStatement : public Castable { public: /// Constructor /// Creates a default case statement diff --git a/src/ast/constant_id_decoration.cc b/src/ast/constant_id_decoration.cc index 3cd219da0f..7b1bc534df 100644 --- a/src/ast/constant_id_decoration.cc +++ b/src/ast/constant_id_decoration.cc @@ -20,7 +20,7 @@ namespace ast { constexpr const DecorationKind ConstantIdDecoration::Kind; ConstantIdDecoration::ConstantIdDecoration(uint32_t val, const Source& source) - : VariableDecoration(source), value_(val) {} + : Base(source), value_(val) {} ConstantIdDecoration::~ConstantIdDecoration() = default; @@ -29,7 +29,7 @@ DecorationKind ConstantIdDecoration::GetKind() const { } bool ConstantIdDecoration::IsKind(DecorationKind kind) const { - return kind == Kind || VariableDecoration::IsKind(kind); + return kind == Kind || Base::IsKind(kind); } bool ConstantIdDecoration::IsConstantId() const { diff --git a/src/ast/constant_id_decoration.h b/src/ast/constant_id_decoration.h index b2776fd33d..cc260cf5b5 100644 --- a/src/ast/constant_id_decoration.h +++ b/src/ast/constant_id_decoration.h @@ -22,7 +22,8 @@ namespace tint { namespace ast { /// A constant id decoration -class ConstantIdDecoration : public VariableDecoration { +class ConstantIdDecoration + : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kConstantId; diff --git a/src/ast/constructor_expression.cc b/src/ast/constructor_expression.cc index 5202bdf090..6aae25003a 100644 --- a/src/ast/constructor_expression.cc +++ b/src/ast/constructor_expression.cc @@ -26,8 +26,10 @@ ConstructorExpression::ConstructorExpression() = default; ConstructorExpression::~ConstructorExpression() = default; +ConstructorExpression::ConstructorExpression(ConstructorExpression&&) = default; + ConstructorExpression::ConstructorExpression(const Source& source) - : Expression(source) {} + : Base(source) {} bool ConstructorExpression::IsConstructor() const { return true; diff --git a/src/ast/constructor_expression.h b/src/ast/constructor_expression.h index 5aaa5c3b8e..96133181a1 100644 --- a/src/ast/constructor_expression.h +++ b/src/ast/constructor_expression.h @@ -24,7 +24,8 @@ class ScalarConstructorExpression; class TypeConstructorExpression; /// Base class for constructor style expressions -class ConstructorExpression : public Expression { +class ConstructorExpression + : public Castable { public: ~ConstructorExpression() override; @@ -48,7 +49,7 @@ class ConstructorExpression : public Expression { /// @param source the constructor source explicit ConstructorExpression(const Source& source); /// Move constructor - ConstructorExpression(ConstructorExpression&&) = default; + ConstructorExpression(ConstructorExpression&&); private: ConstructorExpression(const ConstructorExpression&) = delete; diff --git a/src/ast/continue_statement.cc b/src/ast/continue_statement.cc index efc17d9132..f66a958f99 100644 --- a/src/ast/continue_statement.cc +++ b/src/ast/continue_statement.cc @@ -17,10 +17,9 @@ namespace tint { namespace ast { -ContinueStatement::ContinueStatement() : Statement() {} +ContinueStatement::ContinueStatement() : Base() {} -ContinueStatement::ContinueStatement(const Source& source) - : Statement(source) {} +ContinueStatement::ContinueStatement(const Source& source) : Base(source) {} ContinueStatement::ContinueStatement(ContinueStatement&&) = default; diff --git a/src/ast/continue_statement.h b/src/ast/continue_statement.h index 866917bb40..1eb93f926f 100644 --- a/src/ast/continue_statement.h +++ b/src/ast/continue_statement.h @@ -24,7 +24,7 @@ namespace tint { namespace ast { /// An continue statement -class ContinueStatement : public Statement { +class ContinueStatement : public Castable { public: /// Constructor ContinueStatement(); diff --git a/src/ast/decorated_variable.cc b/src/ast/decorated_variable.cc index cd83395254..9b30e57a39 100644 --- a/src/ast/decorated_variable.cc +++ b/src/ast/decorated_variable.cc @@ -24,7 +24,7 @@ namespace ast { DecoratedVariable::DecoratedVariable() = default; DecoratedVariable::DecoratedVariable(Variable* var) - : Variable(var->source(), var->name(), var->storage_class(), var->type()) {} + : Base(var->source(), var->name(), var->storage_class(), var->type()) {} DecoratedVariable::DecoratedVariable(DecoratedVariable&&) = default; diff --git a/src/ast/decorated_variable.h b/src/ast/decorated_variable.h index 8c2c34b0df..1eeea8c09d 100644 --- a/src/ast/decorated_variable.h +++ b/src/ast/decorated_variable.h @@ -25,7 +25,7 @@ namespace tint { namespace ast { /// A Decorated Variable statement. -class DecoratedVariable : public Variable { +class DecoratedVariable : public Castable { public: /// Create a new empty decorated variable statement DecoratedVariable(); diff --git a/src/ast/decoration.h b/src/ast/decoration.h index c7dffdb449..bf30452b80 100644 --- a/src/ast/decoration.h +++ b/src/ast/decoration.h @@ -47,7 +47,7 @@ enum class DecorationKind { std::ostream& operator<<(std::ostream& out, DecorationKind data); /// The base class for all decorations -class Decoration : public Node { +class Decoration : public Castable { public: ~Decoration() override; @@ -59,19 +59,13 @@ class Decoration : public Node { /// kind. virtual bool IsKind(DecorationKind kind) const = 0; - /// @return true if this decoration is of (or derives from) type |TO| - template - bool Is() const { - return IsKind(TO::Kind); - } - /// @returns true if the node is valid bool IsValid() const override; protected: /// Constructor /// @param source the source of this decoration - explicit Decoration(const Source& source) : Node(source) {} + explicit Decoration(const Source& source) : Base(source) {} }; /// As dynamically casts |deco| to the target type |TO|. diff --git a/src/ast/decoration_test.cc b/src/ast/decoration_test.cc index a9beaac1d8..1df9f9cf89 100644 --- a/src/ast/decoration_test.cc +++ b/src/ast/decoration_test.cc @@ -57,7 +57,7 @@ TEST_F(DecorationTest, AsIncorrectType) { } TEST_F(DecorationTest, Is) { - auto* decoration = create(1, Source{}); + Decoration* decoration = create(1, Source{}); EXPECT_TRUE(decoration->Is()); EXPECT_FALSE(decoration->Is()); } diff --git a/src/ast/discard_statement.cc b/src/ast/discard_statement.cc index 6864aa0fff..e2c17fad5d 100644 --- a/src/ast/discard_statement.cc +++ b/src/ast/discard_statement.cc @@ -17,9 +17,11 @@ namespace tint { namespace ast { -DiscardStatement::DiscardStatement() : Statement() {} +DiscardStatement::DiscardStatement() : Base() {} -DiscardStatement::DiscardStatement(const Source& source) : Statement(source) {} +DiscardStatement::DiscardStatement(const Source& source) : Base(source) {} + +DiscardStatement::DiscardStatement(DiscardStatement&&) = default; DiscardStatement::~DiscardStatement() = default; diff --git a/src/ast/discard_statement.h b/src/ast/discard_statement.h index af0f3fd79b..6f2e42abcf 100644 --- a/src/ast/discard_statement.h +++ b/src/ast/discard_statement.h @@ -21,7 +21,7 @@ namespace tint { namespace ast { /// A discard statement -class DiscardStatement : public Statement { +class DiscardStatement : public Castable { public: /// Constructor DiscardStatement(); @@ -29,7 +29,7 @@ class DiscardStatement : public Statement { /// @param source the discard statement source explicit DiscardStatement(const Source& source); /// Move constructor - DiscardStatement(DiscardStatement&&) = default; + DiscardStatement(DiscardStatement&&); ~DiscardStatement() override; /// @returns true if this is a discard statement diff --git a/src/ast/else_statement.cc b/src/ast/else_statement.cc index b084f8dc71..00279c3172 100644 --- a/src/ast/else_statement.cc +++ b/src/ast/else_statement.cc @@ -17,18 +17,18 @@ namespace tint { namespace ast { -ElseStatement::ElseStatement(BlockStatement* body) : Statement(), body_(body) {} +ElseStatement::ElseStatement(BlockStatement* body) : Base(), body_(body) {} ElseStatement::ElseStatement(Expression* condition, BlockStatement* body) - : Statement(), condition_(condition), body_(body) {} + : Base(), condition_(condition), body_(body) {} ElseStatement::ElseStatement(const Source& source, BlockStatement* body) - : Statement(source), body_(body) {} + : Base(source), body_(body) {} ElseStatement::ElseStatement(const Source& source, Expression* condition, BlockStatement* body) - : Statement(source), condition_(condition), body_(body) {} + : Base(source), condition_(condition), body_(body) {} ElseStatement::ElseStatement(ElseStatement&&) = default; diff --git a/src/ast/else_statement.h b/src/ast/else_statement.h index c1feb6ef45..b75904d8de 100644 --- a/src/ast/else_statement.h +++ b/src/ast/else_statement.h @@ -27,7 +27,7 @@ namespace tint { namespace ast { /// An else statement -class ElseStatement : public Statement { +class ElseStatement : public Castable { public: /// Constructor /// @param body the else body diff --git a/src/ast/expression.cc b/src/ast/expression.cc index 90d597e72c..0f77f2e6ec 100644 --- a/src/ast/expression.cc +++ b/src/ast/expression.cc @@ -31,7 +31,9 @@ namespace ast { Expression::Expression() = default; -Expression::Expression(const Source& source) : Node(source) {} +Expression::Expression(const Source& source) : Base(source) {} + +Expression::Expression(Expression&&) = default; Expression::~Expression() = default; diff --git a/src/ast/expression.h b/src/ast/expression.h index e696812043..c4d85d4e85 100644 --- a/src/ast/expression.h +++ b/src/ast/expression.h @@ -35,7 +35,7 @@ class MemberAccessorExpression; class UnaryOpExpression; /// Base expression class -class Expression : public Node { +class Expression : public Castable { public: ~Expression() override; @@ -109,7 +109,7 @@ class Expression : public Node { /// @param source the source of the expression explicit Expression(const Source& source); /// Move constructor - Expression(Expression&&) = default; + Expression(Expression&&); private: Expression(const Expression&) = delete; diff --git a/src/ast/fallthrough_statement.cc b/src/ast/fallthrough_statement.cc index 9abb2d25ed..6c84ab3a2c 100644 --- a/src/ast/fallthrough_statement.cc +++ b/src/ast/fallthrough_statement.cc @@ -17,10 +17,12 @@ namespace tint { namespace ast { -FallthroughStatement::FallthroughStatement() : Statement() {} +FallthroughStatement::FallthroughStatement() : Base() {} FallthroughStatement::FallthroughStatement(const Source& source) - : Statement(source) {} + : Base(source) {} + +FallthroughStatement::FallthroughStatement(FallthroughStatement&&) = default; FallthroughStatement::~FallthroughStatement() = default; diff --git a/src/ast/fallthrough_statement.h b/src/ast/fallthrough_statement.h index 7579e499e9..f586666d36 100644 --- a/src/ast/fallthrough_statement.h +++ b/src/ast/fallthrough_statement.h @@ -21,7 +21,7 @@ namespace tint { namespace ast { /// An fallthrough statement -class FallthroughStatement : public Statement { +class FallthroughStatement : public Castable { public: /// Constructor FallthroughStatement(); @@ -29,7 +29,7 @@ class FallthroughStatement : public Statement { /// @param source the source information explicit FallthroughStatement(const Source& source); /// Move constructor - FallthroughStatement(FallthroughStatement&&) = default; + FallthroughStatement(FallthroughStatement&&); ~FallthroughStatement() override; /// @returns true if this is an fallthrough statement diff --git a/src/ast/float_literal.cc b/src/ast/float_literal.cc index 3d6d1f84ad..d7b6a3152f 100644 --- a/src/ast/float_literal.cc +++ b/src/ast/float_literal.cc @@ -21,7 +21,7 @@ namespace tint { namespace ast { FloatLiteral::FloatLiteral(ast::type::Type* type, float value) - : Literal(type), value_(value) {} + : Base(type), value_(value) {} FloatLiteral::~FloatLiteral() = default; diff --git a/src/ast/float_literal.h b/src/ast/float_literal.h index 44977c25be..d8b69e4946 100644 --- a/src/ast/float_literal.h +++ b/src/ast/float_literal.h @@ -23,7 +23,7 @@ namespace tint { namespace ast { /// A float literal -class FloatLiteral : public Literal { +class FloatLiteral : public Castable { public: /// Constructor /// @param type the type of the literal diff --git a/src/ast/function.cc b/src/ast/function.cc index 0d20fc1497..da38be0e56 100644 --- a/src/ast/function.cc +++ b/src/ast/function.cc @@ -32,7 +32,7 @@ Function::Function(const std::string& name, VariableList params, type::Type* return_type, BlockStatement* body) - : Node(), + : Base(), name_(name), params_(std::move(params)), return_type_(return_type), @@ -43,7 +43,7 @@ Function::Function(const Source& source, VariableList params, type::Type* return_type, BlockStatement* body) - : Node(source), + : Base(source), name_(name), params_(std::move(params)), return_type_(return_type), diff --git a/src/ast/function.h b/src/ast/function.h index 679a6d8413..acaf30cbd3 100644 --- a/src/ast/function.h +++ b/src/ast/function.h @@ -40,7 +40,7 @@ namespace tint { namespace ast { /// A Function statement. -class Function : public Node { +class Function : public Castable { public: /// Information about a binding struct BindingInfo { diff --git a/src/ast/function_decoration.cc b/src/ast/function_decoration.cc index 2d11714b21..36861c4093 100644 --- a/src/ast/function_decoration.cc +++ b/src/ast/function_decoration.cc @@ -24,8 +24,7 @@ namespace ast { constexpr const DecorationKind FunctionDecoration::Kind; -FunctionDecoration::FunctionDecoration(const Source& source) - : Decoration(source) {} +FunctionDecoration::FunctionDecoration(const Source& source) : Base(source) {} FunctionDecoration::~FunctionDecoration() = default; diff --git a/src/ast/function_decoration.h b/src/ast/function_decoration.h index 86b951420a..5c15a6cee3 100644 --- a/src/ast/function_decoration.h +++ b/src/ast/function_decoration.h @@ -28,7 +28,7 @@ class StageDecoration; class WorkgroupDecoration; /// A decoration attached to a function -class FunctionDecoration : public Decoration { +class FunctionDecoration : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kFunction; diff --git a/src/ast/identifier_expression.cc b/src/ast/identifier_expression.cc index 76f92a2643..ecad6add5a 100644 --- a/src/ast/identifier_expression.cc +++ b/src/ast/identifier_expression.cc @@ -18,11 +18,11 @@ namespace tint { namespace ast { IdentifierExpression::IdentifierExpression(const std::string& name) - : Expression(), name_(name) {} + : Base(), name_(name) {} IdentifierExpression::IdentifierExpression(const Source& source, const std::string& name) - : Expression(source), name_(name) {} + : Base(source), name_(name) {} IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default; diff --git a/src/ast/identifier_expression.h b/src/ast/identifier_expression.h index 4c6ac31a46..b13fb0ef1c 100644 --- a/src/ast/identifier_expression.h +++ b/src/ast/identifier_expression.h @@ -26,7 +26,7 @@ namespace tint { namespace ast { /// An identifier expression -class IdentifierExpression : public Expression { +class IdentifierExpression : public Castable { public: /// Constructor /// @param name the name diff --git a/src/ast/if_statement.cc b/src/ast/if_statement.cc index 6e4ffbe775..bcf156c3af 100644 --- a/src/ast/if_statement.cc +++ b/src/ast/if_statement.cc @@ -20,12 +20,12 @@ namespace tint { namespace ast { IfStatement::IfStatement(Expression* condition, BlockStatement* body) - : Statement(), condition_(condition), body_(body) {} + : Base(), condition_(condition), body_(body) {} IfStatement::IfStatement(const Source& source, Expression* condition, BlockStatement* body) - : Statement(source), condition_(condition), body_(body) {} + : Base(source), condition_(condition), body_(body) {} IfStatement::IfStatement(IfStatement&&) = default; diff --git a/src/ast/if_statement.h b/src/ast/if_statement.h index 62b53ebbaf..4b8a0fb94e 100644 --- a/src/ast/if_statement.h +++ b/src/ast/if_statement.h @@ -27,7 +27,7 @@ namespace tint { namespace ast { /// An if statement -class IfStatement : public Statement { +class IfStatement : public Castable { public: /// Constructor /// @param condition the if condition diff --git a/src/ast/int_literal.cc b/src/ast/int_literal.cc index c641ac28bf..20480d225d 100644 --- a/src/ast/int_literal.cc +++ b/src/ast/int_literal.cc @@ -17,7 +17,7 @@ namespace tint { namespace ast { -IntLiteral::IntLiteral(ast::type::Type* type) : Literal(type) {} +IntLiteral::IntLiteral(ast::type::Type* type) : Base(type) {} IntLiteral::~IntLiteral() = default; diff --git a/src/ast/int_literal.h b/src/ast/int_literal.h index 8f092990d1..d23fceb271 100644 --- a/src/ast/int_literal.h +++ b/src/ast/int_literal.h @@ -23,7 +23,7 @@ namespace tint { namespace ast { /// An integer literal. This could be either signed or unsigned. -class IntLiteral : public Literal { +class IntLiteral : public Castable { public: ~IntLiteral() override; diff --git a/src/ast/literal.h b/src/ast/literal.h index 2154b2b089..b8c1b7c280 100644 --- a/src/ast/literal.h +++ b/src/ast/literal.h @@ -31,7 +31,7 @@ class IntLiteral; class UintLiteral; /// Base class for a literal value -class Literal : public Node { +class Literal : public Castable { public: ~Literal() override; diff --git a/src/ast/location_decoration.cc b/src/ast/location_decoration.cc index 51737d99ef..1ca0e39271 100644 --- a/src/ast/location_decoration.cc +++ b/src/ast/location_decoration.cc @@ -20,7 +20,7 @@ namespace ast { constexpr const DecorationKind LocationDecoration::Kind; LocationDecoration::LocationDecoration(uint32_t val, const Source& source) - : VariableDecoration(source), value_(val) {} + : Base(source), value_(val) {} LocationDecoration::~LocationDecoration() = default; @@ -29,7 +29,7 @@ DecorationKind LocationDecoration::GetKind() const { } bool LocationDecoration::IsKind(DecorationKind kind) const { - return kind == Kind || VariableDecoration::IsKind(kind); + return kind == Kind || Base::IsKind(kind); } bool LocationDecoration::IsLocation() const { diff --git a/src/ast/location_decoration.h b/src/ast/location_decoration.h index ae7aed151b..c99267d16a 100644 --- a/src/ast/location_decoration.h +++ b/src/ast/location_decoration.h @@ -23,7 +23,8 @@ namespace tint { namespace ast { /// A location decoration -class LocationDecoration : public VariableDecoration { +class LocationDecoration + : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kLocation; diff --git a/src/ast/loop_statement.cc b/src/ast/loop_statement.cc index d1e865d3db..fbffebeeac 100644 --- a/src/ast/loop_statement.cc +++ b/src/ast/loop_statement.cc @@ -18,12 +18,12 @@ namespace tint { namespace ast { LoopStatement::LoopStatement(BlockStatement* body, BlockStatement* continuing) - : Statement(), body_(body), continuing_(continuing) {} + : Base(), body_(body), continuing_(continuing) {} LoopStatement::LoopStatement(const Source& source, BlockStatement* body, BlockStatement* continuing) - : Statement(source), body_(body), continuing_(continuing) {} + : Base(source), body_(body), continuing_(continuing) {} LoopStatement::LoopStatement(LoopStatement&&) = default; diff --git a/src/ast/loop_statement.h b/src/ast/loop_statement.h index d0d959f4ff..f1ed1924b0 100644 --- a/src/ast/loop_statement.h +++ b/src/ast/loop_statement.h @@ -25,7 +25,7 @@ namespace tint { namespace ast { /// A loop statement -class LoopStatement : public Statement { +class LoopStatement : public Castable { public: /// Constructor /// @param body the body statements diff --git a/src/ast/member_accessor_expression.cc b/src/ast/member_accessor_expression.cc index 18ca50d4e5..029c272b61 100644 --- a/src/ast/member_accessor_expression.cc +++ b/src/ast/member_accessor_expression.cc @@ -21,12 +21,12 @@ MemberAccessorExpression::MemberAccessorExpression() = default; MemberAccessorExpression::MemberAccessorExpression(Expression* structure, IdentifierExpression* member) - : Expression(), struct_(structure), member_(member) {} + : Base(), struct_(structure), member_(member) {} MemberAccessorExpression::MemberAccessorExpression(const Source& source, Expression* structure, IdentifierExpression* member) - : Expression(source), struct_(structure), member_(member) {} + : Base(source), struct_(structure), member_(member) {} MemberAccessorExpression::MemberAccessorExpression(MemberAccessorExpression&&) = default; diff --git a/src/ast/member_accessor_expression.h b/src/ast/member_accessor_expression.h index f0c9aa97f5..006ef88886 100644 --- a/src/ast/member_accessor_expression.h +++ b/src/ast/member_accessor_expression.h @@ -27,7 +27,8 @@ namespace tint { namespace ast { /// A member accessor expression -class MemberAccessorExpression : public Expression { +class MemberAccessorExpression + : public Castable { public: /// Constructor MemberAccessorExpression(); diff --git a/src/ast/node.cc b/src/ast/node.cc index 8870db00ca..2c7395be2b 100644 --- a/src/ast/node.cc +++ b/src/ast/node.cc @@ -23,6 +23,8 @@ Node::Node() = default; Node::Node(const Source& source) : source_(source) {} +Node::Node(Node&&) = default; + Node::~Node() = default; void Node::make_indent(std::ostream& out, size_t indent) const { diff --git a/src/ast/node.h b/src/ast/node.h index 9ab4db65f2..9bfe8d6711 100644 --- a/src/ast/node.h +++ b/src/ast/node.h @@ -18,15 +18,16 @@ #include #include +#include "src/castable.h" #include "src/source.h" namespace tint { namespace ast { /// AST base class node -class Node { +class Node : public Castable { public: - virtual ~Node(); + ~Node() override; /// @returns the node source data const Source& source() const { return source_; } @@ -53,7 +54,7 @@ class Node { /// @param source The input source for the node explicit Node(const Source& source); /// Move constructor - Node(Node&&) = default; + Node(Node&&); /// Writes indent into stream /// @param out the stream to write to diff --git a/src/ast/null_literal.cc b/src/ast/null_literal.cc index 7d4475199c..3c759ed500 100644 --- a/src/ast/null_literal.cc +++ b/src/ast/null_literal.cc @@ -17,7 +17,7 @@ namespace tint { namespace ast { -NullLiteral::NullLiteral(ast::type::Type* type) : Literal(type) {} +NullLiteral::NullLiteral(ast::type::Type* type) : Base(type) {} NullLiteral::~NullLiteral() = default; diff --git a/src/ast/null_literal.h b/src/ast/null_literal.h index cfe2a87a57..0c396c91b6 100644 --- a/src/ast/null_literal.h +++ b/src/ast/null_literal.h @@ -23,7 +23,7 @@ namespace tint { namespace ast { /// A null literal -class NullLiteral : public Literal { +class NullLiteral : public Castable { public: /// Constructor /// @param type the type diff --git a/src/ast/return_statement.cc b/src/ast/return_statement.cc index 8f788611d8..e395dfcf06 100644 --- a/src/ast/return_statement.cc +++ b/src/ast/return_statement.cc @@ -17,15 +17,14 @@ namespace tint { namespace ast { -ReturnStatement::ReturnStatement() : Statement() {} +ReturnStatement::ReturnStatement() : Base() {} -ReturnStatement::ReturnStatement(const Source& source) : Statement(source) {} +ReturnStatement::ReturnStatement(const Source& source) : Base(source) {} -ReturnStatement::ReturnStatement(Expression* value) - : Statement(), value_(value) {} +ReturnStatement::ReturnStatement(Expression* value) : Base(), value_(value) {} ReturnStatement::ReturnStatement(const Source& source, Expression* value) - : Statement(source), value_(value) {} + : Base(source), value_(value) {} ReturnStatement::ReturnStatement(ReturnStatement&&) = default; diff --git a/src/ast/return_statement.h b/src/ast/return_statement.h index 4605fd7a05..a1177f7125 100644 --- a/src/ast/return_statement.h +++ b/src/ast/return_statement.h @@ -25,7 +25,7 @@ namespace tint { namespace ast { /// A return statement -class ReturnStatement : public Statement { +class ReturnStatement : public Castable { public: /// Constructor ReturnStatement(); diff --git a/src/ast/scalar_constructor_expression.cc b/src/ast/scalar_constructor_expression.cc index f82983db15..02fee32d88 100644 --- a/src/ast/scalar_constructor_expression.cc +++ b/src/ast/scalar_constructor_expression.cc @@ -17,15 +17,14 @@ namespace tint { namespace ast { -ScalarConstructorExpression::ScalarConstructorExpression() - : ConstructorExpression() {} +ScalarConstructorExpression::ScalarConstructorExpression() : Base() {} ScalarConstructorExpression::ScalarConstructorExpression(Literal* literal) : literal_(literal) {} ScalarConstructorExpression::ScalarConstructorExpression(const Source& source, Literal* litearl) - : ConstructorExpression(source), literal_(litearl) {} + : Base(source), literal_(litearl) {} ScalarConstructorExpression::ScalarConstructorExpression( ScalarConstructorExpression&&) = default; diff --git a/src/ast/scalar_constructor_expression.h b/src/ast/scalar_constructor_expression.h index 360a2e83ad..d780fef0b3 100644 --- a/src/ast/scalar_constructor_expression.h +++ b/src/ast/scalar_constructor_expression.h @@ -25,7 +25,8 @@ namespace tint { namespace ast { /// A scalar constructor -class ScalarConstructorExpression : public ConstructorExpression { +class ScalarConstructorExpression + : public Castable { public: /// Constructor ScalarConstructorExpression(); diff --git a/src/ast/set_decoration.cc b/src/ast/set_decoration.cc index 08d5312afc..4178e4d270 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(source), value_(val) {} + : Base(source), value_(val) {} SetDecoration::~SetDecoration() = default; diff --git a/src/ast/set_decoration.h b/src/ast/set_decoration.h index 5398c88f70..73469c43ab 100644 --- a/src/ast/set_decoration.h +++ b/src/ast/set_decoration.h @@ -23,7 +23,7 @@ namespace tint { namespace ast { /// A set decoration -class SetDecoration : public VariableDecoration { +class SetDecoration : public Castable { public: /// constructor /// @param value the set value diff --git a/src/ast/sint_literal.cc b/src/ast/sint_literal.cc index 93aab83c78..6a5da13ea3 100644 --- a/src/ast/sint_literal.cc +++ b/src/ast/sint_literal.cc @@ -18,7 +18,7 @@ namespace tint { namespace ast { SintLiteral::SintLiteral(ast::type::Type* type, int32_t value) - : IntLiteral(type), value_(value) {} + : Base(type), value_(value) {} SintLiteral::~SintLiteral() = default; diff --git a/src/ast/sint_literal.h b/src/ast/sint_literal.h index 3995148e49..0e4db0435f 100644 --- a/src/ast/sint_literal.h +++ b/src/ast/sint_literal.h @@ -23,7 +23,7 @@ namespace tint { namespace ast { /// A signed int literal -class SintLiteral : public IntLiteral { +class SintLiteral : public Castable { public: /// Constructor /// @param type the type diff --git a/src/ast/stage_decoration.cc b/src/ast/stage_decoration.cc index ae996c8fef..307503ba9d 100644 --- a/src/ast/stage_decoration.cc +++ b/src/ast/stage_decoration.cc @@ -20,7 +20,7 @@ namespace ast { constexpr const DecorationKind StageDecoration::Kind; StageDecoration::StageDecoration(ast::PipelineStage stage, const Source& source) - : FunctionDecoration(source), stage_(stage) {} + : Base(source), stage_(stage) {} StageDecoration::~StageDecoration() = default; @@ -29,7 +29,7 @@ DecorationKind StageDecoration::GetKind() const { } bool StageDecoration::IsKind(DecorationKind kind) const { - return kind == Kind || FunctionDecoration::IsKind(kind); + return kind == Kind || Base::IsKind(kind); } bool StageDecoration::IsStage() const { diff --git a/src/ast/stage_decoration.h b/src/ast/stage_decoration.h index 0b7e94a71b..15b1d60485 100644 --- a/src/ast/stage_decoration.h +++ b/src/ast/stage_decoration.h @@ -22,7 +22,7 @@ namespace tint { namespace ast { /// A workgroup decoration -class StageDecoration : public FunctionDecoration { +class StageDecoration : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kStage; diff --git a/src/ast/statement.cc b/src/ast/statement.cc index cd3e09d8b7..f44286f1e6 100644 --- a/src/ast/statement.cc +++ b/src/ast/statement.cc @@ -36,7 +36,7 @@ namespace ast { Statement::Statement() = default; -Statement::Statement(const Source& source) : Node(source) {} +Statement::Statement(const Source& source) : Base(source) {} Statement::Statement(Statement&&) = default; diff --git a/src/ast/statement.h b/src/ast/statement.h index c75b091b1e..7e791ba54d 100644 --- a/src/ast/statement.h +++ b/src/ast/statement.h @@ -39,7 +39,7 @@ class SwitchStatement; class VariableDeclStatement; /// Base statement class -class Statement : public Node { +class Statement : public Castable { public: ~Statement() override; diff --git a/src/ast/stride_decoration.cc b/src/ast/stride_decoration.cc index d92bf58175..8e30f3c9c7 100644 --- a/src/ast/stride_decoration.cc +++ b/src/ast/stride_decoration.cc @@ -20,14 +20,14 @@ namespace ast { constexpr const DecorationKind StrideDecoration::Kind; StrideDecoration::StrideDecoration(uint32_t stride, const Source& source) - : ArrayDecoration(source), stride_(stride) {} + : Base(source), stride_(stride) {} DecorationKind StrideDecoration::GetKind() const { return Kind; } bool StrideDecoration::IsKind(DecorationKind kind) const { - return kind == Kind || ArrayDecoration::IsKind(kind); + return kind == Kind || Base::IsKind(kind); } bool StrideDecoration::IsStride() const { diff --git a/src/ast/stride_decoration.h b/src/ast/stride_decoration.h index f97734ee49..a64754a2cf 100644 --- a/src/ast/stride_decoration.h +++ b/src/ast/stride_decoration.h @@ -25,7 +25,7 @@ namespace tint { namespace ast { /// A stride decoration -class StrideDecoration : public ArrayDecoration { +class StrideDecoration : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kStride; diff --git a/src/ast/struct.cc b/src/ast/struct.cc index 73dc11f2b9..525afe41b5 100644 --- a/src/ast/struct.cc +++ b/src/ast/struct.cc @@ -17,23 +17,23 @@ namespace tint { namespace ast { -Struct::Struct() : Node() {} +Struct::Struct() : Base() {} Struct::Struct(StructMemberList members) - : Node(), members_(std::move(members)) {} + : Base(), members_(std::move(members)) {} Struct::Struct(StructDecorationList decorations, StructMemberList members) - : Node(), + : Base(), decorations_(std::move(decorations)), members_(std::move(members)) {} Struct::Struct(const Source& source, StructMemberList members) - : Node(source), members_(std::move(members)) {} + : Base(source), members_(std::move(members)) {} Struct::Struct(const Source& source, StructDecorationList decorations, StructMemberList members) - : Node(source), + : Base(source), decorations_(std::move(decorations)), members_(std::move(members)) {} diff --git a/src/ast/struct.h b/src/ast/struct.h index 8a55b8d9da..419b2708f7 100644 --- a/src/ast/struct.h +++ b/src/ast/struct.h @@ -27,7 +27,7 @@ namespace tint { namespace ast { /// A struct statement. -class Struct : public Node { +class Struct : public Castable { public: /// Create a new empty struct statement Struct(); diff --git a/src/ast/struct_block_decoration.cc b/src/ast/struct_block_decoration.cc index 585646d0c4..33fa124519 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(source) {} + : Base(source) {} StructBlockDecoration::~StructBlockDecoration() = default; diff --git a/src/ast/struct_block_decoration.h b/src/ast/struct_block_decoration.h index 34b031c44e..9c062554a8 100644 --- a/src/ast/struct_block_decoration.h +++ b/src/ast/struct_block_decoration.h @@ -25,7 +25,8 @@ namespace tint { namespace ast { /// The struct decorations -class StructBlockDecoration : public StructDecoration { +class StructBlockDecoration + : public Castable { public: /// constructor /// @param source the source of this decoration diff --git a/src/ast/struct_decoration.cc b/src/ast/struct_decoration.cc index 5b93b909a3..68b54a4394 100644 --- a/src/ast/struct_decoration.cc +++ b/src/ast/struct_decoration.cc @@ -19,7 +19,7 @@ namespace ast { constexpr const DecorationKind StructDecoration::Kind; -StructDecoration::StructDecoration(const Source& source) : Decoration(source) {} +StructDecoration::StructDecoration(const Source& source) : Base(source) {} StructDecoration::~StructDecoration() = default; diff --git a/src/ast/struct_decoration.h b/src/ast/struct_decoration.h index 727ba7da84..75d3e69a82 100644 --- a/src/ast/struct_decoration.h +++ b/src/ast/struct_decoration.h @@ -25,7 +25,7 @@ namespace tint { namespace ast { /// The struct decorations -class StructDecoration : public Decoration { +class StructDecoration : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kStruct; diff --git a/src/ast/struct_member.cc b/src/ast/struct_member.cc index 8d54ad5d78..629323482c 100644 --- a/src/ast/struct_member.cc +++ b/src/ast/struct_member.cc @@ -24,13 +24,13 @@ StructMember::StructMember() = default; StructMember::StructMember(const std::string& name, type::Type* type, StructMemberDecorationList decorations) - : Node(), name_(name), type_(type), decorations_(std::move(decorations)) {} + : Base(), name_(name), type_(type), decorations_(std::move(decorations)) {} StructMember::StructMember(const Source& source, const std::string& name, type::Type* type, StructMemberDecorationList decorations) - : Node(source), + : Base(source), name_(name), type_(type), decorations_(std::move(decorations)) {} diff --git a/src/ast/struct_member.h b/src/ast/struct_member.h index 00dd870eba..ea18502e8c 100644 --- a/src/ast/struct_member.h +++ b/src/ast/struct_member.h @@ -29,7 +29,7 @@ namespace tint { namespace ast { /// A struct member statement. -class StructMember : public Node { +class StructMember : public Castable { public: /// Create a new empty struct member statement StructMember(); diff --git a/src/ast/struct_member_decoration.cc b/src/ast/struct_member_decoration.cc index 8573bc727e..b56ec520c1 100644 --- a/src/ast/struct_member_decoration.cc +++ b/src/ast/struct_member_decoration.cc @@ -24,7 +24,7 @@ namespace ast { constexpr const DecorationKind StructMemberDecoration::Kind; StructMemberDecoration::StructMemberDecoration(const Source& source) - : Decoration(source) {} + : Base(source) {} StructMemberDecoration::~StructMemberDecoration() = default; diff --git a/src/ast/struct_member_decoration.h b/src/ast/struct_member_decoration.h index 1652df3341..2c1400a9c7 100644 --- a/src/ast/struct_member_decoration.h +++ b/src/ast/struct_member_decoration.h @@ -27,7 +27,8 @@ namespace ast { class StructMemberOffsetDecoration; /// A decoration attached to a struct member -class StructMemberDecoration : public Decoration { +class StructMemberDecoration + : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kStructMember; diff --git a/src/ast/struct_member_offset_decoration.cc b/src/ast/struct_member_offset_decoration.cc index c211c5bb2c..24366584e1 100644 --- a/src/ast/struct_member_offset_decoration.cc +++ b/src/ast/struct_member_offset_decoration.cc @@ -21,14 +21,14 @@ constexpr const DecorationKind StructMemberOffsetDecoration::Kind; StructMemberOffsetDecoration::StructMemberOffsetDecoration(uint32_t offset, const Source& source) - : StructMemberDecoration(source), offset_(offset) {} + : Base(source), offset_(offset) {} DecorationKind StructMemberOffsetDecoration::GetKind() const { return Kind; } bool StructMemberOffsetDecoration::IsKind(DecorationKind kind) const { - return kind == Kind || StructMemberDecoration::IsKind(kind); + return kind == Kind || Base::IsKind(kind); } bool StructMemberOffsetDecoration::IsOffset() const { diff --git a/src/ast/struct_member_offset_decoration.h b/src/ast/struct_member_offset_decoration.h index 60a206851b..531336df82 100644 --- a/src/ast/struct_member_offset_decoration.h +++ b/src/ast/struct_member_offset_decoration.h @@ -25,7 +25,8 @@ namespace tint { namespace ast { /// A struct member offset decoration -class StructMemberOffsetDecoration : public StructMemberDecoration { +class StructMemberOffsetDecoration + : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = diff --git a/src/ast/switch_statement.cc b/src/ast/switch_statement.cc index 2d86fcb6a6..65bb68f313 100644 --- a/src/ast/switch_statement.cc +++ b/src/ast/switch_statement.cc @@ -19,7 +19,7 @@ namespace tint { namespace ast { -SwitchStatement::SwitchStatement() : Statement() {} +SwitchStatement::SwitchStatement() : Base() {} SwitchStatement::SwitchStatement(Expression* condition, CaseStatementList body) : condition_(condition), body_(body) {} @@ -27,7 +27,7 @@ SwitchStatement::SwitchStatement(Expression* condition, CaseStatementList body) SwitchStatement::SwitchStatement(const Source& source, Expression* condition, CaseStatementList body) - : Statement(source), condition_(condition), body_(body) {} + : Base(source), condition_(condition), body_(body) {} bool SwitchStatement::IsSwitch() const { return true; diff --git a/src/ast/switch_statement.h b/src/ast/switch_statement.h index e5346da93f..656918d818 100644 --- a/src/ast/switch_statement.h +++ b/src/ast/switch_statement.h @@ -27,7 +27,7 @@ namespace tint { namespace ast { /// A switch statement -class SwitchStatement : public Statement { +class SwitchStatement : public Castable { public: /// Constructor SwitchStatement(); diff --git a/src/ast/type_constructor_expression.cc b/src/ast/type_constructor_expression.cc index 3168df004e..8f1d8a87d7 100644 --- a/src/ast/type_constructor_expression.cc +++ b/src/ast/type_constructor_expression.cc @@ -17,17 +17,16 @@ namespace tint { namespace ast { -TypeConstructorExpression::TypeConstructorExpression() - : ConstructorExpression() {} +TypeConstructorExpression::TypeConstructorExpression() : Base() {} TypeConstructorExpression::TypeConstructorExpression(type::Type* type, ExpressionList values) - : ConstructorExpression(), type_(type), values_(std::move(values)) {} + : Base(), type_(type), values_(std::move(values)) {} TypeConstructorExpression::TypeConstructorExpression(const Source& source, type::Type* type, ExpressionList values) - : ConstructorExpression(source), type_(type), values_(std::move(values)) {} + : Base(source), type_(type), values_(std::move(values)) {} TypeConstructorExpression::TypeConstructorExpression( TypeConstructorExpression&&) = default; diff --git a/src/ast/type_constructor_expression.h b/src/ast/type_constructor_expression.h index 68ad2d1d6f..ae911e8d42 100644 --- a/src/ast/type_constructor_expression.h +++ b/src/ast/type_constructor_expression.h @@ -25,7 +25,8 @@ namespace tint { namespace ast { /// A type specific constructor -class TypeConstructorExpression : public ConstructorExpression { +class TypeConstructorExpression + : public Castable { public: TypeConstructorExpression(); /// Constructor diff --git a/src/ast/type_decoration.cc b/src/ast/type_decoration.cc index 763d24cfcc..3f08e1a43d 100644 --- a/src/ast/type_decoration.cc +++ b/src/ast/type_decoration.cc @@ -23,7 +23,7 @@ namespace ast { constexpr const DecorationKind TypeDecoration::Kind; -TypeDecoration::TypeDecoration(const Source& source) : Decoration(source) {} +TypeDecoration::TypeDecoration(const Source& source) : Base(source) {} TypeDecoration::~TypeDecoration() = default; diff --git a/src/ast/type_decoration.h b/src/ast/type_decoration.h index f515a4b663..7b962184dc 100644 --- a/src/ast/type_decoration.h +++ b/src/ast/type_decoration.h @@ -28,7 +28,7 @@ namespace ast { class AccessDecoration; /// A decoration attached to a type -class TypeDecoration : public Decoration { +class TypeDecoration : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kType; diff --git a/src/ast/uint_literal.cc b/src/ast/uint_literal.cc index 078066bc33..4548a4f368 100644 --- a/src/ast/uint_literal.cc +++ b/src/ast/uint_literal.cc @@ -18,7 +18,7 @@ namespace tint { namespace ast { UintLiteral::UintLiteral(ast::type::Type* type, uint32_t value) - : IntLiteral(type), value_(value) {} + : Base(type), value_(value) {} UintLiteral::~UintLiteral() = default; diff --git a/src/ast/uint_literal.h b/src/ast/uint_literal.h index 6189ee4d0c..f15642a31d 100644 --- a/src/ast/uint_literal.h +++ b/src/ast/uint_literal.h @@ -23,7 +23,7 @@ namespace tint { namespace ast { /// A uint literal -class UintLiteral : public IntLiteral { +class UintLiteral : public Castable { public: /// Constructor /// @param type the type of the literal diff --git a/src/ast/unary_op_expression.cc b/src/ast/unary_op_expression.cc index d519451819..ed60a62cac 100644 --- a/src/ast/unary_op_expression.cc +++ b/src/ast/unary_op_expression.cc @@ -17,15 +17,15 @@ namespace tint { namespace ast { -UnaryOpExpression::UnaryOpExpression() : Expression() {} +UnaryOpExpression::UnaryOpExpression() : Base() {} UnaryOpExpression::UnaryOpExpression(UnaryOp op, Expression* expr) - : Expression(), op_(op), expr_(expr) {} + : Base(), op_(op), expr_(expr) {} UnaryOpExpression::UnaryOpExpression(const Source& source, UnaryOp op, Expression* expr) - : Expression(source), op_(op), expr_(expr) {} + : Base(source), op_(op), expr_(expr) {} UnaryOpExpression::UnaryOpExpression(UnaryOpExpression&&) = default; diff --git a/src/ast/unary_op_expression.h b/src/ast/unary_op_expression.h index 918d779676..67d9e01d65 100644 --- a/src/ast/unary_op_expression.h +++ b/src/ast/unary_op_expression.h @@ -26,7 +26,7 @@ namespace tint { namespace ast { /// A unary op expression -class UnaryOpExpression : public Expression { +class UnaryOpExpression : public Castable { public: /// Constructor UnaryOpExpression(); diff --git a/src/ast/variable.cc b/src/ast/variable.cc index 408b6f4f31..67b2ed167e 100644 --- a/src/ast/variable.cc +++ b/src/ast/variable.cc @@ -24,13 +24,13 @@ namespace ast { Variable::Variable() = default; Variable::Variable(const std::string& name, StorageClass sc, type::Type* type) - : Node(), name_(name), storage_class_(sc), type_(type) {} + : Base(), name_(name), storage_class_(sc), type_(type) {} Variable::Variable(const Source& source, const std::string& name, StorageClass sc, type::Type* type) - : Node(source), name_(name), storage_class_(sc), type_(type) {} + : Base(source), name_(name), storage_class_(sc), type_(type) {} Variable::Variable(Variable&&) = default; diff --git a/src/ast/variable.h b/src/ast/variable.h index 711d6b784d..6445946711 100644 --- a/src/ast/variable.h +++ b/src/ast/variable.h @@ -78,7 +78,7 @@ class DecoratedVariable; /// defaulting syntax for a "var" declared inside a function. /// The storage class for a "const" is always StorageClass::kNone. /// The storage class for a formal parameter is always StorageClass::kNone. -class Variable : public Node { +class Variable : public Castable { public: /// Create a new empty variable statement Variable(); diff --git a/src/ast/variable_decl_statement.cc b/src/ast/variable_decl_statement.cc index 2a509be350..732c166d02 100644 --- a/src/ast/variable_decl_statement.cc +++ b/src/ast/variable_decl_statement.cc @@ -17,14 +17,14 @@ namespace tint { namespace ast { -VariableDeclStatement::VariableDeclStatement() : Statement() {} +VariableDeclStatement::VariableDeclStatement() : Base() {} VariableDeclStatement::VariableDeclStatement(Variable* variable) - : Statement(), variable_(variable) {} + : Base(), variable_(variable) {} VariableDeclStatement::VariableDeclStatement(const Source& source, Variable* variable) - : Statement(source), variable_(variable) {} + : Base(source), variable_(variable) {} VariableDeclStatement::VariableDeclStatement(VariableDeclStatement&&) = default; diff --git a/src/ast/variable_decl_statement.h b/src/ast/variable_decl_statement.h index a628991e93..a233029bc7 100644 --- a/src/ast/variable_decl_statement.h +++ b/src/ast/variable_decl_statement.h @@ -26,7 +26,8 @@ namespace tint { namespace ast { /// A variable declaration statement -class VariableDeclStatement : public Statement { +class VariableDeclStatement + : public Castable { public: /// Constructor VariableDeclStatement(); diff --git a/src/ast/variable_decoration.cc b/src/ast/variable_decoration.cc index 9b7d2c0a71..84ed238558 100644 --- a/src/ast/variable_decoration.cc +++ b/src/ast/variable_decoration.cc @@ -27,8 +27,7 @@ namespace ast { constexpr const DecorationKind VariableDecoration::Kind; -VariableDecoration::VariableDecoration(const Source& source) - : Decoration(source) {} +VariableDecoration::VariableDecoration(const Source& source) : Base(source) {} VariableDecoration::~VariableDecoration() = default; diff --git a/src/ast/variable_decoration.h b/src/ast/variable_decoration.h index e5c18fd782..8fd4e44def 100644 --- a/src/ast/variable_decoration.h +++ b/src/ast/variable_decoration.h @@ -32,7 +32,7 @@ class LocationDecoration; class SetDecoration; /// A decoration attached to a variable -class VariableDecoration : public Decoration { +class VariableDecoration : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kVariable; diff --git a/src/ast/workgroup_decoration.cc b/src/ast/workgroup_decoration.cc index 1c4c58b704..045143bd08 100644 --- a/src/ast/workgroup_decoration.cc +++ b/src/ast/workgroup_decoration.cc @@ -20,18 +20,18 @@ namespace ast { constexpr const DecorationKind WorkgroupDecoration::Kind; WorkgroupDecoration::WorkgroupDecoration(uint32_t x, const Source& source) - : FunctionDecoration(source), x_(x) {} + : Base(source), x_(x) {} WorkgroupDecoration::WorkgroupDecoration(uint32_t x, uint32_t y, const Source& source) - : FunctionDecoration(source), x_(x), y_(y) {} + : Base(source), x_(x), y_(y) {} WorkgroupDecoration::WorkgroupDecoration(uint32_t x, uint32_t y, uint32_t z, const Source& source) - : FunctionDecoration(source), x_(x), y_(y), z_(z) {} + : Base(source), x_(x), y_(y), z_(z) {} WorkgroupDecoration::~WorkgroupDecoration() = default; @@ -40,7 +40,7 @@ DecorationKind WorkgroupDecoration::GetKind() const { } bool WorkgroupDecoration::IsKind(DecorationKind kind) const { - return kind == Kind || FunctionDecoration::IsKind(kind); + return kind == Kind || Base::IsKind(kind); } bool WorkgroupDecoration::IsWorkgroup() const { diff --git a/src/ast/workgroup_decoration.h b/src/ast/workgroup_decoration.h index fbdbf06e5c..41c690ccb2 100644 --- a/src/ast/workgroup_decoration.h +++ b/src/ast/workgroup_decoration.h @@ -25,7 +25,8 @@ namespace tint { namespace ast { /// A workgroup decoration -class WorkgroupDecoration : public FunctionDecoration { +class WorkgroupDecoration + : public Castable { public: /// The kind of decoration that this type represents static constexpr const DecorationKind Kind = DecorationKind::kWorkgroup;