From 4c88cd93ec6c68344213c0d614d77074443818d7 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 13 Nov 2020 22:23:05 +0000 Subject: [PATCH] writer/msl tests: Replace std::make_unique -> create create() is currently just a simple forwarder to std::make_unique<>, but will be later replaced with a function that returns a raw pointer, and owned by the context. Bug: tint:322 Change-Id: I1756981b206c125d1dbf78ac178e0a7b60ec2941 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32672 Commit-Queue: Ben Clayton Reviewed-by: dan sinclair --- .../msl/generator_impl_alias_type_test.cc | 24 +- .../msl/generator_impl_array_accessor_test.cc | 10 +- src/writer/msl/generator_impl_assign_test.cc | 4 +- src/writer/msl/generator_impl_binary_test.cc | 4 +- src/writer/msl/generator_impl_bitcast_test.cc | 2 +- src/writer/msl/generator_impl_block_test.cc | 4 +- src/writer/msl/generator_impl_call_test.cc | 25 +- src/writer/msl/generator_impl_case_test.cc | 28 +- src/writer/msl/generator_impl_cast_test.cc | 4 +- .../msl/generator_impl_constructor_test.cc | 94 +-- ...tor_impl_function_entry_point_data_test.cc | 231 +++--- .../msl/generator_impl_function_test.cc | 698 ++++++++---------- src/writer/msl/generator_impl_if_test.cc | 56 +- src/writer/msl/generator_impl_import_test.cc | 119 ++- .../msl/generator_impl_intrinsic_test.cc | 21 +- src/writer/msl/generator_impl_loop_test.cc | 62 +- .../generator_impl_member_accessor_test.cc | 4 +- .../generator_impl_module_constant_test.cc | 27 +- src/writer/msl/generator_impl_return_test.cc | 2 +- src/writer/msl/generator_impl_switch_test.cc | 18 +- src/writer/msl/generator_impl_test.cc | 67 +- src/writer/msl/generator_impl_type_test.cc | 65 +- .../msl/generator_impl_unary_op_test.cc | 2 +- ...rator_impl_variable_decl_statement_test.cc | 42 +- src/writer/msl/test_helper.h | 14 +- 25 files changed, 741 insertions(+), 886 deletions(-) diff --git a/src/writer/msl/generator_impl_alias_type_test.cc b/src/writer/msl/generator_impl_alias_type_test.cc index 25aa4d3623..68df2842f2 100644 --- a/src/writer/msl/generator_impl_alias_type_test.cc +++ b/src/writer/msl/generator_impl_alias_type_test.cc @@ -54,16 +54,14 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_Struct) { ast::type::F32Type f32; ast::StructMemberList members; - members.push_back(std::make_unique( - "a", &f32, ast::StructMemberDecorationList{})); + members.push_back( + create("a", &f32, ast::StructMemberDecorationList{})); ast::StructMemberDecorationList b_deco; - b_deco.push_back( - std::make_unique(4, Source{})); - members.push_back( - std::make_unique("b", &i32, std::move(b_deco))); + b_deco.push_back(create(4, Source{})); + members.push_back(create("b", &i32, std::move(b_deco))); - auto str = std::make_unique(); + auto str = create(); str->set_members(std::move(members)); ast::type::StructType s("a", std::move(str)); @@ -81,16 +79,14 @@ TEST_F(MslGeneratorImplTest, EmitConstructedType_AliasStructIdent) { ast::type::F32Type f32; ast::StructMemberList members; - members.push_back(std::make_unique( - "a", &f32, ast::StructMemberDecorationList{})); + members.push_back( + create("a", &f32, ast::StructMemberDecorationList{})); ast::StructMemberDecorationList b_deco; - b_deco.push_back( - std::make_unique(4, Source{})); - members.push_back( - std::make_unique("b", &i32, std::move(b_deco))); + b_deco.push_back(create(4, Source{})); + members.push_back(create("b", &i32, std::move(b_deco))); - auto str = std::make_unique(); + auto str = create(); str->set_members(std::move(members)); ast::type::StructType s("b", std::move(str)); diff --git a/src/writer/msl/generator_impl_array_accessor_test.cc b/src/writer/msl/generator_impl_array_accessor_test.cc index 88ef333d7c..7cf559ccd7 100644 --- a/src/writer/msl/generator_impl_array_accessor_test.cc +++ b/src/writer/msl/generator_impl_array_accessor_test.cc @@ -33,9 +33,9 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, EmitExpression_ArrayAccessor) { ast::type::I32Type i32; - auto lit = std::make_unique(&i32, 5); - auto idx = std::make_unique(std::move(lit)); - auto ary = std::make_unique("ary"); + auto lit = create(&i32, 5); + auto idx = create(std::move(lit)); + auto ary = create("ary"); ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx)); @@ -44,8 +44,8 @@ TEST_F(MslGeneratorImplTest, EmitExpression_ArrayAccessor) { } TEST_F(MslGeneratorImplTest, EmitArrayAccessor) { - auto ary = std::make_unique("ary"); - auto idx = std::make_unique("idx"); + auto ary = create("ary"); + auto idx = create("idx"); ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx)); diff --git a/src/writer/msl/generator_impl_assign_test.cc b/src/writer/msl/generator_impl_assign_test.cc index 33c8844fef..3518795236 100644 --- a/src/writer/msl/generator_impl_assign_test.cc +++ b/src/writer/msl/generator_impl_assign_test.cc @@ -30,8 +30,8 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Assign) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); ast::AssignmentStatement assign(std::move(lhs), std::move(rhs)); gen.increment_indent(); diff --git a/src/writer/msl/generator_impl_binary_test.cc b/src/writer/msl/generator_impl_binary_test.cc index bd39002f83..43ce820660 100644 --- a/src/writer/msl/generator_impl_binary_test.cc +++ b/src/writer/msl/generator_impl_binary_test.cc @@ -38,8 +38,8 @@ using MslBinaryTest = TestParamHelper; TEST_P(MslBinaryTest, Emit) { auto params = GetParam(); - auto left = std::make_unique("left"); - auto right = std::make_unique("right"); + auto left = create("left"); + auto right = create("right"); ast::BinaryExpression expr(params.op, std::move(left), std::move(right)); diff --git a/src/writer/msl/generator_impl_bitcast_test.cc b/src/writer/msl/generator_impl_bitcast_test.cc index b51dc4df30..f20338cae6 100644 --- a/src/writer/msl/generator_impl_bitcast_test.cc +++ b/src/writer/msl/generator_impl_bitcast_test.cc @@ -31,7 +31,7 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, EmitExpression_Bitcast) { ast::type::F32Type f32; - auto id = std::make_unique("id"); + auto id = create("id"); ast::BitcastExpression bitcast(&f32, std::move(id)); ASSERT_TRUE(gen.EmitExpression(&bitcast)) << gen.error(); diff --git a/src/writer/msl/generator_impl_block_test.cc b/src/writer/msl/generator_impl_block_test.cc index 8bc146a29b..4e4cf2b0ab 100644 --- a/src/writer/msl/generator_impl_block_test.cc +++ b/src/writer/msl/generator_impl_block_test.cc @@ -29,7 +29,7 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Block) { ast::BlockStatement b; - b.append(std::make_unique()); + b.append(create()); gen.increment_indent(); @@ -42,7 +42,7 @@ TEST_F(MslGeneratorImplTest, Emit_Block) { TEST_F(MslGeneratorImplTest, Emit_Block_WithoutNewline) { ast::BlockStatement b; - b.append(std::make_unique()); + b.append(create()); gen.increment_indent(); diff --git a/src/writer/msl/generator_impl_call_test.cc b/src/writer/msl/generator_impl_call_test.cc index 5254542eb0..e01f87bf20 100644 --- a/src/writer/msl/generator_impl_call_test.cc +++ b/src/writer/msl/generator_impl_call_test.cc @@ -34,11 +34,10 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) { ast::type::VoidType void_type; - auto id = std::make_unique("my_func"); + auto id = create("my_func"); ast::CallExpression call(std::move(id), {}); - auto func = std::make_unique("my_func", ast::VariableList{}, - &void_type); + auto func = create("my_func", ast::VariableList{}, &void_type); mod.AddFunction(std::move(func)); ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error(); @@ -48,14 +47,13 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) { TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) { ast::type::VoidType void_type; - auto id = std::make_unique("my_func"); + auto id = create("my_func"); ast::ExpressionList params; - params.push_back(std::make_unique("param1")); - params.push_back(std::make_unique("param2")); + params.push_back(create("param1")); + params.push_back(create("param2")); ast::CallExpression call(std::move(id), std::move(params)); - auto func = std::make_unique("my_func", ast::VariableList{}, - &void_type); + auto func = create("my_func", ast::VariableList{}, &void_type); mod.AddFunction(std::move(func)); ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error(); @@ -65,15 +63,14 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) { TEST_F(MslGeneratorImplTest, EmitStatement_Call) { ast::type::VoidType void_type; - auto id = std::make_unique("my_func"); + auto id = create("my_func"); ast::ExpressionList params; - params.push_back(std::make_unique("param1")); - params.push_back(std::make_unique("param2")); + params.push_back(create("param1")); + params.push_back(create("param2")); ast::CallStatement call( - std::make_unique(std::move(id), std::move(params))); + create(std::move(id), std::move(params))); - auto func = std::make_unique("my_func", ast::VariableList{}, - &void_type); + auto func = create("my_func", ast::VariableList{}, &void_type); mod.AddFunction(std::move(func)); gen.increment_indent(); diff --git a/src/writer/msl/generator_impl_case_test.cc b/src/writer/msl/generator_impl_case_test.cc index a35e8977d9..9902a4d604 100644 --- a/src/writer/msl/generator_impl_case_test.cc +++ b/src/writer/msl/generator_impl_case_test.cc @@ -35,11 +35,11 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Case) { ast::type::I32Type i32; - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); ast::CaseSelectorList lit; - lit.push_back(std::make_unique(&i32, 5)); + lit.push_back(create(&i32, 5)); ast::CaseStatement c(std::move(lit), std::move(body)); gen.increment_indent(); @@ -55,8 +55,8 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) { ast::type::I32Type i32; ast::CaseSelectorList lit; - lit.push_back(std::make_unique(&i32, 5)); - ast::CaseStatement c(std::move(lit), std::make_unique()); + lit.push_back(create(&i32, 5)); + ast::CaseStatement c(std::move(lit), create()); gen.increment_indent(); @@ -70,11 +70,11 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) { TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) { ast::type::I32Type i32; - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); ast::CaseSelectorList lit; - lit.push_back(std::make_unique(&i32, 5)); + lit.push_back(create(&i32, 5)); ast::CaseStatement c(std::move(lit), std::move(body)); gen.increment_indent(); @@ -89,12 +89,12 @@ TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) { TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) { ast::type::I32Type i32; - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); ast::CaseSelectorList lit; - lit.push_back(std::make_unique(&i32, 5)); - lit.push_back(std::make_unique(&i32, 6)); + lit.push_back(create(&i32, 5)); + lit.push_back(create(&i32, 6)); ast::CaseStatement c(std::move(lit), std::move(body)); gen.increment_indent(); @@ -110,8 +110,8 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) { TEST_F(MslGeneratorImplTest, Emit_Case_Default) { ast::CaseStatement c; - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); c.set_body(std::move(body)); gen.increment_indent(); diff --git a/src/writer/msl/generator_impl_cast_test.cc b/src/writer/msl/generator_impl_cast_test.cc index cc24552d91..eefa7a33f1 100644 --- a/src/writer/msl/generator_impl_cast_test.cc +++ b/src/writer/msl/generator_impl_cast_test.cc @@ -34,7 +34,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Scalar) { ast::type::F32Type f32; ast::ExpressionList params; - params.push_back(std::make_unique("id")); + params.push_back(create("id")); ast::TypeConstructorExpression cast(&f32, std::move(params)); @@ -47,7 +47,7 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Cast_Vector) { ast::type::VectorType vec3(&f32, 3); ast::ExpressionList params; - params.push_back(std::make_unique("id")); + params.push_back(create("id")); ast::TypeConstructorExpression cast(&vec3, std::move(params)); diff --git a/src/writer/msl/generator_impl_constructor_test.cc b/src/writer/msl/generator_impl_constructor_test.cc index 705cd52d92..4ca41d8f11 100644 --- a/src/writer/msl/generator_impl_constructor_test.cc +++ b/src/writer/msl/generator_impl_constructor_test.cc @@ -39,7 +39,7 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, EmitConstructor_Bool) { ast::type::BoolType bool_type; - auto lit = std::make_unique(&bool_type, false); + auto lit = create(&bool_type, false); ast::ScalarConstructorExpression expr(std::move(lit)); ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error(); @@ -48,7 +48,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Bool) { TEST_F(MslGeneratorImplTest, EmitConstructor_Int) { ast::type::I32Type i32; - auto lit = std::make_unique(&i32, -12345); + auto lit = create(&i32, -12345); ast::ScalarConstructorExpression expr(std::move(lit)); ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error(); @@ -57,7 +57,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Int) { TEST_F(MslGeneratorImplTest, EmitConstructor_UInt) { ast::type::U32Type u32; - auto lit = std::make_unique(&u32, 56779); + auto lit = create(&u32, 56779); ast::ScalarConstructorExpression expr(std::move(lit)); ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error(); @@ -67,8 +67,7 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_UInt) { TEST_F(MslGeneratorImplTest, EmitConstructor_Float) { ast::type::F32Type f32; // Use a number close to 1<<30 but whose decimal representation ends in 0. - auto lit = std::make_unique( - &f32, static_cast((1 << 30) - 4)); + auto lit = create(&f32, static_cast((1 << 30) - 4)); ast::ScalarConstructorExpression expr(std::move(lit)); ASSERT_TRUE(gen.EmitConstructor(&expr)) << gen.error(); @@ -78,10 +77,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Float) { TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Float) { ast::type::F32Type f32; - auto lit = std::make_unique(&f32, -1.2e-5); + auto lit = create(&f32, -1.2e-5); ast::ExpressionList values; - values.push_back( - std::make_unique(std::move(lit))); + values.push_back(create(std::move(lit))); ast::TypeConstructorExpression expr(&f32, std::move(values)); @@ -92,10 +90,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Float) { TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Bool) { ast::type::BoolType b; - auto lit = std::make_unique(&b, true); + auto lit = create(&b, true); ast::ExpressionList values; - values.push_back( - std::make_unique(std::move(lit))); + values.push_back(create(std::move(lit))); ast::TypeConstructorExpression expr(&b, std::move(values)); @@ -106,10 +103,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Bool) { TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Int) { ast::type::I32Type i32; - auto lit = std::make_unique(&i32, -12345); + auto lit = create(&i32, -12345); ast::ExpressionList values; - values.push_back( - std::make_unique(std::move(lit))); + values.push_back(create(std::move(lit))); ast::TypeConstructorExpression expr(&i32, std::move(values)); @@ -120,10 +116,9 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Int) { TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Uint) { ast::type::U32Type u32; - auto lit = std::make_unique(&u32, 12345); + auto lit = create(&u32, 12345); ast::ExpressionList values; - values.push_back( - std::make_unique(std::move(lit))); + values.push_back(create(std::move(lit))); ast::TypeConstructorExpression expr(&u32, std::move(values)); @@ -135,16 +130,13 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Vec) { ast::type::F32Type f32; ast::type::VectorType vec(&f32, 3); - auto lit1 = std::make_unique(&f32, 1.f); - auto lit2 = std::make_unique(&f32, 2.f); - auto lit3 = std::make_unique(&f32, 3.f); + auto lit1 = create(&f32, 1.f); + auto lit2 = create(&f32, 2.f); + auto lit3 = create(&f32, 3.f); ast::ExpressionList values; - values.push_back( - std::make_unique(std::move(lit1))); - values.push_back( - std::make_unique(std::move(lit2))); - values.push_back( - std::make_unique(std::move(lit3))); + values.push_back(create(std::move(lit1))); + values.push_back(create(std::move(lit2))); + values.push_back(create(std::move(lit3))); ast::TypeConstructorExpression expr(&vec, std::move(values)); @@ -174,23 +166,20 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Mat) { ast::ExpressionList mat_values; for (size_t i = 0; i < 2; i++) { - auto lit1 = std::make_unique( - &f32, static_cast(1 + (i * 2))); - auto lit2 = std::make_unique( - &f32, static_cast(2 + (i * 2))); - auto lit3 = std::make_unique( - &f32, static_cast(3 + (i * 2))); + auto lit1 = + create(&f32, static_cast(1 + (i * 2))); + auto lit2 = + create(&f32, static_cast(2 + (i * 2))); + auto lit3 = + create(&f32, static_cast(3 + (i * 2))); ast::ExpressionList values; - values.push_back( - std::make_unique(std::move(lit1))); - values.push_back( - std::make_unique(std::move(lit2))); - values.push_back( - std::make_unique(std::move(lit3))); + values.push_back(create(std::move(lit1))); + values.push_back(create(std::move(lit2))); + values.push_back(create(std::move(lit3))); - mat_values.push_back(std::make_unique( - &vec, std::move(values))); + mat_values.push_back( + create(&vec, std::move(values))); } ast::TypeConstructorExpression expr(&mat, std::move(mat_values)); @@ -212,23 +201,20 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Array) { ast::ExpressionList ary_values; for (size_t i = 0; i < 3; i++) { - auto lit1 = std::make_unique( - &f32, static_cast(1 + (i * 3))); - auto lit2 = std::make_unique( - &f32, static_cast(2 + (i * 3))); - auto lit3 = std::make_unique( - &f32, static_cast(3 + (i * 3))); + auto lit1 = + create(&f32, static_cast(1 + (i * 3))); + auto lit2 = + create(&f32, static_cast(2 + (i * 3))); + auto lit3 = + create(&f32, static_cast(3 + (i * 3))); ast::ExpressionList values; - values.push_back( - std::make_unique(std::move(lit1))); - values.push_back( - std::make_unique(std::move(lit2))); - values.push_back( - std::make_unique(std::move(lit3))); + values.push_back(create(std::move(lit1))); + values.push_back(create(std::move(lit2))); + values.push_back(create(std::move(lit3))); - ary_values.push_back(std::make_unique( - &vec, std::move(values))); + ary_values.push_back( + create(&vec, std::move(values))); } ast::TypeConstructorExpression expr(&ary, std::move(ary_values)); diff --git a/src/writer/msl/generator_impl_function_entry_point_data_test.cc b/src/writer/msl/generator_impl_function_entry_point_data_test.cc index 910e57c4c2..4a0a400c46 100644 --- a/src/writer/msl/generator_impl_function_entry_point_data_test.cc +++ b/src/writer/msl/generator_impl_function_entry_point_data_test.cc @@ -52,16 +52,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) { ast::type::F32Type f32; ast::type::I32Type i32; - auto foo_var = std::make_unique( - std::make_unique("foo", ast::StorageClass::kInput, &f32)); + auto foo_var = create( + create("foo", ast::StorageClass::kInput, &f32)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); + decos.push_back(create(0, Source{})); foo_var->set_decorations(std::move(decos)); - auto bar_var = std::make_unique( - std::make_unique("bar", ast::StorageClass::kInput, &i32)); - decos.push_back(std::make_unique(1, Source{})); + auto bar_var = create( + create("bar", ast::StorageClass::kInput, &i32)); + decos.push_back(create(1, Source{})); bar_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(foo_var.get()); @@ -71,19 +71,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) { mod.AddGlobalVariable(std::move(bar_var)); ast::VariableList params; - auto func = - std::make_unique("vtx_main", std::move(params), &f32); - func->add_decoration(std::make_unique( - ast::PipelineStage::kVertex, Source{})); + auto func = create("vtx_main", std::move(params), &f32); + func->add_decoration( + create(ast::PipelineStage::kVertex, Source{})); auto* func_ptr = func.get(); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("foo"), - std::make_unique("foo"))); - body->append(std::make_unique( - std::make_unique("bar"), - std::make_unique("bar"))); + auto body = create(); + body->append(create( + create("foo"), + create("foo"))); + body->append(create( + create("bar"), + create("bar"))); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -111,16 +110,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) { ast::type::F32Type f32; ast::type::I32Type i32; - auto foo_var = std::make_unique( - std::make_unique("foo", ast::StorageClass::kOutput, &f32)); + auto foo_var = create( + create("foo", ast::StorageClass::kOutput, &f32)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); + decos.push_back(create(0, Source{})); foo_var->set_decorations(std::move(decos)); - auto bar_var = std::make_unique( - std::make_unique("bar", ast::StorageClass::kOutput, &i32)); - decos.push_back(std::make_unique(1, Source{})); + auto bar_var = create( + create("bar", ast::StorageClass::kOutput, &i32)); + decos.push_back(create(1, Source{})); bar_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(foo_var.get()); @@ -130,19 +129,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) { mod.AddGlobalVariable(std::move(bar_var)); ast::VariableList params; - auto func = - std::make_unique("vtx_main", std::move(params), &f32); - func->add_decoration(std::make_unique( - ast::PipelineStage::kVertex, Source{})); + auto func = create("vtx_main", std::move(params), &f32); + func->add_decoration( + create(ast::PipelineStage::kVertex, Source{})); auto* func_ptr = func.get(); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("foo"), - std::make_unique("foo"))); - body->append(std::make_unique( - std::make_unique("bar"), - std::make_unique("bar"))); + auto body = create(); + body->append(create( + create("foo"), + create("foo"))); + body->append(create( + create("bar"), + create("bar"))); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -170,16 +168,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) { ast::type::F32Type f32; ast::type::I32Type i32; - auto foo_var = std::make_unique( - std::make_unique("foo", ast::StorageClass::kInput, &f32)); + auto foo_var = create( + create("foo", ast::StorageClass::kInput, &f32)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); + decos.push_back(create(0, Source{})); foo_var->set_decorations(std::move(decos)); - auto bar_var = std::make_unique( - std::make_unique("bar", ast::StorageClass::kInput, &i32)); - decos.push_back(std::make_unique(1, Source{})); + auto bar_var = create( + create("bar", ast::StorageClass::kInput, &i32)); + decos.push_back(create(1, Source{})); bar_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(foo_var.get()); @@ -189,18 +187,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) { mod.AddGlobalVariable(std::move(bar_var)); ast::VariableList params; - auto func = std::make_unique("main", std::move(params), &f32); - func->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func = create("main", std::move(params), &f32); + func->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); auto* func_ptr = func.get(); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("foo"), - std::make_unique("foo"))); - body->append(std::make_unique( - std::make_unique("bar"), - std::make_unique("bar"))); + auto body = create(); + body->append(create( + create("foo"), + create("foo"))); + body->append(create( + create("bar"), + create("bar"))); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -228,16 +226,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) { ast::type::F32Type f32; ast::type::I32Type i32; - auto foo_var = std::make_unique( - std::make_unique("foo", ast::StorageClass::kOutput, &f32)); + auto foo_var = create( + create("foo", ast::StorageClass::kOutput, &f32)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); + decos.push_back(create(0, Source{})); foo_var->set_decorations(std::move(decos)); - auto bar_var = std::make_unique( - std::make_unique("bar", ast::StorageClass::kOutput, &i32)); - decos.push_back(std::make_unique(1, Source{})); + auto bar_var = create( + create("bar", ast::StorageClass::kOutput, &i32)); + decos.push_back(create(1, Source{})); bar_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(foo_var.get()); @@ -247,18 +245,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) { mod.AddGlobalVariable(std::move(bar_var)); ast::VariableList params; - auto func = std::make_unique("main", std::move(params), &f32); - func->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func = create("main", std::move(params), &f32); + func->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); auto* func_ptr = func.get(); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("foo"), - std::make_unique("foo"))); - body->append(std::make_unique( - std::make_unique("bar"), - std::make_unique("bar"))); + auto body = create(); + body->append(create( + create("foo"), + create("foo"))); + body->append(create( + create("bar"), + create("bar"))); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -283,16 +281,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) { ast::type::F32Type f32; ast::type::I32Type i32; - auto foo_var = std::make_unique( - std::make_unique("foo", ast::StorageClass::kInput, &f32)); + auto foo_var = create( + create("foo", ast::StorageClass::kInput, &f32)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); + decos.push_back(create(0, Source{})); foo_var->set_decorations(std::move(decos)); - auto bar_var = std::make_unique( - std::make_unique("bar", ast::StorageClass::kInput, &i32)); - decos.push_back(std::make_unique(1, Source{})); + auto bar_var = create( + create("bar", ast::StorageClass::kInput, &i32)); + decos.push_back(create(1, Source{})); bar_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(foo_var.get()); @@ -302,18 +300,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) { mod.AddGlobalVariable(std::move(bar_var)); ast::VariableList params; - auto func = std::make_unique("main", std::move(params), &f32); - func->add_decoration(std::make_unique( - ast::PipelineStage::kCompute, Source{})); + auto func = create("main", std::move(params), &f32); + func->add_decoration( + create(ast::PipelineStage::kCompute, Source{})); auto* func_ptr = func.get(); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("foo"), - std::make_unique("foo"))); - body->append(std::make_unique( - std::make_unique("bar"), - std::make_unique("bar"))); + auto body = create(); + body->append(create( + create("foo"), + create("foo"))); + body->append(create( + create("bar"), + create("bar"))); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -333,16 +331,16 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) { ast::type::F32Type f32; ast::type::I32Type i32; - auto foo_var = std::make_unique( - std::make_unique("foo", ast::StorageClass::kOutput, &f32)); + auto foo_var = create( + create("foo", ast::StorageClass::kOutput, &f32)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); + decos.push_back(create(0, Source{})); foo_var->set_decorations(std::move(decos)); - auto bar_var = std::make_unique( - std::make_unique("bar", ast::StorageClass::kOutput, &i32)); - decos.push_back(std::make_unique(1, Source{})); + auto bar_var = create( + create("bar", ast::StorageClass::kOutput, &i32)); + decos.push_back(create(1, Source{})); bar_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(foo_var.get()); @@ -352,18 +350,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) { mod.AddGlobalVariable(std::move(bar_var)); ast::VariableList params; - auto func = std::make_unique("main", std::move(params), &f32); - func->add_decoration(std::make_unique( - ast::PipelineStage::kCompute, Source{})); + auto func = create("main", std::move(params), &f32); + func->add_decoration( + create(ast::PipelineStage::kCompute, Source{})); auto* func_ptr = func.get(); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("foo"), - std::make_unique("foo"))); - body->append(std::make_unique( - std::make_unique("bar"), - std::make_unique("bar"))); + auto body = create(); + body->append(create( + create("foo"), + create("foo"))); + body->append(create( + create("bar"), + create("bar"))); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -389,20 +387,18 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) { ast::type::VoidType void_type; ast::type::VectorType vec4(&f32, 4); - auto coord_var = - std::make_unique(std::make_unique( - "coord", ast::StorageClass::kInput, &vec4)); + auto coord_var = create( + create("coord", ast::StorageClass::kInput, &vec4)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique( - ast::Builtin::kFragCoord, Source{})); + decos.push_back( + create(ast::Builtin::kFragCoord, Source{})); coord_var->set_decorations(std::move(decos)); - auto depth_var = - std::make_unique(std::make_unique( - "depth", ast::StorageClass::kOutput, &f32)); - decos.push_back(std::make_unique( - ast::Builtin::kFragDepth, Source{})); + auto depth_var = create( + create("depth", ast::StorageClass::kOutput, &f32)); + decos.push_back( + create(ast::Builtin::kFragDepth, Source{})); depth_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(coord_var.get()); @@ -412,18 +408,17 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) { mod.AddGlobalVariable(std::move(depth_var)); ast::VariableList params; - auto func = - std::make_unique("main", std::move(params), &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func = create("main", std::move(params), &void_type); + func->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); auto* func_ptr = func.get(); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("depth"), - std::make_unique( - std::make_unique("coord"), - std::make_unique("x")))); + auto body = create(); + body->append(create( + create("depth"), + create( + create("coord"), + create("x")))); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); diff --git a/src/writer/msl/generator_impl_function_test.cc b/src/writer/msl/generator_impl_function_test.cc index 08d61d6490..093e9529c6 100644 --- a/src/writer/msl/generator_impl_function_test.cc +++ b/src/writer/msl/generator_impl_function_test.cc @@ -60,11 +60,10 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Function) { ast::type::VoidType void_type; - auto func = std::make_unique("my_func", ast::VariableList{}, - &void_type); + auto func = create("my_func", ast::VariableList{}, &void_type); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -83,11 +82,10 @@ TEST_F(MslGeneratorImplTest, Emit_Function) { TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) { ast::type::VoidType void_type; - auto func = - std::make_unique("main", ast::VariableList{}, &void_type); + auto func = create("main", ast::VariableList{}, &void_type); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -108,17 +106,14 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) { ast::type::I32Type i32; ast::VariableList params; - params.push_back( - std::make_unique("a", ast::StorageClass::kNone, &f32)); - params.push_back( - std::make_unique("b", ast::StorageClass::kNone, &i32)); + params.push_back(create("a", ast::StorageClass::kNone, &f32)); + params.push_back(create("b", ast::StorageClass::kNone, &i32)); ast::type::VoidType void_type; - auto func = - std::make_unique("my_func", std::move(params), &void_type); + auto func = create("my_func", std::move(params), &void_type); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -138,16 +133,16 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) { ast::type::VoidType void_type; ast::type::F32Type f32; - auto foo_var = std::make_unique( - std::make_unique("foo", ast::StorageClass::kInput, &f32)); + auto foo_var = create( + create("foo", ast::StorageClass::kInput, &f32)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); + decos.push_back(create(0, Source{})); foo_var->set_decorations(std::move(decos)); - auto bar_var = std::make_unique( - std::make_unique("bar", ast::StorageClass::kOutput, &f32)); - decos.push_back(std::make_unique(1, Source{})); + auto bar_var = create( + create("bar", ast::StorageClass::kOutput, &f32)); + decos.push_back(create(1, Source{})); bar_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(foo_var.get()); @@ -157,16 +152,15 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) { mod.AddGlobalVariable(std::move(bar_var)); ast::VariableList params; - auto func = std::make_unique("frag_main", std::move(params), - &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func = create("frag_main", std::move(params), &void_type); + func->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("bar"), - std::make_unique("foo"))); - body->append(std::make_unique()); + auto body = create(); + body->append(create( + create("bar"), + create("foo"))); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -199,20 +193,18 @@ TEST_F(MslGeneratorImplTest, ast::type::F32Type f32; ast::type::VectorType vec4(&f32, 4); - auto coord_var = - std::make_unique(std::make_unique( - "coord", ast::StorageClass::kInput, &vec4)); + auto coord_var = create( + create("coord", ast::StorageClass::kInput, &vec4)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique( - ast::Builtin::kFragCoord, Source{})); + decos.push_back( + create(ast::Builtin::kFragCoord, Source{})); coord_var->set_decorations(std::move(decos)); - auto depth_var = - std::make_unique(std::make_unique( - "depth", ast::StorageClass::kOutput, &f32)); - decos.push_back(std::make_unique( - ast::Builtin::kFragDepth, Source{})); + auto depth_var = create( + create("depth", ast::StorageClass::kOutput, &f32)); + decos.push_back( + create(ast::Builtin::kFragDepth, Source{})); depth_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(coord_var.get()); @@ -222,18 +214,17 @@ TEST_F(MslGeneratorImplTest, mod.AddGlobalVariable(std::move(depth_var)); ast::VariableList params; - auto func = std::make_unique("frag_main", std::move(params), - &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func = create("frag_main", std::move(params), &void_type); + func->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("depth"), - std::make_unique( - std::make_unique("coord"), - std::make_unique("x")))); - body->append(std::make_unique()); + auto body = create(); + body->append(create( + create("depth"), + create( + create("coord"), + create("x")))); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -261,13 +252,12 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) { ast::type::F32Type f32; ast::type::VectorType vec4(&f32, 4); - auto coord_var = - std::make_unique(std::make_unique( - "coord", ast::StorageClass::kUniform, &vec4)); + auto coord_var = create( + create("coord", ast::StorageClass::kUniform, &vec4)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); - decos.push_back(std::make_unique(1, Source{})); + decos.push_back(create(0, Source{})); + decos.push_back(create(1, Source{})); coord_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(coord_var.get()); @@ -275,20 +265,18 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) { mod.AddGlobalVariable(std::move(coord_var)); ast::VariableList params; - auto func = std::make_unique("frag_main", std::move(params), - &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func = create("frag_main", std::move(params), &void_type); + func->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); - auto var = - std::make_unique("v", ast::StorageClass::kFunction, &f32); - var->set_constructor(std::make_unique( - std::make_unique("coord"), - std::make_unique("x"))); + auto var = create("v", ast::StorageClass::kFunction, &f32); + var->set_constructor(create( + create("coord"), + create("x"))); - auto body = std::make_unique(); - body->append(std::make_unique(std::move(var))); - body->append(std::make_unique()); + auto body = create(); + body->append(create(std::move(var))); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -314,18 +302,14 @@ TEST_F(MslGeneratorImplTest, ast::StructMemberList members; ast::StructMemberDecorationList a_deco; - a_deco.push_back( - std::make_unique(0, Source{})); - members.push_back( - std::make_unique("a", &i32, std::move(a_deco))); + a_deco.push_back(create(0, Source{})); + members.push_back(create("a", &i32, std::move(a_deco))); ast::StructMemberDecorationList b_deco; - b_deco.push_back( - std::make_unique(4, Source{})); - members.push_back( - std::make_unique("b", &f32, std::move(b_deco))); + b_deco.push_back(create(4, Source{})); + members.push_back(create("b", &f32, std::move(b_deco))); - auto str = std::make_unique(); + auto str = create(); str->set_members(std::move(members)); ast::type::StructType s("Data", std::move(str)); @@ -333,13 +317,12 @@ TEST_F(MslGeneratorImplTest, mod.AddConstructedType(&s); - auto coord_var = - std::make_unique(std::make_unique( - "coord", ast::StorageClass::kStorageBuffer, &ac)); + auto coord_var = create( + create("coord", ast::StorageClass::kStorageBuffer, &ac)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); - decos.push_back(std::make_unique(1, Source{})); + decos.push_back(create(0, Source{})); + decos.push_back(create(1, Source{})); coord_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(coord_var.get()); @@ -347,20 +330,18 @@ TEST_F(MslGeneratorImplTest, mod.AddGlobalVariable(std::move(coord_var)); ast::VariableList params; - auto func = std::make_unique("frag_main", std::move(params), - &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func = create("frag_main", std::move(params), &void_type); + func->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); - auto var = - std::make_unique("v", ast::StorageClass::kFunction, &f32); - var->set_constructor(std::make_unique( - std::make_unique("coord"), - std::make_unique("b"))); + auto var = create("v", ast::StorageClass::kFunction, &f32); + var->set_constructor(create( + create("coord"), + create("b"))); - auto body = std::make_unique(); - body->append(std::make_unique(std::move(var))); - body->append(std::make_unique()); + auto body = create(); + body->append(create(std::move(var))); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -390,18 +371,14 @@ TEST_F(MslGeneratorImplTest, ast::StructMemberList members; ast::StructMemberDecorationList a_deco; - a_deco.push_back( - std::make_unique(0, Source{})); - members.push_back( - std::make_unique("a", &i32, std::move(a_deco))); + a_deco.push_back(create(0, Source{})); + members.push_back(create("a", &i32, std::move(a_deco))); ast::StructMemberDecorationList b_deco; - b_deco.push_back( - std::make_unique(4, Source{})); - members.push_back( - std::make_unique("b", &f32, std::move(b_deco))); + b_deco.push_back(create(4, Source{})); + members.push_back(create("b", &f32, std::move(b_deco))); - auto str = std::make_unique(); + auto str = create(); str->set_members(std::move(members)); ast::type::StructType s("Data", std::move(str)); @@ -409,13 +386,12 @@ TEST_F(MslGeneratorImplTest, mod.AddConstructedType(&s); - auto coord_var = - std::make_unique(std::make_unique( - "coord", ast::StorageClass::kStorageBuffer, &ac)); + auto coord_var = create( + create("coord", ast::StorageClass::kStorageBuffer, &ac)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); - decos.push_back(std::make_unique(1, Source{})); + decos.push_back(create(0, Source{})); + decos.push_back(create(1, Source{})); coord_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(coord_var.get()); @@ -423,20 +399,18 @@ TEST_F(MslGeneratorImplTest, mod.AddGlobalVariable(std::move(coord_var)); ast::VariableList params; - auto func = std::make_unique("frag_main", std::move(params), - &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func = create("frag_main", std::move(params), &void_type); + func->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); - auto var = - std::make_unique("v", ast::StorageClass::kFunction, &f32); - var->set_constructor(std::make_unique( - std::make_unique("coord"), - std::make_unique("b"))); + auto var = create("v", ast::StorageClass::kFunction, &f32); + var->set_constructor(create( + create("coord"), + create("b"))); - auto body = std::make_unique(); - body->append(std::make_unique(std::move(var))); - body->append(std::make_unique()); + auto body = create(); + body->append(create(std::move(var))); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -465,21 +439,21 @@ TEST_F( ast::type::VoidType void_type; ast::type::F32Type f32; - auto foo_var = std::make_unique( - std::make_unique("foo", ast::StorageClass::kInput, &f32)); + auto foo_var = create( + create("foo", ast::StorageClass::kInput, &f32)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); + decos.push_back(create(0, Source{})); foo_var->set_decorations(std::move(decos)); - auto bar_var = std::make_unique( - std::make_unique("bar", ast::StorageClass::kOutput, &f32)); - decos.push_back(std::make_unique(1, Source{})); + auto bar_var = create( + create("bar", ast::StorageClass::kOutput, &f32)); + decos.push_back(create(1, Source{})); bar_var->set_decorations(std::move(decos)); - auto val_var = std::make_unique( - std::make_unique("val", ast::StorageClass::kOutput, &f32)); - decos.push_back(std::make_unique(0, Source{})); + auto val_var = create( + create("val", ast::StorageClass::kOutput, &f32)); + decos.push_back(create(0, Source{})); val_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(foo_var.get()); @@ -491,40 +465,37 @@ TEST_F( mod.AddGlobalVariable(std::move(val_var)); ast::VariableList params; - params.push_back(std::make_unique( - "param", ast::StorageClass::kFunction, &f32)); - auto sub_func = - std::make_unique("sub_func", std::move(params), &f32); + params.push_back( + create("param", ast::StorageClass::kFunction, &f32)); + auto sub_func = create("sub_func", std::move(params), &f32); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("bar"), - std::make_unique("foo"))); - body->append(std::make_unique( - std::make_unique("val"), - std::make_unique("param"))); - body->append(std::make_unique( - std::make_unique("foo"))); + auto body = create(); + body->append(create( + create("bar"), + create("foo"))); + body->append(create( + create("val"), + create("param"))); + body->append( + create(create("foo"))); sub_func->set_body(std::move(body)); mod.AddFunction(std::move(sub_func)); - auto func_1 = - std::make_unique("ep_1", std::move(params), &void_type); - func_1->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func_1 = create("ep_1", std::move(params), &void_type); + func_1->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); ast::ExpressionList expr; - expr.push_back(std::make_unique( - std::make_unique(&f32, 1.0f))); + expr.push_back(create( + create(&f32, 1.0f))); - body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("bar"), - std::make_unique( - std::make_unique("sub_func"), - std::move(expr)))); - body->append(std::make_unique()); + body = create(); + body->append(create( + create("bar"), + create(create("sub_func"), + std::move(expr)))); + body->append(create()); func_1->set_body(std::move(body)); mod.AddFunction(std::move(func_1)); @@ -564,13 +535,12 @@ TEST_F(MslGeneratorImplTest, ast::type::F32Type f32; ast::type::VectorType vec4(&f32, 4); - auto depth_var = - std::make_unique(std::make_unique( - "depth", ast::StorageClass::kOutput, &f32)); + auto depth_var = create( + create("depth", ast::StorageClass::kOutput, &f32)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique( - ast::Builtin::kFragDepth, Source{})); + decos.push_back( + create(ast::Builtin::kFragDepth, Source{})); depth_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(depth_var.get()); @@ -578,34 +548,31 @@ TEST_F(MslGeneratorImplTest, mod.AddGlobalVariable(std::move(depth_var)); ast::VariableList params; - params.push_back(std::make_unique( - "param", ast::StorageClass::kFunction, &f32)); - auto sub_func = - std::make_unique("sub_func", std::move(params), &f32); + params.push_back( + create("param", ast::StorageClass::kFunction, &f32)); + auto sub_func = create("sub_func", std::move(params), &f32); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("param"))); + auto body = create(); + body->append( + create(create("param"))); sub_func->set_body(std::move(body)); mod.AddFunction(std::move(sub_func)); - auto func_1 = - std::make_unique("ep_1", std::move(params), &void_type); - func_1->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func_1 = create("ep_1", std::move(params), &void_type); + func_1->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); ast::ExpressionList expr; - expr.push_back(std::make_unique( - std::make_unique(&f32, 1.0f))); + expr.push_back(create( + create(&f32, 1.0f))); - body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("depth"), - std::make_unique( - std::make_unique("sub_func"), - std::move(expr)))); - body->append(std::make_unique()); + body = create(); + body->append(create( + create("depth"), + create(create("sub_func"), + std::move(expr)))); + body->append(create()); func_1->set_body(std::move(body)); mod.AddFunction(std::move(func_1)); @@ -639,20 +606,18 @@ TEST_F( ast::type::F32Type f32; ast::type::VectorType vec4(&f32, 4); - auto coord_var = - std::make_unique(std::make_unique( - "coord", ast::StorageClass::kInput, &vec4)); + auto coord_var = create( + create("coord", ast::StorageClass::kInput, &vec4)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique( - ast::Builtin::kFragCoord, Source{})); + decos.push_back( + create(ast::Builtin::kFragCoord, Source{})); coord_var->set_decorations(std::move(decos)); - auto depth_var = - std::make_unique(std::make_unique( - "depth", ast::StorageClass::kOutput, &f32)); - decos.push_back(std::make_unique( - ast::Builtin::kFragDepth, Source{})); + auto depth_var = create( + create("depth", ast::StorageClass::kOutput, &f32)); + decos.push_back( + create(ast::Builtin::kFragDepth, Source{})); depth_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(coord_var.get()); @@ -662,39 +627,36 @@ TEST_F( mod.AddGlobalVariable(std::move(depth_var)); ast::VariableList params; - params.push_back(std::make_unique( - "param", ast::StorageClass::kFunction, &f32)); - auto sub_func = - std::make_unique("sub_func", std::move(params), &f32); + params.push_back( + create("param", ast::StorageClass::kFunction, &f32)); + auto sub_func = create("sub_func", std::move(params), &f32); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("depth"), - std::make_unique( - std::make_unique("coord"), - std::make_unique("x")))); - body->append(std::make_unique( - std::make_unique("param"))); + auto body = create(); + body->append(create( + create("depth"), + create( + create("coord"), + create("x")))); + body->append( + create(create("param"))); sub_func->set_body(std::move(body)); mod.AddFunction(std::move(sub_func)); - auto func_1 = - std::make_unique("ep_1", std::move(params), &void_type); - func_1->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func_1 = create("ep_1", std::move(params), &void_type); + func_1->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); ast::ExpressionList expr; - expr.push_back(std::make_unique( - std::make_unique(&f32, 1.0f))); + expr.push_back(create( + create(&f32, 1.0f))); - body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("depth"), - std::make_unique( - std::make_unique("sub_func"), - std::move(expr)))); - body->append(std::make_unique()); + body = create(); + body->append(create( + create("depth"), + create(create("sub_func"), + std::move(expr)))); + body->append(create()); func_1->set_body(std::move(body)); mod.AddFunction(std::move(func_1)); @@ -727,13 +689,12 @@ TEST_F(MslGeneratorImplTest, ast::type::F32Type f32; ast::type::VectorType vec4(&f32, 4); - auto coord_var = - std::make_unique(std::make_unique( - "coord", ast::StorageClass::kUniform, &vec4)); + auto coord_var = create( + create("coord", ast::StorageClass::kUniform, &vec4)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); - decos.push_back(std::make_unique(1, Source{})); + decos.push_back(create(0, Source{})); + decos.push_back(create(1, Source{})); coord_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(coord_var.get()); @@ -741,38 +702,34 @@ TEST_F(MslGeneratorImplTest, mod.AddGlobalVariable(std::move(coord_var)); ast::VariableList params; - params.push_back(std::make_unique( - "param", ast::StorageClass::kFunction, &f32)); - auto sub_func = - std::make_unique("sub_func", std::move(params), &f32); + params.push_back( + create("param", ast::StorageClass::kFunction, &f32)); + auto sub_func = create("sub_func", std::move(params), &f32); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique( - std::make_unique("coord"), - std::make_unique("x")))); + auto body = create(); + body->append( + create(create( + create("coord"), + create("x")))); sub_func->set_body(std::move(body)); mod.AddFunction(std::move(sub_func)); - auto func = std::make_unique("frag_main", std::move(params), - &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func = create("frag_main", std::move(params), &void_type); + func->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); ast::ExpressionList expr; - expr.push_back(std::make_unique( - std::make_unique(&f32, 1.0f))); + expr.push_back(create( + create(&f32, 1.0f))); - auto var = - std::make_unique("v", ast::StorageClass::kFunction, &f32); - var->set_constructor(std::make_unique( - std::make_unique("sub_func"), - std::move(expr))); + auto var = create("v", ast::StorageClass::kFunction, &f32); + var->set_constructor(create( + create("sub_func"), std::move(expr))); - body = std::make_unique(); - body->append(std::make_unique(std::move(var))); - body->append(std::make_unique()); + body = create(); + body->append(create(std::move(var))); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -801,18 +758,14 @@ TEST_F(MslGeneratorImplTest, ast::StructMemberList members; ast::StructMemberDecorationList a_deco; - a_deco.push_back( - std::make_unique(0, Source{})); - members.push_back( - std::make_unique("a", &i32, std::move(a_deco))); + a_deco.push_back(create(0, Source{})); + members.push_back(create("a", &i32, std::move(a_deco))); ast::StructMemberDecorationList b_deco; - b_deco.push_back( - std::make_unique(4, Source{})); - members.push_back( - std::make_unique("b", &f32, std::move(b_deco))); + b_deco.push_back(create(4, Source{})); + members.push_back(create("b", &f32, std::move(b_deco))); - auto str = std::make_unique(); + auto str = create(); str->set_members(std::move(members)); ast::type::StructType s("Data", std::move(str)); @@ -820,51 +773,46 @@ TEST_F(MslGeneratorImplTest, mod.AddConstructedType(&s); - auto coord_var = - std::make_unique(std::make_unique( - "coord", ast::StorageClass::kStorageBuffer, &ac)); + auto coord_var = create( + create("coord", ast::StorageClass::kStorageBuffer, &ac)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); - decos.push_back(std::make_unique(1, Source{})); + decos.push_back(create(0, Source{})); + decos.push_back(create(1, Source{})); coord_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(coord_var.get()); mod.AddGlobalVariable(std::move(coord_var)); ast::VariableList params; - params.push_back(std::make_unique( - "param", ast::StorageClass::kFunction, &f32)); - auto sub_func = - std::make_unique("sub_func", std::move(params), &f32); + params.push_back( + create("param", ast::StorageClass::kFunction, &f32)); + auto sub_func = create("sub_func", std::move(params), &f32); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique( - std::make_unique("coord"), - std::make_unique("b")))); + auto body = create(); + body->append( + create(create( + create("coord"), + create("b")))); sub_func->set_body(std::move(body)); mod.AddFunction(std::move(sub_func)); - auto func = std::make_unique("frag_main", std::move(params), - &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func = create("frag_main", std::move(params), &void_type); + func->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); ast::ExpressionList expr; - expr.push_back(std::make_unique( - std::make_unique(&f32, 1.0f))); + expr.push_back(create( + create(&f32, 1.0f))); - auto var = - std::make_unique("v", ast::StorageClass::kFunction, &f32); - var->set_constructor(std::make_unique( - std::make_unique("sub_func"), - std::move(expr))); + auto var = create("v", ast::StorageClass::kFunction, &f32); + var->set_constructor(create( + create("sub_func"), std::move(expr))); - body = std::make_unique(); - body->append(std::make_unique(std::move(var))); - body->append(std::make_unique()); + body = create(); + body->append(create(std::move(var))); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -899,18 +847,14 @@ TEST_F(MslGeneratorImplTest, ast::StructMemberList members; ast::StructMemberDecorationList a_deco; - a_deco.push_back( - std::make_unique(0, Source{})); - members.push_back( - std::make_unique("a", &i32, std::move(a_deco))); + a_deco.push_back(create(0, Source{})); + members.push_back(create("a", &i32, std::move(a_deco))); ast::StructMemberDecorationList b_deco; - b_deco.push_back( - std::make_unique(4, Source{})); - members.push_back( - std::make_unique("b", &f32, std::move(b_deco))); + b_deco.push_back(create(4, Source{})); + members.push_back(create("b", &f32, std::move(b_deco))); - auto str = std::make_unique(); + auto str = create(); str->set_members(std::move(members)); ast::type::StructType s("Data", std::move(str)); @@ -918,51 +862,46 @@ TEST_F(MslGeneratorImplTest, mod.AddConstructedType(&s); - auto coord_var = - std::make_unique(std::make_unique( - "coord", ast::StorageClass::kStorageBuffer, &ac)); + auto coord_var = create( + create("coord", ast::StorageClass::kStorageBuffer, &ac)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); - decos.push_back(std::make_unique(1, Source{})); + decos.push_back(create(0, Source{})); + decos.push_back(create(1, Source{})); coord_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(coord_var.get()); mod.AddGlobalVariable(std::move(coord_var)); ast::VariableList params; - params.push_back(std::make_unique( - "param", ast::StorageClass::kFunction, &f32)); - auto sub_func = - std::make_unique("sub_func", std::move(params), &f32); + params.push_back( + create("param", ast::StorageClass::kFunction, &f32)); + auto sub_func = create("sub_func", std::move(params), &f32); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique( - std::make_unique("coord"), - std::make_unique("b")))); + auto body = create(); + body->append( + create(create( + create("coord"), + create("b")))); sub_func->set_body(std::move(body)); mod.AddFunction(std::move(sub_func)); - auto func = std::make_unique("frag_main", std::move(params), - &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func = create("frag_main", std::move(params), &void_type); + func->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); ast::ExpressionList expr; - expr.push_back(std::make_unique( - std::make_unique(&f32, 1.0f))); + expr.push_back(create( + create(&f32, 1.0f))); - auto var = - std::make_unique("v", ast::StorageClass::kFunction, &f32); - var->set_constructor(std::make_unique( - std::make_unique("sub_func"), - std::move(expr))); + auto var = create("v", ast::StorageClass::kFunction, &f32); + var->set_constructor(create( + create("sub_func"), std::move(expr))); - body = std::make_unique(); - body->append(std::make_unique(std::move(var))); - body->append(std::make_unique()); + body = create(); + body->append(create(std::move(var))); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -995,40 +934,38 @@ TEST_F(MslGeneratorImplTest, ast::type::F32Type f32; ast::type::I32Type i32; - auto bar_var = std::make_unique( - std::make_unique("bar", ast::StorageClass::kOutput, &f32)); + auto bar_var = create( + create("bar", ast::StorageClass::kOutput, &f32)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(1, Source{})); + decos.push_back(create(1, Source{})); bar_var->set_decorations(std::move(decos)); td.RegisterVariableForTesting(bar_var.get()); mod.AddGlobalVariable(std::move(bar_var)); ast::VariableList params; - auto func_1 = - std::make_unique("ep_1", std::move(params), &void_type); - func_1->add_decoration(std::make_unique( - ast::PipelineStage::kFragment, Source{})); + auto func_1 = create("ep_1", std::move(params), &void_type); + func_1->add_decoration( + create(ast::PipelineStage::kFragment, Source{})); - auto body = std::make_unique(); - body->append(std::make_unique( - std::make_unique("bar"), - std::make_unique( - std::make_unique(&f32, 1.0f)))); + auto body = create(); + body->append(create( + create("bar"), + create( + create(&f32, 1.0f)))); - auto list = std::make_unique(); - list->append(std::make_unique()); + auto list = create(); + list->append(create()); - body->append(std::make_unique( - std::make_unique( - ast::BinaryOp::kEqual, - std::make_unique( - std::make_unique(&i32, 1)), - std::make_unique( - std::make_unique(&i32, 1))), + body->append(create( + create(ast::BinaryOp::kEqual, + create( + create(&i32, 1)), + create( + create(&i32, 1))), std::move(list))); - body->append(std::make_unique()); + body->append(create()); func_1->set_body(std::move(body)); mod.AddFunction(std::move(func_1)); @@ -1057,10 +994,9 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithNameCollision) { ast::type::VoidType void_type; - auto func = - std::make_unique("main", ast::VariableList{}, &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kCompute, Source{})); + auto func = create("main", ast::VariableList{}, &void_type); + func->add_decoration( + create(ast::PipelineStage::kCompute, Source{})); mod.AddFunction(std::move(func)); @@ -1078,15 +1014,13 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) { ast::type::ArrayType ary(&f32, 5); ast::VariableList params; - params.push_back( - std::make_unique("a", ast::StorageClass::kNone, &ary)); + params.push_back(create("a", ast::StorageClass::kNone, &ary)); ast::type::VoidType void_type; - auto func = - std::make_unique("my_func", std::move(params), &void_type); + auto func = create("my_func", std::move(params), &void_type); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -1126,27 +1060,23 @@ TEST_F(MslGeneratorImplTest, ast::StructMemberList members; ast::StructMemberDecorationList a_deco; - a_deco.push_back( - std::make_unique(0, Source{})); - members.push_back( - std::make_unique("d", &f32, std::move(a_deco))); + a_deco.push_back(create(0, Source{})); + members.push_back(create("d", &f32, std::move(a_deco))); ast::StructDecorationList s_decos; - s_decos.push_back(std::make_unique(Source{})); + s_decos.push_back(create(Source{})); - auto str = - std::make_unique(std::move(s_decos), std::move(members)); + auto str = create(std::move(s_decos), std::move(members)); ast::type::StructType s("Data", std::move(str)); ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s); - auto data_var = - std::make_unique(std::make_unique( - "data", ast::StorageClass::kStorageBuffer, &ac)); + auto data_var = create( + create("data", ast::StorageClass::kStorageBuffer, &ac)); ast::VariableDecorationList decos; - decos.push_back(std::make_unique(0, Source{})); - decos.push_back(std::make_unique(0, Source{})); + decos.push_back(create(0, Source{})); + decos.push_back(create(0, Source{})); data_var->set_decorations(std::move(decos)); mod.AddConstructedType(&s); @@ -1156,20 +1086,18 @@ TEST_F(MslGeneratorImplTest, { ast::VariableList params; - auto func = - std::make_unique("a", std::move(params), &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kCompute, Source{})); + auto func = create("a", std::move(params), &void_type); + func->add_decoration( + create(ast::PipelineStage::kCompute, Source{})); - auto var = std::make_unique( - "v", ast::StorageClass::kFunction, &f32); - var->set_constructor(std::make_unique( - std::make_unique("data"), - std::make_unique("d"))); + auto var = create("v", ast::StorageClass::kFunction, &f32); + var->set_constructor(create( + create("data"), + create("d"))); - auto body = std::make_unique(); - body->append(std::make_unique(std::move(var))); - body->append(std::make_unique()); + auto body = create(); + body->append(create(std::move(var))); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); @@ -1177,20 +1105,18 @@ TEST_F(MslGeneratorImplTest, { ast::VariableList params; - auto func = - std::make_unique("b", std::move(params), &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kCompute, Source{})); + auto func = create("b", std::move(params), &void_type); + func->add_decoration( + create(ast::PipelineStage::kCompute, Source{})); - auto var = std::make_unique( - "v", ast::StorageClass::kFunction, &f32); - var->set_constructor(std::make_unique( - std::make_unique("data"), - std::make_unique("d"))); + auto var = create("v", ast::StorageClass::kFunction, &f32); + var->set_constructor(create( + create("data"), + create("d"))); - auto body = std::make_unique(); - body->append(std::make_unique(std::move(var))); - body->append(std::make_unique()); + auto body = create(); + body->append(create(std::move(var))); + body->append(create()); func->set_body(std::move(body)); mod.AddFunction(std::move(func)); diff --git a/src/writer/msl/generator_impl_if_test.cc b/src/writer/msl/generator_impl_if_test.cc index 04dfc7e001..ad81e360df 100644 --- a/src/writer/msl/generator_impl_if_test.cc +++ b/src/writer/msl/generator_impl_if_test.cc @@ -29,9 +29,9 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_If) { - auto cond = std::make_unique("cond"); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto cond = create("cond"); + auto body = create(); + body->append(create()); ast::IfStatement i(std::move(cond), std::move(body)); @@ -45,17 +45,17 @@ TEST_F(MslGeneratorImplTest, Emit_If) { } TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) { - auto else_cond = std::make_unique("else_cond"); - auto else_body = std::make_unique(); - else_body->append(std::make_unique()); + auto else_cond = create("else_cond"); + auto else_body = create(); + else_body->append(create()); ast::ElseStatementList elses; - elses.push_back(std::make_unique(std::move(else_cond), - std::move(else_body))); + elses.push_back( + create(std::move(else_cond), std::move(else_body))); - auto cond = std::make_unique("cond"); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto cond = create("cond"); + auto body = create(); + body->append(create()); ast::IfStatement i(std::move(cond), std::move(body)); i.set_else_statements(std::move(elses)); @@ -72,15 +72,15 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) { } TEST_F(MslGeneratorImplTest, Emit_IfWithElse) { - auto else_body = std::make_unique(); - else_body->append(std::make_unique()); + auto else_body = create(); + else_body->append(create()); ast::ElseStatementList elses; - elses.push_back(std::make_unique(std::move(else_body))); + elses.push_back(create(std::move(else_body))); - auto cond = std::make_unique("cond"); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto cond = create("cond"); + auto body = create(); + body->append(create()); ast::IfStatement i(std::move(cond), std::move(body)); i.set_else_statements(std::move(elses)); @@ -97,22 +97,22 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElse) { } TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) { - auto else_cond = std::make_unique("else_cond"); + auto else_cond = create("else_cond"); - auto else_body = std::make_unique(); - else_body->append(std::make_unique()); + auto else_body = create(); + else_body->append(create()); - auto else_body_2 = std::make_unique(); - else_body_2->append(std::make_unique()); + auto else_body_2 = create(); + else_body_2->append(create()); ast::ElseStatementList elses; - elses.push_back(std::make_unique(std::move(else_cond), - std::move(else_body))); - elses.push_back(std::make_unique(std::move(else_body_2))); + elses.push_back( + create(std::move(else_cond), std::move(else_body))); + elses.push_back(create(std::move(else_body_2))); - auto cond = std::make_unique("cond"); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto cond = create("cond"); + auto body = create(); + body->append(create()); ast::IfStatement i(std::move(cond), std::move(body)); i.set_else_statements(std::move(elses)); diff --git a/src/writer/msl/generator_impl_import_test.cc b/src/writer/msl/generator_impl_import_test.cc index 8ecb35669e..7408f5ea18 100644 --- a/src/writer/msl/generator_impl_import_test.cc +++ b/src/writer/msl/generator_impl_import_test.cc @@ -55,10 +55,10 @@ TEST_P(MslImportData_SingleParamTest, FloatScalar) { ast::type::F32Type f32; ast::ExpressionList params; - params.push_back(std::make_unique( - std::make_unique(&f32, 1.f))); + params.push_back(create( + create(&f32, 1.f))); - auto ident = std::make_unique(param.name); + auto ident = create(param.name); auto* ident_ptr = ident.get(); ast::CallExpression call(std::move(ident), std::move(params)); @@ -99,10 +99,10 @@ TEST_F(MslGeneratorImplTest, MslImportData_SingleParamTest_IntScalar) { ast::type::I32Type i32; ast::ExpressionList params; - params.push_back(std::make_unique( - std::make_unique(&i32, 1))); + params.push_back(create( + create(&i32, 1))); - ast::CallExpression expr(std::make_unique("abs"), + ast::CallExpression expr(create("abs"), std::move(params)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); @@ -118,14 +118,13 @@ TEST_P(MslImportData_DualParamTest, FloatScalar) { ast::type::F32Type f32; ast::ExpressionList params; - params.push_back(std::make_unique( - std::make_unique(&f32, 1.f))); - params.push_back(std::make_unique( - std::make_unique(&f32, 2.f))); + params.push_back(create( + create(&f32, 1.f))); + params.push_back(create( + create(&f32, 2.f))); - ast::CallExpression expr( - std::make_unique(param.name), - std::move(params)); + ast::CallExpression expr(create(param.name), + std::move(params)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error(); @@ -150,29 +149,28 @@ TEST_P(MslImportData_DualParam_VectorTest, FloatVector) { ast::type::VectorType vec(&f32, 3); ast::ExpressionList type_params; - type_params.push_back(std::make_unique( - std::make_unique(&f32, 1.f))); - type_params.push_back(std::make_unique( - std::make_unique(&f32, 2.f))); - type_params.push_back(std::make_unique( - std::make_unique(&f32, 3.f))); + type_params.push_back(create( + create(&f32, 1.f))); + type_params.push_back(create( + create(&f32, 2.f))); + type_params.push_back(create( + create(&f32, 3.f))); ast::ExpressionList params; - params.push_back(std::make_unique( - &vec, std::move(type_params))); + params.push_back( + create(&vec, std::move(type_params))); - type_params.push_back(std::make_unique( - std::make_unique(&f32, 4.f))); - type_params.push_back(std::make_unique( - std::make_unique(&f32, 5.f))); - type_params.push_back(std::make_unique( - std::make_unique(&f32, 6.f))); - params.push_back(std::make_unique( - &vec, std::move(type_params))); + type_params.push_back(create( + create(&f32, 4.f))); + type_params.push_back(create( + create(&f32, 5.f))); + type_params.push_back(create( + create(&f32, 6.f))); + params.push_back( + create(&vec, std::move(type_params))); - ast::CallExpression expr( - std::make_unique(param.name), - std::move(params)); + ast::CallExpression expr(create(param.name), + std::move(params)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error(); @@ -191,14 +189,13 @@ TEST_P(MslImportData_DualParam_Int_Test, IntScalar) { ast::type::I32Type i32; ast::ExpressionList params; - params.push_back(std::make_unique( - std::make_unique(&i32, 1))); - params.push_back(std::make_unique( - std::make_unique(&i32, 2))); + params.push_back(create( + create(&i32, 1))); + params.push_back(create( + create(&i32, 2))); - ast::CallExpression expr( - std::make_unique(param.name), - std::move(params)); + ast::CallExpression expr(create(param.name), + std::move(params)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error(); @@ -216,16 +213,15 @@ TEST_P(MslImportData_TripleParamTest, FloatScalar) { ast::type::F32Type f32; ast::ExpressionList params; - params.push_back(std::make_unique( - std::make_unique(&f32, 1.f))); - params.push_back(std::make_unique( - std::make_unique(&f32, 2.f))); - params.push_back(std::make_unique( - std::make_unique(&f32, 3.f))); + params.push_back(create( + create(&f32, 1.f))); + params.push_back(create( + create(&f32, 2.f))); + params.push_back(create( + create(&f32, 3.f))); - ast::CallExpression expr( - std::make_unique(param.name), - std::move(params)); + ast::CallExpression expr(create(param.name), + std::move(params)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error(); @@ -248,16 +244,15 @@ TEST_P(MslImportData_TripleParam_Int_Test, IntScalar) { ast::type::I32Type i32; ast::ExpressionList params; - params.push_back(std::make_unique( - std::make_unique(&i32, 1))); - params.push_back(std::make_unique( - std::make_unique(&i32, 2))); - params.push_back(std::make_unique( - std::make_unique(&i32, 3))); + params.push_back(create( + create(&i32, 1))); + params.push_back(create( + create(&i32, 2))); + params.push_back(create( + create(&i32, 3))); - ast::CallExpression expr( - std::make_unique(param.name), - std::move(params)); + ast::CallExpression expr(create(param.name), + std::move(params)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(gen.EmitCall(&expr)) << gen.error(); @@ -273,15 +268,13 @@ TEST_F(MslGeneratorImplTest, MslImportData_Determinant) { ast::type::F32Type f32; ast::type::MatrixType mat(&f32, 3, 3); - auto var = std::make_unique( - "var", ast::StorageClass::kFunction, &mat); + auto var = create("var", ast::StorageClass::kFunction, &mat); ast::ExpressionList params; - params.push_back(std::make_unique("var")); + params.push_back(create("var")); - ast::CallExpression expr( - std::make_unique("determinant"), - std::move(params)); + ast::CallExpression expr(create("determinant"), + std::move(params)); mod.AddGlobalVariable(std::move(var)); diff --git a/src/writer/msl/generator_impl_intrinsic_test.cc b/src/writer/msl/generator_impl_intrinsic_test.cc index eb9121dba2..4dc9c82db8 100644 --- a/src/writer/msl/generator_impl_intrinsic_test.cc +++ b/src/writer/msl/generator_impl_intrinsic_test.cc @@ -71,18 +71,15 @@ TEST_F(MslGeneratorImplTest, DISABLED_Intrinsic_OuterProduct) { ast::type::VectorType vec2(&f32, 2); ast::type::VectorType vec3(&f32, 3); - auto a = - std::make_unique("a", ast::StorageClass::kNone, &vec2); - auto b = - std::make_unique("b", ast::StorageClass::kNone, &vec3); + auto a = create("a", ast::StorageClass::kNone, &vec2); + auto b = create("b", ast::StorageClass::kNone, &vec3); ast::ExpressionList params; - params.push_back(std::make_unique("a")); - params.push_back(std::make_unique("b")); + params.push_back(create("a")); + params.push_back(create("b")); - ast::CallExpression call( - std::make_unique("outer_product"), - std::move(params)); + ast::CallExpression call(create("outer_product"), + std::move(params)); td.RegisterVariableForTesting(a.get()); td.RegisterVariableForTesting(b.get()); @@ -107,10 +104,10 @@ TEST_F(MslGeneratorImplTest, Intrinsic_Call) { ast::type::VectorType vec(&f32, 3); ast::ExpressionList params; - params.push_back(std::make_unique("param1")); - params.push_back(std::make_unique("param2")); + params.push_back(create("param1")); + params.push_back(create("param2")); - ast::CallExpression call(std::make_unique("dot"), + ast::CallExpression call(create("dot"), std::move(params)); ast::Variable v1("param1", ast::StorageClass::kFunction, &vec); diff --git a/src/writer/msl/generator_impl_loop_test.cc b/src/writer/msl/generator_impl_loop_test.cc index c105ccd8f6..09da2c0356 100644 --- a/src/writer/msl/generator_impl_loop_test.cc +++ b/src/writer/msl/generator_impl_loop_test.cc @@ -36,8 +36,8 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Loop) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); ast::LoopStatement l(std::move(body), {}); @@ -51,11 +51,11 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) { } TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); - auto continuing = std::make_unique(); - continuing->append(std::make_unique()); + auto continuing = create(); + continuing->append(create()); ast::LoopStatement l(std::move(body), std::move(continuing)); @@ -79,24 +79,24 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) { TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) { ast::type::F32Type f32; - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); - auto continuing = std::make_unique(); - continuing->append(std::make_unique()); + auto continuing = create(); + continuing->append(create()); - auto inner = std::make_unique(std::move(body), - std::move(continuing)); + auto inner = + create(std::move(body), std::move(continuing)); - body = std::make_unique(); + body = create(); body->append(std::move(inner)); - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); - continuing = std::make_unique(); - continuing->append(std::make_unique( - std::move(lhs), std::move(rhs))); + continuing = create(); + continuing->append( + create(std::move(lhs), std::move(rhs))); ast::LoopStatement outer(std::move(body), std::move(continuing)); @@ -151,23 +151,21 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) { ast::type::F32Type f32; - auto var = std::make_unique( - "lhs", ast::StorageClass::kFunction, &f32); - var->set_constructor(std::make_unique( - std::make_unique(&f32, 2.4))); + auto var = create("lhs", ast::StorageClass::kFunction, &f32); + var->set_constructor(create( + create(&f32, 2.4))); - auto body = std::make_unique(); - body->append(std::make_unique(std::move(var))); - body->append(std::make_unique( - std::make_unique("other", ast::StorageClass::kFunction, - &f32))); + auto body = create(); + body->append(create(std::move(var))); + body->append(create( + create("other", ast::StorageClass::kFunction, &f32))); - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); - auto continuing = std::make_unique(); - continuing->append(std::make_unique( - std::move(lhs), std::move(rhs))); + auto continuing = create(); + continuing->append( + create(std::move(lhs), std::move(rhs))); gen.increment_indent(); diff --git a/src/writer/msl/generator_impl_member_accessor_test.cc b/src/writer/msl/generator_impl_member_accessor_test.cc index ef81eea6ea..cd5fa2ee4e 100644 --- a/src/writer/msl/generator_impl_member_accessor_test.cc +++ b/src/writer/msl/generator_impl_member_accessor_test.cc @@ -29,8 +29,8 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, EmitExpression_MemberAccessor) { - auto str = std::make_unique("str"); - auto mem = std::make_unique("mem"); + auto str = create("str"); + auto mem = create("mem"); ast::MemberAccessorExpression expr(std::move(str), std::move(mem)); diff --git a/src/writer/msl/generator_impl_module_constant_test.cc b/src/writer/msl/generator_impl_module_constant_test.cc index cb4b309904..570783c1bb 100644 --- a/src/writer/msl/generator_impl_module_constant_test.cc +++ b/src/writer/msl/generator_impl_module_constant_test.cc @@ -40,18 +40,17 @@ TEST_F(MslGeneratorImplTest, Emit_ModuleConstant) { ast::type::ArrayType ary(&f32, 3); ast::ExpressionList exprs; - exprs.push_back(std::make_unique( - std::make_unique(&f32, 1.0f))); - exprs.push_back(std::make_unique( - std::make_unique(&f32, 2.0f))); - exprs.push_back(std::make_unique( - std::make_unique(&f32, 3.0f))); + exprs.push_back(create( + create(&f32, 1.0f))); + exprs.push_back(create( + create(&f32, 2.0f))); + exprs.push_back(create( + create(&f32, 3.0f))); - auto var = - std::make_unique("pos", ast::StorageClass::kNone, &ary); + auto var = create("pos", ast::StorageClass::kNone, &ary); var->set_is_const(true); var->set_constructor( - std::make_unique(&ary, std::move(exprs))); + create(&ary, std::move(exprs))); ASSERT_TRUE(gen.EmitProgramConstVariable(var.get())) << gen.error(); EXPECT_EQ( @@ -63,14 +62,14 @@ TEST_F(MslGeneratorImplTest, Emit_SpecConstant) { ast::type::F32Type f32; ast::VariableDecorationList decos; - decos.push_back(std::make_unique(23, Source{})); + decos.push_back(create(23, Source{})); - auto var = std::make_unique( - std::make_unique("pos", ast::StorageClass::kNone, &f32)); + auto var = create( + create("pos", ast::StorageClass::kNone, &f32)); var->set_decorations(std::move(decos)); var->set_is_const(true); - var->set_constructor(std::make_unique( - std::make_unique(&f32, 3.0f))); + var->set_constructor(create( + create(&f32, 3.0f))); ASSERT_TRUE(gen.EmitProgramConstVariable(var.get())) << gen.error(); EXPECT_EQ(gen.result(), "constant float pos [[function_constant(23)]];\n"); diff --git a/src/writer/msl/generator_impl_return_test.cc b/src/writer/msl/generator_impl_return_test.cc index 0318614e95..c3541e0219 100644 --- a/src/writer/msl/generator_impl_return_test.cc +++ b/src/writer/msl/generator_impl_return_test.cc @@ -39,7 +39,7 @@ TEST_F(MslGeneratorImplTest, Emit_Return) { } TEST_F(MslGeneratorImplTest, Emit_ReturnWithValue) { - auto expr = std::make_unique("expr"); + auto expr = create("expr"); ast::ReturnStatement r(std::move(expr)); gen.increment_indent(); diff --git a/src/writer/msl/generator_impl_switch_test.cc b/src/writer/msl/generator_impl_switch_test.cc index 13c99e2d61..9b85f23976 100644 --- a/src/writer/msl/generator_impl_switch_test.cc +++ b/src/writer/msl/generator_impl_switch_test.cc @@ -33,26 +33,26 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Switch) { - auto def = std::make_unique(); - auto def_body = std::make_unique(); - def_body->append(std::make_unique()); + auto def = create(); + auto def_body = create(); + def_body->append(create()); def->set_body(std::move(def_body)); ast::type::I32Type i32; ast::CaseSelectorList case_val; - case_val.push_back(std::make_unique(&i32, 5)); + case_val.push_back(create(&i32, 5)); - auto case_body = std::make_unique(); - case_body->append(std::make_unique()); + auto case_body = create(); + case_body->append(create()); - auto case_stmt = std::make_unique(std::move(case_val), - std::move(case_body)); + auto case_stmt = + create(std::move(case_val), std::move(case_body)); ast::CaseStatementList body; body.push_back(std::move(case_stmt)); body.push_back(std::move(def)); - auto cond = std::make_unique("cond"); + auto cond = create("cond"); ast::SwitchStatement s(std::move(cond), std::move(body)); gen.increment_indent(); diff --git a/src/writer/msl/generator_impl_test.cc b/src/writer/msl/generator_impl_test.cc index 13f6292dd9..7c70ede211 100644 --- a/src/writer/msl/generator_impl_test.cc +++ b/src/writer/msl/generator_impl_test.cc @@ -50,10 +50,9 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Generate) { ast::type::VoidType void_type; - auto func = std::make_unique("my_func", ast::VariableList{}, - &void_type); - func->add_decoration(std::make_unique( - ast::PipelineStage::kCompute, Source{})); + auto func = create("my_func", ast::VariableList{}, &void_type); + func->add_decoration( + create(ast::PipelineStage::kCompute, Source{})); mod.AddFunction(std::move(func)); ASSERT_TRUE(gen.Generate()) << gen.error(); @@ -157,24 +156,18 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct) { ast::type::F32Type f32; ast::StructMemberDecorationList decos; - decos.push_back( - std::make_unique(4, Source{})); + decos.push_back(create(4, Source{})); ast::StructMemberList members; - members.push_back( - std::make_unique("a", &i32, std::move(decos))); + members.push_back(create("a", &i32, std::move(decos))); - decos.push_back( - std::make_unique(32, Source{})); - members.push_back( - std::make_unique("b", &f32, std::move(decos))); + decos.push_back(create(32, Source{})); + members.push_back(create("b", &f32, std::move(decos))); - decos.push_back( - std::make_unique(128, Source{})); - members.push_back( - std::make_unique("c", &f32, std::move(decos))); + decos.push_back(create(128, Source{})); + members.push_back(create("c", &f32, std::move(decos))); - auto str = std::make_unique(); + auto str = create(); str->set_members(std::move(members)); ast::type::StructType s("S", std::move(str)); @@ -188,44 +181,32 @@ TEST_F(MslGeneratorImplTest, calculate_alignment_size_struct_of_struct) { ast::type::VectorType fvec(&f32, 3); ast::StructMemberDecorationList decos; - decos.push_back( - std::make_unique(0, Source{})); + decos.push_back(create(0, Source{})); ast::StructMemberList members; - members.push_back( - std::make_unique("a", &i32, std::move(decos))); + members.push_back(create("a", &i32, std::move(decos))); - decos.push_back( - std::make_unique(16, Source{})); - members.push_back( - std::make_unique("b", &fvec, std::move(decos))); + decos.push_back(create(16, Source{})); + members.push_back(create("b", &fvec, std::move(decos))); - decos.push_back( - std::make_unique(32, Source{})); - members.push_back( - std::make_unique("c", &f32, std::move(decos))); + decos.push_back(create(32, Source{})); + members.push_back(create("c", &f32, std::move(decos))); - auto inner_str = std::make_unique(); + auto inner_str = create(); inner_str->set_members(std::move(members)); ast::type::StructType inner_s("Inner", std::move(inner_str)); - decos.push_back( - std::make_unique(0, Source{})); - members.push_back( - std::make_unique("d", &f32, std::move(decos))); + decos.push_back(create(0, Source{})); + members.push_back(create("d", &f32, std::move(decos))); - decos.push_back( - std::make_unique(32, Source{})); - members.push_back( - std::make_unique("e", &inner_s, std::move(decos))); + decos.push_back(create(32, Source{})); + members.push_back(create("e", &inner_s, std::move(decos))); - decos.push_back( - std::make_unique(64, Source{})); - members.push_back( - std::make_unique("f", &f32, std::move(decos))); + decos.push_back(create(64, Source{})); + members.push_back(create("f", &f32, std::move(decos))); - auto outer_str = std::make_unique(); + auto outer_str = create(); outer_str->set_members(std::move(members)); ast::type::StructType outer_s("Outer", std::move(outer_str)); diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc index 110a9419e2..0136f0f987 100644 --- a/src/writer/msl/generator_impl_type_test.cc +++ b/src/writer/msl/generator_impl_type_test.cc @@ -176,16 +176,14 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct) { ast::type::F32Type f32; ast::StructMemberList members; - members.push_back(std::make_unique( - "a", &i32, ast::StructMemberDecorationList{})); + members.push_back( + create("a", &i32, ast::StructMemberDecorationList{})); ast::StructMemberDecorationList b_deco; - b_deco.push_back( - std::make_unique(4, Source{})); - members.push_back( - std::make_unique("b", &f32, std::move(b_deco))); + b_deco.push_back(create(4, Source{})); + members.push_back(create("b", &f32, std::move(b_deco))); - auto str = std::make_unique(); + auto str = create(); str->set_members(std::move(members)); ast::type::StructType s("S", std::move(str)); @@ -199,16 +197,14 @@ TEST_F(MslGeneratorImplTest, EmitType_StructDecl) { ast::type::F32Type f32; ast::StructMemberList members; - members.push_back(std::make_unique( - "a", &i32, ast::StructMemberDecorationList{})); + members.push_back( + create("a", &i32, ast::StructMemberDecorationList{})); ast::StructMemberDecorationList b_deco; - b_deco.push_back( - std::make_unique(4, Source{})); - members.push_back( - std::make_unique("b", &f32, std::move(b_deco))); + b_deco.push_back(create(4, Source{})); + members.push_back(create("b", &f32, std::move(b_deco))); - auto str = std::make_unique(); + auto str = create(); str->set_members(std::move(members)); ast::type::StructType s("S", std::move(str)); @@ -226,24 +222,18 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_InjectPadding) { ast::type::F32Type f32; ast::StructMemberDecorationList decos; - decos.push_back( - std::make_unique(4, Source{})); + decos.push_back(create(4, Source{})); ast::StructMemberList members; - members.push_back( - std::make_unique("a", &i32, std::move(decos))); + members.push_back(create("a", &i32, std::move(decos))); - decos.push_back( - std::make_unique(32, Source{})); - members.push_back( - std::make_unique("b", &f32, std::move(decos))); + decos.push_back(create(32, Source{})); + members.push_back(create("b", &f32, std::move(decos))); - decos.push_back( - std::make_unique(128, Source{})); - members.push_back( - std::make_unique("c", &f32, std::move(decos))); + decos.push_back(create(128, Source{})); + members.push_back(create("c", &f32, std::move(decos))); - auto str = std::make_unique(); + auto str = create(); str->set_members(std::move(members)); ast::type::StructType s("S", std::move(str)); @@ -265,14 +255,14 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_NameCollision) { ast::type::F32Type f32; ast::StructMemberList members; - members.push_back(std::make_unique( + members.push_back(create( "main", &i32, ast::StructMemberDecorationList{})); ast::StructMemberDecorationList b_deco; members.push_back( - std::make_unique("float", &f32, std::move(b_deco))); + create("float", &f32, std::move(b_deco))); - auto str = std::make_unique(); + auto str = create(); str->set_members(std::move(members)); ast::type::StructType s("S", std::move(str)); @@ -291,19 +281,16 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) { ast::type::F32Type f32; ast::StructMemberList members; - members.push_back(std::make_unique( - "a", &i32, ast::StructMemberDecorationList{})); + members.push_back( + create("a", &i32, ast::StructMemberDecorationList{})); ast::StructMemberDecorationList b_deco; - b_deco.push_back( - std::make_unique(4, Source{})); - members.push_back( - std::make_unique("b", &f32, std::move(b_deco))); + b_deco.push_back(create(4, Source{})); + members.push_back(create("b", &f32, std::move(b_deco))); ast::StructDecorationList decos; - decos.push_back(std::make_unique(Source{})); - auto str = - std::make_unique(std::move(decos), std::move(members)); + decos.push_back(create(Source{})); + auto str = create(std::move(decos), std::move(members)); ast::type::StructType s("S", std::move(str)); diff --git a/src/writer/msl/generator_impl_unary_op_test.cc b/src/writer/msl/generator_impl_unary_op_test.cc index 485f7c8487..aa24674291 100644 --- a/src/writer/msl/generator_impl_unary_op_test.cc +++ b/src/writer/msl/generator_impl_unary_op_test.cc @@ -39,7 +39,7 @@ using MslUnaryOpTest = TestParamHelper; TEST_P(MslUnaryOpTest, Emit) { auto params = GetParam(); - auto expr = std::make_unique("expr"); + auto expr = create("expr"); ast::UnaryOpExpression op(params.op, std::move(expr)); ASSERT_TRUE(gen.EmitExpression(&op)) << gen.error(); diff --git a/src/writer/msl/generator_impl_variable_decl_statement_test.cc b/src/writer/msl/generator_impl_variable_decl_statement_test.cc index 85920839cb..11e6da0703 100644 --- a/src/writer/msl/generator_impl_variable_decl_statement_test.cc +++ b/src/writer/msl/generator_impl_variable_decl_statement_test.cc @@ -42,8 +42,7 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) { ast::type::F32Type f32; - auto var = - std::make_unique("a", ast::StorageClass::kNone, &f32); + auto var = create("a", ast::StorageClass::kNone, &f32); ast::VariableDeclStatement stmt(std::move(var)); @@ -55,8 +54,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement) { TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const) { ast::type::F32Type f32; - auto var = - std::make_unique("a", ast::StorageClass::kNone, &f32); + auto var = create("a", ast::StorageClass::kNone, &f32); var->set_is_const(true); ast::VariableDeclStatement stmt(std::move(var)); @@ -71,8 +69,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Array) { ast::type::F32Type f32; ast::type::ArrayType ary(&f32, 5); - auto var = - std::make_unique("a", ast::StorageClass::kNone, &ary); + auto var = create("a", ast::StorageClass::kNone, &ary); ast::VariableDeclStatement stmt(std::move(var)); @@ -86,21 +83,19 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Struct) { ast::type::F32Type f32; ast::StructMemberList members; - members.push_back(std::make_unique( - "a", &f32, ast::StructMemberDecorationList{})); + members.push_back( + create("a", &f32, ast::StructMemberDecorationList{})); ast::StructMemberDecorationList b_deco; - b_deco.push_back( - std::make_unique(4, Source{})); - members.push_back( - std::make_unique("b", &f32, std::move(b_deco))); + b_deco.push_back(create(4, Source{})); + members.push_back(create("b", &f32, std::move(b_deco))); - auto str = std::make_unique(); + auto str = create(); str->set_members(std::move(members)); ast::type::StructType s("S", std::move(str)); - auto var = std::make_unique("a", ast::StorageClass::kNone, &s); + auto var = create("a", ast::StorageClass::kNone, &s); ast::VariableDeclStatement stmt(std::move(var)); @@ -115,8 +110,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) { ast::type::F32Type f32; ast::type::VectorType vec(&f32, 2); - auto var = - std::make_unique("a", ast::StorageClass::kFunction, &vec); + auto var = create("a", ast::StorageClass::kFunction, &vec); ast::VariableDeclStatement stmt(std::move(var)); @@ -129,8 +123,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Vector) { TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) { ast::type::F32Type f32; ast::type::MatrixType mat(&f32, 2, 3); - auto var = - std::make_unique("a", ast::StorageClass::kFunction, &mat); + auto var = create("a", ast::StorageClass::kFunction, &mat); ast::VariableDeclStatement stmt(std::move(var)); @@ -142,8 +135,7 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Matrix) { TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) { ast::type::F32Type f32; - auto var = - std::make_unique("a", ast::StorageClass::kPrivate, &f32); + auto var = create("a", ast::StorageClass::kPrivate, &f32); ast::VariableDeclStatement stmt(std::move(var)); @@ -154,11 +146,10 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Private) { } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_Private) { - auto ident = std::make_unique("initializer"); + auto ident = create("initializer"); ast::type::F32Type f32; - auto var = - std::make_unique("a", ast::StorageClass::kNone, &f32); + auto var = create("a", ast::StorageClass::kNone, &f32); var->set_constructor(std::move(ident)); ast::VariableDeclStatement stmt(std::move(var)); @@ -174,10 +165,9 @@ TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Initializer_ZeroVec) { ast::ExpressionList values; auto zero_vec = - std::make_unique(&vec, std::move(values)); + create(&vec, std::move(values)); - auto var = - std::make_unique("a", ast::StorageClass::kNone, &vec); + auto var = create("a", ast::StorageClass::kNone, &vec); var->set_constructor(std::move(zero_vec)); ast::VariableDeclStatement stmt(std::move(var)); diff --git a/src/writer/msl/test_helper.h b/src/writer/msl/test_helper.h index b8dda92a0c..5ab2756df4 100644 --- a/src/writer/msl/test_helper.h +++ b/src/writer/msl/test_helper.h @@ -15,6 +15,9 @@ #ifndef SRC_WRITER_MSL_TEST_HELPER_H_ #define SRC_WRITER_MSL_TEST_HELPER_H_ +#include +#include + #include "gtest/gtest.h" #include "src/ast/module.h" #include "src/context.h" @@ -26,12 +29,19 @@ namespace writer { namespace msl { /// Helper class for testing -template -class TestHelperBase : public T { +template +class TestHelperBase : public BASE { public: TestHelperBase() : td(&ctx, &mod), gen(&ctx, &mod) {} ~TestHelperBase() = default; + /// @return a `std::unique_ptr` to a new `T` constructed with `args` + /// @param args the arguments to forward to the constructor for `T` + template + std::unique_ptr create(ARGS&&... args) { + return std::make_unique(std::forward(args)...); + } + /// The context Context ctx; /// The module