From 1523f5c2765ce01ea7e079acf5c605472a378aac Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 14 Dec 2020 22:30:57 +0000 Subject: [PATCH] Start cleaning up tests (3/N) Remove Source{} with ast::Builder::create<> Use Builder helpers where possible Change-Id: I7b3188fa8239bf11e88ff6b396a57c23d76a3152 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35660 Reviewed-by: dan sinclair Commit-Queue: Ben Clayton --- BUILD.gn | 1 + src/CMakeLists.txt | 1 + src/ast/access_decoration_test.cc | 14 +- src/ast/array_accessor_expression_test.cc | 87 ++- src/ast/assignment_statement_test.cc | 87 ++- src/ast/binary_expression_test.cc | 100 ++-- src/ast/binding_decoration_test.cc | 11 +- src/ast/bitcast_expression_test.cc | 64 +-- src/ast/block_statement_test.cc | 56 +- src/ast/bool_literal_test.cc | 27 +- src/ast/break_statement_test.cc | 16 +- src/ast/builder.cc | 20 +- src/ast/builder.h | 14 + src/ast/builtin_decoration_test.cc | 13 +- src/ast/call_expression_test.cc | 94 ++-- src/ast/call_statement_test.cc | 44 +- src/ast/case_statement_test.cc | 165 +++--- src/ast/clone_context.h | 2 +- src/ast/constant_id_decoration_test.cc | 11 +- src/ast/continue_statement_test.cc | 16 +- src/ast/decoration_test.cc | 6 +- src/ast/discard_statement_test.cc | 32 +- src/ast/else_statement_test.cc | 114 ++-- src/ast/expression_test.cc | 19 +- src/ast/fallthrough_statement_test.cc | 26 +- src/ast/float_literal_test.cc | 21 +- src/ast/function_test.cc | 501 +++++++----------- src/ast/identifier_expression_test.cc | 28 +- src/ast/if_statement_test.cc | 262 +++++---- src/ast/int_literal_test.cc | 10 +- src/ast/location_decoration_test.cc | 11 +- src/ast/loop_statement_test.cc | 169 +++--- src/ast/member_accessor_expression_test.cc | 94 ++-- src/ast/module_test.cc | 42 +- src/ast/null_literal_test.cc | 14 +- src/ast/return_statement_test.cc | 55 +- src/ast/scalar_constructor_expression_test.cc | 29 +- src/ast/set_decoration_test.cc | 11 +- src/ast/sint_literal_test.cc | 25 +- src/ast/stage_decoration_test.cc | 11 +- src/ast/stride_decoration_test.cc | 20 +- .../struct_member_offset_decoration_test.cc | 8 +- src/ast/struct_member_test.cc | 75 ++- src/ast/struct_test.cc | 99 ++-- src/ast/switch_statement_test.cc | 138 ++--- src/ast/test_helper.h | 19 +- src/ast/type/access_control_type_test.cc | 36 +- src/ast/type/alias_type_test.cc | 86 +-- src/ast/type/array_type_test.cc | 15 +- src/ast/type/storage_texture_type_test.cc | 27 +- src/ast/type/struct_type_test.cc | 163 +++--- src/ast/type_constructor_expression_test.cc | 81 ++- src/ast/uint_literal_test.cc | 16 +- src/ast/unary_op_expression_test.cc | 49 +- src/ast/variable_decl_statement_test.cc | 54 +- src/ast/variable_test.cc | 153 +++--- src/ast/workgroup_decoration_test.cc | 19 +- 57 files changed, 1486 insertions(+), 1895 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index d59faf4da7..01684a9472 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -750,6 +750,7 @@ config("tint_unittests_config") { source_set("tint_unittests_core_src") { sources = [ + "src/ast/access_decoration_test.cc", "src/ast/array_accessor_expression_test.cc", "src/ast/assignment_statement_test.cc", "src/ast/binary_expression_test.cc", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a063afd22..1a7c6a452b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -387,6 +387,7 @@ endif() if(${TINT_BUILD_TESTS}) set(TINT_TEST_SRCS + ast/access_decoration_test.cc ast/array_accessor_expression_test.cc ast/assignment_statement_test.cc ast/binding_decoration_test.cc diff --git a/src/ast/access_decoration_test.cc b/src/ast/access_decoration_test.cc index 36c030dfaf..55295fcebc 100644 --- a/src/ast/access_decoration_test.cc +++ b/src/ast/access_decoration_test.cc @@ -25,20 +25,20 @@ namespace { using AccessDecorationTest = TestHelper; TEST_F(AccessDecorationTest, Creation) { - AccessDecoration d{ast::AccessControl::kWriteOnly, Source{}}; - EXPECT_EQ(ast::AccessControl::kWriteOnly, d.value()); + auto* d = create(ast::AccessControl::kWriteOnly); + EXPECT_EQ(ast::AccessControl::kWriteOnly, d->value()); } TEST_F(AccessDecorationTest, Is) { - AccessDecoration d{ast::AccessControl::kReadWrite, Source{}}; - EXPECT_FALSE(d.IsAccess()); + auto* d = create(ast::AccessControl::kReadWrite); + EXPECT_TRUE(d->Is()); } TEST_F(AccessDecorationTest, ToStr) { - AccessDecoration d{ast::AccessControl::kReadOnly, Source{}}; + auto* d = create(ast::AccessControl::kReadOnly); std::ostringstream out; - d.to_str(out, 0); - EXPECT_EQ(out.str(), R"(AccessDecoration{read} + d->to_str(out, 0); + EXPECT_EQ(out.str(), R"(AccessDecoration{read_only} )"); } diff --git a/src/ast/array_accessor_expression_test.cc b/src/ast/array_accessor_expression_test.cc index 1de44354b4..be29266afb 100644 --- a/src/ast/array_accessor_expression_test.cc +++ b/src/ast/array_accessor_expression_test.cc @@ -24,91 +24,76 @@ namespace { using ArrayAccessorExpressionTest = TestHelper; TEST_F(ArrayAccessorExpressionTest, Create) { - auto* ary = - create(Source{}, mod.RegisterSymbol("ary"), "ary"); - auto* idx = - create(Source{}, mod.RegisterSymbol("idx"), "idx"); + auto* ary = Expr("ary"); + auto* idx = Expr("idx"); - ArrayAccessorExpression exp(Source{}, ary, idx); - ASSERT_EQ(exp.array(), ary); - ASSERT_EQ(exp.idx_expr(), idx); + auto* exp = create(ary, idx); + ASSERT_EQ(exp->array(), ary); + ASSERT_EQ(exp->idx_expr(), idx); } TEST_F(ArrayAccessorExpressionTest, CreateWithSource) { - auto* ary = - create(Source{}, mod.RegisterSymbol("ary"), "ary"); - auto* idx = - create(Source{}, mod.RegisterSymbol("idx"), "idx"); + auto* ary = Expr("ary"); + auto* idx = Expr("idx"); - ArrayAccessorExpression exp(Source{Source::Location{20, 2}}, ary, idx); - auto src = exp.source(); + auto* exp = create(Source{Source::Location{20, 2}}, + ary, idx); + auto src = exp->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) { - auto* ary = - create(Source{}, mod.RegisterSymbol("ary"), "ary"); - auto* idx = - create(Source{}, mod.RegisterSymbol("idx"), "idx"); + auto* ary = Expr("ary"); + auto* idx = Expr("idx"); - ArrayAccessorExpression exp(Source{}, ary, idx); - EXPECT_TRUE(exp.Is()); + auto* exp = create(ary, idx); + EXPECT_TRUE(exp->Is()); } TEST_F(ArrayAccessorExpressionTest, IsValid) { - auto* ary = - create(Source{}, mod.RegisterSymbol("ary"), "ary"); - auto* idx = - create(Source{}, mod.RegisterSymbol("idx"), "idx"); + auto* ary = Expr("ary"); + auto* idx = Expr("idx"); - ArrayAccessorExpression exp(Source{}, ary, idx); - EXPECT_TRUE(exp.IsValid()); + auto* exp = create(ary, idx); + EXPECT_TRUE(exp->IsValid()); } TEST_F(ArrayAccessorExpressionTest, IsValid_MissingArray) { - auto* idx = - create(Source{}, mod.RegisterSymbol("idx"), "idx"); + auto* idx = Expr("idx"); - ArrayAccessorExpression exp(Source{}, nullptr, idx); - EXPECT_FALSE(exp.IsValid()); + auto* exp = create(nullptr, idx); + EXPECT_FALSE(exp->IsValid()); } TEST_F(ArrayAccessorExpressionTest, IsValid_MissingIndex) { - auto* ary = - create(Source{}, mod.RegisterSymbol("ary"), "ary"); + auto* ary = Expr("ary"); - ArrayAccessorExpression exp(Source{}, ary, nullptr); - EXPECT_FALSE(exp.IsValid()); + auto* exp = create(ary, nullptr); + EXPECT_FALSE(exp->IsValid()); } TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidArray) { - auto* ary = - create(Source{}, mod.RegisterSymbol(""), ""); - auto* idx = - create(Source{}, mod.RegisterSymbol("idx"), "idx"); - ArrayAccessorExpression exp(Source{}, ary, idx); - EXPECT_FALSE(exp.IsValid()); + auto* ary = Expr(""); + auto* idx = Expr("idx"); + auto* exp = create(ary, idx); + EXPECT_FALSE(exp->IsValid()); } TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidIndex) { - auto* ary = - create(Source{}, mod.RegisterSymbol("ary"), "ary"); - auto* idx = - create(Source{}, mod.RegisterSymbol(""), ""); - ArrayAccessorExpression exp(Source{}, ary, idx); - EXPECT_FALSE(exp.IsValid()); + auto* ary = Expr("ary"); + auto* idx = Expr(""); + auto* exp = create(ary, idx); + EXPECT_FALSE(exp->IsValid()); } TEST_F(ArrayAccessorExpressionTest, ToStr) { - auto* ary = - create(Source{}, mod.RegisterSymbol("ary"), "ary"); - auto* idx = - create(Source{}, mod.RegisterSymbol("idx"), "idx"); + auto* ary = Expr("ary"); + auto* idx = Expr("idx"); - ArrayAccessorExpression exp(Source{}, ary, idx); + auto* exp = create(ary, idx); std::ostringstream out; - exp.to_str(out, 2); + exp->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( ArrayAccessor[not set]{ Identifier[not set]{ary} diff --git a/src/ast/assignment_statement_test.cc b/src/ast/assignment_statement_test.cc index 951e32c148..2d7055d65f 100644 --- a/src/ast/assignment_statement_test.cc +++ b/src/ast/assignment_statement_test.cc @@ -24,91 +24,76 @@ namespace { using AssignmentStatementTest = TestHelper; TEST_F(AssignmentStatementTest, Creation) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* lhs = Expr("lhs"); + auto* rhs = Expr("rhs"); - AssignmentStatement stmt(Source{}, lhs, rhs); - EXPECT_EQ(stmt.lhs(), lhs); - EXPECT_EQ(stmt.rhs(), rhs); + auto* stmt = create(lhs, rhs); + EXPECT_EQ(stmt->lhs(), lhs); + EXPECT_EQ(stmt->rhs(), rhs); } TEST_F(AssignmentStatementTest, CreationWithSource) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* lhs = Expr("lhs"); + auto* rhs = Expr("rhs"); - AssignmentStatement stmt(Source{Source::Location{20, 2}}, lhs, rhs); - auto src = stmt.source(); + auto* stmt = + create(Source{Source::Location{20, 2}}, lhs, rhs); + auto src = stmt->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(AssignmentStatementTest, IsAssign) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* lhs = Expr("lhs"); + auto* rhs = Expr("rhs"); - AssignmentStatement stmt(Source{}, lhs, rhs); - EXPECT_TRUE(stmt.Is()); + auto* stmt = create(lhs, rhs); + EXPECT_TRUE(stmt->Is()); } TEST_F(AssignmentStatementTest, IsValid) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* lhs = Expr("lhs"); + auto* rhs = Expr("rhs"); - AssignmentStatement stmt(Source{}, lhs, rhs); - EXPECT_TRUE(stmt.IsValid()); + auto* stmt = create(lhs, rhs); + EXPECT_TRUE(stmt->IsValid()); } TEST_F(AssignmentStatementTest, IsValid_MissingLHS) { - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* rhs = Expr("rhs"); - AssignmentStatement stmt(Source{}, nullptr, rhs); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(nullptr, rhs); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(AssignmentStatementTest, IsValid_MissingRHS) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); + auto* lhs = Expr("lhs"); - AssignmentStatement stmt(Source{}, lhs, nullptr); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(lhs, nullptr); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(AssignmentStatementTest, IsValid_InvalidLHS) { - auto* lhs = - create(Source{}, mod.RegisterSymbol(""), ""); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); - AssignmentStatement stmt(Source{}, lhs, rhs); - EXPECT_FALSE(stmt.IsValid()); + auto* lhs = Expr(""); + auto* rhs = Expr("rhs"); + auto* stmt = create(lhs, rhs); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(AssignmentStatementTest, IsValid_InvalidRHS) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol(""), ""); - AssignmentStatement stmt(Source{}, lhs, rhs); - EXPECT_FALSE(stmt.IsValid()); + auto* lhs = Expr("lhs"); + auto* rhs = Expr(""); + auto* stmt = create(lhs, rhs); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(AssignmentStatementTest, ToStr) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* lhs = Expr("lhs"); + auto* rhs = Expr("rhs"); - AssignmentStatement stmt(Source{}, lhs, rhs); + auto* stmt = create(lhs, rhs); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Assignment{ Identifier[not set]{lhs} diff --git a/src/ast/binary_expression_test.cc b/src/ast/binary_expression_test.cc index 4758a25d2e..432bc45fc2 100644 --- a/src/ast/binary_expression_test.cc +++ b/src/ast/binary_expression_test.cc @@ -26,105 +26,87 @@ namespace { using BinaryExpressionTest = TestHelper; TEST_F(BinaryExpressionTest, Creation) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* lhs = Expr("lhs"); + auto* rhs = Expr("rhs"); - BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, rhs); - EXPECT_EQ(r.lhs(), lhs); - EXPECT_EQ(r.rhs(), rhs); - EXPECT_EQ(r.op(), BinaryOp::kEqual); + auto* r = create(BinaryOp::kEqual, lhs, rhs); + EXPECT_EQ(r->lhs(), lhs); + EXPECT_EQ(r->rhs(), rhs); + EXPECT_EQ(r->op(), BinaryOp::kEqual); } TEST_F(BinaryExpressionTest, Creation_WithSource) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* lhs = Expr("lhs"); + auto* rhs = Expr("rhs"); - BinaryExpression r(Source{Source::Location{20, 2}}, BinaryOp::kEqual, lhs, - rhs); - auto src = r.source(); + auto* r = create(Source{Source::Location{20, 2}}, + BinaryOp::kEqual, lhs, rhs); + auto src = r->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(BinaryExpressionTest, IsBinary) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* lhs = Expr("lhs"); + auto* rhs = Expr("rhs"); - BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, rhs); - EXPECT_TRUE(r.Is()); + auto* r = create(BinaryOp::kEqual, lhs, rhs); + EXPECT_TRUE(r->Is()); } TEST_F(BinaryExpressionTest, IsValid) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* lhs = Expr("lhs"); + auto* rhs = Expr("rhs"); - BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, rhs); - EXPECT_TRUE(r.IsValid()); + auto* r = create(BinaryOp::kEqual, lhs, rhs); + EXPECT_TRUE(r->IsValid()); } TEST_F(BinaryExpressionTest, IsValid_Null_LHS) { - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* rhs = Expr("rhs"); - BinaryExpression r(Source{}, BinaryOp::kEqual, nullptr, rhs); - EXPECT_FALSE(r.IsValid()); + auto* r = create(BinaryOp::kEqual, nullptr, rhs); + EXPECT_FALSE(r->IsValid()); } TEST_F(BinaryExpressionTest, IsValid_Invalid_LHS) { - auto* lhs = - create(Source{}, mod.RegisterSymbol(""), ""); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* lhs = Expr(""); + auto* rhs = Expr("rhs"); - BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, rhs); - EXPECT_FALSE(r.IsValid()); + auto* r = create(BinaryOp::kEqual, lhs, rhs); + EXPECT_FALSE(r->IsValid()); } TEST_F(BinaryExpressionTest, IsValid_Null_RHS) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); + auto* lhs = Expr("lhs"); - BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, nullptr); - EXPECT_FALSE(r.IsValid()); + auto* r = create(BinaryOp::kEqual, lhs, nullptr); + EXPECT_FALSE(r->IsValid()); } TEST_F(BinaryExpressionTest, IsValid_Invalid_RHS) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol(""), ""); + auto* lhs = Expr("lhs"); + auto* rhs = Expr(""); - BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, rhs); - EXPECT_FALSE(r.IsValid()); + auto* r = create(BinaryOp::kEqual, lhs, rhs); + EXPECT_FALSE(r->IsValid()); } TEST_F(BinaryExpressionTest, IsValid_Binary_None) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* lhs = Expr("lhs"); + auto* rhs = Expr("rhs"); - BinaryExpression r(Source{}, BinaryOp::kNone, lhs, rhs); - EXPECT_FALSE(r.IsValid()); + auto* r = create(BinaryOp::kNone, lhs, rhs); + EXPECT_FALSE(r->IsValid()); } TEST_F(BinaryExpressionTest, ToStr) { - auto* lhs = - create(Source{}, mod.RegisterSymbol("lhs"), "lhs"); - auto* rhs = - create(Source{}, mod.RegisterSymbol("rhs"), "rhs"); + auto* lhs = Expr("lhs"); + auto* rhs = Expr("rhs"); - BinaryExpression r(Source{}, BinaryOp::kEqual, lhs, rhs); + auto* r = create(BinaryOp::kEqual, lhs, rhs); std::ostringstream out; - r.to_str(out, 2); + r->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Binary[not set]{ Identifier[not set]{lhs} equal diff --git a/src/ast/binding_decoration_test.cc b/src/ast/binding_decoration_test.cc index 58242360e6..08cde4c28b 100644 --- a/src/ast/binding_decoration_test.cc +++ b/src/ast/binding_decoration_test.cc @@ -24,13 +24,12 @@ namespace { using BindingDecorationTest = TestHelper; TEST_F(BindingDecorationTest, Creation) { - BindingDecoration d{Source{}, 2}; - EXPECT_EQ(2u, d.value()); + auto* d = create(2); + EXPECT_EQ(2u, d->value()); } TEST_F(BindingDecorationTest, Is) { - BindingDecoration bd{Source{}, 2}; - Decoration* d = &bd; + Decoration* d = create(2); EXPECT_TRUE(d->Is()); EXPECT_FALSE(d->Is()); EXPECT_FALSE(d->Is()); @@ -39,9 +38,9 @@ TEST_F(BindingDecorationTest, Is) { } TEST_F(BindingDecorationTest, ToStr) { - BindingDecoration d{Source{}, 2}; + auto* d = create(2); std::ostringstream out; - d.to_str(out, 0); + d->to_str(out, 0); EXPECT_EQ(out.str(), R"(BindingDecoration{2} )"); } diff --git a/src/ast/bitcast_expression_test.cc b/src/ast/bitcast_expression_test.cc index 21d88323f2..dcbd7748b4 100644 --- a/src/ast/bitcast_expression_test.cc +++ b/src/ast/bitcast_expression_test.cc @@ -25,75 +25,61 @@ namespace { using BitcastExpressionTest = TestHelper; TEST_F(BitcastExpressionTest, Create) { - type::F32 f32; - auto* expr = create(Source{}, - mod.RegisterSymbol("expr"), "expr"); + auto* expr = Expr("expr"); - BitcastExpression exp(Source{}, &f32, expr); - ASSERT_EQ(exp.type(), &f32); - ASSERT_EQ(exp.expr(), expr); + auto* exp = create(ty.f32, expr); + ASSERT_EQ(exp->type(), ty.f32); + ASSERT_EQ(exp->expr(), expr); } TEST_F(BitcastExpressionTest, CreateWithSource) { - type::F32 f32; - auto* expr = create(Source{}, - mod.RegisterSymbol("expr"), "expr"); + auto* expr = Expr("expr"); - BitcastExpression exp(Source{Source::Location{20, 2}}, &f32, expr); - auto src = exp.source(); + auto* exp = + create(Source{Source::Location{20, 2}}, ty.f32, expr); + auto src = exp->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(BitcastExpressionTest, IsBitcast) { - type::F32 f32; - auto* expr = create(Source{}, - mod.RegisterSymbol("expr"), "expr"); + auto* expr = Expr("expr"); - BitcastExpression exp(Source{}, &f32, expr); - EXPECT_TRUE(exp.Is()); + auto* exp = create(ty.f32, expr); + EXPECT_TRUE(exp->Is()); } TEST_F(BitcastExpressionTest, IsValid) { - type::F32 f32; - auto* expr = create(Source{}, - mod.RegisterSymbol("expr"), "expr"); + auto* expr = Expr("expr"); - BitcastExpression exp(Source{}, &f32, expr); - EXPECT_TRUE(exp.IsValid()); + auto* exp = create(ty.f32, expr); + EXPECT_TRUE(exp->IsValid()); } TEST_F(BitcastExpressionTest, IsValid_MissingType) { - auto* expr = create(Source{}, - mod.RegisterSymbol("expr"), "expr"); + auto* expr = Expr("expr"); - BitcastExpression exp(Source{}, nullptr, expr); - EXPECT_FALSE(exp.IsValid()); + auto* exp = create(nullptr, expr); + EXPECT_FALSE(exp->IsValid()); } TEST_F(BitcastExpressionTest, IsValid_MissingExpr) { - type::F32 f32; - - BitcastExpression exp(Source{}, &f32, nullptr); - EXPECT_FALSE(exp.IsValid()); + auto* exp = create(ty.f32, nullptr); + EXPECT_FALSE(exp->IsValid()); } TEST_F(BitcastExpressionTest, IsValid_InvalidExpr) { - type::F32 f32; - auto* expr = - create(Source{}, mod.RegisterSymbol(""), ""); - BitcastExpression e(Source{}, &f32, expr); - EXPECT_FALSE(e.IsValid()); + auto* expr = Expr(""); + auto* e = create(ty.f32, expr); + EXPECT_FALSE(e->IsValid()); } TEST_F(BitcastExpressionTest, ToStr) { - type::F32 f32; - auto* expr = create(Source{}, - mod.RegisterSymbol("expr"), "expr"); + auto* expr = Expr("expr"); - BitcastExpression exp(Source{}, &f32, expr); + auto* exp = create(ty.f32, expr); std::ostringstream out; - exp.to_str(out, 2); + exp->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Bitcast[not set]<__f32>{ Identifier[not set]{expr} diff --git a/src/ast/block_statement_test.cc b/src/ast/block_statement_test.cc index 78134c6ca3..02c536ef61 100644 --- a/src/ast/block_statement_test.cc +++ b/src/ast/block_statement_test.cc @@ -28,66 +28,66 @@ namespace { using BlockStatementTest = TestHelper; TEST_F(BlockStatementTest, Creation) { - auto* d = create(Source{}); + auto* d = create(); auto* ptr = d; - BlockStatement b(Source{}, StatementList{d}); + auto* b = create(StatementList{d}); - ASSERT_EQ(b.size(), 1u); - EXPECT_EQ(b[0], ptr); + ASSERT_EQ(b->size(), 1u); + EXPECT_EQ((*b)[0], ptr); } TEST_F(BlockStatementTest, Creation_WithSource) { - BlockStatement b(Source{Source::Location{20, 2}}, ast::StatementList{}); - auto src = b.source(); + auto* b = create(Source{Source::Location{20, 2}}, + ast::StatementList{}); + auto src = b->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(BlockStatementTest, IsBlock) { - BlockStatement b(Source{}, ast::StatementList{}); - EXPECT_TRUE(b.Is()); + auto* b = create(ast::StatementList{}); + EXPECT_TRUE(b->Is()); } TEST_F(BlockStatementTest, IsValid) { - BlockStatement b(Source{}, ast::StatementList{ - create(Source{}), - }); - EXPECT_TRUE(b.IsValid()); + auto* b = create(ast::StatementList{ + create(), + }); + EXPECT_TRUE(b->IsValid()); } TEST_F(BlockStatementTest, IsValid_Empty) { - BlockStatement b(Source{}, ast::StatementList{}); - EXPECT_TRUE(b.IsValid()); + auto* b = create(ast::StatementList{}); + EXPECT_TRUE(b->IsValid()); } TEST_F(BlockStatementTest, IsValid_NullBodyStatement) { - BlockStatement b(Source{}, ast::StatementList{ - create(Source{}), - nullptr, - }); + auto* b = create(ast::StatementList{ + create(), + nullptr, + }); - EXPECT_FALSE(b.IsValid()); + EXPECT_FALSE(b->IsValid()); } TEST_F(BlockStatementTest, IsValid_InvalidBodyStatement) { - BlockStatement b( - Source{}, + auto* b = create( + ast::StatementList{ - create(Source{}, nullptr, - create(Source{}, StatementList{}), + create(nullptr, create(StatementList{}), ElseStatementList{}), }); - EXPECT_FALSE(b.IsValid()); + EXPECT_FALSE(b->IsValid()); } TEST_F(BlockStatementTest, ToStr) { - BlockStatement b(Source{}, ast::StatementList{ - create(Source{}), - }); + auto* b = create(ast::StatementList{ + create(), + }); std::ostringstream out; - b.to_str(out, 2); + b->to_str(out, 2); EXPECT_EQ(out.str(), R"( Block{ Discard{} } diff --git a/src/ast/bool_literal_test.cc b/src/ast/bool_literal_test.cc index d98f98891d..97a9d5d10c 100644 --- a/src/ast/bool_literal_test.cc +++ b/src/ast/bool_literal_test.cc @@ -29,24 +29,23 @@ using BoolLiteralTest = TestHelper; TEST_F(BoolLiteralTest, True) { type::Bool bool_type; - BoolLiteral b{Source{}, &bool_type, true}; - ASSERT_TRUE(b.Is()); - ASSERT_TRUE(b.IsTrue()); - ASSERT_FALSE(b.IsFalse()); + auto* b = create(&bool_type, true); + ASSERT_TRUE(b->Is()); + ASSERT_TRUE(b->IsTrue()); + ASSERT_FALSE(b->IsFalse()); } TEST_F(BoolLiteralTest, False) { type::Bool bool_type; - BoolLiteral b{Source{}, &bool_type, false}; - ASSERT_TRUE(b.Is()); - ASSERT_FALSE(b.IsTrue()); - ASSERT_TRUE(b.IsFalse()); + auto* b = create(&bool_type, false); + ASSERT_TRUE(b->Is()); + ASSERT_FALSE(b->IsTrue()); + ASSERT_TRUE(b->IsFalse()); } TEST_F(BoolLiteralTest, Is) { type::Bool bool_type; - BoolLiteral b{Source{}, &bool_type, false}; - Literal* l = &b; + ast::Literal* l = create(&bool_type, false); EXPECT_TRUE(l->Is()); EXPECT_FALSE(l->Is()); EXPECT_FALSE(l->Is()); @@ -57,11 +56,11 @@ TEST_F(BoolLiteralTest, Is) { TEST_F(BoolLiteralTest, ToStr) { type::Bool bool_type; - BoolLiteral t{Source{}, &bool_type, true}; - BoolLiteral f{Source{}, &bool_type, false}; + auto* t = create(&bool_type, true); + auto* f = create(&bool_type, false); - EXPECT_EQ(t.to_str(), "true"); - EXPECT_EQ(f.to_str(), "false"); + EXPECT_EQ(t->to_str(), "true"); + EXPECT_EQ(f->to_str(), "false"); } } // namespace diff --git a/src/ast/break_statement_test.cc b/src/ast/break_statement_test.cc index 27a7a8f3e0..10063a4648 100644 --- a/src/ast/break_statement_test.cc +++ b/src/ast/break_statement_test.cc @@ -23,26 +23,26 @@ namespace { using BreakStatementTest = TestHelper; TEST_F(BreakStatementTest, Creation_WithSource) { - BreakStatement stmt(Source{Source::Location{20, 2}}); - auto src = stmt.source(); + auto* stmt = create(Source{Source::Location{20, 2}}); + auto src = stmt->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(BreakStatementTest, IsBreak) { - BreakStatement stmt(Source{}); - EXPECT_TRUE(stmt.Is()); + auto* stmt = create(); + EXPECT_TRUE(stmt->Is()); } TEST_F(BreakStatementTest, IsValid) { - BreakStatement stmt(Source{}); - EXPECT_TRUE(stmt.IsValid()); + auto* stmt = create(); + EXPECT_TRUE(stmt->IsValid()); } TEST_F(BreakStatementTest, ToStr) { - BreakStatement stmt(Source{}); + auto* stmt = create(); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(out.str(), R"( Break{} )"); } diff --git a/src/ast/builder.cc b/src/ast/builder.cc index 2c7479cf3b..f9b96a7563 100644 --- a/src/ast/builder.cc +++ b/src/ast/builder.cc @@ -40,8 +40,20 @@ Variable* Builder::Var(const std::string& name, type::Type* type, Expression* constructor, VariableDecorationList decorations) { - auto* var = create(Source{}, name, storage, type, false, - constructor, decorations); + auto* var = + create(name, storage, type, false, constructor, decorations); + OnVariableBuilt(var); + return var; +} + +Variable* Builder::Var(const Source& source, + const std::string& name, + StorageClass storage, + type::Type* type, + Expression* constructor, + VariableDecorationList decorations) { + auto* var = create(source, name, storage, type, false, constructor, + decorations); OnVariableBuilt(var); return var; } @@ -57,8 +69,8 @@ Variable* Builder::Const(const std::string& name, type::Type* type, Expression* constructor, VariableDecorationList decorations) { - auto* var = create(Source{}, name, storage, type, true, constructor, - decorations); + auto* var = + create(name, storage, type, true, constructor, decorations); OnVariableBuilt(var); return var; } diff --git a/src/ast/builder.h b/src/ast/builder.h index 254bd1f3b4..42efe59e64 100644 --- a/src/ast/builder.h +++ b/src/ast/builder.h @@ -464,6 +464,20 @@ class Builder { Expression* constructor, VariableDecorationList decorations); + /// @param source the variable source + /// @param name the variable name + /// @param storage the variable storage class + /// @param type the variable type + /// @param constructor constructor expression + /// @param decorations variable decorations + /// @returns a `Variable` with the given name, storage and type + Variable* Var(const Source& source, + const std::string& name, + StorageClass storage, + type::Type* type, + Expression* constructor, + VariableDecorationList decorations); + /// @param name the variable name /// @param storage the variable storage class /// @param type the variable type diff --git a/src/ast/builtin_decoration_test.cc b/src/ast/builtin_decoration_test.cc index 0618f652be..bee20b4678 100644 --- a/src/ast/builtin_decoration_test.cc +++ b/src/ast/builtin_decoration_test.cc @@ -8,7 +8,7 @@ // // 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. +// 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. @@ -24,13 +24,12 @@ namespace { using BuiltinDecorationTest = TestHelper; TEST_F(BuiltinDecorationTest, Creation) { - BuiltinDecoration d{Source{}, Builtin::kFragDepth}; - EXPECT_EQ(Builtin::kFragDepth, d.value()); + auto* d = create(Builtin::kFragDepth); + EXPECT_EQ(Builtin::kFragDepth, d->value()); } TEST_F(BuiltinDecorationTest, Is) { - BuiltinDecoration bd{Source{}, Builtin::kFragDepth}; - Decoration* d = &bd; + Decoration* d = create(Builtin::kFragDepth); EXPECT_FALSE(d->Is()); EXPECT_TRUE(d->Is()); EXPECT_FALSE(d->Is()); @@ -39,9 +38,9 @@ TEST_F(BuiltinDecorationTest, Is) { } TEST_F(BuiltinDecorationTest, ToStr) { - BuiltinDecoration d{Source{}, Builtin::kFragDepth}; + auto* d = create(Builtin::kFragDepth); std::ostringstream out; - d.to_str(out, 0); + d->to_str(out, 0); EXPECT_EQ(out.str(), R"(BuiltinDecoration{frag_depth} )"); } diff --git a/src/ast/call_expression_test.cc b/src/ast/call_expression_test.cc index 08e832405f..8769a52bc3 100644 --- a/src/ast/call_expression_test.cc +++ b/src/ast/call_expression_test.cc @@ -24,93 +24,80 @@ namespace { using CallExpressionTest = TestHelper; TEST_F(CallExpressionTest, Creation) { - auto* func = create(Source{}, - mod.RegisterSymbol("func"), "func"); + auto* func = Expr("func"); ExpressionList params; - params.push_back(create( - Source{}, mod.RegisterSymbol("param1"), "param1")); - params.push_back(create( - Source{}, mod.RegisterSymbol("param2"), "param2")); + params.push_back(Expr("param1")); + params.push_back(Expr("param2")); - CallExpression stmt(Source{}, func, params); - EXPECT_EQ(stmt.func(), func); + auto* stmt = create(func, params); + EXPECT_EQ(stmt->func(), func); - const auto& vec = stmt.params(); + const auto& vec = stmt->params(); ASSERT_EQ(vec.size(), 2u); EXPECT_EQ(vec[0], params[0]); EXPECT_EQ(vec[1], params[1]); } TEST_F(CallExpressionTest, Creation_WithSource) { - auto* func = create(Source{}, - mod.RegisterSymbol("func"), "func"); - CallExpression stmt(Source{Source::Location{20, 2}}, func, {}); - auto src = stmt.source(); + auto* func = Expr("func"); + auto* stmt = create(Source{Source::Location{20, 2}}, func, + ExpressionList{}); + auto src = stmt->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(CallExpressionTest, IsCall) { - auto* func = create(Source{}, - mod.RegisterSymbol("func"), "func"); - CallExpression stmt(Source{}, func, {}); - EXPECT_TRUE(stmt.Is()); + auto* func = Expr("func"); + auto* stmt = create(func, ExpressionList{}); + EXPECT_TRUE(stmt->Is()); } TEST_F(CallExpressionTest, IsValid) { - auto* func = create(Source{}, - mod.RegisterSymbol("func"), "func"); - CallExpression stmt(Source{}, func, {}); - EXPECT_TRUE(stmt.IsValid()); + auto* func = Expr("func"); + auto* stmt = create(func, ExpressionList{}); + EXPECT_TRUE(stmt->IsValid()); } TEST_F(CallExpressionTest, IsValid_MissingFunction) { - CallExpression stmt(Source{}, nullptr, {}); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(nullptr, ExpressionList{}); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(CallExpressionTest, IsValid_NullParam) { - auto* func = create(Source{}, - mod.RegisterSymbol("func"), "func"); + auto* func = Expr("func"); ExpressionList params; - params.push_back(create( - Source{}, mod.RegisterSymbol("param1"), "param1")); + params.push_back(Expr("param1")); params.push_back(nullptr); - params.push_back(create( - Source{}, mod.RegisterSymbol("param2"), "param2")); + params.push_back(Expr("param2")); - CallExpression stmt(Source{}, func, params); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(func, params); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(CallExpressionTest, IsValid_InvalidFunction) { - auto* func = - create(Source{}, mod.RegisterSymbol(""), ""); + auto* func = Expr(""); ExpressionList params; - params.push_back(create( - Source{}, mod.RegisterSymbol("param1"), "param1")); + params.push_back(Expr("param1")); - CallExpression stmt(Source{}, func, params); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(func, params); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(CallExpressionTest, IsValid_InvalidParam) { - auto* func = create(Source{}, - mod.RegisterSymbol("func"), "func"); + auto* func = Expr("func"); ExpressionList params; - params.push_back( - create(Source{}, mod.RegisterSymbol(""), "")); + params.push_back(Expr("")); - CallExpression stmt(Source{}, func, params); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(func, params); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(CallExpressionTest, ToStr_NoParams) { - auto* func = create(Source{}, - mod.RegisterSymbol("func"), "func"); - CallExpression stmt(Source{}, func, {}); + auto* func = Expr("func"); + auto* stmt = create(func, ExpressionList{}); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Call[not set]{ Identifier[not set]{func} ( @@ -120,17 +107,14 @@ TEST_F(CallExpressionTest, ToStr_NoParams) { } TEST_F(CallExpressionTest, ToStr_WithParams) { - auto* func = create(Source{}, - mod.RegisterSymbol("func"), "func"); + auto* func = Expr("func"); ExpressionList params; - params.push_back(create( - Source{}, mod.RegisterSymbol("param1"), "param1")); - params.push_back(create( - Source{}, mod.RegisterSymbol("param2"), "param2")); + params.push_back(Expr("param1")); + params.push_back(Expr("param2")); - CallExpression stmt(Source{}, func, params); + auto* stmt = create(func, params); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Call[not set]{ Identifier[not set]{func} ( diff --git a/src/ast/call_statement_test.cc b/src/ast/call_statement_test.cc index b6fcee2a0d..a9545e2f81 100644 --- a/src/ast/call_statement_test.cc +++ b/src/ast/call_statement_test.cc @@ -25,52 +25,40 @@ namespace { using CallStatementTest = TestHelper; TEST_F(CallStatementTest, Creation) { - auto* expr = - create(Source{}, - create( - Source{}, mod.RegisterSymbol("func"), "func"), - ExpressionList{}); + auto* expr = create(Expr("func"), ExpressionList{}); - CallStatement c(Source{}, expr); - EXPECT_EQ(c.expr(), expr); + auto* c = create(expr); + EXPECT_EQ(c->expr(), expr); } TEST_F(CallStatementTest, IsCall) { - CallStatement c(Source{}, nullptr); - EXPECT_TRUE(c.Is()); + auto* c = create(nullptr); + EXPECT_TRUE(c->Is()); } TEST_F(CallStatementTest, IsValid) { - CallStatement c( - Source{}, - create(Source{}, - create( - Source{}, mod.RegisterSymbol("func"), "func"), - ExpressionList{})); - EXPECT_TRUE(c.IsValid()); + auto* c = create( + create(Expr("func"), ExpressionList{})); + EXPECT_TRUE(c->IsValid()); } TEST_F(CallStatementTest, IsValid_MissingExpr) { - CallStatement c(Source{}, nullptr); - EXPECT_FALSE(c.IsValid()); + auto* c = create(nullptr); + EXPECT_FALSE(c->IsValid()); } TEST_F(CallStatementTest, IsValid_InvalidExpr) { - CallExpression stmt(Source{}, nullptr, {}); - CallStatement c(Source{}, &stmt); - EXPECT_FALSE(c.IsValid()); + auto* c = create( + create(nullptr, ast::ExpressionList{})); + EXPECT_FALSE(c->IsValid()); } TEST_F(CallStatementTest, ToStr) { - CallStatement c( - Source{}, - create(Source{}, - create( - Source{}, mod.RegisterSymbol("func"), "func"), - ExpressionList{})); + auto* c = create( + create(Expr("func"), ExpressionList{})); std::ostringstream out; - c.to_str(out, 2); + c->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Call[not set]{ Identifier[not set]{func} ( diff --git a/src/ast/case_statement_test.cc b/src/ast/case_statement_test.cc index 95714ad8bb..ce858dfc3b 100644 --- a/src/ast/case_statement_test.cc +++ b/src/ast/case_statement_test.cc @@ -29,128 +29,113 @@ namespace { using CaseStatementTest = TestHelper; TEST_F(CaseStatementTest, Creation_i32) { - type::I32 i32; - CaseSelectorList b; - auto* selector = create(Source{}, &i32, 2); + auto* selector = create(ty.i32, 2); b.push_back(selector); - auto* discard = create(Source{}); - auto* body = create(Source{}, StatementList{discard}); + auto* discard = create(); + auto* body = create(StatementList{discard}); - CaseStatement c(Source{}, b, body); - ASSERT_EQ(c.selectors().size(), 1u); - EXPECT_EQ(c.selectors()[0], selector); - ASSERT_EQ(c.body()->size(), 1u); - EXPECT_EQ(c.body()->get(0), discard); + auto* c = create(b, body); + ASSERT_EQ(c->selectors().size(), 1u); + EXPECT_EQ(c->selectors()[0], selector); + ASSERT_EQ(c->body()->size(), 1u); + EXPECT_EQ(c->body()->get(0), discard); } TEST_F(CaseStatementTest, Creation_u32) { - type::U32 u32; - CaseSelectorList b; - auto* selector = create(Source{}, &u32, 2); + auto* selector = create(ty.u32, 2); b.push_back(selector); - auto* discard = create(Source{}); - auto* body = create(Source{}, StatementList{discard}); + auto* discard = create(); + auto* body = create(StatementList{discard}); - CaseStatement c(Source{}, b, body); - ASSERT_EQ(c.selectors().size(), 1u); - EXPECT_EQ(c.selectors()[0], selector); - ASSERT_EQ(c.body()->size(), 1u); - EXPECT_EQ(c.body()->get(0), discard); + auto* c = create(b, body); + ASSERT_EQ(c->selectors().size(), 1u); + EXPECT_EQ(c->selectors()[0], selector); + ASSERT_EQ(c->body()->size(), 1u); + EXPECT_EQ(c->body()->get(0), discard); } TEST_F(CaseStatementTest, Creation_WithSource) { - type::I32 i32; CaseSelectorList b; - b.push_back(create(Source{}, &i32, 2)); + b.push_back(create(ty.i32, 2)); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); - CaseStatement c(Source{Source::Location{20, 2}}, b, body); - auto src = c.source(); + auto* body = create(StatementList{ + create(), + }); + auto* c = create(Source{Source::Location{20, 2}}, b, body); + auto src = c->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) { - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); - CaseStatement c(Source{}, CaseSelectorList{}, body); - EXPECT_TRUE(c.IsDefault()); + auto* body = create(StatementList{ + create(), + }); + auto* c = create(CaseSelectorList{}, body); + EXPECT_TRUE(c->IsDefault()); } TEST_F(CaseStatementTest, IsDefault_WithSelectors) { - type::I32 i32; CaseSelectorList b; - b.push_back(create(Source{}, &i32, 2)); + b.push_back(create(ty.i32, 2)); - CaseStatement c(Source{}, b, - create(Source{}, StatementList{})); - EXPECT_FALSE(c.IsDefault()); + auto* c = create(b, create(StatementList{})); + EXPECT_FALSE(c->IsDefault()); } TEST_F(CaseStatementTest, IsCase) { - CaseStatement c(Source{}, CaseSelectorList{}, - create(Source{}, StatementList{})); - EXPECT_TRUE(c.Is()); + auto* c = create(CaseSelectorList{}, + create(StatementList{})); + EXPECT_TRUE(c->Is()); } TEST_F(CaseStatementTest, IsValid) { - CaseStatement c(Source{}, CaseSelectorList{}, - create(Source{}, StatementList{})); - EXPECT_TRUE(c.IsValid()); + auto* c = create(CaseSelectorList{}, + create(StatementList{})); + EXPECT_TRUE(c->IsValid()); } TEST_F(CaseStatementTest, IsValid_NullBodyStatement) { - type::I32 i32; CaseSelectorList b; - b.push_back(create(Source{}, &i32, 2)); + b.push_back(create(ty.i32, 2)); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - nullptr, - }); - CaseStatement c(Source{}, b, body); - EXPECT_FALSE(c.IsValid()); + auto* body = create(StatementList{ + create(), + nullptr, + }); + auto* c = create(b, body); + EXPECT_FALSE(c->IsValid()); } TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) { - type::I32 i32; CaseSelectorList b; - b.push_back(create(Source{}, &i32, 2)); + b.push_back(create(ty.i32, 2)); auto* body = create( - Source{}, + StatementList{ - create(Source{}, nullptr, - create(Source{}, StatementList{}), + create(nullptr, create(StatementList{}), ElseStatementList{}), }); - CaseStatement c(Source{}, {b}, body); - EXPECT_FALSE(c.IsValid()); + auto* c = create(CaseSelectorList{b}, body); + EXPECT_FALSE(c->IsValid()); } TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) { - type::I32 i32; CaseSelectorList b; - b.push_back(create(Source{}, &i32, -2)); + b.push_back(create(ty.i32, -2)); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); - CaseStatement c(Source{}, {b}, body); + auto* body = create(StatementList{ + create(), + }); + auto* c = create(CaseSelectorList{b}, body); std::ostringstream out; - c.to_str(out, 2); + c->to_str(out, 2); EXPECT_EQ(out.str(), R"( Case -2{ Discard{} } @@ -158,18 +143,16 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) { } TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) { - type::U32 u32; CaseSelectorList b; - b.push_back(create(Source{}, &u32, 2)); + b.push_back(create(ty.u32, 2)); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); - CaseStatement c(Source{}, {b}, body); + auto* body = create(StatementList{ + create(), + }); + auto* c = create(CaseSelectorList{b}, body); std::ostringstream out; - c.to_str(out, 2); + c->to_str(out, 2); EXPECT_EQ(out.str(), R"( Case 2{ Discard{} } @@ -177,20 +160,17 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) { } TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) { - type::I32 i32; - CaseSelectorList b; - b.push_back(create(Source{}, &i32, 1)); - b.push_back(create(Source{}, &i32, 2)); + b.push_back(create(ty.i32, 1)); + b.push_back(create(ty.i32, 2)); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); - CaseStatement c(Source{}, b, body); + auto* body = create(StatementList{ + create(), + }); + auto* c = create(b, body); std::ostringstream out; - c.to_str(out, 2); + c->to_str(out, 2); EXPECT_EQ(out.str(), R"( Case 1, 2{ Discard{} } @@ -198,14 +178,13 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) { } TEST_F(CaseStatementTest, ToStr_WithoutSelectors) { - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); - CaseStatement c(Source{}, CaseSelectorList{}, body); + auto* body = create(StatementList{ + create(), + }); + auto* c = create(CaseSelectorList{}, body); std::ostringstream out; - c.to_str(out, 2); + c->to_str(out, 2); EXPECT_EQ(out.str(), R"( Default{ Discard{} } diff --git a/src/ast/clone_context.h b/src/ast/clone_context.h index 9bfb906c9b..05f11d6be2 100644 --- a/src/ast/clone_context.h +++ b/src/ast/clone_context.h @@ -78,7 +78,7 @@ class CloneContext { /// @return the cloned source Source Clone(const Source& s) { return s; } - /// Clones each of the elements of the vector `v` into the module #mod. + /// Clones each of the elements of the vector `v` into the module #mod-> /// @param v the vector to clone /// @return the cloned vector template diff --git a/src/ast/constant_id_decoration_test.cc b/src/ast/constant_id_decoration_test.cc index 493c6da6b9..2da917a252 100644 --- a/src/ast/constant_id_decoration_test.cc +++ b/src/ast/constant_id_decoration_test.cc @@ -23,13 +23,12 @@ namespace { using ConstantIdDecorationTest = TestHelper; TEST_F(ConstantIdDecorationTest, Creation) { - ConstantIdDecoration d{Source{}, 12}; - EXPECT_EQ(12u, d.value()); + auto* d = create(12); + EXPECT_EQ(12u, d->value()); } TEST_F(ConstantIdDecorationTest, Is) { - ConstantIdDecoration cd{Source{}, 27}; - Decoration* d = &cd; + Decoration* d = create(27); EXPECT_FALSE(d->Is()); EXPECT_FALSE(d->Is()); EXPECT_TRUE(d->Is()); @@ -38,9 +37,9 @@ TEST_F(ConstantIdDecorationTest, Is) { } TEST_F(ConstantIdDecorationTest, ToStr) { - ConstantIdDecoration d{Source{}, 1200}; + auto* d = create(1200); std::ostringstream out; - d.to_str(out, 0); + d->to_str(out, 0); EXPECT_EQ(out.str(), R"(ConstantIdDecoration{1200} )"); } diff --git a/src/ast/continue_statement_test.cc b/src/ast/continue_statement_test.cc index 5c15b809a9..ab725b171d 100644 --- a/src/ast/continue_statement_test.cc +++ b/src/ast/continue_statement_test.cc @@ -23,26 +23,26 @@ namespace { using ContinueStatementTest = TestHelper; TEST_F(ContinueStatementTest, Creation_WithSource) { - ContinueStatement stmt(Source{Source::Location{20, 2}}); - auto src = stmt.source(); + auto* stmt = create(Source{Source::Location{20, 2}}); + auto src = stmt->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(ContinueStatementTest, IsContinue) { - ContinueStatement stmt(Source{}); - EXPECT_TRUE(stmt.Is()); + auto* stmt = create(); + EXPECT_TRUE(stmt->Is()); } TEST_F(ContinueStatementTest, IsValid) { - ContinueStatement stmt(Source{}); - EXPECT_TRUE(stmt.IsValid()); + auto* stmt = create(); + EXPECT_TRUE(stmt->IsValid()); } TEST_F(ContinueStatementTest, ToStr) { - ContinueStatement stmt(Source{}); + auto* stmt = create(); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(out.str(), R"( Continue{} )"); } diff --git a/src/ast/decoration_test.cc b/src/ast/decoration_test.cc index 8ec0a01607..ea8ac2ac82 100644 --- a/src/ast/decoration_test.cc +++ b/src/ast/decoration_test.cc @@ -43,21 +43,21 @@ namespace { using DecorationTest = TestHelper; TEST_F(DecorationTest, AsCorrectType) { - auto* decoration = create(Source{}, 1); + auto* decoration = create(1); auto* upcast = static_cast(decoration); auto* downcast = As(upcast); EXPECT_EQ(decoration, downcast); } TEST_F(DecorationTest, AsIncorrectType) { - auto* decoration = create(Source{}, 1); + auto* decoration = create(1); auto* upcast = static_cast(decoration); auto* downcast = As(upcast); EXPECT_EQ(nullptr, downcast); } TEST_F(DecorationTest, Is) { - Decoration* decoration = create(Source{}, 1); + Decoration* decoration = create(1); EXPECT_TRUE(decoration->Is()); EXPECT_FALSE(decoration->Is()); } diff --git a/src/ast/discard_statement_test.cc b/src/ast/discard_statement_test.cc index 3cd5256003..545d732aec 100644 --- a/src/ast/discard_statement_test.cc +++ b/src/ast/discard_statement_test.cc @@ -25,36 +25,36 @@ namespace { using DiscardStatementTest = TestHelper; TEST_F(DiscardStatementTest, Creation) { - DiscardStatement stmt(Source{}); - EXPECT_EQ(stmt.source().range.begin.line, 0u); - EXPECT_EQ(stmt.source().range.begin.column, 0u); - EXPECT_EQ(stmt.source().range.end.line, 0u); - EXPECT_EQ(stmt.source().range.end.column, 0u); + auto* stmt = create(); + EXPECT_EQ(stmt->source().range.begin.line, 0u); + EXPECT_EQ(stmt->source().range.begin.column, 0u); + EXPECT_EQ(stmt->source().range.end.line, 0u); + EXPECT_EQ(stmt->source().range.end.column, 0u); } TEST_F(DiscardStatementTest, Creation_WithSource) { - DiscardStatement stmt( + auto* stmt = create( Source{Source::Range{Source::Location{20, 2}, Source::Location{20, 5}}}); - EXPECT_EQ(stmt.source().range.begin.line, 20u); - EXPECT_EQ(stmt.source().range.begin.column, 2u); - EXPECT_EQ(stmt.source().range.end.line, 20u); - EXPECT_EQ(stmt.source().range.end.column, 5u); + EXPECT_EQ(stmt->source().range.begin.line, 20u); + EXPECT_EQ(stmt->source().range.begin.column, 2u); + EXPECT_EQ(stmt->source().range.end.line, 20u); + EXPECT_EQ(stmt->source().range.end.column, 5u); } TEST_F(DiscardStatementTest, IsDiscard) { - DiscardStatement stmt(Source{}); - EXPECT_TRUE(stmt.Is()); + auto* stmt = create(); + EXPECT_TRUE(stmt->Is()); } TEST_F(DiscardStatementTest, IsValid) { - DiscardStatement stmt(Source{}); - EXPECT_TRUE(stmt.IsValid()); + auto* stmt = create(); + EXPECT_TRUE(stmt->IsValid()); } TEST_F(DiscardStatementTest, ToStr) { - DiscardStatement stmt(Source{}); + auto* stmt = create(); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(out.str(), R"( Discard{} )"); } diff --git a/src/ast/else_statement_test.cc b/src/ast/else_statement_test.cc index f1b681cb4e..b9f1fd7610 100644 --- a/src/ast/else_statement_test.cc +++ b/src/ast/else_statement_test.cc @@ -30,103 +30,98 @@ using ElseStatementTest = TestHelper; TEST_F(ElseStatementTest, Creation) { type::Bool bool_type; auto* cond = create( - Source{}, create(Source{}, &bool_type, true)); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); + create(&bool_type, true)); + auto* body = create(StatementList{ + create(), + }); auto* discard = body->get(0); - ElseStatement e(Source{}, cond, body); - EXPECT_EQ(e.condition(), cond); - ASSERT_EQ(e.body()->size(), 1u); - EXPECT_EQ(e.body()->get(0), discard); + auto* e = create(cond, body); + EXPECT_EQ(e->condition(), cond); + ASSERT_EQ(e->body()->size(), 1u); + EXPECT_EQ(e->body()->get(0), discard); } TEST_F(ElseStatementTest, Creation_WithSource) { - ElseStatement e(Source{Source::Location{20, 2}}, nullptr, - create(Source{}, StatementList{})); - auto src = e.source(); + auto* e = create(Source{Source::Location{20, 2}}, nullptr, + create(StatementList{})); + auto src = e->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(ElseStatementTest, IsElse) { - ElseStatement e(Source{}, nullptr, - create(Source{}, StatementList{})); - EXPECT_TRUE(e.Is()); + auto* e = + create(nullptr, create(StatementList{})); + EXPECT_TRUE(e->Is()); } TEST_F(ElseStatementTest, HasCondition) { type::Bool bool_type; auto* cond = create( - Source{}, create(Source{}, &bool_type, true)); - ElseStatement e(Source{}, cond, - create(Source{}, StatementList{})); - EXPECT_TRUE(e.HasCondition()); + create(&bool_type, true)); + auto* e = + create(cond, create(StatementList{})); + EXPECT_TRUE(e->HasCondition()); } TEST_F(ElseStatementTest, HasContition_NullCondition) { - ElseStatement e(Source{}, nullptr, - create(Source{}, StatementList{})); - EXPECT_FALSE(e.HasCondition()); + auto* e = + create(nullptr, create(StatementList{})); + EXPECT_FALSE(e->HasCondition()); } TEST_F(ElseStatementTest, IsValid) { - ElseStatement e(Source{}, nullptr, - create(Source{}, StatementList{})); - EXPECT_TRUE(e.IsValid()); + auto* e = + create(nullptr, create(StatementList{})); + EXPECT_TRUE(e->IsValid()); } TEST_F(ElseStatementTest, IsValid_WithBody) { - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); - ElseStatement e(Source{}, nullptr, body); - EXPECT_TRUE(e.IsValid()); + auto* body = create(StatementList{ + create(), + }); + auto* e = create(nullptr, body); + EXPECT_TRUE(e->IsValid()); } TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) { - auto* body = - create(Source{}, StatementList{ - create(Source{}), - nullptr, - }); - ElseStatement e(Source{}, nullptr, body); - EXPECT_FALSE(e.IsValid()); + auto* body = create(StatementList{ + create(), + nullptr, + }); + auto* e = create(nullptr, body); + EXPECT_FALSE(e->IsValid()); } TEST_F(ElseStatementTest, IsValid_InvalidCondition) { - auto* cond = create(Source{}, nullptr); - ElseStatement e(Source{}, cond, - create(Source{}, StatementList{})); - EXPECT_FALSE(e.IsValid()); + auto* cond = create(nullptr); + auto* e = + create(cond, create(StatementList{})); + EXPECT_FALSE(e->IsValid()); } TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) { auto* body = create( - Source{}, + StatementList{ - create(Source{}, nullptr, - create(Source{}, StatementList{}), + create(nullptr, create(StatementList{}), ElseStatementList{}), }); - ElseStatement e(Source{}, nullptr, body); - EXPECT_FALSE(e.IsValid()); + auto* e = create(nullptr, body); + EXPECT_FALSE(e->IsValid()); } TEST_F(ElseStatementTest, ToStr) { type::Bool bool_type; auto* cond = create( - Source{}, create(Source{}, &bool_type, true)); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); - ElseStatement e(Source{}, cond, body); + create(&bool_type, true)); + auto* body = create(StatementList{ + create(), + }); + auto* e = create(cond, body); std::ostringstream out; - e.to_str(out, 2); + e->to_str(out, 2); EXPECT_EQ(out.str(), R"( Else{ ( ScalarConstructor[not set]{true} @@ -139,13 +134,12 @@ TEST_F(ElseStatementTest, ToStr) { } TEST_F(ElseStatementTest, ToStr_NoCondition) { - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); - ElseStatement e(Source{}, nullptr, body); + auto* body = create(StatementList{ + create(), + }); + auto* e = create(nullptr, body); std::ostringstream out; - e.to_str(out, 2); + e->to_str(out, 2); EXPECT_EQ(out.str(), R"( Else{ { Discard{} diff --git a/src/ast/expression_test.cc b/src/ast/expression_test.cc index bf6bb7445c..35a381ea81 100644 --- a/src/ast/expression_test.cc +++ b/src/ast/expression_test.cc @@ -22,11 +22,11 @@ namespace tint { namespace ast { namespace { -class Expr : public Expression { +class FakeExpr : public Expression { public: - Expr() : Expression(Source{}) {} + FakeExpr() : Expression(Source{}) {} - Expr* Clone(CloneContext*) const override { return nullptr; } + FakeExpr* Clone(CloneContext*) const override { return nullptr; } bool IsValid() const override { return true; } void to_str(std::ostream&, size_t) const override {} }; @@ -34,20 +34,17 @@ class Expr : public Expression { using ExpressionTest = TestHelper; TEST_F(ExpressionTest, set_result_type) { - type::I32 i32; - - Expr e; - e.set_result_type(&i32); + FakeExpr e; + e.set_result_type(ty.i32); ASSERT_NE(e.result_type(), nullptr); EXPECT_TRUE(e.result_type()->Is()); } TEST_F(ExpressionTest, set_result_type_alias) { - type::I32 i32; - type::Alias a(mod.RegisterSymbol("a"), "a", &i32); - type::Alias b(mod.RegisterSymbol("b"), "b", &a); + type::Alias a(mod->RegisterSymbol("a"), "a", ty.i32); + type::Alias b(mod->RegisterSymbol("b"), "b", &a); - Expr e; + FakeExpr e; e.set_result_type(&b); ASSERT_NE(e.result_type(), nullptr); EXPECT_TRUE(e.result_type()->Is()); diff --git a/src/ast/fallthrough_statement_test.cc b/src/ast/fallthrough_statement_test.cc index 1e926dd272..a17131afe4 100644 --- a/src/ast/fallthrough_statement_test.cc +++ b/src/ast/fallthrough_statement_test.cc @@ -23,34 +23,34 @@ namespace { using FallthroughStatementTest = TestHelper; TEST_F(FallthroughStatementTest, Creation) { - FallthroughStatement stmt(Source{}); - EXPECT_EQ(stmt.source().range.begin.line, 0u); - EXPECT_EQ(stmt.source().range.begin.column, 0u); - EXPECT_EQ(stmt.source().range.end.line, 0u); - EXPECT_EQ(stmt.source().range.end.column, 0u); + auto* stmt = create(); + EXPECT_EQ(stmt->source().range.begin.line, 0u); + EXPECT_EQ(stmt->source().range.begin.column, 0u); + EXPECT_EQ(stmt->source().range.end.line, 0u); + EXPECT_EQ(stmt->source().range.end.column, 0u); } TEST_F(FallthroughStatementTest, Creation_WithSource) { - FallthroughStatement stmt(Source{Source::Location{20, 2}}); - auto src = stmt.source(); + auto* stmt = create(Source{Source::Location{20, 2}}); + auto src = stmt->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(FallthroughStatementTest, IsFallthrough) { - FallthroughStatement stmt(Source{}); - EXPECT_TRUE(stmt.Is()); + auto* stmt = create(); + EXPECT_TRUE(stmt->Is()); } TEST_F(FallthroughStatementTest, IsValid) { - FallthroughStatement stmt(Source{}); - EXPECT_TRUE(stmt.IsValid()); + auto* stmt = create(); + EXPECT_TRUE(stmt->IsValid()); } TEST_F(FallthroughStatementTest, ToStr) { - FallthroughStatement stmt(Source{}); + auto* stmt = create(); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(out.str(), R"( Fallthrough{} )"); } diff --git a/src/ast/float_literal_test.cc b/src/ast/float_literal_test.cc index 2b4394e38a..1cd4cfe7a2 100644 --- a/src/ast/float_literal_test.cc +++ b/src/ast/float_literal_test.cc @@ -28,16 +28,13 @@ namespace { using FloatLiteralTest = TestHelper; TEST_F(FloatLiteralTest, Value) { - type::F32 f32; - FloatLiteral f{Source{}, &f32, 47.2f}; - ASSERT_TRUE(f.Is()); - EXPECT_EQ(f.value(), 47.2f); + auto* f = create(ty.f32, 47.2f); + ASSERT_TRUE(f->Is()); + EXPECT_EQ(f->value(), 47.2f); } TEST_F(FloatLiteralTest, Is) { - type::F32 f32; - FloatLiteral f{Source{}, &f32, 42.f}; - Literal* l = &f; + ast::Literal* l = create(ty.f32, 42.f); EXPECT_FALSE(l->Is()); EXPECT_FALSE(l->Is()); EXPECT_FALSE(l->Is()); @@ -47,16 +44,14 @@ TEST_F(FloatLiteralTest, Is) { } TEST_F(FloatLiteralTest, ToStr) { - type::F32 f32; - FloatLiteral f{Source{}, &f32, 42.1f}; + auto* f = create(ty.f32, 42.1f); - EXPECT_EQ(f.to_str(), "42.099998"); + EXPECT_EQ(f->to_str(), "42.099998"); } TEST_F(FloatLiteralTest, ToName) { - type::F32 f32; - FloatLiteral f{Source{}, &f32, 42.1f}; - EXPECT_EQ(f.name(), "__float42.0999985"); + auto* f = create(ty.f32, 42.1f); + EXPECT_EQ(f->name(), "__float42.0999985"); } } // namespace diff --git a/src/ast/function_test.cc b/src/ast/function_test.cc index 0d9f6455ba..718a2effc3 100644 --- a/src/ast/function_test.cc +++ b/src/ast/function_test.cc @@ -19,9 +19,6 @@ #include "src/ast/location_decoration.h" #include "src/ast/pipeline_stage.h" #include "src/ast/test_helper.h" -#include "src/ast/type/f32_type.h" -#include "src/ast/type/i32_type.h" -#include "src/ast/type/void_type.h" #include "src/ast/variable.h" #include "src/ast/workgroup_decoration.h" @@ -32,113 +29,91 @@ namespace { using FunctionTest = TestHelper; TEST_F(FunctionTest, Creation) { - type::Void void_type; - type::I32 i32; - - auto func_sym = mod.RegisterSymbol("func"); + auto func_sym = mod->RegisterSymbol("func"); VariableList params; - params.push_back(create(Source{}, "var", StorageClass::kNone, &i32, - false, nullptr, - ast::VariableDecorationList{})); + params.push_back(Var("var", StorageClass::kNone, ty.i32)); auto* var = params[0]; - Function f(Source{}, func_sym, "func", params, &void_type, - create(Source{}, StatementList{}), - FunctionDecorationList{}); - EXPECT_EQ(f.symbol(), func_sym); - EXPECT_EQ(f.name(), "func"); - ASSERT_EQ(f.params().size(), 1u); - EXPECT_EQ(f.return_type(), &void_type); - EXPECT_EQ(f.params()[0], var); + auto* f = create(func_sym, "func", params, ty.void_, + create(StatementList{}), + FunctionDecorationList{}); + EXPECT_EQ(f->symbol(), func_sym); + EXPECT_EQ(f->name(), "func"); + ASSERT_EQ(f->params().size(), 1u); + EXPECT_EQ(f->return_type(), ty.void_); + EXPECT_EQ(f->params()[0], var); } TEST_F(FunctionTest, Creation_WithSource) { - type::Void void_type; - type::I32 i32; - - auto func_sym = mod.RegisterSymbol("func"); + auto func_sym = mod->RegisterSymbol("func"); VariableList params; - params.push_back(create(Source{}, "var", StorageClass::kNone, &i32, - false, nullptr, - ast::VariableDecorationList{})); + params.push_back(Var("var", StorageClass::kNone, ty.i32)); - Function f(Source{Source::Location{20, 2}}, func_sym, "func", params, - &void_type, create(Source{}, StatementList{}), - FunctionDecorationList{}); - auto src = f.source(); + auto* f = create( + Source{Source::Location{20, 2}}, func_sym, "func", params, ty.void_, + create(StatementList{}), FunctionDecorationList{}); + auto src = f->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(FunctionTest, AddDuplicateReferencedVariables) { - type::Void void_type; - type::I32 i32; + auto func_sym = mod->RegisterSymbol("func"); - auto func_sym = mod.RegisterSymbol("func"); + auto* v = Var("var", StorageClass::kInput, ty.i32); + auto* f = create(func_sym, "func", VariableList{}, ty.void_, + create(StatementList{}), + FunctionDecorationList{}); - Variable v(Source{}, "var", StorageClass::kInput, &i32, false, nullptr, - ast::VariableDecorationList{}); - Function f(Source{}, func_sym, "func", VariableList{}, &void_type, - create(Source{}, StatementList{}), - FunctionDecorationList{}); + f->add_referenced_module_variable(v); + ASSERT_EQ(f->referenced_module_variables().size(), 1u); + EXPECT_EQ(f->referenced_module_variables()[0], v); - f.add_referenced_module_variable(&v); - ASSERT_EQ(f.referenced_module_variables().size(), 1u); - EXPECT_EQ(f.referenced_module_variables()[0], &v); + f->add_referenced_module_variable(v); + ASSERT_EQ(f->referenced_module_variables().size(), 1u); - f.add_referenced_module_variable(&v); - ASSERT_EQ(f.referenced_module_variables().size(), 1u); - - Variable v2(Source{}, "var2", StorageClass::kOutput, &i32, false, nullptr, - ast::VariableDecorationList{}); - f.add_referenced_module_variable(&v2); - ASSERT_EQ(f.referenced_module_variables().size(), 2u); - EXPECT_EQ(f.referenced_module_variables()[1], &v2); + auto* v2 = Var("var2", StorageClass::kOutput, ty.i32); + f->add_referenced_module_variable(v2); + ASSERT_EQ(f->referenced_module_variables().size(), 2u); + EXPECT_EQ(f->referenced_module_variables()[1], v2); } TEST_F(FunctionTest, GetReferenceLocations) { - type::Void void_type; - type::I32 i32; + auto func_sym = mod->RegisterSymbol("func"); - auto func_sym = mod.RegisterSymbol("func"); + auto* loc1 = Var("loc1", StorageClass::kInput, ty.i32, nullptr, + ast::VariableDecorationList{ + create(0), + }); - auto* loc1 = create(Source{}, "loc1", StorageClass::kInput, &i32, - false, nullptr, - ast::VariableDecorationList{ - create(Source{}, 0), - }); + auto* loc2 = Var("loc2", StorageClass::kInput, ty.i32, nullptr, + ast::VariableDecorationList{ + create(1), + }); - auto* loc2 = create(Source{}, "loc2", StorageClass::kInput, &i32, - false, nullptr, - ast::VariableDecorationList{ - create(Source{}, 1), - }); + auto* builtin1 = Var("builtin1", StorageClass::kInput, ty.i32, nullptr, + ast::VariableDecorationList{ + create(Builtin::kPosition), + }); - auto* builtin1 = create( - Source{}, "builtin1", StorageClass::kInput, &i32, false, nullptr, - ast::VariableDecorationList{ - create(Source{}, Builtin::kPosition), - }); + auto* builtin2 = Var("builtin2", StorageClass::kInput, ty.i32, nullptr, + ast::VariableDecorationList{ + create(Builtin::kFragDepth), + }); - auto* builtin2 = create( - Source{}, "builtin2", StorageClass::kInput, &i32, false, nullptr, - ast::VariableDecorationList{ - create(Source{}, Builtin::kFragDepth), - }); + auto* f = create(func_sym, "func", VariableList{}, ty.void_, + create(StatementList{}), + FunctionDecorationList{}); - Function f(Source{}, func_sym, "func", VariableList{}, &void_type, - create(Source{}, StatementList{}), - FunctionDecorationList{}); + f->add_referenced_module_variable(loc1); + f->add_referenced_module_variable(builtin1); + f->add_referenced_module_variable(loc2); + f->add_referenced_module_variable(builtin2); + ASSERT_EQ(f->referenced_module_variables().size(), 4u); - f.add_referenced_module_variable(loc1); - f.add_referenced_module_variable(builtin1); - f.add_referenced_module_variable(loc2); - f.add_referenced_module_variable(builtin2); - ASSERT_EQ(f.referenced_module_variables().size(), 4u); - - auto ref_locs = f.referenced_location_variables(); + auto ref_locs = f->referenced_location_variables(); ASSERT_EQ(ref_locs.size(), 2u); EXPECT_EQ(ref_locs[0].first, loc1); EXPECT_EQ(ref_locs[0].second->value(), 0u); @@ -147,46 +122,39 @@ TEST_F(FunctionTest, GetReferenceLocations) { } TEST_F(FunctionTest, GetReferenceBuiltins) { - type::Void void_type; - type::I32 i32; + auto func_sym = mod->RegisterSymbol("func"); - auto func_sym = mod.RegisterSymbol("func"); + auto* loc1 = Var("loc1", StorageClass::kInput, ty.i32, nullptr, + ast::VariableDecorationList{ + create(0), + }); - auto* loc1 = create(Source{}, "loc1", StorageClass::kInput, &i32, - false, nullptr, - ast::VariableDecorationList{ - create(Source{}, 0), - }); + auto* loc2 = Var("loc2", StorageClass::kInput, ty.i32, nullptr, + ast::VariableDecorationList{ + create(1), + }); - auto* loc2 = create(Source{}, "loc2", StorageClass::kInput, &i32, - false, nullptr, - ast::VariableDecorationList{ - create(Source{}, 1), - }); + auto* builtin1 = Var("builtin1", StorageClass::kInput, ty.i32, nullptr, + ast::VariableDecorationList{ + create(Builtin::kPosition), + }); - auto* builtin1 = create( - Source{}, "builtin1", StorageClass::kInput, &i32, false, nullptr, - ast::VariableDecorationList{ - create(Source{}, Builtin::kPosition), - }); + auto* builtin2 = Var("builtin2", StorageClass::kInput, ty.i32, nullptr, + ast::VariableDecorationList{ + create(Builtin::kFragDepth), + }); - auto* builtin2 = create( - Source{}, "builtin2", StorageClass::kInput, &i32, false, nullptr, - ast::VariableDecorationList{ - create(Source{}, Builtin::kFragDepth), - }); + auto* f = create(func_sym, "func", VariableList{}, ty.void_, + create(StatementList{}), + FunctionDecorationList{}); - Function f(Source{}, func_sym, "func", VariableList{}, &void_type, - create(Source{}, StatementList{}), - FunctionDecorationList{}); + f->add_referenced_module_variable(loc1); + f->add_referenced_module_variable(builtin1); + f->add_referenced_module_variable(loc2); + f->add_referenced_module_variable(builtin2); + ASSERT_EQ(f->referenced_module_variables().size(), 4u); - f.add_referenced_module_variable(loc1); - f.add_referenced_module_variable(builtin1); - f.add_referenced_module_variable(loc2); - f.add_referenced_module_variable(builtin2); - ASSERT_EQ(f.referenced_module_variables().size(), 4u); - - auto ref_locs = f.referenced_builtin_variables(); + auto ref_locs = f->referenced_builtin_variables(); ASSERT_EQ(ref_locs.size(), 2u); EXPECT_EQ(ref_locs[0].first, builtin1); EXPECT_EQ(ref_locs[0].second->value(), Builtin::kPosition); @@ -195,173 +163,131 @@ TEST_F(FunctionTest, GetReferenceBuiltins) { } TEST_F(FunctionTest, AddDuplicateEntryPoints) { - type::Void void_type; + auto func_sym = mod->RegisterSymbol("func"); + auto main_sym = mod->RegisterSymbol("main"); - auto func_sym = mod.RegisterSymbol("func"); - auto main_sym = mod.RegisterSymbol("main"); + auto* f = create(func_sym, "func", VariableList{}, ty.void_, + create(StatementList{}), + FunctionDecorationList{}); - Function f(Source{}, func_sym, "func", VariableList{}, &void_type, - create(Source{}, StatementList{}), - FunctionDecorationList{}); + f->add_ancestor_entry_point(main_sym); + ASSERT_EQ(1u, f->ancestor_entry_points().size()); + EXPECT_EQ(main_sym, f->ancestor_entry_points()[0]); - f.add_ancestor_entry_point(main_sym); - ASSERT_EQ(1u, f.ancestor_entry_points().size()); - EXPECT_EQ(main_sym, f.ancestor_entry_points()[0]); - - f.add_ancestor_entry_point(main_sym); - ASSERT_EQ(1u, f.ancestor_entry_points().size()); - EXPECT_EQ(main_sym, f.ancestor_entry_points()[0]); + f->add_ancestor_entry_point(main_sym); + ASSERT_EQ(1u, f->ancestor_entry_points().size()); + EXPECT_EQ(main_sym, f->ancestor_entry_points()[0]); } TEST_F(FunctionTest, IsValid) { - type::Void void_type; - type::I32 i32; - - auto func_sym = mod.RegisterSymbol("func"); + auto func_sym = mod->RegisterSymbol("func"); VariableList params; - params.push_back(create(Source{}, "var", StorageClass::kNone, &i32, - false, nullptr, - ast::VariableDecorationList{})); + params.push_back(Var("var", StorageClass::kNone, ty.i32)); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); + auto* body = create(StatementList{ + create(), + }); - Function f(Source{}, func_sym, "func", params, &void_type, body, - FunctionDecorationList{}); - EXPECT_TRUE(f.IsValid()); + auto* f = create(func_sym, "func", params, ty.void_, body, + FunctionDecorationList{}); + EXPECT_TRUE(f->IsValid()); } TEST_F(FunctionTest, IsValid_InvalidName) { - type::Void void_type; - type::I32 i32; - - auto func_sym = mod.RegisterSymbol(""); + auto func_sym = mod->RegisterSymbol(""); VariableList params; - params.push_back(create(Source{}, "var", StorageClass::kNone, &i32, - false, nullptr, - ast::VariableDecorationList{})); + params.push_back(Var("var", StorageClass::kNone, ty.i32)); - Function f(Source{}, func_sym, "", params, &void_type, - create(Source{}, StatementList{}), - FunctionDecorationList{}); - EXPECT_FALSE(f.IsValid()); + auto* f = create(func_sym, "", params, ty.void_, + create(StatementList{}), + FunctionDecorationList{}); + EXPECT_FALSE(f->IsValid()); } TEST_F(FunctionTest, IsValid_MissingReturnType) { - type::I32 i32; - - auto func_sym = mod.RegisterSymbol("func"); + auto func_sym = mod->RegisterSymbol("func"); VariableList params; - params.push_back(create(Source{}, "var", StorageClass::kNone, &i32, - false, nullptr, - ast::VariableDecorationList{})); + params.push_back(Var("var", StorageClass::kNone, ty.i32)); - Function f(Source{}, func_sym, "func", params, nullptr, - create(Source{}, StatementList{}), - FunctionDecorationList{}); - EXPECT_FALSE(f.IsValid()); + auto* f = create(func_sym, "func", params, nullptr, + create(StatementList{}), + FunctionDecorationList{}); + EXPECT_FALSE(f->IsValid()); } TEST_F(FunctionTest, IsValid_NullParam) { - type::Void void_type; - type::I32 i32; - - auto func_sym = mod.RegisterSymbol("func"); + auto func_sym = mod->RegisterSymbol("func"); VariableList params; - params.push_back(create(Source{}, "var", StorageClass::kNone, &i32, - false, nullptr, - ast::VariableDecorationList{})); + params.push_back(Var("var", StorageClass::kNone, ty.i32)); params.push_back(nullptr); - Function f(Source{}, func_sym, "func", params, &void_type, - create(Source{}, StatementList{}), - FunctionDecorationList{}); - EXPECT_FALSE(f.IsValid()); + auto* f = create(func_sym, "func", params, ty.void_, + create(StatementList{}), + FunctionDecorationList{}); + EXPECT_FALSE(f->IsValid()); } TEST_F(FunctionTest, IsValid_InvalidParam) { - type::Void void_type; - - auto func_sym = mod.RegisterSymbol("func"); + auto func_sym = mod->RegisterSymbol("func"); VariableList params; - params.push_back(create(Source{}, "var", StorageClass::kNone, - nullptr, false, nullptr, - ast::VariableDecorationList{})); + params.push_back(Var("var", StorageClass::kNone, nullptr)); - Function f(Source{}, func_sym, "func", params, &void_type, - create(Source{}, StatementList{}), - FunctionDecorationList{}); - EXPECT_FALSE(f.IsValid()); + auto* f = create(func_sym, "func", params, ty.void_, + create(StatementList{}), + FunctionDecorationList{}); + EXPECT_FALSE(f->IsValid()); } TEST_F(FunctionTest, IsValid_NullBodyStatement) { - type::Void void_type; - type::I32 i32; - - auto func_sym = mod.RegisterSymbol("func"); + auto func_sym = mod->RegisterSymbol("func"); VariableList params; - params.push_back(create(Source{}, "var", StorageClass::kNone, &i32, - false, nullptr, - ast::VariableDecorationList{})); + params.push_back(Var("var", StorageClass::kNone, ty.i32)); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - nullptr, - }); + auto* body = create(StatementList{ + create(), + nullptr, + }); - Function f(Source{}, func_sym, "func", params, &void_type, body, - FunctionDecorationList{}); + auto* f = create(func_sym, "func", params, ty.void_, body, + FunctionDecorationList{}); - EXPECT_FALSE(f.IsValid()); + EXPECT_FALSE(f->IsValid()); } TEST_F(FunctionTest, IsValid_InvalidBodyStatement) { - type::Void void_type; - type::I32 i32; - - auto func_sym = mod.RegisterSymbol("func"); + auto func_sym = mod->RegisterSymbol("func"); VariableList params; - params.push_back(create(Source{}, "var", StorageClass::kNone, &i32, - false, nullptr, - ast::VariableDecorationList{})); + params.push_back(Var("var", StorageClass::kNone, ty.i32)); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - nullptr, - }); + auto* body = create(StatementList{ + create(), + nullptr, + }); - Function f(Source{}, func_sym, "func", params, &void_type, body, - FunctionDecorationList{}); - EXPECT_FALSE(f.IsValid()); + auto* f = create(func_sym, "func", params, ty.void_, body, + FunctionDecorationList{}); + EXPECT_FALSE(f->IsValid()); } TEST_F(FunctionTest, ToStr) { - type::Void void_type; - type::I32 i32; + auto func_sym = mod->RegisterSymbol("func"); - auto func_sym = mod.RegisterSymbol("func"); + auto* body = create(StatementList{ + create(), + }); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); - - Function f(Source{}, func_sym, "func", {}, &void_type, body, - FunctionDecorationList{}); + auto* f = create(func_sym, "func", VariableList{}, ty.void_, body, + FunctionDecorationList{}); std::ostringstream out; - f.to_str(out, 2); + f->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Function func -> __void () { @@ -371,21 +297,17 @@ TEST_F(FunctionTest, ToStr) { } TEST_F(FunctionTest, ToStr_WithDecoration) { - type::Void void_type; - type::I32 i32; + auto func_sym = mod->RegisterSymbol("func"); - auto func_sym = mod.RegisterSymbol("func"); - - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); - Function f( - Source{}, func_sym, "func", {}, &void_type, body, - FunctionDecorationList{create(Source{}, 2, 4, 6)}); + auto* body = create(StatementList{ + create(), + }); + auto* f = create( + func_sym, "func", VariableList{}, ty.void_, body, + FunctionDecorationList{create(2, 4, 6)}); std::ostringstream out; - f.to_str(out, 2); + f->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Function func -> __void WorkgroupDecoration{2 4 6} () @@ -396,25 +318,19 @@ TEST_F(FunctionTest, ToStr_WithDecoration) { } TEST_F(FunctionTest, ToStr_WithParams) { - type::Void void_type; - type::I32 i32; - - auto func_sym = mod.RegisterSymbol("func"); + auto func_sym = mod->RegisterSymbol("func"); VariableList params; - params.push_back(create(Source{}, "var", StorageClass::kNone, &i32, - false, nullptr, - ast::VariableDecorationList{})); + params.push_back(Var("var", StorageClass::kNone, ty.i32)); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - }); - Function f(Source{}, func_sym, "func", params, &void_type, body, - FunctionDecorationList{}); + auto* body = create(StatementList{ + create(), + }); + auto* f = create(func_sym, "func", params, ty.void_, body, + FunctionDecorationList{}); std::ostringstream out; - f.to_str(out, 2); + f->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Function func -> __void ( Variable{ @@ -430,94 +346,77 @@ TEST_F(FunctionTest, ToStr_WithParams) { } TEST_F(FunctionTest, TypeName) { - type::Void void_type; + auto func_sym = mod->RegisterSymbol("func"); - auto func_sym = mod.RegisterSymbol("func"); - - Function f(Source{}, func_sym, "func", {}, &void_type, - create(Source{}, StatementList{}), - FunctionDecorationList{}); - EXPECT_EQ(f.type_name(), "__func__void"); + auto* f = create(func_sym, "func", VariableList{}, ty.void_, + create(StatementList{}), + FunctionDecorationList{}); + EXPECT_EQ(f->type_name(), "__func__void"); } TEST_F(FunctionTest, TypeName_WithParams) { - type::Void void_type; - type::I32 i32; - type::F32 f32; - - auto func_sym = mod.RegisterSymbol("func"); + auto func_sym = mod->RegisterSymbol("func"); VariableList params; - params.push_back(create(Source{}, "var1", StorageClass::kNone, &i32, - false, nullptr, - ast::VariableDecorationList{})); - params.push_back(create(Source{}, "var2", StorageClass::kNone, &f32, - false, nullptr, - ast::VariableDecorationList{})); + params.push_back(Var("var1", StorageClass::kNone, ty.i32)); + params.push_back(Var("var2", StorageClass::kNone, ty.f32)); - Function f(Source{}, func_sym, "func", params, &void_type, - create(Source{}, StatementList{}), - FunctionDecorationList{}); - EXPECT_EQ(f.type_name(), "__func__void__i32__f32"); + auto* f = create(func_sym, "func", params, ty.void_, + create(StatementList{}), + FunctionDecorationList{}); + EXPECT_EQ(f->type_name(), "__func__void__i32__f32"); } TEST_F(FunctionTest, GetLastStatement) { - type::Void void_type; - - auto func_sym = mod.RegisterSymbol("func"); + auto func_sym = mod->RegisterSymbol("func"); VariableList params; - auto* stmt = create(Source{}); - auto* body = create(Source{}, StatementList{stmt}); - Function f(Source{}, func_sym, "func", params, &void_type, body, - FunctionDecorationList{}); + auto* stmt = create(); + auto* body = create(StatementList{stmt}); + auto* f = create(func_sym, "func", params, ty.void_, body, + FunctionDecorationList{}); - EXPECT_EQ(f.get_last_statement(), stmt); + EXPECT_EQ(f->get_last_statement(), stmt); } TEST_F(FunctionTest, GetLastStatement_nullptr) { - type::Void void_type; - - auto func_sym = mod.RegisterSymbol("func"); + auto func_sym = mod->RegisterSymbol("func"); VariableList params; - auto* body = create(Source{}, StatementList{}); - Function f(Source{}, func_sym, "func", params, &void_type, body, - FunctionDecorationList{}); + auto* body = create(StatementList{}); + auto* f = create(func_sym, "func", params, ty.void_, body, + FunctionDecorationList{}); - EXPECT_EQ(f.get_last_statement(), nullptr); + EXPECT_EQ(f->get_last_statement(), nullptr); } TEST_F(FunctionTest, WorkgroupSize_NoneSet) { - type::Void void_type; + auto func_sym = mod->RegisterSymbol("func"); - auto func_sym = mod.RegisterSymbol("func"); - - Function f(Source{}, func_sym, "func", {}, &void_type, - create(Source{}, StatementList{}), - FunctionDecorationList{}); + auto* f = create(func_sym, "func", VariableList{}, ty.void_, + create(StatementList{}), + FunctionDecorationList{}); uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - std::tie(x, y, z) = f.workgroup_size(); + std::tie(x, y, z) = f->workgroup_size(); EXPECT_EQ(x, 1u); EXPECT_EQ(y, 1u); EXPECT_EQ(z, 1u); } TEST_F(FunctionTest, WorkgroupSize) { - type::Void void_type; + auto func_sym = mod->RegisterSymbol("func"); - auto func_sym = mod.RegisterSymbol("func"); - - Function f(Source{}, func_sym, "func", {}, &void_type, - create(Source{}, StatementList{}), - {create(Source{}, 2u, 4u, 6u)}); + auto* f = create( + func_sym, "func", VariableList{}, ty.void_, + create(StatementList{}), + FunctionDecorationList{create(2u, 4u, 6u)}); uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - std::tie(x, y, z) = f.workgroup_size(); + std::tie(x, y, z) = f->workgroup_size(); EXPECT_EQ(x, 2u); EXPECT_EQ(y, 4u); EXPECT_EQ(z, 6u); diff --git a/src/ast/identifier_expression_test.cc b/src/ast/identifier_expression_test.cc index 70a03bb74d..92b30d31db 100644 --- a/src/ast/identifier_expression_test.cc +++ b/src/ast/identifier_expression_test.cc @@ -23,36 +23,36 @@ namespace { using IdentifierExpressionTest = TestHelper; TEST_F(IdentifierExpressionTest, Creation) { - IdentifierExpression i(Source{}, mod.RegisterSymbol("ident"), "ident"); - EXPECT_EQ(i.symbol(), Symbol(1)); - EXPECT_EQ(i.name(), "ident"); + auto* i = Expr("ident"); + EXPECT_EQ(i->symbol(), Symbol(1)); + EXPECT_EQ(i->name(), "ident"); } TEST_F(IdentifierExpressionTest, Creation_WithSource) { - IdentifierExpression i(Source{Source::Location{20, 2}}, - mod.RegisterSymbol("ident"), "ident"); - EXPECT_EQ(i.symbol(), Symbol(1)); - EXPECT_EQ(i.name(), "ident"); + auto* i = create(Source{Source::Location{20, 2}}, + mod->RegisterSymbol("ident"), "ident"); + EXPECT_EQ(i->symbol(), Symbol(1)); + EXPECT_EQ(i->name(), "ident"); - auto src = i.source(); + auto src = i->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(IdentifierExpressionTest, IsIdentifier) { - IdentifierExpression i(Source{}, mod.RegisterSymbol("ident"), "ident"); - EXPECT_TRUE(i.Is()); + auto* i = Expr("ident"); + EXPECT_TRUE(i->Is()); } TEST_F(IdentifierExpressionTest, IsValid) { - IdentifierExpression i(Source{}, mod.RegisterSymbol("ident"), "ident"); - EXPECT_TRUE(i.IsValid()); + auto* i = Expr("ident"); + EXPECT_TRUE(i->IsValid()); } TEST_F(IdentifierExpressionTest, ToStr) { - IdentifierExpression i(Source{}, mod.RegisterSymbol("ident"), "ident"); + auto* i = Expr("ident"); std::ostringstream out; - i.to_str(out, 2); + i->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Identifier[not set]{ident} )"); } diff --git a/src/ast/if_statement_test.cc b/src/ast/if_statement_test.cc index 250c145706..ba3e6f7aa8 100644 --- a/src/ast/if_statement_test.cc +++ b/src/ast/if_statement_test.cc @@ -25,176 +25,153 @@ namespace { using IfStatementTest = TestHelper; TEST_F(IfStatementTest, Creation) { - auto* cond = create(Source{}, - mod.RegisterSymbol("cond"), "cond"); - auto* body = create( - Source{}, StatementList{create(Source{})}); - IfStatement stmt(Source{Source::Location{20, 2}}, cond, body, - ElseStatementList{}); - auto src = stmt.source(); + auto* cond = Expr("cond"); + auto* body = + create(StatementList{create()}); + auto* stmt = create(Source{Source::Location{20, 2}}, cond, body, + ElseStatementList{}); + auto src = stmt->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(IfStatementTest, IsIf) { - IfStatement stmt(Source{}, nullptr, - create(Source{}, StatementList{}), - ElseStatementList{}); - EXPECT_TRUE(stmt.Is()); + auto* stmt = create( + nullptr, create(StatementList{}), ElseStatementList{}); + EXPECT_TRUE(stmt->Is()); } TEST_F(IfStatementTest, IsValid) { - auto* cond = create(Source{}, - mod.RegisterSymbol("cond"), "cond"); - auto* body = create( - Source{}, StatementList{create(Source{})}); - IfStatement stmt(Source{}, cond, body, ElseStatementList{}); - EXPECT_TRUE(stmt.IsValid()); + auto* cond = Expr("cond"); + auto* body = + create(StatementList{create()}); + auto* stmt = create(cond, body, ElseStatementList{}); + EXPECT_TRUE(stmt->IsValid()); } TEST_F(IfStatementTest, IsValid_WithElseStatements) { - auto* cond = create(Source{}, - mod.RegisterSymbol("cond"), "cond"); - auto* body = create( - Source{}, StatementList{create(Source{})}); - IfStatement stmt(Source{}, cond, body, - { - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("Ident"), "Ident"), - create(Source{}, StatementList{})), - create( - Source{}, nullptr, - create(Source{}, StatementList{})), - }); - EXPECT_TRUE(stmt.IsValid()); + auto* cond = Expr("cond"); + auto* body = + create(StatementList{create()}); + auto* stmt = create( + cond, body, + ElseStatementList{ + create(create( + mod->RegisterSymbol("Ident"), "Ident"), + create(StatementList{})), + create(nullptr, + create(StatementList{})), + }); + EXPECT_TRUE(stmt->IsValid()); } TEST_F(IfStatementTest, IsValid_MissingCondition) { - auto* body = create( - Source{}, StatementList{create(Source{})}); - IfStatement stmt(Source{}, nullptr, body, ElseStatementList{}); - EXPECT_FALSE(stmt.IsValid()); + auto* body = + create(StatementList{create()}); + auto* stmt = create(nullptr, body, ElseStatementList{}); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(IfStatementTest, IsValid_InvalidCondition) { - auto* cond = - create(Source{}, mod.RegisterSymbol(""), ""); - auto* body = create( - Source{}, StatementList{create(Source{})}); - IfStatement stmt(Source{}, cond, body, ElseStatementList{}); - EXPECT_FALSE(stmt.IsValid()); + auto* cond = Expr(""); + auto* body = + create(StatementList{create()}); + auto* stmt = create(cond, body, ElseStatementList{}); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(IfStatementTest, IsValid_NullBodyStatement) { - auto* cond = create(Source{}, - mod.RegisterSymbol("cond"), "cond"); - auto* body = - create(Source{}, StatementList{ - create(Source{}), - nullptr, - }); - IfStatement stmt(Source{}, cond, body, ElseStatementList{}); - EXPECT_FALSE(stmt.IsValid()); + auto* cond = Expr("cond"); + auto* body = create(StatementList{ + create(), + nullptr, + }); + auto* stmt = create(cond, body, ElseStatementList{}); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) { - auto* cond = create(Source{}, - mod.RegisterSymbol("cond"), "cond"); + auto* cond = Expr("cond"); auto* body = create( - Source{}, + StatementList{ - create(Source{}), - create(Source{}, nullptr, - create(Source{}, StatementList{}), + create(), + create(nullptr, create(StatementList{}), ast::ElseStatementList{}), }); - IfStatement stmt(Source{}, cond, body, ElseStatementList{}); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(cond, body, ElseStatementList{}); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(IfStatementTest, IsValid_NullElseStatement) { - auto* cond = create(Source{}, - mod.RegisterSymbol("cond"), "cond"); - auto* body = create( - Source{}, StatementList{create(Source{})}); - IfStatement stmt(Source{}, cond, body, - { - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("Ident"), "Ident"), - create(Source{}, StatementList{})), - create( - Source{}, nullptr, - create(Source{}, StatementList{})), - nullptr, - }); - EXPECT_FALSE(stmt.IsValid()); + auto* cond = Expr("cond"); + auto* body = + create(StatementList{create()}); + auto* stmt = create( + cond, body, + ElseStatementList{ + create(create( + mod->RegisterSymbol("Ident"), "Ident"), + create(StatementList{})), + create(nullptr, + create(StatementList{})), + nullptr, + }); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { - auto* cond = create(Source{}, - mod.RegisterSymbol("cond"), "cond"); - auto* body = create( - Source{}, StatementList{create(Source{})}); - IfStatement stmt(Source{}, cond, body, - { - create( - Source{}, - create( - Source{}, mod.RegisterSymbol(""), ""), - create(Source{}, StatementList{})), - }); - EXPECT_FALSE(stmt.IsValid()); + auto* cond = Expr("cond"); + auto* body = + create(StatementList{create()}); + auto* stmt = create( + cond, body, + ElseStatementList{ + create(Expr(""), + create(StatementList{})), + }); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { - auto* cond = create(Source{}, - mod.RegisterSymbol("cond"), "cond"); - auto* body = create( - Source{}, StatementList{create(Source{})}); - IfStatement stmt(Source{}, cond, body, - { - create( - Source{}, nullptr, - create(Source{}, StatementList{})), - create( - Source{}, nullptr, - create(Source{}, StatementList{})), - }); - EXPECT_FALSE(stmt.IsValid()); + auto* cond = Expr("cond"); + auto* body = + create(StatementList{create()}); + auto* stmt = create( + cond, body, + ElseStatementList{ + create(nullptr, + create(StatementList{})), + create(nullptr, + create(StatementList{})), + }); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(IfStatementTest, IsValid_ElseNotLast) { - auto* cond = create(Source{}, - mod.RegisterSymbol("cond"), "cond"); - auto* body = create( - Source{}, StatementList{create(Source{})}); - IfStatement stmt(Source{}, cond, body, - { - create( - Source{}, nullptr, - create(Source{}, StatementList{})), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("Ident"), "Ident"), - create(Source{}, StatementList{})), - }); - EXPECT_FALSE(stmt.IsValid()); + auto* cond = Expr("cond"); + auto* body = + create(StatementList{create()}); + auto* stmt = create( + cond, body, + ElseStatementList{ + create(nullptr, + create(StatementList{})), + create(create( + mod->RegisterSymbol("Ident"), "Ident"), + create(StatementList{})), + }); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(IfStatementTest, ToStr) { - auto* cond = create(Source{}, - mod.RegisterSymbol("cond"), "cond"); - auto* body = create( - Source{}, StatementList{create(Source{})}); - IfStatement stmt(Source{}, cond, body, ElseStatementList{}); + auto* cond = Expr("cond"); + auto* body = + create(StatementList{create()}); + auto* stmt = create(cond, body, ElseStatementList{}); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( If{ ( Identifier[not set]{cond} @@ -207,27 +184,24 @@ TEST_F(IfStatementTest, ToStr) { } TEST_F(IfStatementTest, ToStr_WithElseStatements) { - auto* cond = create(Source{}, - mod.RegisterSymbol("cond"), "cond"); - auto* body = create( - Source{}, StatementList{create(Source{})}); - auto* else_if_body = create( - Source{}, StatementList{create(Source{})}); + auto* cond = Expr("cond"); + auto* body = + create(StatementList{create()}); + auto* else_if_body = + create(StatementList{create()}); auto* else_body = create( - Source{}, StatementList{create(Source{}), - create(Source{})}); - IfStatement stmt(Source{}, cond, body, - { - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("ident"), "ident"), - else_if_body), - create(Source{}, nullptr, else_body), - }); + StatementList{create(), create()}); + auto* stmt = create( + cond, body, + ElseStatementList{ + create(create( + mod->RegisterSymbol("ident"), "ident"), + else_if_body), + create(nullptr, else_body), + }); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( If{ ( Identifier[not set]{cond} diff --git a/src/ast/int_literal_test.cc b/src/ast/int_literal_test.cc index edf744042d..dfeb534b7f 100644 --- a/src/ast/int_literal_test.cc +++ b/src/ast/int_literal_test.cc @@ -30,15 +30,13 @@ namespace { using IntLiteralTest = TestHelper; TEST_F(IntLiteralTest, Sint_IsInt) { - type::I32 i32; - SintLiteral i{Source{}, &i32, 47}; - ASSERT_TRUE(i.Is()); + auto* i = create(ty.i32, 47); + ASSERT_TRUE(i->Is()); } TEST_F(IntLiteralTest, Uint_IsInt) { - type::I32 i32; - UintLiteral i{Source{}, &i32, 42}; - EXPECT_TRUE(i.Is()); + auto* i = create(ty.i32, 42); + EXPECT_TRUE(i->Is()); } } // namespace diff --git a/src/ast/location_decoration_test.cc b/src/ast/location_decoration_test.cc index 0e32216b74..fef2647b26 100644 --- a/src/ast/location_decoration_test.cc +++ b/src/ast/location_decoration_test.cc @@ -26,13 +26,12 @@ namespace { using LocationDecorationTest = TestHelper; TEST_F(LocationDecorationTest, Creation) { - LocationDecoration d{Source{}, 2}; - EXPECT_EQ(2u, d.value()); + auto* d = create(2); + EXPECT_EQ(2u, d->value()); } TEST_F(LocationDecorationTest, Is) { - LocationDecoration ld{Source{}, 2}; - Decoration* d = &ld; + Decoration* d = create(2); EXPECT_FALSE(d->Is()); EXPECT_FALSE(d->Is()); EXPECT_FALSE(d->Is()); @@ -41,9 +40,9 @@ TEST_F(LocationDecorationTest, Is) { } TEST_F(LocationDecorationTest, ToStr) { - LocationDecoration d{Source{}, 2}; + auto* d = create(2); std::ostringstream out; - d.to_str(out, 0); + d->to_str(out, 0); EXPECT_EQ(out.str(), R"(LocationDecoration{2} )"); } diff --git a/src/ast/loop_statement_test.cc b/src/ast/loop_statement_test.cc index 58e4b79ef3..d3dca64809 100644 --- a/src/ast/loop_statement_test.cc +++ b/src/ast/loop_statement_test.cc @@ -28,153 +28,150 @@ namespace { using LoopStatementTest = TestHelper; TEST_F(LoopStatementTest, Creation) { - auto* body = create( - Source{}, StatementList{create(Source{})}); + auto* body = + create(StatementList{create()}); auto* b = body->last(); - auto* continuing = create( - Source{}, StatementList{create(Source{})}); + auto* continuing = + create(StatementList{create()}); - LoopStatement l(Source{}, body, continuing); - ASSERT_EQ(l.body()->size(), 1u); - EXPECT_EQ(l.body()->get(0), b); - ASSERT_EQ(l.continuing()->size(), 1u); - EXPECT_EQ(l.continuing()->get(0), continuing->last()); + auto* l = create(body, continuing); + ASSERT_EQ(l->body()->size(), 1u); + EXPECT_EQ(l->body()->get(0), b); + ASSERT_EQ(l->continuing()->size(), 1u); + EXPECT_EQ(l->continuing()->get(0), continuing->last()); } TEST_F(LoopStatementTest, Creation_WithSource) { - auto* body = create( - Source{}, StatementList{create(Source{})}); + auto* body = + create(StatementList{create()}); - auto* continuing = create( - Source{}, StatementList{create(Source{})}); + auto* continuing = + create(StatementList{create()}); - LoopStatement l(Source{Source::Location{20, 2}}, body, continuing); - auto src = l.source(); + auto* l = + create(Source{Source::Location{20, 2}}, body, continuing); + auto src = l->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(LoopStatementTest, IsLoop) { - LoopStatement l(Source{}, create(Source{}, StatementList{}), - create(Source{}, StatementList{})); - EXPECT_TRUE(l.Is()); + auto* l = create(create(StatementList{}), + create(StatementList{})); + EXPECT_TRUE(l->Is()); } TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) { - auto* body = create( - Source{}, StatementList{create(Source{})}); + auto* body = + create(StatementList{create()}); - LoopStatement l(Source{}, body, {}); - EXPECT_FALSE(l.has_continuing()); + auto* l = create(body, nullptr); + EXPECT_FALSE(l->has_continuing()); } TEST_F(LoopStatementTest, HasContinuing_WithContinuing) { - auto* body = create( - Source{}, StatementList{create(Source{})}); + auto* body = + create(StatementList{create()}); - auto* continuing = create( - Source{}, StatementList{create(Source{})}); + auto* continuing = + create(StatementList{create()}); - LoopStatement l(Source{}, body, continuing); - EXPECT_TRUE(l.has_continuing()); + auto* l = create(body, continuing); + EXPECT_TRUE(l->has_continuing()); } TEST_F(LoopStatementTest, IsValid) { - auto* body = create( - Source{}, StatementList{create(Source{})}); + auto* body = + create(StatementList{create()}); - auto* continuing = create( - Source{}, StatementList{create(Source{})}); + auto* continuing = + create(StatementList{create()}); - LoopStatement l(Source{}, body, continuing); - EXPECT_TRUE(l.IsValid()); + auto* l = create(body, continuing); + EXPECT_TRUE(l->IsValid()); } TEST_F(LoopStatementTest, IsValid_WithoutContinuing) { - auto* body = create( - Source{}, StatementList{create(Source{})}); + auto* body = + create(StatementList{create()}); - LoopStatement l(Source{}, body, - create(Source{}, StatementList{})); - EXPECT_TRUE(l.IsValid()); + auto* l = + create(body, create(StatementList{})); + EXPECT_TRUE(l->IsValid()); } TEST_F(LoopStatementTest, IsValid_WithoutBody) { - LoopStatement l(Source{}, create(Source{}, StatementList{}), - create(Source{}, StatementList{})); - EXPECT_TRUE(l.IsValid()); + auto* l = create(create(StatementList{}), + create(StatementList{})); + EXPECT_TRUE(l->IsValid()); } TEST_F(LoopStatementTest, IsValid_NullBodyStatement) { - auto* body = - create(Source{}, StatementList{ - create(Source{}), - nullptr, - }); + auto* body = create(StatementList{ + create(), + nullptr, + }); - auto* continuing = create( - Source{}, StatementList{create(Source{})}); + auto* continuing = + create(StatementList{create()}); - LoopStatement l(Source{}, body, continuing); - EXPECT_FALSE(l.IsValid()); + auto* l = create(body, continuing); + EXPECT_FALSE(l->IsValid()); } TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) { auto* body = create( - Source{}, + StatementList{ - create(Source{}), - create(Source{}, nullptr, - create(Source{}, StatementList{}), + create(), + create(nullptr, create(StatementList{}), ElseStatementList{}), }); - auto* continuing = create( - Source{}, StatementList{create(Source{})}); + auto* continuing = + create(StatementList{create()}); - LoopStatement l(Source{}, body, continuing); - EXPECT_FALSE(l.IsValid()); + auto* l = create(body, continuing); + EXPECT_FALSE(l->IsValid()); } TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) { - auto* body = create( - Source{}, StatementList{create(Source{})}); + auto* body = + create(StatementList{create()}); - auto* continuing = - create(Source{}, StatementList{ - create(Source{}), - nullptr, - }); + auto* continuing = create(StatementList{ + create(), + nullptr, + }); - LoopStatement l(Source{}, body, continuing); - EXPECT_FALSE(l.IsValid()); + auto* l = create(body, continuing); + EXPECT_FALSE(l->IsValid()); } TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) { - auto* body = create( - Source{}, StatementList{create(Source{})}); + auto* body = + create(StatementList{create()}); auto* continuing = create( - Source{}, + StatementList{ - create(Source{}), - create(Source{}, nullptr, - create(Source{}, StatementList{}), + create(), + create(nullptr, create(StatementList{}), ElseStatementList{}), }); - LoopStatement l(Source{}, body, continuing); - EXPECT_FALSE(l.IsValid()); + auto* l = create(body, continuing); + EXPECT_FALSE(l->IsValid()); } TEST_F(LoopStatementTest, ToStr) { - auto* body = create( - Source{}, StatementList{create(Source{})}); + auto* body = + create(StatementList{create()}); - LoopStatement l(Source{}, body, {}); + auto* l = create(body, nullptr); std::ostringstream out; - l.to_str(out, 2); + l->to_str(out, 2); EXPECT_EQ(out.str(), R"( Loop{ Discard{} } @@ -182,15 +179,15 @@ TEST_F(LoopStatementTest, ToStr) { } TEST_F(LoopStatementTest, ToStr_WithContinuing) { - auto* body = create( - Source{}, StatementList{create(Source{})}); + auto* body = + create(StatementList{create()}); - auto* continuing = create( - Source{}, StatementList{create(Source{})}); + auto* continuing = + create(StatementList{create()}); - LoopStatement l(Source{}, body, continuing); + auto* l = create(body, continuing); std::ostringstream out; - l.to_str(out, 2); + l->to_str(out, 2); EXPECT_EQ(out.str(), R"( Loop{ Discard{} continuing { diff --git a/src/ast/member_accessor_expression_test.cc b/src/ast/member_accessor_expression_test.cc index 95a4f91eb0..fb1d3a3de0 100644 --- a/src/ast/member_accessor_expression_test.cc +++ b/src/ast/member_accessor_expression_test.cc @@ -26,93 +26,85 @@ namespace { using MemberAccessorExpressionTest = TestHelper; TEST_F(MemberAccessorExpressionTest, Creation) { - auto* str = create( - Source{}, mod.RegisterSymbol("structure"), "structure"); - auto* mem = create( - Source{}, mod.RegisterSymbol("member"), "member"); + auto* str = create(mod->RegisterSymbol("structure"), + "structure"); + auto* mem = Expr("member"); - MemberAccessorExpression stmt(Source{}, str, mem); - EXPECT_EQ(stmt.structure(), str); - EXPECT_EQ(stmt.member(), mem); + auto* stmt = create(str, mem); + EXPECT_EQ(stmt->structure(), str); + EXPECT_EQ(stmt->member(), mem); } TEST_F(MemberAccessorExpressionTest, Creation_WithSource) { - auto* str = create( - Source{}, mod.RegisterSymbol("structure"), "structure"); - auto* mem = create( - Source{}, mod.RegisterSymbol("member"), "member"); + auto* str = create(mod->RegisterSymbol("structure"), + "structure"); + auto* mem = Expr("member"); - MemberAccessorExpression stmt(Source{Source::Location{20, 2}}, str, mem); - auto src = stmt.source(); + auto* stmt = create(Source{Source::Location{20, 2}}, + str, mem); + auto src = stmt->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) { - auto* str = create( - Source{}, mod.RegisterSymbol("structure"), "structure"); - auto* mem = create( - Source{}, mod.RegisterSymbol("member"), "member"); + auto* str = create(mod->RegisterSymbol("structure"), + "structure"); + auto* mem = Expr("member"); - MemberAccessorExpression stmt(Source{}, str, mem); - EXPECT_TRUE(stmt.Is()); + auto* stmt = create(str, mem); + EXPECT_TRUE(stmt->Is()); } TEST_F(MemberAccessorExpressionTest, IsValid) { - auto* str = create( - Source{}, mod.RegisterSymbol("structure"), "structure"); - auto* mem = create( - Source{}, mod.RegisterSymbol("member"), "member"); + auto* str = create(mod->RegisterSymbol("structure"), + "structure"); + auto* mem = Expr("member"); - MemberAccessorExpression stmt(Source{}, str, mem); - EXPECT_TRUE(stmt.IsValid()); + auto* stmt = create(str, mem); + EXPECT_TRUE(stmt->IsValid()); } TEST_F(MemberAccessorExpressionTest, IsValid_NullStruct) { - auto* mem = create( - Source{}, mod.RegisterSymbol("member"), "member"); + auto* mem = Expr("member"); - MemberAccessorExpression stmt(Source{}, nullptr, mem); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(nullptr, mem); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(MemberAccessorExpressionTest, IsValid_InvalidStruct) { - auto* str = - create(Source{}, mod.RegisterSymbol(""), ""); - auto* mem = create( - Source{}, mod.RegisterSymbol("member"), "member"); + auto* str = Expr(""); + auto* mem = Expr("member"); - MemberAccessorExpression stmt(Source{}, str, mem); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(str, mem); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(MemberAccessorExpressionTest, IsValid_NullMember) { - auto* str = create( - Source{}, mod.RegisterSymbol("structure"), "structure"); + auto* str = create(mod->RegisterSymbol("structure"), + "structure"); - MemberAccessorExpression stmt(Source{}, str, nullptr); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(str, nullptr); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(MemberAccessorExpressionTest, IsValid_InvalidMember) { - auto* str = create( - Source{}, mod.RegisterSymbol("structure"), "structure"); - auto* mem = - create(Source{}, mod.RegisterSymbol(""), ""); + auto* str = create(mod->RegisterSymbol("structure"), + "structure"); + auto* mem = Expr(""); - MemberAccessorExpression stmt(Source{}, str, mem); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(str, mem); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(MemberAccessorExpressionTest, ToStr) { - auto* str = create( - Source{}, mod.RegisterSymbol("structure"), "structure"); - auto* mem = create( - Source{}, mod.RegisterSymbol("member"), "member"); + auto* str = create(mod->RegisterSymbol("structure"), + "structure"); + auto* mem = Expr("member"); - MemberAccessorExpression stmt(Source{}, str, mem); + auto* stmt = create(str, mem); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( MemberAccessor[not set]{ Identifier[not set]{structure} Identifier[not set]{member} diff --git a/src/ast/module_test.cc b/src/ast/module_test.cc index 03be7eb7eb..e8263829f8 100644 --- a/src/ast/module_test.cc +++ b/src/ast/module_test.cc @@ -45,14 +45,12 @@ TEST_F(ModuleTest, ToStrEmitsPreambleAndPostamble) { } TEST_F(ModuleTest, LookupFunction) { - type::F32 f32; Module m; auto func_sym = m.RegisterSymbol("main"); - auto* func = - create(Source{}, func_sym, "main", VariableList{}, &f32, - create(Source{}, StatementList{}), - ast::FunctionDecorationList{}); + auto* func = create(func_sym, "main", VariableList{}, ty.f32, + create(StatementList{}), + ast::FunctionDecorationList{}); m.AddFunction(func); EXPECT_EQ(func, m.FindFunctionBySymbol(func_sym)); } @@ -68,9 +66,8 @@ TEST_F(ModuleTest, IsValid_Empty) { } TEST_F(ModuleTest, IsValid_GlobalVariable) { - type::F32 f32; - auto* var = create(Source{}, "var", StorageClass::kInput, &f32, - false, nullptr, ast::VariableDecorationList{}); + auto* var = create("var", StorageClass::kInput, ty.f32, false, + nullptr, ast::VariableDecorationList{}); Module m; m.AddGlobalVariable(var); @@ -84,8 +81,8 @@ TEST_F(ModuleTest, IsValid_Null_GlobalVariable) { } TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) { - auto* var = create(Source{}, "var", StorageClass::kInput, nullptr, - false, nullptr, ast::VariableDecorationList{}); + auto* var = create("var", StorageClass::kInput, nullptr, false, + nullptr, ast::VariableDecorationList{}); Module m; m.AddGlobalVariable(var); @@ -93,8 +90,7 @@ TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) { } TEST_F(ModuleTest, IsValid_Alias) { - type::F32 f32; - type::Alias alias(mod.RegisterSymbol("alias"), "alias", &f32); + type::Alias alias(mod->RegisterSymbol("alias"), "alias", ty.f32); Module m; m.AddConstructedType(&alias); @@ -108,9 +104,8 @@ TEST_F(ModuleTest, IsValid_Null_Alias) { } TEST_F(ModuleTest, IsValid_Struct) { - type::F32 f32; - type::Struct st(mod.RegisterSymbol("name"), "name", {}); - type::Alias alias(mod.RegisterSymbol("name"), "name", &st); + type::Struct st(mod->RegisterSymbol("name"), "name", {}); + type::Alias alias(mod->RegisterSymbol("name"), "name", &st); Module m; m.AddConstructedType(&alias); @@ -118,9 +113,8 @@ TEST_F(ModuleTest, IsValid_Struct) { } TEST_F(ModuleTest, IsValid_Struct_EmptyName) { - type::F32 f32; - type::Struct st(mod.RegisterSymbol(""), "", {}); - type::Alias alias(mod.RegisterSymbol("name"), "name", &st); + type::Struct st(mod->RegisterSymbol(""), "", {}); + type::Alias alias(mod->RegisterSymbol("name"), "name", &st); Module m; m.AddConstructedType(&alias); @@ -128,14 +122,11 @@ TEST_F(ModuleTest, IsValid_Struct_EmptyName) { } TEST_F(ModuleTest, IsValid_Function) { - type::F32 f32; - Module m; auto* func = create( - Source{}, m.RegisterSymbol("main"), "main", VariableList(), &f32, - create(Source{}, StatementList{}), - ast::FunctionDecorationList{}); + m.RegisterSymbol("main"), "main", VariableList(), ty.f32, + create(StatementList{}), ast::FunctionDecorationList{}); m.AddFunction(func); EXPECT_TRUE(m.IsValid()); @@ -152,9 +143,8 @@ TEST_F(ModuleTest, IsValid_Invalid_Function) { Module m; - auto* func = - create(Source{}, m.RegisterSymbol("main"), "main", p, nullptr, - nullptr, ast::FunctionDecorationList{}); + auto* func = create(m.RegisterSymbol("main"), "main", p, nullptr, + nullptr, ast::FunctionDecorationList{}); m.AddFunction(func); EXPECT_FALSE(m.IsValid()); diff --git a/src/ast/null_literal_test.cc b/src/ast/null_literal_test.cc index 1d2afa01f8..025e02c303 100644 --- a/src/ast/null_literal_test.cc +++ b/src/ast/null_literal_test.cc @@ -28,9 +28,7 @@ namespace { using NullLiteralTest = TestHelper; TEST_F(NullLiteralTest, Is) { - type::I32 i32; - NullLiteral i{Source{}, &i32}; - Literal* l = &i; + ast::Literal* l = create(ty.i32); EXPECT_FALSE(l->Is()); EXPECT_FALSE(l->Is()); EXPECT_FALSE(l->Is()); @@ -40,16 +38,14 @@ TEST_F(NullLiteralTest, Is) { } TEST_F(NullLiteralTest, ToStr) { - type::I32 i32; - NullLiteral i{Source{}, &i32}; + auto* i = create(ty.i32); - EXPECT_EQ(i.to_str(), "null __i32"); + EXPECT_EQ(i->to_str(), "null __i32"); } TEST_F(NullLiteralTest, Name_I32) { - type::I32 i32; - NullLiteral i{Source{}, &i32}; - EXPECT_EQ("__null__i32", i.name()); + auto* i = create(ty.i32); + EXPECT_EQ("__null__i32", i->name()); } } // namespace diff --git a/src/ast/return_statement_test.cc b/src/ast/return_statement_test.cc index 221082dd86..68506c005c 100644 --- a/src/ast/return_statement_test.cc +++ b/src/ast/return_statement_test.cc @@ -26,62 +26,57 @@ namespace { using ReturnStatementTest = TestHelper; TEST_F(ReturnStatementTest, Creation) { - auto* expr = create(Source{}, - mod.RegisterSymbol("expr"), "expr"); + auto* expr = Expr("expr"); - ReturnStatement r(Source{}, expr); - EXPECT_EQ(r.value(), expr); + auto* r = create(expr); + EXPECT_EQ(r->value(), expr); } TEST_F(ReturnStatementTest, Creation_WithSource) { - ReturnStatement r(Source{Source::Location{20, 2}}); - auto src = r.source(); + auto* r = create(Source{Source::Location{20, 2}}); + auto src = r->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(ReturnStatementTest, IsReturn) { - ReturnStatement r(Source{}); - EXPECT_TRUE(r.Is()); + auto* r = create(); + EXPECT_TRUE(r->Is()); } TEST_F(ReturnStatementTest, HasValue_WithoutValue) { - ReturnStatement r(Source{}); - EXPECT_FALSE(r.has_value()); + auto* r = create(); + EXPECT_FALSE(r->has_value()); } TEST_F(ReturnStatementTest, HasValue_WithValue) { - auto* expr = create(Source{}, - mod.RegisterSymbol("expr"), "expr"); - ReturnStatement r(Source{}, expr); - EXPECT_TRUE(r.has_value()); + auto* expr = Expr("expr"); + auto* r = create(expr); + EXPECT_TRUE(r->has_value()); } TEST_F(ReturnStatementTest, IsValid_WithoutValue) { - ReturnStatement r(Source{}); - EXPECT_TRUE(r.IsValid()); + auto* r = create(); + EXPECT_TRUE(r->IsValid()); } TEST_F(ReturnStatementTest, IsValid_WithValue) { - auto* expr = create(Source{}, - mod.RegisterSymbol("expr"), "expr"); - ReturnStatement r(Source{}, expr); - EXPECT_TRUE(r.IsValid()); + auto* expr = Expr("expr"); + auto* r = create(expr); + EXPECT_TRUE(r->IsValid()); } TEST_F(ReturnStatementTest, IsValid_InvalidValue) { - auto* expr = - create(Source{}, mod.RegisterSymbol(""), ""); - ReturnStatement r(Source{}, expr); - EXPECT_FALSE(r.IsValid()); + auto* expr = Expr(""); + auto* r = create(expr); + EXPECT_FALSE(r->IsValid()); } TEST_F(ReturnStatementTest, ToStr_WithValue) { - auto* expr = create(Source{}, - mod.RegisterSymbol("expr"), "expr"); - ReturnStatement r(Source{}, expr); + auto* expr = Expr("expr"); + auto* r = create(expr); std::ostringstream out; - r.to_str(out, 2); + r->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Return{ { Identifier[not set]{expr} @@ -91,9 +86,9 @@ TEST_F(ReturnStatementTest, ToStr_WithValue) { } TEST_F(ReturnStatementTest, ToStr_WithoutValue) { - ReturnStatement r(Source{}); + auto* r = create(); std::ostringstream out; - r.to_str(out, 2); + r->to_str(out, 2); EXPECT_EQ(out.str(), R"( Return{} )"); } diff --git a/src/ast/scalar_constructor_expression_test.cc b/src/ast/scalar_constructor_expression_test.cc index 4f648c353f..14fbd96674 100644 --- a/src/ast/scalar_constructor_expression_test.cc +++ b/src/ast/scalar_constructor_expression_test.cc @@ -26,38 +26,39 @@ using ScalarConstructorExpressionTest = TestHelper; TEST_F(ScalarConstructorExpressionTest, Creation) { type::Bool bool_type; - auto* b = create(Source{}, &bool_type, true); - ScalarConstructorExpression c(Source{}, b); - EXPECT_EQ(c.literal(), b); + auto* b = create(&bool_type, true); + auto* c = create(b); + EXPECT_EQ(c->literal(), b); } TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) { type::Bool bool_type; - auto* b = create(Source{}, &bool_type, true); - ScalarConstructorExpression c(Source{Source::Location{20, 2}}, b); - auto src = c.source(); + auto* b = create(&bool_type, true); + auto* c = + create(Source{Source::Location{20, 2}}, b); + auto src = c->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(ScalarConstructorExpressionTest, IsValid) { type::Bool bool_type; - auto* b = create(Source{}, &bool_type, true); - ScalarConstructorExpression c(Source{}, b); - EXPECT_TRUE(c.IsValid()); + auto* b = create(&bool_type, true); + auto* c = create(b); + EXPECT_TRUE(c->IsValid()); } TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) { - ScalarConstructorExpression c(Source{}, nullptr); - EXPECT_FALSE(c.IsValid()); + auto* c = create(nullptr); + EXPECT_FALSE(c->IsValid()); } TEST_F(ScalarConstructorExpressionTest, ToStr) { type::Bool bool_type; - auto* b = create(Source{}, &bool_type, true); - ScalarConstructorExpression c(Source{}, b); + auto* b = create(&bool_type, true); + auto* c = create(b); std::ostringstream out; - c.to_str(out, 2); + c->to_str(out, 2); EXPECT_EQ(out.str(), R"( ScalarConstructor[not set]{true} )"); } diff --git a/src/ast/set_decoration_test.cc b/src/ast/set_decoration_test.cc index c0d6a15c43..b5ae13853d 100644 --- a/src/ast/set_decoration_test.cc +++ b/src/ast/set_decoration_test.cc @@ -24,13 +24,12 @@ namespace { using SetDecorationTest = TestHelper; TEST_F(SetDecorationTest, Creation) { - SetDecoration d{Source{}, 2}; - EXPECT_EQ(2u, d.value()); + auto* d = create(2); + EXPECT_EQ(2u, d->value()); } TEST_F(SetDecorationTest, Is) { - SetDecoration sd{Source{}, 2}; - Decoration* d = &sd; + Decoration* d = create(2); EXPECT_FALSE(d->Is()); EXPECT_FALSE(d->Is()); EXPECT_FALSE(d->Is()); @@ -39,9 +38,9 @@ TEST_F(SetDecorationTest, Is) { } TEST_F(SetDecorationTest, ToStr) { - SetDecoration d{Source{}, 2}; + auto* d = create(2); std::ostringstream out; - d.to_str(out, 0); + d->to_str(out, 0); EXPECT_EQ(out.str(), R"(SetDecoration{2} )"); } diff --git a/src/ast/sint_literal_test.cc b/src/ast/sint_literal_test.cc index f4fcc08ebb..e4a32d21b7 100644 --- a/src/ast/sint_literal_test.cc +++ b/src/ast/sint_literal_test.cc @@ -29,16 +29,13 @@ namespace { using SintLiteralTest = TestHelper; TEST_F(SintLiteralTest, Value) { - type::I32 i32; - SintLiteral i{Source{}, &i32, 47}; - ASSERT_TRUE(i.Is()); - EXPECT_EQ(i.value(), 47); + auto* i = create(ty.i32, 47); + ASSERT_TRUE(i->Is()); + EXPECT_EQ(i->value(), 47); } TEST_F(SintLiteralTest, Is) { - type::I32 i32; - SintLiteral i{Source{}, &i32, 42}; - Literal* l = &i; + ast::Literal* l = create(ty.i32, 42); EXPECT_FALSE(l->Is()); EXPECT_TRUE(l->Is()); EXPECT_FALSE(l->Is()); @@ -47,22 +44,20 @@ TEST_F(SintLiteralTest, Is) { } TEST_F(SintLiteralTest, ToStr) { - type::I32 i32; - SintLiteral i{Source{}, &i32, -42}; + auto* i = create(ty.i32, -42); - EXPECT_EQ(i.to_str(), "-42"); + EXPECT_EQ(i->to_str(), "-42"); } TEST_F(SintLiteralTest, Name_I32) { - type::I32 i32; - SintLiteral i{Source{}, &i32, 2}; - EXPECT_EQ("__sint__i32_2", i.name()); + auto* i = create(ty.i32, 2); + EXPECT_EQ("__sint__i32_2", i->name()); } TEST_F(SintLiteralTest, Name_U32) { type::U32 u32; - SintLiteral i{Source{}, &u32, 2}; - EXPECT_EQ("__sint__u32_2", i.name()); + auto* i = create(&u32, 2); + EXPECT_EQ("__sint__u32_2", i->name()); } } // namespace diff --git a/src/ast/stage_decoration_test.cc b/src/ast/stage_decoration_test.cc index 966d7e0c1f..82a5ccd7fa 100644 --- a/src/ast/stage_decoration_test.cc +++ b/src/ast/stage_decoration_test.cc @@ -26,21 +26,20 @@ namespace { using StageDecorationTest = TestHelper; TEST_F(StageDecorationTest, Creation_1param) { - StageDecoration d{Source{}, PipelineStage::kFragment}; - EXPECT_EQ(d.value(), PipelineStage::kFragment); + auto* d = create(PipelineStage::kFragment); + EXPECT_EQ(d->value(), PipelineStage::kFragment); } TEST_F(StageDecorationTest, Is) { - StageDecoration sd{Source{}, PipelineStage::kFragment}; - Decoration* d = &sd; + Decoration* d = create(PipelineStage::kFragment); EXPECT_FALSE(d->Is()); EXPECT_TRUE(d->Is()); } TEST_F(StageDecorationTest, ToStr) { - StageDecoration d{Source{}, PipelineStage::kFragment}; + auto* d = create(PipelineStage::kFragment); std::ostringstream out; - d.to_str(out, 0); + d->to_str(out, 0); EXPECT_EQ(out.str(), R"(StageDecoration{fragment} )"); } diff --git a/src/ast/stride_decoration_test.cc b/src/ast/stride_decoration_test.cc index 34a1079e81..7046767acf 100644 --- a/src/ast/stride_decoration_test.cc +++ b/src/ast/stride_decoration_test.cc @@ -23,22 +23,22 @@ namespace { using StrideDecorationTest = TestHelper; TEST_F(StrideDecorationTest, Creation) { - StrideDecoration d{Source{}, 2}; - EXPECT_EQ(2u, d.stride()); + auto* d = create(2); + EXPECT_EQ(2u, d->stride()); } TEST_F(StrideDecorationTest, Is) { - StrideDecoration d{Source{}, 2}; - EXPECT_TRUE(d.Is()); + auto* d = create(2); + EXPECT_TRUE(d->Is()); } TEST_F(StrideDecorationTest, Source) { - StrideDecoration d{ - Source{Source::Range{Source::Location{1, 2}, Source::Location{3, 4}}}, 2}; - EXPECT_EQ(d.source().range.begin.line, 1u); - EXPECT_EQ(d.source().range.begin.column, 2u); - EXPECT_EQ(d.source().range.end.line, 3u); - EXPECT_EQ(d.source().range.end.column, 4u); + auto* d = create( + Source{Source::Range{Source::Location{1, 2}, Source::Location{3, 4}}}, 2); + EXPECT_EQ(d->source().range.begin.line, 1u); + EXPECT_EQ(d->source().range.begin.column, 2u); + EXPECT_EQ(d->source().range.end.line, 3u); + EXPECT_EQ(d->source().range.end.column, 4u); } } // namespace diff --git a/src/ast/struct_member_offset_decoration_test.cc b/src/ast/struct_member_offset_decoration_test.cc index 49a4796855..196bebb372 100644 --- a/src/ast/struct_member_offset_decoration_test.cc +++ b/src/ast/struct_member_offset_decoration_test.cc @@ -23,13 +23,13 @@ namespace { using StructMemberOffsetDecorationTest = TestHelper; TEST_F(StructMemberOffsetDecorationTest, Creation) { - StructMemberOffsetDecoration d{Source{}, 2}; - EXPECT_EQ(2u, d.offset()); + auto* d = create(2); + EXPECT_EQ(2u, d->offset()); } TEST_F(StructMemberOffsetDecorationTest, Is) { - StructMemberOffsetDecoration d{Source{}, 2}; - EXPECT_TRUE(d.Is()); + auto* d = create(2); + EXPECT_TRUE(d->Is()); } } // namespace diff --git a/src/ast/struct_member_test.cc b/src/ast/struct_member_test.cc index 1c9a6d7826..9130b96c15 100644 --- a/src/ast/struct_member_test.cc +++ b/src/ast/struct_member_test.cc @@ -28,78 +28,71 @@ namespace { using StructMemberTest = TestHelper; TEST_F(StructMemberTest, Creation) { - type::I32 i32; StructMemberDecorationList decorations; - decorations.emplace_back(create(Source{}, 4)); + decorations.emplace_back(create(4)); - StructMember st{Source{}, "a", &i32, decorations}; - EXPECT_EQ(st.name(), "a"); - EXPECT_EQ(st.type(), &i32); - EXPECT_EQ(st.decorations().size(), 1u); - EXPECT_TRUE(st.decorations()[0]->Is()); - EXPECT_EQ(st.source().range.begin.line, 0u); - EXPECT_EQ(st.source().range.begin.column, 0u); - EXPECT_EQ(st.source().range.end.line, 0u); - EXPECT_EQ(st.source().range.end.column, 0u); + auto* st = create("a", ty.i32, decorations); + EXPECT_EQ(st->name(), "a"); + EXPECT_EQ(st->type(), ty.i32); + EXPECT_EQ(st->decorations().size(), 1u); + EXPECT_TRUE(st->decorations()[0]->Is()); + EXPECT_EQ(st->source().range.begin.line, 0u); + EXPECT_EQ(st->source().range.begin.column, 0u); + EXPECT_EQ(st->source().range.end.line, 0u); + EXPECT_EQ(st->source().range.end.column, 0u); } TEST_F(StructMemberTest, CreationWithSource) { - type::I32 i32; - Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}; - - StructMember st{s, "a", &i32, {}}; - EXPECT_EQ(st.name(), "a"); - EXPECT_EQ(st.type(), &i32); - EXPECT_EQ(st.decorations().size(), 0u); - EXPECT_EQ(st.source().range.begin.line, 27u); - EXPECT_EQ(st.source().range.begin.column, 4u); - EXPECT_EQ(st.source().range.end.line, 27u); - EXPECT_EQ(st.source().range.end.column, 8u); + auto* st = create( + Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, + "a", ty.i32, StructMemberDecorationList{}); + EXPECT_EQ(st->name(), "a"); + EXPECT_EQ(st->type(), ty.i32); + EXPECT_EQ(st->decorations().size(), 0u); + EXPECT_EQ(st->source().range.begin.line, 27u); + EXPECT_EQ(st->source().range.begin.column, 4u); + EXPECT_EQ(st->source().range.end.line, 27u); + EXPECT_EQ(st->source().range.end.column, 8u); } TEST_F(StructMemberTest, IsValid) { - type::I32 i32; - StructMember st{Source{}, "a", &i32, {}}; - EXPECT_TRUE(st.IsValid()); + auto* st = create("a", ty.i32, StructMemberDecorationList{}); + EXPECT_TRUE(st->IsValid()); } TEST_F(StructMemberTest, IsValid_EmptyName) { - type::I32 i32; - StructMember st{Source{}, "", &i32, {}}; - EXPECT_FALSE(st.IsValid()); + auto* st = create("", ty.i32, StructMemberDecorationList{}); + EXPECT_FALSE(st->IsValid()); } TEST_F(StructMemberTest, IsValid_NullType) { - StructMember st{Source{}, "a", nullptr, {}}; - EXPECT_FALSE(st.IsValid()); + auto* st = create("a", nullptr, StructMemberDecorationList{}); + EXPECT_FALSE(st->IsValid()); } TEST_F(StructMemberTest, IsValid_Null_Decoration) { - type::I32 i32; StructMemberDecorationList decorations; - decorations.emplace_back(create(Source{}, 4)); + decorations.emplace_back(create(4)); decorations.push_back(nullptr); - StructMember st{Source{}, "a", &i32, decorations}; - EXPECT_FALSE(st.IsValid()); + auto* st = create("a", ty.i32, decorations); + EXPECT_FALSE(st->IsValid()); } TEST_F(StructMemberTest, ToStr) { - type::I32 i32; StructMemberDecorationList decorations; - decorations.emplace_back(create(Source{}, 4)); + decorations.emplace_back(create(4)); - StructMember st{Source{}, "a", &i32, decorations}; + auto* st = create("a", ty.i32, decorations); std::ostringstream out; - st.to_str(out, 2); + st->to_str(out, 2); EXPECT_EQ(out.str(), " StructMember{[[ offset 4 ]] a: __i32}\n"); } TEST_F(StructMemberTest, ToStrNoDecorations) { - type::I32 i32; - StructMember st{Source{}, "a", &i32, {}}; + auto* st = create("a", ty.i32, StructMemberDecorationList{}); std::ostringstream out; - st.to_str(out, 2); + st->to_str(out, 2); EXPECT_EQ(out.str(), " StructMember{a: __i32}\n"); } diff --git a/src/ast/struct_test.cc b/src/ast/struct_test.cc index 5f0f1f0659..9ad9c91d14 100644 --- a/src/ast/struct_test.cc +++ b/src/ast/struct_test.cc @@ -30,104 +30,93 @@ namespace { using StructTest = TestHelper; TEST_F(StructTest, Creation) { - type::I32 i32; StructMemberList members; members.push_back( - create(Source{}, "a", &i32, StructMemberDecorationList())); + create("a", ty.i32, StructMemberDecorationList{})); - Struct s{Source{}, members, ast::StructDecorationList{}}; - EXPECT_EQ(s.members().size(), 1u); - EXPECT_TRUE(s.decorations().empty()); - EXPECT_EQ(s.source().range.begin.line, 0u); - EXPECT_EQ(s.source().range.begin.column, 0u); - EXPECT_EQ(s.source().range.end.line, 0u); - EXPECT_EQ(s.source().range.end.column, 0u); -} + auto* s = create(members, ast::StructDecorationList{}); + EXPECT_EQ(s->members().size(), 1u); + EXPECT_TRUE(s->decorations().empty()); + EXPECT_EQ(s->source().range.begin.line, 0u); + EXPECT_EQ(s->source().range.begin.column, 0u); + EXPECT_EQ(s->source().range.end.line, 0u); + EXPECT_EQ(s->source().range.end.column, 0u); +} // namespace TEST_F(StructTest, Creation_WithDecorations) { - type::I32 i32; - StructMemberList members; members.push_back( - create(Source{}, "a", &i32, StructMemberDecorationList())); + create("a", ty.i32, StructMemberDecorationList{})); StructDecorationList decos; - decos.push_back(create(Source{})); + decos.push_back(create()); - Struct s{Source{}, members, decos}; - EXPECT_EQ(s.members().size(), 1u); - ASSERT_EQ(s.decorations().size(), 1u); - EXPECT_TRUE(s.decorations()[0]->Is()); - EXPECT_EQ(s.source().range.begin.line, 0u); - EXPECT_EQ(s.source().range.begin.column, 0u); - EXPECT_EQ(s.source().range.end.line, 0u); - EXPECT_EQ(s.source().range.end.column, 0u); + auto* s = create(members, decos); + EXPECT_EQ(s->members().size(), 1u); + ASSERT_EQ(s->decorations().size(), 1u); + EXPECT_TRUE(s->decorations()[0]->Is()); + EXPECT_EQ(s->source().range.begin.line, 0u); + EXPECT_EQ(s->source().range.begin.column, 0u); + EXPECT_EQ(s->source().range.end.line, 0u); + EXPECT_EQ(s->source().range.end.column, 0u); } TEST_F(StructTest, CreationWithSourceAndDecorations) { - type::I32 i32; - StructMemberList members; members.emplace_back( - create(Source{}, "a", &i32, StructMemberDecorationList())); + create("a", ty.i32, StructMemberDecorationList{})); StructDecorationList decos; - decos.push_back(create(Source{})); + decos.push_back(create()); - Struct s{ + auto* s = create( Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, - members, decos}; - EXPECT_EQ(s.members().size(), 1u); - ASSERT_EQ(s.decorations().size(), 1u); - EXPECT_TRUE(s.decorations()[0]->Is()); - EXPECT_EQ(s.source().range.begin.line, 27u); - EXPECT_EQ(s.source().range.begin.column, 4u); - EXPECT_EQ(s.source().range.end.line, 27u); - EXPECT_EQ(s.source().range.end.column, 8u); + members, decos); + EXPECT_EQ(s->members().size(), 1u); + ASSERT_EQ(s->decorations().size(), 1u); + EXPECT_TRUE(s->decorations()[0]->Is()); + EXPECT_EQ(s->source().range.begin.line, 27u); + EXPECT_EQ(s->source().range.begin.column, 4u); + EXPECT_EQ(s->source().range.end.line, 27u); + EXPECT_EQ(s->source().range.end.column, 8u); } TEST_F(StructTest, IsValid) { - Struct s(Source{}, StructMemberList{}, StructDecorationList{}); - EXPECT_TRUE(s.IsValid()); + auto* s = create(StructMemberList{}, StructDecorationList{}); + EXPECT_TRUE(s->IsValid()); } TEST_F(StructTest, IsValid_Null_StructMember) { - type::I32 i32; - StructMemberList members; members.push_back( - create(Source{}, "a", &i32, StructMemberDecorationList())); + create("a", ty.i32, StructMemberDecorationList{})); members.push_back(nullptr); - Struct s{Source{}, members, ast::StructDecorationList{}}; - EXPECT_FALSE(s.IsValid()); -} + auto* s = create(members, ast::StructDecorationList{}); + EXPECT_FALSE(s->IsValid()); +} // namespace ast TEST_F(StructTest, IsValid_Invalid_StructMember) { - type::I32 i32; - StructMemberList members; members.push_back( - create(Source{}, "", &i32, StructMemberDecorationList())); + create("", ty.i32, StructMemberDecorationList{})); - Struct s{Source{}, members, ast::StructDecorationList{}}; - EXPECT_FALSE(s.IsValid()); -} + auto* s = create(members, ast::StructDecorationList{}); + EXPECT_FALSE(s->IsValid()); +} // namespace tint TEST_F(StructTest, ToStr) { - type::I32 i32; - StructMemberList members; members.emplace_back( - create(Source{}, "a", &i32, StructMemberDecorationList())); + create("a", ty.i32, StructMemberDecorationList{})); StructDecorationList decos; - decos.push_back(create(Source{})); + decos.push_back(create()); - Struct s{Source{}, members, decos}; + auto* s = create(members, decos); std::ostringstream out; - s.to_str(out, 2); + s->to_str(out, 2); EXPECT_EQ(out.str(), R"(Struct{ [[block]] StructMember{a: __i32} diff --git a/src/ast/switch_statement_test.cc b/src/ast/switch_statement_test.cc index bb5ce31676..175365812c 100644 --- a/src/ast/switch_statement_test.cc +++ b/src/ast/switch_statement_test.cc @@ -29,136 +29,115 @@ namespace { using SwitchStatementTest = TestHelper; TEST_F(SwitchStatementTest, Creation) { - type::I32 i32; - CaseSelectorList lit; - lit.push_back(create(Source{}, &i32, 1)); + lit.push_back(create(ty.i32, 1)); - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); + auto* ident = Expr("ident"); CaseStatementList body; - auto* case_stmt = create( - Source{}, lit, create(Source{}, StatementList{})); + auto* case_stmt = + create(lit, create(StatementList{})); body.push_back(case_stmt); - SwitchStatement stmt(Source{}, ident, body); - EXPECT_EQ(stmt.condition(), ident); - ASSERT_EQ(stmt.body().size(), 1u); - EXPECT_EQ(stmt.body()[0], case_stmt); + auto* stmt = create(ident, body); + EXPECT_EQ(stmt->condition(), ident); + ASSERT_EQ(stmt->body().size(), 1u); + EXPECT_EQ(stmt->body()[0], case_stmt); } TEST_F(SwitchStatementTest, Creation_WithSource) { - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); + auto* ident = Expr("ident"); - SwitchStatement stmt(Source{Source::Location{20, 2}}, ident, - CaseStatementList()); - auto src = stmt.source(); + auto* stmt = create(Source{Source::Location{20, 2}}, ident, + CaseStatementList()); + auto src = stmt->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(SwitchStatementTest, IsSwitch) { - type::I32 i32; - CaseSelectorList lit; - lit.push_back(create(Source{}, &i32, 2)); + lit.push_back(create(ty.i32, 2)); - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); + auto* ident = Expr("ident"); CaseStatementList body; - body.push_back(create( - Source{}, lit, create(Source{}, StatementList{}))); + body.push_back( + create(lit, create(StatementList{}))); - SwitchStatement stmt(Source{}, ident, body); - EXPECT_TRUE(stmt.Is()); + auto* stmt = create(ident, body); + EXPECT_TRUE(stmt->Is()); } TEST_F(SwitchStatementTest, IsValid) { - type::I32 i32; - CaseSelectorList lit; - lit.push_back(create(Source{}, &i32, 2)); + lit.push_back(create(ty.i32, 2)); - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); + auto* ident = Expr("ident"); CaseStatementList body; - body.push_back(create( - Source{}, lit, create(Source{}, StatementList{}))); + body.push_back( + create(lit, create(StatementList{}))); - SwitchStatement stmt(Source{}, ident, body); - EXPECT_TRUE(stmt.IsValid()); + auto* stmt = create(ident, body); + EXPECT_TRUE(stmt->IsValid()); } TEST_F(SwitchStatementTest, IsValid_Null_Condition) { - type::I32 i32; - CaseSelectorList lit; - lit.push_back(create(Source{}, &i32, 2)); + lit.push_back(create(ty.i32, 2)); CaseStatementList body; - body.push_back(create( - Source{}, lit, create(Source{}, StatementList{}))); + body.push_back( + create(lit, create(StatementList{}))); - SwitchStatement stmt(Source{}, nullptr, body); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(nullptr, body); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) { - type::I32 i32; - CaseSelectorList lit; - lit.push_back(create(Source{}, &i32, 2)); + lit.push_back(create(ty.i32, 2)); - auto* ident = - create(Source{}, mod.RegisterSymbol(""), ""); + auto* ident = Expr(""); CaseStatementList body; - body.push_back(create( - Source{}, lit, create(Source{}, StatementList{}))); + body.push_back( + create(lit, create(StatementList{}))); - SwitchStatement stmt(Source{}, ident, body); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(ident, body); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) { - type::I32 i32; - CaseSelectorList lit; - lit.push_back(create(Source{}, &i32, 2)); + lit.push_back(create(ty.i32, 2)); - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); + auto* ident = Expr("ident"); CaseStatementList body; - body.push_back(create( - Source{}, lit, create(Source{}, StatementList{}))); + body.push_back( + create(lit, create(StatementList{}))); body.push_back(nullptr); - SwitchStatement stmt(Source{}, ident, body); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(ident, body); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) { - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); + auto* ident = Expr("ident"); - auto* case_body = create(Source{}, StatementList{ - nullptr, - }); + auto* case_body = create(StatementList{ + nullptr, + }); CaseStatementList body; - body.push_back( - create(Source{}, CaseSelectorList{}, case_body)); + body.push_back(create(CaseSelectorList{}, case_body)); - SwitchStatement stmt(Source{}, ident, body); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(ident, body); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(SwitchStatementTest, ToStr_Empty) { - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); + auto* ident = Expr("ident"); - SwitchStatement stmt(Source{}, ident, {}); + auto* stmt = create(ident, CaseStatementList{}); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Switch{ Identifier[not set]{ident} { @@ -168,20 +147,17 @@ TEST_F(SwitchStatementTest, ToStr_Empty) { } TEST_F(SwitchStatementTest, ToStr) { - type::I32 i32; - CaseSelectorList lit; - lit.push_back(create(Source{}, &i32, 2)); + lit.push_back(create(ty.i32, 2)); - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); + auto* ident = Expr("ident"); CaseStatementList body; - body.push_back(create( - Source{}, lit, create(Source{}, StatementList{}))); + body.push_back( + create(lit, create(StatementList{}))); - SwitchStatement stmt(Source{}, ident, body); + auto* stmt = create(ident, body); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( Switch{ Identifier[not set]{ident} { diff --git a/src/ast/test_helper.h b/src/ast/test_helper.h index 5bb3402352..7cb44f8aa5 100644 --- a/src/ast/test_helper.h +++ b/src/ast/test_helper.h @@ -20,6 +20,7 @@ #include #include "gtest/gtest.h" +#include "src/ast/builder.h" #include "src/ast/module.h" #include "src/demangler.h" @@ -28,29 +29,15 @@ namespace ast { /// Helper class for testing template -class TestHelperBase : public BASE { +class TestHelperBase : public BASE, public BuilderWithModule { public: - TestHelperBase() {} - ~TestHelperBase() = default; - - /// Creates a new `Node` owned by the Module. When the Module is - /// destructed, the `Node` will also be destructed. - /// @param args the arguments to pass to the type constructor - /// @returns the node pointer - template - T* create(ARGS&&... args) { - return mod.create(std::forward(args)...); - } - /// Demangles the given string /// @param s the string to demangle /// @returns the demangled string std::string demangle(const std::string& s) { - return demanger.Demangle(mod, s); + return demanger.Demangle(*mod, s); } - /// The module - Module mod; /// A demangler Demangler demanger; }; diff --git a/src/ast/type/access_control_type_test.cc b/src/ast/type/access_control_type_test.cc index ef803ac50f..37d93d9aff 100644 --- a/src/ast/type/access_control_type_test.cc +++ b/src/ast/type/access_control_type_test.cc @@ -106,16 +106,14 @@ TEST_F(AccessControlTest, MinBufferBindingSizeU32) { TEST_F(AccessControlTest, MinBufferBindingSizeArray) { U32 u32; - Array array(&u32, 4, - ArrayDecorationList{create(Source{}, 4)}); + Array array(&u32, 4, ArrayDecorationList{create(4)}); AccessControl at{ast::AccessControl::kReadOnly, &array}; EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } TEST_F(AccessControlTest, MinBufferBindingSizeRuntimeArray) { U32 u32; - Array array(&u32, 0, - ArrayDecorationList{create(Source{}, 4)}); + Array array(&u32, 0, ArrayDecorationList{create(4)}); AccessControl at{ast::AccessControl::kReadOnly, &array}; EXPECT_EQ(4u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } @@ -125,17 +123,17 @@ TEST_F(AccessControlTest, MinBufferBindingSizeStruct) { StructMemberList members; StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &u32, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &u32, deco)); deco = StructMemberDecorationList(); - deco.push_back(create(Source{}, 4)); - members.push_back(create(Source{}, "bar", &u32, deco)); + deco.push_back(create(4)); + members.push_back(create("bar", &u32, deco)); StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); AccessControl at{ast::AccessControl::kReadOnly, &struct_type}; EXPECT_EQ(16u, at.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(8u, at.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); @@ -149,16 +147,14 @@ TEST_F(AccessControlTest, BaseAlignmentU32) { TEST_F(AccessControlTest, BaseAlignmentArray) { U32 u32; - Array array(&u32, 4, - ArrayDecorationList{create(Source{}, 4)}); + Array array(&u32, 4, ArrayDecorationList{create(4)}); AccessControl at{ast::AccessControl::kReadOnly, &array}; EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer)); } TEST_F(AccessControlTest, BaseAlignmentRuntimeArray) { U32 u32; - Array array(&u32, 0, - ArrayDecorationList{create(Source{}, 4)}); + Array array(&u32, 0, ArrayDecorationList{create(4)}); AccessControl at{ast::AccessControl::kReadOnly, &array}; EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer)); } @@ -169,18 +165,18 @@ TEST_F(AccessControlTest, BaseAlignmentStruct) { { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &u32, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 4)); - members.push_back(create(Source{}, "bar", &u32, deco)); + deco.push_back(create(4)); + members.push_back(create("bar", &u32, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); AccessControl at{ast::AccessControl::kReadOnly, &struct_type}; EXPECT_EQ(16u, at.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, at.BaseAlignment(MemoryLayout::kStorageBuffer)); diff --git a/src/ast/type/alias_type_test.cc b/src/ast/type/alias_type_test.cc index dc34994240..6cc025b6fb 100644 --- a/src/ast/type/alias_type_test.cc +++ b/src/ast/type/alias_type_test.cc @@ -44,7 +44,7 @@ using AliasTest = TestHelper; TEST_F(AliasTest, Create) { U32 u32; - Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32}; + Alias a{mod->RegisterSymbol("a_type"), "a_type", &u32}; EXPECT_EQ(a.symbol(), Symbol(1)); // EXPECT_EQ(a.name(), "a_type"); EXPECT_EQ(a.type(), &u32); @@ -53,7 +53,7 @@ TEST_F(AliasTest, Create) { TEST_F(AliasTest, Is) { I32 i32; - Alias at{mod.RegisterSymbol("a"), "a", &i32}; + Alias at{mod->RegisterSymbol("a"), "a", &i32}; Type* ty = &at; EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); @@ -72,13 +72,13 @@ TEST_F(AliasTest, Is) { TEST_F(AliasTest, TypeName) { I32 i32; - Alias at{mod.RegisterSymbol("Particle"), "Particle", &i32}; + Alias at{mod->RegisterSymbol("Particle"), "Particle", &i32}; EXPECT_EQ(at.type_name(), "__alias_tint_symbol_1__i32"); } TEST_F(AliasTest, UnwrapIfNeeded_Alias) { U32 u32; - Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32}; + Alias a{mod->RegisterSymbol("a_type"), "a_type", &u32}; EXPECT_EQ(a.symbol(), Symbol(1)); // EXPECT_EQ(a.name(), "a_type"); EXPECT_EQ(a.type(), &u32); @@ -95,8 +95,8 @@ TEST_F(AliasTest, UnwrapIfNeeded_AccessControl) { TEST_F(AliasTest, UnwrapIfNeeded_MultiLevel) { U32 u32; - Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32}; - Alias aa{mod.RegisterSymbol("aa_type"), "aa_type", &a}; + Alias a{mod->RegisterSymbol("a_type"), "a_type", &u32}; + Alias aa{mod->RegisterSymbol("aa_type"), "aa_type", &a}; EXPECT_EQ(aa.symbol(), Symbol(2)); // EXPECT_EQ(aa.name(), "aa_type"); EXPECT_EQ(aa.type(), &a); @@ -105,7 +105,7 @@ TEST_F(AliasTest, UnwrapIfNeeded_MultiLevel) { TEST_F(AliasTest, UnwrapIfNeeded_MultiLevel_AliasAccessControl) { U32 u32; - Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32}; + Alias a{mod->RegisterSymbol("a_type"), "a_type", &u32}; AccessControl aa{ast::AccessControl::kReadWrite, &a}; EXPECT_EQ(aa.type(), &a); EXPECT_EQ(aa.UnwrapIfNeeded(), &u32); @@ -113,11 +113,11 @@ TEST_F(AliasTest, UnwrapIfNeeded_MultiLevel_AliasAccessControl) { TEST_F(AliasTest, UnwrapAll_TwiceAliasPointerTwiceAlias) { U32 u32; - Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32}; - Alias aa{mod.RegisterSymbol("aa_type"), "aa_type", &a}; + Alias a{mod->RegisterSymbol("a_type"), "a_type", &u32}; + Alias aa{mod->RegisterSymbol("aa_type"), "aa_type", &a}; Pointer paa{&aa, StorageClass::kUniform}; - Alias apaa{mod.RegisterSymbol("paa_type"), "paa_type", &paa}; - Alias aapaa{mod.RegisterSymbol("aapaa_type"), "aapaa_type", &apaa}; + Alias apaa{mod->RegisterSymbol("paa_type"), "paa_type", &paa}; + Alias aapaa{mod->RegisterSymbol("aapaa_type"), "aapaa_type", &apaa}; EXPECT_EQ(aapaa.symbol(), Symbol(4)); // EXPECT_EQ(aapaa.name(), "aapaa_type"); EXPECT_EQ(aapaa.type(), &apaa); @@ -127,23 +127,23 @@ TEST_F(AliasTest, UnwrapAll_TwiceAliasPointerTwiceAlias) { TEST_F(AliasTest, UnwrapAll_SecondConsecutivePointerBlocksUnrapping) { U32 u32; - Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32}; - Alias aa{mod.RegisterSymbol("aa_type"), "aa_type", &a}; + Alias a{mod->RegisterSymbol("a_type"), "a_type", &u32}; + Alias aa{mod->RegisterSymbol("aa_type"), "aa_type", &a}; Pointer paa{&aa, StorageClass::kUniform}; Pointer ppaa{&paa, StorageClass::kUniform}; - Alias appaa{mod.RegisterSymbol("appaa_type"), "appaa_type", &ppaa}; + Alias appaa{mod->RegisterSymbol("appaa_type"), "appaa_type", &ppaa}; EXPECT_EQ(appaa.UnwrapAll(), &paa); } TEST_F(AliasTest, UnwrapAll_SecondNonConsecutivePointerBlocksUnrapping) { U32 u32; - Alias a{mod.RegisterSymbol("a_type"), "a_type", &u32}; - Alias aa{mod.RegisterSymbol("aa_type"), "aa_type", &a}; + Alias a{mod->RegisterSymbol("a_type"), "a_type", &u32}; + Alias aa{mod->RegisterSymbol("aa_type"), "aa_type", &a}; Pointer paa{&aa, StorageClass::kUniform}; - Alias apaa{mod.RegisterSymbol("apaa_type"), "apaa_type", &paa}; - Alias aapaa{mod.RegisterSymbol("aapaa_type"), "aapaa_type", &apaa}; + Alias apaa{mod->RegisterSymbol("apaa_type"), "apaa_type", &paa}; + Alias aapaa{mod->RegisterSymbol("aapaa_type"), "aapaa_type", &apaa}; Pointer paapaa{&aapaa, StorageClass::kUniform}; - Alias apaapaa{mod.RegisterSymbol("apaapaa_type"), "apaapaa_type", &paapaa}; + Alias apaapaa{mod->RegisterSymbol("apaapaa_type"), "apaapaa_type", &paapaa}; EXPECT_EQ(apaapaa.UnwrapAll(), &paa); } @@ -167,7 +167,7 @@ TEST_F(AliasTest, UnwrapAll_PointerAccessControl) { TEST_F(AliasTest, MinBufferBindingSizeU32) { U32 u32; - Alias alias{mod.RegisterSymbol("alias"), "alias", &u32}; + Alias alias{mod->RegisterSymbol("alias"), "alias", &u32}; EXPECT_EQ(4u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } @@ -175,9 +175,9 @@ TEST_F(AliasTest, MinBufferBindingSizeArray) { U32 u32; Array array(&u32, 4, ArrayDecorationList{ - create(Source{}, 4), + create(4), }); - Alias alias{mod.RegisterSymbol("alias"), "alias", &array}; + Alias alias{mod->RegisterSymbol("alias"), "alias", &array}; EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } @@ -185,9 +185,9 @@ TEST_F(AliasTest, MinBufferBindingSizeRuntimeArray) { U32 u32; Array array(&u32, 0, ArrayDecorationList{ - create(Source{}, 4), + create(4), }); - Alias alias{mod.RegisterSymbol("alias"), "alias", &array}; + Alias alias{mod->RegisterSymbol("alias"), "alias", &array}; EXPECT_EQ(4u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } @@ -197,26 +197,26 @@ TEST_F(AliasTest, MinBufferBindingSizeStruct) { { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &u32, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 4)); - members.push_back(create(Source{}, "bar", &u32, deco)); + deco.push_back(create(4)); + members.push_back(create("bar", &u32, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); - Alias alias{mod.RegisterSymbol("alias"), "alias", &struct_type}; + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); + Alias alias{mod->RegisterSymbol("alias"), "alias", &struct_type}; EXPECT_EQ(16u, alias.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(8u, alias.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); } TEST_F(AliasTest, BaseAlignmentU32) { U32 u32; - Alias alias{mod.RegisterSymbol("alias"), "alias", &u32}; + Alias alias{mod->RegisterSymbol("alias"), "alias", &u32}; EXPECT_EQ(4u, alias.BaseAlignment(MemoryLayout::kUniformBuffer)); } @@ -224,9 +224,9 @@ TEST_F(AliasTest, BaseAlignmentArray) { U32 u32; Array array(&u32, 4, ArrayDecorationList{ - create(Source{}, 4), + create(4), }); - Alias alias{mod.RegisterSymbol("alias"), "alias", &array}; + Alias alias{mod->RegisterSymbol("alias"), "alias", &array}; EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer)); } @@ -234,9 +234,9 @@ TEST_F(AliasTest, BaseAlignmentRuntimeArray) { U32 u32; Array array(&u32, 0, ArrayDecorationList{ - create(Source{}, 4), + create(4), }); - Alias alias{mod.RegisterSymbol("alias"), "alias", &array}; + Alias alias{mod->RegisterSymbol("alias"), "alias", &array}; EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer)); } @@ -246,19 +246,19 @@ TEST_F(AliasTest, BaseAlignmentStruct) { { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &u32, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 4)); - members.push_back(create(Source{}, "bar", &u32, deco)); + deco.push_back(create(4)); + members.push_back(create("bar", &u32, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); - Alias alias{mod.RegisterSymbol("alias"), "alias", &struct_type}; + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); + Alias alias{mod->RegisterSymbol("alias"), "alias", &struct_type}; EXPECT_EQ(16u, alias.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, alias.BaseAlignment(MemoryLayout::kStorageBuffer)); } diff --git a/src/ast/type/array_type_test.cc b/src/ast/type/array_type_test.cc index 4de28df670..8d61e27f97 100644 --- a/src/ast/type/array_type_test.cc +++ b/src/ast/type/array_type_test.cc @@ -89,8 +89,7 @@ TEST_F(ArrayTest, TypeName_RuntimeArray) { TEST_F(ArrayTest, TypeName_WithStride) { I32 i32; - Array arr{&i32, 3, - ArrayDecorationList{create(Source{}, 16)}}; + Array arr{&i32, 3, ArrayDecorationList{create(16)}}; EXPECT_EQ(arr.type_name(), "__array__i32_3_stride_16"); } @@ -102,30 +101,26 @@ TEST_F(ArrayTest, MinBufferBindingSizeNoStride) { TEST_F(ArrayTest, MinBufferBindingSizeArray) { U32 u32; - Array arr(&u32, 4, - ArrayDecorationList{create(Source{}, 4)}); + Array arr(&u32, 4, ArrayDecorationList{create(4)}); EXPECT_EQ(16u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } TEST_F(ArrayTest, MinBufferBindingSizeRuntimeArray) { U32 u32; - Array arr(&u32, 0, - ArrayDecorationList{create(Source{}, 4)}); + Array arr(&u32, 0, ArrayDecorationList{create(4)}); EXPECT_EQ(4u, arr.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); } TEST_F(ArrayTest, BaseAlignmentArray) { U32 u32; - Array arr(&u32, 4, - ArrayDecorationList{create(Source{}, 4)}); + Array arr(&u32, 4, ArrayDecorationList{create(4)}); EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer)); } TEST_F(ArrayTest, BaseAlignmentRuntimeArray) { U32 u32; - Array arr(&u32, 0, - ArrayDecorationList{create(Source{}, 4)}); + Array arr(&u32, 0, ArrayDecorationList{create(4)}); EXPECT_EQ(16u, arr.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, arr.BaseAlignment(MemoryLayout::kStorageBuffer)); } diff --git a/src/ast/type/storage_texture_type_test.cc b/src/ast/type/storage_texture_type_test.cc index 0ed1e51156..c47078bb76 100644 --- a/src/ast/type/storage_texture_type_test.cc +++ b/src/ast/type/storage_texture_type_test.cc @@ -92,11 +92,10 @@ TEST_F(StorageTextureTest, TypeName) { } TEST_F(StorageTextureTest, F32) { - Module mod; - Type* s = mod.create(TextureDimension::k2dArray, - ast::AccessControl::kReadOnly, - ImageFormat::kRgba32Float); - TypeDeterminer td(&mod); + Type* s = mod->create(TextureDimension::k2dArray, + ast::AccessControl::kReadOnly, + ImageFormat::kRgba32Float); + TypeDeterminer td(mod); ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(s->Is()); @@ -105,11 +104,10 @@ TEST_F(StorageTextureTest, F32) { } TEST_F(StorageTextureTest, U32) { - Module mod; - Type* s = mod.create(TextureDimension::k2dArray, - ast::AccessControl::kReadOnly, - ImageFormat::kRg32Uint); - TypeDeterminer td(&mod); + Type* s = mod->create(TextureDimension::k2dArray, + ast::AccessControl::kReadOnly, + ImageFormat::kRg32Uint); + TypeDeterminer td(mod); ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(s->Is()); @@ -118,11 +116,10 @@ TEST_F(StorageTextureTest, U32) { } TEST_F(StorageTextureTest, I32) { - Module mod; - Type* s = mod.create(TextureDimension::k2dArray, - ast::AccessControl::kReadOnly, - ImageFormat::kRgba32Sint); - TypeDeterminer td(&mod); + Type* s = mod->create(TextureDimension::k2dArray, + ast::AccessControl::kReadOnly, + ImageFormat::kRgba32Sint); + TypeDeterminer td(mod); ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(s->Is()); diff --git a/src/ast/type/struct_type_test.cc b/src/ast/type/struct_type_test.cc index ad1131ba0b..a4d04e66f0 100644 --- a/src/ast/type/struct_type_test.cc +++ b/src/ast/type/struct_type_test.cc @@ -41,18 +41,16 @@ using StructTest = TestHelper; TEST_F(StructTest, Creation) { StructMemberList members; - auto* impl = - create(Source{}, members, ast::StructDecorationList{}); + auto* impl = create(members, ast::StructDecorationList{}); auto* ptr = impl; - Struct s{mod.RegisterSymbol("S"), "S", impl}; + Struct s{mod->RegisterSymbol("S"), "S", impl}; EXPECT_EQ(s.impl(), ptr); } TEST_F(StructTest, Is) { StructMemberList members; - auto* impl = - create(Source{}, members, ast::StructDecorationList{}); - Struct s{mod.RegisterSymbol("S"), "S", impl}; + auto* impl = create(members, ast::StructDecorationList{}); + Struct s{mod->RegisterSymbol("S"), "S", impl}; Type* ty = &s; EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); @@ -71,9 +69,8 @@ TEST_F(StructTest, Is) { TEST_F(StructTest, TypeName) { StructMemberList members; - auto* impl = - create(Source{}, members, ast::StructDecorationList{}); - Struct s{mod.RegisterSymbol("my_struct"), "my_struct", impl}; + auto* impl = create(members, ast::StructDecorationList{}); + Struct s{mod->RegisterSymbol("my_struct"), "my_struct", impl}; EXPECT_EQ(s.type_name(), "__struct_tint_symbol_1"); } @@ -83,18 +80,18 @@ TEST_F(StructTest, MinBufferBindingSize) { { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &u32, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 4)); - members.push_back(create(Source{}, "bar", &u32, deco)); + deco.push_back(create(4)); + members.push_back(create("bar", &u32, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); EXPECT_EQ(16u, struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(8u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); @@ -102,29 +99,28 @@ TEST_F(StructTest, MinBufferBindingSize) { TEST_F(StructTest, MinBufferBindingSizeArray) { U32 u32; - Array arr(&u32, 4, - ArrayDecorationList{create(Source{}, 4)}); + Array arr(&u32, 4, ArrayDecorationList{create(4)}); StructMemberList members; { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &u32, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 4)); - members.push_back(create(Source{}, "bar", &u32, deco)); + deco.push_back(create(4)); + members.push_back(create("bar", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 8)); - members.push_back(create(Source{}, "bar", &arr, deco)); + deco.push_back(create(8)); + members.push_back(create("bar", &arr, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); EXPECT_EQ(32u, struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(24u, @@ -133,29 +129,28 @@ TEST_F(StructTest, MinBufferBindingSizeArray) { TEST_F(StructTest, MinBufferBindingSizeRuntimeArray) { U32 u32; - Array arr(&u32, 0, - ArrayDecorationList{create(Source{}, 4)}); + Array arr(&u32, 0, ArrayDecorationList{create(4)}); StructMemberList members; { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &u32, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 4)); - members.push_back(create(Source{}, "bar", &u32, deco)); + deco.push_back(create(4)); + members.push_back(create("bar", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 8)); - members.push_back(create(Source{}, "bar", &u32, deco)); + deco.push_back(create(8)); + members.push_back(create("bar", &u32, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); EXPECT_EQ(12u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); } @@ -167,13 +162,13 @@ TEST_F(StructTest, MinBufferBindingSizeVec2) { StructMemberList members; { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &vec2, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &vec2, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); EXPECT_EQ(16u, struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(8u, struct_type.MinBufferBindingSize(MemoryLayout::kStorageBuffer)); @@ -186,13 +181,13 @@ TEST_F(StructTest, MinBufferBindingSizeVec3) { StructMemberList members; { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &vec3, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &vec3, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); EXPECT_EQ(16u, struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, @@ -206,13 +201,13 @@ TEST_F(StructTest, MinBufferBindingSizeVec4) { StructMemberList members; { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &vec4, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &vec4, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); EXPECT_EQ(16u, struct_type.MinBufferBindingSize(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, @@ -225,76 +220,74 @@ TEST_F(StructTest, BaseAlignment) { { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &u32, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 4)); - members.push_back(create(Source{}, "bar", &u32, deco)); + deco.push_back(create(4)); + members.push_back(create("bar", &u32, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); } TEST_F(StructTest, BaseAlignmentArray) { U32 u32; - Array arr(&u32, 4, - ArrayDecorationList{create(Source{}, 4)}); + Array arr(&u32, 4, ArrayDecorationList{create(4)}); StructMemberList members; { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &u32, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 4)); - members.push_back(create(Source{}, "bar", &u32, deco)); + deco.push_back(create(4)); + members.push_back(create("bar", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 8)); - members.push_back(create(Source{}, "bar", &arr, deco)); + deco.push_back(create(8)); + members.push_back(create("bar", &arr, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); } TEST_F(StructTest, BaseAlignmentRuntimeArray) { U32 u32; - Array arr(&u32, 0, - ArrayDecorationList{create(Source{}, 4)}); + Array arr(&u32, 0, ArrayDecorationList{create(4)}); StructMemberList members; { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &u32, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 4)); - members.push_back(create(Source{}, "bar", &u32, deco)); + deco.push_back(create(4)); + members.push_back(create("bar", &u32, deco)); } { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 8)); - members.push_back(create(Source{}, "bar", &u32, deco)); + deco.push_back(create(8)); + members.push_back(create("bar", &u32, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); EXPECT_EQ(4u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); } @@ -305,13 +298,13 @@ TEST_F(StructTest, BaseAlignmentVec2) { StructMemberList members; { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &vec2, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &vec2, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(8u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); } @@ -323,13 +316,13 @@ TEST_F(StructTest, BaseAlignmentVec3) { StructMemberList members; { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &vec3, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &vec3, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); } @@ -341,13 +334,13 @@ TEST_F(StructTest, BaseAlignmentVec4) { StructMemberList members; { StructMemberDecorationList deco; - deco.push_back(create(Source{}, 0)); - members.push_back(create(Source{}, "foo", &vec4, deco)); + deco.push_back(create(0)); + members.push_back(create("foo", &vec4, deco)); } StructDecorationList decos; - auto* str = create(Source{}, members, decos); - Struct struct_type(mod.RegisterSymbol("struct_type"), "struct_type", str); + auto* str = create(members, decos); + Struct struct_type(mod->RegisterSymbol("struct_type"), "struct_type", str); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kUniformBuffer)); EXPECT_EQ(16u, struct_type.BaseAlignment(MemoryLayout::kStorageBuffer)); } diff --git a/src/ast/type_constructor_expression_test.cc b/src/ast/type_constructor_expression_test.cc index f40139a3c7..9b51d8e88b 100644 --- a/src/ast/type_constructor_expression_test.cc +++ b/src/ast/type_constructor_expression_test.cc @@ -30,101 +30,84 @@ namespace { using TypeConstructorExpressionTest = TestHelper; TEST_F(TypeConstructorExpressionTest, Creation) { - type::F32 f32; ExpressionList expr; - expr.push_back(create( - Source{}, mod.RegisterSymbol("expr"), "expr")); + expr.push_back(Expr("expr")); - TypeConstructorExpression t(Source{}, &f32, expr); - EXPECT_EQ(t.type(), &f32); - ASSERT_EQ(t.values().size(), 1u); - EXPECT_EQ(t.values()[0], expr[0]); + auto* t = create(ty.f32, expr); + EXPECT_EQ(t->type(), ty.f32); + ASSERT_EQ(t->values().size(), 1u); + EXPECT_EQ(t->values()[0], expr[0]); } TEST_F(TypeConstructorExpressionTest, Creation_WithSource) { - type::F32 f32; ExpressionList expr; - expr.push_back(create( - Source{}, mod.RegisterSymbol("expr"), "expr")); + expr.push_back(Expr("expr")); - TypeConstructorExpression t(Source{Source::Location{20, 2}}, &f32, expr); - auto src = t.source(); + auto* t = create(Source{Source::Location{20, 2}}, + ty.f32, expr); + auto src = t->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) { - type::F32 f32; ExpressionList expr; - expr.push_back(create( - Source{}, mod.RegisterSymbol("expr"), "expr")); + expr.push_back(Expr("expr")); - TypeConstructorExpression t(Source{}, &f32, expr); - EXPECT_TRUE(t.Is()); + auto* t = create(ty.f32, expr); + EXPECT_TRUE(t->Is()); } TEST_F(TypeConstructorExpressionTest, IsValid) { - type::F32 f32; ExpressionList expr; - expr.push_back(create( - Source{}, mod.RegisterSymbol("expr"), "expr")); + expr.push_back(Expr("expr")); - TypeConstructorExpression t(Source{}, &f32, expr); - EXPECT_TRUE(t.IsValid()); + auto* t = create(ty.f32, expr); + EXPECT_TRUE(t->IsValid()); } TEST_F(TypeConstructorExpressionTest, IsValid_EmptyValue) { - type::F32 f32; ExpressionList expr; - TypeConstructorExpression t(Source{}, &f32, expr); - EXPECT_TRUE(t.IsValid()); + auto* t = create(ty.f32, expr); + EXPECT_TRUE(t->IsValid()); } TEST_F(TypeConstructorExpressionTest, IsValid_NullType) { ExpressionList expr; - expr.push_back(create( - Source{}, mod.RegisterSymbol("expr"), "expr")); + expr.push_back(Expr("expr")); - TypeConstructorExpression t(Source{}, nullptr, expr); - EXPECT_FALSE(t.IsValid()); + auto* t = create(nullptr, expr); + EXPECT_FALSE(t->IsValid()); } TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) { - type::F32 f32; ExpressionList expr; - expr.push_back(create( - Source{}, mod.RegisterSymbol("expr"), "expr")); + expr.push_back(Expr("expr")); expr.push_back(nullptr); - TypeConstructorExpression t(Source{}, &f32, expr); - EXPECT_FALSE(t.IsValid()); + auto* t = create(ty.f32, expr); + EXPECT_FALSE(t->IsValid()); } TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) { - type::F32 f32; ExpressionList expr; - expr.push_back( - create(Source{}, mod.RegisterSymbol(""), "")); + expr.push_back(Expr("")); - TypeConstructorExpression t(Source{}, &f32, expr); - EXPECT_FALSE(t.IsValid()); + auto* t = create(ty.f32, expr); + EXPECT_FALSE(t->IsValid()); } TEST_F(TypeConstructorExpressionTest, ToStr) { - type::F32 f32; - type::Vector vec(&f32, 3); + type::Vector vec(ty.f32, 3); ExpressionList expr; - expr.push_back(create( - Source{}, mod.RegisterSymbol("expr_1"), "expr_1")); - expr.push_back(create( - Source{}, mod.RegisterSymbol("expr_2"), "expr_2")); - expr.push_back(create( - Source{}, mod.RegisterSymbol("expr_3"), "expr_3")); + expr.push_back(Expr("expr_1")); + expr.push_back(Expr("expr_2")); + expr.push_back(Expr("expr_3")); - TypeConstructorExpression t(Source{}, &vec, expr); + auto* t = create(&vec, expr); std::ostringstream out; - t.to_str(out, 2); + t->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( TypeConstructor[not set]{ __vec_3__f32 Identifier[not set]{expr_1} diff --git a/src/ast/uint_literal_test.cc b/src/ast/uint_literal_test.cc index 6090de1915..1197ba707d 100644 --- a/src/ast/uint_literal_test.cc +++ b/src/ast/uint_literal_test.cc @@ -28,16 +28,13 @@ namespace { using UintLiteralTest = TestHelper; TEST_F(UintLiteralTest, Value) { - type::U32 u32; - UintLiteral u{Source{}, &u32, 47}; - ASSERT_TRUE(u.Is()); - EXPECT_EQ(u.value(), 47u); + auto* u = create(ty.u32, 47); + ASSERT_TRUE(u->Is()); + EXPECT_EQ(u->value(), 47u); } TEST_F(UintLiteralTest, Is) { - type::U32 u32; - UintLiteral u{Source{}, &u32, 42}; - Literal* l = &u; + ast::Literal* l = create(ty.u32, 42); EXPECT_FALSE(l->Is()); EXPECT_FALSE(l->Is()); EXPECT_FALSE(l->Is()); @@ -46,9 +43,8 @@ TEST_F(UintLiteralTest, Is) { } TEST_F(UintLiteralTest, ToStr) { - type::U32 u32; - UintLiteral u{Source{}, &u32, 42}; - EXPECT_EQ(u.to_str(), "42"); + auto* u = create(ty.u32, 42); + EXPECT_EQ(u->to_str(), "42"); } } // namespace diff --git a/src/ast/unary_op_expression_test.cc b/src/ast/unary_op_expression_test.cc index 10b45ffe9d..9b0717ae3c 100644 --- a/src/ast/unary_op_expression_test.cc +++ b/src/ast/unary_op_expression_test.cc @@ -26,55 +26,50 @@ namespace { using UnaryOpExpressionTest = TestHelper; TEST_F(UnaryOpExpressionTest, Creation) { - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); + auto* ident = Expr("ident"); - UnaryOpExpression u(Source{}, UnaryOp::kNot, ident); - EXPECT_EQ(u.op(), UnaryOp::kNot); - EXPECT_EQ(u.expr(), ident); + auto* u = create(UnaryOp::kNot, ident); + EXPECT_EQ(u->op(), UnaryOp::kNot); + EXPECT_EQ(u->expr(), ident); } TEST_F(UnaryOpExpressionTest, Creation_WithSource) { - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); - UnaryOpExpression u(Source{Source::Location{20, 2}}, UnaryOp::kNot, ident); - auto src = u.source(); + auto* ident = Expr("ident"); + auto* u = create(Source{Source::Location{20, 2}}, + UnaryOp::kNot, ident); + auto src = u->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(UnaryOpExpressionTest, IsUnaryOp) { - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); - UnaryOpExpression u(Source{}, UnaryOp::kNot, ident); - EXPECT_TRUE(u.Is()); + auto* ident = Expr("ident"); + auto* u = create(UnaryOp::kNot, ident); + EXPECT_TRUE(u->Is()); } TEST_F(UnaryOpExpressionTest, IsValid) { - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); - UnaryOpExpression u(Source{}, UnaryOp::kNot, ident); - EXPECT_TRUE(u.IsValid()); + auto* ident = Expr("ident"); + auto* u = create(UnaryOp::kNot, ident); + EXPECT_TRUE(u->IsValid()); } TEST_F(UnaryOpExpressionTest, IsValid_NullExpression) { - UnaryOpExpression u(Source{}, UnaryOp::kNot, nullptr); - EXPECT_FALSE(u.IsValid()); + auto* u = create(UnaryOp::kNot, nullptr); + EXPECT_FALSE(u->IsValid()); } TEST_F(UnaryOpExpressionTest, IsValid_InvalidExpression) { - auto* ident = - create(Source{}, mod.RegisterSymbol(""), ""); - UnaryOpExpression u(Source{}, UnaryOp::kNot, ident); - EXPECT_FALSE(u.IsValid()); + auto* ident = Expr(""); + auto* u = create(UnaryOp::kNot, ident); + EXPECT_FALSE(u->IsValid()); } TEST_F(UnaryOpExpressionTest, ToStr) { - auto* ident = create( - Source{}, mod.RegisterSymbol("ident"), "ident"); - UnaryOpExpression u(Source{}, UnaryOp::kNot, ident); + auto* ident = Expr("ident"); + auto* u = create(UnaryOp::kNot, ident); std::ostringstream out; - u.to_str(out, 2); + u->to_str(out, 2); EXPECT_EQ(demangle(out.str()), R"( UnaryOp[not set]{ not Identifier[not set]{ident} diff --git a/src/ast/variable_decl_statement_test.cc b/src/ast/variable_decl_statement_test.cc index edc7d97aeb..67289f69a0 100644 --- a/src/ast/variable_decl_statement_test.cc +++ b/src/ast/variable_decl_statement_test.cc @@ -25,63 +25,53 @@ namespace { using VariableDeclStatementTest = TestHelper; TEST_F(VariableDeclStatementTest, Creation) { - type::F32 f32; - auto* var = create(Source{}, "a", StorageClass::kNone, &f32, false, - nullptr, ast::VariableDecorationList{}); + auto* var = Var("a", StorageClass::kNone, ty.f32); - VariableDeclStatement stmt(Source{}, var); - EXPECT_EQ(stmt.variable(), var); + auto* stmt = create(var); + EXPECT_EQ(stmt->variable(), var); } TEST_F(VariableDeclStatementTest, Creation_WithSource) { - type::F32 f32; - auto* var = create(Source{}, "a", StorageClass::kNone, &f32, false, - nullptr, ast::VariableDecorationList{}); + auto* var = Var("a", StorageClass::kNone, ty.f32); - VariableDeclStatement stmt(Source{Source::Location{20, 2}}, var); - auto src = stmt.source(); + auto* stmt = + create(Source{Source::Location{20, 2}}, var); + auto src = stmt->source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(VariableDeclStatementTest, IsVariableDecl) { - type::F32 f32; - auto* var = create(Source{}, "a", StorageClass::kNone, &f32, false, - nullptr, ast::VariableDecorationList{}); + auto* var = Var("a", StorageClass::kNone, ty.f32); - VariableDeclStatement stmt(Source{}, var); - EXPECT_TRUE(stmt.Is()); + auto* stmt = create(var); + EXPECT_TRUE(stmt->Is()); } TEST_F(VariableDeclStatementTest, IsValid) { - type::F32 f32; - auto* var = create(Source{}, "a", StorageClass::kNone, &f32, false, - nullptr, ast::VariableDecorationList{}); - VariableDeclStatement stmt(Source{}, var); - EXPECT_TRUE(stmt.IsValid()); + auto* var = Var("a", StorageClass::kNone, ty.f32); + auto* stmt = create(var); + EXPECT_TRUE(stmt->IsValid()); } TEST_F(VariableDeclStatementTest, IsValid_InvalidVariable) { - type::F32 f32; - auto* var = create(Source{}, "", StorageClass::kNone, &f32, false, - nullptr, ast::VariableDecorationList{}); - VariableDeclStatement stmt(Source{}, var); - EXPECT_FALSE(stmt.IsValid()); + auto* var = Var("", StorageClass::kNone, ty.f32); + auto* stmt = create(var); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(VariableDeclStatementTest, IsValid_NullVariable) { - VariableDeclStatement stmt(Source{}, nullptr); - EXPECT_FALSE(stmt.IsValid()); + auto* stmt = create(nullptr); + EXPECT_FALSE(stmt->IsValid()); } TEST_F(VariableDeclStatementTest, ToStr) { - type::F32 f32; - auto* var = create(Source{}, "a", StorageClass::kNone, &f32, false, - nullptr, ast::VariableDecorationList{}); + auto* var = Var("a", StorageClass::kNone, ty.f32); - VariableDeclStatement stmt(Source{Source::Location{20, 2}}, var); + auto* stmt = + create(Source{Source::Location{20, 2}}, var); std::ostringstream out; - stmt.to_str(out, 2); + stmt->to_str(out, 2); EXPECT_EQ(out.str(), R"( VariableDeclStatement{ Variable{ a diff --git a/src/ast/variable_test.cc b/src/ast/variable_test.cc index 778b4b7001..3004d31018 100644 --- a/src/ast/variable_test.cc +++ b/src/ast/variable_test.cc @@ -27,106 +27,83 @@ namespace { using VariableTest = TestHelper; TEST_F(VariableTest, Creation) { - type::I32 t; - Variable v(Source{}, "my_var", StorageClass::kFunction, &t, false, nullptr, - ast::VariableDecorationList{}); + auto* v = Var("my_var", StorageClass::kFunction, ty.i32); - EXPECT_EQ(v.name(), "my_var"); - EXPECT_EQ(v.storage_class(), StorageClass::kFunction); - EXPECT_EQ(v.type(), &t); - EXPECT_EQ(v.source().range.begin.line, 0u); - EXPECT_EQ(v.source().range.begin.column, 0u); - EXPECT_EQ(v.source().range.end.line, 0u); - EXPECT_EQ(v.source().range.end.column, 0u); + EXPECT_EQ(v->name(), "my_var"); + EXPECT_EQ(v->storage_class(), StorageClass::kFunction); + EXPECT_EQ(v->type(), ty.i32); + EXPECT_EQ(v->source().range.begin.line, 0u); + EXPECT_EQ(v->source().range.begin.column, 0u); + EXPECT_EQ(v->source().range.end.line, 0u); + EXPECT_EQ(v->source().range.end.column, 0u); } TEST_F(VariableTest, CreationWithSource) { - Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}; - type::F32 t; - Variable v(s, "i", StorageClass::kPrivate, &t, false, nullptr, - ast::VariableDecorationList{}); + auto* v = Var( + Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, + "i", StorageClass::kPrivate, ty.f32, nullptr, VariableDecorationList{}); - EXPECT_EQ(v.name(), "i"); - EXPECT_EQ(v.storage_class(), StorageClass::kPrivate); - EXPECT_EQ(v.type(), &t); - EXPECT_EQ(v.source().range.begin.line, 27u); - EXPECT_EQ(v.source().range.begin.column, 4u); - EXPECT_EQ(v.source().range.end.line, 27u); - EXPECT_EQ(v.source().range.end.column, 5u); + EXPECT_EQ(v->name(), "i"); + EXPECT_EQ(v->storage_class(), StorageClass::kPrivate); + EXPECT_EQ(v->type(), ty.f32); + EXPECT_EQ(v->source().range.begin.line, 27u); + EXPECT_EQ(v->source().range.begin.column, 4u); + EXPECT_EQ(v->source().range.end.line, 27u); + EXPECT_EQ(v->source().range.end.column, 5u); } TEST_F(VariableTest, CreationEmpty) { - type::I32 t; - Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}; - Variable v(s, "a_var", StorageClass::kWorkgroup, &t, false, nullptr, - ast::VariableDecorationList{}); + auto* v = Var( + Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, + "a_var", StorageClass::kWorkgroup, ty.i32, nullptr, + VariableDecorationList{}); - EXPECT_EQ(v.name(), "a_var"); - EXPECT_EQ(v.storage_class(), StorageClass::kWorkgroup); - EXPECT_EQ(v.type(), &t); - EXPECT_EQ(v.source().range.begin.line, 27u); - EXPECT_EQ(v.source().range.begin.column, 4u); - EXPECT_EQ(v.source().range.end.line, 27u); - EXPECT_EQ(v.source().range.end.column, 7u); + EXPECT_EQ(v->name(), "a_var"); + EXPECT_EQ(v->storage_class(), StorageClass::kWorkgroup); + EXPECT_EQ(v->type(), ty.i32); + EXPECT_EQ(v->source().range.begin.line, 27u); + EXPECT_EQ(v->source().range.begin.column, 4u); + EXPECT_EQ(v->source().range.end.line, 27u); + EXPECT_EQ(v->source().range.end.column, 7u); } TEST_F(VariableTest, IsValid) { - type::I32 t; - Variable v{Source{}, "my_var", StorageClass::kNone, &t, - false, nullptr, ast::VariableDecorationList{}}; - EXPECT_TRUE(v.IsValid()); + auto* v = Var("my_var", StorageClass::kNone, ty.i32); + EXPECT_TRUE(v->IsValid()); } TEST_F(VariableTest, IsValid_WithConstructor) { - type::I32 t; - Variable v{Source{}, - "my_var", - StorageClass::kNone, - &t, - false, - create(Source{}, mod.RegisterSymbol("ident"), - "ident"), - ast::VariableDecorationList{}}; - EXPECT_TRUE(v.IsValid()); + auto* v = Var("my_var", StorageClass::kNone, ty.i32, Expr("ident"), + ast::VariableDecorationList{}); + EXPECT_TRUE(v->IsValid()); } TEST_F(VariableTest, IsValid_MissinName) { - type::I32 t; - Variable v{Source{}, "", StorageClass::kNone, &t, - false, nullptr, ast::VariableDecorationList{}}; - EXPECT_FALSE(v.IsValid()); + auto* v = Var("", StorageClass::kNone, ty.i32); + EXPECT_FALSE(v->IsValid()); } TEST_F(VariableTest, IsValid_MissingType) { - Variable v{Source{}, "x", StorageClass::kNone, nullptr, - false, nullptr, ast::VariableDecorationList{}}; - EXPECT_FALSE(v.IsValid()); + auto* v = Var("x", StorageClass::kNone, nullptr); + EXPECT_FALSE(v->IsValid()); } TEST_F(VariableTest, IsValid_MissingBoth) { - Variable v{Source{}, "", StorageClass::kNone, nullptr, - false, nullptr, ast::VariableDecorationList{}}; - EXPECT_FALSE(v.IsValid()); + auto* v = Var("", StorageClass::kNone, nullptr); + EXPECT_FALSE(v->IsValid()); } TEST_F(VariableTest, IsValid_InvalidConstructor) { - type::I32 t; - Variable v{Source{}, - "my_var", - StorageClass::kNone, - &t, - false, - create(Source{}, mod.RegisterSymbol(""), ""), - ast::VariableDecorationList{}}; - EXPECT_FALSE(v.IsValid()); + auto* v = Var("my_var", StorageClass::kNone, ty.i32, Expr(""), + ast::VariableDecorationList{}); + EXPECT_FALSE(v->IsValid()); } TEST_F(VariableTest, to_str) { - type::F32 t; - Variable v{Source{}, "my_var", StorageClass::kFunction, &t, - false, nullptr, ast::VariableDecorationList{}}; + auto* v = Var("my_var", StorageClass::kFunction, ty.f32, nullptr, + ast::VariableDecorationList{}); std::ostringstream out; - v.to_str(out, 2); + v->to_str(out, 2); EXPECT_EQ(out.str(), R"( Variable{ my_var function @@ -136,14 +113,12 @@ TEST_F(VariableTest, to_str) { } TEST_F(VariableTest, WithDecorations) { - type::F32 t; - auto* var = create( - Source{}, "my_var", StorageClass::kFunction, &t, false, nullptr, - VariableDecorationList{ - create(Source{}, 1), - create(Source{}, Builtin::kPosition), - create(Source{}, 1200), - }); + auto* var = Var("my_var", StorageClass::kFunction, ty.i32, nullptr, + VariableDecorationList{ + create(1), + create(Builtin::kPosition), + create(1200), + }); EXPECT_TRUE(var->HasLocationDecoration()); EXPECT_TRUE(var->HasBuiltinDecoration()); @@ -151,26 +126,20 @@ TEST_F(VariableTest, WithDecorations) { } TEST_F(VariableTest, ConstantId) { - type::F32 t; - auto* var = create(Source{}, "my_var", StorageClass::kFunction, &t, - false, nullptr, - VariableDecorationList{ - create(Source{}, 1200), - }); + auto* var = Var("my_var", StorageClass::kFunction, ty.i32, nullptr, + VariableDecorationList{ + create(1200), + }); EXPECT_EQ(var->constant_id(), 1200u); } TEST_F(VariableTest, Decorated_to_str) { - type::F32 t; - auto* var = - create(Source{}, "my_var", StorageClass::kFunction, &t, false, - create( - Source{}, mod.RegisterSymbol("expr"), "expr"), - VariableDecorationList{ - create(Source{}, 2), - create(Source{}, 1), - }); + auto* var = Var("my_var", StorageClass::kFunction, ty.f32, Expr("expr"), + VariableDecorationList{ + create(2), + create(1), + }); std::ostringstream out; var->to_str(out, 2); diff --git a/src/ast/workgroup_decoration_test.cc b/src/ast/workgroup_decoration_test.cc index b45dff8c6d..4a749f1c0f 100644 --- a/src/ast/workgroup_decoration_test.cc +++ b/src/ast/workgroup_decoration_test.cc @@ -26,48 +26,47 @@ namespace { using WorkgroupDecorationTest = TestHelper; TEST_F(WorkgroupDecorationTest, Creation_1param) { - WorkgroupDecoration d{Source{}, 2}; + auto* d = create(2); uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - std::tie(x, y, z) = d.values(); + std::tie(x, y, z) = d->values(); EXPECT_EQ(x, 2u); EXPECT_EQ(y, 1u); EXPECT_EQ(z, 1u); } TEST_F(WorkgroupDecorationTest, Creation_2param) { - WorkgroupDecoration d{Source{}, 2, 4}; + auto* d = create(2, 4); uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - std::tie(x, y, z) = d.values(); + std::tie(x, y, z) = d->values(); EXPECT_EQ(x, 2u); EXPECT_EQ(y, 4u); EXPECT_EQ(z, 1u); } TEST_F(WorkgroupDecorationTest, Creation_3param) { - WorkgroupDecoration d{Source{}, 2, 4, 6}; + auto* d = create(2, 4, 6); uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - std::tie(x, y, z) = d.values(); + std::tie(x, y, z) = d->values(); EXPECT_EQ(x, 2u); EXPECT_EQ(y, 4u); EXPECT_EQ(z, 6u); } TEST_F(WorkgroupDecorationTest, Is) { - WorkgroupDecoration wd{Source{}, 2, 4, 6}; - Decoration* d = &wd; + Decoration* d = create(2, 4, 6); EXPECT_TRUE(d->Is()); EXPECT_FALSE(d->Is()); } TEST_F(WorkgroupDecorationTest, ToStr) { - WorkgroupDecoration d{Source{}, 2, 4, 6}; + auto* d = create(2, 4, 6); std::ostringstream out; - d.to_str(out, 0); + d->to_str(out, 0); EXPECT_EQ(out.str(), R"(WorkgroupDecoration{2 4 6} )"); }