writer/hlsl tests: Replace std::make_unique<T> -> create<T>

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: I06511413e4d1afd84504f9ec8ab36f2c02764b9b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32671
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-13 22:21:05 +00:00 committed by Commit Bot service account
parent 16b12fa9a4
commit bbc9b967a3
25 changed files with 1114 additions and 1367 deletions

View File

@ -51,16 +51,14 @@ TEST_F(HlslGeneratorImplTest_AliasType, EmitAliasType_Struct) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(std::make_unique<ast::StructMember>( members.push_back(
"a", &f32, ast::StructMemberDecorationList{})); create<ast::StructMember>("a", &f32, ast::StructMemberDecorationList{}));
ast::StructMemberDecorationList b_deco; ast::StructMemberDecorationList b_deco;
b_deco.push_back( b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{})); members.push_back(create<ast::StructMember>("b", &i32, std::move(b_deco)));
members.push_back(
std::make_unique<ast::StructMember>("b", &i32, std::move(b_deco)));
auto str = std::make_unique<ast::Struct>(); auto str = create<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s("A", std::move(str)); ast::type::StructType s("A", std::move(str));

View File

@ -31,9 +31,9 @@ using HlslGeneratorImplTest_Expression = TestHelper;
TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) { TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto lit = std::make_unique<ast::SintLiteral>(&i32, 5); auto lit = create<ast::SintLiteral>(&i32, 5);
auto idx = std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)); auto idx = create<ast::ScalarConstructorExpression>(std::move(lit));
auto ary = std::make_unique<ast::IdentifierExpression>("ary"); auto ary = create<ast::IdentifierExpression>("ary");
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx)); ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));
@ -42,8 +42,8 @@ TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) {
} }
TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) { TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) {
auto ary = std::make_unique<ast::IdentifierExpression>("ary"); auto ary = create<ast::IdentifierExpression>("ary");
auto idx = std::make_unique<ast::IdentifierExpression>("idx"); auto idx = create<ast::IdentifierExpression>("idx");
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx)); ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx));

View File

@ -28,8 +28,8 @@ namespace {
using HlslGeneratorImplTest_Assign = TestHelper; using HlslGeneratorImplTest_Assign = TestHelper;
TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) { TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) {
auto lhs = std::make_unique<ast::IdentifierExpression>("lhs"); auto lhs = create<ast::IdentifierExpression>("lhs");
auto rhs = std::make_unique<ast::IdentifierExpression>("rhs"); auto rhs = create<ast::IdentifierExpression>("rhs");
ast::AssignmentStatement assign(std::move(lhs), std::move(rhs)); ast::AssignmentStatement assign(std::move(lhs), std::move(rhs));
gen.increment_indent(); gen.increment_indent();

View File

@ -54,8 +54,8 @@ using HlslBinaryTest = TestParamHelper<BinaryData>;
TEST_P(HlslBinaryTest, Emit) { TEST_P(HlslBinaryTest, Emit) {
auto params = GetParam(); auto params = GetParam();
auto left = std::make_unique<ast::IdentifierExpression>("left"); auto left = create<ast::IdentifierExpression>("left");
auto right = std::make_unique<ast::IdentifierExpression>("right"); auto right = create<ast::IdentifierExpression>("right");
ast::BinaryExpression expr(params.op, std::move(left), std::move(right)); ast::BinaryExpression expr(params.op, std::move(left), std::move(right));
@ -84,8 +84,8 @@ INSTANTIATE_TEST_SUITE_P(
BinaryData{"(left % right)", ast::BinaryOp::kModulo})); BinaryData{"(left % right)", ast::BinaryOp::kModulo}));
TEST_F(HlslGeneratorImplTest_Binary, Logical_And) { TEST_F(HlslGeneratorImplTest_Binary, Logical_And) {
auto left = std::make_unique<ast::IdentifierExpression>("left"); auto left = create<ast::IdentifierExpression>("left");
auto right = std::make_unique<ast::IdentifierExpression>("right"); auto right = create<ast::IdentifierExpression>("right");
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, std::move(left), ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, std::move(left),
std::move(right)); std::move(right));
@ -101,17 +101,17 @@ if (_tint_tmp) {
TEST_F(HlslGeneratorImplTest_Binary, Logical_Multi) { TEST_F(HlslGeneratorImplTest_Binary, Logical_Multi) {
// (a && b) || (c || d) // (a && b) || (c || d)
auto a = std::make_unique<ast::IdentifierExpression>("a"); auto a = create<ast::IdentifierExpression>("a");
auto b = std::make_unique<ast::IdentifierExpression>("b"); auto b = create<ast::IdentifierExpression>("b");
auto c = std::make_unique<ast::IdentifierExpression>("c"); auto c = create<ast::IdentifierExpression>("c");
auto d = std::make_unique<ast::IdentifierExpression>("d"); auto d = create<ast::IdentifierExpression>("d");
ast::BinaryExpression expr( ast::BinaryExpression expr(
ast::BinaryOp::kLogicalOr, ast::BinaryOp::kLogicalOr,
std::make_unique<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, std::move(a),
std::move(a), std::move(b)), std::move(b)),
std::make_unique<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, std::move(c),
std::move(c), std::move(d))); std::move(d)));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp_0)"); EXPECT_EQ(result(), "(_tint_tmp_0)");
@ -131,8 +131,8 @@ if (!_tint_tmp_0) {
} }
TEST_F(HlslGeneratorImplTest_Binary, Logical_Or) { TEST_F(HlslGeneratorImplTest_Binary, Logical_Or) {
auto left = std::make_unique<ast::IdentifierExpression>("left"); auto left = create<ast::IdentifierExpression>("left");
auto right = std::make_unique<ast::IdentifierExpression>("right"); auto right = create<ast::IdentifierExpression>("right");
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, std::move(left), ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, std::move(left),
std::move(right)); std::move(right));
@ -157,37 +157,36 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::ReturnStatement>( body->append(
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ReturnStatement>(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
auto else_stmt = std::make_unique<ast::ElseStatement>(std::move(body)); auto else_stmt = create<ast::ElseStatement>(std::move(body));
body = std::make_unique<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::ReturnStatement>( body->append(
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ReturnStatement>(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto else_if_stmt = std::make_unique<ast::ElseStatement>( auto else_if_stmt = create<ast::ElseStatement>(
std::make_unique<ast::BinaryExpression>( create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
ast::BinaryOp::kLogicalOr, create<ast::IdentifierExpression>("b"),
std::make_unique<ast::IdentifierExpression>("b"), create<ast::IdentifierExpression>("c")),
std::make_unique<ast::IdentifierExpression>("c")),
std::move(body)); std::move(body));
ast::ElseStatementList else_stmts; ast::ElseStatementList else_stmts;
else_stmts.push_back(std::move(else_if_stmt)); else_stmts.push_back(std::move(else_if_stmt));
else_stmts.push_back(std::move(else_stmt)); else_stmts.push_back(std::move(else_stmt));
body = std::make_unique<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::ReturnStatement>( body->append(
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ReturnStatement>(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
ast::IfStatement expr(std::make_unique<ast::BinaryExpression>( ast::IfStatement expr(
ast::BinaryOp::kLogicalAnd, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,
std::make_unique<ast::IdentifierExpression>("a"), create<ast::IdentifierExpression>("a"),
std::make_unique<ast::IdentifierExpression>("b")), create<ast::IdentifierExpression>("b")),
std::move(body)); std::move(body));
expr.set_else_statements(std::move(else_stmts)); expr.set_else_statements(std::move(else_stmts));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
@ -213,14 +212,14 @@ if ((_tint_tmp)) {
TEST_F(HlslGeneratorImplTest_Binary, Return_WithLogical) { TEST_F(HlslGeneratorImplTest_Binary, Return_WithLogical) {
// return (a && b) || c; // return (a && b) || c;
auto a = std::make_unique<ast::IdentifierExpression>("a"); auto a = create<ast::IdentifierExpression>("a");
auto b = std::make_unique<ast::IdentifierExpression>("b"); auto b = create<ast::IdentifierExpression>("b");
auto c = std::make_unique<ast::IdentifierExpression>("c"); auto c = create<ast::IdentifierExpression>("c");
ast::ReturnStatement expr(std::make_unique<ast::BinaryExpression>( ast::ReturnStatement expr(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr, ast::BinaryOp::kLogicalOr,
std::make_unique<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, std::move(a),
std::move(a), std::move(b)), std::move(b)),
std::move(c))); std::move(c)));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
@ -238,17 +237,17 @@ return (_tint_tmp_0);
TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) { TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) {
// a = (b || c) && d; // a = (b || c) && d;
auto a = std::make_unique<ast::IdentifierExpression>("a"); auto a = create<ast::IdentifierExpression>("a");
auto b = std::make_unique<ast::IdentifierExpression>("b"); auto b = create<ast::IdentifierExpression>("b");
auto c = std::make_unique<ast::IdentifierExpression>("c"); auto c = create<ast::IdentifierExpression>("c");
auto d = std::make_unique<ast::IdentifierExpression>("d"); auto d = create<ast::IdentifierExpression>("d");
ast::AssignmentStatement expr( ast::AssignmentStatement expr(
std::move(a), std::move(a),
std::make_unique<ast::BinaryExpression>( create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, ast::BinaryOp::kLogicalAnd,
std::make_unique<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, std::move(b),
std::move(b), std::move(c)), std::move(c)),
std::move(d))); std::move(d)));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
@ -268,16 +267,16 @@ TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) {
// var a : bool = (b && c) || d; // var a : bool = (b && c) || d;
ast::type::BoolType bool_type; ast::type::BoolType bool_type;
auto b = std::make_unique<ast::IdentifierExpression>("b"); auto b = create<ast::IdentifierExpression>("b");
auto c = std::make_unique<ast::IdentifierExpression>("c"); auto c = create<ast::IdentifierExpression>("c");
auto d = std::make_unique<ast::IdentifierExpression>("d"); auto d = create<ast::IdentifierExpression>("d");
auto var = std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, auto var =
&bool_type); create<ast::Variable>("a", ast::StorageClass::kFunction, &bool_type);
var->set_constructor(std::make_unique<ast::BinaryExpression>( var->set_constructor(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr, ast::BinaryOp::kLogicalOr,
std::make_unique<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, std::move(b),
std::move(b), std::move(c)), std::move(c)),
std::move(d))); std::move(d)));
ast::VariableDeclStatement expr(std::move(var)); ast::VariableDeclStatement expr(std::move(var));
@ -299,15 +298,15 @@ TEST_F(HlslGeneratorImplTest_Binary, Bitcast_WithLogical) {
// as<i32>(a && (b || c)) // as<i32>(a && (b || c))
ast::type::I32Type i32; ast::type::I32Type i32;
auto a = std::make_unique<ast::IdentifierExpression>("a"); auto a = create<ast::IdentifierExpression>("a");
auto b = std::make_unique<ast::IdentifierExpression>("b"); auto b = create<ast::IdentifierExpression>("b");
auto c = std::make_unique<ast::IdentifierExpression>("c"); auto c = create<ast::IdentifierExpression>("c");
ast::BitcastExpression expr( ast::BitcastExpression expr(
&i32, std::make_unique<ast::BinaryExpression>( &i32, create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, std::move(a), ast::BinaryOp::kLogicalAnd, std::move(a),
std::make_unique<ast::BinaryExpression>( create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
ast::BinaryOp::kLogicalOr, std::move(b), std::move(c)))); std::move(b), std::move(c))));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = a; EXPECT_EQ(pre_result(), R"(bool _tint_tmp = a;
@ -327,32 +326,27 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
auto func = auto func = create<ast::Function>("foo", ast::VariableList{}, &void_type);
std::make_unique<ast::Function>("foo", ast::VariableList{}, &void_type);
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::BinaryExpression>( params.push_back(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, create<ast::IdentifierExpression>("a"),
create<ast::IdentifierExpression>("b")));
params.push_back(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr, create<ast::IdentifierExpression>("c"),
create<ast::IdentifierExpression>("d")));
params.push_back(create<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd, ast::BinaryOp::kLogicalAnd,
std::make_unique<ast::IdentifierExpression>("a"), create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
std::make_unique<ast::IdentifierExpression>("b"))); create<ast::IdentifierExpression>("a"),
params.push_back(std::make_unique<ast::BinaryExpression>( create<ast::IdentifierExpression>("c")),
ast::BinaryOp::kLogicalOr, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
std::make_unique<ast::IdentifierExpression>("c"), create<ast::IdentifierExpression>("b"),
std::make_unique<ast::IdentifierExpression>("d"))); create<ast::IdentifierExpression>("d"))));
params.push_back(std::make_unique<ast::BinaryExpression>(
ast::BinaryOp::kLogicalAnd,
std::make_unique<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr,
std::make_unique<ast::IdentifierExpression>("a"),
std::make_unique<ast::IdentifierExpression>("c")),
std::make_unique<ast::BinaryExpression>(
ast::BinaryOp::kLogicalOr,
std::make_unique<ast::IdentifierExpression>("b"),
std::make_unique<ast::IdentifierExpression>("d"))));
ast::CallStatement expr(std::make_unique<ast::CallExpression>( ast::CallStatement expr(create<ast::CallExpression>(
std::make_unique<ast::IdentifierExpression>("foo"), std::move(params))); create<ast::IdentifierExpression>("foo"), std::move(params)));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a; EXPECT_EQ(result(), R"(bool _tint_tmp = a;

View File

@ -31,7 +31,7 @@ using HlslGeneratorImplTest_Bitcast = TestHelper;
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) { TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto id = std::make_unique<ast::IdentifierExpression>("id"); auto id = create<ast::IdentifierExpression>("id");
ast::BitcastExpression bitcast(&f32, std::move(id)); ast::BitcastExpression bitcast(&f32, std::move(id));
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
@ -40,7 +40,7 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) { TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto id = std::make_unique<ast::IdentifierExpression>("id"); auto id = create<ast::IdentifierExpression>("id");
ast::BitcastExpression bitcast(&i32, std::move(id)); ast::BitcastExpression bitcast(&i32, std::move(id));
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();
@ -49,7 +49,7 @@ TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) { TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
ast::type::U32Type u32; ast::type::U32Type u32;
auto id = std::make_unique<ast::IdentifierExpression>("id"); auto id = create<ast::IdentifierExpression>("id");
ast::BitcastExpression bitcast(&u32, std::move(id)); ast::BitcastExpression bitcast(&u32, std::move(id));
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error();

View File

@ -27,7 +27,7 @@ using HlslGeneratorImplTest_Block = TestHelper;
TEST_F(HlslGeneratorImplTest_Block, Emit_Block) { TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
ast::BlockStatement b; ast::BlockStatement b;
b.append(std::make_unique<ast::DiscardStatement>()); b.append(create<ast::DiscardStatement>());
gen.increment_indent(); gen.increment_indent();
@ -40,7 +40,7 @@ TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
TEST_F(HlslGeneratorImplTest_Block, Emit_Block_WithoutNewline) { TEST_F(HlslGeneratorImplTest_Block, Emit_Block_WithoutNewline) {
ast::BlockStatement b; ast::BlockStatement b;
b.append(std::make_unique<ast::DiscardStatement>()); b.append(create<ast::DiscardStatement>());
gen.increment_indent(); gen.increment_indent();

View File

@ -32,11 +32,10 @@ using HlslGeneratorImplTest_Call = TestHelper;
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) { TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
auto id = std::make_unique<ast::IdentifierExpression>("my_func"); auto id = create<ast::IdentifierExpression>("my_func");
ast::CallExpression call(std::move(id), {}); ast::CallExpression call(std::move(id), {});
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{}, auto func = create<ast::Function>("my_func", ast::VariableList{}, &void_type);
&void_type);
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
@ -46,14 +45,13 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) { TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
auto id = std::make_unique<ast::IdentifierExpression>("my_func"); auto id = create<ast::IdentifierExpression>("my_func");
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::IdentifierExpression>("param1")); params.push_back(create<ast::IdentifierExpression>("param1"));
params.push_back(std::make_unique<ast::IdentifierExpression>("param2")); params.push_back(create<ast::IdentifierExpression>("param2"));
ast::CallExpression call(std::move(id), std::move(params)); ast::CallExpression call(std::move(id), std::move(params));
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{}, auto func = create<ast::Function>("my_func", ast::VariableList{}, &void_type);
&void_type);
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error();
@ -63,15 +61,14 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) { TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
auto id = std::make_unique<ast::IdentifierExpression>("my_func"); auto id = create<ast::IdentifierExpression>("my_func");
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::IdentifierExpression>("param1")); params.push_back(create<ast::IdentifierExpression>("param1"));
params.push_back(std::make_unique<ast::IdentifierExpression>("param2")); params.push_back(create<ast::IdentifierExpression>("param2"));
ast::CallStatement call( ast::CallStatement call(
std::make_unique<ast::CallExpression>(std::move(id), std::move(params))); create<ast::CallExpression>(std::move(id), std::move(params)));
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{}, auto func = create<ast::Function>("my_func", ast::VariableList{}, &void_type);
&void_type);
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &call)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, &call)) << gen.error();

View File

@ -33,11 +33,11 @@ using HlslGeneratorImplTest_Case = TestHelper;
TEST_F(HlslGeneratorImplTest_Case, Emit_Case) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::BreakStatement>()); body->append(create<ast::BreakStatement>());
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5)); lit.push_back(create<ast::SintLiteral>(&i32, 5));
ast::CaseStatement c(std::move(lit), std::move(body)); ast::CaseStatement c(std::move(lit), std::move(body));
gen.increment_indent(); gen.increment_indent();
@ -53,8 +53,8 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
ast::type::I32Type i32; ast::type::I32Type i32;
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5)); lit.push_back(create<ast::SintLiteral>(&i32, 5));
ast::CaseStatement c(std::move(lit), std::make_unique<ast::BlockStatement>()); ast::CaseStatement c(std::move(lit), create<ast::BlockStatement>());
gen.increment_indent(); gen.increment_indent();
@ -68,11 +68,11 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::FallthroughStatement>()); body->append(create<ast::FallthroughStatement>());
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5)); lit.push_back(create<ast::SintLiteral>(&i32, 5));
ast::CaseStatement c(std::move(lit), std::move(body)); ast::CaseStatement c(std::move(lit), std::move(body));
gen.increment_indent(); gen.increment_indent();
@ -87,12 +87,12 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::BreakStatement>()); body->append(create<ast::BreakStatement>());
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 5)); lit.push_back(create<ast::SintLiteral>(&i32, 5));
lit.push_back(std::make_unique<ast::SintLiteral>(&i32, 6)); lit.push_back(create<ast::SintLiteral>(&i32, 6));
ast::CaseStatement c(std::move(lit), std::move(body)); ast::CaseStatement c(std::move(lit), std::move(body));
gen.increment_indent(); gen.increment_indent();
@ -108,8 +108,8 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) {
ast::CaseStatement c; ast::CaseStatement c;
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::BreakStatement>()); body->append(create<ast::BreakStatement>());
c.set_body(std::move(body)); c.set_body(std::move(body));
gen.increment_indent(); gen.increment_indent();

View File

@ -32,7 +32,7 @@ TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Scalar) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::IdentifierExpression>("id")); params.push_back(create<ast::IdentifierExpression>("id"));
ast::TypeConstructorExpression cast(&f32, std::move(params)); ast::TypeConstructorExpression cast(&f32, std::move(params));
@ -45,7 +45,7 @@ TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Vector) {
ast::type::VectorType vec3(&f32, 3); ast::type::VectorType vec3(&f32, 3);
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::IdentifierExpression>("id")); params.push_back(create<ast::IdentifierExpression>("id"));
ast::TypeConstructorExpression cast(&vec3, std::move(params)); ast::TypeConstructorExpression cast(&vec3, std::move(params));

View File

@ -37,7 +37,7 @@ using HlslGeneratorImplTest_Constructor = TestHelper;
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) {
ast::type::BoolType bool_type; ast::type::BoolType bool_type;
auto lit = std::make_unique<ast::BoolLiteral>(&bool_type, false); auto lit = create<ast::BoolLiteral>(&bool_type, false);
ast::ScalarConstructorExpression expr(std::move(lit)); ast::ScalarConstructorExpression expr(std::move(lit));
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
@ -46,7 +46,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) {
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto lit = std::make_unique<ast::SintLiteral>(&i32, -12345); auto lit = create<ast::SintLiteral>(&i32, -12345);
ast::ScalarConstructorExpression expr(std::move(lit)); ast::ScalarConstructorExpression expr(std::move(lit));
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
@ -55,7 +55,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) {
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_UInt) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_UInt) {
ast::type::U32Type u32; ast::type::U32Type u32;
auto lit = std::make_unique<ast::UintLiteral>(&u32, 56779); auto lit = create<ast::UintLiteral>(&u32, 56779);
ast::ScalarConstructorExpression expr(std::move(lit)); ast::ScalarConstructorExpression expr(std::move(lit));
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
@ -65,8 +65,7 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_UInt) {
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Float) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Float) {
ast::type::F32Type f32; ast::type::F32Type f32;
// Use a number close to 1<<30 but whose decimal representation ends in 0. // Use a number close to 1<<30 but whose decimal representation ends in 0.
auto lit = std::make_unique<ast::FloatLiteral>( auto lit = create<ast::FloatLiteral>(&f32, static_cast<float>((1 << 30) - 4));
&f32, static_cast<float>((1 << 30) - 4));
ast::ScalarConstructorExpression expr(std::move(lit)); ast::ScalarConstructorExpression expr(std::move(lit));
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
@ -76,10 +75,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Float) {
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Float) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Float) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto lit = std::make_unique<ast::FloatLiteral>(&f32, -1.2e-5); auto lit = create<ast::FloatLiteral>(&f32, -1.2e-5);
ast::ExpressionList values; ast::ExpressionList values;
values.push_back( values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
ast::TypeConstructorExpression expr(&f32, std::move(values)); ast::TypeConstructorExpression expr(&f32, std::move(values));
@ -90,10 +88,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Float) {
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Bool) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Bool) {
ast::type::BoolType b; ast::type::BoolType b;
auto lit = std::make_unique<ast::BoolLiteral>(&b, true); auto lit = create<ast::BoolLiteral>(&b, true);
ast::ExpressionList values; ast::ExpressionList values;
values.push_back( values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
ast::TypeConstructorExpression expr(&b, std::move(values)); ast::TypeConstructorExpression expr(&b, std::move(values));
@ -104,10 +101,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Bool) {
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Int) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Int) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto lit = std::make_unique<ast::SintLiteral>(&i32, -12345); auto lit = create<ast::SintLiteral>(&i32, -12345);
ast::ExpressionList values; ast::ExpressionList values;
values.push_back( values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
ast::TypeConstructorExpression expr(&i32, std::move(values)); ast::TypeConstructorExpression expr(&i32, std::move(values));
@ -118,10 +114,9 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Int) {
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Uint) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Uint) {
ast::type::U32Type u32; ast::type::U32Type u32;
auto lit = std::make_unique<ast::UintLiteral>(&u32, 12345); auto lit = create<ast::UintLiteral>(&u32, 12345);
ast::ExpressionList values; ast::ExpressionList values;
values.push_back( values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit)));
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit)));
ast::TypeConstructorExpression expr(&u32, std::move(values)); ast::TypeConstructorExpression expr(&u32, std::move(values));
@ -133,16 +128,13 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 3); ast::type::VectorType vec(&f32, 3);
auto lit1 = std::make_unique<ast::FloatLiteral>(&f32, 1.f); auto lit1 = create<ast::FloatLiteral>(&f32, 1.f);
auto lit2 = std::make_unique<ast::FloatLiteral>(&f32, 2.f); auto lit2 = create<ast::FloatLiteral>(&f32, 2.f);
auto lit3 = std::make_unique<ast::FloatLiteral>(&f32, 3.f); auto lit3 = create<ast::FloatLiteral>(&f32, 3.f);
ast::ExpressionList values; ast::ExpressionList values;
values.push_back( values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit1))); values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back( values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit3)));
ast::TypeConstructorExpression expr(&vec, std::move(values)); ast::TypeConstructorExpression expr(&vec, std::move(values));
@ -173,23 +165,20 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) {
ast::ExpressionList mat_values; ast::ExpressionList mat_values;
for (size_t i = 0; i < 2; i++) { for (size_t i = 0; i < 2; i++) {
auto lit1 = std::make_unique<ast::FloatLiteral>( auto lit1 =
&f32, static_cast<float>(1 + (i * 2))); create<ast::FloatLiteral>(&f32, static_cast<float>(1 + (i * 2)));
auto lit2 = std::make_unique<ast::FloatLiteral>( auto lit2 =
&f32, static_cast<float>(2 + (i * 2))); create<ast::FloatLiteral>(&f32, static_cast<float>(2 + (i * 2)));
auto lit3 = std::make_unique<ast::FloatLiteral>( auto lit3 =
&f32, static_cast<float>(3 + (i * 2))); create<ast::FloatLiteral>(&f32, static_cast<float>(3 + (i * 2)));
ast::ExpressionList values; ast::ExpressionList values;
values.push_back( values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit1))); values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back( values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit3)));
mat_values.push_back(std::make_unique<ast::TypeConstructorExpression>( mat_values.push_back(
&vec, std::move(values))); create<ast::TypeConstructorExpression>(&vec, std::move(values)));
} }
ast::TypeConstructorExpression expr(&mat, std::move(mat_values)); ast::TypeConstructorExpression expr(&mat, std::move(mat_values));
@ -212,23 +201,20 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Array) {
ast::ExpressionList ary_values; ast::ExpressionList ary_values;
for (size_t i = 0; i < 3; i++) { for (size_t i = 0; i < 3; i++) {
auto lit1 = std::make_unique<ast::FloatLiteral>( auto lit1 =
&f32, static_cast<float>(1 + (i * 3))); create<ast::FloatLiteral>(&f32, static_cast<float>(1 + (i * 3)));
auto lit2 = std::make_unique<ast::FloatLiteral>( auto lit2 =
&f32, static_cast<float>(2 + (i * 3))); create<ast::FloatLiteral>(&f32, static_cast<float>(2 + (i * 3)));
auto lit3 = std::make_unique<ast::FloatLiteral>( auto lit3 =
&f32, static_cast<float>(3 + (i * 3))); create<ast::FloatLiteral>(&f32, static_cast<float>(3 + (i * 3)));
ast::ExpressionList values; ast::ExpressionList values;
values.push_back( values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit1)));
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit1))); values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back( values.push_back(create<ast::ScalarConstructorExpression>(std::move(lit3)));
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit2)));
values.push_back(
std::make_unique<ast::ScalarConstructorExpression>(std::move(lit3)));
ary_values.push_back(std::make_unique<ast::TypeConstructorExpression>( ary_values.push_back(
&vec, std::move(values))); create<ast::TypeConstructorExpression>(&vec, std::move(values)));
} }
ast::TypeConstructorExpression expr(&ary, std::move(ary_values)); ast::TypeConstructorExpression expr(&ary, std::move(ary_values));

View File

@ -53,16 +53,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::I32Type i32; ast::type::I32Type i32;
auto foo_var = std::make_unique<ast::DecoratedVariable>( auto foo_var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("foo", ast::StorageClass::kInput, &f32)); create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{})); decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos)); foo_var->set_decorations(std::move(decos));
auto bar_var = std::make_unique<ast::DecoratedVariable>( auto bar_var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("bar", ast::StorageClass::kInput, &i32)); create<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{})); decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos)); bar_var->set_decorations(std::move(decos));
td.RegisterVariableForTesting(foo_var.get()); td.RegisterVariableForTesting(foo_var.get());
@ -72,19 +72,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(std::move(bar_var)); mod.AddGlobalVariable(std::move(bar_var));
ast::VariableList params; ast::VariableList params;
auto func = auto func = create<ast::Function>("vtx_main", std::move(params), &f32);
std::make_unique<ast::Function>("vtx_main", std::move(params), &f32); func->add_decoration(
func->add_decoration(std::make_unique<ast::StageDecoration>( create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
ast::PipelineStage::kVertex, Source{}));
auto* func_ptr = func.get(); auto* func_ptr = func.get();
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>("foo"),
std::make_unique<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>("foo")));
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>("bar"),
std::make_unique<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>("bar")));
func->set_body(std::move(body)); func->set_body(std::move(body));
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));
@ -114,16 +113,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::I32Type i32; ast::type::I32Type i32;
auto foo_var = std::make_unique<ast::DecoratedVariable>( auto foo_var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("foo", ast::StorageClass::kOutput, &f32)); create<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{})); decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos)); foo_var->set_decorations(std::move(decos));
auto bar_var = std::make_unique<ast::DecoratedVariable>( auto bar_var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("bar", ast::StorageClass::kOutput, &i32)); create<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{})); decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos)); bar_var->set_decorations(std::move(decos));
td.RegisterVariableForTesting(foo_var.get()); td.RegisterVariableForTesting(foo_var.get());
@ -133,19 +132,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(std::move(bar_var)); mod.AddGlobalVariable(std::move(bar_var));
ast::VariableList params; ast::VariableList params;
auto func = auto func = create<ast::Function>("vtx_main", std::move(params), &f32);
std::make_unique<ast::Function>("vtx_main", std::move(params), &f32); func->add_decoration(
func->add_decoration(std::make_unique<ast::StageDecoration>( create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
ast::PipelineStage::kVertex, Source{}));
auto* func_ptr = func.get(); auto* func_ptr = func.get();
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>("foo"),
std::make_unique<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>("foo")));
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>("bar"),
std::make_unique<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>("bar")));
func->set_body(std::move(body)); func->set_body(std::move(body));
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));
@ -175,16 +173,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::I32Type i32; ast::type::I32Type i32;
auto foo_var = std::make_unique<ast::DecoratedVariable>( auto foo_var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("foo", ast::StorageClass::kInput, &f32)); create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{})); decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos)); foo_var->set_decorations(std::move(decos));
auto bar_var = std::make_unique<ast::DecoratedVariable>( auto bar_var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("bar", ast::StorageClass::kInput, &i32)); create<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{})); decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos)); bar_var->set_decorations(std::move(decos));
td.RegisterVariableForTesting(foo_var.get()); td.RegisterVariableForTesting(foo_var.get());
@ -194,18 +192,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(std::move(bar_var)); mod.AddGlobalVariable(std::move(bar_var));
ast::VariableList params; ast::VariableList params;
auto func = std::make_unique<ast::Function>("main", std::move(params), &f32); auto func = create<ast::Function>("main", std::move(params), &f32);
func->add_decoration(std::make_unique<ast::StageDecoration>( func->add_decoration(
ast::PipelineStage::kVertex, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
auto* func_ptr = func.get(); auto* func_ptr = func.get();
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>("foo"),
std::make_unique<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>("foo")));
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>("bar"),
std::make_unique<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>("bar")));
func->set_body(std::move(body)); func->set_body(std::move(body));
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));
@ -235,16 +233,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::I32Type i32; ast::type::I32Type i32;
auto foo_var = std::make_unique<ast::DecoratedVariable>( auto foo_var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("foo", ast::StorageClass::kOutput, &f32)); create<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{})); decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos)); foo_var->set_decorations(std::move(decos));
auto bar_var = std::make_unique<ast::DecoratedVariable>( auto bar_var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("bar", ast::StorageClass::kOutput, &i32)); create<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{})); decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos)); bar_var->set_decorations(std::move(decos));
td.RegisterVariableForTesting(foo_var.get()); td.RegisterVariableForTesting(foo_var.get());
@ -254,18 +252,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(std::move(bar_var)); mod.AddGlobalVariable(std::move(bar_var));
ast::VariableList params; ast::VariableList params;
auto func = std::make_unique<ast::Function>("main", std::move(params), &f32); auto func = create<ast::Function>("main", std::move(params), &f32);
func->add_decoration(std::make_unique<ast::StageDecoration>( func->add_decoration(
ast::PipelineStage::kFragment, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
auto* func_ptr = func.get(); auto* func_ptr = func.get();
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>("foo"),
std::make_unique<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>("foo")));
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>("bar"),
std::make_unique<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>("bar")));
func->set_body(std::move(body)); func->set_body(std::move(body));
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));
@ -292,16 +290,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::I32Type i32; ast::type::I32Type i32;
auto foo_var = std::make_unique<ast::DecoratedVariable>( auto foo_var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("foo", ast::StorageClass::kInput, &f32)); create<ast::Variable>("foo", ast::StorageClass::kInput, &f32));
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{})); decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos)); foo_var->set_decorations(std::move(decos));
auto bar_var = std::make_unique<ast::DecoratedVariable>( auto bar_var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("bar", ast::StorageClass::kInput, &i32)); create<ast::Variable>("bar", ast::StorageClass::kInput, &i32));
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{})); decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos)); bar_var->set_decorations(std::move(decos));
td.RegisterVariableForTesting(foo_var.get()); td.RegisterVariableForTesting(foo_var.get());
@ -311,18 +309,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(std::move(bar_var)); mod.AddGlobalVariable(std::move(bar_var));
ast::VariableList params; ast::VariableList params;
auto func = std::make_unique<ast::Function>("main", std::move(params), &f32); auto func = create<ast::Function>("main", std::move(params), &f32);
func->add_decoration(std::make_unique<ast::StageDecoration>( func->add_decoration(
ast::PipelineStage::kCompute, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
auto* func_ptr = func.get(); auto* func_ptr = func.get();
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>("foo"),
std::make_unique<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>("foo")));
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>("bar"),
std::make_unique<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>("bar")));
func->set_body(std::move(body)); func->set_body(std::move(body));
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));
@ -344,16 +342,16 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::I32Type i32; ast::type::I32Type i32;
auto foo_var = std::make_unique<ast::DecoratedVariable>( auto foo_var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("foo", ast::StorageClass::kOutput, &f32)); create<ast::Variable>("foo", ast::StorageClass::kOutput, &f32));
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::LocationDecoration>(0, Source{})); decos.push_back(create<ast::LocationDecoration>(0, Source{}));
foo_var->set_decorations(std::move(decos)); foo_var->set_decorations(std::move(decos));
auto bar_var = std::make_unique<ast::DecoratedVariable>( auto bar_var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("bar", ast::StorageClass::kOutput, &i32)); create<ast::Variable>("bar", ast::StorageClass::kOutput, &i32));
decos.push_back(std::make_unique<ast::LocationDecoration>(1, Source{})); decos.push_back(create<ast::LocationDecoration>(1, Source{}));
bar_var->set_decorations(std::move(decos)); bar_var->set_decorations(std::move(decos));
td.RegisterVariableForTesting(foo_var.get()); td.RegisterVariableForTesting(foo_var.get());
@ -363,18 +361,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(std::move(bar_var)); mod.AddGlobalVariable(std::move(bar_var));
ast::VariableList params; ast::VariableList params;
auto func = std::make_unique<ast::Function>("main", std::move(params), &f32); auto func = create<ast::Function>("main", std::move(params), &f32);
func->add_decoration(std::make_unique<ast::StageDecoration>( func->add_decoration(
ast::PipelineStage::kCompute, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
auto* func_ptr = func.get(); auto* func_ptr = func.get();
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("foo"), create<ast::IdentifierExpression>("foo"),
std::make_unique<ast::IdentifierExpression>("foo"))); create<ast::IdentifierExpression>("foo")));
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("bar"), create<ast::IdentifierExpression>("bar"),
std::make_unique<ast::IdentifierExpression>("bar"))); create<ast::IdentifierExpression>("bar")));
func->set_body(std::move(body)); func->set_body(std::move(body));
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));
@ -403,20 +401,18 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
ast::type::VoidType void_type; ast::type::VoidType void_type;
ast::type::VectorType vec4(&f32, 4); ast::type::VectorType vec4(&f32, 4);
auto coord_var = auto coord_var = create<ast::DecoratedVariable>(
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( create<ast::Variable>("coord", ast::StorageClass::kInput, &vec4));
"coord", ast::StorageClass::kInput, &vec4));
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::BuiltinDecoration>( decos.push_back(
ast::Builtin::kFragCoord, Source{})); create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord, Source{}));
coord_var->set_decorations(std::move(decos)); coord_var->set_decorations(std::move(decos));
auto depth_var = auto depth_var = create<ast::DecoratedVariable>(
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( create<ast::Variable>("depth", ast::StorageClass::kOutput, &f32));
"depth", ast::StorageClass::kOutput, &f32)); decos.push_back(
decos.push_back(std::make_unique<ast::BuiltinDecoration>( create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth, Source{}));
ast::Builtin::kFragDepth, Source{}));
depth_var->set_decorations(std::move(decos)); depth_var->set_decorations(std::move(decos));
td.RegisterVariableForTesting(coord_var.get()); td.RegisterVariableForTesting(coord_var.get());
@ -426,18 +422,17 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
mod.AddGlobalVariable(std::move(depth_var)); mod.AddGlobalVariable(std::move(depth_var));
ast::VariableList params; ast::VariableList params;
auto func = auto func = create<ast::Function>("main", std::move(params), &void_type);
std::make_unique<ast::Function>("main", std::move(params), &void_type); func->add_decoration(
func->add_decoration(std::make_unique<ast::StageDecoration>( create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
ast::PipelineStage::kFragment, Source{}));
auto* func_ptr = func.get(); auto* func_ptr = func.get();
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("depth"), create<ast::IdentifierExpression>("depth"),
std::make_unique<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("coord"), create<ast::IdentifierExpression>("coord"),
std::make_unique<ast::IdentifierExpression>("x")))); create<ast::IdentifierExpression>("x"))));
func->set_body(std::move(body)); func->set_body(std::move(body));
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));

File diff suppressed because it is too large Load Diff

View File

@ -27,9 +27,9 @@ namespace {
using HlslGeneratorImplTest_If = TestHelper; using HlslGeneratorImplTest_If = TestHelper;
TEST_F(HlslGeneratorImplTest_If, Emit_If) { TEST_F(HlslGeneratorImplTest_If, Emit_If) {
auto cond = std::make_unique<ast::IdentifierExpression>("cond"); auto cond = create<ast::IdentifierExpression>("cond");
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
ast::IfStatement i(std::move(cond), std::move(body)); ast::IfStatement i(std::move(cond), std::move(body));
gen.increment_indent(); gen.increment_indent();
@ -42,17 +42,17 @@ TEST_F(HlslGeneratorImplTest_If, Emit_If) {
} }
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
auto else_cond = std::make_unique<ast::IdentifierExpression>("else_cond"); auto else_cond = create<ast::IdentifierExpression>("else_cond");
auto else_body = std::make_unique<ast::BlockStatement>(); auto else_body = create<ast::BlockStatement>();
else_body->append(std::make_unique<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses; ast::ElseStatementList elses;
elses.push_back(std::make_unique<ast::ElseStatement>(std::move(else_cond), elses.push_back(
std::move(else_body))); create<ast::ElseStatement>(std::move(else_cond), std::move(else_body)));
auto cond = std::make_unique<ast::IdentifierExpression>("cond"); auto cond = create<ast::IdentifierExpression>("cond");
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
ast::IfStatement i(std::move(cond), std::move(body)); ast::IfStatement i(std::move(cond), std::move(body));
i.set_else_statements(std::move(elses)); i.set_else_statements(std::move(elses));
@ -71,15 +71,15 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
} }
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
auto else_body = std::make_unique<ast::BlockStatement>(); auto else_body = create<ast::BlockStatement>();
else_body->append(std::make_unique<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses; ast::ElseStatementList elses;
elses.push_back(std::make_unique<ast::ElseStatement>(std::move(else_body))); elses.push_back(create<ast::ElseStatement>(std::move(else_body)));
auto cond = std::make_unique<ast::IdentifierExpression>("cond"); auto cond = create<ast::IdentifierExpression>("cond");
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
ast::IfStatement i(std::move(cond), std::move(body)); ast::IfStatement i(std::move(cond), std::move(body));
i.set_else_statements(std::move(elses)); i.set_else_statements(std::move(elses));
@ -96,22 +96,22 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
} }
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
auto else_cond = std::make_unique<ast::IdentifierExpression>("else_cond"); auto else_cond = create<ast::IdentifierExpression>("else_cond");
auto else_body = std::make_unique<ast::BlockStatement>(); auto else_body = create<ast::BlockStatement>();
else_body->append(std::make_unique<ast::ReturnStatement>()); else_body->append(create<ast::ReturnStatement>());
auto else_body_2 = std::make_unique<ast::BlockStatement>(); auto else_body_2 = create<ast::BlockStatement>();
else_body_2->append(std::make_unique<ast::ReturnStatement>()); else_body_2->append(create<ast::ReturnStatement>());
ast::ElseStatementList elses; ast::ElseStatementList elses;
elses.push_back(std::make_unique<ast::ElseStatement>(std::move(else_cond), elses.push_back(
std::move(else_body))); create<ast::ElseStatement>(std::move(else_cond), std::move(else_body)));
elses.push_back(std::make_unique<ast::ElseStatement>(std::move(else_body_2))); elses.push_back(create<ast::ElseStatement>(std::move(else_body_2)));
auto cond = std::make_unique<ast::IdentifierExpression>("cond"); auto cond = create<ast::IdentifierExpression>("cond");
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
ast::IfStatement i(std::move(cond), std::move(body)); ast::IfStatement i(std::move(cond), std::move(body));
i.set_else_statements(std::move(elses)); i.set_else_statements(std::move(elses));

View File

@ -54,10 +54,10 @@ TEST_P(HlslImportData_SingleParamTest, FloatScalar) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto ident = std::make_unique<ast::IdentifierExpression>(param.name); auto ident = create<ast::IdentifierExpression>(param.name);
ast::CallExpression expr(std::move(ident), std::move(params)); ast::CallExpression expr(std::move(ident), std::move(params));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -99,12 +99,11 @@ TEST_P(HlslImportData_SingleIntParamTest, IntScalar) {
ast::type::I32Type i32; ast::type::I32Type i32;
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
ast::CallExpression expr( ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::make_unique<ast::IdentifierExpression>(param.name), std::move(params));
std::move(params));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -121,14 +120,13 @@ TEST_P(HlslImportData_DualParamTest, FloatScalar) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
params.push_back(std::make_unique<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.f))); create<ast::FloatLiteral>(&f32, 2.f)));
ast::CallExpression expr( ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::make_unique<ast::IdentifierExpression>(param.name), std::move(params));
std::move(params));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -153,29 +151,28 @@ TEST_P(HlslImportData_DualParam_VectorTest, FloatVector) {
ast::type::VectorType vec(&f32, 3); ast::type::VectorType vec(&f32, 3);
ast::ExpressionList type_params; ast::ExpressionList type_params;
type_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( type_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
type_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( type_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.f))); create<ast::FloatLiteral>(&f32, 2.f)));
type_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( type_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.f))); create<ast::FloatLiteral>(&f32, 3.f)));
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::TypeConstructorExpression>( params.push_back(
&vec, std::move(type_params))); create<ast::TypeConstructorExpression>(&vec, std::move(type_params)));
type_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( type_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 4.f))); create<ast::FloatLiteral>(&f32, 4.f)));
type_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( type_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 5.f))); create<ast::FloatLiteral>(&f32, 5.f)));
type_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( type_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 6.f))); create<ast::FloatLiteral>(&f32, 6.f)));
params.push_back(std::make_unique<ast::TypeConstructorExpression>( params.push_back(
&vec, std::move(type_params))); create<ast::TypeConstructorExpression>(&vec, std::move(type_params)));
ast::CallExpression expr( ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::make_unique<ast::IdentifierExpression>(param.name), std::move(params));
std::move(params));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -195,14 +192,13 @@ TEST_P(HlslImportData_DualParam_Int_Test, IntScalar) {
ast::type::I32Type i32; ast::type::I32Type i32;
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
params.push_back(std::make_unique<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2))); create<ast::SintLiteral>(&i32, 2)));
ast::CallExpression expr( ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::make_unique<ast::IdentifierExpression>(param.name), std::move(params));
std::move(params));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -220,16 +216,15 @@ TEST_P(HlslImportData_TripleParamTest, FloatScalar) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
params.push_back(std::make_unique<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.f))); create<ast::FloatLiteral>(&f32, 2.f)));
params.push_back(std::make_unique<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.f))); create<ast::FloatLiteral>(&f32, 3.f)));
ast::CallExpression expr( ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::make_unique<ast::IdentifierExpression>(param.name), std::move(params));
std::move(params));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -255,16 +250,15 @@ TEST_P(HlslImportData_TripleParam_Int_Test, IntScalar) {
ast::type::I32Type i32; ast::type::I32Type i32;
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
params.push_back(std::make_unique<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2))); create<ast::SintLiteral>(&i32, 2)));
params.push_back(std::make_unique<ast::ScalarConstructorExpression>( params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3))); create<ast::SintLiteral>(&i32, 3)));
ast::CallExpression expr( ast::CallExpression expr(create<ast::IdentifierExpression>(param.name),
std::make_unique<ast::IdentifierExpression>(param.name), std::move(params));
std::move(params));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
@ -278,15 +272,13 @@ TEST_F(HlslGeneratorImplTest_Import, HlslImportData_Determinant) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::MatrixType mat(&f32, 3, 3); ast::type::MatrixType mat(&f32, 3, 3);
auto var = std::make_unique<ast::Variable>( auto var = create<ast::Variable>("var", ast::StorageClass::kFunction, &mat);
"var", ast::StorageClass::kFunction, &mat);
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::IdentifierExpression>("var")); params.push_back(create<ast::IdentifierExpression>("var"));
ast::CallExpression expr( ast::CallExpression expr(create<ast::IdentifierExpression>("determinant"),
std::make_unique<ast::IdentifierExpression>("determinant"), std::move(params));
std::move(params));
mod.AddGlobalVariable(std::move(var)); mod.AddGlobalVariable(std::move(var));

View File

@ -76,18 +76,15 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, DISABLED_Intrinsic_OuterProduct) {
ast::type::VectorType vec2(&f32, 2); ast::type::VectorType vec2(&f32, 2);
ast::type::VectorType vec3(&f32, 3); ast::type::VectorType vec3(&f32, 3);
auto a = auto a = create<ast::Variable>("a", ast::StorageClass::kNone, &vec2);
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &vec2); auto b = create<ast::Variable>("b", ast::StorageClass::kNone, &vec3);
auto b =
std::make_unique<ast::Variable>("b", ast::StorageClass::kNone, &vec3);
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::IdentifierExpression>("a")); params.push_back(create<ast::IdentifierExpression>("a"));
params.push_back(std::make_unique<ast::IdentifierExpression>("b")); params.push_back(create<ast::IdentifierExpression>("b"));
ast::CallExpression call( ast::CallExpression call(create<ast::IdentifierExpression>("outer_product"),
std::make_unique<ast::IdentifierExpression>("outer_product"), std::move(params));
std::move(params));
td.RegisterVariableForTesting(a.get()); td.RegisterVariableForTesting(a.get());
td.RegisterVariableForTesting(b.get()); td.RegisterVariableForTesting(b.get());
@ -112,10 +109,10 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
ast::type::VectorType vec(&f32, 3); ast::type::VectorType vec(&f32, 3);
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(std::make_unique<ast::IdentifierExpression>("param1")); params.push_back(create<ast::IdentifierExpression>("param1"));
params.push_back(std::make_unique<ast::IdentifierExpression>("param2")); params.push_back(create<ast::IdentifierExpression>("param2"));
ast::CallExpression call(std::make_unique<ast::IdentifierExpression>("dot"), ast::CallExpression call(create<ast::IdentifierExpression>("dot"),
std::move(params)); std::move(params));
ast::Variable v1("param1", ast::StorageClass::kFunction, &vec); ast::Variable v1("param1", ast::StorageClass::kFunction, &vec);

View File

@ -34,8 +34,8 @@ namespace {
using HlslGeneratorImplTest_Loop = TestHelper; using HlslGeneratorImplTest_Loop = TestHelper;
TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) { TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
ast::LoopStatement l(std::move(body), {}); ast::LoopStatement l(std::move(body), {});
gen.increment_indent(); gen.increment_indent();
@ -48,11 +48,11 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
} }
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) { TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
auto continuing = std::make_unique<ast::BlockStatement>(); auto continuing = create<ast::BlockStatement>();
continuing->append(std::make_unique<ast::ReturnStatement>()); continuing->append(create<ast::ReturnStatement>());
ast::LoopStatement l(std::move(body), std::move(continuing)); ast::LoopStatement l(std::move(body), std::move(continuing));
gen.increment_indent(); gen.increment_indent();
@ -75,24 +75,24 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) { TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::DiscardStatement>()); body->append(create<ast::DiscardStatement>());
auto continuing = std::make_unique<ast::BlockStatement>(); auto continuing = create<ast::BlockStatement>();
continuing->append(std::make_unique<ast::ReturnStatement>()); continuing->append(create<ast::ReturnStatement>());
auto inner = std::make_unique<ast::LoopStatement>(std::move(body), auto inner =
std::move(continuing)); create<ast::LoopStatement>(std::move(body), std::move(continuing));
body = std::make_unique<ast::BlockStatement>(); body = create<ast::BlockStatement>();
body->append(std::move(inner)); body->append(std::move(inner));
auto lhs = std::make_unique<ast::IdentifierExpression>("lhs"); auto lhs = create<ast::IdentifierExpression>("lhs");
auto rhs = std::make_unique<ast::IdentifierExpression>("rhs"); auto rhs = create<ast::IdentifierExpression>("rhs");
continuing = std::make_unique<ast::BlockStatement>(); continuing = create<ast::BlockStatement>();
continuing->append(std::make_unique<ast::AssignmentStatement>( continuing->append(
std::move(lhs), std::move(rhs))); create<ast::AssignmentStatement>(std::move(lhs), std::move(rhs)));
ast::LoopStatement outer(std::move(body), std::move(continuing)); ast::LoopStatement outer(std::move(body), std::move(continuing));
gen.increment_indent(); gen.increment_indent();
@ -146,23 +146,21 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto var = std::make_unique<ast::Variable>( auto var = create<ast::Variable>("lhs", ast::StorageClass::kFunction, &f32);
"lhs", ast::StorageClass::kFunction, &f32); var->set_constructor(create<ast::ScalarConstructorExpression>(
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>( create<ast::FloatLiteral>(&f32, 2.4)));
std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::VariableDeclStatement>(std::move(var))); body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(std::make_unique<ast::VariableDeclStatement>( body->append(create<ast::VariableDeclStatement>(
std::make_unique<ast::Variable>("other", ast::StorageClass::kFunction, create<ast::Variable>("other", ast::StorageClass::kFunction, &f32)));
&f32)));
auto lhs = std::make_unique<ast::IdentifierExpression>("lhs"); auto lhs = create<ast::IdentifierExpression>("lhs");
auto rhs = std::make_unique<ast::IdentifierExpression>("rhs"); auto rhs = create<ast::IdentifierExpression>("rhs");
auto continuing = std::make_unique<ast::BlockStatement>(); auto continuing = create<ast::BlockStatement>();
continuing->append(std::make_unique<ast::AssignmentStatement>( continuing->append(
std::move(lhs), std::move(rhs))); create<ast::AssignmentStatement>(std::move(lhs), std::move(rhs)));
ast::LoopStatement outer(std::move(body), std::move(continuing)); ast::LoopStatement outer(std::move(body), std::move(continuing));
gen.increment_indent(); gen.increment_indent();

File diff suppressed because it is too large Load Diff

View File

@ -38,18 +38,17 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
ast::type::ArrayType ary(&f32, 3); ast::type::ArrayType ary(&f32, 3);
ast::ExpressionList exprs; ast::ExpressionList exprs;
exprs.push_back(std::make_unique<ast::ScalarConstructorExpression>( exprs.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
exprs.push_back(std::make_unique<ast::ScalarConstructorExpression>( exprs.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.0f))); create<ast::FloatLiteral>(&f32, 2.0f)));
exprs.push_back(std::make_unique<ast::ScalarConstructorExpression>( exprs.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto var = auto var = create<ast::Variable>("pos", ast::StorageClass::kNone, &ary);
std::make_unique<ast::Variable>("pos", ast::StorageClass::kNone, &ary);
var->set_is_const(true); var->set_is_const(true);
var->set_constructor( var->set_constructor(
std::make_unique<ast::TypeConstructorExpression>(&ary, std::move(exprs))); create<ast::TypeConstructorExpression>(&ary, std::move(exprs)));
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var.get())) << gen.error(); ASSERT_TRUE(gen.EmitProgramConstVariable(out, var.get())) << gen.error();
EXPECT_EQ( EXPECT_EQ(
@ -61,14 +60,14 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(23, Source{})); decos.push_back(create<ast::ConstantIdDecoration>(23, Source{}));
auto var = std::make_unique<ast::DecoratedVariable>( auto var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("pos", ast::StorageClass::kNone, &f32)); create<ast::Variable>("pos", ast::StorageClass::kNone, &f32));
var->set_decorations(std::move(decos)); var->set_decorations(std::move(decos));
var->set_is_const(true); var->set_is_const(true);
var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>( var->set_constructor(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var.get())) << gen.error(); ASSERT_TRUE(gen.EmitProgramConstVariable(out, var.get())) << gen.error();
EXPECT_EQ(result(), R"(#ifndef WGSL_SPEC_CONSTANT_23 EXPECT_EQ(result(), R"(#ifndef WGSL_SPEC_CONSTANT_23
@ -83,10 +82,10 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant_NoConstructor) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(23, Source{})); decos.push_back(create<ast::ConstantIdDecoration>(23, Source{}));
auto var = std::make_unique<ast::DecoratedVariable>( auto var = create<ast::DecoratedVariable>(
std::make_unique<ast::Variable>("pos", ast::StorageClass::kNone, &f32)); create<ast::Variable>("pos", ast::StorageClass::kNone, &f32));
var->set_decorations(std::move(decos)); var->set_decorations(std::move(decos));
var->set_is_const(true); var->set_is_const(true);

View File

@ -36,7 +36,7 @@ TEST_F(HlslGeneratorImplTest_Return, Emit_Return) {
} }
TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) { TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) {
auto expr = std::make_unique<ast::IdentifierExpression>("expr"); auto expr = create<ast::IdentifierExpression>("expr");
ast::ReturnStatement r(std::move(expr)); ast::ReturnStatement r(std::move(expr));
gen.increment_indent(); gen.increment_indent();

View File

@ -31,26 +31,26 @@ namespace {
using HlslGeneratorImplTest_Switch = TestHelper; using HlslGeneratorImplTest_Switch = TestHelper;
TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) { TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
auto def = std::make_unique<ast::CaseStatement>(); auto def = create<ast::CaseStatement>();
auto def_body = std::make_unique<ast::BlockStatement>(); auto def_body = create<ast::BlockStatement>();
def_body->append(std::make_unique<ast::BreakStatement>()); def_body->append(create<ast::BreakStatement>());
def->set_body(std::move(def_body)); def->set_body(std::move(def_body));
ast::type::I32Type i32; ast::type::I32Type i32;
ast::CaseSelectorList case_val; ast::CaseSelectorList case_val;
case_val.push_back(std::make_unique<ast::SintLiteral>(&i32, 5)); case_val.push_back(create<ast::SintLiteral>(&i32, 5));
auto case_body = std::make_unique<ast::BlockStatement>(); auto case_body = create<ast::BlockStatement>();
case_body->append(std::make_unique<ast::BreakStatement>()); case_body->append(create<ast::BreakStatement>());
auto case_stmt = std::make_unique<ast::CaseStatement>(std::move(case_val), auto case_stmt =
std::move(case_body)); create<ast::CaseStatement>(std::move(case_val), std::move(case_body));
ast::CaseStatementList body; ast::CaseStatementList body;
body.push_back(std::move(case_stmt)); body.push_back(std::move(case_stmt));
body.push_back(std::move(def)); body.push_back(std::move(def));
auto cond = std::make_unique<ast::IdentifierExpression>("cond"); auto cond = create<ast::IdentifierExpression>("cond");
ast::SwitchStatement s(std::move(cond), std::move(body)); ast::SwitchStatement s(std::move(cond), std::move(body));
gen.increment_indent(); gen.increment_indent();

View File

@ -29,8 +29,7 @@ using HlslGeneratorImplTest = TestHelper;
TEST_F(HlslGeneratorImplTest, Generate) { TEST_F(HlslGeneratorImplTest, Generate) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
auto func = std::make_unique<ast::Function>("my_func", ast::VariableList{}, auto func = create<ast::Function>("my_func", ast::VariableList{}, &void_type);
&void_type);
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));
ASSERT_TRUE(gen.Generate(out)) << gen.error(); ASSERT_TRUE(gen.Generate(out)) << gen.error();

View File

@ -174,16 +174,14 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(std::make_unique<ast::StructMember>( members.push_back(
"a", &i32, ast::StructMemberDecorationList{})); create<ast::StructMember>("a", &i32, ast::StructMemberDecorationList{}));
ast::StructMemberDecorationList b_deco; ast::StructMemberDecorationList b_deco;
b_deco.push_back( b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{})); members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(
std::make_unique<ast::StructMember>("b", &f32, std::move(b_deco)));
auto str = std::make_unique<ast::Struct>(); auto str = create<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s("S", std::move(str)); ast::type::StructType s("S", std::move(str));
@ -201,16 +199,14 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(std::make_unique<ast::StructMember>( members.push_back(
"a", &i32, ast::StructMemberDecorationList{})); create<ast::StructMember>("a", &i32, ast::StructMemberDecorationList{}));
ast::StructMemberDecorationList b_deco; ast::StructMemberDecorationList b_deco;
b_deco.push_back( b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{})); members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(
std::make_unique<ast::StructMember>("b", &f32, std::move(b_deco)));
auto str = std::make_unique<ast::Struct>(); auto str = create<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s("S", std::move(str)); ast::type::StructType s("S", std::move(str));
@ -224,24 +220,18 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_InjectPadding) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
decos.push_back( decos.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{}));
ast::StructMemberList members; ast::StructMemberList members;
members.push_back( members.push_back(create<ast::StructMember>("a", &i32, std::move(decos)));
std::make_unique<ast::StructMember>("a", &i32, std::move(decos)));
decos.push_back( decos.push_back(create<ast::StructMemberOffsetDecoration>(32, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(32, Source{})); members.push_back(create<ast::StructMember>("b", &f32, std::move(decos)));
members.push_back(
std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
decos.push_back( decos.push_back(create<ast::StructMemberOffsetDecoration>(128, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(128, Source{})); members.push_back(create<ast::StructMember>("c", &f32, std::move(decos)));
members.push_back(
std::make_unique<ast::StructMember>("c", &f32, std::move(decos)));
auto str = std::make_unique<ast::Struct>(); auto str = create<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s("S", std::move(str)); ast::type::StructType s("S", std::move(str));
@ -262,14 +252,14 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(std::make_unique<ast::StructMember>( members.push_back(create<ast::StructMember>(
"double", &i32, ast::StructMemberDecorationList{})); "double", &i32, ast::StructMemberDecorationList{}));
ast::StructMemberDecorationList b_deco; ast::StructMemberDecorationList b_deco;
members.push_back( members.push_back(
std::make_unique<ast::StructMember>("float", &f32, std::move(b_deco))); create<ast::StructMember>("float", &f32, std::move(b_deco)));
auto str = std::make_unique<ast::Struct>(); auto str = create<ast::Struct>();
str->set_members(std::move(members)); str->set_members(std::move(members));
ast::type::StructType s("S", std::move(str)); ast::type::StructType s("S", std::move(str));
@ -288,20 +278,17 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(std::make_unique<ast::StructMember>( members.push_back(
"a", &i32, ast::StructMemberDecorationList{})); create<ast::StructMember>("a", &i32, ast::StructMemberDecorationList{}));
ast::StructMemberDecorationList b_deco; ast::StructMemberDecorationList b_deco;
b_deco.push_back( b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(4, Source{})); members.push_back(create<ast::StructMember>("b", &f32, std::move(b_deco)));
members.push_back(
std::make_unique<ast::StructMember>("b", &f32, std::move(b_deco)));
ast::StructDecorationList decos; ast::StructDecorationList decos;
decos.push_back(std::make_unique<ast::StructBlockDecoration>(Source{})); decos.push_back(create<ast::StructBlockDecoration>(Source{}));
auto str = auto str = create<ast::Struct>(std::move(decos), std::move(members));
std::make_unique<ast::Struct>(std::move(decos), std::move(members));
ast::type::StructType s("S", std::move(str)); ast::type::StructType s("S", std::move(str));

View File

@ -37,7 +37,7 @@ using HlslUnaryOpTest = TestParamHelper<UnaryOpData>;
TEST_P(HlslUnaryOpTest, Emit) { TEST_P(HlslUnaryOpTest, Emit) {
auto params = GetParam(); auto params = GetParam();
auto expr = std::make_unique<ast::IdentifierExpression>("expr"); auto expr = create<ast::IdentifierExpression>("expr");
ast::UnaryOpExpression op(params.op, std::move(expr)); ast::UnaryOpExpression op(params.op, std::move(expr));
ASSERT_TRUE(gen.EmitExpression(pre, out, &op)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, &op)) << gen.error();

View File

@ -34,8 +34,7 @@ using HlslGeneratorImplTest_VariableDecl = TestHelper;
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) { TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto var = auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
ast::VariableDeclStatement stmt(std::move(var)); ast::VariableDeclStatement stmt(std::move(var));
gen.increment_indent(); gen.increment_indent();
@ -46,8 +45,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) { TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto var = auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
var->set_is_const(true); var->set_is_const(true);
ast::VariableDeclStatement stmt(std::move(var)); ast::VariableDeclStatement stmt(std::move(var));
@ -61,8 +59,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Array) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::ArrayType ary(&f32, 5); ast::type::ArrayType ary(&f32, 5);
auto var = auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &ary);
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &ary);
ast::VariableDeclStatement stmt(std::move(var)); ast::VariableDeclStatement stmt(std::move(var));
gen.increment_indent(); gen.increment_indent();
@ -74,8 +71,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Array) {
TEST_F(HlslGeneratorImplTest_VariableDecl, TEST_F(HlslGeneratorImplTest_VariableDecl,
Emit_VariableDeclStatement_Function) { Emit_VariableDeclStatement_Function) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto var = auto var = create<ast::Variable>("a", ast::StorageClass::kFunction, &f32);
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &f32);
ast::VariableDeclStatement stmt(std::move(var)); ast::VariableDeclStatement stmt(std::move(var));
gen.increment_indent(); gen.increment_indent();
@ -86,8 +82,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) { TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto var = auto var = create<ast::Variable>("a", ast::StorageClass::kPrivate, &f32);
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &f32);
ast::VariableDeclStatement stmt(std::move(var)); ast::VariableDeclStatement stmt(std::move(var));
gen.increment_indent(); gen.increment_indent();
@ -98,11 +93,10 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) {
TEST_F(HlslGeneratorImplTest_VariableDecl, TEST_F(HlslGeneratorImplTest_VariableDecl,
Emit_VariableDeclStatement_Initializer_Private) { Emit_VariableDeclStatement_Initializer_Private) {
auto ident = std::make_unique<ast::IdentifierExpression>("initializer"); auto ident = create<ast::IdentifierExpression>("initializer");
ast::type::F32Type f32; ast::type::F32Type f32;
auto var = auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &f32);
var->set_constructor(std::move(ident)); var->set_constructor(std::move(ident));
ast::VariableDeclStatement stmt(std::move(var)); ast::VariableDeclStatement stmt(std::move(var));
@ -118,10 +112,9 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
ast::ExpressionList values; ast::ExpressionList values;
auto zero_vec = auto zero_vec =
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(values)); create<ast::TypeConstructorExpression>(&vec, std::move(values));
auto var = auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &vec);
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &vec);
var->set_constructor(std::move(zero_vec)); var->set_constructor(std::move(zero_vec));
ast::VariableDeclStatement stmt(std::move(var)); ast::VariableDeclStatement stmt(std::move(var));
@ -137,10 +130,9 @@ TEST_F(HlslGeneratorImplTest_VariableDecl,
ast::ExpressionList values; ast::ExpressionList values;
auto zero_mat = auto zero_mat =
std::make_unique<ast::TypeConstructorExpression>(&mat, std::move(values)); create<ast::TypeConstructorExpression>(&mat, std::move(values));
auto var = auto var = create<ast::Variable>("a", ast::StorageClass::kNone, &mat);
std::make_unique<ast::Variable>("a", ast::StorageClass::kNone, &mat);
var->set_constructor(std::move(zero_mat)); var->set_constructor(std::move(zero_mat));
ast::VariableDeclStatement stmt(std::move(var)); ast::VariableDeclStatement stmt(std::move(var));

View File

@ -15,8 +15,10 @@
#ifndef SRC_WRITER_HLSL_TEST_HELPER_H_ #ifndef SRC_WRITER_HLSL_TEST_HELPER_H_
#define SRC_WRITER_HLSL_TEST_HELPER_H_ #define SRC_WRITER_HLSL_TEST_HELPER_H_
#include <memory>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <utility>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/module.h" #include "src/ast/module.h"
@ -29,8 +31,8 @@ namespace writer {
namespace hlsl { namespace hlsl {
/// Helper class for testing /// Helper class for testing
template <typename T> template <typename BODY>
class TestHelperBase : public T { class TestHelperBase : public BODY {
public: public:
TestHelperBase() : td(&ctx, &mod), gen(&ctx, &mod) {} TestHelperBase() : td(&ctx, &mod), gen(&ctx, &mod) {}
~TestHelperBase() = default; ~TestHelperBase() = default;
@ -41,6 +43,13 @@ class TestHelperBase : public T {
/// @returns the pre result string /// @returns the pre result string
std::string pre_result() const { return pre.str(); } std::string pre_result() const { return pre.str(); }
/// @return a `std::unique_ptr` to a new `T` constructed with `args`
/// @param args the arguments to forward to the constructor for `T`
template <typename T, typename... ARGS>
std::unique_ptr<T> create(ARGS&&... args) {
return std::make_unique<T>(std::forward<ARGS>(args)...);
}
/// The context /// The context
Context ctx; Context ctx;
/// The module /// The module