diff --git a/src/ast/array_accessor_expression_test.cc b/src/ast/array_accessor_expression_test.cc index 289379738b..1b1f3bdf9a 100644 --- a/src/ast/array_accessor_expression_test.cc +++ b/src/ast/array_accessor_expression_test.cc @@ -24,8 +24,8 @@ namespace { using ArrayAccessorExpressionTest = TestHelper; TEST_F(ArrayAccessorExpressionTest, Create) { - auto ary = std::make_unique("ary"); - auto idx = std::make_unique("idx"); + auto ary = create("ary"); + auto idx = create("idx"); auto* ary_ptr = ary.get(); auto* idx_ptr = idx.get(); @@ -35,8 +35,8 @@ TEST_F(ArrayAccessorExpressionTest, Create) { ASSERT_EQ(exp.idx_expr(), idx_ptr); } TEST_F(ArrayAccessorExpressionTest, CreateWithSource) { - auto ary = std::make_unique("ary"); - auto idx = std::make_unique("idx"); + auto ary = create("ary"); + auto idx = create("idx"); ArrayAccessorExpression exp(Source{Source::Location{20, 2}}, std::move(ary), std::move(idx)); @@ -51,15 +51,15 @@ TEST_F(ArrayAccessorExpressionTest, IsArrayAccessor) { } TEST_F(ArrayAccessorExpressionTest, IsValid) { - auto ary = std::make_unique("ary"); - auto idx = std::make_unique("idx"); + auto ary = create("ary"); + auto idx = create("idx"); ArrayAccessorExpression exp(std::move(ary), std::move(idx)); EXPECT_TRUE(exp.IsValid()); } TEST_F(ArrayAccessorExpressionTest, IsValid_MissingArray) { - auto idx = std::make_unique("idx"); + auto idx = create("idx"); ArrayAccessorExpression exp; exp.set_idx_expr(std::move(idx)); @@ -67,7 +67,7 @@ TEST_F(ArrayAccessorExpressionTest, IsValid_MissingArray) { } TEST_F(ArrayAccessorExpressionTest, IsValid_MissingIndex) { - auto ary = std::make_unique("ary"); + auto ary = create("ary"); ArrayAccessorExpression exp; exp.set_array(std::move(ary)); @@ -75,22 +75,22 @@ TEST_F(ArrayAccessorExpressionTest, IsValid_MissingIndex) { } TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidArray) { - auto ary = std::make_unique(""); - auto idx = std::make_unique("idx"); + auto ary = create(""); + auto idx = create("idx"); ArrayAccessorExpression exp(std::move(ary), std::move(idx)); EXPECT_FALSE(exp.IsValid()); } TEST_F(ArrayAccessorExpressionTest, IsValid_InvalidIndex) { - auto ary = std::make_unique("ary"); - auto idx = std::make_unique(""); + auto ary = create("ary"); + auto idx = create(""); ArrayAccessorExpression exp(std::move(ary), std::move(idx)); EXPECT_FALSE(exp.IsValid()); } TEST_F(ArrayAccessorExpressionTest, ToStr) { - auto ary = std::make_unique("ary"); - auto idx = std::make_unique("idx"); + auto ary = create("ary"); + auto idx = create("idx"); ArrayAccessorExpression exp(std::move(ary), std::move(idx)); std::ostringstream out; diff --git a/src/ast/assignment_statement_test.cc b/src/ast/assignment_statement_test.cc index 8ac74a9a10..10c9542fe1 100644 --- a/src/ast/assignment_statement_test.cc +++ b/src/ast/assignment_statement_test.cc @@ -24,8 +24,8 @@ namespace { using AssignmentStatementTest = TestHelper; TEST_F(AssignmentStatementTest, Creation) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); auto* lhs_ptr = lhs.get(); auto* rhs_ptr = rhs.get(); @@ -36,8 +36,8 @@ TEST_F(AssignmentStatementTest, Creation) { } TEST_F(AssignmentStatementTest, CreationWithSource) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); AssignmentStatement stmt(Source{Source::Location{20, 2}}, std::move(lhs), std::move(rhs)); @@ -47,23 +47,23 @@ TEST_F(AssignmentStatementTest, CreationWithSource) { } TEST_F(AssignmentStatementTest, IsAssign) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); AssignmentStatement stmt(std::move(lhs), std::move(rhs)); EXPECT_TRUE(stmt.IsAssign()); } TEST_F(AssignmentStatementTest, IsValid) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); AssignmentStatement stmt(std::move(lhs), std::move(rhs)); EXPECT_TRUE(stmt.IsValid()); } TEST_F(AssignmentStatementTest, IsValid_MissingLHS) { - auto rhs = std::make_unique("rhs"); + auto rhs = create("rhs"); AssignmentStatement stmt; stmt.set_rhs(std::move(rhs)); @@ -71,7 +71,7 @@ TEST_F(AssignmentStatementTest, IsValid_MissingLHS) { } TEST_F(AssignmentStatementTest, IsValid_MissingRHS) { - auto lhs = std::make_unique("lhs"); + auto lhs = create("lhs"); AssignmentStatement stmt; stmt.set_lhs(std::move(lhs)); @@ -79,22 +79,22 @@ TEST_F(AssignmentStatementTest, IsValid_MissingRHS) { } TEST_F(AssignmentStatementTest, IsValid_InvalidLHS) { - auto lhs = std::make_unique(""); - auto rhs = std::make_unique("rhs"); + auto lhs = create(""); + auto rhs = create("rhs"); AssignmentStatement stmt(std::move(lhs), std::move(rhs)); EXPECT_FALSE(stmt.IsValid()); } TEST_F(AssignmentStatementTest, IsValid_InvalidRHS) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique(""); + auto lhs = create("lhs"); + auto rhs = create(""); AssignmentStatement stmt(std::move(lhs), std::move(rhs)); EXPECT_FALSE(stmt.IsValid()); } TEST_F(AssignmentStatementTest, ToStr) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); AssignmentStatement stmt(std::move(lhs), std::move(rhs)); std::ostringstream out; diff --git a/src/ast/binary_expression_test.cc b/src/ast/binary_expression_test.cc index 4daf6cebf4..395c844b06 100644 --- a/src/ast/binary_expression_test.cc +++ b/src/ast/binary_expression_test.cc @@ -26,8 +26,8 @@ namespace { using BinaryExpressionTest = TestHelper; TEST_F(BinaryExpressionTest, Creation) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); auto* lhs_ptr = lhs.get(); auto* rhs_ptr = rhs.get(); @@ -39,8 +39,8 @@ TEST_F(BinaryExpressionTest, Creation) { } TEST_F(BinaryExpressionTest, Creation_WithSource) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); BinaryExpression r(Source{Source::Location{20, 2}}, BinaryOp::kEqual, std::move(lhs), std::move(rhs)); @@ -55,15 +55,15 @@ TEST_F(BinaryExpressionTest, IsBinaryal) { } TEST_F(BinaryExpressionTest, IsValid) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); BinaryExpression r(BinaryOp::kEqual, std::move(lhs), std::move(rhs)); EXPECT_TRUE(r.IsValid()); } TEST_F(BinaryExpressionTest, IsValid_Null_LHS) { - auto rhs = std::make_unique("rhs"); + auto rhs = create("rhs"); BinaryExpression r; r.set_op(BinaryOp::kEqual); @@ -72,15 +72,15 @@ TEST_F(BinaryExpressionTest, IsValid_Null_LHS) { } TEST_F(BinaryExpressionTest, IsValid_Invalid_LHS) { - auto lhs = std::make_unique(""); - auto rhs = std::make_unique("rhs"); + auto lhs = create(""); + auto rhs = create("rhs"); BinaryExpression r(BinaryOp::kEqual, std::move(lhs), std::move(rhs)); EXPECT_FALSE(r.IsValid()); } TEST_F(BinaryExpressionTest, IsValid_Null_RHS) { - auto lhs = std::make_unique("lhs"); + auto lhs = create("lhs"); BinaryExpression r; r.set_op(BinaryOp::kEqual); @@ -89,24 +89,24 @@ TEST_F(BinaryExpressionTest, IsValid_Null_RHS) { } TEST_F(BinaryExpressionTest, IsValid_Invalid_RHS) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique(""); + auto lhs = create("lhs"); + auto rhs = create(""); BinaryExpression r(BinaryOp::kEqual, std::move(lhs), std::move(rhs)); EXPECT_FALSE(r.IsValid()); } TEST_F(BinaryExpressionTest, IsValid_Binary_None) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); BinaryExpression r(BinaryOp::kNone, std::move(lhs), std::move(rhs)); EXPECT_FALSE(r.IsValid()); } TEST_F(BinaryExpressionTest, ToStr) { - auto lhs = std::make_unique("lhs"); - auto rhs = std::make_unique("rhs"); + auto lhs = create("lhs"); + auto rhs = create("rhs"); BinaryExpression r(BinaryOp::kEqual, std::move(lhs), std::move(rhs)); std::ostringstream out; diff --git a/src/ast/bitcast_expression_test.cc b/src/ast/bitcast_expression_test.cc index 8641442417..071ad8918e 100644 --- a/src/ast/bitcast_expression_test.cc +++ b/src/ast/bitcast_expression_test.cc @@ -26,7 +26,7 @@ using BitcastExpressionTest = TestHelper; TEST_F(BitcastExpressionTest, Create) { type::F32Type f32; - auto expr = std::make_unique("expr"); + auto expr = create("expr"); auto* expr_ptr = expr.get(); @@ -37,7 +37,7 @@ TEST_F(BitcastExpressionTest, Create) { TEST_F(BitcastExpressionTest, CreateWithSource) { type::F32Type f32; - auto expr = std::make_unique("expr"); + auto expr = create("expr"); BitcastExpression exp(Source{Source::Location{20, 2}}, &f32, std::move(expr)); auto src = exp.source(); @@ -52,14 +52,14 @@ TEST_F(BitcastExpressionTest, IsBitcast) { TEST_F(BitcastExpressionTest, IsValid) { type::F32Type f32; - auto expr = std::make_unique("expr"); + auto expr = create("expr"); BitcastExpression exp(&f32, std::move(expr)); EXPECT_TRUE(exp.IsValid()); } TEST_F(BitcastExpressionTest, IsValid_MissingType) { - auto expr = std::make_unique("expr"); + auto expr = create("expr"); BitcastExpression exp; exp.set_expr(std::move(expr)); @@ -76,14 +76,14 @@ TEST_F(BitcastExpressionTest, IsValid_MissingExpr) { TEST_F(BitcastExpressionTest, IsValid_InvalidExpr) { type::F32Type f32; - auto expr = std::make_unique(""); + auto expr = create(""); BitcastExpression e(&f32, std::move(expr)); EXPECT_FALSE(e.IsValid()); } TEST_F(BitcastExpressionTest, ToStr) { type::F32Type f32; - auto expr = std::make_unique("expr"); + auto expr = create("expr"); BitcastExpression exp(&f32, std::move(expr)); std::ostringstream out; diff --git a/src/ast/block_statement_test.cc b/src/ast/block_statement_test.cc index 893ad38e71..802bb01767 100644 --- a/src/ast/block_statement_test.cc +++ b/src/ast/block_statement_test.cc @@ -28,7 +28,7 @@ namespace { using BlockStatementTest = TestHelper; TEST_F(BlockStatementTest, Creation) { - auto d = std::make_unique(); + auto d = create(); auto* ptr = d.get(); BlockStatement b; @@ -39,9 +39,9 @@ TEST_F(BlockStatementTest, Creation) { } TEST_F(BlockStatementTest, Creation_WithInsert) { - auto s1 = std::make_unique(); - auto s2 = std::make_unique(); - auto s3 = std::make_unique(); + auto s1 = create(); + auto s2 = create(); + auto s3 = create(); auto* p1 = s1.get(); auto* p2 = s2.get(); auto* p3 = s3.get(); @@ -73,7 +73,7 @@ TEST_F(BlockStatementTest, IsBlock) { TEST_F(BlockStatementTest, IsValid) { BlockStatement b; - b.append(std::make_unique()); + b.append(create()); EXPECT_TRUE(b.IsValid()); } @@ -84,20 +84,20 @@ TEST_F(BlockStatementTest, IsValid_Empty) { TEST_F(BlockStatementTest, IsValid_NullBodyStatement) { BlockStatement b; - b.append(std::make_unique()); + b.append(create()); b.append(nullptr); EXPECT_FALSE(b.IsValid()); } TEST_F(BlockStatementTest, IsValid_InvalidBodyStatement) { BlockStatement b; - b.append(std::make_unique()); + b.append(create()); EXPECT_FALSE(b.IsValid()); } TEST_F(BlockStatementTest, ToStr) { BlockStatement b; - b.append(std::make_unique()); + b.append(create()); std::ostringstream out; b.to_str(out, 2); diff --git a/src/ast/builder.h b/src/ast/builder.h index 692e799ce5..77c9e2d3fe 100644 --- a/src/ast/builder.h +++ b/src/ast/builder.h @@ -115,58 +115,55 @@ class Builder { /// @return an IdentifierExpression with the given name std::unique_ptr make_expr( const std::string& name) { - return std::make_unique(name); + return create(name); } /// @param name the identifier name /// @return an IdentifierExpression with the given name std::unique_ptr make_expr(const char* name) { - return std::make_unique(name); + return create(name); } /// @param value the float value /// @return a Scalar constructor for the given value std::unique_ptr make_expr(float value) { - return std::make_unique( - make_literal(value)); + return create(make_literal(value)); } /// @param value the int value /// @return a Scalar constructor for the given value std::unique_ptr make_expr(int32_t value) { - return std::make_unique( - make_literal(value)); + return create(make_literal(value)); } /// @param value the unsigned int value /// @return a Scalar constructor for the given value std::unique_ptr make_expr(uint32_t value) { - return std::make_unique( - make_literal(value)); + return create(make_literal(value)); } /// @param val the boolan value /// @return a boolean literal with the given value std::unique_ptr make_literal(bool val) { - return std::make_unique(bool_type(), val); + return create(bool_type(), val); } /// @param val the float value /// @return a float literal with the given value std::unique_ptr make_literal(float val) { - return std::make_unique(f32(), val); + return create(f32(), val); } /// @param val the unsigned int value /// @return a UintLiteral with the given value std::unique_ptr make_literal(uint32_t val) { - return std::make_unique(u32(), val); + return create(u32(), val); } /// @param val the integer value /// @return the SintLiteral with the given value std::unique_ptr make_literal(int32_t val) { - return std::make_unique(i32(), val); + return create(i32(), val); } /// Converts `arg` to an `ast::Expression` using `make_expr()`, then appends @@ -198,8 +195,7 @@ class Builder { ARGS&&... args) { ast::ExpressionList vals; append_expr(vals, std::forward(args)...); - return std::make_unique(ty, - std::move(vals)); + return create(ty, std::move(vals)); } /// @param name the variable name @@ -221,6 +217,13 @@ class Builder { return ast::CallExpression{make_expr(func), std::move(params)}; } + /// @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)...); + } + private: Context* ctx_ = nullptr; }; diff --git a/src/ast/call_expression_test.cc b/src/ast/call_expression_test.cc index aae13891c3..6cdcbcbfc2 100644 --- a/src/ast/call_expression_test.cc +++ b/src/ast/call_expression_test.cc @@ -24,10 +24,10 @@ namespace { using CallExpressionTest = TestHelper; TEST_F(CallExpressionTest, Creation) { - auto func = std::make_unique("func"); + auto func = create("func"); 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")); auto* func_ptr = func.get(); auto* param1_ptr = params[0].get(); @@ -43,7 +43,7 @@ TEST_F(CallExpressionTest, Creation) { } TEST_F(CallExpressionTest, Creation_WithSource) { - auto func = std::make_unique("func"); + auto func = create("func"); CallExpression stmt(Source{Source::Location{20, 2}}, std::move(func), {}); auto src = stmt.source(); EXPECT_EQ(src.range.begin.line, 20u); @@ -51,13 +51,13 @@ TEST_F(CallExpressionTest, Creation_WithSource) { } TEST_F(CallExpressionTest, IsCall) { - auto func = std::make_unique("func"); + auto func = create("func"); CallExpression stmt(std::move(func), {}); EXPECT_TRUE(stmt.IsCall()); } TEST_F(CallExpressionTest, IsValid) { - auto func = std::make_unique("func"); + auto func = create("func"); CallExpression stmt(std::move(func), {}); EXPECT_TRUE(stmt.IsValid()); } @@ -68,36 +68,36 @@ TEST_F(CallExpressionTest, IsValid_MissingFunction) { } TEST_F(CallExpressionTest, IsValid_NullParam) { - auto func = std::make_unique("func"); + auto func = create("func"); ExpressionList params; - params.push_back(std::make_unique("param1")); + params.push_back(create("param1")); params.push_back(nullptr); - params.push_back(std::make_unique("param2")); + params.push_back(create("param2")); CallExpression stmt(std::move(func), std::move(params)); EXPECT_FALSE(stmt.IsValid()); } TEST_F(CallExpressionTest, IsValid_InvalidFunction) { - auto func = std::make_unique(""); + auto func = create(""); ExpressionList params; - params.push_back(std::make_unique("param1")); + params.push_back(create("param1")); CallExpression stmt(std::move(func), std::move(params)); EXPECT_FALSE(stmt.IsValid()); } TEST_F(CallExpressionTest, IsValid_InvalidParam) { - auto func = std::make_unique("func"); + auto func = create("func"); ExpressionList params; - params.push_back(std::make_unique("")); + params.push_back(create("")); CallExpression stmt(std::move(func), std::move(params)); EXPECT_FALSE(stmt.IsValid()); } TEST_F(CallExpressionTest, ToStr_NoParams) { - auto func = std::make_unique("func"); + auto func = create("func"); CallExpression stmt(std::move(func), {}); std::ostringstream out; stmt.to_str(out, 2); @@ -110,10 +110,10 @@ TEST_F(CallExpressionTest, ToStr_NoParams) { } TEST_F(CallExpressionTest, ToStr_WithParams) { - auto func = std::make_unique("func"); + auto func = create("func"); 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")); CallExpression stmt(std::move(func), std::move(params)); std::ostringstream out; diff --git a/src/ast/call_statement_test.cc b/src/ast/call_statement_test.cc index 1337440439..b9df302c1e 100644 --- a/src/ast/call_statement_test.cc +++ b/src/ast/call_statement_test.cc @@ -25,8 +25,8 @@ namespace { using CallStatementTest = TestHelper; TEST_F(CallStatementTest, Creation) { - auto expr = std::make_unique( - std::make_unique("func"), ExpressionList{}); + auto expr = create( + create("func"), ExpressionList{}); auto* expr_ptr = expr.get(); CallStatement c(std::move(expr)); @@ -39,8 +39,8 @@ TEST_F(CallStatementTest, IsCall) { } TEST_F(CallStatementTest, IsValid) { - CallStatement c(std::make_unique( - std::make_unique("func"), ExpressionList{})); + CallStatement c(create( + create("func"), ExpressionList{})); EXPECT_TRUE(c.IsValid()); } @@ -50,13 +50,13 @@ TEST_F(CallStatementTest, IsValid_MissingExpr) { } TEST_F(CallStatementTest, IsValid_InvalidExpr) { - CallStatement c(std::make_unique()); + CallStatement c(create()); EXPECT_FALSE(c.IsValid()); } TEST_F(CallStatementTest, ToStr) { - CallStatement c(std::make_unique( - std::make_unique("func"), ExpressionList{})); + CallStatement c(create( + create("func"), ExpressionList{})); std::ostringstream out; c.to_str(out, 2); diff --git a/src/ast/case_statement_test.cc b/src/ast/case_statement_test.cc index 9a415c874c..1d61291d01 100644 --- a/src/ast/case_statement_test.cc +++ b/src/ast/case_statement_test.cc @@ -32,10 +32,10 @@ TEST_F(CaseStatementTest, Creation_i32) { ast::type::I32Type i32; CaseSelectorList b; - b.push_back(std::make_unique(&i32, 2)); + b.push_back(create(&i32, 2)); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); auto* int_ptr = b.back().get(); auto* discard_ptr = body->get(0); @@ -51,10 +51,10 @@ TEST_F(CaseStatementTest, Creation_u32) { ast::type::U32Type u32; CaseSelectorList b; - b.push_back(std::make_unique(&u32, 2)); + b.push_back(create(&u32, 2)); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); auto* int_ptr = b.back().get(); auto* discard_ptr = body->get(0); @@ -69,10 +69,10 @@ TEST_F(CaseStatementTest, Creation_u32) { TEST_F(CaseStatementTest, Creation_WithSource) { ast::type::I32Type i32; CaseSelectorList b; - b.push_back(std::make_unique(&i32, 2)); + b.push_back(create(&i32, 2)); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); CaseStatement c(Source{Source::Location{20, 2}}, std::move(b), std::move(body)); @@ -82,8 +82,8 @@ TEST_F(CaseStatementTest, Creation_WithSource) { } TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); CaseStatement c; c.set_body(std::move(body)); @@ -93,7 +93,7 @@ TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) { TEST_F(CaseStatementTest, IsDefault_WithSelectors) { ast::type::I32Type i32; CaseSelectorList b; - b.push_back(std::make_unique(&i32, 2)); + b.push_back(create(&i32, 2)); CaseStatement c; c.set_selectors(std::move(b)); @@ -113,10 +113,10 @@ TEST_F(CaseStatementTest, IsValid) { TEST_F(CaseStatementTest, IsValid_NullBodyStatement) { ast::type::I32Type i32; CaseSelectorList b; - b.push_back(std::make_unique(&i32, 2)); + b.push_back(create(&i32, 2)); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); body->append(nullptr); CaseStatement c(std::move(b), std::move(body)); @@ -126,10 +126,10 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) { TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) { ast::type::I32Type i32; CaseSelectorList b; - b.push_back(std::make_unique(&i32, 2)); + b.push_back(create(&i32, 2)); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); CaseStatement c({std::move(b)}, std::move(body)); EXPECT_FALSE(c.IsValid()); @@ -138,10 +138,10 @@ TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) { TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) { ast::type::I32Type i32; CaseSelectorList b; - b.push_back(std::make_unique(&i32, -2)); + b.push_back(create(&i32, -2)); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); CaseStatement c({std::move(b)}, std::move(body)); std::ostringstream out; @@ -155,10 +155,10 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) { TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) { ast::type::U32Type u32; CaseSelectorList b; - b.push_back(std::make_unique(&u32, 2)); + b.push_back(create(&u32, 2)); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); CaseStatement c({std::move(b)}, std::move(body)); std::ostringstream out; @@ -173,11 +173,11 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) { ast::type::I32Type i32; CaseSelectorList b; - b.push_back(std::make_unique(&i32, 1)); - b.push_back(std::make_unique(&i32, 2)); + b.push_back(create(&i32, 1)); + b.push_back(create(&i32, 2)); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); CaseStatement c(std::move(b), std::move(body)); std::ostringstream out; @@ -189,8 +189,8 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) { } TEST_F(CaseStatementTest, ToStr_WithoutSelectors) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); CaseStatement c(CaseSelectorList{}, std::move(body)); std::ostringstream out; diff --git a/src/ast/decorated_variable_test.cc b/src/ast/decorated_variable_test.cc index 0e511356ee..7c82d78505 100644 --- a/src/ast/decorated_variable_test.cc +++ b/src/ast/decorated_variable_test.cc @@ -34,7 +34,7 @@ using DecoratedVariableTest = TestHelper; TEST_F(DecoratedVariableTest, Creation) { type::I32Type t; - auto var = std::make_unique("my_var", StorageClass::kFunction, &t); + auto var = create("my_var", StorageClass::kFunction, &t); DecoratedVariable dv(std::move(var)); EXPECT_EQ(dv.name(), "my_var"); @@ -49,7 +49,7 @@ TEST_F(DecoratedVariableTest, Creation) { TEST_F(DecoratedVariableTest, CreationWithSource) { Source s{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}; type::F32Type t; - auto var = std::make_unique(s, "i", StorageClass::kPrivate, &t); + auto var = create(s, "i", StorageClass::kPrivate, &t); DecoratedVariable dv(std::move(var)); EXPECT_EQ(dv.name(), "i"); @@ -63,7 +63,7 @@ TEST_F(DecoratedVariableTest, CreationWithSource) { TEST_F(DecoratedVariableTest, NoDecorations) { type::I32Type t; - auto var = std::make_unique("my_var", StorageClass::kFunction, &t); + auto var = create("my_var", StorageClass::kFunction, &t); DecoratedVariable dv(std::move(var)); EXPECT_FALSE(dv.HasLocationDecoration()); EXPECT_FALSE(dv.HasBuiltinDecoration()); @@ -72,14 +72,13 @@ TEST_F(DecoratedVariableTest, NoDecorations) { TEST_F(DecoratedVariableTest, WithDecorations) { type::F32Type t; - auto var = std::make_unique("my_var", StorageClass::kFunction, &t); + auto var = create("my_var", StorageClass::kFunction, &t); DecoratedVariable dv(std::move(var)); VariableDecorationList decos; - decos.push_back(std::make_unique(1, Source{})); - decos.push_back( - std::make_unique(ast::Builtin::kPosition, Source{})); - decos.push_back(std::make_unique(1200, Source{})); + decos.push_back(create(1, Source{})); + decos.push_back(create(ast::Builtin::kPosition, Source{})); + decos.push_back(create(1200, Source{})); dv.set_decorations(std::move(decos)); @@ -90,11 +89,11 @@ TEST_F(DecoratedVariableTest, WithDecorations) { TEST_F(DecoratedVariableTest, ConstantId) { type::F32Type t; - auto var = std::make_unique("my_var", StorageClass::kFunction, &t); + auto var = create("my_var", StorageClass::kFunction, &t); DecoratedVariable dv(std::move(var)); VariableDecorationList decos; - decos.push_back(std::make_unique(1200, Source{})); + decos.push_back(create(1200, Source{})); dv.set_decorations(std::move(decos)); EXPECT_EQ(dv.constant_id(), 1200u); @@ -102,7 +101,7 @@ TEST_F(DecoratedVariableTest, ConstantId) { TEST_F(DecoratedVariableTest, IsValid) { type::I32Type t; - auto var = std::make_unique("my_var", StorageClass::kNone, &t); + auto var = create("my_var", StorageClass::kNone, &t); DecoratedVariable dv(std::move(var)); EXPECT_TRUE(dv.IsValid()); } @@ -114,13 +113,13 @@ TEST_F(DecoratedVariableTest, IsDecorated) { TEST_F(DecoratedVariableTest, to_str) { type::F32Type t; - auto var = std::make_unique("my_var", StorageClass::kFunction, &t); + auto var = create("my_var", StorageClass::kFunction, &t); DecoratedVariable dv(std::move(var)); - dv.set_constructor(std::make_unique("expr")); + dv.set_constructor(create("expr")); VariableDecorationList decos; - decos.push_back(std::make_unique(2, Source{})); - decos.push_back(std::make_unique(1, Source{})); + decos.push_back(create(2, Source{})); + decos.push_back(create(1, Source{})); dv.set_decorations(std::move(decos)); std::ostringstream out; diff --git a/src/ast/decoration_test.cc b/src/ast/decoration_test.cc index 8f3254641b..06029e7b04 100644 --- a/src/ast/decoration_test.cc +++ b/src/ast/decoration_test.cc @@ -42,7 +42,7 @@ TEST_F(DecorationTest, AsIncorrectType) { } TEST_F(DecorationTest, Is) { - auto decoration = std::make_unique(1, Source{}); + auto decoration = create(1, Source{}); EXPECT_TRUE(decoration->Is()); EXPECT_FALSE(decoration->Is()); } diff --git a/src/ast/else_statement_test.cc b/src/ast/else_statement_test.cc index 4e436faf33..b8ae12ac71 100644 --- a/src/ast/else_statement_test.cc +++ b/src/ast/else_statement_test.cc @@ -29,10 +29,10 @@ using ElseStatementTest = TestHelper; TEST_F(ElseStatementTest, Creation) { ast::type::BoolType bool_type; - auto cond = std::make_unique( - std::make_unique(&bool_type, true)); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto cond = create( + create(&bool_type, true)); + auto body = create(); + body->append(create()); auto* cond_ptr = cond.get(); auto* discard_ptr = body->get(0); @@ -44,8 +44,7 @@ TEST_F(ElseStatementTest, Creation) { } TEST_F(ElseStatementTest, Creation_WithSource) { - ElseStatement e(Source{Source::Location{20, 2}}, - std::make_unique()); + ElseStatement e(Source{Source::Location{20, 2}}, create()); auto src = e.source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); @@ -58,9 +57,9 @@ TEST_F(ElseStatementTest, IsElse) { TEST_F(ElseStatementTest, HasCondition) { ast::type::BoolType bool_type; - auto cond = std::make_unique( - std::make_unique(&bool_type, true)); - ElseStatement e(std::move(cond), std::make_unique()); + auto cond = create( + create(&bool_type, true)); + ElseStatement e(std::move(cond), create()); EXPECT_TRUE(e.HasCondition()); } @@ -75,16 +74,16 @@ TEST_F(ElseStatementTest, IsValid) { } TEST_F(ElseStatementTest, IsValid_WithBody) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); ElseStatement e(std::move(body)); EXPECT_TRUE(e.IsValid()); } TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); body->append(nullptr); ElseStatement e(std::move(body)); @@ -92,14 +91,14 @@ TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) { } TEST_F(ElseStatementTest, IsValid_InvalidCondition) { - auto cond = std::make_unique(); - ElseStatement e(std::move(cond), std::make_unique()); + auto cond = create(); + ElseStatement e(std::move(cond), create()); EXPECT_FALSE(e.IsValid()); } TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); ElseStatement e(std::move(body)); EXPECT_FALSE(e.IsValid()); @@ -107,10 +106,10 @@ TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) { TEST_F(ElseStatementTest, ToStr) { ast::type::BoolType bool_type; - auto cond = std::make_unique( - std::make_unique(&bool_type, true)); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto cond = create( + create(&bool_type, true)); + auto body = create(); + body->append(create()); ElseStatement e(std::move(cond), std::move(body)); std::ostringstream out; @@ -127,8 +126,8 @@ TEST_F(ElseStatementTest, ToStr) { } TEST_F(ElseStatementTest, ToStr_NoCondition) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); ElseStatement e(std::move(body)); std::ostringstream out; diff --git a/src/ast/function_test.cc b/src/ast/function_test.cc index 34c01a86c4..91785bc860 100644 --- a/src/ast/function_test.cc +++ b/src/ast/function_test.cc @@ -37,8 +37,7 @@ TEST_F(FunctionTest, Creation) { type::I32Type i32; VariableList params; - params.push_back( - std::make_unique("var", StorageClass::kNone, &i32)); + params.push_back(create("var", StorageClass::kNone, &i32)); auto* var_ptr = params[0].get(); Function f("func", std::move(params), &void_type); @@ -53,8 +52,7 @@ TEST_F(FunctionTest, Creation_WithSource) { type::I32Type i32; VariableList params; - params.push_back( - std::make_unique("var", StorageClass::kNone, &i32)); + params.push_back(create("var", StorageClass::kNone, &i32)); Function f(Source{Source::Location{20, 2}}, "func", std::move(params), &void_type); @@ -89,25 +87,25 @@ TEST_F(FunctionTest, GetReferenceLocations) { VariableDecorationList decos; DecoratedVariable loc1( - std::make_unique("loc1", StorageClass::kInput, &i32)); - decos.push_back(std::make_unique(0, Source{})); + create("loc1", StorageClass::kInput, &i32)); + decos.push_back(create(0, Source{})); loc1.set_decorations(std::move(decos)); DecoratedVariable loc2( - std::make_unique("loc2", StorageClass::kInput, &i32)); - decos.push_back(std::make_unique(1, Source{})); + create("loc2", StorageClass::kInput, &i32)); + decos.push_back(create(1, Source{})); loc2.set_decorations(std::move(decos)); DecoratedVariable builtin1( - std::make_unique("builtin1", StorageClass::kInput, &i32)); - decos.push_back(std::make_unique( - ast::Builtin::kPosition, Source{})); + create("builtin1", StorageClass::kInput, &i32)); + decos.push_back( + create(ast::Builtin::kPosition, Source{})); builtin1.set_decorations(std::move(decos)); DecoratedVariable builtin2( - std::make_unique("builtin2", StorageClass::kInput, &i32)); - decos.push_back(std::make_unique( - ast::Builtin::kFragDepth, Source{})); + create("builtin2", StorageClass::kInput, &i32)); + decos.push_back( + create(ast::Builtin::kFragDepth, Source{})); builtin2.set_decorations(std::move(decos)); Function f("func", VariableList{}, &void_type); @@ -132,25 +130,25 @@ TEST_F(FunctionTest, GetReferenceBuiltins) { VariableDecorationList decos; DecoratedVariable loc1( - std::make_unique("loc1", StorageClass::kInput, &i32)); - decos.push_back(std::make_unique(0, Source{})); + create("loc1", StorageClass::kInput, &i32)); + decos.push_back(create(0, Source{})); loc1.set_decorations(std::move(decos)); DecoratedVariable loc2( - std::make_unique("loc2", StorageClass::kInput, &i32)); - decos.push_back(std::make_unique(1, Source{})); + create("loc2", StorageClass::kInput, &i32)); + decos.push_back(create(1, Source{})); loc2.set_decorations(std::move(decos)); DecoratedVariable builtin1( - std::make_unique("builtin1", StorageClass::kInput, &i32)); - decos.push_back(std::make_unique( - ast::Builtin::kPosition, Source{})); + create("builtin1", StorageClass::kInput, &i32)); + decos.push_back( + create(ast::Builtin::kPosition, Source{})); builtin1.set_decorations(std::move(decos)); DecoratedVariable builtin2( - std::make_unique("builtin2", StorageClass::kInput, &i32)); - decos.push_back(std::make_unique( - ast::Builtin::kFragDepth, Source{})); + create("builtin2", StorageClass::kInput, &i32)); + decos.push_back( + create(ast::Builtin::kFragDepth, Source{})); builtin2.set_decorations(std::move(decos)); Function f("func", VariableList{}, &void_type); @@ -187,11 +185,10 @@ TEST_F(FunctionTest, IsValid) { type::I32Type i32; VariableList params; - params.push_back( - std::make_unique("var", StorageClass::kNone, &i32)); + params.push_back(create("var", StorageClass::kNone, &i32)); - auto block = std::make_unique(); - block->append(std::make_unique()); + auto block = create(); + block->append(create()); Function f("func", std::move(params), &void_type); f.set_body(std::move(block)); @@ -203,8 +200,7 @@ TEST_F(FunctionTest, IsValid_EmptyName) { type::I32Type i32; VariableList params; - params.push_back( - std::make_unique("var", StorageClass::kNone, &i32)); + params.push_back(create("var", StorageClass::kNone, &i32)); Function f("", std::move(params), &void_type); EXPECT_FALSE(f.IsValid()); @@ -214,8 +210,7 @@ TEST_F(FunctionTest, IsValid_MissingReturnType) { type::I32Type i32; VariableList params; - params.push_back( - std::make_unique("var", StorageClass::kNone, &i32)); + params.push_back(create("var", StorageClass::kNone, &i32)); Function f("func", std::move(params), nullptr); EXPECT_FALSE(f.IsValid()); @@ -226,8 +221,7 @@ TEST_F(FunctionTest, IsValid_NullParam) { type::I32Type i32; VariableList params; - params.push_back( - std::make_unique("var", StorageClass::kNone, &i32)); + params.push_back(create("var", StorageClass::kNone, &i32)); params.push_back(nullptr); Function f("func", std::move(params), &void_type); @@ -238,8 +232,7 @@ TEST_F(FunctionTest, IsValid_InvalidParam) { type::VoidType void_type; VariableList params; - params.push_back( - std::make_unique("var", StorageClass::kNone, nullptr)); + params.push_back(create("var", StorageClass::kNone, nullptr)); Function f("func", std::move(params), &void_type); EXPECT_FALSE(f.IsValid()); @@ -250,11 +243,10 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) { type::I32Type i32; VariableList params; - params.push_back( - std::make_unique("var", StorageClass::kNone, &i32)); + params.push_back(create("var", StorageClass::kNone, &i32)); - auto block = std::make_unique(); - block->append(std::make_unique()); + auto block = create(); + block->append(create()); block->append(nullptr); Function f("func", std::move(params), &void_type); @@ -267,11 +259,10 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) { type::I32Type i32; VariableList params; - params.push_back( - std::make_unique("var", StorageClass::kNone, &i32)); + params.push_back(create("var", StorageClass::kNone, &i32)); - auto block = std::make_unique(); - block->append(std::make_unique()); + auto block = create(); + block->append(create()); block->append(nullptr); Function f("func", std::move(params), &void_type); @@ -283,8 +274,8 @@ TEST_F(FunctionTest, ToStr) { type::VoidType void_type; type::I32Type i32; - auto block = std::make_unique(); - block->append(std::make_unique()); + auto block = create(); + block->append(create()); Function f("func", {}, &void_type); f.set_body(std::move(block)); @@ -303,12 +294,12 @@ TEST_F(FunctionTest, ToStr_WithDecoration) { type::VoidType void_type; type::I32Type i32; - auto block = std::make_unique(); - block->append(std::make_unique()); + auto block = create(); + block->append(create()); Function f("func", {}, &void_type); f.set_body(std::move(block)); - f.add_decoration(std::make_unique(2, 4, 6, Source{})); + f.add_decoration(create(2, 4, 6, Source{})); std::ostringstream out; f.to_str(out, 2); @@ -326,11 +317,10 @@ TEST_F(FunctionTest, ToStr_WithParams) { type::I32Type i32; VariableList params; - params.push_back( - std::make_unique("var", StorageClass::kNone, &i32)); + params.push_back(create("var", StorageClass::kNone, &i32)); - auto block = std::make_unique(); - block->append(std::make_unique()); + auto block = create(); + block->append(create()); Function f("func", std::move(params), &void_type); f.set_body(std::move(block)); @@ -364,10 +354,8 @@ TEST_F(FunctionTest, TypeName_WithParams) { type::F32Type f32; VariableList params; - params.push_back( - std::make_unique("var1", StorageClass::kNone, &i32)); - params.push_back( - std::make_unique("var2", StorageClass::kNone, &f32)); + params.push_back(create("var1", StorageClass::kNone, &i32)); + params.push_back(create("var2", StorageClass::kNone, &f32)); Function f("func", std::move(params), &void_type); EXPECT_EQ(f.type_name(), "__func__void__i32__f32"); @@ -377,8 +365,8 @@ TEST_F(FunctionTest, GetLastStatement) { type::VoidType void_type; VariableList params; - auto body = std::make_unique(); - auto stmt = std::make_unique(); + auto body = create(); + auto stmt = create(); auto* stmt_ptr = stmt.get(); body->append(std::move(stmt)); Function f("func", std::move(params), &void_type); @@ -391,7 +379,7 @@ TEST_F(FunctionTest, GetLastStatement_nullptr) { type::VoidType void_type; VariableList params; - auto body = std::make_unique(); + auto body = create(); Function f("func", std::move(params), &void_type); f.set_body(std::move(body)); @@ -413,7 +401,7 @@ TEST_F(FunctionTest, WorkgroupSize_NoneSet) { TEST_F(FunctionTest, WorkgroupSize) { type::VoidType void_type; Function f("f", {}, &void_type); - f.add_decoration(std::make_unique(2u, 4u, 6u, Source{})); + f.add_decoration(create(2u, 4u, 6u, Source{})); uint32_t x = 0; uint32_t y = 0; diff --git a/src/ast/if_statement_test.cc b/src/ast/if_statement_test.cc index e36cc1fa03..d63368b0ad 100644 --- a/src/ast/if_statement_test.cc +++ b/src/ast/if_statement_test.cc @@ -25,9 +25,9 @@ namespace { using IfStatementTest = TestHelper; TEST_F(IfStatementTest, Creation) { - 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()); auto* cond_ptr = cond.get(); auto* stmt_ptr = body->get(0); @@ -39,9 +39,9 @@ TEST_F(IfStatementTest, Creation) { } TEST_F(IfStatementTest, Creation_WithSource) { - 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()); IfStatement stmt(Source{Source::Location{20, 2}}, std::move(cond), std::move(body)); @@ -56,23 +56,23 @@ TEST_F(IfStatementTest, IsIf) { } TEST_F(IfStatementTest, IsValid) { - 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()); IfStatement stmt(std::move(cond), std::move(body)); EXPECT_TRUE(stmt.IsValid()); } TEST_F(IfStatementTest, IsValid_WithElseStatements) { - 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()); ElseStatementList else_stmts; - else_stmts.push_back(std::make_unique()); - else_stmts[0]->set_condition(std::make_unique("Ident")); - else_stmts.push_back(std::make_unique()); + else_stmts.push_back(create()); + else_stmts[0]->set_condition(create("Ident")); + else_stmts.push_back(create()); IfStatement stmt(std::move(cond), std::move(body)); stmt.set_else_statements(std::move(else_stmts)); @@ -80,26 +80,26 @@ TEST_F(IfStatementTest, IsValid_WithElseStatements) { } TEST_F(IfStatementTest, IsValid_MissingCondition) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); IfStatement stmt(nullptr, std::move(body)); EXPECT_FALSE(stmt.IsValid()); } TEST_F(IfStatementTest, IsValid_InvalidCondition) { - auto cond = std::make_unique(""); - auto body = std::make_unique(); - body->append(std::make_unique()); + auto cond = create(""); + auto body = create(); + body->append(create()); IfStatement stmt(std::move(cond), std::move(body)); EXPECT_FALSE(stmt.IsValid()); } TEST_F(IfStatementTest, IsValid_NullBodyStatement) { - 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()); body->append(nullptr); IfStatement stmt(std::move(cond), std::move(body)); @@ -107,24 +107,24 @@ TEST_F(IfStatementTest, IsValid_NullBodyStatement) { } TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) { - auto cond = std::make_unique("cond"); - auto body = std::make_unique(); - body->append(std::make_unique()); - body->append(std::make_unique()); + auto cond = create("cond"); + auto body = create(); + body->append(create()); + body->append(create()); IfStatement stmt(std::move(cond), std::move(body)); EXPECT_FALSE(stmt.IsValid()); } TEST_F(IfStatementTest, IsValid_NullElseStatement) { - 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()); ElseStatementList else_stmts; - else_stmts.push_back(std::make_unique()); - else_stmts[0]->set_condition(std::make_unique("Ident")); - else_stmts.push_back(std::make_unique()); + else_stmts.push_back(create()); + else_stmts[0]->set_condition(create("Ident")); + else_stmts.push_back(create()); else_stmts.push_back(nullptr); IfStatement stmt(std::move(cond), std::move(body)); @@ -133,13 +133,13 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) { } TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { - 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()); ElseStatementList else_stmts; - else_stmts.push_back(std::make_unique()); - else_stmts[0]->set_condition(std::make_unique("")); + else_stmts.push_back(create()); + else_stmts[0]->set_condition(create("")); IfStatement stmt(std::move(cond), std::move(body)); stmt.set_else_statements(std::move(else_stmts)); @@ -147,13 +147,13 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { } TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { - 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()); ElseStatementList else_stmts; - else_stmts.push_back(std::make_unique()); - else_stmts.push_back(std::make_unique()); + else_stmts.push_back(create()); + else_stmts.push_back(create()); IfStatement stmt(std::move(cond), std::move(body)); stmt.set_else_statements(std::move(else_stmts)); @@ -161,14 +161,14 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { } TEST_F(IfStatementTest, IsValid_ElseNotLast) { - 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()); ElseStatementList else_stmts; - else_stmts.push_back(std::make_unique()); - else_stmts.push_back(std::make_unique()); - else_stmts[1]->set_condition(std::make_unique("ident")); + else_stmts.push_back(create()); + else_stmts.push_back(create()); + else_stmts[1]->set_condition(create("ident")); IfStatement stmt(std::move(cond), std::move(body)); stmt.set_else_statements(std::move(else_stmts)); @@ -176,9 +176,9 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) { } TEST_F(IfStatementTest, ToStr) { - 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()); IfStatement stmt(std::move(cond), std::move(body)); @@ -196,22 +196,22 @@ TEST_F(IfStatementTest, ToStr) { } TEST_F(IfStatementTest, ToStr_WithElseStatements) { - 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()); - auto else_if_body = std::make_unique(); - else_if_body->append(std::make_unique()); + auto else_if_body = create(); + else_if_body->append(create()); - auto else_body = std::make_unique(); - else_body->append(std::make_unique()); - else_body->append(std::make_unique()); + auto else_body = create(); + else_body->append(create()); + else_body->append(create()); ElseStatementList else_stmts; - else_stmts.push_back(std::make_unique()); - else_stmts[0]->set_condition(std::make_unique("ident")); + else_stmts.push_back(create()); + else_stmts[0]->set_condition(create("ident")); else_stmts[0]->set_body(std::move(else_if_body)); - else_stmts.push_back(std::make_unique()); + else_stmts.push_back(create()); else_stmts[1]->set_body(std::move(else_body)); IfStatement stmt(std::move(cond), std::move(body)); diff --git a/src/ast/loop_statement_test.cc b/src/ast/loop_statement_test.cc index 73f0f932d8..a090f9a32d 100644 --- a/src/ast/loop_statement_test.cc +++ b/src/ast/loop_statement_test.cc @@ -28,12 +28,12 @@ namespace { using LoopStatementTest = TestHelper; TEST_F(LoopStatementTest, Creation) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); auto* b_ptr = body->last(); - auto continuing = std::make_unique(); - continuing->append(std::make_unique()); + auto continuing = create(); + continuing->append(create()); auto* c_ptr = continuing->last(); LoopStatement l(std::move(body), std::move(continuing)); @@ -44,11 +44,11 @@ TEST_F(LoopStatementTest, Creation) { } TEST_F(LoopStatementTest, Creation_WithSource) { - 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()); LoopStatement l(Source{Source::Location{20, 2}}, std::move(body), std::move(continuing)); @@ -63,79 +63,78 @@ TEST_F(LoopStatementTest, IsLoop) { } TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); LoopStatement l(std::move(body), {}); EXPECT_FALSE(l.has_continuing()); } TEST_F(LoopStatementTest, HasContinuing_WithContinuing) { - 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()); LoopStatement l(std::move(body), std::move(continuing)); EXPECT_TRUE(l.has_continuing()); } TEST_F(LoopStatementTest, IsValid) { - 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()); LoopStatement l(std::move(body), std::move(continuing)); EXPECT_TRUE(l.IsValid()); } TEST_F(LoopStatementTest, IsValid_WithoutContinuing) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); - LoopStatement l(std::move(body), std::make_unique()); + LoopStatement l(std::move(body), create()); EXPECT_TRUE(l.IsValid()); } TEST_F(LoopStatementTest, IsValid_WithoutBody) { - LoopStatement l(std::make_unique(), - std::make_unique()); + LoopStatement l(create(), create()); EXPECT_TRUE(l.IsValid()); } TEST_F(LoopStatementTest, IsValid_NullBodyStatement) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); body->append(nullptr); - auto continuing = std::make_unique(); - continuing->append(std::make_unique()); + auto continuing = create(); + continuing->append(create()); LoopStatement l(std::move(body), std::move(continuing)); EXPECT_FALSE(l.IsValid()); } TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) { - auto body = std::make_unique(); - body->append(std::make_unique()); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); + body->append(create()); - auto continuing = std::make_unique(); - continuing->append(std::make_unique()); + auto continuing = create(); + continuing->append(create()); LoopStatement l(std::move(body), std::move(continuing)); EXPECT_FALSE(l.IsValid()); } TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) { - 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()); continuing->append(nullptr); LoopStatement l(std::move(body), std::move(continuing)); @@ -143,20 +142,20 @@ TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) { } TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) { - 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()); - continuing->append(std::make_unique()); + auto continuing = create(); + continuing->append(create()); + continuing->append(create()); LoopStatement l(std::move(body), std::move(continuing)); EXPECT_FALSE(l.IsValid()); } TEST_F(LoopStatementTest, ToStr) { - auto body = std::make_unique(); - body->append(std::make_unique()); + auto body = create(); + body->append(create()); LoopStatement l(std::move(body), {}); std::ostringstream out; @@ -168,11 +167,11 @@ TEST_F(LoopStatementTest, ToStr) { } TEST_F(LoopStatementTest, ToStr_WithContinuing) { - 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()); LoopStatement l(std::move(body), std::move(continuing)); std::ostringstream out; diff --git a/src/ast/member_accessor_expression_test.cc b/src/ast/member_accessor_expression_test.cc index 4c49327777..6dc2a9e69a 100644 --- a/src/ast/member_accessor_expression_test.cc +++ b/src/ast/member_accessor_expression_test.cc @@ -26,8 +26,8 @@ namespace { using MemberAccessorExpressionTest = TestHelper; TEST_F(MemberAccessorExpressionTest, Creation) { - auto str = std::make_unique("structure"); - auto mem = std::make_unique("member"); + auto str = create("structure"); + auto mem = create("member"); auto* str_ptr = str.get(); auto* mem_ptr = mem.get(); @@ -38,8 +38,8 @@ TEST_F(MemberAccessorExpressionTest, Creation) { } TEST_F(MemberAccessorExpressionTest, Creation_WithSource) { - auto str = std::make_unique("structure"); - auto mem = std::make_unique("member"); + auto str = create("structure"); + auto mem = create("member"); MemberAccessorExpression stmt(Source{Source::Location{20, 2}}, std::move(str), std::move(mem)); @@ -54,15 +54,15 @@ TEST_F(MemberAccessorExpressionTest, IsMemberAccessor) { } TEST_F(MemberAccessorExpressionTest, IsValid) { - auto str = std::make_unique("structure"); - auto mem = std::make_unique("member"); + auto str = create("structure"); + auto mem = create("member"); MemberAccessorExpression stmt(std::move(str), std::move(mem)); EXPECT_TRUE(stmt.IsValid()); } TEST_F(MemberAccessorExpressionTest, IsValid_NullStruct) { - auto mem = std::make_unique("member"); + auto mem = create("member"); MemberAccessorExpression stmt; stmt.set_member(std::move(mem)); @@ -70,15 +70,15 @@ TEST_F(MemberAccessorExpressionTest, IsValid_NullStruct) { } TEST_F(MemberAccessorExpressionTest, IsValid_InvalidStruct) { - auto str = std::make_unique(""); - auto mem = std::make_unique("member"); + auto str = create(""); + auto mem = create("member"); MemberAccessorExpression stmt(std::move(str), std::move(mem)); EXPECT_FALSE(stmt.IsValid()); } TEST_F(MemberAccessorExpressionTest, IsValid_NullMember) { - auto str = std::make_unique("structure"); + auto str = create("structure"); MemberAccessorExpression stmt; stmt.set_structure(std::move(str)); @@ -86,16 +86,16 @@ TEST_F(MemberAccessorExpressionTest, IsValid_NullMember) { } TEST_F(MemberAccessorExpressionTest, IsValid_InvalidMember) { - auto str = std::make_unique("structure"); - auto mem = std::make_unique(""); + auto str = create("structure"); + auto mem = create(""); MemberAccessorExpression stmt(std::move(str), std::move(mem)); EXPECT_FALSE(stmt.IsValid()); } TEST_F(MemberAccessorExpressionTest, ToStr) { - auto str = std::make_unique("structure"); - auto mem = std::make_unique("member"); + auto str = create("structure"); + auto mem = create("member"); MemberAccessorExpression stmt(std::move(str), std::move(mem)); std::ostringstream out; diff --git a/src/ast/module_test.cc b/src/ast/module_test.cc index f5fd5ae21e..eaddc076e1 100644 --- a/src/ast/module_test.cc +++ b/src/ast/module_test.cc @@ -48,7 +48,7 @@ TEST_F(ModuleTest, LookupFunction) { type::F32Type f32; Module m; - auto func = std::make_unique("main", VariableList{}, &f32); + auto func = create("main", VariableList{}, &f32); auto* func_ptr = func.get(); m.AddFunction(std::move(func)); EXPECT_EQ(func_ptr, m.FindFunctionByName("main")); @@ -66,7 +66,7 @@ TEST_F(ModuleTest, IsValid_Empty) { TEST_F(ModuleTest, IsValid_GlobalVariable) { type::F32Type f32; - auto var = std::make_unique("var", StorageClass::kInput, &f32); + auto var = create("var", StorageClass::kInput, &f32); Module m; m.AddGlobalVariable(std::move(var)); @@ -80,7 +80,7 @@ TEST_F(ModuleTest, IsValid_Null_GlobalVariable) { } TEST_F(ModuleTest, IsValid_Invalid_GlobalVariable) { - auto var = std::make_unique("var", StorageClass::kInput, nullptr); + auto var = create("var", StorageClass::kInput, nullptr); Module m; m.AddGlobalVariable(std::move(var)); @@ -124,7 +124,7 @@ TEST_F(ModuleTest, IsValid_Struct_EmptyName) { TEST_F(ModuleTest, IsValid_Function) { type::F32Type f32; - auto func = std::make_unique("main", VariableList(), &f32); + auto func = create("main", VariableList(), &f32); Module m; m.AddFunction(std::move(func)); @@ -138,7 +138,7 @@ TEST_F(ModuleTest, IsValid_Null_Function) { } TEST_F(ModuleTest, IsValid_Invalid_Function) { - auto func = std::make_unique(); + auto func = create(); Module m; m.AddFunction(std::move(func)); diff --git a/src/ast/return_statement_test.cc b/src/ast/return_statement_test.cc index 0a68f9bad2..02bf3d2df7 100644 --- a/src/ast/return_statement_test.cc +++ b/src/ast/return_statement_test.cc @@ -26,7 +26,7 @@ namespace { using ReturnStatementTest = TestHelper; TEST_F(ReturnStatementTest, Creation) { - auto expr = std::make_unique("expr"); + auto expr = create("expr"); auto* expr_ptr = expr.get(); ReturnStatement r(std::move(expr)); @@ -51,7 +51,7 @@ TEST_F(ReturnStatementTest, HasValue_WithoutValue) { } TEST_F(ReturnStatementTest, HasValue_WithValue) { - auto expr = std::make_unique("expr"); + auto expr = create("expr"); ReturnStatement r(std::move(expr)); EXPECT_TRUE(r.has_value()); } @@ -62,19 +62,19 @@ TEST_F(ReturnStatementTest, IsValid_WithoutValue) { } TEST_F(ReturnStatementTest, IsValid_WithValue) { - auto expr = std::make_unique("expr"); + auto expr = create("expr"); ReturnStatement r(std::move(expr)); EXPECT_TRUE(r.IsValid()); } TEST_F(ReturnStatementTest, IsValid_InvalidValue) { - auto expr = std::make_unique(""); + auto expr = create(""); ReturnStatement r(std::move(expr)); EXPECT_FALSE(r.IsValid()); } TEST_F(ReturnStatementTest, ToStr_WithValue) { - auto expr = std::make_unique("expr"); + auto expr = create("expr"); ReturnStatement r(std::move(expr)); std::ostringstream out; r.to_str(out, 2); diff --git a/src/ast/scalar_constructor_expression_test.cc b/src/ast/scalar_constructor_expression_test.cc index b82dbfa6cc..9ca57a7a6b 100644 --- a/src/ast/scalar_constructor_expression_test.cc +++ b/src/ast/scalar_constructor_expression_test.cc @@ -26,7 +26,7 @@ using ScalarConstructorExpressionTest = TestHelper; TEST_F(ScalarConstructorExpressionTest, Creation) { ast::type::BoolType bool_type; - auto b = std::make_unique(&bool_type, true); + auto b = create(&bool_type, true); auto* b_ptr = b.get(); ScalarConstructorExpression c(std::move(b)); EXPECT_EQ(c.literal(), b_ptr); @@ -34,7 +34,7 @@ TEST_F(ScalarConstructorExpressionTest, Creation) { TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) { ast::type::BoolType bool_type; - auto b = std::make_unique(&bool_type, true); + auto b = create(&bool_type, true); ScalarConstructorExpression c(Source{Source::Location{20, 2}}, std::move(b)); auto src = c.source(); EXPECT_EQ(src.range.begin.line, 20u); @@ -43,7 +43,7 @@ TEST_F(ScalarConstructorExpressionTest, Creation_WithSource) { TEST_F(ScalarConstructorExpressionTest, IsValid) { ast::type::BoolType bool_type; - auto b = std::make_unique(&bool_type, true); + auto b = create(&bool_type, true); ScalarConstructorExpression c(std::move(b)); EXPECT_TRUE(c.IsValid()); } @@ -55,7 +55,7 @@ TEST_F(ScalarConstructorExpressionTest, IsValid_MissingLiteral) { TEST_F(ScalarConstructorExpressionTest, ToStr) { ast::type::BoolType bool_type; - auto b = std::make_unique(&bool_type, true); + auto b = create(&bool_type, true); ScalarConstructorExpression c(std::move(b)); std::ostringstream out; c.to_str(out, 2); diff --git a/src/ast/struct_member_test.cc b/src/ast/struct_member_test.cc index 20912bc27a..4981a2c837 100644 --- a/src/ast/struct_member_test.cc +++ b/src/ast/struct_member_test.cc @@ -30,8 +30,7 @@ using StructMemberTest = TestHelper; TEST_F(StructMemberTest, Creation) { type::I32Type i32; StructMemberDecorationList decorations; - decorations.emplace_back( - std::make_unique(4, Source{})); + decorations.emplace_back(create(4, Source{})); StructMember st{"a", &i32, std::move(decorations)}; EXPECT_EQ(st.name(), "a"); @@ -78,8 +77,7 @@ TEST_F(StructMemberTest, IsValid_NullType) { TEST_F(StructMemberTest, IsValid_Null_Decoration) { type::I32Type i32; StructMemberDecorationList decorations; - decorations.emplace_back( - std::make_unique(4, Source{})); + decorations.emplace_back(create(4, Source{})); decorations.push_back(nullptr); StructMember st{"a", &i32, std::move(decorations)}; @@ -89,8 +87,7 @@ TEST_F(StructMemberTest, IsValid_Null_Decoration) { TEST_F(StructMemberTest, ToStr) { type::I32Type i32; StructMemberDecorationList decorations; - decorations.emplace_back( - std::make_unique(4, Source{})); + decorations.emplace_back(create(4, Source{})); StructMember st{"a", &i32, std::move(decorations)}; std::ostringstream out; diff --git a/src/ast/struct_test.cc b/src/ast/struct_test.cc index 540a4a8e06..e61a7debde 100644 --- a/src/ast/struct_test.cc +++ b/src/ast/struct_test.cc @@ -33,7 +33,7 @@ TEST_F(StructTest, Creation) { type::I32Type i32; StructMemberList members; members.push_back( - std::make_unique("a", &i32, StructMemberDecorationList())); + create("a", &i32, StructMemberDecorationList())); Struct s{std::move(members)}; EXPECT_EQ(s.members().size(), 1u); @@ -49,10 +49,10 @@ TEST_F(StructTest, Creation_WithDecorations) { StructMemberList members; members.push_back( - std::make_unique("a", &i32, StructMemberDecorationList())); + create("a", &i32, StructMemberDecorationList())); StructDecorationList decos; - decos.push_back(std::make_unique(Source{})); + decos.push_back(create(Source{})); Struct s{std::move(decos), std::move(members)}; EXPECT_EQ(s.members().size(), 1u); @@ -69,10 +69,10 @@ TEST_F(StructTest, CreationWithSourceAndDecorations) { StructMemberList members; members.emplace_back( - std::make_unique("a", &i32, StructMemberDecorationList())); + create("a", &i32, StructMemberDecorationList())); StructDecorationList decos; - decos.push_back(std::make_unique(Source{})); + decos.push_back(create(Source{})); Struct s{ Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, @@ -96,7 +96,7 @@ TEST_F(StructTest, IsValid_Null_StructMember) { StructMemberList members; members.push_back( - std::make_unique("a", &i32, StructMemberDecorationList())); + create("a", &i32, StructMemberDecorationList())); members.push_back(nullptr); Struct s{std::move(members)}; @@ -108,7 +108,7 @@ TEST_F(StructTest, IsValid_Invalid_StructMember) { StructMemberList members; members.push_back( - std::make_unique("", &i32, StructMemberDecorationList())); + create("", &i32, StructMemberDecorationList())); Struct s{std::move(members)}; EXPECT_FALSE(s.IsValid()); @@ -119,10 +119,10 @@ TEST_F(StructTest, ToStr) { StructMemberList members; members.emplace_back( - std::make_unique("a", &i32, StructMemberDecorationList())); + create("a", &i32, StructMemberDecorationList())); StructDecorationList decos; - decos.push_back(std::make_unique(Source{})); + decos.push_back(create(Source{})); Struct s{std::move(decos), std::move(members)}; diff --git a/src/ast/switch_statement_test.cc b/src/ast/switch_statement_test.cc index 4b78e799d8..8bf21b7705 100644 --- a/src/ast/switch_statement_test.cc +++ b/src/ast/switch_statement_test.cc @@ -32,12 +32,12 @@ TEST_F(SwitchStatementTest, Creation) { ast::type::I32Type i32; CaseSelectorList lit; - lit.push_back(std::make_unique(&i32, 1)); + lit.push_back(create(&i32, 1)); - auto ident = std::make_unique("ident"); + auto ident = create("ident"); CaseStatementList body; - body.push_back(std::make_unique( - std::move(lit), std::make_unique())); + body.push_back( + create(std::move(lit), create())); auto* ident_ptr = ident.get(); auto* case_ptr = body[0].get(); @@ -49,7 +49,7 @@ TEST_F(SwitchStatementTest, Creation) { } TEST_F(SwitchStatementTest, Creation_WithSource) { - auto ident = std::make_unique("ident"); + auto ident = create("ident"); SwitchStatement stmt(Source{Source::Location{20, 2}}, std::move(ident), CaseStatementList()); @@ -67,12 +67,12 @@ TEST_F(SwitchStatementTest, IsValid) { ast::type::I32Type i32; CaseSelectorList lit; - lit.push_back(std::make_unique(&i32, 2)); + lit.push_back(create(&i32, 2)); - auto ident = std::make_unique("ident"); + auto ident = create("ident"); CaseStatementList body; - body.push_back(std::make_unique( - std::move(lit), std::make_unique())); + body.push_back( + create(std::move(lit), create())); SwitchStatement stmt(std::move(ident), std::move(body)); EXPECT_TRUE(stmt.IsValid()); @@ -82,11 +82,11 @@ TEST_F(SwitchStatementTest, IsValid_Null_Condition) { ast::type::I32Type i32; CaseSelectorList lit; - lit.push_back(std::make_unique(&i32, 2)); + lit.push_back(create(&i32, 2)); CaseStatementList body; - body.push_back(std::make_unique( - std::move(lit), std::make_unique())); + body.push_back( + create(std::move(lit), create())); SwitchStatement stmt; stmt.set_body(std::move(body)); @@ -97,12 +97,12 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) { ast::type::I32Type i32; CaseSelectorList lit; - lit.push_back(std::make_unique(&i32, 2)); + lit.push_back(create(&i32, 2)); - auto ident = std::make_unique(""); + auto ident = create(""); CaseStatementList body; - body.push_back(std::make_unique( - std::move(lit), std::make_unique())); + body.push_back( + create(std::move(lit), create())); SwitchStatement stmt(std::move(ident), std::move(body)); EXPECT_FALSE(stmt.IsValid()); @@ -112,12 +112,12 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) { ast::type::I32Type i32; CaseSelectorList lit; - lit.push_back(std::make_unique(&i32, 2)); + lit.push_back(create(&i32, 2)); - auto ident = std::make_unique("ident"); + auto ident = create("ident"); CaseStatementList body; - body.push_back(std::make_unique( - std::move(lit), std::make_unique())); + body.push_back( + create(std::move(lit), create())); body.push_back(nullptr); SwitchStatement stmt(std::move(ident), std::move(body)); @@ -125,21 +125,21 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) { } TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) { - auto ident = std::make_unique("ident"); + auto ident = create("ident"); - auto case_body = std::make_unique(); + auto case_body = create(); case_body->append(nullptr); CaseStatementList body; - body.push_back(std::make_unique(CaseSelectorList{}, - std::move(case_body))); + body.push_back( + create(CaseSelectorList{}, std::move(case_body))); SwitchStatement stmt(std::move(ident), std::move(body)); EXPECT_FALSE(stmt.IsValid()); } TEST_F(SwitchStatementTest, ToStr_Empty) { - auto ident = std::make_unique("ident"); + auto ident = create("ident"); SwitchStatement stmt(std::move(ident), {}); std::ostringstream out; @@ -156,12 +156,12 @@ TEST_F(SwitchStatementTest, ToStr) { ast::type::I32Type i32; CaseSelectorList lit; - lit.push_back(std::make_unique(&i32, 2)); + lit.push_back(create(&i32, 2)); - auto ident = std::make_unique("ident"); + auto ident = create("ident"); CaseStatementList body; - body.push_back(std::make_unique( - std::move(lit), std::make_unique())); + body.push_back( + create(std::move(lit), create())); SwitchStatement stmt(std::move(ident), std::move(body)); std::ostringstream out; diff --git a/src/ast/test_helper.h b/src/ast/test_helper.h index a00623f46e..596d0ce863 100644 --- a/src/ast/test_helper.h +++ b/src/ast/test_helper.h @@ -15,6 +15,9 @@ #ifndef SRC_AST_TEST_HELPER_H_ #define SRC_AST_TEST_HELPER_H_ +#include +#include + #include "gtest/gtest.h" namespace tint { @@ -26,6 +29,13 @@ class TestHelperBase : public BASE { public: TestHelperBase() {} ~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)...); + } }; using TestHelper = TestHelperBase; diff --git a/src/ast/type_constructor_expression_test.cc b/src/ast/type_constructor_expression_test.cc index c3df0fb28f..8a30a62d52 100644 --- a/src/ast/type_constructor_expression_test.cc +++ b/src/ast/type_constructor_expression_test.cc @@ -32,7 +32,7 @@ using TypeConstructorExpressionTest = TestHelper; TEST_F(TypeConstructorExpressionTest, Creation) { type::F32Type f32; ExpressionList expr; - expr.push_back(std::make_unique("expr")); + expr.push_back(create("expr")); auto* expr_ptr = expr[0].get(); TypeConstructorExpression t(&f32, std::move(expr)); @@ -44,7 +44,7 @@ TEST_F(TypeConstructorExpressionTest, Creation) { TEST_F(TypeConstructorExpressionTest, Creation_WithSource) { type::F32Type f32; ExpressionList expr; - expr.push_back(std::make_unique("expr")); + expr.push_back(create("expr")); TypeConstructorExpression t(Source{Source::Location{20, 2}}, &f32, std::move(expr)); @@ -61,7 +61,7 @@ TEST_F(TypeConstructorExpressionTest, IsTypeConstructor) { TEST_F(TypeConstructorExpressionTest, IsValid) { type::F32Type f32; ExpressionList expr; - expr.push_back(std::make_unique("expr")); + expr.push_back(create("expr")); TypeConstructorExpression t(&f32, std::move(expr)); EXPECT_TRUE(t.IsValid()); @@ -77,7 +77,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_EmptyValue) { TEST_F(TypeConstructorExpressionTest, IsValid_NullType) { ExpressionList expr; - expr.push_back(std::make_unique("expr")); + expr.push_back(create("expr")); TypeConstructorExpression t; t.set_values(std::move(expr)); @@ -87,7 +87,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullType) { TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) { type::F32Type f32; ExpressionList expr; - expr.push_back(std::make_unique("expr")); + expr.push_back(create("expr")); expr.push_back(nullptr); TypeConstructorExpression t(&f32, std::move(expr)); @@ -97,7 +97,7 @@ TEST_F(TypeConstructorExpressionTest, IsValid_NullValue) { TEST_F(TypeConstructorExpressionTest, IsValid_InvalidValue) { type::F32Type f32; ExpressionList expr; - expr.push_back(std::make_unique("")); + expr.push_back(create("")); TypeConstructorExpression t(&f32, std::move(expr)); EXPECT_FALSE(t.IsValid()); @@ -107,9 +107,9 @@ TEST_F(TypeConstructorExpressionTest, ToStr) { type::F32Type f32; type::VectorType vec(&f32, 3); ExpressionList expr; - expr.push_back(std::make_unique("expr_1")); - expr.push_back(std::make_unique("expr_2")); - expr.push_back(std::make_unique("expr_3")); + expr.push_back(create("expr_1")); + expr.push_back(create("expr_2")); + expr.push_back(create("expr_3")); TypeConstructorExpression t(&vec, std::move(expr)); std::ostringstream out; diff --git a/src/ast/unary_op_expression_test.cc b/src/ast/unary_op_expression_test.cc index b23fa61f6d..4adc29d4d0 100644 --- a/src/ast/unary_op_expression_test.cc +++ b/src/ast/unary_op_expression_test.cc @@ -26,7 +26,7 @@ namespace { using UnaryOpExpressionTest = TestHelper; TEST_F(UnaryOpExpressionTest, Creation) { - auto ident = std::make_unique("ident"); + auto ident = create("ident"); auto* ident_ptr = ident.get(); UnaryOpExpression u(UnaryOp::kNot, std::move(ident)); @@ -35,7 +35,7 @@ TEST_F(UnaryOpExpressionTest, Creation) { } TEST_F(UnaryOpExpressionTest, Creation_WithSource) { - auto ident = std::make_unique("ident"); + auto ident = create("ident"); UnaryOpExpression u(Source{Source::Location{20, 2}}, UnaryOp::kNot, std::move(ident)); auto src = u.source(); @@ -49,7 +49,7 @@ TEST_F(UnaryOpExpressionTest, IsUnaryOp) { } TEST_F(UnaryOpExpressionTest, IsValid) { - auto ident = std::make_unique("ident"); + auto ident = create("ident"); UnaryOpExpression u(UnaryOp::kNot, std::move(ident)); EXPECT_TRUE(u.IsValid()); } @@ -61,13 +61,13 @@ TEST_F(UnaryOpExpressionTest, IsValid_NullExpression) { } TEST_F(UnaryOpExpressionTest, IsValid_InvalidExpression) { - auto ident = std::make_unique(""); + auto ident = create(""); UnaryOpExpression u(UnaryOp::kNot, std::move(ident)); EXPECT_FALSE(u.IsValid()); } TEST_F(UnaryOpExpressionTest, ToStr) { - auto ident = std::make_unique("ident"); + auto ident = create("ident"); UnaryOpExpression u(UnaryOp::kNot, std::move(ident)); std::ostringstream out; u.to_str(out, 2); diff --git a/src/ast/variable_decl_statement_test.cc b/src/ast/variable_decl_statement_test.cc index 7a104d078a..b32e2c177f 100644 --- a/src/ast/variable_decl_statement_test.cc +++ b/src/ast/variable_decl_statement_test.cc @@ -26,7 +26,7 @@ using VariableDeclStatementTest = TestHelper; TEST_F(VariableDeclStatementTest, Creation) { type::F32Type f32; - auto var = std::make_unique("a", StorageClass::kNone, &f32); + auto var = create("a", StorageClass::kNone, &f32); auto* var_ptr = var.get(); VariableDeclStatement stmt(std::move(var)); @@ -35,7 +35,7 @@ TEST_F(VariableDeclStatementTest, Creation) { TEST_F(VariableDeclStatementTest, Creation_WithSource) { type::F32Type f32; - auto var = std::make_unique("a", StorageClass::kNone, &f32); + auto var = create("a", StorageClass::kNone, &f32); VariableDeclStatement stmt(Source{Source::Location{20, 2}}, std::move(var)); auto src = stmt.source(); @@ -50,14 +50,14 @@ TEST_F(VariableDeclStatementTest, IsVariableDecl) { TEST_F(VariableDeclStatementTest, IsValid) { type::F32Type f32; - auto var = std::make_unique("a", StorageClass::kNone, &f32); + auto var = create("a", StorageClass::kNone, &f32); VariableDeclStatement stmt(std::move(var)); EXPECT_TRUE(stmt.IsValid()); } TEST_F(VariableDeclStatementTest, IsValid_InvalidVariable) { type::F32Type f32; - auto var = std::make_unique("", StorageClass::kNone, &f32); + auto var = create("", StorageClass::kNone, &f32); VariableDeclStatement stmt(std::move(var)); EXPECT_FALSE(stmt.IsValid()); } @@ -69,7 +69,7 @@ TEST_F(VariableDeclStatementTest, IsValid_NullVariable) { TEST_F(VariableDeclStatementTest, ToStr) { type::F32Type f32; - auto var = std::make_unique("a", StorageClass::kNone, &f32); + auto var = create("a", StorageClass::kNone, &f32); VariableDeclStatement stmt(Source{Source::Location{20, 2}}, std::move(var)); std::ostringstream out; diff --git a/src/ast/variable_test.cc b/src/ast/variable_test.cc index 4898d6b66f..0643b84c19 100644 --- a/src/ast/variable_test.cc +++ b/src/ast/variable_test.cc @@ -80,7 +80,7 @@ TEST_F(VariableTest, IsValid) { TEST_F(VariableTest, IsValid_WithConstructor) { type::I32Type t; Variable v{"my_var", StorageClass::kNone, &t}; - v.set_constructor(std::make_unique("ident")); + v.set_constructor(create("ident")); EXPECT_TRUE(v.IsValid()); } @@ -103,7 +103,7 @@ TEST_F(VariableTest, IsValid_MissingBoth) { TEST_F(VariableTest, IsValid_InvalidConstructor) { type::I32Type t; Variable v{"my_var", StorageClass::kNone, &t}; - v.set_constructor(std::make_unique("")); + v.set_constructor(create("")); EXPECT_FALSE(v.IsValid()); }