From 0573714bfd0fdc996d4d3087b0e44e1169310ecc Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 9 Nov 2020 20:44:34 +0000 Subject: [PATCH] wsgl parser: Have Expect & Maybe operator-> deref For values of type T* and std::unique_ptr. This allows us to replace all occurances of `res.value->member` with: `res->member`, which also asserts that `res` is not in an error state. Brings the verbosity back down to pre-expect and pre-maybe levels. Bug: tint:282 Change-Id: Ib00018affca53ac5e71ee2140e7e0cd607b83715 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32141 Commit-Queue: Ben Clayton Reviewed-by: dan sinclair --- BUILD.gn | 1 + src/CMakeLists.txt | 1 + src/reader/wgsl/parser_impl.cc | 30 ++--- src/reader/wgsl/parser_impl.h | 21 +++- .../parser_impl_additive_expression_test.cc | 10 +- .../wgsl/parser_impl_and_expression_test.cc | 6 +- .../wgsl/parser_impl_assignment_stmt_test.cc | 32 ++--- src/reader/wgsl/parser_impl_body_stmt_test.cc | 8 +- .../wgsl/parser_impl_break_stmt_test.cc | 2 +- src/reader/wgsl/parser_impl_call_stmt_test.cc | 8 +- src/reader/wgsl/parser_impl_case_body_test.cc | 12 +- .../wgsl/parser_impl_const_expr_test.cc | 12 +- .../wgsl/parser_impl_const_literal_test.cc | 20 ++-- .../wgsl/parser_impl_continue_stmt_test.cc | 2 +- .../wgsl/parser_impl_continuing_stmt_test.cc | 4 +- .../parser_impl_depth_texture_type_test.cc | 25 ++-- src/reader/wgsl/parser_impl_detail.h | 71 +++++++++++ src/reader/wgsl/parser_impl_else_stmt_test.cc | 6 +- .../parser_impl_equality_expression_test.cc | 10 +- ...arser_impl_exclusive_or_expression_test.cc | 6 +- src/reader/wgsl/parser_impl_for_stmt_test.cc | 2 +- .../wgsl/parser_impl_function_decl_test.cc | 66 +++++------ .../wgsl/parser_impl_function_header_test.cc | 10 +- .../parser_impl_global_constant_decl_test.cc | 20 ++-- .../parser_impl_global_variable_decl_test.cc | 88 +++++++------- src/reader/wgsl/parser_impl_if_stmt_test.cc | 30 ++--- ...arser_impl_inclusive_or_expression_test.cc | 6 +- ...parser_impl_logical_and_expression_test.cc | 6 +- .../parser_impl_logical_or_expression_test.cc | 6 +- src/reader/wgsl/parser_impl_loop_stmt_test.cc | 24 ++-- ...ser_impl_multiplicative_expression_test.cc | 14 +-- .../wgsl/parser_impl_paren_rhs_stmt_test.cc | 2 +- .../parser_impl_postfix_expression_test.cc | 22 ++-- .../parser_impl_primary_expression_test.cc | 34 +++--- .../parser_impl_relational_expression_test.cc | 18 +-- .../wgsl/parser_impl_sampler_type_test.cc | 8 +- .../wgsl/parser_impl_shift_expression_test.cc | 10 +- src/reader/wgsl/parser_impl_statement_test.cc | 30 ++--- .../wgsl/parser_impl_statements_test.cc | 8 +- .../wgsl/parser_impl_struct_decl_test.cc | 36 +++--- .../wgsl/parser_impl_struct_member_test.cc | 54 ++++----- .../wgsl/parser_impl_switch_body_test.cc | 16 +-- .../wgsl/parser_impl_switch_stmt_test.cc | 22 ++-- .../parser_impl_texture_sampler_types_test.cc | 110 +++++++++--------- .../wgsl/parser_impl_type_alias_test.cc | 8 +- src/reader/wgsl/parser_impl_type_decl_test.cc | 68 +++++------ .../wgsl/parser_impl_unary_expression_test.cc | 12 +- .../wgsl/parser_impl_variable_decl_test.cc | 28 ++--- .../wgsl/parser_impl_variable_stmt_test.cc | 44 +++---- 49 files changed, 585 insertions(+), 504 deletions(-) create mode 100644 src/reader/wgsl/parser_impl_detail.h diff --git a/BUILD.gn b/BUILD.gn index b94c05496e..ca9ce6c937 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -524,6 +524,7 @@ source_set("libtint_wgsl_reader_src") { "src/reader/wgsl/parser.h", "src/reader/wgsl/parser_impl.cc", "src/reader/wgsl/parser_impl.h", + "src/reader/wgsl/parser_impl_detail.h", "src/reader/wgsl/token.cc", "src/reader/wgsl/token.h", ] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1cc7808d69..0356719715 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -280,6 +280,7 @@ if(${TINT_BUILD_WGSL_READER}) reader/wgsl/parser.h reader/wgsl/parser_impl.cc reader/wgsl/parser_impl.h + reader/wgsl/parser_impl_detail.h reader/wgsl/token.cc reader/wgsl/token.h ) diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index a4e4e71652..03bdaf4a81 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -1156,13 +1156,13 @@ Maybe> ParserImpl::function_decl( if (func_decos.errored) return Failure::kErrored; - f.value->set_decorations(std::move(func_decos.value)); + f->set_decorations(std::move(func_decos.value)); auto body = expect_body_stmt(); if (body.errored) return Failure::kErrored; - f.value->set_body(std::move(body.value)); + f->set_body(std::move(body.value)); return std::move(f.value); } @@ -1491,10 +1491,10 @@ Maybe> ParserImpl::variable_stmt() { if (!constructor.matched) return add_error(peek(), "missing constructor for variable declaration"); - var.value->set_constructor(std::move(constructor.value)); + var->set_constructor(std::move(constructor.value)); } - return std::make_unique(var.value->source(), + return std::make_unique(var->source(), std::move(var.value)); } @@ -1655,7 +1655,7 @@ Expect ParserImpl::expect_case_selectors() { return Failure::kErrored; if (!cond.matched) break; - if (!cond.value->IsInt()) + if (!cond->IsInt()) return add_error(t, "invalid case selector must be an integer value"); std::unique_ptr selector(cond.value.release()->AsInt()); @@ -1819,11 +1819,11 @@ Maybe> ParserImpl::for_stmt() { // The for statement is a syntactic sugar on top of the loop statement. // We create corresponding nodes in ast with the exact same behaviour // as we would expect from the loop statement. - if (header.value->condition != nullptr) { + if (header->condition != nullptr) { // !condition auto not_condition = std::make_unique( - header.value->condition->source(), ast::UnaryOp::kNot, - std::move(header.value->condition)); + header->condition->source(), ast::UnaryOp::kNot, + std::move(header->condition)); // { break; } auto break_stmt = std::make_unique(not_condition->source()); @@ -1834,22 +1834,22 @@ Maybe> ParserImpl::for_stmt() { auto break_if_not_condition = std::make_unique( not_condition->source(), std::move(not_condition), std::move(break_body)); - body.value->insert(0, std::move(break_if_not_condition)); + body->insert(0, std::move(break_if_not_condition)); } std::unique_ptr continuing_body = nullptr; - if (header.value->continuing != nullptr) { - continuing_body = std::make_unique( - header.value->continuing->source()); - continuing_body->append(std::move(header.value->continuing)); + if (header->continuing != nullptr) { + continuing_body = + std::make_unique(header->continuing->source()); + continuing_body->append(std::move(header->continuing)); } auto loop = std::make_unique( source, std::move(body.value), std::move(continuing_body)); - if (header.value->initializer != nullptr) { + if (header->initializer != nullptr) { auto result = std::make_unique(source); - result->append(std::move(header.value->initializer)); + result->append(std::move(header->initializer)); result->append(std::move(loop)); return result; } diff --git a/src/reader/wgsl/parser_impl.h b/src/reader/wgsl/parser_impl.h index ab3efeaea1..0dcaa37614 100644 --- a/src/reader/wgsl/parser_impl.h +++ b/src/reader/wgsl/parser_impl.h @@ -50,6 +50,7 @@ #include "src/context.h" #include "src/diagnostic/diagnostic.h" #include "src/diagnostic/formatter.h" +#include "src/reader/wgsl/parser_impl_detail.h" #include "src/reader/wgsl/token.h" namespace tint { @@ -121,10 +122,13 @@ class ParserImpl { /// @return this Expect inline Expect& operator=(Expect&&) = default; - /// @return a pointer to |value|. |errored| must be false to call. - inline T* operator->() { + /// @return a pointer to the returned value. If T is a pointer or + /// std::unique_ptr, operator->() automatically dereferences so that the + /// return type will always be a pointer to a non-pointer type. |errored| + /// must be false to call. + inline typename detail::OperatorArrow::type operator->() { assert(!errored); - return &value; + return detail::OperatorArrow::ptr(value); } /// The expected value of a successful parse. @@ -161,6 +165,7 @@ class ParserImpl { inline Maybe(Failure::NoMatch) {} // NOLINT /// Constructor from an Expect. + /// @param e the Expect to copy this Maybe from template inline Maybe(const Expect& e) // NOLINT : value(e.value), @@ -169,6 +174,7 @@ class ParserImpl { matched(!e.errored) {} /// Move from an Expect. + /// @param e the Expect to move this Maybe from template inline Maybe(Expect&& e) // NOLINT : value(std::move(e.value)), @@ -187,10 +193,13 @@ class ParserImpl { /// @return this Maybe inline Maybe& operator=(Maybe&&) = default; - /// @return a pointer to |value|. |errored| must be false to call. - inline T* operator->() { + /// @return a pointer to the returned value. If T is a pointer or + /// std::unique_ptr, operator->() automatically dereferences so that the + /// return type will always be a pointer to a non-pointer type. |errored| + /// must be false to call. + inline typename detail::OperatorArrow::type operator->() { assert(!errored); - return &value; + return detail::OperatorArrow::ptr(value); } /// The value of a successful parse. diff --git a/src/reader/wgsl/parser_impl_additive_expression_test.cc b/src/reader/wgsl/parser_impl_additive_expression_test.cc index 7a939753bc..e77c67029d 100644 --- a/src/reader/wgsl/parser_impl_additive_expression_test.cc +++ b/src/reader/wgsl/parser_impl_additive_expression_test.cc @@ -33,8 +33,8 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Plus) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kAdd, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -56,8 +56,8 @@ TEST_F(ParserImplTest, AdditiveExpression_Parses_Minus) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kSubtract, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -97,7 +97,7 @@ TEST_F(ParserImplTest, AdditiveExpression_NoOr_ReturnsLHS) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIdentifier()); + ASSERT_TRUE(e->IsIdentifier()); } } // namespace diff --git a/src/reader/wgsl/parser_impl_and_expression_test.cc b/src/reader/wgsl/parser_impl_and_expression_test.cc index 2b85958696..990e149aca 100644 --- a/src/reader/wgsl/parser_impl_and_expression_test.cc +++ b/src/reader/wgsl/parser_impl_and_expression_test.cc @@ -33,8 +33,8 @@ TEST_F(ParserImplTest, AndExpression_Parses) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kAnd, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -74,7 +74,7 @@ TEST_F(ParserImplTest, AndExpression_NoOr_ReturnsLHS) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIdentifier()); + ASSERT_TRUE(e->IsIdentifier()); } } // namespace diff --git a/src/reader/wgsl/parser_impl_assignment_stmt_test.cc b/src/reader/wgsl/parser_impl_assignment_stmt_test.cc index 304781efb4..89ab5e40f1 100644 --- a/src/reader/wgsl/parser_impl_assignment_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_assignment_stmt_test.cc @@ -36,18 +36,18 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsAssign()); - ASSERT_NE(e.value->lhs(), nullptr); - ASSERT_NE(e.value->rhs(), nullptr); + ASSERT_TRUE(e->IsAssign()); + ASSERT_NE(e->lhs(), nullptr); + ASSERT_NE(e->rhs(), nullptr); - ASSERT_TRUE(e.value->lhs()->IsIdentifier()); - auto* ident = e.value->lhs()->AsIdentifier(); + ASSERT_TRUE(e->lhs()->IsIdentifier()); + auto* ident = e->lhs()->AsIdentifier(); EXPECT_EQ(ident->name(), "a"); - ASSERT_TRUE(e.value->rhs()->IsConstructor()); - ASSERT_TRUE(e.value->rhs()->AsConstructor()->IsScalarConstructor()); + ASSERT_TRUE(e->rhs()->IsConstructor()); + ASSERT_TRUE(e->rhs()->AsConstructor()->IsScalarConstructor()); - auto* init = e.value->rhs()->AsConstructor()->AsScalarConstructor(); + auto* init = e->rhs()->AsConstructor()->AsScalarConstructor(); ASSERT_NE(init->literal(), nullptr); ASSERT_TRUE(init->literal()->IsSint()); EXPECT_EQ(init->literal()->AsSint()->value(), 123); @@ -61,19 +61,19 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsAssign()); - ASSERT_NE(e.value->lhs(), nullptr); - ASSERT_NE(e.value->rhs(), nullptr); + ASSERT_TRUE(e->IsAssign()); + ASSERT_NE(e->lhs(), nullptr); + ASSERT_NE(e->rhs(), nullptr); - ASSERT_TRUE(e.value->rhs()->IsConstructor()); - ASSERT_TRUE(e.value->rhs()->AsConstructor()->IsScalarConstructor()); - auto* init = e.value->rhs()->AsConstructor()->AsScalarConstructor(); + ASSERT_TRUE(e->rhs()->IsConstructor()); + ASSERT_TRUE(e->rhs()->AsConstructor()->IsScalarConstructor()); + auto* init = e->rhs()->AsConstructor()->AsScalarConstructor(); ASSERT_NE(init->literal(), nullptr); ASSERT_TRUE(init->literal()->IsSint()); EXPECT_EQ(init->literal()->AsSint()->value(), 123); - ASSERT_TRUE(e.value->lhs()->IsMemberAccessor()); - auto* mem = e.value->lhs()->AsMemberAccessor(); + ASSERT_TRUE(e->lhs()->IsMemberAccessor()); + auto* mem = e->lhs()->AsMemberAccessor(); ASSERT_TRUE(mem->member()->IsIdentifier()); auto* ident = mem->member()->AsIdentifier(); diff --git a/src/reader/wgsl/parser_impl_body_stmt_test.cc b/src/reader/wgsl/parser_impl_body_stmt_test.cc index 4a3b5a0814..d0474eb633 100644 --- a/src/reader/wgsl/parser_impl_body_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_body_stmt_test.cc @@ -29,9 +29,9 @@ TEST_F(ParserImplTest, BodyStmt) { auto e = p->expect_body_stmt(); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(e.errored); - ASSERT_EQ(e.value->size(), 2u); - EXPECT_TRUE(e.value->get(0)->IsDiscard()); - EXPECT_TRUE(e.value->get(1)->IsReturn()); + ASSERT_EQ(e->size(), 2u); + EXPECT_TRUE(e->get(0)->IsDiscard()); + EXPECT_TRUE(e->get(1)->IsReturn()); } TEST_F(ParserImplTest, BodyStmt_Empty) { @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, BodyStmt_Empty) { auto e = p->expect_body_stmt(); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(e.errored); - EXPECT_EQ(e.value->size(), 0u); + EXPECT_EQ(e->size(), 0u); } TEST_F(ParserImplTest, BodyStmt_InvalidStmt) { diff --git a/src/reader/wgsl/parser_impl_break_stmt_test.cc b/src/reader/wgsl/parser_impl_break_stmt_test.cc index 8fd49c36fa..a45f7190ef 100644 --- a/src/reader/wgsl/parser_impl_break_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_break_stmt_test.cc @@ -28,7 +28,7 @@ TEST_F(ParserImplTest, BreakStmt) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBreak()); + ASSERT_TRUE(e->IsBreak()); } } // namespace diff --git a/src/reader/wgsl/parser_impl_call_stmt_test.cc b/src/reader/wgsl/parser_impl_call_stmt_test.cc index ded8f509bc..875805d3eb 100644 --- a/src/reader/wgsl/parser_impl_call_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_call_stmt_test.cc @@ -32,8 +32,8 @@ TEST_F(ParserImplTest, Statement_Call) { EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsCall()); - auto* c = e.value->AsCall()->expr(); + ASSERT_TRUE(e->IsCall()); + auto* c = e->AsCall()->expr(); ASSERT_TRUE(c->func()->IsIdentifier()); auto* func = c->func()->AsIdentifier(); @@ -50,8 +50,8 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) { EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsCall()); - auto* c = e.value->AsCall()->expr(); + ASSERT_TRUE(e->IsCall()); + auto* c = e->AsCall()->expr(); ASSERT_TRUE(c->func()->IsIdentifier()); auto* func = c->func()->AsIdentifier(); diff --git a/src/reader/wgsl/parser_impl_case_body_test.cc b/src/reader/wgsl/parser_impl_case_body_test.cc index b840d70beb..17e55da4e9 100644 --- a/src/reader/wgsl/parser_impl_case_body_test.cc +++ b/src/reader/wgsl/parser_impl_case_body_test.cc @@ -27,7 +27,7 @@ TEST_F(ParserImplTest, CaseBody_Empty) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(e.errored); EXPECT_TRUE(e.matched); - EXPECT_EQ(e.value->size(), 0u); + EXPECT_EQ(e->size(), 0u); } TEST_F(ParserImplTest, CaseBody_Statements) { @@ -39,9 +39,9 @@ TEST_F(ParserImplTest, CaseBody_Statements) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(e.errored); EXPECT_TRUE(e.matched); - ASSERT_EQ(e.value->size(), 2u); - EXPECT_TRUE(e.value->get(0)->IsVariableDecl()); - EXPECT_TRUE(e.value->get(1)->IsAssign()); + ASSERT_EQ(e->size(), 2u); + EXPECT_TRUE(e->get(0)->IsVariableDecl()); + EXPECT_TRUE(e->get(1)->IsAssign()); } TEST_F(ParserImplTest, CaseBody_InvalidStatement) { @@ -59,8 +59,8 @@ TEST_F(ParserImplTest, CaseBody_Fallthrough) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_FALSE(e.errored); EXPECT_TRUE(e.matched); - ASSERT_EQ(e.value->size(), 1u); - EXPECT_TRUE(e.value->get(0)->IsFallthrough()); + ASSERT_EQ(e->size(), 1u); + EXPECT_TRUE(e->get(0)->IsFallthrough()); } TEST_F(ParserImplTest, CaseBody_Fallthrough_MissingSemicolon) { diff --git a/src/reader/wgsl/parser_impl_const_expr_test.cc b/src/reader/wgsl/parser_impl_const_expr_test.cc index 14b716fe13..f07fbc2014 100644 --- a/src/reader/wgsl/parser_impl_const_expr_test.cc +++ b/src/reader/wgsl/parser_impl_const_expr_test.cc @@ -31,10 +31,10 @@ TEST_F(ParserImplTest, ConstExpr_TypeDecl) { auto e = p->expect_const_expr(); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsConstructor()); - ASSERT_TRUE(e.value->AsConstructor()->IsTypeConstructor()); + ASSERT_TRUE(e->IsConstructor()); + ASSERT_TRUE(e->AsConstructor()->IsTypeConstructor()); - auto* t = e.value->AsConstructor()->AsTypeConstructor(); + auto* t = e->AsConstructor()->AsTypeConstructor(); ASSERT_TRUE(t->type()->IsVector()); EXPECT_EQ(t->type()->AsVector()->size(), 2u); @@ -114,9 +114,9 @@ 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->IsConstructor()); - ASSERT_TRUE(e.value->AsConstructor()->IsScalarConstructor()); - auto* c = e.value->AsConstructor()->AsScalarConstructor(); + ASSERT_TRUE(e->IsConstructor()); + ASSERT_TRUE(e->AsConstructor()->IsScalarConstructor()); + auto* c = e->AsConstructor()->AsScalarConstructor(); ASSERT_TRUE(c->literal()->IsBool()); EXPECT_TRUE(c->literal()->AsBool()->IsTrue()); } diff --git a/src/reader/wgsl/parser_impl_const_literal_test.cc b/src/reader/wgsl/parser_impl_const_literal_test.cc index 28b0771f5b..acb7637674 100644 --- a/src/reader/wgsl/parser_impl_const_literal_test.cc +++ b/src/reader/wgsl/parser_impl_const_literal_test.cc @@ -32,8 +32,8 @@ TEST_F(ParserImplTest, ConstLiteral_Int) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c.value->IsSint()); - EXPECT_EQ(c.value->AsSint()->value(), -234); + ASSERT_TRUE(c->IsSint()); + EXPECT_EQ(c->AsSint()->value(), -234); } TEST_F(ParserImplTest, ConstLiteral_Uint) { @@ -43,8 +43,8 @@ TEST_F(ParserImplTest, ConstLiteral_Uint) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c.value->IsUint()); - EXPECT_EQ(c.value->AsUint()->value(), 234u); + ASSERT_TRUE(c->IsUint()); + EXPECT_EQ(c->AsUint()->value(), 234u); } TEST_F(ParserImplTest, ConstLiteral_Float) { @@ -54,8 +54,8 @@ TEST_F(ParserImplTest, ConstLiteral_Float) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c.value->IsFloat()); - EXPECT_FLOAT_EQ(c.value->AsFloat()->value(), 234e12f); + ASSERT_TRUE(c->IsFloat()); + EXPECT_FLOAT_EQ(c->AsFloat()->value(), 234e12f); } TEST_F(ParserImplTest, ConstLiteral_InvalidFloat) { @@ -73,8 +73,8 @@ TEST_F(ParserImplTest, ConstLiteral_True) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c.value->IsBool()); - EXPECT_TRUE(c.value->AsBool()->IsTrue()); + ASSERT_TRUE(c->IsBool()); + EXPECT_TRUE(c->AsBool()->IsTrue()); } TEST_F(ParserImplTest, ConstLiteral_False) { @@ -84,8 +84,8 @@ TEST_F(ParserImplTest, ConstLiteral_False) { EXPECT_FALSE(c.errored); EXPECT_FALSE(p->has_error()); ASSERT_NE(c.value, nullptr); - ASSERT_TRUE(c.value->IsBool()); - EXPECT_TRUE(c.value->AsBool()->IsFalse()); + ASSERT_TRUE(c->IsBool()); + EXPECT_TRUE(c->AsBool()->IsFalse()); } TEST_F(ParserImplTest, ConstLiteral_NoMatch) { diff --git a/src/reader/wgsl/parser_impl_continue_stmt_test.cc b/src/reader/wgsl/parser_impl_continue_stmt_test.cc index 1a7f644ab4..b2003cea19 100644 --- a/src/reader/wgsl/parser_impl_continue_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_continue_stmt_test.cc @@ -28,7 +28,7 @@ TEST_F(ParserImplTest, ContinueStmt) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsContinue()); + ASSERT_TRUE(e->IsContinue()); } } // namespace diff --git a/src/reader/wgsl/parser_impl_continuing_stmt_test.cc b/src/reader/wgsl/parser_impl_continuing_stmt_test.cc index e29b1d405f..68c9ec6042 100644 --- a/src/reader/wgsl/parser_impl_continuing_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_continuing_stmt_test.cc @@ -27,8 +27,8 @@ TEST_F(ParserImplTest, ContinuingStmt) { EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); - ASSERT_EQ(e.value->size(), 1u); - ASSERT_TRUE(e.value->get(0)->IsDiscard()); + ASSERT_EQ(e->size(), 1u); + ASSERT_TRUE(e->get(0)->IsDiscard()); } TEST_F(ParserImplTest, ContinuingStmt_InvalidBody) { diff --git a/src/reader/wgsl/parser_impl_depth_texture_type_test.cc b/src/reader/wgsl/parser_impl_depth_texture_type_test.cc index 35119bbfce..5125c066c4 100644 --- a/src/reader/wgsl/parser_impl_depth_texture_type_test.cc +++ b/src/reader/wgsl/parser_impl_depth_texture_type_test.cc @@ -36,9 +36,9 @@ TEST_F(ParserImplTest, DepthTextureType_2d) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsDepth()); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsDepth()); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); } @@ -48,9 +48,9 @@ TEST_F(ParserImplTest, DepthTextureType_2dArray) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsDepth()); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k2dArray); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsDepth()); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2dArray); EXPECT_FALSE(p->has_error()); } @@ -60,9 +60,9 @@ TEST_F(ParserImplTest, DepthTextureType_Cube) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsDepth()); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::kCube); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsDepth()); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::kCube); EXPECT_FALSE(p->has_error()); } @@ -72,10 +72,9 @@ TEST_F(ParserImplTest, DepthTextureType_CubeArray) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsDepth()); - EXPECT_EQ(t.value->AsTexture()->dim(), - ast::type::TextureDimension::kCubeArray); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsDepth()); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::kCubeArray); EXPECT_FALSE(p->has_error()); } diff --git a/src/reader/wgsl/parser_impl_detail.h b/src/reader/wgsl/parser_impl_detail.h new file mode 100644 index 0000000000..b19a523317 --- /dev/null +++ b/src/reader/wgsl/parser_impl_detail.h @@ -0,0 +1,71 @@ +// Copyright 2020 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_READER_WGSL_PARSER_IMPL_DETAIL_H_ +#define SRC_READER_WGSL_PARSER_IMPL_DETAIL_H_ + +#include +#include + +namespace tint { +namespace reader { +namespace wgsl { +namespace detail { + +/// OperatorArrow is a traits helper for ParserImpl::Expect::operator->() and +/// ParserImpl::Maybe::operator->() so that pointer types are automatically +/// dereferenced. This simplifies usage by allowing +/// `result.value->field` +/// to be written as: +/// `result->field` +/// As well as reducing the amount of code, using the operator->() asserts that +/// the Expect or Maybe is not in an error state before dereferencing. +template +struct OperatorArrow { + /// type resolves to the return type for the operator->() + using type = T*; + /// @param val the value held by `ParserImpl::Expect` or + /// `ParserImpl::Maybe`. + /// @return a pointer to `val` + static inline T* ptr(T& val) { return &val; } +}; + +/// OperatorArrow template specialization for std::unique_ptr<>. +template +struct OperatorArrow> { + /// type resolves to the return type for the operator->() + using type = T*; + /// @param val the value held by `ParserImpl::Expect` or + /// `ParserImpl::Maybe`. + /// @return the raw pointer held by `val`. + static inline T* ptr(std::unique_ptr& val) { return val.get(); } +}; + +/// OperatorArrow template specialization for T*. +template +struct OperatorArrow { + /// type resolves to the return type for the operator->() + using type = T*; + /// @param val the value held by `ParserImpl::Expect` or + /// `ParserImpl::Maybe`. + /// @return `val`. + static inline T* ptr(T* val) { return val; } +}; + +} // namespace detail +} // namespace wgsl +} // namespace reader +} // namespace tint + +#endif // SRC_READER_WGSL_PARSER_IMPL_DETAIL_H_ diff --git a/src/reader/wgsl/parser_impl_else_stmt_test.cc b/src/reader/wgsl/parser_impl_else_stmt_test.cc index 08313f2d1e..89632e32e3 100644 --- a/src/reader/wgsl/parser_impl_else_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_else_stmt_test.cc @@ -29,9 +29,9 @@ TEST_F(ParserImplTest, ElseStmt) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsElse()); - ASSERT_EQ(e.value->condition(), nullptr); - EXPECT_EQ(e.value->body()->size(), 2u); + ASSERT_TRUE(e->IsElse()); + ASSERT_EQ(e->condition(), nullptr); + EXPECT_EQ(e->body()->size(), 2u); } TEST_F(ParserImplTest, ElseStmt_InvalidBody) { diff --git a/src/reader/wgsl/parser_impl_equality_expression_test.cc b/src/reader/wgsl/parser_impl_equality_expression_test.cc index 9801d006aa..f16007503f 100644 --- a/src/reader/wgsl/parser_impl_equality_expression_test.cc +++ b/src/reader/wgsl/parser_impl_equality_expression_test.cc @@ -33,8 +33,8 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_Equal) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kEqual, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -56,8 +56,8 @@ TEST_F(ParserImplTest, EqualityExpression_Parses_NotEqual) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kNotEqual, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -97,7 +97,7 @@ TEST_F(ParserImplTest, EqualityExpression_NoOr_ReturnsLHS) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIdentifier()); + ASSERT_TRUE(e->IsIdentifier()); } } // namespace 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 39f34e402d..c3a3139d22 100644 --- a/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc +++ b/src/reader/wgsl/parser_impl_exclusive_or_expression_test.cc @@ -33,8 +33,8 @@ TEST_F(ParserImplTest, ExclusiveOrExpression_Parses) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kXor, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -74,7 +74,7 @@ TEST_F(ParserImplTest, ExclusiveOrExpression_NoOr_ReturnsLHS) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIdentifier()); + ASSERT_TRUE(e->IsIdentifier()); } } // namespace diff --git a/src/reader/wgsl/parser_impl_for_stmt_test.cc b/src/reader/wgsl/parser_impl_for_stmt_test.cc index fe9b63f051..27c7defe9a 100644 --- a/src/reader/wgsl/parser_impl_for_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_for_stmt_test.cc @@ -38,7 +38,7 @@ class ForStmtTest : public ParserImplTest { EXPECT_FALSE(p_for->has_error()) << p_for->error(); ASSERT_NE(e_for.value, nullptr); - EXPECT_EQ(e_loop.value->str(), e_for.value->str()); + EXPECT_EQ(e_loop->str(), e_for->str()); } }; diff --git a/src/reader/wgsl/parser_impl_function_decl_test.cc b/src/reader/wgsl/parser_impl_function_decl_test.cc index 68ba11a6f1..03dc6cbdb0 100644 --- a/src/reader/wgsl/parser_impl_function_decl_test.cc +++ b/src/reader/wgsl/parser_impl_function_decl_test.cc @@ -36,18 +36,18 @@ TEST_F(ParserImplTest, FunctionDecl) { EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f.value->name(), "main"); - ASSERT_NE(f.value->return_type(), nullptr); - EXPECT_TRUE(f.value->return_type()->IsVoid()); + EXPECT_EQ(f->name(), "main"); + ASSERT_NE(f->return_type(), nullptr); + EXPECT_TRUE(f->return_type()->IsVoid()); - ASSERT_EQ(f.value->params().size(), 2u); - EXPECT_EQ(f.value->params()[0]->name(), "a"); - EXPECT_EQ(f.value->params()[1]->name(), "b"); + ASSERT_EQ(f->params().size(), 2u); + EXPECT_EQ(f->params()[0]->name(), "a"); + EXPECT_EQ(f->params()[1]->name(), "b"); - ASSERT_NE(f.value->return_type(), nullptr); - EXPECT_TRUE(f.value->return_type()->IsVoid()); + ASSERT_NE(f->return_type(), nullptr); + EXPECT_TRUE(f->return_type()->IsVoid()); - auto* body = f.value->body(); + auto* body = f->body(); ASSERT_EQ(body->size(), 1u); EXPECT_TRUE(body->get(0)->IsReturn()); } @@ -64,14 +64,14 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) { EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f.value->name(), "main"); - ASSERT_NE(f.value->return_type(), nullptr); - EXPECT_TRUE(f.value->return_type()->IsVoid()); - ASSERT_EQ(f.value->params().size(), 0u); - ASSERT_NE(f.value->return_type(), nullptr); - EXPECT_TRUE(f.value->return_type()->IsVoid()); + EXPECT_EQ(f->name(), "main"); + ASSERT_NE(f->return_type(), nullptr); + EXPECT_TRUE(f->return_type()->IsVoid()); + ASSERT_EQ(f->params().size(), 0u); + ASSERT_NE(f->return_type(), nullptr); + EXPECT_TRUE(f->return_type()->IsVoid()); - auto& decorations = f.value->decorations(); + auto& decorations = f->decorations(); ASSERT_EQ(decorations.size(), 1u); ASSERT_TRUE(decorations[0]->IsWorkgroup()); @@ -83,7 +83,7 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) { EXPECT_EQ(y, 3u); EXPECT_EQ(z, 4u); - auto* body = f.value->body(); + auto* body = f->body(); ASSERT_EQ(body->size(), 1u); EXPECT_TRUE(body->get(0)->IsReturn()); } @@ -102,14 +102,14 @@ fn main() -> void { return; })"); EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f.value->name(), "main"); - ASSERT_NE(f.value->return_type(), nullptr); - EXPECT_TRUE(f.value->return_type()->IsVoid()); - ASSERT_EQ(f.value->params().size(), 0u); - ASSERT_NE(f.value->return_type(), nullptr); - EXPECT_TRUE(f.value->return_type()->IsVoid()); + EXPECT_EQ(f->name(), "main"); + ASSERT_NE(f->return_type(), nullptr); + EXPECT_TRUE(f->return_type()->IsVoid()); + ASSERT_EQ(f->params().size(), 0u); + ASSERT_NE(f->return_type(), nullptr); + EXPECT_TRUE(f->return_type()->IsVoid()); - auto& decorations = f.value->decorations(); + auto& decorations = f->decorations(); ASSERT_EQ(decorations.size(), 2u); uint32_t x = 0; @@ -127,7 +127,7 @@ fn main() -> void { return; })"); EXPECT_EQ(y, 6u); EXPECT_EQ(z, 7u); - auto* body = f.value->body(); + auto* body = f->body(); ASSERT_EQ(body->size(), 1u); EXPECT_TRUE(body->get(0)->IsReturn()); } @@ -147,14 +147,14 @@ fn main() -> void { return; })"); EXPECT_TRUE(f.matched); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f.value->name(), "main"); - ASSERT_NE(f.value->return_type(), nullptr); - EXPECT_TRUE(f.value->return_type()->IsVoid()); - ASSERT_EQ(f.value->params().size(), 0u); - ASSERT_NE(f.value->return_type(), nullptr); - EXPECT_TRUE(f.value->return_type()->IsVoid()); + EXPECT_EQ(f->name(), "main"); + ASSERT_NE(f->return_type(), nullptr); + EXPECT_TRUE(f->return_type()->IsVoid()); + ASSERT_EQ(f->params().size(), 0u); + ASSERT_NE(f->return_type(), nullptr); + EXPECT_TRUE(f->return_type()->IsVoid()); - auto& decos = f.value->decorations(); + auto& decos = f->decorations(); ASSERT_EQ(decos.size(), 2u); uint32_t x = 0; @@ -172,7 +172,7 @@ fn main() -> void { return; })"); EXPECT_EQ(y, 6u); EXPECT_EQ(z, 7u); - auto* body = f.value->body(); + auto* body = f->body(); ASSERT_EQ(body->size(), 1u); EXPECT_TRUE(body->get(0)->IsReturn()); } diff --git a/src/reader/wgsl/parser_impl_function_header_test.cc b/src/reader/wgsl/parser_impl_function_header_test.cc index a7f000b321..ae1e2d3165 100644 --- a/src/reader/wgsl/parser_impl_function_header_test.cc +++ b/src/reader/wgsl/parser_impl_function_header_test.cc @@ -31,11 +31,11 @@ TEST_F(ParserImplTest, FunctionHeader) { EXPECT_FALSE(f.errored); ASSERT_NE(f.value, nullptr); - EXPECT_EQ(f.value->name(), "main"); - ASSERT_EQ(f.value->params().size(), 2u); - EXPECT_EQ(f.value->params()[0]->name(), "a"); - EXPECT_EQ(f.value->params()[1]->name(), "b"); - EXPECT_TRUE(f.value->return_type()->IsVoid()); + EXPECT_EQ(f->name(), "main"); + ASSERT_EQ(f->params().size(), 2u); + EXPECT_EQ(f->params()[0]->name(), "a"); + EXPECT_EQ(f->params()[1]->name(), "b"); + EXPECT_TRUE(f->return_type()->IsVoid()); } TEST_F(ParserImplTest, FunctionHeader_MissingIdent) { 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 929be791b8..5888ee97b8 100644 --- a/src/reader/wgsl/parser_impl_global_constant_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_constant_decl_test.cc @@ -31,18 +31,18 @@ TEST_F(ParserImplTest, GlobalConstantDecl) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_TRUE(e.value->is_const()); - EXPECT_EQ(e.value->name(), "a"); - ASSERT_NE(e.value->type(), nullptr); - EXPECT_TRUE(e.value->type()->IsF32()); + EXPECT_TRUE(e->is_const()); + EXPECT_EQ(e->name(), "a"); + ASSERT_NE(e->type(), nullptr); + EXPECT_TRUE(e->type()->IsF32()); - EXPECT_EQ(e.value->source().range.begin.line, 1u); - EXPECT_EQ(e.value->source().range.begin.column, 7u); - EXPECT_EQ(e.value->source().range.end.line, 1u); - EXPECT_EQ(e.value->source().range.end.column, 8u); + EXPECT_EQ(e->source().range.begin.line, 1u); + EXPECT_EQ(e->source().range.begin.column, 7u); + EXPECT_EQ(e->source().range.end.line, 1u); + EXPECT_EQ(e->source().range.end.column, 8u); - ASSERT_NE(e.value->constructor(), nullptr); - EXPECT_TRUE(e.value->constructor()->IsConstructor()); + ASSERT_NE(e->constructor(), nullptr); + EXPECT_TRUE(e->constructor()->IsConstructor()); } TEST_F(ParserImplTest, GlobalConstantDecl_MissingEqual) { 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 d6dbcbd544..446d93fe0c 100644 --- a/src/reader/wgsl/parser_impl_global_variable_decl_test.cc +++ b/src/reader/wgsl/parser_impl_global_variable_decl_test.cc @@ -34,17 +34,17 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutConstructor) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_EQ(e.value->name(), "a"); - EXPECT_TRUE(e.value->type()->IsF32()); - EXPECT_EQ(e.value->storage_class(), ast::StorageClass::kOutput); + EXPECT_EQ(e->name(), "a"); + EXPECT_TRUE(e->type()->IsF32()); + EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); - EXPECT_EQ(e.value->source().range.begin.line, 1u); - EXPECT_EQ(e.value->source().range.begin.column, 10u); - EXPECT_EQ(e.value->source().range.end.line, 1u); - EXPECT_EQ(e.value->source().range.end.column, 11u); + EXPECT_EQ(e->source().range.begin.line, 1u); + EXPECT_EQ(e->source().range.begin.column, 10u); + EXPECT_EQ(e->source().range.end.line, 1u); + EXPECT_EQ(e->source().range.end.column, 11u); - ASSERT_EQ(e.value->constructor(), nullptr); - ASSERT_FALSE(e.value->IsDecorated()); + ASSERT_EQ(e->constructor(), nullptr); + ASSERT_FALSE(e->IsDecorated()); } TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) { @@ -58,20 +58,20 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithConstructor) { EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - EXPECT_EQ(e.value->name(), "a"); - EXPECT_TRUE(e.value->type()->IsF32()); - EXPECT_EQ(e.value->storage_class(), ast::StorageClass::kOutput); + EXPECT_EQ(e->name(), "a"); + EXPECT_TRUE(e->type()->IsF32()); + EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); - EXPECT_EQ(e.value->source().range.begin.line, 1u); - EXPECT_EQ(e.value->source().range.begin.column, 10u); - EXPECT_EQ(e.value->source().range.end.line, 1u); - EXPECT_EQ(e.value->source().range.end.column, 11u); + EXPECT_EQ(e->source().range.begin.line, 1u); + EXPECT_EQ(e->source().range.begin.column, 10u); + EXPECT_EQ(e->source().range.end.line, 1u); + EXPECT_EQ(e->source().range.end.column, 11u); - ASSERT_NE(e.value->constructor(), nullptr); - ASSERT_TRUE(e.value->constructor()->IsConstructor()); - ASSERT_TRUE(e.value->constructor()->AsConstructor()->IsScalarConstructor()); + ASSERT_NE(e->constructor(), nullptr); + ASSERT_TRUE(e->constructor()->IsConstructor()); + ASSERT_TRUE(e->constructor()->AsConstructor()->IsScalarConstructor()); - ASSERT_FALSE(e.value->IsDecorated()); + ASSERT_FALSE(e->IsDecorated()); } TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) { @@ -84,22 +84,22 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration) { EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsDecorated()); + ASSERT_TRUE(e->IsDecorated()); - EXPECT_EQ(e.value->name(), "a"); - ASSERT_NE(e.value->type(), nullptr); - EXPECT_TRUE(e.value->type()->IsF32()); - EXPECT_EQ(e.value->storage_class(), ast::StorageClass::kOutput); + EXPECT_EQ(e->name(), "a"); + ASSERT_NE(e->type(), nullptr); + EXPECT_TRUE(e->type()->IsF32()); + EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); - EXPECT_EQ(e.value->source().range.begin.line, 1u); - EXPECT_EQ(e.value->source().range.begin.column, 33u); - EXPECT_EQ(e.value->source().range.end.line, 1u); - EXPECT_EQ(e.value->source().range.end.column, 34u); + EXPECT_EQ(e->source().range.begin.line, 1u); + EXPECT_EQ(e->source().range.begin.column, 33u); + EXPECT_EQ(e->source().range.end.line, 1u); + EXPECT_EQ(e->source().range.end.column, 34u); - ASSERT_EQ(e.value->constructor(), nullptr); + ASSERT_EQ(e->constructor(), nullptr); - ASSERT_TRUE(e.value->IsDecorated()); - auto* v = e.value->AsDecorated(); + ASSERT_TRUE(e->IsDecorated()); + auto* v = e->AsDecorated(); auto& decorations = v->decorations(); ASSERT_EQ(decorations.size(), 2u); @@ -118,22 +118,22 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithDecoration_MulitpleGroups) { EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsDecorated()); + ASSERT_TRUE(e->IsDecorated()); - EXPECT_EQ(e.value->name(), "a"); - ASSERT_NE(e.value->type(), nullptr); - EXPECT_TRUE(e.value->type()->IsF32()); - EXPECT_EQ(e.value->storage_class(), ast::StorageClass::kOutput); + EXPECT_EQ(e->name(), "a"); + ASSERT_NE(e->type(), nullptr); + EXPECT_TRUE(e->type()->IsF32()); + EXPECT_EQ(e->storage_class(), ast::StorageClass::kOutput); - EXPECT_EQ(e.value->source().range.begin.line, 1u); - EXPECT_EQ(e.value->source().range.begin.column, 36u); - EXPECT_EQ(e.value->source().range.end.line, 1u); - EXPECT_EQ(e.value->source().range.end.column, 37u); + EXPECT_EQ(e->source().range.begin.line, 1u); + EXPECT_EQ(e->source().range.begin.column, 36u); + EXPECT_EQ(e->source().range.end.line, 1u); + EXPECT_EQ(e->source().range.end.column, 37u); - ASSERT_EQ(e.value->constructor(), nullptr); + ASSERT_EQ(e->constructor(), nullptr); - ASSERT_TRUE(e.value->IsDecorated()); - auto* v = e.value->AsDecorated(); + ASSERT_TRUE(e->IsDecorated()); + auto* v = e->AsDecorated(); auto& decorations = v->decorations(); ASSERT_EQ(decorations.size(), 2u); diff --git a/src/reader/wgsl/parser_impl_if_stmt_test.cc b/src/reader/wgsl/parser_impl_if_stmt_test.cc index 8dea243046..0297559770 100644 --- a/src/reader/wgsl/parser_impl_if_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_if_stmt_test.cc @@ -31,11 +31,11 @@ TEST_F(ParserImplTest, IfStmt) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIf()); - ASSERT_NE(e.value->condition(), nullptr); - ASSERT_TRUE(e.value->condition()->IsBinary()); - EXPECT_EQ(e.value->body()->size(), 2u); - EXPECT_EQ(e.value->else_statements().size(), 0u); + ASSERT_TRUE(e->IsIf()); + ASSERT_NE(e->condition(), nullptr); + ASSERT_TRUE(e->condition()->IsBinary()); + EXPECT_EQ(e->body()->size(), 2u); + EXPECT_EQ(e->else_statements().size(), 0u); } TEST_F(ParserImplTest, IfStmt_WithElse) { @@ -47,18 +47,18 @@ TEST_F(ParserImplTest, IfStmt_WithElse) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIf()); - ASSERT_NE(e.value->condition(), nullptr); - ASSERT_TRUE(e.value->condition()->IsBinary()); - EXPECT_EQ(e.value->body()->size(), 2u); + ASSERT_TRUE(e->IsIf()); + ASSERT_NE(e->condition(), nullptr); + ASSERT_TRUE(e->condition()->IsBinary()); + EXPECT_EQ(e->body()->size(), 2u); - ASSERT_EQ(e.value->else_statements().size(), 2u); - ASSERT_NE(e.value->else_statements()[0]->condition(), nullptr); - ASSERT_TRUE(e.value->else_statements()[0]->condition()->IsIdentifier()); - EXPECT_EQ(e.value->else_statements()[0]->body()->size(), 1u); + ASSERT_EQ(e->else_statements().size(), 2u); + ASSERT_NE(e->else_statements()[0]->condition(), nullptr); + ASSERT_TRUE(e->else_statements()[0]->condition()->IsIdentifier()); + EXPECT_EQ(e->else_statements()[0]->body()->size(), 1u); - ASSERT_EQ(e.value->else_statements()[1]->condition(), nullptr); - EXPECT_EQ(e.value->else_statements()[1]->body()->size(), 0u); + ASSERT_EQ(e->else_statements()[1]->condition(), nullptr); + EXPECT_EQ(e->else_statements()[1]->body()->size(), 0u); } TEST_F(ParserImplTest, IfStmt_InvalidCondition) { 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 073c2beac4..e01042955a 100644 --- a/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc +++ b/src/reader/wgsl/parser_impl_inclusive_or_expression_test.cc @@ -33,8 +33,8 @@ TEST_F(ParserImplTest, InclusiveOrExpression_Parses) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kOr, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -74,7 +74,7 @@ TEST_F(ParserImplTest, InclusiveOrExpression_NoOr_ReturnsLHS) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIdentifier()); + ASSERT_TRUE(e->IsIdentifier()); } } // namespace 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 c11de2abcf..0235cad37f 100644 --- a/src/reader/wgsl/parser_impl_logical_and_expression_test.cc +++ b/src/reader/wgsl/parser_impl_logical_and_expression_test.cc @@ -33,8 +33,8 @@ TEST_F(ParserImplTest, LogicalAndExpression_Parses) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kLogicalAnd, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -74,7 +74,7 @@ TEST_F(ParserImplTest, LogicalAndExpression_NoOr_ReturnsLHS) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIdentifier()); + ASSERT_TRUE(e->IsIdentifier()); } } // namespace 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 3925590817..fd8c9348b8 100644 --- a/src/reader/wgsl/parser_impl_logical_or_expression_test.cc +++ b/src/reader/wgsl/parser_impl_logical_or_expression_test.cc @@ -33,8 +33,8 @@ TEST_F(ParserImplTest, LogicalOrExpression_Parses) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kLogicalOr, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -74,7 +74,7 @@ TEST_F(ParserImplTest, LogicalOrExpression_NoOr_ReturnsLHS) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIdentifier()); + ASSERT_TRUE(e->IsIdentifier()); } } // namespace diff --git a/src/reader/wgsl/parser_impl_loop_stmt_test.cc b/src/reader/wgsl/parser_impl_loop_stmt_test.cc index 6b4aa2fe20..f9198a07e0 100644 --- a/src/reader/wgsl/parser_impl_loop_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_loop_stmt_test.cc @@ -29,10 +29,10 @@ TEST_F(ParserImplTest, LoopStmt_BodyNoContinuing) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_EQ(e.value->body()->size(), 1u); - EXPECT_TRUE(e.value->body()->get(0)->IsDiscard()); + ASSERT_EQ(e->body()->size(), 1u); + EXPECT_TRUE(e->body()->get(0)->IsDiscard()); - EXPECT_EQ(e.value->continuing()->size(), 0u); + EXPECT_EQ(e->continuing()->size(), 0u); } TEST_F(ParserImplTest, LoopStmt_BodyWithContinuing) { @@ -43,11 +43,11 @@ TEST_F(ParserImplTest, LoopStmt_BodyWithContinuing) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_EQ(e.value->body()->size(), 1u); - EXPECT_TRUE(e.value->body()->get(0)->IsDiscard()); + ASSERT_EQ(e->body()->size(), 1u); + EXPECT_TRUE(e->body()->get(0)->IsDiscard()); - EXPECT_EQ(e.value->continuing()->size(), 1u); - EXPECT_TRUE(e.value->continuing()->get(0)->IsDiscard()); + EXPECT_EQ(e->continuing()->size(), 1u); + EXPECT_TRUE(e->continuing()->get(0)->IsDiscard()); } TEST_F(ParserImplTest, LoopStmt_NoBodyNoContinuing) { @@ -57,8 +57,8 @@ TEST_F(ParserImplTest, LoopStmt_NoBodyNoContinuing) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_EQ(e.value->body()->size(), 0u); - ASSERT_EQ(e.value->continuing()->size(), 0u); + ASSERT_EQ(e->body()->size(), 0u); + ASSERT_EQ(e->continuing()->size(), 0u); } TEST_F(ParserImplTest, LoopStmt_NoBodyWithContinuing) { @@ -68,9 +68,9 @@ TEST_F(ParserImplTest, LoopStmt_NoBodyWithContinuing) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_EQ(e.value->body()->size(), 0u); - ASSERT_EQ(e.value->continuing()->size(), 1u); - EXPECT_TRUE(e.value->continuing()->get(0)->IsDiscard()); + ASSERT_EQ(e->body()->size(), 0u); + ASSERT_EQ(e->continuing()->size(), 1u); + EXPECT_TRUE(e->continuing()->get(0)->IsDiscard()); } TEST_F(ParserImplTest, LoopStmt_MissingBracketLeft) { diff --git a/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc b/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc index d3110202d6..19936e9ebc 100644 --- a/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc +++ b/src/reader/wgsl/parser_impl_multiplicative_expression_test.cc @@ -33,8 +33,8 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Multiply) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kMultiply, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -56,8 +56,8 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Divide) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kDivide, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -79,8 +79,8 @@ TEST_F(ParserImplTest, MultiplicativeExpression_Parses_Modulo) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kModulo, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -120,7 +120,7 @@ TEST_F(ParserImplTest, MultiplicativeExpression_NoOr_ReturnsLHS) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIdentifier()); + ASSERT_TRUE(e->IsIdentifier()); } } // namespace diff --git a/src/reader/wgsl/parser_impl_paren_rhs_stmt_test.cc b/src/reader/wgsl/parser_impl_paren_rhs_stmt_test.cc index e55bc8900b..9cdcf4f51b 100644 --- a/src/reader/wgsl/parser_impl_paren_rhs_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_paren_rhs_stmt_test.cc @@ -27,7 +27,7 @@ TEST_F(ParserImplTest, ParenRhsStmt) { ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); + ASSERT_TRUE(e->IsBinary()); } TEST_F(ParserImplTest, ParenRhsStmt_MissingLeftParen) { diff --git a/src/reader/wgsl/parser_impl_postfix_expression_test.cc b/src/reader/wgsl/parser_impl_postfix_expression_test.cc index 952103b51f..90b5cfecba 100644 --- a/src/reader/wgsl/parser_impl_postfix_expression_test.cc +++ b/src/reader/wgsl/parser_impl_postfix_expression_test.cc @@ -36,8 +36,8 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ConstantIndex) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsArrayAccessor()); - auto* ary = e.value->AsArrayAccessor(); + ASSERT_TRUE(e->IsArrayAccessor()); + auto* ary = e->AsArrayAccessor(); ASSERT_TRUE(ary->array()->IsIdentifier()); auto* ident = ary->array()->AsIdentifier(); @@ -58,8 +58,8 @@ TEST_F(ParserImplTest, PostfixExpression_Array_ExpressionIndex) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsArrayAccessor()); - auto* ary = e.value->AsArrayAccessor(); + ASSERT_TRUE(e->IsArrayAccessor()); + auto* ary = e->AsArrayAccessor(); ASSERT_TRUE(ary->array()->IsIdentifier()); auto* ident = ary->array()->AsIdentifier(); @@ -106,8 +106,8 @@ TEST_F(ParserImplTest, PostfixExpression_Call_Empty) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsCall()); - auto* c = e.value->AsCall(); + ASSERT_TRUE(e->IsCall()); + auto* c = e->AsCall(); ASSERT_TRUE(c->func()->IsIdentifier()); auto* func = c->func()->AsIdentifier(); @@ -124,8 +124,8 @@ TEST_F(ParserImplTest, PostfixExpression_Call_WithArgs) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsCall()); - auto* c = e.value->AsCall(); + ASSERT_TRUE(e->IsCall()); + auto* c = e->AsCall(); ASSERT_TRUE(c->func()->IsIdentifier()); auto* func = c->func()->AsIdentifier(); @@ -174,9 +174,9 @@ TEST_F(ParserImplTest, PostfixExpression_MemberAccessor) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsMemberAccessor()); + ASSERT_TRUE(e->IsMemberAccessor()); - auto* m = e.value->AsMemberAccessor(); + auto* m = e->AsMemberAccessor(); ASSERT_TRUE(m->structure()->IsIdentifier()); EXPECT_EQ(m->structure()->AsIdentifier()->name(), "a"); @@ -211,7 +211,7 @@ TEST_F(ParserImplTest, PostfixExpression_NonMatch_returnLHS) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIdentifier()); + ASSERT_TRUE(e->IsIdentifier()); } } // namespace diff --git a/src/reader/wgsl/parser_impl_primary_expression_test.cc b/src/reader/wgsl/parser_impl_primary_expression_test.cc index 3ef055daf9..249105e3ce 100644 --- a/src/reader/wgsl/parser_impl_primary_expression_test.cc +++ b/src/reader/wgsl/parser_impl_primary_expression_test.cc @@ -39,8 +39,8 @@ TEST_F(ParserImplTest, PrimaryExpression_Ident) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIdentifier()); - auto* ident = e.value->AsIdentifier(); + ASSERT_TRUE(e->IsIdentifier()); + auto* ident = e->AsIdentifier(); EXPECT_EQ(ident->name(), "a"); } @@ -51,9 +51,9 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsConstructor()); - ASSERT_TRUE(e.value->AsConstructor()->IsTypeConstructor()); - auto* ty = e.value->AsConstructor()->AsTypeConstructor(); + ASSERT_TRUE(e->IsConstructor()); + ASSERT_TRUE(e->AsConstructor()->IsTypeConstructor()); + auto* ty = e->AsConstructor()->AsTypeConstructor(); ASSERT_EQ(ty->values().size(), 4u); const auto& val = ty->values(); @@ -89,9 +89,9 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_ZeroConstructor) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsConstructor()); - ASSERT_TRUE(e.value->AsConstructor()->IsTypeConstructor()); - auto* ty = e.value->AsConstructor()->AsTypeConstructor(); + ASSERT_TRUE(e->IsConstructor()); + ASSERT_TRUE(e->AsConstructor()->IsTypeConstructor()); + auto* ty = e->AsConstructor()->AsTypeConstructor(); ASSERT_EQ(ty->values().size(), 0u); } @@ -143,9 +143,9 @@ 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.value->IsConstructor()); - ASSERT_TRUE(e.value->AsConstructor()->IsScalarConstructor()); - auto* init = e.value->AsConstructor()->AsScalarConstructor(); + ASSERT_TRUE(e->IsConstructor()); + ASSERT_TRUE(e->AsConstructor()->IsScalarConstructor()); + auto* init = e->AsConstructor()->AsScalarConstructor(); ASSERT_TRUE(init->literal()->IsBool()); EXPECT_TRUE(init->literal()->AsBool()->IsTrue()); } @@ -157,7 +157,7 @@ TEST_F(ParserImplTest, PrimaryExpression_ParenExpr) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); + ASSERT_TRUE(e->IsBinary()); } TEST_F(ParserImplTest, PrimaryExpression_ParenExpr_MissingRightParen) { @@ -199,10 +199,10 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsConstructor()); - ASSERT_TRUE(e.value->AsConstructor()->IsTypeConstructor()); + ASSERT_TRUE(e->IsConstructor()); + ASSERT_TRUE(e->AsConstructor()->IsTypeConstructor()); - auto* c = e.value->AsConstructor()->AsTypeConstructor(); + auto* c = e->AsConstructor()->AsTypeConstructor(); ASSERT_EQ(c->type(), f32_type); ASSERT_EQ(c->values().size(), 1u); @@ -219,9 +219,9 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBitcast()); + ASSERT_TRUE(e->IsBitcast()); - auto* c = e.value->AsBitcast(); + auto* c = e->AsBitcast(); ASSERT_EQ(c->type(), f32_type); ASSERT_TRUE(c->expr()->IsConstructor()); diff --git a/src/reader/wgsl/parser_impl_relational_expression_test.cc b/src/reader/wgsl/parser_impl_relational_expression_test.cc index be712b961d..f679dd8929 100644 --- a/src/reader/wgsl/parser_impl_relational_expression_test.cc +++ b/src/reader/wgsl/parser_impl_relational_expression_test.cc @@ -33,8 +33,8 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThan) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kLessThan, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -56,8 +56,8 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThan) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kGreaterThan, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -79,8 +79,8 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_LessThanEqual) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kLessThanEqual, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -102,8 +102,8 @@ TEST_F(ParserImplTest, RelationalExpression_Parses_GreaterThanEqual) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kGreaterThanEqual, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -141,7 +141,7 @@ TEST_F(ParserImplTest, RelationalExpression_NoOr_ReturnsLHS) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIdentifier()); + ASSERT_TRUE(e->IsIdentifier()); } } // namespace diff --git a/src/reader/wgsl/parser_impl_sampler_type_test.cc b/src/reader/wgsl/parser_impl_sampler_type_test.cc index caf313ca67..d1c69ed243 100644 --- a/src/reader/wgsl/parser_impl_sampler_type_test.cc +++ b/src/reader/wgsl/parser_impl_sampler_type_test.cc @@ -37,8 +37,8 @@ TEST_F(ParserImplTest, SamplerType_Sampler) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsSampler()); - EXPECT_FALSE(t.value->AsSampler()->IsComparison()); + ASSERT_TRUE(t->IsSampler()); + EXPECT_FALSE(t->AsSampler()->IsComparison()); EXPECT_FALSE(p->has_error()); } @@ -48,8 +48,8 @@ TEST_F(ParserImplTest, SamplerType_ComparisonSampler) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsSampler()); - EXPECT_TRUE(t.value->AsSampler()->IsComparison()); + ASSERT_TRUE(t->IsSampler()); + EXPECT_TRUE(t->AsSampler()->IsComparison()); EXPECT_FALSE(p->has_error()); } diff --git a/src/reader/wgsl/parser_impl_shift_expression_test.cc b/src/reader/wgsl/parser_impl_shift_expression_test.cc index 2122bfd466..9118cfdc2e 100644 --- a/src/reader/wgsl/parser_impl_shift_expression_test.cc +++ b/src/reader/wgsl/parser_impl_shift_expression_test.cc @@ -33,8 +33,8 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftLeft) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kShiftLeft, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -56,8 +56,8 @@ TEST_F(ParserImplTest, ShiftExpression_Parses_ShiftRight) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsBinary()); - auto* rel = e.value->AsBinary(); + ASSERT_TRUE(e->IsBinary()); + auto* rel = e->AsBinary(); EXPECT_EQ(ast::BinaryOp::kShiftRight, rel->op()); ASSERT_TRUE(rel->lhs()->IsIdentifier()); @@ -97,7 +97,7 @@ TEST_F(ParserImplTest, ShiftExpression_NoOr_ReturnsLHS) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsIdentifier()); + ASSERT_TRUE(e->IsIdentifier()); } } // namespace diff --git a/src/reader/wgsl/parser_impl_statement_test.cc b/src/reader/wgsl/parser_impl_statement_test.cc index 57c5cb17b0..bdef0888d8 100644 --- a/src/reader/wgsl/parser_impl_statement_test.cc +++ b/src/reader/wgsl/parser_impl_statement_test.cc @@ -29,7 +29,7 @@ TEST_F(ParserImplTest, Statement) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsReturn()); + ASSERT_TRUE(e->IsReturn()); } TEST_F(ParserImplTest, Statement_Semicolon) { @@ -44,8 +44,8 @@ TEST_F(ParserImplTest, Statement_Return_NoValue) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsReturn()); - auto* ret = e.value->AsReturn(); + ASSERT_TRUE(e->IsReturn()); + auto* ret = e->AsReturn(); ASSERT_EQ(ret->value(), nullptr); } @@ -56,8 +56,8 @@ TEST_F(ParserImplTest, Statement_Return_Value) { EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsReturn()); - auto* ret = e.value->AsReturn(); + ASSERT_TRUE(e->IsReturn()); + auto* ret = e->AsReturn(); ASSERT_NE(ret->value(), nullptr); EXPECT_TRUE(ret->value()->IsBinary()); } @@ -88,7 +88,7 @@ TEST_F(ParserImplTest, Statement_If) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsIf()); + ASSERT_TRUE(e->IsIf()); } TEST_F(ParserImplTest, Statement_If_Invalid) { @@ -107,7 +107,7 @@ TEST_F(ParserImplTest, Statement_Variable) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsVariableDecl()); + ASSERT_TRUE(e->IsVariableDecl()); } TEST_F(ParserImplTest, Statement_Variable_Invalid) { @@ -136,7 +136,7 @@ TEST_F(ParserImplTest, Statement_Switch) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsSwitch()); + ASSERT_TRUE(e->IsSwitch()); } TEST_F(ParserImplTest, Statement_Switch_Invalid) { @@ -155,7 +155,7 @@ TEST_F(ParserImplTest, Statement_Loop) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsLoop()); + ASSERT_TRUE(e->IsLoop()); } TEST_F(ParserImplTest, Statement_Loop_Invalid) { @@ -174,7 +174,7 @@ TEST_F(ParserImplTest, Statement_Assignment) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsAssign()); + ASSERT_TRUE(e->IsAssign()); } TEST_F(ParserImplTest, Statement_Assignment_Invalid) { @@ -203,7 +203,7 @@ TEST_F(ParserImplTest, Statement_Break) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsBreak()); + ASSERT_TRUE(e->IsBreak()); } TEST_F(ParserImplTest, Statement_Break_MissingSemicolon) { @@ -222,7 +222,7 @@ TEST_F(ParserImplTest, Statement_Continue) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsContinue()); + ASSERT_TRUE(e->IsContinue()); } TEST_F(ParserImplTest, Statement_Continue_MissingSemicolon) { @@ -242,7 +242,7 @@ TEST_F(ParserImplTest, Statement_Discard) { ASSERT_NE(e.value, nullptr); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsDiscard()); + ASSERT_TRUE(e->IsDiscard()); } TEST_F(ParserImplTest, Statement_Discard_MissingSemicolon) { @@ -261,8 +261,8 @@ TEST_F(ParserImplTest, Statement_Body) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - ASSERT_TRUE(e.value->IsBlock()); - EXPECT_TRUE(e.value->AsBlock()->get(0)->IsVariableDecl()); + ASSERT_TRUE(e->IsBlock()); + EXPECT_TRUE(e->AsBlock()->get(0)->IsVariableDecl()); } TEST_F(ParserImplTest, Statement_Body_Invalid) { diff --git a/src/reader/wgsl/parser_impl_statements_test.cc b/src/reader/wgsl/parser_impl_statements_test.cc index c7417e9395..58cdc215bc 100644 --- a/src/reader/wgsl/parser_impl_statements_test.cc +++ b/src/reader/wgsl/parser_impl_statements_test.cc @@ -27,9 +27,9 @@ TEST_F(ParserImplTest, Statements) { auto e = p->expect_statements(); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); - ASSERT_EQ(e.value->size(), 2u); - EXPECT_TRUE(e.value->get(0)->IsDiscard()); - EXPECT_TRUE(e.value->get(1)->IsReturn()); + ASSERT_EQ(e->size(), 2u); + EXPECT_TRUE(e->get(0)->IsDiscard()); + EXPECT_TRUE(e->get(1)->IsReturn()); } TEST_F(ParserImplTest, Statements_Empty) { @@ -37,7 +37,7 @@ TEST_F(ParserImplTest, Statements_Empty) { auto e = p->expect_statements(); EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); - ASSERT_EQ(e.value->size(), 0u); + ASSERT_EQ(e->size(), 0u); } } // namespace diff --git a/src/reader/wgsl/parser_impl_struct_decl_test.cc b/src/reader/wgsl/parser_impl_struct_decl_test.cc index 81fac22f61..37c5f06451 100644 --- a/src/reader/wgsl/parser_impl_struct_decl_test.cc +++ b/src/reader/wgsl/parser_impl_struct_decl_test.cc @@ -38,10 +38,10 @@ struct S { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s.value->name(), "S"); - ASSERT_EQ(s.value->impl()->members().size(), 2u); - EXPECT_EQ(s.value->impl()->members()[0]->name(), "a"); - EXPECT_EQ(s.value->impl()->members()[1]->name(), "b"); + ASSERT_EQ(s->name(), "S"); + ASSERT_EQ(s->impl()->members().size(), 2u); + EXPECT_EQ(s->impl()->members()[0]->name(), "a"); + EXPECT_EQ(s->impl()->members()[1]->name(), "b"); } TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) { @@ -60,12 +60,12 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s.value->name(), "B"); - ASSERT_EQ(s.value->impl()->members().size(), 2u); - EXPECT_EQ(s.value->impl()->members()[0]->name(), "a"); - EXPECT_EQ(s.value->impl()->members()[1]->name(), "b"); - ASSERT_EQ(s.value->impl()->decorations().size(), 1u); - EXPECT_TRUE(s.value->impl()->decorations()[0]->IsBlock()); + ASSERT_EQ(s->name(), "B"); + ASSERT_EQ(s->impl()->members().size(), 2u); + EXPECT_EQ(s->impl()->members()[0]->name(), "a"); + EXPECT_EQ(s->impl()->members()[1]->name(), "b"); + ASSERT_EQ(s->impl()->decorations().size(), 1u); + EXPECT_TRUE(s->impl()->decorations()[0]->IsBlock()); } TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) { @@ -85,13 +85,13 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s.value->name(), "S"); - ASSERT_EQ(s.value->impl()->members().size(), 2u); - EXPECT_EQ(s.value->impl()->members()[0]->name(), "a"); - EXPECT_EQ(s.value->impl()->members()[1]->name(), "b"); - ASSERT_EQ(s.value->impl()->decorations().size(), 2u); - EXPECT_TRUE(s.value->impl()->decorations()[0]->IsBlock()); - EXPECT_TRUE(s.value->impl()->decorations()[1]->IsBlock()); + ASSERT_EQ(s->name(), "S"); + ASSERT_EQ(s->impl()->members().size(), 2u); + EXPECT_EQ(s->impl()->members()[0]->name(), "a"); + EXPECT_EQ(s->impl()->members()[1]->name(), "b"); + ASSERT_EQ(s->impl()->decorations().size(), 2u); + EXPECT_TRUE(s->impl()->decorations()[0]->IsBlock()); + EXPECT_TRUE(s->impl()->decorations()[1]->IsBlock()); } TEST_F(ParserImplTest, StructDecl_EmptyMembers) { @@ -106,7 +106,7 @@ TEST_F(ParserImplTest, StructDecl_EmptyMembers) { EXPECT_FALSE(s.errored); EXPECT_TRUE(s.matched); ASSERT_NE(s.value, nullptr); - ASSERT_EQ(s.value->impl()->members().size(), 0u); + ASSERT_EQ(s->impl()->members().size(), 0u); } TEST_F(ParserImplTest, StructDecl_MissingIdent) { diff --git a/src/reader/wgsl/parser_impl_struct_member_test.cc b/src/reader/wgsl/parser_impl_struct_member_test.cc index b63ee50fcd..d8c3fe7432 100644 --- a/src/reader/wgsl/parser_impl_struct_member_test.cc +++ b/src/reader/wgsl/parser_impl_struct_member_test.cc @@ -38,14 +38,14 @@ TEST_F(ParserImplTest, StructMember_Parses) { ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m.value->name(), "a"); - EXPECT_EQ(m.value->type(), i32); - EXPECT_EQ(m.value->decorations().size(), 0u); + EXPECT_EQ(m->name(), "a"); + EXPECT_EQ(m->type(), i32); + EXPECT_EQ(m->decorations().size(), 0u); - ASSERT_EQ(m.value->source().range.begin.line, 1u); - ASSERT_EQ(m.value->source().range.begin.column, 1u); - ASSERT_EQ(m.value->source().range.end.line, 1u); - ASSERT_EQ(m.value->source().range.end.column, 2u); + ASSERT_EQ(m->source().range.begin.line, 1u); + ASSERT_EQ(m->source().range.begin.column, 1u); + ASSERT_EQ(m->source().range.end.line, 1u); + ASSERT_EQ(m->source().range.end.column, 2u); } TEST_F(ParserImplTest, StructMember_ParsesWithDecoration) { @@ -62,16 +62,16 @@ TEST_F(ParserImplTest, StructMember_ParsesWithDecoration) { ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m.value->name(), "a"); - EXPECT_EQ(m.value->type(), i32); - EXPECT_EQ(m.value->decorations().size(), 1u); - EXPECT_TRUE(m.value->decorations()[0]->IsOffset()); - EXPECT_EQ(m.value->decorations()[0]->AsOffset()->offset(), 2u); + EXPECT_EQ(m->name(), "a"); + EXPECT_EQ(m->type(), i32); + EXPECT_EQ(m->decorations().size(), 1u); + EXPECT_TRUE(m->decorations()[0]->IsOffset()); + EXPECT_EQ(m->decorations()[0]->AsOffset()->offset(), 2u); - ASSERT_EQ(m.value->source().range.begin.line, 1u); - ASSERT_EQ(m.value->source().range.begin.column, 15u); - ASSERT_EQ(m.value->source().range.end.line, 1u); - ASSERT_EQ(m.value->source().range.end.column, 16u); + ASSERT_EQ(m->source().range.begin.line, 1u); + ASSERT_EQ(m->source().range.begin.column, 15u); + ASSERT_EQ(m->source().range.end.line, 1u); + ASSERT_EQ(m->source().range.end.column, 16u); } TEST_F(ParserImplTest, StructMember_ParsesWithMultipleDecorations) { @@ -89,18 +89,18 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleDecorations) { ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m.value->name(), "a"); - EXPECT_EQ(m.value->type(), i32); - EXPECT_EQ(m.value->decorations().size(), 2u); - EXPECT_TRUE(m.value->decorations()[0]->IsOffset()); - EXPECT_EQ(m.value->decorations()[0]->AsOffset()->offset(), 2u); - EXPECT_TRUE(m.value->decorations()[1]->IsOffset()); - EXPECT_EQ(m.value->decorations()[1]->AsOffset()->offset(), 4u); + EXPECT_EQ(m->name(), "a"); + EXPECT_EQ(m->type(), i32); + EXPECT_EQ(m->decorations().size(), 2u); + EXPECT_TRUE(m->decorations()[0]->IsOffset()); + EXPECT_EQ(m->decorations()[0]->AsOffset()->offset(), 2u); + EXPECT_TRUE(m->decorations()[1]->IsOffset()); + EXPECT_EQ(m->decorations()[1]->AsOffset()->offset(), 4u); - ASSERT_EQ(m.value->source().range.begin.line, 2u); - ASSERT_EQ(m.value->source().range.begin.column, 15u); - ASSERT_EQ(m.value->source().range.end.line, 2u); - ASSERT_EQ(m.value->source().range.end.column, 16u); + ASSERT_EQ(m->source().range.begin.line, 2u); + ASSERT_EQ(m->source().range.begin.column, 15u); + ASSERT_EQ(m->source().range.end.line, 2u); + ASSERT_EQ(m->source().range.end.column, 16u); } TEST_F(ParserImplTest, StructMember_InvalidDecoration) { diff --git a/src/reader/wgsl/parser_impl_switch_body_test.cc b/src/reader/wgsl/parser_impl_switch_body_test.cc index 69af79f323..ae2f1b7d64 100644 --- a/src/reader/wgsl/parser_impl_switch_body_test.cc +++ b/src/reader/wgsl/parser_impl_switch_body_test.cc @@ -29,10 +29,10 @@ TEST_F(ParserImplTest, SwitchBody_Case) { EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsCase()); - EXPECT_FALSE(e.value->IsDefault()); - ASSERT_EQ(e.value->body()->size(), 1u); - EXPECT_TRUE(e.value->body()->get(0)->IsAssign()); + ASSERT_TRUE(e->IsCase()); + EXPECT_FALSE(e->IsDefault()); + ASSERT_EQ(e->body()->size(), 1u); + EXPECT_TRUE(e->body()->get(0)->IsAssign()); } TEST_F(ParserImplTest, SwitchBody_Case_InvalidConstLiteral) { @@ -112,10 +112,10 @@ TEST_F(ParserImplTest, SwitchBody_Default) { EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsCase()); - EXPECT_TRUE(e.value->IsDefault()); - ASSERT_EQ(e.value->body()->size(), 1u); - EXPECT_TRUE(e.value->body()->get(0)->IsAssign()); + ASSERT_TRUE(e->IsCase()); + EXPECT_TRUE(e->IsDefault()); + ASSERT_EQ(e->body()->size(), 1u); + EXPECT_TRUE(e->body()->get(0)->IsAssign()); } TEST_F(ParserImplTest, SwitchBody_Default_MissingColon) { diff --git a/src/reader/wgsl/parser_impl_switch_stmt_test.cc b/src/reader/wgsl/parser_impl_switch_stmt_test.cc index d0ea352979..85a5a97d15 100644 --- a/src/reader/wgsl/parser_impl_switch_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_switch_stmt_test.cc @@ -33,10 +33,10 @@ TEST_F(ParserImplTest, SwitchStmt_WithoutDefault) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsSwitch()); - ASSERT_EQ(e.value->body().size(), 2u); - EXPECT_FALSE(e.value->body()[0]->IsDefault()); - EXPECT_FALSE(e.value->body()[1]->IsDefault()); + ASSERT_TRUE(e->IsSwitch()); + ASSERT_EQ(e->body().size(), 2u); + EXPECT_FALSE(e->body()[0]->IsDefault()); + EXPECT_FALSE(e->body()[1]->IsDefault()); } TEST_F(ParserImplTest, SwitchStmt_Empty) { @@ -46,8 +46,8 @@ TEST_F(ParserImplTest, SwitchStmt_Empty) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsSwitch()); - ASSERT_EQ(e.value->body().size(), 0u); + ASSERT_TRUE(e->IsSwitch()); + ASSERT_EQ(e->body().size(), 0u); } TEST_F(ParserImplTest, SwitchStmt_DefaultInMiddle) { @@ -61,12 +61,12 @@ TEST_F(ParserImplTest, SwitchStmt_DefaultInMiddle) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsSwitch()); + ASSERT_TRUE(e->IsSwitch()); - ASSERT_EQ(e.value->body().size(), 3u); - ASSERT_FALSE(e.value->body()[0]->IsDefault()); - ASSERT_TRUE(e.value->body()[1]->IsDefault()); - ASSERT_FALSE(e.value->body()[2]->IsDefault()); + ASSERT_EQ(e->body().size(), 3u); + ASSERT_FALSE(e->body()[0]->IsDefault()); + ASSERT_TRUE(e->body()[1]->IsDefault()); + ASSERT_FALSE(e->body()[2]->IsDefault()); } TEST_F(ParserImplTest, SwitchStmt_InvalidExpression) { diff --git a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc index b040fadcd6..29137718b2 100644 --- a/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc +++ b/src/reader/wgsl/parser_impl_texture_sampler_types_test.cc @@ -40,8 +40,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_Sampler) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsSampler()); - ASSERT_FALSE(t.value->AsSampler()->IsComparison()); + ASSERT_TRUE(t->IsSampler()); + ASSERT_FALSE(t->AsSampler()->IsComparison()); } TEST_F(ParserImplTest, TextureSamplerTypes_SamplerComparison) { @@ -51,8 +51,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SamplerComparison) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsSampler()); - ASSERT_TRUE(t.value->AsSampler()->IsComparison()); + ASSERT_TRUE(t->IsSampler()); + ASSERT_TRUE(t->AsSampler()->IsComparison()); } TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) { @@ -62,9 +62,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsDepth()); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsDepth()); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32_Old) { @@ -74,10 +74,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32_Old) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsSampled()); - ASSERT_TRUE(t.value->AsTexture()->AsSampled()->type()->IsF32()); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k1d); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsSampled()); + ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsF32()); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32_Old) { @@ -87,10 +87,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32_Old) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsSampled()); - ASSERT_TRUE(t.value->AsTexture()->AsSampled()->type()->IsI32()); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsSampled()); + ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsI32()); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32_Old) { @@ -100,10 +100,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32_Old) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsSampled()); - ASSERT_TRUE(t.value->AsTexture()->AsSampled()->type()->IsU32()); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k3d); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsSampled()); + ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsU32()); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k3d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid_Old) { @@ -154,10 +154,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsSampled()); - ASSERT_TRUE(t.value->AsTexture()->AsSampled()->type()->IsF32()); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k1d); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsSampled()); + ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsF32()); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) { @@ -167,10 +167,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsSampled()); - ASSERT_TRUE(t.value->AsTexture()->AsSampled()->type()->IsI32()); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsSampled()); + ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsI32()); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { @@ -180,10 +180,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsSampled()); - ASSERT_TRUE(t.value->AsTexture()->AsSampled()->type()->IsU32()); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k3d); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsSampled()); + ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsU32()); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k3d); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_Invalid) { @@ -233,10 +233,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsMultisampled()); - ASSERT_TRUE(t.value->AsTexture()->AsMultisampled()->type()->IsI32()); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k2d); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsMultisampled()); + ASSERT_TRUE(t->AsTexture()->AsMultisampled()->type()->IsI32()); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_Invalid) { @@ -287,13 +287,13 @@ TEST_F(ParserImplTest, EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsStorage()); - EXPECT_EQ(t.value->AsTexture()->AsStorage()->image_format(), + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsStorage()); + EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(), ast::type::ImageFormat::kR8Unorm); - EXPECT_EQ(t.value->AsTexture()->AsStorage()->access(), + EXPECT_EQ(t->AsTexture()->AsStorage()->access(), ast::AccessControl::kReadOnly); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k1d); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d); } TEST_F(ParserImplTest, @@ -304,13 +304,13 @@ TEST_F(ParserImplTest, EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsStorage()); - EXPECT_EQ(t.value->AsTexture()->AsStorage()->image_format(), + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsStorage()); + EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(), ast::type::ImageFormat::kR16Float); - EXPECT_EQ(t.value->AsTexture()->AsStorage()->access(), + EXPECT_EQ(t->AsTexture()->AsStorage()->access(), ast::AccessControl::kWriteOnly); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k2d); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType_Old) { @@ -357,13 +357,13 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dR8Unorm) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsStorage()); - EXPECT_EQ(t.value->AsTexture()->AsStorage()->image_format(), + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsStorage()); + EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(), ast::type::ImageFormat::kR8Unorm); - EXPECT_EQ(t.value->AsTexture()->AsStorage()->access(), + EXPECT_EQ(t->AsTexture()->AsStorage()->access(), ast::AccessControl::kReadOnly); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k1d); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k1d); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) { @@ -373,13 +373,13 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR16Float) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsStorage()); - EXPECT_EQ(t.value->AsTexture()->AsStorage()->image_format(), + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsStorage()); + EXPECT_EQ(t->AsTexture()->AsStorage()->image_format(), ast::type::ImageFormat::kR16Float); - EXPECT_EQ(t.value->AsTexture()->AsStorage()->access(), + EXPECT_EQ(t->AsTexture()->AsStorage()->access(), ast::AccessControl::kWriteOnly); - EXPECT_EQ(t.value->AsTexture()->dim(), ast::type::TextureDimension::k2d); + EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType) { diff --git a/src/reader/wgsl/parser_impl_type_alias_test.cc b/src/reader/wgsl/parser_impl_type_alias_test.cc index df97a4cca1..cbfb7a101a 100644 --- a/src/reader/wgsl/parser_impl_type_alias_test.cc +++ b/src/reader/wgsl/parser_impl_type_alias_test.cc @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) { EXPECT_FALSE(t.errored); EXPECT_TRUE(t.matched); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsAlias()); - auto* alias = t.value->AsAlias(); + ASSERT_TRUE(t->IsAlias()); + auto* alias = t->AsAlias(); ASSERT_TRUE(alias->type()->IsI32()); ASSERT_EQ(alias->type(), i32); } @@ -52,8 +52,8 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) { EXPECT_FALSE(t.errored); EXPECT_TRUE(t.matched); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->IsAlias()); - auto* alias = t.value->AsAlias(); + ASSERT_TRUE(t->IsAlias()); + auto* alias = t->AsAlias(); EXPECT_EQ(alias->name(), "a"); ASSERT_TRUE(alias->type()->IsStruct()); diff --git a/src/reader/wgsl/parser_impl_type_decl_test.cc b/src/reader/wgsl/parser_impl_type_decl_test.cc index f0cc10df52..a3d6eae192 100644 --- a/src/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/reader/wgsl/parser_impl_type_decl_test.cc @@ -59,9 +59,9 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, alias_type); - ASSERT_TRUE(t.value->IsAlias()); + ASSERT_TRUE(t->IsAlias()); - auto* alias = t.value->AsAlias(); + auto* alias = t->AsAlias(); EXPECT_EQ(alias->name(), "A"); EXPECT_EQ(alias->type(), int_type); } @@ -87,7 +87,7 @@ TEST_F(ParserImplTest, TypeDecl_Bool) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, bool_type); - ASSERT_TRUE(t.value->IsBool()); + ASSERT_TRUE(t->IsBool()); } TEST_F(ParserImplTest, TypeDecl_F32) { @@ -100,7 +100,7 @@ TEST_F(ParserImplTest, TypeDecl_F32) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, float_type); - ASSERT_TRUE(t.value->IsF32()); + ASSERT_TRUE(t->IsF32()); } TEST_F(ParserImplTest, TypeDecl_I32) { @@ -113,7 +113,7 @@ TEST_F(ParserImplTest, TypeDecl_I32) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, int_type); - ASSERT_TRUE(t.value->IsI32()); + ASSERT_TRUE(t->IsI32()); } TEST_F(ParserImplTest, TypeDecl_U32) { @@ -126,7 +126,7 @@ TEST_F(ParserImplTest, TypeDecl_U32) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, uint_type); - ASSERT_TRUE(t.value->IsU32()); + ASSERT_TRUE(t->IsU32()); } struct VecData { @@ -148,8 +148,8 @@ TEST_P(VecTest, Parse) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - EXPECT_TRUE(t.value->IsVector()); - EXPECT_EQ(t.value->AsVector()->size(), params.count); + EXPECT_TRUE(t->IsVector()); + EXPECT_EQ(t->AsVector()->size(), params.count); } INSTANTIATE_TEST_SUITE_P(ParserImplTest, VecTest, @@ -236,9 +236,9 @@ TEST_F(ParserImplTest, TypeDecl_Ptr) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->IsPointer()); + ASSERT_TRUE(t->IsPointer()); - auto* ptr = t.value->AsPointer(); + auto* ptr = t->AsPointer(); ASSERT_TRUE(ptr->type()->IsF32()); ASSERT_EQ(ptr->storage_class(), ast::StorageClass::kFunction); } @@ -250,9 +250,9 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_ToVec) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->IsPointer()); + ASSERT_TRUE(t->IsPointer()); - auto* ptr = t.value->AsPointer(); + auto* ptr = t->AsPointer(); ASSERT_TRUE(ptr->type()->IsVector()); ASSERT_EQ(ptr->storage_class(), ast::StorageClass::kFunction); @@ -348,9 +348,9 @@ TEST_F(ParserImplTest, TypeDecl_Array) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->IsArray()); + ASSERT_TRUE(t->IsArray()); - auto* a = t.value->AsArray(); + auto* a = t->AsArray(); ASSERT_FALSE(a->IsRuntimeArray()); ASSERT_EQ(a->size(), 5u); ASSERT_TRUE(a->type()->IsF32()); @@ -364,9 +364,9 @@ TEST_F(ParserImplTest, TypeDecl_Array_Stride) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->IsArray()); + ASSERT_TRUE(t->IsArray()); - auto* a = t.value->AsArray(); + auto* a = t->AsArray(); ASSERT_FALSE(a->IsRuntimeArray()); ASSERT_EQ(a->size(), 5u); ASSERT_TRUE(a->type()->IsF32()); @@ -381,9 +381,9 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Stride) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->IsArray()); + ASSERT_TRUE(t->IsArray()); - auto* a = t.value->AsArray(); + auto* a = t->AsArray(); ASSERT_TRUE(a->IsRuntimeArray()); ASSERT_TRUE(a->type()->IsF32()); ASSERT_TRUE(a->has_array_stride()); @@ -397,9 +397,9 @@ TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_OneBlock) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->IsArray()); + ASSERT_TRUE(t->IsArray()); - auto* a = t.value->AsArray(); + auto* a = t->AsArray(); ASSERT_TRUE(a->IsRuntimeArray()); ASSERT_TRUE(a->type()->IsF32()); @@ -418,9 +418,9 @@ TEST_F(ParserImplTest, TypeDecl_Array_MultipleDecorations_MultipleBlocks) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->IsArray()); + ASSERT_TRUE(t->IsArray()); - auto* a = t.value->AsArray(); + auto* a = t->AsArray(); ASSERT_TRUE(a->IsRuntimeArray()); ASSERT_TRUE(a->type()->IsF32()); @@ -521,9 +521,9 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->IsArray()); + ASSERT_TRUE(t->IsArray()); - auto* a = t.value->AsArray(); + auto* a = t->AsArray(); ASSERT_TRUE(a->IsRuntimeArray()); ASSERT_TRUE(a->type()->IsU32()); } @@ -618,8 +618,8 @@ TEST_P(MatrixTest, Parse) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - EXPECT_TRUE(t.value->IsMatrix()); - auto* mat = t.value->AsMatrix(); + EXPECT_TRUE(t->IsMatrix()); + auto* mat = t->AsMatrix(); EXPECT_EQ(mat->rows(), params.rows); EXPECT_EQ(mat->columns(), params.columns); } @@ -743,8 +743,8 @@ TEST_F(ParserImplTest, TypeDecl_Sampler) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, type); - ASSERT_TRUE(t.value->IsSampler()); - ASSERT_FALSE(t.value->AsSampler()->IsComparison()); + ASSERT_TRUE(t->IsSampler()); + ASSERT_FALSE(t->AsSampler()->IsComparison()); } TEST_F(ParserImplTest, TypeDecl_Texture_Old) { @@ -759,9 +759,9 @@ TEST_F(ParserImplTest, TypeDecl_Texture_Old) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); EXPECT_EQ(t.value, type); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsSampled()); - ASSERT_TRUE(t.value->AsTexture()->AsSampled()->type()->IsF32()); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsSampled()); + ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsF32()); } TEST_F(ParserImplTest, TypeDecl_Texture) { @@ -776,9 +776,9 @@ TEST_F(ParserImplTest, TypeDecl_Texture) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); EXPECT_EQ(t.value, type); - ASSERT_TRUE(t.value->IsTexture()); - ASSERT_TRUE(t.value->AsTexture()->IsSampled()); - ASSERT_TRUE(t.value->AsTexture()->AsSampled()->type()->IsF32()); + ASSERT_TRUE(t->IsTexture()); + ASSERT_TRUE(t->AsTexture()->IsSampled()); + ASSERT_TRUE(t->AsTexture()->AsSampled()->type()->IsF32()); } } // namespace diff --git a/src/reader/wgsl/parser_impl_unary_expression_test.cc b/src/reader/wgsl/parser_impl_unary_expression_test.cc index d9c645cfeb..57787cabff 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) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsArrayAccessor()); - auto* ary = e.value->AsArrayAccessor(); + ASSERT_TRUE(e->IsArrayAccessor()); + auto* ary = e->AsArrayAccessor(); ASSERT_TRUE(ary->array()->IsIdentifier()); auto* ident = ary->array()->AsIdentifier(); EXPECT_EQ(ident->name(), "a"); @@ -54,9 +54,9 @@ TEST_F(ParserImplTest, UnaryExpression_Minus) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsUnaryOp()); + ASSERT_TRUE(e->IsUnaryOp()); - auto* u = e.value->AsUnaryOp(); + auto* u = e->AsUnaryOp(); ASSERT_EQ(u->op(), ast::UnaryOp::kNegation); ASSERT_TRUE(u->expr()->IsConstructor()); @@ -84,9 +84,9 @@ TEST_F(ParserImplTest, UnaryExpression_Bang) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsUnaryOp()); + ASSERT_TRUE(e->IsUnaryOp()); - auto* u = e.value->AsUnaryOp(); + auto* u = e->AsUnaryOp(); ASSERT_EQ(u->op(), ast::UnaryOp::kNot); ASSERT_TRUE(u->expr()->IsConstructor()); diff --git a/src/reader/wgsl/parser_impl_variable_decl_test.cc b/src/reader/wgsl/parser_impl_variable_decl_test.cc index 3ff51ac1dc..f84f0d9e87 100644 --- a/src/reader/wgsl/parser_impl_variable_decl_test.cc +++ b/src/reader/wgsl/parser_impl_variable_decl_test.cc @@ -29,14 +29,14 @@ TEST_F(ParserImplTest, VariableDecl_Parses) { EXPECT_TRUE(var.matched); EXPECT_FALSE(var.errored); ASSERT_NE(var.value, nullptr); - EXPECT_EQ(var.value->name(), "my_var"); - EXPECT_NE(var.value->type(), nullptr); - EXPECT_TRUE(var.value->type()->IsF32()); + EXPECT_EQ(var->name(), "my_var"); + EXPECT_NE(var->type(), nullptr); + EXPECT_TRUE(var->type()->IsF32()); - EXPECT_EQ(var.value->source().range.begin.line, 1u); - EXPECT_EQ(var.value->source().range.begin.column, 5u); - EXPECT_EQ(var.value->source().range.end.line, 1u); - EXPECT_EQ(var.value->source().range.end.column, 11u); + EXPECT_EQ(var->source().range.begin.line, 1u); + EXPECT_EQ(var->source().range.begin.column, 5u); + EXPECT_EQ(var->source().range.end.line, 1u); + EXPECT_EQ(var->source().range.end.column, 11u); } TEST_F(ParserImplTest, VariableDecl_MissingVar) { @@ -68,14 +68,14 @@ TEST_F(ParserImplTest, VariableDecl_WithStorageClass) { EXPECT_FALSE(v.errored); EXPECT_FALSE(p->has_error()); ASSERT_NE(v.value, nullptr); - EXPECT_EQ(v.value->name(), "my_var"); - EXPECT_TRUE(v.value->type()->IsF32()); - EXPECT_EQ(v.value->storage_class(), ast::StorageClass::kPrivate); + EXPECT_EQ(v->name(), "my_var"); + EXPECT_TRUE(v->type()->IsF32()); + EXPECT_EQ(v->storage_class(), ast::StorageClass::kPrivate); - EXPECT_EQ(v.value->source().range.begin.line, 1u); - EXPECT_EQ(v.value->source().range.begin.column, 14u); - EXPECT_EQ(v.value->source().range.end.line, 1u); - EXPECT_EQ(v.value->source().range.end.column, 20u); + EXPECT_EQ(v->source().range.begin.line, 1u); + EXPECT_EQ(v->source().range.begin.column, 14u); + EXPECT_EQ(v->source().range.end.line, 1u); + EXPECT_EQ(v->source().range.end.column, 20u); } TEST_F(ParserImplTest, VariableDecl_InvalidStorageClass) { diff --git a/src/reader/wgsl/parser_impl_variable_stmt_test.cc b/src/reader/wgsl/parser_impl_variable_stmt_test.cc index a0fba9582d..20a966c709 100644 --- a/src/reader/wgsl/parser_impl_variable_stmt_test.cc +++ b/src/reader/wgsl/parser_impl_variable_stmt_test.cc @@ -30,16 +30,16 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsVariableDecl()); - ASSERT_NE(e.value->variable(), nullptr); - EXPECT_EQ(e.value->variable()->name(), "a"); + ASSERT_TRUE(e->IsVariableDecl()); + ASSERT_NE(e->variable(), nullptr); + EXPECT_EQ(e->variable()->name(), "a"); - ASSERT_EQ(e.value->source().range.begin.line, 1u); - ASSERT_EQ(e.value->source().range.begin.column, 5u); - ASSERT_EQ(e.value->source().range.end.line, 1u); - ASSERT_EQ(e.value->source().range.end.column, 6u); + ASSERT_EQ(e->source().range.begin.line, 1u); + ASSERT_EQ(e->source().range.begin.column, 5u); + ASSERT_EQ(e->source().range.end.line, 1u); + ASSERT_EQ(e->source().range.end.column, 6u); - EXPECT_EQ(e.value->variable()->constructor(), nullptr); + EXPECT_EQ(e->variable()->constructor(), nullptr); } TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) { @@ -49,17 +49,17 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsVariableDecl()); - ASSERT_NE(e.value->variable(), nullptr); - EXPECT_EQ(e.value->variable()->name(), "a"); + ASSERT_TRUE(e->IsVariableDecl()); + ASSERT_NE(e->variable(), nullptr); + EXPECT_EQ(e->variable()->name(), "a"); - ASSERT_EQ(e.value->source().range.begin.line, 1u); - ASSERT_EQ(e.value->source().range.begin.column, 5u); - ASSERT_EQ(e.value->source().range.end.line, 1u); - ASSERT_EQ(e.value->source().range.end.column, 6u); + ASSERT_EQ(e->source().range.begin.line, 1u); + ASSERT_EQ(e->source().range.begin.column, 5u); + ASSERT_EQ(e->source().range.end.line, 1u); + ASSERT_EQ(e->source().range.end.column, 6u); - ASSERT_NE(e.value->variable()->constructor(), nullptr); - EXPECT_TRUE(e.value->variable()->constructor()->IsConstructor()); + ASSERT_NE(e->variable()->constructor(), nullptr); + EXPECT_TRUE(e->variable()->constructor()->IsConstructor()); } TEST_F(ParserImplTest, VariableStmt_VariableDecl_Invalid) { @@ -89,12 +89,12 @@ TEST_F(ParserImplTest, VariableStmt_Const) { EXPECT_FALSE(e.errored); EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); - ASSERT_TRUE(e.value->IsVariableDecl()); + ASSERT_TRUE(e->IsVariableDecl()); - ASSERT_EQ(e.value->source().range.begin.line, 1u); - ASSERT_EQ(e.value->source().range.begin.column, 7u); - ASSERT_EQ(e.value->source().range.end.line, 1u); - ASSERT_EQ(e.value->source().range.end.column, 8u); + ASSERT_EQ(e->source().range.begin.line, 1u); + ASSERT_EQ(e->source().range.begin.column, 7u); + ASSERT_EQ(e->source().range.end.line, 1u); + ASSERT_EQ(e->source().range.end.column, 8u); } TEST_F(ParserImplTest, VariableStmt_Const_InvalidVarIdent) {