From 5c9a80b6f64062bef001269938ce577acbf12fca Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 10 Nov 2021 19:23:07 +0000 Subject: [PATCH] ast: Add 'Expression' suffix to literals (2/2) Literals are now expressions, so in keeping with all the other expression types, suffix the class name with Expression. I'm not overly keen on requiring everything to have an Expression suffix, but consistency is better than personal preference. Note: this should have been part of 30848b6, but I managed to drop this change instead of squashing it. Opps. Bug: tint:888 Change-Id: Idfaf96abe165a6bf5028e60a160e7408aa2bf9db Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68943 Kokoro: Kokoro Reviewed-by: James Price --- src/ast/array.cc | 2 +- src/ast/bool_literal_expression.cc | 13 ++-- src/ast/bool_literal_expression.h | 9 +-- src/ast/bool_literal_expression_test.cc | 14 ++-- src/ast/case_statement.h | 2 +- src/ast/case_statement_test.cc | 13 ++-- src/ast/float_literal_expression.cc | 13 ++-- src/ast/float_literal_expression.h | 9 +-- src/ast/float_literal_expression_test.cc | 8 +-- src/ast/int_literal_expression.cc | 7 +- src/ast/int_literal_expression.h | 7 +- src/ast/int_literal_expression_test.cc | 14 ++-- src/ast/literal_expression.cc | 7 +- src/ast/literal_expression.h | 6 +- src/ast/sint_literal_expression.cc | 15 +++-- src/ast/sint_literal_expression.h | 9 +-- src/ast/sint_literal_expression_test.cc | 8 +-- src/ast/switch_statement_test.cc | 4 +- src/ast/traverse_expressions.h | 2 +- src/ast/uint_literal_expression.cc | 15 +++-- src/ast/uint_literal_expression.h | 9 +-- src/ast/uint_literal_expression_test.cc | 8 +-- src/ast/workgroup_decoration_test.cc | 32 ++++----- src/clone_context.h | 6 +- src/inspector/inspector.cc | 10 +-- src/program_builder.h | 66 +++++++++---------- src/reader/spirv/function.cc | 14 ++-- src/reader/spirv/parser_impl.cc | 32 ++++----- src/reader/wgsl/parser_impl.cc | 16 ++--- src/reader/wgsl/parser_impl.h | 2 +- .../parser_impl_additive_expression_test.cc | 8 +-- .../wgsl/parser_impl_and_expression_test.cc | 4 +- ...rser_impl_argument_expression_list_test.cc | 4 +- .../wgsl/parser_impl_assignment_stmt_test.cc | 16 ++--- src/reader/wgsl/parser_impl_call_stmt_test.cc | 4 +- .../wgsl/parser_impl_const_expr_test.cc | 16 ++--- .../wgsl/parser_impl_const_literal_test.cc | 32 ++++----- .../parser_impl_equality_expression_test.cc | 8 +-- ...arser_impl_exclusive_or_expression_test.cc | 4 +- .../wgsl/parser_impl_function_decl_test.cc | 36 +++++----- ...rser_impl_function_decoration_list_test.cc | 6 +- .../parser_impl_function_decoration_test.cc | 28 ++++---- .../parser_impl_global_constant_decl_test.cc | 8 +-- .../parser_impl_global_variable_decl_test.cc | 2 +- ...arser_impl_inclusive_or_expression_test.cc | 4 +- ...parser_impl_logical_and_expression_test.cc | 4 +- .../parser_impl_logical_or_expression_test.cc | 4 +- ...ser_impl_multiplicative_expression_test.cc | 12 ++-- .../parser_impl_primary_expression_test.cc | 32 ++++----- .../parser_impl_relational_expression_test.cc | 16 ++--- .../wgsl/parser_impl_shift_expression_test.cc | 8 +-- .../parser_impl_singular_expression_test.cc | 6 +- src/reader/wgsl/parser_impl_type_decl_test.cc | 6 +- .../wgsl/parser_impl_unary_expression_test.cc | 16 ++--- .../wgsl/parser_impl_variable_stmt_test.cc | 2 +- src/resolver/resolver.cc | 25 +++---- src/resolver/resolver.h | 6 +- src/resolver/resolver_constants.cc | 15 +++-- src/resolver/resolver_test.cc | 2 +- src/transform/decompose_memory_access.cc | 4 +- src/transform/fold_constants.cc | 6 +- src/transform/fold_trivial_single_use_lets.cc | 2 +- src/transform/inline_pointer_lets.cc | 2 +- src/transform/transform_test.cc | 4 +- src/writer/append_vector.cc | 2 +- src/writer/append_vector_test.cc | 2 +- src/writer/glsl/generator_impl.cc | 13 ++-- src/writer/glsl/generator_impl.h | 2 +- src/writer/hlsl/generator_impl.cc | 13 ++-- src/writer/hlsl/generator_impl.h | 2 +- src/writer/msl/generator_impl.cc | 13 ++-- src/writer/msl/generator_impl.h | 2 +- src/writer/spirv/builder.cc | 50 +++++++------- src/writer/spirv/builder.h | 2 +- src/writer/spirv/builder_literal_test.cc | 26 ++++---- src/writer/wgsl/generator_impl.cc | 13 ++-- src/writer/wgsl/generator_impl.h | 2 +- 77 files changed, 449 insertions(+), 417 deletions(-) diff --git a/src/ast/array.cc b/src/ast/array.cc index 779a950cd2..e8339f848b 100644 --- a/src/ast/array.cc +++ b/src/ast/array.cc @@ -30,7 +30,7 @@ std::string SizeExprToString(const Expression* size, if (auto* ident = size->As()) { return symbols.NameFor(ident->symbol); } - if (auto* literal = size->As()) { + if (auto* literal = size->As()) { return std::to_string(literal->ValueAsU32()); } // This will never be exposed to the user as the Resolver will reject this diff --git a/src/ast/bool_literal_expression.cc b/src/ast/bool_literal_expression.cc index c61afd8aa7..8bb4e2b8af 100644 --- a/src/ast/bool_literal_expression.cc +++ b/src/ast/bool_literal_expression.cc @@ -16,20 +16,23 @@ #include "src/program_builder.h" -TINT_INSTANTIATE_TYPEINFO(tint::ast::BoolLiteral); +TINT_INSTANTIATE_TYPEINFO(tint::ast::BoolLiteralExpression); namespace tint { namespace ast { -BoolLiteral::BoolLiteral(ProgramID pid, const Source& src, bool val) +BoolLiteralExpression::BoolLiteralExpression(ProgramID pid, + const Source& src, + bool val) : Base(pid, src), value(val) {} -BoolLiteral::~BoolLiteral() = default; +BoolLiteralExpression::~BoolLiteralExpression() = default; -const BoolLiteral* BoolLiteral::Clone(CloneContext* ctx) const { +const BoolLiteralExpression* BoolLiteralExpression::Clone( + CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering auto src = ctx->Clone(source); - return ctx->dst->create(src, value); + return ctx->dst->create(src, value); } } // namespace ast diff --git a/src/ast/bool_literal_expression.h b/src/ast/bool_literal_expression.h index 9a571d2b12..a41d3cb12b 100644 --- a/src/ast/bool_literal_expression.h +++ b/src/ast/bool_literal_expression.h @@ -23,20 +23,21 @@ namespace tint { namespace ast { /// A boolean literal -class BoolLiteral : public Castable { +class BoolLiteralExpression + : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node /// @param src the source of this node /// @param value the bool literals value - BoolLiteral(ProgramID pid, const Source& src, bool value); - ~BoolLiteral() override; + BoolLiteralExpression(ProgramID pid, const Source& src, bool value); + ~BoolLiteralExpression() override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node - const BoolLiteral* Clone(CloneContext* ctx) const override; + const BoolLiteralExpression* Clone(CloneContext* ctx) const override; /// The boolean literal value const bool value; diff --git a/src/ast/bool_literal_expression_test.cc b/src/ast/bool_literal_expression_test.cc index 67d306ee35..d8093db34c 100644 --- a/src/ast/bool_literal_expression_test.cc +++ b/src/ast/bool_literal_expression_test.cc @@ -18,17 +18,17 @@ namespace tint { namespace ast { namespace { -using BoolLiteralTest = TestHelper; +using BoolLiteralExpressionTest = TestHelper; -TEST_F(BoolLiteralTest, True) { - auto* b = create(true); - ASSERT_TRUE(b->Is()); +TEST_F(BoolLiteralExpressionTest, True) { + auto* b = create(true); + ASSERT_TRUE(b->Is()); ASSERT_TRUE(b->value); } -TEST_F(BoolLiteralTest, False) { - auto* b = create(false); - ASSERT_TRUE(b->Is()); +TEST_F(BoolLiteralExpressionTest, False) { + auto* b = create(false); + ASSERT_TRUE(b->Is()); ASSERT_FALSE(b->value); } diff --git a/src/ast/case_statement.h b/src/ast/case_statement.h index 71c80db238..c1e5688b4e 100644 --- a/src/ast/case_statement.h +++ b/src/ast/case_statement.h @@ -24,7 +24,7 @@ namespace tint { namespace ast { /// A list of case literals -using CaseSelectorList = std::vector; +using CaseSelectorList = std::vector; /// A case statement class CaseStatement : public Castable { diff --git a/src/ast/case_statement_test.cc b/src/ast/case_statement_test.cc index 7fc92ec187..a46161b68a 100644 --- a/src/ast/case_statement_test.cc +++ b/src/ast/case_statement_test.cc @@ -27,7 +27,7 @@ using CaseStatementTest = TestHelper; TEST_F(CaseStatementTest, Creation_i32) { CaseSelectorList b; - auto* selector = create(2); + auto* selector = create(2); b.push_back(selector); auto* discard = create(); @@ -42,7 +42,7 @@ TEST_F(CaseStatementTest, Creation_i32) { TEST_F(CaseStatementTest, Creation_u32) { CaseSelectorList b; - auto* selector = create(2u); + auto* selector = create(2u); b.push_back(selector); auto* discard = create(); @@ -57,7 +57,7 @@ TEST_F(CaseStatementTest, Creation_u32) { TEST_F(CaseStatementTest, Creation_WithSource) { CaseSelectorList b; - b.push_back(create(2)); + b.push_back(create(2)); auto* body = create(StatementList{ create(), @@ -78,7 +78,7 @@ TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) { TEST_F(CaseStatementTest, IsDefault_WithSelectors) { CaseSelectorList b; - b.push_back(create(2)); + b.push_back(create(2)); auto* c = create(b, create(StatementList{})); EXPECT_FALSE(c->IsDefault()); @@ -125,8 +125,9 @@ TEST_F(CaseStatementTest, Assert_DifferentProgramID_Selector) { { ProgramBuilder b1; ProgramBuilder b2; - b1.create(CaseSelectorList{b2.create(2)}, - b1.create(StatementList{})); + b1.create( + CaseSelectorList{b2.create(2)}, + b1.create(StatementList{})); }, "internal compiler error"); } diff --git a/src/ast/float_literal_expression.cc b/src/ast/float_literal_expression.cc index a76cc8d75e..4a1f45b45a 100644 --- a/src/ast/float_literal_expression.cc +++ b/src/ast/float_literal_expression.cc @@ -18,20 +18,23 @@ #include "src/program_builder.h" -TINT_INSTANTIATE_TYPEINFO(tint::ast::FloatLiteral); +TINT_INSTANTIATE_TYPEINFO(tint::ast::FloatLiteralExpression); namespace tint { namespace ast { -FloatLiteral::FloatLiteral(ProgramID pid, const Source& src, float val) +FloatLiteralExpression::FloatLiteralExpression(ProgramID pid, + const Source& src, + float val) : Base(pid, src), value(val) {} -FloatLiteral::~FloatLiteral() = default; +FloatLiteralExpression::~FloatLiteralExpression() = default; -const FloatLiteral* FloatLiteral::Clone(CloneContext* ctx) const { +const FloatLiteralExpression* FloatLiteralExpression::Clone( + CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering auto src = ctx->Clone(source); - return ctx->dst->create(src, value); + return ctx->dst->create(src, value); } } // namespace ast diff --git a/src/ast/float_literal_expression.h b/src/ast/float_literal_expression.h index 0e1b243214..1765d533a5 100644 --- a/src/ast/float_literal_expression.h +++ b/src/ast/float_literal_expression.h @@ -23,20 +23,21 @@ namespace tint { namespace ast { /// A float literal -class FloatLiteral : public Castable { +class FloatLiteralExpression + : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node /// @param src the source of this node /// @param value the float literals value - FloatLiteral(ProgramID pid, const Source& src, float value); - ~FloatLiteral() override; + FloatLiteralExpression(ProgramID pid, const Source& src, float value); + ~FloatLiteralExpression() override; /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node - const FloatLiteral* Clone(CloneContext* ctx) const override; + const FloatLiteralExpression* Clone(CloneContext* ctx) const override; /// The float literal value const float value; diff --git a/src/ast/float_literal_expression_test.cc b/src/ast/float_literal_expression_test.cc index a89f2ee119..cd1e4451f6 100644 --- a/src/ast/float_literal_expression_test.cc +++ b/src/ast/float_literal_expression_test.cc @@ -18,11 +18,11 @@ namespace tint { namespace ast { namespace { -using FloatLiteralTest = TestHelper; +using FloatLiteralExpressionTest = TestHelper; -TEST_F(FloatLiteralTest, Value) { - auto* f = create(47.2f); - ASSERT_TRUE(f->Is()); +TEST_F(FloatLiteralExpressionTest, Value) { + auto* f = create(47.2f); + ASSERT_TRUE(f->Is()); EXPECT_EQ(f->value, 47.2f); } diff --git a/src/ast/int_literal_expression.cc b/src/ast/int_literal_expression.cc index c620d290a6..b610de9211 100644 --- a/src/ast/int_literal_expression.cc +++ b/src/ast/int_literal_expression.cc @@ -14,14 +14,15 @@ #include "src/ast/int_literal_expression.h" -TINT_INSTANTIATE_TYPEINFO(tint::ast::IntLiteral); +TINT_INSTANTIATE_TYPEINFO(tint::ast::IntLiteralExpression); namespace tint { namespace ast { -IntLiteral::IntLiteral(ProgramID pid, const Source& src) : Base(pid, src) {} +IntLiteralExpression::IntLiteralExpression(ProgramID pid, const Source& src) + : Base(pid, src) {} -IntLiteral::~IntLiteral() = default; +IntLiteralExpression::~IntLiteralExpression() = default; } // namespace ast } // namespace tint diff --git a/src/ast/int_literal_expression.h b/src/ast/int_literal_expression.h index aa79aaf95a..88aa1de8fc 100644 --- a/src/ast/int_literal_expression.h +++ b/src/ast/int_literal_expression.h @@ -21,9 +21,10 @@ namespace tint { namespace ast { /// An integer literal. This could be either signed or unsigned. -class IntLiteral : public Castable { +class IntLiteralExpression + : public Castable { public: - ~IntLiteral() override; + ~IntLiteralExpression() override; /// @returns the literal value as a u32 virtual uint32_t ValueAsU32() const = 0; @@ -35,7 +36,7 @@ class IntLiteral : public Castable { /// Constructor /// @param pid the identifier of the program that owns this node /// @param src the source of this node - IntLiteral(ProgramID pid, const Source& src); + IntLiteralExpression(ProgramID pid, const Source& src); }; // namespace ast } // namespace ast diff --git a/src/ast/int_literal_expression_test.cc b/src/ast/int_literal_expression_test.cc index 8f95e0fdae..d6d9f1cfe2 100644 --- a/src/ast/int_literal_expression_test.cc +++ b/src/ast/int_literal_expression_test.cc @@ -18,16 +18,16 @@ namespace tint { namespace ast { namespace { -using IntLiteralTest = TestHelper; +using IntLiteralExpressionTest = TestHelper; -TEST_F(IntLiteralTest, Sint_IsInt) { - auto* i = create(47); - ASSERT_TRUE(i->Is()); +TEST_F(IntLiteralExpressionTest, Sint_IsInt) { + auto* i = create(47); + ASSERT_TRUE(i->Is()); } -TEST_F(IntLiteralTest, Uint_IsInt) { - auto* i = create(42); - EXPECT_TRUE(i->Is()); +TEST_F(IntLiteralExpressionTest, Uint_IsInt) { + auto* i = create(42); + EXPECT_TRUE(i->Is()); } } // namespace diff --git a/src/ast/literal_expression.cc b/src/ast/literal_expression.cc index 523cd519c0..e9ab969a2c 100644 --- a/src/ast/literal_expression.cc +++ b/src/ast/literal_expression.cc @@ -14,14 +14,15 @@ #include "src/ast/literal_expression.h" -TINT_INSTANTIATE_TYPEINFO(tint::ast::Literal); +TINT_INSTANTIATE_TYPEINFO(tint::ast::LiteralExpression); namespace tint { namespace ast { -Literal::Literal(ProgramID pid, const Source& src) : Base(pid, src) {} +LiteralExpression::LiteralExpression(ProgramID pid, const Source& src) + : Base(pid, src) {} -Literal::~Literal() = default; +LiteralExpression::~LiteralExpression() = default; } // namespace ast } // namespace tint diff --git a/src/ast/literal_expression.h b/src/ast/literal_expression.h index c76deb6971..40114e19db 100644 --- a/src/ast/literal_expression.h +++ b/src/ast/literal_expression.h @@ -23,15 +23,15 @@ namespace tint { namespace ast { /// Base class for a literal value expressions -class Literal : public Castable { +class LiteralExpression : public Castable { public: - ~Literal() override; + ~LiteralExpression() override; protected: /// Constructor /// @param pid the identifier of the program that owns this node /// @param src the input source - Literal(ProgramID pid, const Source& src); + LiteralExpression(ProgramID pid, const Source& src); }; } // namespace ast diff --git a/src/ast/sint_literal_expression.cc b/src/ast/sint_literal_expression.cc index 78da9fca78..72882509eb 100644 --- a/src/ast/sint_literal_expression.cc +++ b/src/ast/sint_literal_expression.cc @@ -16,24 +16,27 @@ #include "src/program_builder.h" -TINT_INSTANTIATE_TYPEINFO(tint::ast::SintLiteral); +TINT_INSTANTIATE_TYPEINFO(tint::ast::SintLiteralExpression); namespace tint { namespace ast { -SintLiteral::SintLiteral(ProgramID pid, const Source& src, int32_t val) +SintLiteralExpression::SintLiteralExpression(ProgramID pid, + const Source& src, + int32_t val) : Base(pid, src), value(val) {} -SintLiteral::~SintLiteral() = default; +SintLiteralExpression::~SintLiteralExpression() = default; -uint32_t SintLiteral::ValueAsU32() const { +uint32_t SintLiteralExpression::ValueAsU32() const { return static_cast(value); } -const SintLiteral* SintLiteral::Clone(CloneContext* ctx) const { +const SintLiteralExpression* SintLiteralExpression::Clone( + CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering auto src = ctx->Clone(source); - return ctx->dst->create(src, value); + return ctx->dst->create(src, value); } } // namespace ast diff --git a/src/ast/sint_literal_expression.h b/src/ast/sint_literal_expression.h index 584f360624..dac1b3fc64 100644 --- a/src/ast/sint_literal_expression.h +++ b/src/ast/sint_literal_expression.h @@ -23,14 +23,15 @@ namespace tint { namespace ast { /// A signed int literal -class SintLiteral : public Castable { +class SintLiteralExpression + : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node /// @param src the source of this node /// @param value the signed int literals value - SintLiteral(ProgramID pid, const Source& src, int32_t value); - ~SintLiteral() override; + SintLiteralExpression(ProgramID pid, const Source& src, int32_t value); + ~SintLiteralExpression() override; /// @returns the literal value as a u32 uint32_t ValueAsU32() const override; @@ -39,7 +40,7 @@ class SintLiteral : public Castable { /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node - const SintLiteral* Clone(CloneContext* ctx) const override; + const SintLiteralExpression* Clone(CloneContext* ctx) const override; /// The int literal value const int32_t value; diff --git a/src/ast/sint_literal_expression_test.cc b/src/ast/sint_literal_expression_test.cc index 7503e623d8..5f3652e25d 100644 --- a/src/ast/sint_literal_expression_test.cc +++ b/src/ast/sint_literal_expression_test.cc @@ -18,11 +18,11 @@ namespace tint { namespace ast { namespace { -using SintLiteralTest = TestHelper; +using SintLiteralExpressionTest = TestHelper; -TEST_F(SintLiteralTest, Value) { - auto* i = create(47); - ASSERT_TRUE(i->Is()); +TEST_F(SintLiteralExpressionTest, Value) { + auto* i = create(47); + ASSERT_TRUE(i->Is()); EXPECT_EQ(i->value, 47); } diff --git a/src/ast/switch_statement_test.cc b/src/ast/switch_statement_test.cc index 355f70f2f6..ed2f8406b1 100644 --- a/src/ast/switch_statement_test.cc +++ b/src/ast/switch_statement_test.cc @@ -25,7 +25,7 @@ using SwitchStatementTest = TestHelper; TEST_F(SwitchStatementTest, Creation) { CaseSelectorList lit; - lit.push_back(create(1)); + lit.push_back(create(1)); auto* ident = Expr("ident"); CaseStatementList body; @@ -50,7 +50,7 @@ TEST_F(SwitchStatementTest, Creation_WithSource) { TEST_F(SwitchStatementTest, IsSwitch) { CaseSelectorList lit; - lit.push_back(create(2)); + lit.push_back(create(2)); auto* ident = Expr("ident"); CaseStatementList body; diff --git a/src/ast/traverse_expressions.h b/src/ast/traverse_expressions.h index ebcd6843f6..028190687d 100644 --- a/src/ast/traverse_expressions.h +++ b/src/ast/traverse_expressions.h @@ -122,7 +122,7 @@ bool TraverseExpressions(const ast::Expression* root, to_visit.push_back(member->structure); } else if (auto* unary = expr->As()) { to_visit.push_back(unary->expr); - } else if (expr->IsAnyOfIsAnyOf()) { // Leaf expression } else { diff --git a/src/ast/uint_literal_expression.cc b/src/ast/uint_literal_expression.cc index 9efc365fc2..0fc837c854 100644 --- a/src/ast/uint_literal_expression.cc +++ b/src/ast/uint_literal_expression.cc @@ -16,24 +16,27 @@ #include "src/program_builder.h" -TINT_INSTANTIATE_TYPEINFO(tint::ast::UintLiteral); +TINT_INSTANTIATE_TYPEINFO(tint::ast::UintLiteralExpression); namespace tint { namespace ast { -UintLiteral::UintLiteral(ProgramID pid, const Source& src, uint32_t val) +UintLiteralExpression::UintLiteralExpression(ProgramID pid, + const Source& src, + uint32_t val) : Base(pid, src), value(val) {} -UintLiteral::~UintLiteral() = default; +UintLiteralExpression::~UintLiteralExpression() = default; -uint32_t UintLiteral::ValueAsU32() const { +uint32_t UintLiteralExpression::ValueAsU32() const { return value; } -const UintLiteral* UintLiteral::Clone(CloneContext* ctx) const { +const UintLiteralExpression* UintLiteralExpression::Clone( + CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering auto src = ctx->Clone(source); - return ctx->dst->create(src, value); + return ctx->dst->create(src, value); } } // namespace ast diff --git a/src/ast/uint_literal_expression.h b/src/ast/uint_literal_expression.h index 9a89046475..61ed4f0d80 100644 --- a/src/ast/uint_literal_expression.h +++ b/src/ast/uint_literal_expression.h @@ -23,14 +23,15 @@ namespace tint { namespace ast { /// A uint literal -class UintLiteral : public Castable { +class UintLiteralExpression + : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node /// @param src the source of this node /// @param value the uint literals value - UintLiteral(ProgramID pid, const Source& src, uint32_t value); - ~UintLiteral() override; + UintLiteralExpression(ProgramID pid, const Source& src, uint32_t value); + ~UintLiteralExpression() override; /// @returns the literal value as a u32 uint32_t ValueAsU32() const override; @@ -39,7 +40,7 @@ class UintLiteral : public Castable { /// `ctx`. /// @param ctx the clone context /// @return the newly cloned node - const UintLiteral* Clone(CloneContext* ctx) const override; + const UintLiteralExpression* Clone(CloneContext* ctx) const override; /// The int literal value const uint32_t value; diff --git a/src/ast/uint_literal_expression_test.cc b/src/ast/uint_literal_expression_test.cc index a65750a292..15d6243ae3 100644 --- a/src/ast/uint_literal_expression_test.cc +++ b/src/ast/uint_literal_expression_test.cc @@ -18,11 +18,11 @@ namespace tint { namespace ast { namespace { -using UintLiteralTest = TestHelper; +using UintLiteralExpressionTest = TestHelper; -TEST_F(UintLiteralTest, Value) { - auto* u = create(47); - ASSERT_TRUE(u->Is()); +TEST_F(UintLiteralExpressionTest, Value) { + auto* u = create(47); + ASSERT_TRUE(u->Is()); EXPECT_EQ(u->value, 47u); } diff --git a/src/ast/workgroup_decoration_test.cc b/src/ast/workgroup_decoration_test.cc index 68b5b22944..c8b3bf39dd 100644 --- a/src/ast/workgroup_decoration_test.cc +++ b/src/ast/workgroup_decoration_test.cc @@ -27,8 +27,8 @@ TEST_F(WorkgroupDecorationTest, Creation_1param) { auto* d = WorkgroupSize(2); auto values = d->Values(); - ASSERT_TRUE(values[0]->Is()); - EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); + ASSERT_TRUE(values[0]->Is()); + EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); EXPECT_EQ(values[1], nullptr); EXPECT_EQ(values[2], nullptr); @@ -37,11 +37,11 @@ TEST_F(WorkgroupDecorationTest, Creation_2param) { auto* d = WorkgroupSize(2, 4); auto values = d->Values(); - ASSERT_TRUE(values[0]->Is()); - EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); + ASSERT_TRUE(values[0]->Is()); + EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); - ASSERT_TRUE(values[1]->Is()); - EXPECT_EQ(values[1]->As()->ValueAsU32(), 4u); + ASSERT_TRUE(values[1]->Is()); + EXPECT_EQ(values[1]->As()->ValueAsU32(), 4u); EXPECT_EQ(values[2], nullptr); } @@ -50,25 +50,25 @@ TEST_F(WorkgroupDecorationTest, Creation_3param) { auto* d = WorkgroupSize(2, 4, 6); auto values = d->Values(); - ASSERT_TRUE(values[0]->Is()); - EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); + ASSERT_TRUE(values[0]->Is()); + EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); - ASSERT_TRUE(values[1]->Is()); - EXPECT_EQ(values[1]->As()->ValueAsU32(), 4u); + ASSERT_TRUE(values[1]->Is()); + EXPECT_EQ(values[1]->As()->ValueAsU32(), 4u); - ASSERT_TRUE(values[2]->Is()); - EXPECT_EQ(values[2]->As()->ValueAsU32(), 6u); + ASSERT_TRUE(values[2]->Is()); + EXPECT_EQ(values[2]->As()->ValueAsU32(), 6u); } TEST_F(WorkgroupDecorationTest, Creation_WithIdentifier) { auto* d = WorkgroupSize(2, 4, "depth"); auto values = d->Values(); - ASSERT_TRUE(values[0]->Is()); - EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); + ASSERT_TRUE(values[0]->Is()); + EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); - ASSERT_TRUE(values[1]->Is()); - EXPECT_EQ(values[1]->As()->ValueAsU32(), 4u); + ASSERT_TRUE(values[1]->Is()); + EXPECT_EQ(values[1]->As()->ValueAsU32(), 4u); auto* z_ident = As(values[2]); ASSERT_TRUE(z_ident); diff --git a/src/clone_context.h b/src/clone_context.h index 9d765a06eb..e399deba02 100644 --- a/src/clone_context.h +++ b/src/clone_context.h @@ -251,10 +251,10 @@ class CloneContext { /// Example: /// /// ``` - /// // Replace all ast::UintLiterals with the number 42 + /// // Replace all ast::UintLiteralExpressions with the number 42 /// CloneCtx ctx(&out, in); - /// ctx.ReplaceAll([&] (ast::UintLiteral* l) { - /// return ctx->dst->create( + /// ctx.ReplaceAll([&] (ast::UintLiteralExpression* l) { + /// return ctx->dst->create( /// ctx->Clone(l->source), /// ctx->Clone(l->type), /// 42); diff --git a/src/inspector/inspector.cc b/src/inspector/inspector.cc index baf9b45ce4..171dbc8369 100644 --- a/src/inspector/inspector.cc +++ b/src/inspector/inspector.cc @@ -263,29 +263,29 @@ std::map Inspector::GetConstantIDs() { continue; } - auto* literal = var->constructor->As(); + auto* literal = var->constructor->As(); if (!literal) { // This is invalid WGSL, but handling gracefully. result[constant_id] = Scalar(); continue; } - if (auto* l = literal->As()) { + if (auto* l = literal->As()) { result[constant_id] = Scalar(l->value); continue; } - if (auto* l = literal->As()) { + if (auto* l = literal->As()) { result[constant_id] = Scalar(l->value); continue; } - if (auto* l = literal->As()) { + if (auto* l = literal->As()) { result[constant_id] = Scalar(l->value); continue; } - if (auto* l = literal->As()) { + if (auto* l = literal->As()) { result[constant_id] = Scalar(l->value); continue; } diff --git a/src/program_builder.h b/src/program_builder.h index 2b3406d044..fd8b19479a 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -1037,53 +1037,53 @@ class ProgramBuilder { /// @param source the source information /// @param value the boolean value /// @return a Scalar constructor for the given value - const ast::Literal* Expr(const Source& source, bool value) { - return create(source, value); + const ast::LiteralExpression* Expr(const Source& source, bool value) { + return create(source, value); } /// @param value the boolean value /// @return a Scalar constructor for the given value - const ast::BoolLiteral* Expr(bool value) { - return create(value); + const ast::BoolLiteralExpression* Expr(bool value) { + return create(value); } /// @param source the source information /// @param value the float value /// @return a Scalar constructor for the given value - const ast::FloatLiteral* Expr(const Source& source, f32 value) { - return create(source, value); + const ast::FloatLiteralExpression* Expr(const Source& source, f32 value) { + return create(source, value); } /// @param value the float value /// @return a Scalar constructor for the given value - const ast::FloatLiteral* Expr(f32 value) { - return create(value); + const ast::FloatLiteralExpression* Expr(f32 value) { + return create(value); } /// @param source the source information /// @param value the integer value /// @return a Scalar constructor for the given value - const ast::Literal* Expr(const Source& source, i32 value) { - return create(source, value); + const ast::LiteralExpression* Expr(const Source& source, i32 value) { + return create(source, value); } /// @param value the integer value /// @return a Scalar constructor for the given value - const ast::SintLiteral* Expr(i32 value) { - return create(value); + const ast::SintLiteralExpression* Expr(i32 value) { + return create(value); } /// @param source the source information /// @param value the unsigned int value /// @return a Scalar constructor for the given value - const ast::UintLiteral* Expr(const Source& source, u32 value) { - return create(source, value); + const ast::UintLiteralExpression* Expr(const Source& source, u32 value) { + return create(source, value); } /// @param value the unsigned int value /// @return a Scalar constructor for the given value - const ast::UintLiteral* Expr(u32 value) { - return create(value); + const ast::UintLiteralExpression* Expr(u32 value) { + return create(value); } /// Converts `arg` to an `ast::Expression` using `Expr()`, then appends it to @@ -1127,53 +1127,53 @@ class ProgramBuilder { /// @param source the source location for the literal /// @param val the boolan value /// @return a boolean literal with the given value - const ast::BoolLiteral* Literal(const Source& source, bool val) { - return create(source, val); + const ast::BoolLiteralExpression* Literal(const Source& source, bool val) { + return create(source, val); } /// @param val the boolan value /// @return a boolean literal with the given value - const ast::BoolLiteral* Literal(bool val) { - return create(val); + const ast::BoolLiteralExpression* Literal(bool val) { + return create(val); } /// @param source the source location for the literal /// @param val the float value /// @return a float literal with the given value - const ast::FloatLiteral* Literal(const Source& source, f32 val) { - return create(source, val); + const ast::FloatLiteralExpression* Literal(const Source& source, f32 val) { + return create(source, val); } /// @param val the float value /// @return a float literal with the given value - const ast::FloatLiteral* Literal(f32 val) { - return create(val); + const ast::FloatLiteralExpression* Literal(f32 val) { + return create(val); } /// @param source the source location for the literal /// @param val the unsigned int value /// @return a ast::UintLiteral with the given value - const ast::UintLiteral* Literal(const Source& source, u32 val) { - return create(source, val); + const ast::UintLiteralExpression* Literal(const Source& source, u32 val) { + return create(source, val); } /// @param val the unsigned int value /// @return a ast::UintLiteral with the given value - const ast::UintLiteral* Literal(u32 val) { - return create(val); + const ast::UintLiteralExpression* Literal(u32 val) { + return create(val); } /// @param source the source location for the literal /// @param val the integer value /// @return the ast::SintLiteral with the given value - const ast::SintLiteral* Literal(const Source& source, i32 val) { - return create(source, val); + const ast::SintLiteralExpression* Literal(const Source& source, i32 val) { + return create(source, val); } /// @param val the integer value /// @return the ast::SintLiteral with the given value - const ast::SintLiteral* Literal(i32 val) { - return create(val); + const ast::SintLiteralExpression* Literal(i32 val) { + return create(val); } /// @param args the arguments for the type constructor @@ -2237,7 +2237,7 @@ class ProgramBuilder { /// @param selector a single case selector /// @param body the case body /// @returns the case statement pointer - const ast::CaseStatement* Case(const ast::IntLiteral* selector, + const ast::CaseStatement* Case(const ast::IntLiteralExpression* selector, const ast::BlockStatement* body = nullptr) { return Case(ast::CaseSelectorList{selector}, body); } diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 8c3166725f..08db5f40eb 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -2548,7 +2548,7 @@ TypedExpression FunctionEmitter::MakeExpression(uint32_t id) { return source_expr; } case SkipReason::kPointSizeBuiltinValue: { - return {ty_.F32(), create(Source{}, 1.0f)}; + return {ty_.F32(), create(Source{}, 1.0f)}; } case SkipReason::kPointSizeBuiltinPointer: Fail() << "unhandled use of a pointer to the PointSize builtin, with ID: " @@ -3063,9 +3063,11 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) { // The Tint AST handles 32-bit values. const uint32_t value32 = uint32_t(value & 0xFFFFFFFF); if (selector.type->IsUnsignedScalarOrVector()) { - selectors.emplace_back(create(Source{}, value32)); + selectors.emplace_back( + create(Source{}, value32)); } else { - selectors.emplace_back(create(Source{}, value32)); + selectors.emplace_back( + create(Source{}, value32)); } } } @@ -4475,7 +4477,7 @@ TypedExpression FunctionEmitter::MakeCompositeValueDecomposition( auto current_type_id = composite_type_id; auto make_index = [this](uint32_t literal) { - return create(Source{}, literal); + return create(Source{}, literal); }; // Build up a nested expression for the decomposition by walking down the type @@ -4591,11 +4593,11 @@ TypedExpression FunctionEmitter::MakeCompositeValueDecomposition( } const ast::Expression* FunctionEmitter::MakeTrue(const Source& source) const { - return create(source, true); + return create(source, true); } const ast::Expression* FunctionEmitter::MakeFalse(const Source& source) const { - return create(source, false); + return create(source, false); } TypedExpression FunctionEmitter::MakeVectorShuffle( diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 15fed61f10..252a2ff863 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -603,7 +603,7 @@ Source ParserImpl::GetSourceForInst( if (where == inst_source_.end()) { return {}; } - return Source{where->second }; + return Source{where->second}; } bool ParserImpl::ParseInternalModuleExceptFunctions() { @@ -1353,13 +1353,13 @@ bool ParserImpl::EmitScalarSpecConstants() { for (auto& inst : module_->types_values()) { // These will be populated for a valid scalar spec constant. const Type* ast_type = nullptr; - ast::Literal* ast_expr = nullptr; + ast::LiteralExpression* ast_expr = nullptr; switch (inst.opcode()) { case SpvOpSpecConstantTrue: case SpvOpSpecConstantFalse: { ast_type = ConvertType(inst.type_id()); - ast_expr = create( + ast_expr = create( Source{}, inst.opcode() == SpvOpSpecConstantTrue); break; } @@ -1367,16 +1367,16 @@ bool ParserImpl::EmitScalarSpecConstants() { ast_type = ConvertType(inst.type_id()); const uint32_t literal_value = inst.GetSingleWordInOperand(0); if (ast_type->Is()) { - ast_expr = create( + ast_expr = create( Source{}, static_cast(literal_value)); } else if (ast_type->Is()) { - ast_expr = create( + ast_expr = create( Source{}, static_cast(literal_value)); } else if (ast_type->Is()) { float float_value; // Copy the bits so we can read them as a float. std::memcpy(&float_value, &literal_value, sizeof(float_value)); - ast_expr = create(Source{}, float_value); + ast_expr = create(Source{}, float_value); } else { return Fail() << " invalid result type for OpSpecConstant " << inst.PrettyPrint(); @@ -1955,20 +1955,22 @@ TypedExpression ParserImpl::MakeConstantExpressionForScalarSpirvConstant( // Currently "null" is missing from the WGSL parser. // See https://bugs.chromium.org/p/tint/issues/detail?id=34 if (ast_type->Is()) { - return {ty_.U32(), create(source, spirv_const->GetU32())}; + return {ty_.U32(), + create(source, spirv_const->GetU32())}; } if (ast_type->Is()) { - return {ty_.I32(), create(source, spirv_const->GetS32())}; + return {ty_.I32(), + create(source, spirv_const->GetS32())}; } if (ast_type->Is()) { - return {ty_.F32(), - create(source, spirv_const->GetFloat())}; + return {ty_.F32(), create( + source, spirv_const->GetFloat())}; } if (ast_type->Is()) { const bool value = spirv_const->AsNullConstant() ? false : spirv_const->AsBoolConstant()->value(); - return {ty_.Bool(), create(source, value)}; + return {ty_.Bool(), create(source, value)}; } Fail() << "expected scalar constant"; return {}; @@ -1989,16 +1991,16 @@ const ast::Expression* ParserImpl::MakeNullValue(const Type* type) { type = type->UnwrapAlias(); if (type->Is()) { - return create(Source{}, false); + return create(Source{}, false); } if (type->Is()) { - return create(Source{}, 0u); + return create(Source{}, 0u); } if (type->Is()) { - return create(Source{}, 0); + return create(Source{}, 0); } if (type->Is()) { - return create(Source{}, 0.0f); + return create(Source{}, 0.0f); } if (type->Is()) { // TODO(amaiorano): No type constructor for TypeName (yet?) diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 1ae05edc5a..77df7edbbc 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -1947,12 +1947,12 @@ Expect ParserImpl::expect_case_selectors() { return Failure::kErrored; } else if (!cond.matched) { break; - } else if (!cond->Is()) { + } else if (!cond->Is()) { return add_error(cond.value->source, "invalid case selector must be an integer value"); } - selectors.push_back(cond.value->As()); + selectors.push_back(cond.value->As()); if (!match(Token::Type::kComma)) { break; @@ -2841,22 +2841,22 @@ Maybe ParserImpl::assignment_stmt() { // | FLOAT_LITERAL // | TRUE // | FALSE -Maybe ParserImpl::const_literal() { +Maybe ParserImpl::const_literal() { auto t = peek(); if (t.IsError()) { return add_error(t.source(), t.to_str()); } if (match(Token::Type::kTrue)) { - return create(t.source(), true); + return create(t.source(), true); } if (match(Token::Type::kFalse)) { - return create(t.source(), false); + return create(t.source(), false); } if (match(Token::Type::kSintLiteral)) { - return create(t.source(), t.to_i32()); + return create(t.source(), t.to_i32()); } if (match(Token::Type::kUintLiteral)) { - return create(t.source(), t.to_u32()); + return create(t.source(), t.to_u32()); } if (match(Token::Type::kFloatLiteral)) { auto p = peek(); @@ -2865,7 +2865,7 @@ Maybe ParserImpl::const_literal() { return add_error(p.source(), "float literals must not be suffixed with 'f'"); } - return create(t.source(), t.to_f32()); + return create(t.source(), t.to_f32()); } return Failure::kNoMatch; } diff --git a/src/reader/wgsl/parser_impl.h b/src/reader/wgsl/parser_impl.h index 2da91e240e..26601c425a 100644 --- a/src/reader/wgsl/parser_impl.h +++ b/src/reader/wgsl/parser_impl.h @@ -568,7 +568,7 @@ class ParserImpl { Maybe continuing_stmt(); /// Parses a `const_literal` grammar element /// @returns the const literal parsed or nullptr if none found - Maybe const_literal(); + Maybe const_literal(); /// Parses a `const_expr` grammar element, erroring on parse failure. /// @returns the parsed constructor expression or nullptr on error Expect expect_const_expr(); diff --git a/src/reader/wgsl/parser_impl_additive_expression_test.cc b/src/reader/wgsl/parser_impl_additive_expression_test.cc index fb66a736dd..e4eae743cf 100644 --- a/src/reader/wgsl/parser_impl_additive_expression_test.cc +++ b/src/reader/wgsl/parser_impl_additive_expression_test.cc @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) { @@ -55,8 +55,8 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, AdditiveExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_and_expression_test.cc b/src/reader/wgsl/parser_impl_and_expression_test.cc index 73aa8dea68..823b5d82b2 100644 --- a/src/reader/wgsl/parser_impl_and_expression_test.cc +++ b/src/reader/wgsl/parser_impl_and_expression_test.cc @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, AndExpression_Parses) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, AndExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_argument_expression_list_test.cc b/src/reader/wgsl/parser_impl_argument_expression_list_test.cc index 575ca439f4..b16d67b556 100644 --- a/src/reader/wgsl/parser_impl_argument_expression_list_test.cc +++ b/src/reader/wgsl/parser_impl_argument_expression_list_test.cc @@ -46,7 +46,7 @@ TEST_F(ParserImplTest, ArgumentExpressionList_ParsesMultiple) { ASSERT_EQ(e.value.size(), 3u); ASSERT_TRUE(e.value[0]->Is()); - ASSERT_TRUE(e.value[1]->Is()); + ASSERT_TRUE(e.value[1]->Is()); ASSERT_TRUE(e.value[2]->Is()); } @@ -58,7 +58,7 @@ TEST_F(ParserImplTest, ArgumentExpressionList_TrailingComma) { ASSERT_EQ(e.value.size(), 2u); ASSERT_TRUE(e.value[0]->Is()); - ASSERT_TRUE(e.value[1]->Is()); + ASSERT_TRUE(e.value[1]->Is()); } TEST_F(ParserImplTest, ArgumentExpressionList_HandlesMissingLeftParen) { diff --git a/src/reader/wgsl/parser_impl_assignment_stmt_test.cc b/src/reader/wgsl/parser_impl_assignment_stmt_test.cc index 99ffcb3858..8f8f16596f 100644 --- a/src/reader/wgsl/parser_impl_assignment_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_assignment_stmt_test.cc @@ -36,8 +36,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) { EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(e->rhs, nullptr); - ASSERT_TRUE(e->rhs->Is()); - EXPECT_EQ(e->rhs->As()->value, 123); + ASSERT_TRUE(e->rhs->Is()); + EXPECT_EQ(e->rhs->As()->value, 123); } TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) { @@ -53,8 +53,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) { ASSERT_NE(e->rhs, nullptr); ASSERT_NE(e->rhs, nullptr); - ASSERT_TRUE(e->rhs->Is()); - EXPECT_EQ(e->rhs->As()->value, 123); + ASSERT_TRUE(e->rhs->Is()); + EXPECT_EQ(e->rhs->As()->value, 123); ASSERT_TRUE(e->lhs->Is()); auto* mem = e->lhs->As(); @@ -67,8 +67,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) { auto* idx = mem->structure->As(); ASSERT_NE(idx->index, nullptr); - ASSERT_TRUE(idx->index->Is()); - EXPECT_EQ(idx->index->As()->value, 2); + ASSERT_TRUE(idx->index->Is()); + EXPECT_EQ(idx->index->As()->value, 2); ASSERT_TRUE(idx->object->Is()); mem = idx->object->As(); @@ -101,8 +101,8 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToPhony) { ASSERT_NE(e->rhs, nullptr); ASSERT_NE(e->rhs, nullptr); - ASSERT_TRUE(e->rhs->Is()); - EXPECT_EQ(e->rhs->As()->value, 123); + ASSERT_TRUE(e->rhs->Is()); + EXPECT_EQ(e->rhs->As()->value, 123); ASSERT_TRUE(e->lhs->Is()); } diff --git a/src/reader/wgsl/parser_impl_call_stmt_test.cc b/src/reader/wgsl/parser_impl_call_stmt_test.cc index edd81424a0..ed49d4bacc 100644 --- a/src/reader/wgsl/parser_impl_call_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_call_stmt_test.cc @@ -55,7 +55,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) { EXPECT_EQ(c->func->symbol, p->builder().Symbols().Get("a")); EXPECT_EQ(c->args.size(), 3u); - EXPECT_TRUE(c->args[0]->Is()); + EXPECT_TRUE(c->args[0]->Is()); EXPECT_TRUE(c->args[1]->Is()); EXPECT_TRUE(c->args[2]->Is()); } @@ -74,7 +74,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams_TrailingComma) { EXPECT_EQ(c->func->symbol, p->builder().Symbols().Get("a")); EXPECT_EQ(c->args.size(), 2u); - EXPECT_TRUE(c->args[0]->Is()); + EXPECT_TRUE(c->args[0]->Is()); EXPECT_TRUE(c->args[1]->Is()); } diff --git a/src/reader/wgsl/parser_impl_const_expr_test.cc b/src/reader/wgsl/parser_impl_const_expr_test.cc index baf5823e48..f5958d148a 100644 --- a/src/reader/wgsl/parser_impl_const_expr_test.cc +++ b/src/reader/wgsl/parser_impl_const_expr_test.cc @@ -33,11 +33,11 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl) { ASSERT_EQ(t->values.size(), 2u); auto& v = t->values; - ASSERT_TRUE(v[0]->Is()); - EXPECT_FLOAT_EQ(v[0]->As()->value, 1.); + ASSERT_TRUE(v[0]->Is()); + EXPECT_FLOAT_EQ(v[0]->As()->value, 1.); - ASSERT_TRUE(v[1]->Is()); - EXPECT_FLOAT_EQ(v[1]->As()->value, 2.); + ASSERT_TRUE(v[1]->Is()); + EXPECT_FLOAT_EQ(v[1]->As()->value, 2.); } TEST_F(ParserImplTest, ConstExpr_TypeDecl_Empty) { @@ -66,8 +66,8 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl_TrailingComma) { EXPECT_EQ(t->type->As()->width, 2u); ASSERT_EQ(t->values.size(), 2u); - ASSERT_TRUE(t->values[0]->Is()); - ASSERT_TRUE(t->values[1]->Is()); + ASSERT_TRUE(t->values[0]->Is()); + ASSERT_TRUE(t->values[1]->Is()); } TEST_F(ParserImplTest, ConstExpr_TypeDecl_MissingRightParen) { @@ -112,8 +112,8 @@ TEST_F(ParserImplTest, ConstExpr_ConstLiteral) { ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->Is()); - EXPECT_TRUE(e.value->As()->value); + ASSERT_TRUE(e.value->Is()); + EXPECT_TRUE(e.value->As()->value); } TEST_F(ParserImplTest, ConstExpr_ConstLiteral_Invalid) { diff --git a/src/reader/wgsl/parser_impl_const_literal_test.cc b/src/reader/wgsl/parser_impl_const_literal_test.cc index 97d625e734..37350b9cbe 100644 --- a/src/reader/wgsl/parser_impl_const_literal_test.cc +++ b/src/reader/wgsl/parser_impl_const_literal_test.cc @@ -48,8 +48,8 @@ TEST_F(ParserImplTest, ConstLiteral_Int) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c->Is()); - EXPECT_EQ(c->As()->value, -234); + ASSERT_TRUE(c->Is()); + EXPECT_EQ(c->As()->value, -234); EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 5u}})); } @@ -60,8 +60,8 @@ TEST_F(ParserImplTest, ConstLiteral_Uint) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c->Is()); - EXPECT_EQ(c->As()->value, 234u); + ASSERT_TRUE(c->Is()); + EXPECT_EQ(c->As()->value, 234u); EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 5u}})); } @@ -72,8 +72,8 @@ TEST_F(ParserImplTest, ConstLiteral_Float) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c->Is()); - EXPECT_FLOAT_EQ(c->As()->value, 234e12f); + ASSERT_TRUE(c->Is()); + EXPECT_FLOAT_EQ(c->As()->value, 234e12f); EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 8u}})); } @@ -136,8 +136,8 @@ TEST_P(ParserImplFloatLiteralTest, Parse) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c->Is()); - EXPECT_FLOAT_EQ(c->As()->value, params.expected); + ASSERT_TRUE(c->Is()); + EXPECT_FLOAT_EQ(c->As()->value, params.expected); } FloatLiteralTestCase float_literal_test_cases[] = { @@ -394,8 +394,8 @@ TEST_F(ParserImplTest, ConstLiteral_FloatHighest) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c->Is()); - EXPECT_FLOAT_EQ(c->As()->value, + ASSERT_TRUE(c->Is()); + EXPECT_FLOAT_EQ(c->As()->value, std::numeric_limits::max()); EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 42u}})); } @@ -417,8 +417,8 @@ TEST_F(ParserImplTest, ConstLiteral_FloatLowest) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c->Is()); - EXPECT_FLOAT_EQ(c->As()->value, + ASSERT_TRUE(c->Is()); + EXPECT_FLOAT_EQ(c->As()->value, std::numeric_limits::lowest()); EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 43u}})); } @@ -430,8 +430,8 @@ TEST_F(ParserImplTest, ConstLiteral_True) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c->Is()); - EXPECT_TRUE(c->As()->value); + ASSERT_TRUE(c->Is()); + EXPECT_TRUE(c->As()->value); EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 5u}})); } @@ -442,8 +442,8 @@ TEST_F(ParserImplTest, ConstLiteral_False) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c->Is()); - EXPECT_FALSE(c->As()->value); + ASSERT_TRUE(c->Is()); + EXPECT_FALSE(c->As()->value); EXPECT_EQ(c->source.range, (Source::Range{{1u, 1u}, {1u, 6u}})); } diff --git a/src/reader/wgsl/parser_impl_equality_expression_test.cc b/src/reader/wgsl/parser_impl_equality_expression_test.cc index 72db3a6f5e..2d6c2f0dba 100644 --- a/src/reader/wgsl/parser_impl_equality_expression_test.cc +++ b/src/reader/wgsl/parser_impl_equality_expression_test.cc @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_Equal) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) { @@ -55,8 +55,8 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, EqualityExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc b/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc index 6fbf186fb6..ad58ce6a73 100644 --- a/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc +++ b/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, ExclusiveOrExpression_Parses) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, ExclusiveOrExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_function_decl_test.cc b/src/reader/wgsl/parser_impl_function_decl_test.cc index 67131b895c..d593c22c19 100644 --- a/src/reader/wgsl/parser_impl_function_decl_test.cc +++ b/src/reader/wgsl/parser_impl_function_decl_test.cc @@ -71,14 +71,14 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) { auto values = decorations[0]->As()->Values(); - ASSERT_TRUE(values[0]->Is()); - EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); + ASSERT_TRUE(values[0]->Is()); + EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); - ASSERT_TRUE(values[1]->Is()); - EXPECT_EQ(values[1]->As()->ValueAsU32(), 3u); + ASSERT_TRUE(values[1]->Is()); + EXPECT_EQ(values[1]->As()->ValueAsU32(), 3u); - ASSERT_TRUE(values[2]->Is()); - EXPECT_EQ(values[2]->As()->ValueAsU32(), 4u); + ASSERT_TRUE(values[2]->Is()); + EXPECT_EQ(values[2]->As()->ValueAsU32(), 4u); auto* body = f->body; ASSERT_EQ(body->statements.size(), 1u); @@ -110,14 +110,14 @@ fn main() { return; })"); ASSERT_TRUE(decorations[0]->Is()); auto values = decorations[0]->As()->Values(); - ASSERT_TRUE(values[0]->Is()); - EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); + ASSERT_TRUE(values[0]->Is()); + EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); - ASSERT_TRUE(values[1]->Is()); - EXPECT_EQ(values[1]->As()->ValueAsU32(), 3u); + ASSERT_TRUE(values[1]->Is()); + EXPECT_EQ(values[1]->As()->ValueAsU32(), 3u); - ASSERT_TRUE(values[2]->Is()); - EXPECT_EQ(values[2]->As()->ValueAsU32(), 4u); + ASSERT_TRUE(values[2]->Is()); + EXPECT_EQ(values[2]->As()->ValueAsU32(), 4u); ASSERT_TRUE(decorations[1]->Is()); EXPECT_EQ(decorations[1]->As()->stage, @@ -154,14 +154,14 @@ fn main() { return; })"); ASSERT_TRUE(decos[0]->Is()); auto values = decos[0]->As()->Values(); - ASSERT_TRUE(values[0]->Is()); - EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); + ASSERT_TRUE(values[0]->Is()); + EXPECT_EQ(values[0]->As()->ValueAsU32(), 2u); - ASSERT_TRUE(values[1]->Is()); - EXPECT_EQ(values[1]->As()->ValueAsU32(), 3u); + ASSERT_TRUE(values[1]->Is()); + EXPECT_EQ(values[1]->As()->ValueAsU32(), 3u); - ASSERT_TRUE(values[2]->Is()); - EXPECT_EQ(values[2]->As()->ValueAsU32(), 4u); + ASSERT_TRUE(values[2]->Is()); + EXPECT_EQ(values[2]->As()->ValueAsU32(), 4u); ASSERT_TRUE(decos[1]->Is()); EXPECT_EQ(decos[1]->As()->stage, diff --git a/src/reader/wgsl/parser_impl_function_decoration_list_test.cc b/src/reader/wgsl/parser_impl_function_decoration_list_test.cc index 0b681c01ba..9f5b0b6ac2 100644 --- a/src/reader/wgsl/parser_impl_function_decoration_list_test.cc +++ b/src/reader/wgsl/parser_impl_function_decoration_list_test.cc @@ -36,10 +36,10 @@ TEST_F(ParserImplTest, DecorationList_Parses) { ASSERT_TRUE(deco_0->Is()); const ast::Expression* x = deco_0->As()->x; ASSERT_NE(x, nullptr); - auto* x_literal = x->As(); + auto* x_literal = x->As(); ASSERT_NE(x_literal, nullptr); - ASSERT_TRUE(x_literal->Is()); - EXPECT_EQ(x_literal->As()->ValueAsU32(), 2u); + ASSERT_TRUE(x_literal->Is()); + EXPECT_EQ(x_literal->As()->ValueAsU32(), 2u); ASSERT_TRUE(deco_1->Is()); EXPECT_EQ(deco_1->As()->stage, diff --git a/src/reader/wgsl/parser_impl_function_decoration_test.cc b/src/reader/wgsl/parser_impl_function_decoration_test.cc index d63d2721e1..f254f35ffb 100644 --- a/src/reader/wgsl/parser_impl_function_decoration_test.cc +++ b/src/reader/wgsl/parser_impl_function_decoration_test.cc @@ -34,8 +34,8 @@ TEST_F(ParserImplTest, Decoration_Workgroup) { auto values = func_deco->As()->Values(); - ASSERT_TRUE(values[0]->Is()); - EXPECT_EQ(values[0]->As()->ValueAsU32(), 4u); + ASSERT_TRUE(values[0]->Is()); + EXPECT_EQ(values[0]->As()->ValueAsU32(), 4u); EXPECT_EQ(values[1], nullptr); EXPECT_EQ(values[2], nullptr); @@ -54,11 +54,11 @@ TEST_F(ParserImplTest, Decoration_Workgroup_2Param) { auto values = func_deco->As()->Values(); - ASSERT_TRUE(values[0]->Is()); - EXPECT_EQ(values[0]->As()->ValueAsU32(), 4u); + ASSERT_TRUE(values[0]->Is()); + EXPECT_EQ(values[0]->As()->ValueAsU32(), 4u); - ASSERT_TRUE(values[1]->Is()); - EXPECT_EQ(values[1]->As()->ValueAsU32(), 5u); + ASSERT_TRUE(values[1]->Is()); + EXPECT_EQ(values[1]->As()->ValueAsU32(), 5u); EXPECT_EQ(values[2], nullptr); } @@ -76,14 +76,14 @@ TEST_F(ParserImplTest, Decoration_Workgroup_3Param) { auto values = func_deco->As()->Values(); - ASSERT_TRUE(values[0]->Is()); - EXPECT_EQ(values[0]->As()->ValueAsU32(), 4u); + ASSERT_TRUE(values[0]->Is()); + EXPECT_EQ(values[0]->As()->ValueAsU32(), 4u); - ASSERT_TRUE(values[1]->Is()); - EXPECT_EQ(values[1]->As()->ValueAsU32(), 5u); + ASSERT_TRUE(values[1]->Is()); + EXPECT_EQ(values[1]->As()->ValueAsU32(), 5u); - ASSERT_TRUE(values[2]->Is()); - EXPECT_EQ(values[2]->As()->ValueAsU32(), 6u); + ASSERT_TRUE(values[2]->Is()); + EXPECT_EQ(values[2]->As()->ValueAsU32(), 6u); } TEST_F(ParserImplTest, Decoration_Workgroup_WithIdent) { @@ -99,8 +99,8 @@ TEST_F(ParserImplTest, Decoration_Workgroup_WithIdent) { auto values = func_deco->As()->Values(); - ASSERT_TRUE(values[0]->Is()); - EXPECT_EQ(values[0]->As()->ValueAsU32(), 4u); + ASSERT_TRUE(values[0]->Is()); + EXPECT_EQ(values[0]->As()->ValueAsU32(), 4u); ASSERT_NE(values[1], nullptr); auto* y_ident = values[1]->As(); diff --git a/src/reader/wgsl/parser_impl_global_constant_decl_test.cc b/src/reader/wgsl/parser_impl_global_constant_decl_test.cc index 29fe7954ad..f77aa31732 100644 --- a/src/reader/wgsl/parser_impl_global_constant_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_constant_decl_test.cc @@ -42,7 +42,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl) { EXPECT_EQ(e->source.range.end.column, 6u); ASSERT_NE(e->constructor, nullptr); - EXPECT_TRUE(e->constructor->Is()); + EXPECT_TRUE(e->constructor->Is()); EXPECT_FALSE( ast::HasDecoration(e.value->decorations)); @@ -69,7 +69,7 @@ TEST_F(ParserImplTest, GlobalConstantDecl_Inferred) { EXPECT_EQ(e->source.range.end.column, 6u); ASSERT_NE(e->constructor, nullptr); - EXPECT_TRUE(e->constructor->Is()); + EXPECT_TRUE(e->constructor->Is()); EXPECT_FALSE( ast::HasDecoration(e.value->decorations)); @@ -137,7 +137,7 @@ TEST_F(ParserImplTest, GlobalConstantDec_Override_WithId) { EXPECT_EQ(e->source.range.end.column, 22u); ASSERT_NE(e->constructor, nullptr); - EXPECT_TRUE(e->constructor->Is()); + EXPECT_TRUE(e->constructor->Is()); auto* override_deco = ast::GetDecoration(e.value->decorations); @@ -169,7 +169,7 @@ TEST_F(ParserImplTest, GlobalConstantDec_Override_WithoutId) { EXPECT_EQ(e->source.range.end.column, 19u); ASSERT_NE(e->constructor, nullptr); - EXPECT_TRUE(e->constructor->Is()); + EXPECT_TRUE(e->constructor->Is()); auto* override_deco = ast::GetDecoration(e.value->decorations); diff --git a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc index 9823c3f555..d79a8aeee0 100644 --- a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc @@ -63,7 +63,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) { EXPECT_EQ(e->source.range.end.column, 15u); ASSERT_NE(e->constructor, nullptr); - ASSERT_TRUE(e->constructor->Is()); + ASSERT_TRUE(e->constructor->Is()); } TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) { diff --git a/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc b/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc index 5f6d5da161..bc633ad0ba 100644 --- a/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc +++ b/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, InclusiveOrExpression_Parses) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, InclusiveOrExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_logical_and_expression_test.cc b/src/reader/wgsl/parser_impl_logical_and_expression_test.cc index b394558538..13223085c7 100644 --- a/src/reader/wgsl/parser_impl_logical_and_expression_test.cc +++ b/src/reader/wgsl/parser_impl_logical_and_expression_test.cc @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, LogicalAndExpression_Parses) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, LogicalAndExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_logical_or_expression_test.cc b/src/reader/wgsl/parser_impl_logical_or_expression_test.cc index 5b1d8842c7..fe60f8b71b 100644 --- a/src/reader/wgsl/parser_impl_logical_or_expression_test.cc +++ b/src/reader/wgsl/parser_impl_logical_or_expression_test.cc @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, LogicalOrExpression_Parses) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, LogicalOrExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc b/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc index c2ab2f17bd..08a1ccf290 100644 --- a/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc +++ b/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Multiply) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Divide) { @@ -55,8 +55,8 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Divide) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Modulo) { @@ -75,8 +75,8 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Modulo) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, MultiplicativeExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_primary_expression_test.cc b/src/reader/wgsl/parser_impl_primary_expression_test.cc index e364e5a409..66312fddb2 100644 --- a/src/reader/wgsl/parser_impl_primary_expression_test.cc +++ b/src/reader/wgsl/parser_impl_primary_expression_test.cc @@ -44,17 +44,17 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) { ASSERT_EQ(ty->values.size(), 4u); const auto& val = ty->values; - ASSERT_TRUE(val[0]->Is()); - EXPECT_EQ(val[0]->As()->value, 1); + ASSERT_TRUE(val[0]->Is()); + EXPECT_EQ(val[0]->As()->value, 1); - ASSERT_TRUE(val[1]->Is()); - EXPECT_EQ(val[1]->As()->value, 2); + ASSERT_TRUE(val[1]->Is()); + EXPECT_EQ(val[1]->As()->value, 2); - ASSERT_TRUE(val[2]->Is()); - EXPECT_EQ(val[2]->As()->value, 3); + ASSERT_TRUE(val[2]->Is()); + EXPECT_EQ(val[2]->As()->value, 3); - ASSERT_TRUE(val[3]->Is()); - EXPECT_EQ(val[3]->As()->value, 4); + ASSERT_TRUE(val[3]->Is()); + EXPECT_EQ(val[3]->As()->value, 4); } TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_ZeroConstructor) { @@ -159,11 +159,11 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructConstructor_NotEmpty) { auto values = constructor->values; ASSERT_EQ(values.size(), 2u); - ASSERT_TRUE(values[0]->Is()); - EXPECT_EQ(values[0]->As()->value, 1u); + ASSERT_TRUE(values[0]->Is()); + EXPECT_EQ(values[0]->As()->value, 1u); - ASSERT_TRUE(values[1]->Is()); - EXPECT_EQ(values[1]->As()->value, 2.f); + ASSERT_TRUE(values[1]->Is()); + EXPECT_EQ(values[1]->As()->value, 2.f); } TEST_F(ParserImplTest, PrimaryExpression_ConstLiteral_True) { @@ -173,8 +173,8 @@ TEST_F(ParserImplTest, PrimaryExpression_ConstLiteral_True) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e->Is()); - EXPECT_TRUE(e->As()->value); + ASSERT_TRUE(e->Is()); + EXPECT_TRUE(e->As()->value); } TEST_F(ParserImplTest, PrimaryExpression_ParenExpr) { @@ -231,7 +231,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) { ASSERT_TRUE(c->type->Is()); ASSERT_EQ(c->values.size(), 1u); - ASSERT_TRUE(c->values[0]->Is()); + ASSERT_TRUE(c->values[0]->Is()); } TEST_F(ParserImplTest, PrimaryExpression_Bitcast) { @@ -246,7 +246,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) { auto* c = e->As(); ASSERT_TRUE(c->type->Is()); - ASSERT_TRUE(c->expr->Is()); + ASSERT_TRUE(c->expr->Is()); } TEST_F(ParserImplTest, PrimaryExpression_Bitcast_MissingGreaterThan) { diff --git a/src/reader/wgsl/parser_impl_relational_expression_test.cc b/src/reader/wgsl/parser_impl_relational_expression_test.cc index 290fec3b36..1418b83d86 100644 --- a/src/reader/wgsl/parser_impl_relational_expression_test.cc +++ b/src/reader/wgsl/parser_impl_relational_expression_test.cc @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThan) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) { @@ -55,8 +55,8 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) { @@ -75,8 +75,8 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) { @@ -95,8 +95,8 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Register("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, RelationalExpression_InvalidLHS) { diff --git a/src/reader/wgsl/parser_impl_shift_expression_test.cc b/src/reader/wgsl/parser_impl_shift_expression_test.cc index 1b6e73beba..98694c5e6a 100644 --- a/src/reader/wgsl/parser_impl_shift_expression_test.cc +++ b/src/reader/wgsl/parser_impl_shift_expression_test.cc @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftLeft) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) { @@ -55,8 +55,8 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) { auto* ident = rel->lhs->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(rel->rhs->Is()); - ASSERT_TRUE(rel->rhs->As()->value); + ASSERT_TRUE(rel->rhs->Is()); + ASSERT_TRUE(rel->rhs->As()->value); } TEST_F(ParserImplTest, ShiftExpression_InvalidSpaceLeft) { diff --git a/src/reader/wgsl/parser_impl_singular_expression_test.cc b/src/reader/wgsl/parser_impl_singular_expression_test.cc index d229ce4d53..b0d1f45f71 100644 --- a/src/reader/wgsl/parser_impl_singular_expression_test.cc +++ b/src/reader/wgsl/parser_impl_singular_expression_test.cc @@ -34,8 +34,8 @@ TEST_F(ParserImplTest, SingularExpression_Array_ConstantIndex) { auto* ident = idx->object->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(idx->index->Is()); - EXPECT_EQ(idx->index->As()->value, 1); + ASSERT_TRUE(idx->index->Is()); + EXPECT_EQ(idx->index->As()->value, 1); } TEST_F(ParserImplTest, SingularExpression_Array_ExpressionIndex) { @@ -116,7 +116,7 @@ TEST_F(ParserImplTest, SingularExpression_Call_WithArgs) { EXPECT_EQ(c->func->symbol, p->builder().Symbols().Get("test")); EXPECT_EQ(c->args.size(), 3u); - EXPECT_TRUE(c->args[0]->Is()); + EXPECT_TRUE(c->args[0]->Is()); EXPECT_TRUE(c->args[1]->Is()); EXPECT_TRUE(c->args[2]->Is()); } diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc index 957ab0793a..17c3b206b4 100644 --- a/src/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_type_decl_test.cc @@ -455,7 +455,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_SintLiteralSize) { EXPECT_EQ(a->decorations.size(), 0u); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 14u}})); - auto* size = a->count->As(); + auto* size = a->count->As(); ASSERT_NE(size, nullptr); EXPECT_EQ(size->ValueAsI32(), 5); } @@ -475,7 +475,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_UintLiteralSize) { EXPECT_EQ(a->decorations.size(), 0u); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 15u}})); - auto* size = a->count->As(); + auto* size = a->count->As(); ASSERT_NE(size, nullptr); EXPECT_EQ(size->ValueAsU32(), 5u); } @@ -513,7 +513,7 @@ TEST_F(ParserImplTest, TypeDecl_Array_Stride) { ASSERT_FALSE(a->IsRuntimeArray()); ASSERT_TRUE(a->type->Is()); - auto* size = a->count->As(); + auto* size = a->count->As(); ASSERT_NE(size, nullptr); EXPECT_EQ(size->ValueAsI32(), 5); diff --git a/src/reader/wgsl/parser_impl_unary_expression_test.cc b/src/reader/wgsl/parser_impl_unary_expression_test.cc index b746035fb2..8a3dd242f4 100644 --- a/src/reader/wgsl/parser_impl_unary_expression_test.cc +++ b/src/reader/wgsl/parser_impl_unary_expression_test.cc @@ -34,8 +34,8 @@ TEST_F(ParserImplTest, UnaryExpression_Postix) { auto* ident = idx->object->As(); EXPECT_EQ(ident->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(idx->index->Is()); - ASSERT_EQ(idx->index->As()->value, 2); + ASSERT_TRUE(idx->index->Is()); + ASSERT_EQ(idx->index->As()->value, 2); } TEST_F(ParserImplTest, UnaryExpression_Minus) { @@ -50,8 +50,8 @@ TEST_F(ParserImplTest, UnaryExpression_Minus) { auto* u = e->As(); ASSERT_EQ(u->op, ast::UnaryOp::kNegation); - ASSERT_TRUE(u->expr->Is()); - EXPECT_EQ(u->expr->As()->value, 1); + ASSERT_TRUE(u->expr->Is()); + EXPECT_EQ(u->expr->As()->value, 1); } TEST_F(ParserImplTest, UnaryExpression_AddressOf) { @@ -132,8 +132,8 @@ TEST_F(ParserImplTest, UnaryExpression_Bang) { auto* u = e->As(); ASSERT_EQ(u->op, ast::UnaryOp::kNot); - ASSERT_TRUE(u->expr->Is()); - EXPECT_EQ(u->expr->As()->value, 1); + ASSERT_TRUE(u->expr->Is()); + EXPECT_EQ(u->expr->As()->value, 1); } TEST_F(ParserImplTest, UnaryExpression_Bang_InvalidRHS) { @@ -158,8 +158,8 @@ TEST_F(ParserImplTest, UnaryExpression_Tilde) { auto* u = e->As(); ASSERT_EQ(u->op, ast::UnaryOp::kComplement); - ASSERT_TRUE(u->expr->Is()); - EXPECT_EQ(u->expr->As()->value, 1); + ASSERT_TRUE(u->expr->Is()); + EXPECT_EQ(u->expr->As()->value, 1); } TEST_F(ParserImplTest, UnaryExpression_PrefixPlusPlus) { diff --git a/src/reader/wgsl/parser_impl_variable_stmt_test.cc b/src/reader/wgsl/parser_impl_variable_stmt_test.cc index 5a6653dc4f..c248e7af44 100644 --- a/src/reader/wgsl/parser_impl_variable_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_variable_stmt_test.cc @@ -55,7 +55,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) { ASSERT_EQ(e->source.range.end.column, 6u); ASSERT_NE(e->variable->constructor, nullptr); - EXPECT_TRUE(e->variable->constructor->Is()); + EXPECT_TRUE(e->variable->constructor->Is()); } TEST_F(ParserImplTest, VariableStmt_VariableDecl_Invalid) { diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc index 28ed7ba37d..1f3bceac8d 100644 --- a/src/resolver/resolver.cc +++ b/src/resolver/resolver.cc @@ -2015,7 +2015,7 @@ bool Resolver::WorkgroupSizeFor(const ast::Function* func, ws[i].value = 0; continue; } - } else if (!expr->Is()) { + } else if (!expr->Is()) { AddError( "workgroup_size argument must be either a literal or a " "module-scope constant", @@ -2367,7 +2367,7 @@ sem::Expression* Resolver::Expression(const ast::Expression* root) { sem_expr = TypeConstructor(ctor); } else if (auto* ident = expr->As()) { sem_expr = Identifier(ident); - } else if (auto* literal = expr->As()) { + } else if (auto* literal = expr->As()) { sem_expr = Literal(literal); } else if (auto* member = expr->As()) { sem_expr = MemberAccessor(member); @@ -2424,7 +2424,7 @@ sem::Expression* Resolver::IndexAccessor( if (!parent_raw_ty->Is()) { // TODO(bclayton): expand this to allow any const_expr expression // https://github.com/gpuweb/gpuweb/issues/1272 - if (!idx->As()) { + if (!idx->As()) { AddError("index must be signed or unsigned integer literal", idx->source); return nullptr; @@ -2617,7 +2617,8 @@ bool Resolver::ValidateTextureIntrinsicFunction(const sem::Call* call) { bool is_const_expr = true; ast::TraverseExpressions( arg->Declaration(), diagnostics_, [&](const ast::Expression* e) { - if (e->IsAnyOf()) { + if (e->IsAnyOf()) { return ast::TraverseAction::Descend; } is_const_expr = false; @@ -2764,7 +2765,7 @@ sem::Expression* Resolver::TypeConstructor( return builder_->create(expr, ty, current_statement_, val); } -sem::Expression* Resolver::Literal(const ast::Literal* literal) { +sem::Expression* Resolver::Literal(const ast::LiteralExpression* literal) { auto* ty = TypeOf(literal); if (!ty) { return nullptr; @@ -3574,17 +3575,17 @@ std::string Resolver::RawTypeNameOf(const sem::Type* ty) { return ty->FriendlyName(builder_->Symbols()); } -sem::Type* Resolver::TypeOf(const ast::Literal* lit) { - if (lit->Is()) { +sem::Type* Resolver::TypeOf(const ast::LiteralExpression* lit) { + if (lit->Is()) { return builder_->create(); } - if (lit->Is()) { + if (lit->Is()) { return builder_->create(); } - if (lit->Is()) { + if (lit->Is()) { return builder_->create(); } - if (lit->Is()) { + if (lit->Is()) { return builder_->create(); } TINT_UNREACHABLE(Resolver, diagnostics_) @@ -3780,7 +3781,7 @@ sem::Array* Resolver::Array(const ast::Array* arr) { } count_expr = var->Declaration()->constructor; - } else if (!count_expr->Is()) { + } else if (!count_expr->Is()) { AddError( "array size expression must be either a literal or a module-scope " "constant", @@ -4259,7 +4260,7 @@ bool Resolver::ValidateSwitch(const ast::SwitchStatement* s) { auto v = selector->ValueAsU32(); auto it = selectors.find(v); if (it != selectors.end()) { - auto val = selector->Is() + auto val = selector->Is() ? std::to_string(selector->ValueAsI32()) : std::to_string(selector->ValueAsU32()); AddError("duplicate switch case '" + val + "'", selector->source); diff --git a/src/resolver/resolver.h b/src/resolver/resolver.h index b6c511866c..6578ce1fac 100644 --- a/src/resolver/resolver.h +++ b/src/resolver/resolver.h @@ -176,7 +176,7 @@ class Resolver { sem::Call* FunctionCall(const ast::CallExpression*); sem::Expression* Identifier(const ast::IdentifierExpression*); sem::Call* IntrinsicCall(const ast::CallExpression*, sem::IntrinsicType); - sem::Expression* Literal(const ast::Literal*); + sem::Expression* Literal(const ast::LiteralExpression*); sem::Expression* MemberAccessor(const ast::MemberAccessorExpression*); sem::Expression* TypeConstructor(const ast::TypeConstructorExpression*); sem::Expression* UnaryOp(const ast::UnaryOpExpression*); @@ -329,7 +329,7 @@ class Resolver { /// @returns the semantic type of the AST literal `lit` /// @param lit the literal - sem::Type* TypeOf(const ast::Literal* lit); + sem::Type* TypeOf(const ast::LiteralExpression* lit); /// Assigns `stmt` to #current_statement_, #current_compound_statement_, and /// possibly #current_block_, pushes the variable scope, then calls @@ -376,7 +376,7 @@ class Resolver { sem::Constant EvaluateConstantValue(const ast::Expression* expr, const sem::Type* type); - sem::Constant EvaluateConstantValue(const ast::Literal* literal, + sem::Constant EvaluateConstantValue(const ast::LiteralExpression* literal, const sem::Type* type); sem::Constant EvaluateConstantValue( const ast::TypeConstructorExpression* type_ctor, diff --git a/src/resolver/resolver_constants.cc b/src/resolver/resolver_constants.cc index 5541d64145..4252e1bc54 100644 --- a/src/resolver/resolver_constants.cc +++ b/src/resolver/resolver_constants.cc @@ -29,7 +29,7 @@ using f32 = ProgramBuilder::f32; sem::Constant Resolver::EvaluateConstantValue(const ast::Expression* expr, const sem::Type* type) { - if (auto* e = expr->As()) { + if (auto* e = expr->As()) { return EvaluateConstantValue(e, type); } if (auto* e = expr->As()) { @@ -38,18 +38,19 @@ sem::Constant Resolver::EvaluateConstantValue(const ast::Expression* expr, return {}; } -sem::Constant Resolver::EvaluateConstantValue(const ast::Literal* literal, - const sem::Type* type) { - if (auto* lit = literal->As()) { +sem::Constant Resolver::EvaluateConstantValue( + const ast::LiteralExpression* literal, + const sem::Type* type) { + if (auto* lit = literal->As()) { return {type, {lit->ValueAsI32()}}; } - if (auto* lit = literal->As()) { + if (auto* lit = literal->As()) { return {type, {lit->ValueAsU32()}}; } - if (auto* lit = literal->As()) { + if (auto* lit = literal->As()) { return {type, {lit->value}}; } - if (auto* lit = literal->As()) { + if (auto* lit = literal->As()) { return {type, {lit->value}}; } TINT_UNREACHABLE(Resolver, builder_->Diagnostics()); diff --git a/src/resolver/resolver_test.cc b/src/resolver/resolver_test.cc index 45afc802b2..a92c19c0de 100644 --- a/src/resolver/resolver_test.cc +++ b/src/resolver/resolver_test.cc @@ -114,7 +114,7 @@ TEST_F(ResolverTest, Stmt_Case) { auto* assign = Assign(lhs, rhs); auto* block = Block(assign); ast::CaseSelectorList lit; - lit.push_back(create(3)); + lit.push_back(create(3)); auto* cse = create(lit, block); auto* cond_var = Var("c", ty.i32()); auto* sw = Switch(cond_var, cse, DefaultCase()); diff --git a/src/transform/decompose_memory_access.cc b/src/transform/decompose_memory_access.cc index ff9d8adb6d..a06f8e05cf 100644 --- a/src/transform/decompose_memory_access.cc +++ b/src/transform/decompose_memory_access.cc @@ -330,9 +330,9 @@ struct DecomposeMemoryAccess::State { /// @param expr the expression to convert to an Offset /// @returns an Offset for the given ast::Expression const Offset* ToOffset(const ast::Expression* expr) { - if (auto* u32 = expr->As()) { + if (auto* u32 = expr->As()) { return offsets_.Create(u32->value); - } else if (auto* i32 = expr->As()) { + } else if (auto* i32 = expr->As()) { if (i32->value > 0) { return offsets_.Create(i32->value); } diff --git a/src/transform/fold_constants.cc b/src/transform/fold_constants.cc index 773136f7c3..994bc1e79e 100644 --- a/src/transform/fold_constants.cc +++ b/src/transform/fold_constants.cc @@ -81,8 +81,10 @@ void FoldConstants::Run(CloneContext& ctx, const DataMap&, DataMap&) { } if (ty->is_scalar()) { - return value.WithScalarAt( - 0, [&](auto&& s) -> const ast::Literal* { return ctx.dst->Expr(s); }); + return value.WithScalarAt(0, + [&](auto&& s) -> const ast::LiteralExpression* { + return ctx.dst->Expr(s); + }); } return nullptr; diff --git a/src/transform/fold_trivial_single_use_lets.cc b/src/transform/fold_trivial_single_use_lets.cc index c83008c9eb..aa83b8fdbd 100644 --- a/src/transform/fold_trivial_single_use_lets.cc +++ b/src/transform/fold_trivial_single_use_lets.cc @@ -37,7 +37,7 @@ const ast::VariableDeclStatement* AsTrivialLetDecl(const ast::Statement* stmt) { return nullptr; } auto* ctor = var->constructor; - if (!IsAnyOf(ctor)) { + if (!IsAnyOf(ctor)) { return nullptr; } return var_decl; diff --git a/src/transform/inline_pointer_lets.cc b/src/transform/inline_pointer_lets.cc index 0c59887309..5bdf0fca95 100644 --- a/src/transform/inline_pointer_lets.cc +++ b/src/transform/inline_pointer_lets.cc @@ -46,7 +46,7 @@ void CollectSavedArrayIndices(const Program* program, if (auto* a = expr->As()) { CollectSavedArrayIndices(program, a->object, cb); - if (!a->index->Is()) { + if (!a->index->Is()) { cb(a->index); } return; diff --git a/src/transform/transform_test.cc b/src/transform/transform_test.cc index 981f7d2be1..e8b87366c6 100644 --- a/src/transform/transform_test.cc +++ b/src/transform/transform_test.cc @@ -84,7 +84,7 @@ TEST_F(CreateASTTypeForTest, ArrayImplicitStride) { ASSERT_TRUE(arr->As()->type->Is()); ASSERT_EQ(arr->As()->decorations.size(), 0u); - auto* size = arr->As()->count->As(); + auto* size = arr->As()->count->As(); ASSERT_NE(size, nullptr); EXPECT_EQ(size->ValueAsI32(), 2); } @@ -104,7 +104,7 @@ TEST_F(CreateASTTypeForTest, ArrayNonImplicitStride) { ->stride, 64u); - auto* size = arr->As()->count->As(); + auto* size = arr->As()->count->As(); ASSERT_NE(size, nullptr); EXPECT_EQ(size->ValueAsI32(), 2); } diff --git a/src/writer/append_vector.cc b/src/writer/append_vector.cc index 9520cc9654..5059690d20 100644 --- a/src/writer/append_vector.cc +++ b/src/writer/append_vector.cc @@ -85,7 +85,7 @@ const ast::TypeConstructorExpression* AppendVector( const auto num_supplied = vc->values.size(); if (num_supplied == 0) { // Zero-value vector constructor. Populate with zeros - auto buildZero = [&]() -> const ast::Literal* { + auto buildZero = [&]() -> const ast::LiteralExpression* { if (packed_el_sem_ty->Is()) { return b->Expr(0); } else if (packed_el_sem_ty->Is()) { diff --git a/src/writer/append_vector_test.cc b/src/writer/append_vector_test.cc index 26de490f54..67030e8c5e 100644 --- a/src/writer/append_vector_test.cc +++ b/src/writer/append_vector_test.cc @@ -249,7 +249,7 @@ TEST_F(AppendVectorTest, ZeroVec3i32_i32) { ASSERT_NE(vec_0004, nullptr); ASSERT_EQ(vec_0004->values.size(), 4u); for (size_t i = 0; i < 3; i++) { - auto* literal = As(vec_0004->values[i]); + auto* literal = As(vec_0004->values[i]); ASSERT_NE(literal, nullptr); EXPECT_EQ(literal->value, 0); } diff --git a/src/writer/glsl/generator_impl.cc b/src/writer/glsl/generator_impl.cc index 81aac7f85a..7825126211 100644 --- a/src/writer/glsl/generator_impl.cc +++ b/src/writer/glsl/generator_impl.cc @@ -1472,7 +1472,7 @@ bool GeneratorImpl::EmitExpression(std::ostream& out, if (auto* i = expr->As()) { return EmitIdentifier(out, i); } - if (auto* l = expr->As()) { + if (auto* l = expr->As()) { return EmitLiteral(out, l); } if (auto* m = expr->As()) { @@ -2008,10 +2008,11 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { return true; } -bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) { - if (auto* l = lit->As()) { +bool GeneratorImpl::EmitLiteral(std::ostream& out, + const ast::LiteralExpression* lit) { + if (auto* l = lit->As()) { out << (l->value ? "true" : "false"); - } else if (auto* fl = lit->As()) { + } else if (auto* fl = lit->As()) { if (std::isinf(fl->value)) { out << (fl->value >= 0 ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)"); } else if (std::isnan(fl->value)) { @@ -2019,9 +2020,9 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) { } else { out << FloatToString(fl->value) << "f"; } - } else if (auto* sl = lit->As()) { + } else if (auto* sl = lit->As()) { out << sl->value; - } else if (auto* ul = lit->As()) { + } else if (auto* ul = lit->As()) { out << ul->value << "u"; } else { diagnostics_.add_error(diag::System::Writer, "unknown literal type"); diff --git a/src/writer/glsl/generator_impl.h b/src/writer/glsl/generator_impl.h index 42ff92f976..6155f0b93a 100644 --- a/src/writer/glsl/generator_impl.h +++ b/src/writer/glsl/generator_impl.h @@ -254,7 +254,7 @@ class GeneratorImpl : public TextGenerator { /// @param out the output stream /// @param lit the literal to emit /// @returns true if the literal was successfully emitted - bool EmitLiteral(std::ostream& out, const ast::Literal* lit); + bool EmitLiteral(std::ostream& out, const ast::LiteralExpression* lit); /// Handles a loop statement /// @param stmt the statement to emit /// @returns true if the statement was emitted diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 23433cef6f..0bc975f7fb 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -2204,7 +2204,7 @@ bool GeneratorImpl::EmitExpression(std::ostream& out, if (auto* i = expr->As()) { return EmitIdentifier(out, i); } - if (auto* l = expr->As()) { + if (auto* l = expr->As()) { return EmitLiteral(out, l); } if (auto* m = expr->As()) { @@ -2683,10 +2683,11 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { return true; } -bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) { - if (auto* l = lit->As()) { +bool GeneratorImpl::EmitLiteral(std::ostream& out, + const ast::LiteralExpression* lit) { + if (auto* l = lit->As()) { out << (l->value ? "true" : "false"); - } else if (auto* fl = lit->As()) { + } else if (auto* fl = lit->As()) { if (std::isinf(fl->value)) { out << (fl->value >= 0 ? "asfloat(0x7f800000u)" : "asfloat(0xff800000u)"); } else if (std::isnan(fl->value)) { @@ -2694,9 +2695,9 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) { } else { out << FloatToString(fl->value) << "f"; } - } else if (auto* sl = lit->As()) { + } else if (auto* sl = lit->As()) { out << sl->value; - } else if (auto* ul = lit->As()) { + } else if (auto* ul = lit->As()) { out << ul->value << "u"; } else { diagnostics_.add_error(diag::System::Writer, "unknown literal type"); diff --git a/src/writer/hlsl/generator_impl.h b/src/writer/hlsl/generator_impl.h index 62b822b3a0..e63524f14c 100644 --- a/src/writer/hlsl/generator_impl.h +++ b/src/writer/hlsl/generator_impl.h @@ -287,7 +287,7 @@ class GeneratorImpl : public TextGenerator { /// @param out the output stream /// @param lit the literal to emit /// @returns true if the literal was successfully emitted - bool EmitLiteral(std::ostream& out, const ast::Literal* lit); + bool EmitLiteral(std::ostream& out, const ast::LiteralExpression* lit); /// Handles a loop statement /// @param stmt the statement to emit /// @returns true if the statement was emitted diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 7593e2a528..77c87bdb75 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -1379,10 +1379,11 @@ bool GeneratorImpl::EmitZeroValue(std::ostream& out, const sem::Type* type) { return true; } -bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) { - if (auto* l = lit->As()) { +bool GeneratorImpl::EmitLiteral(std::ostream& out, + const ast::LiteralExpression* lit) { + if (auto* l = lit->As()) { out << (l->value ? "true" : "false"); - } else if (auto* fl = lit->As()) { + } else if (auto* fl = lit->As()) { if (std::isinf(fl->value)) { out << (fl->value >= 0 ? "INFINITY" : "-INFINITY"); } else if (std::isnan(fl->value)) { @@ -1390,7 +1391,7 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) { } else { out << FloatToString(fl->value) << "f"; } - } else if (auto* sl = lit->As()) { + } else if (auto* sl = lit->As()) { // MSL (and C++) parse `-2147483648` as a `long` because it parses unary // minus and `2147483648` as separate tokens, and the latter doesn't // fit into an (32-bit) `int`. WGSL, OTOH, parses this as an `i32`. To avoid @@ -1402,7 +1403,7 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) { } else { out << sl->value; } - } else if (auto* ul = lit->As()) { + } else if (auto* ul = lit->As()) { out << ul->value << "u"; } else { diagnostics_.add_error(diag::System::Writer, "unknown literal type"); @@ -1431,7 +1432,7 @@ bool GeneratorImpl::EmitExpression(std::ostream& out, if (auto* i = expr->As()) { return EmitIdentifier(out, i); } - if (auto* l = expr->As()) { + if (auto* l = expr->As()) { return EmitLiteral(out, l); } if (auto* m = expr->As()) { diff --git a/src/writer/msl/generator_impl.h b/src/writer/msl/generator_impl.h index e72cf775a5..40b16ccfd4 100644 --- a/src/writer/msl/generator_impl.h +++ b/src/writer/msl/generator_impl.h @@ -216,7 +216,7 @@ class GeneratorImpl : public TextGenerator { /// @param out the output of the expression stream /// @param lit the literal to emit /// @returns true if the literal was successfully emitted - bool EmitLiteral(std::ostream& out, const ast::Literal* lit); + bool EmitLiteral(std::ostream& out, const ast::LiteralExpression* lit); /// Handles a loop statement /// @param stmt the statement to emit /// @returns true if the statement was emitted diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 27e87e0403..e6a136566c 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -583,7 +583,7 @@ uint32_t Builder::GenerateExpression(const ast::Expression* expr) { if (auto* i = expr->As()) { return GenerateIdentifierExpression(i); } - if (auto* l = expr->As()) { + if (auto* l = expr->As()) { return GenerateLiteralIfNeeded(nullptr, l); } if (auto* m = expr->As()) { @@ -777,16 +777,16 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* var) { // SPIR-V requires specialization constants to have initializers. if (type->Is()) { - ast::FloatLiteral l(ProgramID(), Source{}, 0.0f); + ast::FloatLiteralExpression l(ProgramID(), Source{}, 0.0f); init_id = GenerateLiteralIfNeeded(var, &l); } else if (type->Is()) { - ast::UintLiteral l(ProgramID(), Source{}, 0); + ast::UintLiteralExpression l(ProgramID(), Source{}, 0); init_id = GenerateLiteralIfNeeded(var, &l); } else if (type->Is()) { - ast::SintLiteral l(ProgramID(), Source{}, 0); + ast::SintLiteralExpression l(ProgramID(), Source{}, 0); init_id = GenerateLiteralIfNeeded(var, &l); } else if (type->Is()) { - ast::BoolLiteral l(ProgramID(), Source{}, false); + ast::BoolLiteralExpression l(ProgramID(), Source{}, false); init_id = GenerateLiteralIfNeeded(var, &l); } else { error_ = "invalid type for pipeline constant ID, must be scalar"; @@ -928,7 +928,7 @@ bool Builder::GenerateIndexAccessor(const ast::IndexAccessorExpression* expr, auto extract_id = extract.to_i(); // If the index is a literal, we use OpCompositeExtract. - if (auto* literal = expr->index->As()) { + if (auto* literal = expr->index->As()) { if (!push_function_inst(spv::Op::OpCompositeExtract, {Operand::Int(result_type_id), extract, Operand::Int(info->source_id), @@ -1256,7 +1256,7 @@ uint32_t Builder::GetGLSLstd450Import() { uint32_t Builder::GenerateConstructorExpression(const ast::Variable* var, const ast::Expression* expr) { - if (auto* literal = expr->As()) { + if (auto* literal = expr->As()) { return GenerateLiteralIfNeeded(var, literal); } if (auto* type = expr->As()) { @@ -1269,7 +1269,7 @@ uint32_t Builder::GenerateConstructorExpression(const ast::Variable* var, bool Builder::is_constructor_const(const ast::Expression* expr, bool is_global_init) { - if (expr->Is()) { + if (expr->Is()) { return true; } @@ -1281,7 +1281,7 @@ bool Builder::is_constructor_const(const ast::Expression* expr, for (size_t i = 0; i < tc->values.size(); ++i) { auto* e = tc->values[i]; - if (!e->IsAnyOf()) { + if (!e->IsAnyOf()) { if (is_global_init) { error_ = "constructor must be a constant expression"; return false; @@ -1295,7 +1295,7 @@ bool Builder::is_constructor_const(const ast::Expression* expr, return false; } - auto* lit = e->As(); + auto* lit = e->As(); if (result_type->Is() && lit == nullptr) { return false; } @@ -1610,18 +1610,18 @@ uint32_t Builder::GenerateCastOrCopyOrPassthrough( uint32_t one_id; uint32_t zero_id; if (to_elem_type->Is()) { - ast::FloatLiteral one(ProgramID(), Source{}, 1.0f); - ast::FloatLiteral zero(ProgramID(), Source{}, 0.0f); + ast::FloatLiteralExpression one(ProgramID(), Source{}, 1.0f); + ast::FloatLiteralExpression zero(ProgramID(), Source{}, 0.0f); one_id = GenerateLiteralIfNeeded(nullptr, &one); zero_id = GenerateLiteralIfNeeded(nullptr, &zero); } else if (to_elem_type->Is()) { - ast::UintLiteral one(ProgramID(), Source{}, 1); - ast::UintLiteral zero(ProgramID(), Source{}, 0); + ast::UintLiteralExpression one(ProgramID(), Source{}, 1); + ast::UintLiteralExpression zero(ProgramID(), Source{}, 0); one_id = GenerateLiteralIfNeeded(nullptr, &one); zero_id = GenerateLiteralIfNeeded(nullptr, &zero); } else if (to_elem_type->Is()) { - ast::SintLiteral one(ProgramID(), Source{}, 1); - ast::SintLiteral zero(ProgramID(), Source{}, 0); + ast::SintLiteralExpression one(ProgramID(), Source{}, 1); + ast::SintLiteralExpression zero(ProgramID(), Source{}, 0); one_id = GenerateLiteralIfNeeded(nullptr, &one); zero_id = GenerateLiteralIfNeeded(nullptr, &zero); } else { @@ -1665,7 +1665,7 @@ uint32_t Builder::GenerateCastOrCopyOrPassthrough( } uint32_t Builder::GenerateLiteralIfNeeded(const ast::Variable* var, - const ast::Literal* lit) { + const ast::LiteralExpression* lit) { ScalarConstant constant; auto* global = builder_.Sem().Get(var); @@ -1674,16 +1674,16 @@ uint32_t Builder::GenerateLiteralIfNeeded(const ast::Variable* var, constant.constant_id = global->ConstantId(); } - if (auto* l = lit->As()) { + if (auto* l = lit->As()) { constant.kind = ScalarConstant::Kind::kBool; constant.value.b = l->value; - } else if (auto* sl = lit->As()) { + } else if (auto* sl = lit->As()) { constant.kind = ScalarConstant::Kind::kI32; constant.value.i32 = sl->value; - } else if (auto* ul = lit->As()) { + } else if (auto* ul = lit->As()) { constant.kind = ScalarConstant::Kind::kU32; constant.value.u32 = ul->value; - } else if (auto* fl = lit->As()) { + } else if (auto* fl = lit->As()) { constant.kind = ScalarConstant::Kind::kF32; constant.value.f32 = fl->value; } else { @@ -2920,7 +2920,7 @@ bool Builder::GenerateTextureIntrinsic(const ast::CallExpression* call, op = spv::Op::OpImageQuerySizeLod; spirv_params.emplace_back(gen(level)); } else { - ast::SintLiteral i32_0(ProgramID(), Source{}, 0); + ast::SintLiteralExpression i32_0(ProgramID(), Source{}, 0); op = spv::Op::OpImageQuerySizeLod; spirv_params.emplace_back( Operand::Int(GenerateLiteralIfNeeded(nullptr, &i32_0))); @@ -2952,7 +2952,7 @@ bool Builder::GenerateTextureIntrinsic(const ast::CallExpression* call, texture_type->Is()) { op = spv::Op::OpImageQuerySize; } else { - ast::SintLiteral i32_0(ProgramID(), Source{}, 0); + ast::SintLiteralExpression i32_0(ProgramID(), Source{}, 0); op = spv::Op::OpImageQuerySizeLod; spirv_params.emplace_back( Operand::Int(GenerateLiteralIfNeeded(nullptr, &i32_0))); @@ -3074,7 +3074,7 @@ bool Builder::GenerateTextureIntrinsic(const ast::CallExpression* call, } spirv_params.emplace_back(gen_arg(Usage::kDepthRef)); - ast::FloatLiteral float_0(ProgramID(), Source{}, 0.0); + ast::FloatLiteralExpression float_0(ProgramID(), Source{}, 0.0); image_operands.emplace_back(ImageOperand{ SpvImageOperandsLodMask, Operand::Int(GenerateLiteralIfNeeded(nullptr, &float_0))}); @@ -3625,7 +3625,7 @@ bool Builder::GenerateSwitchStatement(const ast::SwitchStatement* stmt) { case_ids.push_back(block_id); for (auto* selector : item->selectors) { - auto* int_literal = selector->As(); + auto* int_literal = selector->As(); if (!int_literal) { error_ = "expected integer literal for switch case label"; return false; diff --git a/src/writer/spirv/builder.h b/src/writer/spirv/builder.h index c07ca5fff8..66e4f4a220 100644 --- a/src/writer/spirv/builder.h +++ b/src/writer/spirv/builder.h @@ -353,7 +353,7 @@ class Builder { /// @param lit the literal to generate /// @returns the ID on success or 0 on failure uint32_t GenerateLiteralIfNeeded(const ast::Variable* var, - const ast::Literal* lit); + const ast::LiteralExpression* lit); /// Generates a binary expression /// @param expr the expression to generate /// @returns the expression ID on success or 0 otherwise diff --git a/src/writer/spirv/builder_literal_test.cc b/src/writer/spirv/builder_literal_test.cc index d93e34a52f..ee72713a1a 100644 --- a/src/writer/spirv/builder_literal_test.cc +++ b/src/writer/spirv/builder_literal_test.cc @@ -22,7 +22,7 @@ namespace spirv { using BuilderTest = TestHelper; TEST_F(BuilderTest, Literal_Bool_True) { - auto* b_true = create(true); + auto* b_true = create(true); WrapInFunction(b_true); spirv::Builder& b = Build(); @@ -37,7 +37,7 @@ TEST_F(BuilderTest, Literal_Bool_True) { } TEST_F(BuilderTest, Literal_Bool_False) { - auto* b_false = create(false); + auto* b_false = create(false); WrapInFunction(b_false); spirv::Builder& b = Build(); @@ -52,8 +52,8 @@ TEST_F(BuilderTest, Literal_Bool_False) { } TEST_F(BuilderTest, Literal_Bool_Dedup) { - auto* b_true = create(true); - auto* b_false = create(false); + auto* b_true = create(true); + auto* b_false = create(false); WrapInFunction(b_true, b_false); spirv::Builder& b = Build(); @@ -72,7 +72,7 @@ TEST_F(BuilderTest, Literal_Bool_Dedup) { } TEST_F(BuilderTest, Literal_I32) { - auto* i = create(-23); + auto* i = create(-23); WrapInFunction(i); spirv::Builder& b = Build(); @@ -86,8 +86,8 @@ TEST_F(BuilderTest, Literal_I32) { } TEST_F(BuilderTest, Literal_I32_Dedup) { - auto* i1 = create(-23); - auto* i2 = create(-23); + auto* i1 = create(-23); + auto* i2 = create(-23); WrapInFunction(i1, i2); spirv::Builder& b = Build(); @@ -102,7 +102,7 @@ TEST_F(BuilderTest, Literal_I32_Dedup) { } TEST_F(BuilderTest, Literal_U32) { - auto* i = create(23); + auto* i = create(23); WrapInFunction(i); spirv::Builder& b = Build(); @@ -117,8 +117,8 @@ TEST_F(BuilderTest, Literal_U32) { } TEST_F(BuilderTest, Literal_U32_Dedup) { - auto* i1 = create(23); - auto* i2 = create(23); + auto* i1 = create(23); + auto* i2 = create(23); WrapInFunction(i1, i2); spirv::Builder& b = Build(); @@ -133,7 +133,7 @@ TEST_F(BuilderTest, Literal_U32_Dedup) { } TEST_F(BuilderTest, Literal_F32) { - auto* i = create(23.245f); + auto* i = create(23.245f); WrapInFunction(i); spirv::Builder& b = Build(); @@ -148,8 +148,8 @@ TEST_F(BuilderTest, Literal_F32) { } TEST_F(BuilderTest, Literal_F32_Dedup) { - auto* i1 = create(23.245f); - auto* i2 = create(23.245f); + auto* i1 = create(23.245f); + auto* i2 = create(23.245f); WrapInFunction(i1, i2); spirv::Builder& b = Build(); diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index 4a316c9f7b..b1fe63bbf4 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -131,7 +131,7 @@ bool GeneratorImpl::EmitExpression(std::ostream& out, if (auto* i = expr->As()) { return EmitIdentifier(out, i); } - if (auto* l = expr->As()) { + if (auto* l = expr->As()) { return EmitLiteral(out, l); } if (auto* c = expr->As()) { @@ -268,14 +268,15 @@ bool GeneratorImpl::EmitTypeConstructor( return true; } -bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::Literal* lit) { - if (auto* bl = lit->As()) { +bool GeneratorImpl::EmitLiteral(std::ostream& out, + const ast::LiteralExpression* lit) { + if (auto* bl = lit->As()) { out << (bl->value ? "true" : "false"); - } else if (auto* fl = lit->As()) { + } else if (auto* fl = lit->As()) { out << FloatToBitPreservingString(fl->value); - } else if (auto* sl = lit->As()) { + } else if (auto* sl = lit->As()) { out << sl->value; - } else if (auto* ul = lit->As()) { + } else if (auto* ul = lit->As()) { out << ul->value << "u"; } else { diagnostics_.add_error(diag::System::Writer, "unknown literal type"); diff --git a/src/writer/wgsl/generator_impl.h b/src/writer/wgsl/generator_impl.h index e1a060c67b..7f4a68cafd 100644 --- a/src/writer/wgsl/generator_impl.h +++ b/src/writer/wgsl/generator_impl.h @@ -99,7 +99,7 @@ class GeneratorImpl : public TextGenerator { /// @param out the output of the expression stream /// @param expr the literal expression expression /// @returns true if the literal expression is emitted - bool EmitLiteral(std::ostream& out, const ast::Literal* expr); + bool EmitLiteral(std::ostream& out, const ast::LiteralExpression* expr); /// Handles a continue statement /// @param stmt the statement to emit /// @returns true if the statement was emitted successfully