writer/spirv 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: I5321553847b6a7d47ac211ba093d219c7f3bb9bd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32673
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-14 01:09:04 +00:00 committed by Commit Bot service account
parent 4c88cd93ec
commit 16b1b9438d
20 changed files with 1499 additions and 1621 deletions

View File

@ -56,9 +56,9 @@ TEST_F(BuilderTest, ArrayAccessor) {
ast::Variable var("ary", ast::StorageClass::kFunction, &vec3); ast::Variable var("ary", ast::StorageClass::kFunction, &vec3);
auto ary = std::make_unique<ast::IdentifierExpression>("ary"); auto ary = create<ast::IdentifierExpression>("ary");
auto idx_expr = std::make_unique<ast::ScalarConstructorExpression>( auto idx_expr = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1)); create<ast::SintLiteral>(&i32, 1));
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx_expr)); ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx_expr));
@ -98,8 +98,8 @@ TEST_F(BuilderTest, Accessor_Array_LoadIndex) {
ast::Variable var("ary", ast::StorageClass::kFunction, &vec3); ast::Variable var("ary", ast::StorageClass::kFunction, &vec3);
ast::Variable idx("idx", ast::StorageClass::kFunction, &i32); ast::Variable idx("idx", ast::StorageClass::kFunction, &i32);
auto ary = std::make_unique<ast::IdentifierExpression>("ary"); auto ary = create<ast::IdentifierExpression>("ary");
auto idx_expr = std::make_unique<ast::IdentifierExpression>("idx"); auto idx_expr = create<ast::IdentifierExpression>("idx");
ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx_expr)); ast::ArrayAccessorExpression expr(std::move(ary), std::move(idx_expr));
@ -142,15 +142,15 @@ TEST_F(BuilderTest, ArrayAccessor_Dynamic) {
ast::Variable var("ary", ast::StorageClass::kFunction, &vec3); ast::Variable var("ary", ast::StorageClass::kFunction, &vec3);
auto ary = std::make_unique<ast::IdentifierExpression>("ary"); auto ary = create<ast::IdentifierExpression>("ary");
ast::ArrayAccessorExpression expr( ast::ArrayAccessorExpression expr(
std::move(ary), std::make_unique<ast::BinaryExpression>( std::move(ary),
ast::BinaryOp::kAdd, create<ast::BinaryExpression>(ast::BinaryOp::kAdd,
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1)), create<ast::SintLiteral>(&i32, 1)),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -190,12 +190,12 @@ TEST_F(BuilderTest, ArrayAccessor_MultiLevel) {
ast::Variable var("ary", ast::StorageClass::kFunction, &ary4); ast::Variable var("ary", ast::StorageClass::kFunction, &ary4);
ast::ArrayAccessorExpression expr( ast::ArrayAccessorExpression expr(
std::make_unique<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("ary"), create<ast::IdentifierExpression>("ary"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3))), create<ast::SintLiteral>(&i32, 3))),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2))); create<ast::SintLiteral>(&i32, 2)));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -237,11 +237,11 @@ TEST_F(BuilderTest, Accessor_ArrayWithSwizzle) {
ast::Variable var("ary", ast::StorageClass::kFunction, &ary4); ast::Variable var("ary", ast::StorageClass::kFunction, &ary4);
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(
std::make_unique<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("ary"), create<ast::IdentifierExpression>("ary"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2))), create<ast::SintLiteral>(&i32, 2))),
std::make_unique<ast::IdentifierExpression>("xy")); create<ast::IdentifierExpression>("xy"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -284,19 +284,16 @@ TEST_F(BuilderTest, MemberAccessor) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back( members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
std::make_unique<ast::StructMember>("a", &f32, std::move(decos))); members.push_back(create<ast::StructMember>("b", &f32, std::move(decos)));
members.push_back(
std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("my_struct", std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("ident"),
std::make_unique<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>("b"));
std::make_unique<ast::IdentifierExpression>("b"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -337,27 +334,27 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
ast::StructMemberList inner_members; ast::StructMemberList inner_members;
inner_members.push_back( inner_members.push_back(
std::make_unique<ast::StructMember>("a", &f32, std::move(decos))); create<ast::StructMember>("a", &f32, std::move(decos)));
inner_members.push_back( inner_members.push_back(
std::make_unique<ast::StructMember>("b", &f32, std::move(decos))); create<ast::StructMember>("b", &f32, std::move(decos)));
ast::type::StructType inner_struct( ast::type::StructType inner_struct(
"Inner", std::make_unique<ast::Struct>(std::move(inner_members))); "Inner", create<ast::Struct>(std::move(inner_members)));
ast::StructMemberList outer_members; ast::StructMemberList outer_members;
outer_members.push_back(std::make_unique<ast::StructMember>( outer_members.push_back(
"inner", &inner_struct, std::move(decos))); create<ast::StructMember>("inner", &inner_struct, std::move(decos)));
ast::type::StructType s_type( ast::type::StructType s_type("my_struct",
"my_struct", std::make_unique<ast::Struct>(std::move(outer_members))); create<ast::Struct>(std::move(outer_members)));
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(
std::make_unique<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>("ident"),
std::make_unique<ast::IdentifierExpression>("inner")), create<ast::IdentifierExpression>("inner")),
std::make_unique<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>("a"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -400,29 +397,29 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
ast::StructMemberList inner_members; ast::StructMemberList inner_members;
inner_members.push_back( inner_members.push_back(
std::make_unique<ast::StructMember>("a", &f32, std::move(decos))); create<ast::StructMember>("a", &f32, std::move(decos)));
inner_members.push_back( inner_members.push_back(
std::make_unique<ast::StructMember>("b", &f32, std::move(decos))); create<ast::StructMember>("b", &f32, std::move(decos)));
ast::type::StructType inner_struct( ast::type::StructType inner_struct(
"Inner", std::make_unique<ast::Struct>(std::move(inner_members))); "Inner", create<ast::Struct>(std::move(inner_members)));
ast::type::AliasType alias("Inner", &inner_struct); ast::type::AliasType alias("Inner", &inner_struct);
ast::StructMemberList outer_members; ast::StructMemberList outer_members;
outer_members.push_back( outer_members.push_back(
std::make_unique<ast::StructMember>("inner", &alias, std::move(decos))); create<ast::StructMember>("inner", &alias, std::move(decos)));
ast::type::StructType s_type( ast::type::StructType s_type("Outer",
"Outer", std::make_unique<ast::Struct>(std::move(outer_members))); create<ast::Struct>(std::move(outer_members)));
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(
std::make_unique<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>("ident"),
std::make_unique<ast::IdentifierExpression>("inner")), create<ast::IdentifierExpression>("inner")),
std::make_unique<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>("a"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -465,30 +462,30 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
ast::StructMemberList inner_members; ast::StructMemberList inner_members;
inner_members.push_back( inner_members.push_back(
std::make_unique<ast::StructMember>("a", &f32, std::move(decos))); create<ast::StructMember>("a", &f32, std::move(decos)));
inner_members.push_back( inner_members.push_back(
std::make_unique<ast::StructMember>("b", &f32, std::move(decos))); create<ast::StructMember>("b", &f32, std::move(decos)));
ast::type::StructType inner_struct( ast::type::StructType inner_struct(
"Inner", std::make_unique<ast::Struct>(std::move(inner_members))); "Inner", create<ast::Struct>(std::move(inner_members)));
ast::StructMemberList outer_members; ast::StructMemberList outer_members;
outer_members.push_back(std::make_unique<ast::StructMember>( outer_members.push_back(
"inner", &inner_struct, std::move(decos))); create<ast::StructMember>("inner", &inner_struct, std::move(decos)));
ast::type::StructType s_type( ast::type::StructType s_type("my_struct",
"my_struct", std::make_unique<ast::Struct>(std::move(outer_members))); create<ast::Struct>(std::move(outer_members)));
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
auto lhs = std::make_unique<ast::MemberAccessorExpression>( auto lhs = create<ast::MemberAccessorExpression>(
std::make_unique<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>("ident"),
std::make_unique<ast::IdentifierExpression>("inner")), create<ast::IdentifierExpression>("inner")),
std::make_unique<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>("a"));
auto rhs = std::make_unique<ast::ScalarConstructorExpression>( auto rhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.f)); create<ast::FloatLiteral>(&f32, 2.f));
ast::AssignmentStatement expr(std::move(lhs), std::move(rhs)); ast::AssignmentStatement expr(std::move(lhs), std::move(rhs));
@ -535,30 +532,30 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
ast::StructMemberList inner_members; ast::StructMemberList inner_members;
inner_members.push_back( inner_members.push_back(
std::make_unique<ast::StructMember>("a", &f32, std::move(decos))); create<ast::StructMember>("a", &f32, std::move(decos)));
inner_members.push_back( inner_members.push_back(
std::make_unique<ast::StructMember>("b", &f32, std::move(decos))); create<ast::StructMember>("b", &f32, std::move(decos)));
ast::type::StructType inner_struct( ast::type::StructType inner_struct(
"Inner", std::make_unique<ast::Struct>(std::move(inner_members))); "Inner", create<ast::Struct>(std::move(inner_members)));
ast::StructMemberList outer_members; ast::StructMemberList outer_members;
outer_members.push_back(std::make_unique<ast::StructMember>( outer_members.push_back(
"inner", &inner_struct, std::move(decos))); create<ast::StructMember>("inner", &inner_struct, std::move(decos)));
ast::type::StructType s_type( ast::type::StructType s_type("my_struct",
"my_struct", std::make_unique<ast::Struct>(std::move(outer_members))); create<ast::Struct>(std::move(outer_members)));
ast::Variable var("ident", ast::StorageClass::kFunction, &s_type); ast::Variable var("ident", ast::StorageClass::kFunction, &s_type);
ast::Variable store("store", ast::StorageClass::kFunction, &f32); ast::Variable store("store", ast::StorageClass::kFunction, &f32);
auto lhs = std::make_unique<ast::IdentifierExpression>("store"); auto lhs = create<ast::IdentifierExpression>("store");
auto rhs = std::make_unique<ast::MemberAccessorExpression>( auto rhs = create<ast::MemberAccessorExpression>(
std::make_unique<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>("ident"),
std::make_unique<ast::IdentifierExpression>("inner")), create<ast::IdentifierExpression>("inner")),
std::make_unique<ast::IdentifierExpression>("a")); create<ast::IdentifierExpression>("a"));
ast::AssignmentStatement expr(std::move(lhs), std::move(rhs)); ast::AssignmentStatement expr(std::move(lhs), std::move(rhs));
@ -601,9 +598,8 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
ast::Variable var("ident", ast::StorageClass::kFunction, &vec3); ast::Variable var("ident", ast::StorageClass::kFunction, &vec3);
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("ident"),
std::make_unique<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>("y"));
std::make_unique<ast::IdentifierExpression>("y"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -637,9 +633,8 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
ast::Variable var("ident", ast::StorageClass::kFunction, &vec3); ast::Variable var("ident", ast::StorageClass::kFunction, &vec3);
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(create<ast::IdentifierExpression>("ident"),
std::make_unique<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>("yx"));
std::make_unique<ast::IdentifierExpression>("yx"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -673,10 +668,10 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
ast::Variable var("ident", ast::StorageClass::kFunction, &vec3); ast::Variable var("ident", ast::StorageClass::kFunction, &vec3);
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(
std::make_unique<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>("ident"),
std::make_unique<ast::IdentifierExpression>("yxz")), create<ast::IdentifierExpression>("yxz")),
std::make_unique<ast::IdentifierExpression>("xz")); create<ast::IdentifierExpression>("xz"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -711,10 +706,10 @@ TEST_F(BuilderTest, MemberAccessor_Member_of_Swizzle) {
ast::Variable var("ident", ast::StorageClass::kFunction, &vec3); ast::Variable var("ident", ast::StorageClass::kFunction, &vec3);
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(
std::make_unique<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>("ident"),
std::make_unique<ast::IdentifierExpression>("yxz")), create<ast::IdentifierExpression>("yxz")),
std::make_unique<ast::IdentifierExpression>("x")); create<ast::IdentifierExpression>("x"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -749,11 +744,11 @@ TEST_F(BuilderTest, MemberAccessor_Array_of_Swizzle) {
ast::Variable var("ident", ast::StorageClass::kFunction, &vec3); ast::Variable var("ident", ast::StorageClass::kFunction, &vec3);
ast::ArrayAccessorExpression expr( ast::ArrayAccessorExpression expr(
std::make_unique<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>("ident"),
std::make_unique<ast::IdentifierExpression>("yxz")), create<ast::IdentifierExpression>("yxz")),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -799,21 +794,20 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back( members.push_back(create<ast::StructMember>("baz", &vec3, std::move(decos)));
std::make_unique<ast::StructMember>("baz", &vec3, std::move(decos))); auto s = create<ast::Struct>(std::move(members));
auto s = std::make_unique<ast::Struct>(std::move(members));
ast::type::StructType c_type("C", std::move(s)); ast::type::StructType c_type("C", std::move(s));
members.push_back( members.push_back(
std::make_unique<ast::StructMember>("bar", &c_type, std::move(decos))); create<ast::StructMember>("bar", &c_type, std::move(decos)));
s = std::make_unique<ast::Struct>(std::move(members)); s = create<ast::Struct>(std::move(members));
ast::type::StructType b_type("B", std::move(s)); ast::type::StructType b_type("B", std::move(s));
ast::type::ArrayType b_ary_type(&b_type, 3); ast::type::ArrayType b_ary_type(&b_type, 3);
members.push_back(std::make_unique<ast::StructMember>("foo", &b_ary_type, members.push_back(
std::move(decos))); create<ast::StructMember>("foo", &b_ary_type, std::move(decos)));
s = std::make_unique<ast::Struct>(std::move(members)); s = create<ast::Struct>(std::move(members));
ast::type::StructType a_type("A", std::move(s)); ast::type::StructType a_type("A", std::move(s));
ast::type::ArrayType a_ary_type(&a_type, 2); ast::type::ArrayType a_ary_type(&a_type, 2);
@ -821,20 +815,20 @@ TEST_F(BuilderTest, Accessor_Mixed_ArrayAndMember) {
ast::Variable var("index", ast::StorageClass::kFunction, &a_ary_type); ast::Variable var("index", ast::StorageClass::kFunction, &a_ary_type);
ast::MemberAccessorExpression expr( ast::MemberAccessorExpression expr(
std::make_unique<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
std::make_unique<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
std::make_unique<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
std::make_unique<ast::MemberAccessorExpression>( create<ast::MemberAccessorExpression>(
std::make_unique<ast::ArrayAccessorExpression>( create<ast::ArrayAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("index"), create<ast::IdentifierExpression>("index"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 0))), create<ast::SintLiteral>(&i32, 0))),
std::make_unique<ast::IdentifierExpression>("foo")), create<ast::IdentifierExpression>("foo")),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2))), create<ast::SintLiteral>(&i32, 2))),
std::make_unique<ast::IdentifierExpression>("bar")), create<ast::IdentifierExpression>("bar")),
std::make_unique<ast::IdentifierExpression>("baz")), create<ast::IdentifierExpression>("baz")),
std::make_unique<ast::IdentifierExpression>("yx")); create<ast::IdentifierExpression>("yx"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -888,36 +882,35 @@ TEST_F(BuilderTest, Accessor_Array_Of_Vec) {
ast::ExpressionList ary_params; ast::ExpressionList ary_params;
ast::ExpressionList vec_params; ast::ExpressionList vec_params;
vec_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( vec_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 0.0))); create<ast::FloatLiteral>(&f32, 0.0)));
vec_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( vec_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 0.5))); create<ast::FloatLiteral>(&f32, 0.5)));
ary_params.push_back(std::make_unique<ast::TypeConstructorExpression>( ary_params.push_back(
&vec, std::move(vec_params))); create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
vec_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( vec_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, -0.5))); create<ast::FloatLiteral>(&f32, -0.5)));
vec_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( vec_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, -0.5))); create<ast::FloatLiteral>(&f32, -0.5)));
ary_params.push_back(std::make_unique<ast::TypeConstructorExpression>( ary_params.push_back(
&vec, std::move(vec_params))); create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
vec_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( vec_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 0.5))); create<ast::FloatLiteral>(&f32, 0.5)));
vec_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( vec_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, -0.5))); create<ast::FloatLiteral>(&f32, -0.5)));
ary_params.push_back(std::make_unique<ast::TypeConstructorExpression>( ary_params.push_back(
&vec, std::move(vec_params))); create<ast::TypeConstructorExpression>(&vec, std::move(vec_params)));
ast::Variable var("pos", ast::StorageClass::kPrivate, &arr); ast::Variable var("pos", ast::StorageClass::kPrivate, &arr);
var.set_is_const(true); var.set_is_const(true);
var.set_constructor(std::make_unique<ast::TypeConstructorExpression>( var.set_constructor(
&arr, std::move(ary_params))); create<ast::TypeConstructorExpression>(&arr, std::move(ary_params)));
ast::ArrayAccessorExpression expr( ast::ArrayAccessorExpression expr(create<ast::IdentifierExpression>("pos"),
std::make_unique<ast::IdentifierExpression>("pos"), create<ast::ScalarConstructorExpression>(
std::make_unique<ast::ScalarConstructorExpression>( create<ast::UintLiteral>(&u32, 1)));
std::make_unique<ast::UintLiteral>(&u32, 1)));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
ASSERT_TRUE(td.DetermineResultType(var.constructor())) << td.error(); ASSERT_TRUE(td.DetermineResultType(var.constructor())) << td.error();

View File

@ -47,9 +47,9 @@ TEST_F(BuilderTest, Assign_Var) {
ast::Variable v("var", ast::StorageClass::kOutput, &f32); ast::Variable v("var", ast::StorageClass::kOutput, &f32);
auto ident = std::make_unique<ast::IdentifierExpression>("var"); auto ident = create<ast::IdentifierExpression>("var");
auto val = std::make_unique<ast::ScalarConstructorExpression>( auto val = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)); create<ast::FloatLiteral>(&f32, 1.0f));
ast::AssignmentStatement assign(std::move(ident), std::move(val)); ast::AssignmentStatement assign(std::move(ident), std::move(val));
@ -81,10 +81,9 @@ TEST_F(BuilderTest, Assign_Var_ZeroConstructor) {
ast::Variable v("var", ast::StorageClass::kOutput, &vec); ast::Variable v("var", ast::StorageClass::kOutput, &vec);
auto ident = std::make_unique<ast::IdentifierExpression>("var"); auto ident = create<ast::IdentifierExpression>("var");
ast::ExpressionList vals; ast::ExpressionList vals;
auto val = auto val = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
ast::AssignmentStatement assign(std::move(ident), std::move(val)); ast::AssignmentStatement assign(std::move(ident), std::move(val));
@ -116,24 +115,22 @@ TEST_F(BuilderTest, Assign_Var_Complex_ConstructorWithExtract) {
ast::type::VectorType vec2(&f32, 2); ast::type::VectorType vec2(&f32, 2);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.0f))); create<ast::FloatLiteral>(&f32, 2.0f)));
auto first = auto first = create<ast::TypeConstructorExpression>(&vec2, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec2, std::move(vals));
vals.push_back(std::move(first)); vals.push_back(std::move(first));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto init = auto init = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
ast::Variable v("var", ast::StorageClass::kOutput, &vec3); ast::Variable v("var", ast::StorageClass::kOutput, &vec3);
ast::AssignmentStatement assign( ast::AssignmentStatement assign(create<ast::IdentifierExpression>("var"),
std::make_unique<ast::IdentifierExpression>("var"), std::move(init)); std::move(init));
td.RegisterVariableForTesting(&v); td.RegisterVariableForTesting(&v);
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
@ -169,20 +166,19 @@ TEST_F(BuilderTest, Assign_Var_Complex_Constructor) {
ast::type::VectorType vec3(&f32, 3); ast::type::VectorType vec3(&f32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.0f))); create<ast::FloatLiteral>(&f32, 2.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto init = auto init = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
ast::Variable v("var", ast::StorageClass::kOutput, &vec3); ast::Variable v("var", ast::StorageClass::kOutput, &vec3);
ast::AssignmentStatement assign( ast::AssignmentStatement assign(create<ast::IdentifierExpression>("var"),
std::make_unique<ast::IdentifierExpression>("var"), std::move(init)); std::move(init));
td.RegisterVariableForTesting(&v); td.RegisterVariableForTesting(&v);
ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&assign)) << td.error();
@ -220,22 +216,20 @@ TEST_F(BuilderTest, Assign_StructMember) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back( members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
std::make_unique<ast::StructMember>("a", &f32, std::move(decos))); members.push_back(create<ast::StructMember>("b", &f32, std::move(decos)));
members.push_back(
std::make_unique<ast::StructMember>("b", &f32, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("my_struct", std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
ast::Variable v("ident", ast::StorageClass::kFunction, &s_type); ast::Variable v("ident", ast::StorageClass::kFunction, &s_type);
auto ident = std::make_unique<ast::MemberAccessorExpression>( auto ident = create<ast::MemberAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("ident"), create<ast::IdentifierExpression>("ident"),
std::make_unique<ast::IdentifierExpression>("b")); create<ast::IdentifierExpression>("b"));
auto val = std::make_unique<ast::ScalarConstructorExpression>( auto val = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 4.0f)); create<ast::FloatLiteral>(&f32, 4.0f));
ast::AssignmentStatement assign(std::move(ident), std::move(val)); ast::AssignmentStatement assign(std::move(ident), std::move(val));
@ -272,18 +266,17 @@ TEST_F(BuilderTest, Assign_Vector) {
ast::Variable v("var", ast::StorageClass::kOutput, &vec3); ast::Variable v("var", ast::StorageClass::kOutput, &vec3);
auto ident = std::make_unique<ast::IdentifierExpression>("var"); auto ident = create<ast::IdentifierExpression>("var");
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto val = auto val = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
ast::AssignmentStatement assign(std::move(ident), std::move(val)); ast::AssignmentStatement assign(std::move(ident), std::move(val));
@ -320,11 +313,11 @@ TEST_F(BuilderTest, Assign_Vector_MemberByName) {
ast::Variable v("var", ast::StorageClass::kOutput, &vec3); ast::Variable v("var", ast::StorageClass::kOutput, &vec3);
auto ident = std::make_unique<ast::MemberAccessorExpression>( auto ident = create<ast::MemberAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("var"), create<ast::IdentifierExpression>("var"),
std::make_unique<ast::IdentifierExpression>("y")); create<ast::IdentifierExpression>("y"));
auto val = std::make_unique<ast::ScalarConstructorExpression>( auto val = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)); create<ast::FloatLiteral>(&f32, 1.0f));
ast::AssignmentStatement assign(std::move(ident), std::move(val)); ast::AssignmentStatement assign(std::move(ident), std::move(val));
@ -365,12 +358,12 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
ast::Variable v("var", ast::StorageClass::kOutput, &vec3); ast::Variable v("var", ast::StorageClass::kOutput, &vec3);
auto ident = std::make_unique<ast::ArrayAccessorExpression>( auto ident = create<ast::ArrayAccessorExpression>(
std::make_unique<ast::IdentifierExpression>("var"), create<ast::IdentifierExpression>("var"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
auto val = std::make_unique<ast::ScalarConstructorExpression>( auto val = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f)); create<ast::FloatLiteral>(&f32, 1.0f));
ast::AssignmentStatement assign(std::move(ident), std::move(val)); ast::AssignmentStatement assign(std::move(ident), std::move(val));

View File

@ -57,10 +57,10 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto lhs = std::make_unique<ast::ScalarConstructorExpression>( auto lhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3)); create<ast::SintLiteral>(&i32, 3));
auto rhs = std::make_unique<ast::ScalarConstructorExpression>( auto rhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 4)); create<ast::SintLiteral>(&i32, 4));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -83,23 +83,21 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
ast::type::VectorType vec3(&i32, 3); ast::type::VectorType vec3(&i32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
auto lhs = auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
auto rhs = auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -123,8 +121,8 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar_Loads) {
ast::Variable var("param", ast::StorageClass::kFunction, &i32); ast::Variable var("param", ast::StorageClass::kFunction, &i32);
auto lhs = std::make_unique<ast::IdentifierExpression>("param"); auto lhs = create<ast::IdentifierExpression>("param");
auto rhs = std::make_unique<ast::IdentifierExpression>("param"); auto rhs = create<ast::IdentifierExpression>("param");
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -171,10 +169,10 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
ast::type::U32Type u32; ast::type::U32Type u32;
auto lhs = std::make_unique<ast::ScalarConstructorExpression>( auto lhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 3)); create<ast::UintLiteral>(&u32, 3));
auto rhs = std::make_unique<ast::ScalarConstructorExpression>( auto rhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 4)); create<ast::UintLiteral>(&u32, 4));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -197,23 +195,21 @@ TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
ast::type::VectorType vec3(&u32, 3); ast::type::VectorType vec3(&u32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
auto lhs = auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
auto rhs = auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -251,10 +247,10 @@ TEST_P(BinaryArithFloatTest, Scalar) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto lhs = std::make_unique<ast::ScalarConstructorExpression>( auto lhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.2f)); create<ast::FloatLiteral>(&f32, 3.2f));
auto rhs = std::make_unique<ast::ScalarConstructorExpression>( auto rhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 4.5f)); create<ast::FloatLiteral>(&f32, 4.5f));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -277,23 +273,21 @@ TEST_P(BinaryArithFloatTest, Vector) {
ast::type::VectorType vec3(&f32, 3); ast::type::VectorType vec3(&f32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto lhs = auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto rhs = auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -325,10 +319,10 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
ast::type::U32Type u32; ast::type::U32Type u32;
auto lhs = std::make_unique<ast::ScalarConstructorExpression>( auto lhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 3)); create<ast::UintLiteral>(&u32, 3));
auto rhs = std::make_unique<ast::ScalarConstructorExpression>( auto rhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 4)); create<ast::UintLiteral>(&u32, 4));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -353,23 +347,21 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Vector) {
ast::type::VectorType vec3(&u32, 3); ast::type::VectorType vec3(&u32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
auto lhs = auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::UintLiteral>(&u32, 1))); create<ast::UintLiteral>(&u32, 1)));
auto rhs = auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -405,10 +397,10 @@ TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto lhs = std::make_unique<ast::ScalarConstructorExpression>( auto lhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3)); create<ast::SintLiteral>(&i32, 3));
auto rhs = std::make_unique<ast::ScalarConstructorExpression>( auto rhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 4)); create<ast::SintLiteral>(&i32, 4));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -433,23 +425,21 @@ TEST_P(BinaryCompareSignedIntegerTest, Vector) {
ast::type::VectorType vec3(&i32, 3); ast::type::VectorType vec3(&i32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
auto lhs = auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1))); create<ast::SintLiteral>(&i32, 1)));
auto rhs = auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -485,10 +475,10 @@ TEST_P(BinaryCompareFloatTest, Scalar) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto lhs = std::make_unique<ast::ScalarConstructorExpression>( auto lhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.2f)); create<ast::FloatLiteral>(&f32, 3.2f));
auto rhs = std::make_unique<ast::ScalarConstructorExpression>( auto rhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 4.5f)); create<ast::FloatLiteral>(&f32, 4.5f));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -513,23 +503,21 @@ TEST_P(BinaryCompareFloatTest, Vector) {
ast::type::VectorType vec3(&f32, 3); ast::type::VectorType vec3(&f32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto lhs = auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto rhs = auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs)); ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
@ -564,17 +552,16 @@ TEST_F(BuilderTest, Binary_Multiply_VectorScalar) {
ast::type::VectorType vec3(&f32, 3); ast::type::VectorType vec3(&f32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto lhs = auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto rhs = std::make_unique<ast::ScalarConstructorExpression>( auto rhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f)); create<ast::FloatLiteral>(&f32, 1.f));
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs), ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs)); std::move(rhs));
@ -597,18 +584,17 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::VectorType vec3(&f32, 3); ast::type::VectorType vec3(&f32, 3);
auto lhs = std::make_unique<ast::ScalarConstructorExpression>( auto lhs = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f)); create<ast::FloatLiteral>(&f32, 1.f));
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto rhs = auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs), ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs)); std::move(rhs));
@ -631,11 +617,10 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::MatrixType mat3(&f32, 3, 3); ast::type::MatrixType mat3(&f32, 3, 3);
auto var = std::make_unique<ast::Variable>( auto var = create<ast::Variable>("mat", ast::StorageClass::kFunction, &mat3);
"mat", ast::StorageClass::kFunction, &mat3); auto lhs = create<ast::IdentifierExpression>("mat");
auto lhs = std::make_unique<ast::IdentifierExpression>("mat"); auto rhs = create<ast::ScalarConstructorExpression>(
auto rhs = std::make_unique<ast::ScalarConstructorExpression>( create<ast::FloatLiteral>(&f32, 1.f));
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
td.RegisterVariableForTesting(var.get()); td.RegisterVariableForTesting(var.get());
@ -665,11 +650,10 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::MatrixType mat3(&f32, 3, 3); ast::type::MatrixType mat3(&f32, 3, 3);
auto var = std::make_unique<ast::Variable>( auto var = create<ast::Variable>("mat", ast::StorageClass::kFunction, &mat3);
"mat", ast::StorageClass::kFunction, &mat3); auto lhs = create<ast::ScalarConstructorExpression>(
auto lhs = std::make_unique<ast::ScalarConstructorExpression>( create<ast::FloatLiteral>(&f32, 1.f));
std::make_unique<ast::FloatLiteral>(&f32, 1.f)); auto rhs = create<ast::IdentifierExpression>("mat");
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
td.RegisterVariableForTesting(var.get()); td.RegisterVariableForTesting(var.get());
@ -700,19 +684,17 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
ast::type::VectorType vec3(&f32, 3); ast::type::VectorType vec3(&f32, 3);
ast::type::MatrixType mat3(&f32, 3, 3); ast::type::MatrixType mat3(&f32, 3, 3);
auto var = std::make_unique<ast::Variable>( auto var = create<ast::Variable>("mat", ast::StorageClass::kFunction, &mat3);
"mat", ast::StorageClass::kFunction, &mat3); auto lhs = create<ast::IdentifierExpression>("mat");
auto lhs = std::make_unique<ast::IdentifierExpression>("mat");
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto rhs = auto rhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
td.RegisterVariableForTesting(var.get()); td.RegisterVariableForTesting(var.get());
@ -744,20 +726,18 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
ast::type::VectorType vec3(&f32, 3); ast::type::VectorType vec3(&f32, 3);
ast::type::MatrixType mat3(&f32, 3, 3); ast::type::MatrixType mat3(&f32, 3, 3);
auto var = std::make_unique<ast::Variable>( auto var = create<ast::Variable>("mat", ast::StorageClass::kFunction, &mat3);
"mat", ast::StorageClass::kFunction, &mat3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
auto lhs = auto lhs = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
auto rhs = std::make_unique<ast::IdentifierExpression>("mat"); auto rhs = create<ast::IdentifierExpression>("mat");
td.RegisterVariableForTesting(var.get()); td.RegisterVariableForTesting(var.get());
@ -789,10 +769,9 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
ast::type::VectorType vec3(&f32, 3); ast::type::VectorType vec3(&f32, 3);
ast::type::MatrixType mat3(&f32, 3, 3); ast::type::MatrixType mat3(&f32, 3, 3);
auto var = std::make_unique<ast::Variable>( auto var = create<ast::Variable>("mat", ast::StorageClass::kFunction, &mat3);
"mat", ast::StorageClass::kFunction, &mat3); auto lhs = create<ast::IdentifierExpression>("mat");
auto lhs = std::make_unique<ast::IdentifierExpression>("mat"); auto rhs = create<ast::IdentifierExpression>("mat");
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
td.RegisterVariableForTesting(var.get()); td.RegisterVariableForTesting(var.get());
@ -821,19 +800,19 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
TEST_F(BuilderTest, Binary_LogicalAnd) { TEST_F(BuilderTest, Binary_LogicalAnd) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto lhs = std::make_unique<ast::BinaryExpression>( auto lhs =
ast::BinaryOp::kEqual, create<ast::BinaryExpression>(ast::BinaryOp::kEqual,
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1)), create<ast::SintLiteral>(&i32, 1)),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2))); create<ast::SintLiteral>(&i32, 2)));
auto rhs = std::make_unique<ast::BinaryExpression>( auto rhs =
ast::BinaryOp::kEqual, create<ast::BinaryExpression>(ast::BinaryOp::kEqual,
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3)), create<ast::SintLiteral>(&i32, 3)),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 4))); create<ast::SintLiteral>(&i32, 4)));
ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, std::move(lhs), ast::BinaryExpression expr(ast::BinaryOp::kLogicalAnd, std::move(lhs),
std::move(rhs)); std::move(rhs));
@ -867,17 +846,17 @@ OpBranch %7
TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) { TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
ast::type::BoolType bool_type; ast::type::BoolType bool_type;
auto a_var = std::make_unique<ast::Variable>( auto a_var =
"a", ast::StorageClass::kFunction, &bool_type); create<ast::Variable>("a", ast::StorageClass::kFunction, &bool_type);
a_var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>( a_var->set_constructor(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true))); create<ast::BoolLiteral>(&bool_type, true)));
auto b_var = std::make_unique<ast::Variable>( auto b_var =
"b", ast::StorageClass::kFunction, &bool_type); create<ast::Variable>("b", ast::StorageClass::kFunction, &bool_type);
b_var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>( b_var->set_constructor(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, false))); create<ast::BoolLiteral>(&bool_type, false)));
auto lhs = std::make_unique<ast::IdentifierExpression>("a"); auto lhs = create<ast::IdentifierExpression>("a");
auto rhs = std::make_unique<ast::IdentifierExpression>("b"); auto rhs = create<ast::IdentifierExpression>("b");
td.RegisterVariableForTesting(a_var.get()); td.RegisterVariableForTesting(a_var.get());
td.RegisterVariableForTesting(b_var.get()); td.RegisterVariableForTesting(b_var.get());
@ -917,19 +896,19 @@ OpBranch %9
TEST_F(BuilderTest, Binary_LogicalOr) { TEST_F(BuilderTest, Binary_LogicalOr) {
ast::type::I32Type i32; ast::type::I32Type i32;
auto lhs = std::make_unique<ast::BinaryExpression>( auto lhs =
ast::BinaryOp::kEqual, create<ast::BinaryExpression>(ast::BinaryOp::kEqual,
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1)), create<ast::SintLiteral>(&i32, 1)),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2))); create<ast::SintLiteral>(&i32, 2)));
auto rhs = std::make_unique<ast::BinaryExpression>( auto rhs =
ast::BinaryOp::kEqual, create<ast::BinaryExpression>(ast::BinaryOp::kEqual,
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3)), create<ast::SintLiteral>(&i32, 3)),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 4))); create<ast::SintLiteral>(&i32, 4)));
ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, std::move(lhs), ast::BinaryExpression expr(ast::BinaryOp::kLogicalOr, std::move(lhs),
std::move(rhs)); std::move(rhs));
@ -963,17 +942,17 @@ OpBranch %7
TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) { TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
ast::type::BoolType bool_type; ast::type::BoolType bool_type;
auto a_var = std::make_unique<ast::Variable>( auto a_var =
"a", ast::StorageClass::kFunction, &bool_type); create<ast::Variable>("a", ast::StorageClass::kFunction, &bool_type);
a_var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>( a_var->set_constructor(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true))); create<ast::BoolLiteral>(&bool_type, true)));
auto b_var = std::make_unique<ast::Variable>( auto b_var =
"b", ast::StorageClass::kFunction, &bool_type); create<ast::Variable>("b", ast::StorageClass::kFunction, &bool_type);
b_var->set_constructor(std::make_unique<ast::ScalarConstructorExpression>( b_var->set_constructor(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, false))); create<ast::BoolLiteral>(&bool_type, false)));
auto lhs = std::make_unique<ast::IdentifierExpression>("a"); auto lhs = create<ast::IdentifierExpression>("a");
auto rhs = std::make_unique<ast::IdentifierExpression>("b"); auto rhs = create<ast::IdentifierExpression>("b");
td.RegisterVariableForTesting(a_var.get()); td.RegisterVariableForTesting(a_var.get());
td.RegisterVariableForTesting(b_var.get()); td.RegisterVariableForTesting(b_var.get());

View File

@ -36,9 +36,9 @@ TEST_F(BuilderTest, Bitcast) {
ast::type::U32Type u32; ast::type::U32Type u32;
ast::type::F32Type f32; ast::type::F32Type f32;
ast::BitcastExpression bitcast( ast::BitcastExpression bitcast(&u32,
&u32, std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.4))); create<ast::FloatLiteral>(&f32, 2.4)));
ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();
@ -57,9 +57,9 @@ TEST_F(BuilderTest, Bitcast) {
TEST_F(BuilderTest, Bitcast_DuplicateType) { TEST_F(BuilderTest, Bitcast_DuplicateType) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::BitcastExpression bitcast( ast::BitcastExpression bitcast(&f32,
&f32, std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.4))); create<ast::FloatLiteral>(&f32, 2.4)));
ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&bitcast)) << td.error();

View File

@ -42,28 +42,26 @@ TEST_F(BuilderTest, Block) {
// serves to prove the block code is pushing new scopes as needed. // serves to prove the block code is pushing new scopes as needed.
ast::BlockStatement outer; ast::BlockStatement outer;
outer.append(std::make_unique<ast::VariableDeclStatement>( outer.append(create<ast::VariableDeclStatement>(
std::make_unique<ast::Variable>("var", ast::StorageClass::kFunction, create<ast::Variable>("var", ast::StorageClass::kFunction, &f32)));
&f32))); outer.append(create<ast::AssignmentStatement>(
outer.append(std::make_unique<ast::AssignmentStatement>( create<ast::IdentifierExpression>("var"),
std::make_unique<ast::IdentifierExpression>("var"), create<ast::ScalarConstructorExpression>(
std::make_unique<ast::ScalarConstructorExpression>( create<ast::FloatLiteral>(&f32, 1.0f))));
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))));
auto inner = std::make_unique<ast::BlockStatement>(); auto inner = create<ast::BlockStatement>();
inner->append(std::make_unique<ast::VariableDeclStatement>( inner->append(create<ast::VariableDeclStatement>(
std::make_unique<ast::Variable>("var", ast::StorageClass::kFunction, create<ast::Variable>("var", ast::StorageClass::kFunction, &f32)));
&f32))); inner->append(create<ast::AssignmentStatement>(
inner->append(std::make_unique<ast::AssignmentStatement>( create<ast::IdentifierExpression>("var"),
std::make_unique<ast::IdentifierExpression>("var"), create<ast::ScalarConstructorExpression>(
std::make_unique<ast::ScalarConstructorExpression>( create<ast::FloatLiteral>(&f32, 2.0f))));
std::make_unique<ast::FloatLiteral>(&f32, 2.0f))));
outer.append(std::move(inner)); outer.append(std::move(inner));
outer.append(std::make_unique<ast::AssignmentStatement>( outer.append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("var"), create<ast::IdentifierExpression>("var"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)))); create<ast::FloatLiteral>(&f32, 3.0f))));
ASSERT_TRUE(td.DetermineResultType(&outer)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&outer)) << td.error();

View File

@ -45,29 +45,27 @@ TEST_F(BuilderTest, Expression_Call) {
ast::VariableList func_params; ast::VariableList func_params;
func_params.push_back( func_params.push_back(
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &f32)); create<ast::Variable>("a", ast::StorageClass::kFunction, &f32));
func_params.push_back( func_params.push_back(
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32)); create<ast::Variable>("b", ast::StorageClass::kFunction, &f32));
ast::Function a_func("a_func", std::move(func_params), &f32); ast::Function a_func("a_func", std::move(func_params), &f32);
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(create<ast::BinaryExpression>(
std::make_unique<ast::BinaryExpression>( ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("a"),
ast::BinaryOp::kAdd, std::make_unique<ast::IdentifierExpression>("a"), create<ast::IdentifierExpression>("b"))));
std::make_unique<ast::IdentifierExpression>("b"))));
a_func.set_body(std::move(body)); a_func.set_body(std::move(body));
ast::Function func("main", {}, &void_type); ast::Function func("main", {}, &void_type);
ast::ExpressionList call_params; ast::ExpressionList call_params;
call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( call_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( call_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
ast::CallExpression expr( ast::CallExpression expr(create<ast::IdentifierExpression>("a_func"),
std::make_unique<ast::IdentifierExpression>("a_func"),
std::move(call_params)); std::move(call_params));
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error(); ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();
@ -109,30 +107,28 @@ TEST_F(BuilderTest, Statement_Call) {
ast::VariableList func_params; ast::VariableList func_params;
func_params.push_back( func_params.push_back(
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &f32)); create<ast::Variable>("a", ast::StorageClass::kFunction, &f32));
func_params.push_back( func_params.push_back(
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &f32)); create<ast::Variable>("b", ast::StorageClass::kFunction, &f32));
ast::Function a_func("a_func", std::move(func_params), &void_type); ast::Function a_func("a_func", std::move(func_params), &void_type);
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::ReturnStatement>( body->append(create<ast::ReturnStatement>(create<ast::BinaryExpression>(
std::make_unique<ast::BinaryExpression>( ast::BinaryOp::kAdd, create<ast::IdentifierExpression>("a"),
ast::BinaryOp::kAdd, std::make_unique<ast::IdentifierExpression>("a"), create<ast::IdentifierExpression>("b"))));
std::make_unique<ast::IdentifierExpression>("b"))));
a_func.set_body(std::move(body)); a_func.set_body(std::move(body));
ast::Function func("main", {}, &void_type); ast::Function func("main", {}, &void_type);
ast::ExpressionList call_params; ast::ExpressionList call_params;
call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( call_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>( call_params.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f))); create<ast::FloatLiteral>(&f32, 1.f)));
ast::CallStatement expr(std::make_unique<ast::CallExpression>( ast::CallStatement expr(create<ast::CallExpression>(
std::make_unique<ast::IdentifierExpression>("a_func"), create<ast::IdentifierExpression>("a_func"), std::move(call_params)));
std::move(call_params)));
ASSERT_TRUE(td.DetermineFunction(&func)) << td.error(); ASSERT_TRUE(td.DetermineFunction(&func)) << td.error();
ASSERT_TRUE(td.DetermineFunction(&a_func)) << td.error(); ASSERT_TRUE(td.DetermineFunction(&a_func)) << td.error();

File diff suppressed because it is too large Load Diff

View File

@ -43,8 +43,8 @@ TEST_F(BuilderTest, FunctionDecoration_Stage) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
ast::Function func("main", {}, &void_type); ast::Function func("main", {}, &void_type);
func.add_decoration(std::make_unique<ast::StageDecoration>( func.add_decoration(
ast::PipelineStage::kVertex, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
EXPECT_EQ(DumpInstructions(b.entry_points()), EXPECT_EQ(DumpInstructions(b.entry_points()),
@ -67,8 +67,7 @@ TEST_P(FunctionDecoration_StageTest, Emit) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
ast::Function func("main", {}, &void_type); ast::Function func("main", {}, &void_type);
func.add_decoration( func.add_decoration(create<ast::StageDecoration>(params.stage, Source{}));
std::make_unique<ast::StageDecoration>(params.stage, Source{}));
ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error();
@ -94,14 +93,13 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
ast::Function func("main", {}, &void_type); ast::Function func("main", {}, &void_type);
func.add_decoration(std::make_unique<ast::StageDecoration>( func.add_decoration(
ast::PipelineStage::kVertex, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
auto v_in = auto v_in = create<ast::Variable>("my_in", ast::StorageClass::kInput, &f32);
std::make_unique<ast::Variable>("my_in", ast::StorageClass::kInput, &f32); auto v_out =
auto v_out = std::make_unique<ast::Variable>( create<ast::Variable>("my_out", ast::StorageClass::kOutput, &f32);
"my_out", ast::StorageClass::kOutput, &f32); auto v_wg =
auto v_wg = std::make_unique<ast::Variable>( create<ast::Variable>("my_wg", ast::StorageClass::kWorkgroup, &f32);
"my_wg", ast::StorageClass::kWorkgroup, &f32);
EXPECT_TRUE(b.GenerateGlobalVariable(v_in.get())) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v_in.get())) << b.error();
EXPECT_TRUE(b.GenerateGlobalVariable(v_out.get())) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(v_out.get())) << b.error();
@ -138,28 +136,27 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
ast::Function func("main", {}, &void_type); ast::Function func("main", {}, &void_type);
func.add_decoration(std::make_unique<ast::StageDecoration>( func.add_decoration(
ast::PipelineStage::kVertex, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
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>("my_out"), create<ast::IdentifierExpression>("my_out"),
std::make_unique<ast::IdentifierExpression>("my_in"))); create<ast::IdentifierExpression>("my_in")));
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("my_wg"), create<ast::IdentifierExpression>("my_wg"),
std::make_unique<ast::IdentifierExpression>("my_wg"))); create<ast::IdentifierExpression>("my_wg")));
// Add duplicate usages so we show they don't get output multiple times. // Add duplicate usages so we show they don't get output multiple times.
body->append(std::make_unique<ast::AssignmentStatement>( body->append(create<ast::AssignmentStatement>(
std::make_unique<ast::IdentifierExpression>("my_out"), create<ast::IdentifierExpression>("my_out"),
std::make_unique<ast::IdentifierExpression>("my_in"))); create<ast::IdentifierExpression>("my_in")));
func.set_body(std::move(body)); func.set_body(std::move(body));
auto v_in = auto v_in = create<ast::Variable>("my_in", ast::StorageClass::kInput, &f32);
std::make_unique<ast::Variable>("my_in", ast::StorageClass::kInput, &f32); auto v_out =
auto v_out = std::make_unique<ast::Variable>( create<ast::Variable>("my_out", ast::StorageClass::kOutput, &f32);
"my_out", ast::StorageClass::kOutput, &f32); auto v_wg =
auto v_wg = std::make_unique<ast::Variable>( create<ast::Variable>("my_wg", ast::StorageClass::kWorkgroup, &f32);
"my_wg", ast::StorageClass::kWorkgroup, &f32);
td.RegisterVariableForTesting(v_in.get()); td.RegisterVariableForTesting(v_in.get());
td.RegisterVariableForTesting(v_out.get()); td.RegisterVariableForTesting(v_out.get());
@ -201,8 +198,8 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_Fragment_OriginUpperLeft) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
ast::Function func("main", {}, &void_type); ast::Function func("main", {}, &void_type);
func.add_decoration(std::make_unique<ast::StageDecoration>( func.add_decoration(
ast::PipelineStage::kFragment, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
ASSERT_TRUE(b.GenerateExecutionModes(&func, 3)) << b.error(); ASSERT_TRUE(b.GenerateExecutionModes(&func, 3)) << b.error();
EXPECT_EQ(DumpInstructions(b.execution_modes()), EXPECT_EQ(DumpInstructions(b.execution_modes()),
@ -214,8 +211,8 @@ TEST_F(BuilderTest, FunctionDecoration_WorkgroupSize_Default) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
ast::Function func("main", {}, &void_type); ast::Function func("main", {}, &void_type);
func.add_decoration(std::make_unique<ast::StageDecoration>( func.add_decoration(
ast::PipelineStage::kCompute, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
ASSERT_TRUE(b.GenerateExecutionModes(&func, 3)) << b.error(); ASSERT_TRUE(b.GenerateExecutionModes(&func, 3)) << b.error();
EXPECT_EQ(DumpInstructions(b.execution_modes()), EXPECT_EQ(DumpInstructions(b.execution_modes()),
@ -227,10 +224,9 @@ TEST_F(BuilderTest, FunctionDecoration_WorkgroupSize) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
ast::Function func("main", {}, &void_type); ast::Function func("main", {}, &void_type);
func.add_decoration(create<ast::WorkgroupDecoration>(2u, 4u, 6u, Source{}));
func.add_decoration( func.add_decoration(
std::make_unique<ast::WorkgroupDecoration>(2u, 4u, 6u, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
func.add_decoration(std::make_unique<ast::StageDecoration>(
ast::PipelineStage::kCompute, Source{}));
ASSERT_TRUE(b.GenerateExecutionModes(&func, 3)) << b.error(); ASSERT_TRUE(b.GenerateExecutionModes(&func, 3)) << b.error();
EXPECT_EQ(DumpInstructions(b.execution_modes()), EXPECT_EQ(DumpInstructions(b.execution_modes()),
@ -242,12 +238,12 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_MultipleFragment) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
ast::Function func1("main1", {}, &void_type); ast::Function func1("main1", {}, &void_type);
func1.add_decoration(std::make_unique<ast::StageDecoration>( func1.add_decoration(
ast::PipelineStage::kFragment, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
ast::Function func2("main2", {}, &void_type); ast::Function func2("main2", {}, &void_type);
func2.add_decoration(std::make_unique<ast::StageDecoration>( func2.add_decoration(
ast::PipelineStage::kFragment, Source{})); create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
ASSERT_TRUE(b.GenerateFunction(&func1)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func1)) << b.error();
ASSERT_TRUE(b.GenerateFunction(&func2)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func2)) << b.error();

View File

@ -69,20 +69,18 @@ TEST_F(BuilderTest, Function_WithParams) {
ast::type::I32Type i32; ast::type::I32Type i32;
ast::VariableList params; ast::VariableList params;
auto var_a = auto var_a = create<ast::Variable>("a", ast::StorageClass::kFunction, &f32);
std::make_unique<ast::Variable>("a", ast::StorageClass::kFunction, &f32);
var_a->set_is_const(true); var_a->set_is_const(true);
params.push_back(std::move(var_a)); params.push_back(std::move(var_a));
auto var_b = auto var_b = create<ast::Variable>("b", ast::StorageClass::kFunction, &i32);
std::make_unique<ast::Variable>("b", ast::StorageClass::kFunction, &i32);
var_b->set_is_const(true); var_b->set_is_const(true);
params.push_back(std::move(var_b)); params.push_back(std::move(var_b));
ast::Function func("a_func", std::move(params), &f32); ast::Function func("a_func", std::move(params), &f32);
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::IdentifierExpression>("a"))); create<ast::ReturnStatement>(create<ast::IdentifierExpression>("a")));
func.set_body(std::move(body)); func.set_body(std::move(body));
td.RegisterVariableForTesting(func.params()[0].get()); td.RegisterVariableForTesting(func.params()[0].get());
@ -108,8 +106,8 @@ OpFunctionEnd
TEST_F(BuilderTest, Function_WithBody) { TEST_F(BuilderTest, Function_WithBody) {
ast::type::VoidType void_type; ast::type::VoidType void_type;
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::Function func("a_func", {}, &void_type); ast::Function func("a_func", {}, &void_type);
func.set_body(std::move(body)); func.set_body(std::move(body));
@ -169,27 +167,23 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
ast::StructMemberList members; ast::StructMemberList members;
ast::StructMemberDecorationList a_deco; ast::StructMemberDecorationList a_deco;
a_deco.push_back( a_deco.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(0, Source{})); members.push_back(create<ast::StructMember>("d", &f32, std::move(a_deco)));
members.push_back(
std::make_unique<ast::StructMember>("d", &f32, std::move(a_deco)));
ast::StructDecorationList s_decos; ast::StructDecorationList s_decos;
s_decos.push_back(std::make_unique<ast::StructBlockDecoration>(Source{})); s_decos.push_back(create<ast::StructBlockDecoration>(Source{}));
auto str = auto str = create<ast::Struct>(std::move(s_decos), std::move(members));
std::make_unique<ast::Struct>(std::move(s_decos), std::move(members));
ast::type::StructType s("Data", std::move(str)); ast::type::StructType s("Data", std::move(str));
ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s); ast::type::AccessControlType ac(ast::AccessControl::kReadWrite, &s);
auto data_var = auto data_var = create<ast::DecoratedVariable>(
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>( create<ast::Variable>("data", ast::StorageClass::kStorageBuffer, &ac));
"data", ast::StorageClass::kStorageBuffer, &ac));
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::BindingDecoration>(0, Source{})); decos.push_back(create<ast::BindingDecoration>(0, Source{}));
decos.push_back(std::make_unique<ast::SetDecoration>(0, Source{})); decos.push_back(create<ast::SetDecoration>(0, Source{}));
data_var->set_decorations(std::move(decos)); data_var->set_decorations(std::move(decos));
mod.AddConstructedType(&s); mod.AddConstructedType(&s);
@ -199,20 +193,18 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
{ {
ast::VariableList params; ast::VariableList params;
auto func = auto func = create<ast::Function>("a", std::move(params), &void_type);
std::make_unique<ast::Function>("a", std::move(params), &void_type); func->add_decoration(
func->add_decoration(std::make_unique<ast::StageDecoration>( create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
ast::PipelineStage::kCompute, Source{}));
auto var = std::make_unique<ast::Variable>( auto var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
"v", ast::StorageClass::kFunction, &f32); var->set_constructor(create<ast::MemberAccessorExpression>(
var->set_constructor(std::make_unique<ast::MemberAccessorExpression>( create<ast::IdentifierExpression>("data"),
std::make_unique<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>("d")));
std::make_unique<ast::IdentifierExpression>("d")));
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::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
func->set_body(std::move(body)); func->set_body(std::move(body));
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));
@ -220,20 +212,18 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) {
{ {
ast::VariableList params; ast::VariableList params;
auto func = auto func = create<ast::Function>("b", std::move(params), &void_type);
std::make_unique<ast::Function>("b", std::move(params), &void_type); func->add_decoration(
func->add_decoration(std::make_unique<ast::StageDecoration>( create<ast::StageDecoration>(ast::PipelineStage::kCompute, Source{}));
ast::PipelineStage::kCompute, Source{}));
auto var = std::make_unique<ast::Variable>( auto var = create<ast::Variable>("v", ast::StorageClass::kFunction, &f32);
"v", ast::StorageClass::kFunction, &f32); var->set_constructor(create<ast::MemberAccessorExpression>(
var->set_constructor(std::make_unique<ast::MemberAccessorExpression>( create<ast::IdentifierExpression>("data"),
std::make_unique<ast::IdentifierExpression>("data"), create<ast::IdentifierExpression>("d")));
std::make_unique<ast::IdentifierExpression>("d")));
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::ReturnStatement>()); body->append(create<ast::ReturnStatement>());
func->set_body(std::move(body)); func->set_body(std::move(body));
mod.AddFunction(std::move(func)); mod.AddFunction(std::move(func));

View File

@ -70,15 +70,14 @@ TEST_F(BuilderTest, FunctionVar_WithConstantConstructor) {
ast::type::VectorType vec(&f32, 3); ast::type::VectorType vec(&f32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto init = auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error(); EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
@ -112,20 +111,19 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantConstructor) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::type::VectorType vec(&f32, 2); ast::type::VectorType vec(&f32, 2);
auto rel = std::make_unique<ast::BinaryExpression>( auto rel =
ast::BinaryOp::kAdd, create<ast::BinaryExpression>(ast::BinaryOp::kAdd,
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f)), create<ast::FloatLiteral>(&f32, 3.0f)),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::move(rel)); vals.push_back(std::move(rel));
auto init = auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error(); EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
@ -170,15 +168,14 @@ TEST_F(BuilderTest, FunctionVar_Const) {
ast::type::VectorType vec(&f32, 3); ast::type::VectorType vec(&f32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto init = auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error(); EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();

View File

@ -97,15 +97,14 @@ TEST_F(BuilderTest, GlobalVar_WithConstructor) {
ast::type::VectorType vec(&f32, 3); ast::type::VectorType vec(&f32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto init = auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error(); EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
@ -133,15 +132,14 @@ TEST_F(BuilderTest, GlobalVar_Const) {
ast::type::VectorType vec(&f32, 3); ast::type::VectorType vec(&f32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto init = auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error(); EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
@ -168,14 +166,13 @@ TEST_F(BuilderTest, GlobalVar_Complex_Constructor) {
ast::type::VectorType vec3(&f32, 3); ast::type::VectorType vec3(&f32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.0f))); create<ast::FloatLiteral>(&f32, 2.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto init = auto init = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error(); EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
@ -202,19 +199,17 @@ TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
ast::type::VectorType vec2(&f32, 2); ast::type::VectorType vec2(&f32, 2);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.0f))); create<ast::FloatLiteral>(&f32, 2.0f)));
auto first = auto first = create<ast::TypeConstructorExpression>(&vec2, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec2, std::move(vals));
vals.push_back(std::move(first)); vals.push_back(std::move(first));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto init = auto init = create<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error(); EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
@ -244,10 +239,9 @@ TEST_F(BuilderTest, GlobalVar_Complex_ConstructorWithExtract) {
TEST_F(BuilderTest, GlobalVar_WithLocation) { TEST_F(BuilderTest, GlobalVar_WithLocation) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto v = auto v = create<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
std::make_unique<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::LocationDecoration>(5, Source{})); decos.push_back(create<ast::LocationDecoration>(5, Source{}));
ast::DecoratedVariable dv(std::move(v)); ast::DecoratedVariable dv(std::move(v));
dv.set_decorations(std::move(decos)); dv.set_decorations(std::move(decos));
@ -266,11 +260,10 @@ TEST_F(BuilderTest, GlobalVar_WithLocation) {
TEST_F(BuilderTest, GlobalVar_WithBindingAndSet) { TEST_F(BuilderTest, GlobalVar_WithBindingAndSet) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto v = auto v = create<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
std::make_unique<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::BindingDecoration>(2, Source{})); decos.push_back(create<ast::BindingDecoration>(2, Source{}));
decos.push_back(std::make_unique<ast::SetDecoration>(3, Source{})); decos.push_back(create<ast::SetDecoration>(3, Source{}));
ast::DecoratedVariable dv(std::move(v)); ast::DecoratedVariable dv(std::move(v));
dv.set_decorations(std::move(decos)); dv.set_decorations(std::move(decos));
@ -290,11 +283,10 @@ OpDecorate %1 DescriptorSet 3
TEST_F(BuilderTest, GlobalVar_WithBuiltin) { TEST_F(BuilderTest, GlobalVar_WithBuiltin) {
ast::type::F32Type f32; ast::type::F32Type f32;
auto v = auto v = create<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
std::make_unique<ast::Variable>("var", ast::StorageClass::kOutput, &f32);
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::BuiltinDecoration>( decos.push_back(
ast::Builtin::kPosition, Source{})); create<ast::BuiltinDecoration>(ast::Builtin::kPosition, Source{}));
ast::DecoratedVariable dv(std::move(v)); ast::DecoratedVariable dv(std::move(v));
dv.set_decorations(std::move(decos)); dv.set_decorations(std::move(decos));
@ -315,13 +307,13 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool) {
ast::type::BoolType bool_type; ast::type::BoolType bool_type;
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(1200, Source{})); decos.push_back(create<ast::ConstantIdDecoration>(1200, Source{}));
ast::DecoratedVariable v(std::make_unique<ast::Variable>( ast::DecoratedVariable v(
"var", ast::StorageClass::kNone, &bool_type)); create<ast::Variable>("var", ast::StorageClass::kNone, &bool_type));
v.set_decorations(std::move(decos)); v.set_decorations(std::move(decos));
v.set_constructor(std::make_unique<ast::ScalarConstructorExpression>( v.set_constructor(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true))); create<ast::BoolLiteral>(&bool_type, true)));
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_766172" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_766172"
@ -339,10 +331,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Bool_NoConstructor) {
ast::type::BoolType bool_type; ast::type::BoolType bool_type;
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(1200, Source{})); decos.push_back(create<ast::ConstantIdDecoration>(1200, Source{}));
ast::DecoratedVariable v(std::make_unique<ast::Variable>( ast::DecoratedVariable v(
"var", ast::StorageClass::kNone, &bool_type)); create<ast::Variable>("var", ast::StorageClass::kNone, &bool_type));
v.set_decorations(std::move(decos)); v.set_decorations(std::move(decos));
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
@ -361,13 +353,13 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(0, Source{})); decos.push_back(create<ast::ConstantIdDecoration>(0, Source{}));
ast::DecoratedVariable v( ast::DecoratedVariable v(
std::make_unique<ast::Variable>("var", ast::StorageClass::kNone, &f32)); create<ast::Variable>("var", ast::StorageClass::kNone, &f32));
v.set_decorations(std::move(decos)); v.set_decorations(std::move(decos));
v.set_constructor(std::make_unique<ast::ScalarConstructorExpression>( v.set_constructor(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 2.0))); create<ast::FloatLiteral>(&f32, 2.0)));
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_766172" EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "tint_766172"
@ -385,10 +377,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_F32_NoConstructor) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(0, Source{})); decos.push_back(create<ast::ConstantIdDecoration>(0, Source{}));
ast::DecoratedVariable v( ast::DecoratedVariable v(
std::make_unique<ast::Variable>("var", ast::StorageClass::kNone, &f32)); create<ast::Variable>("var", ast::StorageClass::kNone, &f32));
v.set_decorations(std::move(decos)); v.set_decorations(std::move(decos));
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
@ -407,10 +399,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_I32_NoConstructor) {
ast::type::I32Type i32; ast::type::I32Type i32;
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(0, Source{})); decos.push_back(create<ast::ConstantIdDecoration>(0, Source{}));
ast::DecoratedVariable v( ast::DecoratedVariable v(
std::make_unique<ast::Variable>("var", ast::StorageClass::kNone, &i32)); create<ast::Variable>("var", ast::StorageClass::kNone, &i32));
v.set_decorations(std::move(decos)); v.set_decorations(std::move(decos));
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
@ -429,10 +421,10 @@ TEST_F(BuilderTest, GlobalVar_ConstantId_Scalar_U32_NoConstructor) {
ast::type::U32Type u32; ast::type::U32Type u32;
ast::VariableDecorationList decos; ast::VariableDecorationList decos;
decos.push_back(std::make_unique<ast::ConstantIdDecoration>(0, Source{})); decos.push_back(create<ast::ConstantIdDecoration>(0, Source{}));
ast::DecoratedVariable v( ast::DecoratedVariable v(
std::make_unique<ast::Variable>("var", ast::StorageClass::kNone, &u32)); create<ast::Variable>("var", ast::StorageClass::kNone, &u32));
v.set_decorations(std::move(decos)); v.set_decorations(std::move(decos));
EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error();
@ -491,13 +483,10 @@ TEST_F(BuilderTest, GlobalVar_DeclReadOnly) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
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))); members.push_back(create<ast::StructMember>("b", &i32, std::move(decos)));
members.push_back(
std::make_unique<ast::StructMember>("b", &i32, std::move(decos)));
ast::type::StructType A("A", ast::type::StructType A("A", create<ast::Struct>(std::move(members)));
std::make_unique<ast::Struct>(std::move(members)));
ast::type::AccessControlType ac{ast::AccessControl::kReadOnly, &A}; ast::type::AccessControlType ac{ast::AccessControl::kReadOnly, &A};
ast::Variable var("b", ast::StorageClass::kStorageBuffer, &ac); ast::Variable var("b", ast::StorageClass::kStorageBuffer, &ac);
@ -530,11 +519,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
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)));
ast::type::StructType A("A", ast::type::StructType A("A", create<ast::Struct>(std::move(members)));
std::make_unique<ast::Struct>(std::move(members)));
ast::type::AliasType B("B", &A); ast::type::AliasType B("B", &A);
ast::type::AccessControlType ac{ast::AccessControl::kReadOnly, &B}; ast::type::AccessControlType ac{ast::AccessControl::kReadOnly, &B};
@ -566,11 +553,9 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
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)));
ast::type::StructType A("A", ast::type::StructType A("A", create<ast::Struct>(std::move(members)));
std::make_unique<ast::Struct>(std::move(members)));
ast::type::AccessControlType ac{ast::AccessControl::kReadOnly, &A}; ast::type::AccessControlType ac{ast::AccessControl::kReadOnly, &A};
ast::type::AliasType B("B", &ac); ast::type::AliasType B("B", &ac);
@ -602,11 +587,9 @@ TEST_F(BuilderTest, GlobalVar_TwoVarDeclReadOnly) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
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)));
ast::type::StructType A("A", ast::type::StructType A("A", create<ast::Struct>(std::move(members)));
std::make_unique<ast::Struct>(std::move(members)));
ast::type::AccessControlType read{ast::AccessControl::kReadOnly, &A}; ast::type::AccessControlType read{ast::AccessControl::kReadOnly, &A};
ast::type::AccessControlType rw{ast::AccessControl::kReadWrite, &A}; ast::type::AccessControlType rw{ast::AccessControl::kReadWrite, &A};

View File

@ -43,15 +43,14 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
ast::type::VectorType vec(&f32, 3); ast::type::VectorType vec(&f32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto init = auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error(); EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
@ -103,15 +102,14 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
ast::type::VectorType vec(&f32, 3); ast::type::VectorType vec(&f32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto init = auto init = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error(); EXPECT_TRUE(td.DetermineResultType(init.get())) << td.error();
@ -167,8 +165,8 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
auto lhs = std::make_unique<ast::IdentifierExpression>("var"); auto lhs = create<ast::IdentifierExpression>("var");
auto rhs = std::make_unique<ast::IdentifierExpression>("var"); auto rhs = create<ast::IdentifierExpression>("var");
ast::BinaryExpression expr(ast::BinaryOp::kAdd, std::move(lhs), ast::BinaryExpression expr(ast::BinaryOp::kAdd, std::move(lhs),
std::move(rhs)); std::move(rhs));
@ -195,14 +193,14 @@ TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
ast::type::I32Type i32; ast::type::I32Type i32;
ast::Variable var("var", ast::StorageClass::kNone, &i32); ast::Variable var("var", ast::StorageClass::kNone, &i32);
var.set_constructor(std::make_unique<ast::ScalarConstructorExpression>( var.set_constructor(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2))); create<ast::SintLiteral>(&i32, 2)));
var.set_is_const(true); var.set_is_const(true);
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
auto lhs = std::make_unique<ast::IdentifierExpression>("var"); auto lhs = create<ast::IdentifierExpression>("var");
auto rhs = std::make_unique<ast::IdentifierExpression>("var"); auto rhs = create<ast::IdentifierExpression>("var");
ast::BinaryExpression expr(ast::BinaryOp::kAdd, std::move(lhs), ast::BinaryExpression expr(ast::BinaryOp::kAdd, std::move(lhs),
std::move(rhs)); std::move(rhs));

View File

@ -46,11 +46,10 @@ TEST_F(BuilderTest, If_Empty) {
// if (true) { // if (true) {
// } // }
auto cond = std::make_unique<ast::ScalarConstructorExpression>( auto cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
ast::IfStatement expr(std::move(cond), ast::IfStatement expr(std::move(cond), create<ast::BlockStatement>());
std::make_unique<ast::BlockStatement>());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -76,17 +75,16 @@ TEST_F(BuilderTest, If_WithStatements) {
// if (true) { // if (true) {
// v = 2; // v = 2;
// } // }
auto var = auto var = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto cond = std::make_unique<ast::ScalarConstructorExpression>( auto cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
ast::IfStatement expr(std::move(cond), std::move(body)); ast::IfStatement expr(std::move(cond), std::move(body));
@ -124,27 +122,25 @@ TEST_F(BuilderTest, If_WithElse) {
// } else { // } else {
// v = 3; // v = 3;
// } // }
auto var = auto var = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto else_body = std::make_unique<ast::BlockStatement>(); auto else_body = create<ast::BlockStatement>();
else_body->append(std::make_unique<ast::AssignmentStatement>( else_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
ast::ElseStatementList else_stmts; ast::ElseStatementList else_stmts;
else_stmts.push_back( else_stmts.push_back(create<ast::ElseStatement>(std::move(else_body)));
std::make_unique<ast::ElseStatement>(std::move(else_body)));
auto cond = std::make_unique<ast::ScalarConstructorExpression>( auto cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
ast::IfStatement expr(std::move(cond), std::move(body)); ast::IfStatement expr(std::move(cond), std::move(body));
expr.set_else_statements(std::move(else_stmts)); expr.set_else_statements(std::move(else_stmts));
@ -188,30 +184,29 @@ TEST_F(BuilderTest, If_WithElseIf) {
// } elseif (true) { // } elseif (true) {
// v = 3; // v = 3;
// } // }
auto var = auto var = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto else_body = std::make_unique<ast::BlockStatement>(); auto else_body = create<ast::BlockStatement>();
else_body->append(std::make_unique<ast::AssignmentStatement>( else_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
auto else_cond = std::make_unique<ast::ScalarConstructorExpression>( auto else_cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
ast::ElseStatementList else_stmts; ast::ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ast::ElseStatement>( else_stmts.push_back(
std::move(else_cond), std::move(else_body))); create<ast::ElseStatement>(std::move(else_cond), std::move(else_body)));
auto cond = std::make_unique<ast::ScalarConstructorExpression>( auto cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
ast::IfStatement expr(std::move(cond), std::move(body)); ast::IfStatement expr(std::move(cond), std::move(body));
expr.set_else_statements(std::move(else_stmts)); expr.set_else_statements(std::move(else_stmts));
@ -264,45 +259,43 @@ TEST_F(BuilderTest, If_WithMultiple) {
// } else { // } else {
// v = 5; // v = 5;
// } // }
auto var = auto var = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto elseif_1_body = std::make_unique<ast::BlockStatement>(); auto elseif_1_body = create<ast::BlockStatement>();
elseif_1_body->append(std::make_unique<ast::AssignmentStatement>( elseif_1_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
auto elseif_2_body = std::make_unique<ast::BlockStatement>(); auto elseif_2_body = create<ast::BlockStatement>();
elseif_2_body->append(std::make_unique<ast::AssignmentStatement>( elseif_2_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 4)))); create<ast::SintLiteral>(&i32, 4))));
auto else_body = std::make_unique<ast::BlockStatement>(); auto else_body = create<ast::BlockStatement>();
else_body->append(std::make_unique<ast::AssignmentStatement>( else_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 5)))); create<ast::SintLiteral>(&i32, 5))));
auto elseif_1_cond = std::make_unique<ast::ScalarConstructorExpression>( auto elseif_1_cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
auto elseif_2_cond = std::make_unique<ast::ScalarConstructorExpression>( auto elseif_2_cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, false)); create<ast::BoolLiteral>(&bool_type, false));
ast::ElseStatementList else_stmts; ast::ElseStatementList else_stmts;
else_stmts.push_back(std::make_unique<ast::ElseStatement>( else_stmts.push_back(create<ast::ElseStatement>(std::move(elseif_1_cond),
std::move(elseif_1_cond), std::move(elseif_1_body))); std::move(elseif_1_body)));
else_stmts.push_back(std::make_unique<ast::ElseStatement>( else_stmts.push_back(create<ast::ElseStatement>(std::move(elseif_2_cond),
std::move(elseif_2_cond), std::move(elseif_2_body))); std::move(elseif_2_body)));
else_stmts.push_back( else_stmts.push_back(create<ast::ElseStatement>(std::move(else_body)));
std::make_unique<ast::ElseStatement>(std::move(else_body)));
auto cond = std::make_unique<ast::ScalarConstructorExpression>( auto cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
ast::IfStatement expr(std::move(cond), std::move(body)); ast::IfStatement expr(std::move(cond), std::move(body));
expr.set_else_statements(std::move(else_stmts)); expr.set_else_statements(std::move(else_stmts));
@ -363,20 +356,18 @@ TEST_F(BuilderTest, If_WithBreak) {
// break; // break;
// } // }
// } // }
auto cond = std::make_unique<ast::ScalarConstructorExpression>( auto cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
auto if_body = std::make_unique<ast::BlockStatement>(); auto if_body = create<ast::BlockStatement>();
if_body->append(std::make_unique<ast::BreakStatement>()); if_body->append(create<ast::BreakStatement>());
auto if_stmt = auto if_stmt = create<ast::IfStatement>(std::move(cond), std::move(if_body));
std::make_unique<ast::IfStatement>(std::move(cond), std::move(if_body));
auto loop_body = std::make_unique<ast::BlockStatement>(); auto loop_body = create<ast::BlockStatement>();
loop_body->append(std::move(if_stmt)); loop_body->append(std::move(if_stmt));
ast::LoopStatement expr(std::move(loop_body), ast::LoopStatement expr(std::move(loop_body), create<ast::BlockStatement>());
std::make_unique<ast::BlockStatement>());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -412,25 +403,23 @@ TEST_F(BuilderTest, If_WithElseBreak) {
// break; // break;
// } // }
// } // }
auto cond = std::make_unique<ast::ScalarConstructorExpression>( auto cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
auto else_body = std::make_unique<ast::BlockStatement>(); auto else_body = create<ast::BlockStatement>();
else_body->append(std::make_unique<ast::BreakStatement>()); else_body->append(create<ast::BreakStatement>());
ast::ElseStatementList else_stmts; ast::ElseStatementList else_stmts;
else_stmts.push_back( else_stmts.push_back(create<ast::ElseStatement>(std::move(else_body)));
std::make_unique<ast::ElseStatement>(std::move(else_body)));
auto if_stmt = std::make_unique<ast::IfStatement>( auto if_stmt =
std::move(cond), std::make_unique<ast::BlockStatement>()); create<ast::IfStatement>(std::move(cond), create<ast::BlockStatement>());
if_stmt->set_else_statements(std::move(else_stmts)); if_stmt->set_else_statements(std::move(else_stmts));
auto loop_body = std::make_unique<ast::BlockStatement>(); auto loop_body = create<ast::BlockStatement>();
loop_body->append(std::move(if_stmt)); loop_body->append(std::move(if_stmt));
ast::LoopStatement expr(std::move(loop_body), ast::LoopStatement expr(std::move(loop_body), create<ast::BlockStatement>());
std::make_unique<ast::BlockStatement>());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -467,20 +456,18 @@ TEST_F(BuilderTest, If_WithContinue) {
// continue; // continue;
// } // }
// } // }
auto cond = std::make_unique<ast::ScalarConstructorExpression>( auto cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
auto if_body = std::make_unique<ast::BlockStatement>(); auto if_body = create<ast::BlockStatement>();
if_body->append(std::make_unique<ast::ContinueStatement>()); if_body->append(create<ast::ContinueStatement>());
auto if_stmt = auto if_stmt = create<ast::IfStatement>(std::move(cond), std::move(if_body));
std::make_unique<ast::IfStatement>(std::move(cond), std::move(if_body));
auto loop_body = std::make_unique<ast::BlockStatement>(); auto loop_body = create<ast::BlockStatement>();
loop_body->append(std::move(if_stmt)); loop_body->append(std::move(if_stmt));
ast::LoopStatement expr(std::move(loop_body), ast::LoopStatement expr(std::move(loop_body), create<ast::BlockStatement>());
std::make_unique<ast::BlockStatement>());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -516,25 +503,23 @@ TEST_F(BuilderTest, If_WithElseContinue) {
// continue; // continue;
// } // }
// } // }
auto cond = std::make_unique<ast::ScalarConstructorExpression>( auto cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
auto else_body = std::make_unique<ast::BlockStatement>(); auto else_body = create<ast::BlockStatement>();
else_body->append(std::make_unique<ast::ContinueStatement>()); else_body->append(create<ast::ContinueStatement>());
ast::ElseStatementList else_stmts; ast::ElseStatementList else_stmts;
else_stmts.push_back( else_stmts.push_back(create<ast::ElseStatement>(std::move(else_body)));
std::make_unique<ast::ElseStatement>(std::move(else_body)));
auto if_stmt = std::make_unique<ast::IfStatement>( auto if_stmt =
std::move(cond), std::make_unique<ast::BlockStatement>()); create<ast::IfStatement>(std::move(cond), create<ast::BlockStatement>());
if_stmt->set_else_statements(std::move(else_stmts)); if_stmt->set_else_statements(std::move(else_stmts));
auto loop_body = std::make_unique<ast::BlockStatement>(); auto loop_body = create<ast::BlockStatement>();
loop_body->append(std::move(if_stmt)); loop_body->append(std::move(if_stmt));
ast::LoopStatement expr(std::move(loop_body), ast::LoopStatement expr(std::move(loop_body), create<ast::BlockStatement>());
std::make_unique<ast::BlockStatement>());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -569,11 +554,11 @@ TEST_F(BuilderTest, If_WithReturn) {
// if (true) { // if (true) {
// return; // return;
// } // }
auto cond = std::make_unique<ast::ScalarConstructorExpression>( auto cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
auto if_body = std::make_unique<ast::BlockStatement>(); auto if_body = create<ast::BlockStatement>();
if_body->append(std::make_unique<ast::ReturnStatement>()); if_body->append(create<ast::ReturnStatement>());
ast::IfStatement expr(std::move(cond), std::move(if_body)); ast::IfStatement expr(std::move(cond), std::move(if_body));
@ -599,13 +584,13 @@ TEST_F(BuilderTest, If_WithReturnValue) {
// if (true) { // if (true) {
// return false; // return false;
// } // }
auto cond = std::make_unique<ast::ScalarConstructorExpression>( auto cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)); create<ast::BoolLiteral>(&bool_type, true));
auto cond2 = std::make_unique<ast::ScalarConstructorExpression>( auto cond2 = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, false)); create<ast::BoolLiteral>(&bool_type, false));
auto if_body = std::make_unique<ast::BlockStatement>(); auto if_body = create<ast::BlockStatement>();
if_body->append(std::make_unique<ast::ReturnStatement>(std::move(cond2))); if_body->append(create<ast::ReturnStatement>(std::move(cond2)));
ast::IfStatement expr(std::move(cond), std::move(if_body)); ast::IfStatement expr(std::move(cond), std::move(if_body));

View File

@ -64,6 +64,13 @@ class IntrinsicBuilderTest : public ast::Builder, public testing::Test {
return var; return var;
} }
/// @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)...);
}
Context ctx; Context ctx;
ast::Module mod; ast::Module mod;
TypeDeterminer td{&ctx, &mod}; TypeDeterminer td{&ctx, &mod};
@ -1706,16 +1713,14 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back( members.push_back(create<ast::StructMember>("a", &ary, std::move(decos)));
std::make_unique<ast::StructMember>("a", &ary, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("my_struct", std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
auto var = make_var("b", ast::StorageClass::kPrivate, &s_type); auto var = make_var("b", ast::StorageClass::kPrivate, &s_type);
auto expr = auto expr = call_expr("arrayLength", create<ast::MemberAccessorExpression>(
call_expr("arrayLength", std::make_unique<ast::MemberAccessorExpression>(
make_expr("b"), make_expr("a"))); make_expr("b"), make_expr("a")));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -1748,17 +1753,14 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength_OtherMembersInStruct) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back( members.push_back(create<ast::StructMember>("z", f32(), std::move(decos)));
std::make_unique<ast::StructMember>("z", f32(), std::move(decos))); members.push_back(create<ast::StructMember>("a", &ary, std::move(decos)));
members.push_back(
std::make_unique<ast::StructMember>("a", &ary, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("my_struct", std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
auto var = make_var("b", ast::StorageClass::kPrivate, &s_type); auto var = make_var("b", ast::StorageClass::kPrivate, &s_type);
auto expr = auto expr = call_expr("arrayLength", create<ast::MemberAccessorExpression>(
call_expr("arrayLength", std::make_unique<ast::MemberAccessorExpression>(
make_expr("b"), make_expr("a"))); make_expr("b"), make_expr("a")));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -1793,19 +1795,17 @@ TEST_F(IntrinsicBuilderTest, DISABLED_Call_ArrayLength_Ptr) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back( members.push_back(create<ast::StructMember>("z", f32(), std::move(decos)));
std::make_unique<ast::StructMember>("z", f32(), std::move(decos))); members.push_back(create<ast::StructMember>("a", &ary, std::move(decos)));
members.push_back(
std::make_unique<ast::StructMember>("a", &ary, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("my_struct", std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
auto var = make_var("b", ast::StorageClass::kPrivate, &s_type); auto var = make_var("b", ast::StorageClass::kPrivate, &s_type);
auto ptr_var = make_var("ptr_var", ast::StorageClass::kPrivate, &ptr); auto ptr_var = make_var("ptr_var", ast::StorageClass::kPrivate, &ptr);
ptr_var->set_constructor(std::make_unique<ast::MemberAccessorExpression>( ptr_var->set_constructor(
make_expr("b"), make_expr("a"))); create<ast::MemberAccessorExpression>(make_expr("b"), make_expr("a")));
auto expr = call_expr("arrayLength", "ptr_var"); auto expr = call_expr("arrayLength", "ptr_var");
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();

View File

@ -65,17 +65,15 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
// loop { // loop {
// v = 2; // v = 2;
// } // }
auto var = auto var = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
ast::LoopStatement expr(std::move(body), ast::LoopStatement expr(std::move(body), create<ast::BlockStatement>());
std::make_unique<ast::BlockStatement>());
td.RegisterVariableForTesting(var.get()); td.RegisterVariableForTesting(var.get());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -113,20 +111,19 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
// } // }
// } // }
auto var = auto var = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::AssignmentStatement>( body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto continuing = std::make_unique<ast::BlockStatement>(); auto continuing = create<ast::BlockStatement>();
continuing->append(std::make_unique<ast::AssignmentStatement>( continuing->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
ast::LoopStatement expr(std::move(body), std::move(continuing)); ast::LoopStatement expr(std::move(body), std::move(continuing));
td.RegisterVariableForTesting(var.get()); td.RegisterVariableForTesting(var.get());
@ -162,11 +159,10 @@ TEST_F(BuilderTest, Loop_WithContinue) {
// loop { // loop {
// continue; // continue;
// } // }
auto body = std::make_unique<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(std::make_unique<ast::ContinueStatement>()); body->append(create<ast::ContinueStatement>());
ast::LoopStatement expr(std::move(body), ast::LoopStatement expr(std::move(body), create<ast::BlockStatement>());
std::make_unique<ast::BlockStatement>());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -190,11 +186,10 @@ TEST_F(BuilderTest, Loop_WithBreak) {
// loop { // loop {
// break; // break;
// } // }
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::LoopStatement expr(std::move(body), ast::LoopStatement expr(std::move(body), create<ast::BlockStatement>());
std::make_unique<ast::BlockStatement>());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();

View File

@ -51,15 +51,14 @@ TEST_F(BuilderTest, Return_WithValue) {
ast::type::VectorType vec(&f32, 3); ast::type::VectorType vec(&f32, 3);
ast::ExpressionList vals; ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.0f))); create<ast::FloatLiteral>(&f32, 1.0f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>( vals.push_back(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 3.0f))); create<ast::FloatLiteral>(&f32, 3.0f)));
auto val = auto val = create<ast::TypeConstructorExpression>(&vec, std::move(vals));
std::make_unique<ast::TypeConstructorExpression>(&vec, std::move(vals));
ast::ReturnStatement ret(std::move(val)); ast::ReturnStatement ret(std::move(val));
@ -85,8 +84,7 @@ TEST_F(BuilderTest, Return_WithValue_GeneratesLoad) {
ast::Variable var("param", ast::StorageClass::kFunction, &f32); ast::Variable var("param", ast::StorageClass::kFunction, &f32);
ast::ReturnStatement ret( ast::ReturnStatement ret(create<ast::IdentifierExpression>("param"));
std::make_unique<ast::IdentifierExpression>("param"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error(); EXPECT_TRUE(td.DetermineResultType(&ret)) << td.error();

View File

@ -45,8 +45,8 @@ TEST_F(BuilderTest, Switch_Empty) {
// switch (1) { // switch (1) {
// } // }
auto cond = std::make_unique<ast::ScalarConstructorExpression>( auto cond = create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1)); create<ast::SintLiteral>(&i32, 1));
ast::SwitchStatement expr(std::move(cond), ast::CaseStatementList{}); ast::SwitchStatement expr(std::move(cond), ast::CaseStatementList{});
@ -77,36 +77,34 @@ TEST_F(BuilderTest, Switch_WithCase) {
// v = 2; // v = 2;
// } // }
auto v = auto v = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32); auto a = create<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
auto a =
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
auto case_1_body = std::make_unique<ast::BlockStatement>(); auto case_1_body = create<ast::BlockStatement>();
case_1_body->append(std::make_unique<ast::AssignmentStatement>( case_1_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
auto case_2_body = std::make_unique<ast::BlockStatement>(); auto case_2_body = create<ast::BlockStatement>();
case_2_body->append(std::make_unique<ast::AssignmentStatement>( case_2_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
ast::CaseSelectorList selector_1; ast::CaseSelectorList selector_1;
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1)); selector_1.push_back(create<ast::SintLiteral>(&i32, 1));
ast::CaseSelectorList selector_2; ast::CaseSelectorList selector_2;
selector_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 2)); selector_2.push_back(create<ast::SintLiteral>(&i32, 2));
ast::CaseStatementList cases; ast::CaseStatementList cases;
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1), cases.push_back(create<ast::CaseStatement>(std::move(selector_1),
std::move(case_1_body))); std::move(case_1_body)));
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_2), cases.push_back(create<ast::CaseStatement>(std::move(selector_2),
std::move(case_2_body))); std::move(case_2_body)));
ast::SwitchStatement expr(std::make_unique<ast::IdentifierExpression>("a"), ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"),
std::move(cases)); std::move(cases));
td.RegisterVariableForTesting(v.get()); td.RegisterVariableForTesting(v.get());
@ -158,22 +156,19 @@ TEST_F(BuilderTest, Switch_WithDefault) {
// v = 1; // v = 1;
// } // }
auto v = auto v = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32); auto a = create<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
auto a =
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
auto default_body = std::make_unique<ast::BlockStatement>(); auto default_body = create<ast::BlockStatement>();
default_body->append(std::make_unique<ast::AssignmentStatement>( default_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
ast::CaseStatementList cases; ast::CaseStatementList cases;
cases.push_back( cases.push_back(create<ast::CaseStatement>(std::move(default_body)));
std::make_unique<ast::CaseStatement>(std::move(default_body)));
ast::SwitchStatement expr(std::make_unique<ast::IdentifierExpression>("a"), ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"),
std::move(cases)); std::move(cases));
td.RegisterVariableForTesting(v.get()); td.RegisterVariableForTesting(v.get());
@ -223,45 +218,42 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) {
// v = 3; // v = 3;
// } // }
auto v = auto v = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32); auto a = create<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
auto a =
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
auto case_1_body = std::make_unique<ast::BlockStatement>(); auto case_1_body = create<ast::BlockStatement>();
case_1_body->append(std::make_unique<ast::AssignmentStatement>( case_1_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
auto case_2_body = std::make_unique<ast::BlockStatement>(); auto case_2_body = create<ast::BlockStatement>();
case_2_body->append(std::make_unique<ast::AssignmentStatement>( case_2_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto default_body = std::make_unique<ast::BlockStatement>(); auto default_body = create<ast::BlockStatement>();
default_body->append(std::make_unique<ast::AssignmentStatement>( default_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
ast::CaseSelectorList selector_1; ast::CaseSelectorList selector_1;
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1)); selector_1.push_back(create<ast::SintLiteral>(&i32, 1));
ast::CaseSelectorList selector_2; ast::CaseSelectorList selector_2;
selector_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 2)); selector_2.push_back(create<ast::SintLiteral>(&i32, 2));
selector_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 3)); selector_2.push_back(create<ast::SintLiteral>(&i32, 3));
ast::CaseStatementList cases; ast::CaseStatementList cases;
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1), cases.push_back(create<ast::CaseStatement>(std::move(selector_1),
std::move(case_1_body))); std::move(case_1_body)));
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_2), cases.push_back(create<ast::CaseStatement>(std::move(selector_2),
std::move(case_2_body))); std::move(case_2_body)));
cases.push_back( cases.push_back(create<ast::CaseStatement>(std::move(default_body)));
std::make_unique<ast::CaseStatement>(std::move(default_body)));
ast::SwitchStatement expr(std::make_unique<ast::IdentifierExpression>("a"), ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"),
std::move(cases)); std::move(cases));
td.RegisterVariableForTesting(v.get()); td.RegisterVariableForTesting(v.get());
@ -320,45 +312,42 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) {
// v = 3; // v = 3;
// } // }
auto v = auto v = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32); auto a = create<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
auto a =
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
auto case_1_body = std::make_unique<ast::BlockStatement>(); auto case_1_body = create<ast::BlockStatement>();
case_1_body->append(std::make_unique<ast::AssignmentStatement>( case_1_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
case_1_body->append(std::make_unique<ast::FallthroughStatement>()); case_1_body->append(create<ast::FallthroughStatement>());
auto case_2_body = std::make_unique<ast::BlockStatement>(); auto case_2_body = create<ast::BlockStatement>();
case_2_body->append(std::make_unique<ast::AssignmentStatement>( case_2_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 2)))); create<ast::SintLiteral>(&i32, 2))));
auto default_body = std::make_unique<ast::BlockStatement>(); auto default_body = create<ast::BlockStatement>();
default_body->append(std::make_unique<ast::AssignmentStatement>( default_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 3)))); create<ast::SintLiteral>(&i32, 3))));
ast::CaseSelectorList selector_1; ast::CaseSelectorList selector_1;
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1)); selector_1.push_back(create<ast::SintLiteral>(&i32, 1));
ast::CaseSelectorList selector_2; ast::CaseSelectorList selector_2;
selector_2.push_back(std::make_unique<ast::SintLiteral>(&i32, 2)); selector_2.push_back(create<ast::SintLiteral>(&i32, 2));
ast::CaseStatementList cases; ast::CaseStatementList cases;
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1), cases.push_back(create<ast::CaseStatement>(std::move(selector_1),
std::move(case_1_body))); std::move(case_1_body)));
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_2), cases.push_back(create<ast::CaseStatement>(std::move(selector_2),
std::move(case_2_body))); std::move(case_2_body)));
cases.push_back( cases.push_back(create<ast::CaseStatement>(std::move(default_body)));
std::make_unique<ast::CaseStatement>(std::move(default_body)));
ast::SwitchStatement expr(std::make_unique<ast::IdentifierExpression>("a"), ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"),
std::move(cases)); std::move(cases));
td.RegisterVariableForTesting(v.get()); td.RegisterVariableForTesting(v.get());
@ -413,26 +402,24 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) {
// fallthrough; // fallthrough;
// } // }
auto v = auto v = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32); auto a = create<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
auto a =
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
auto case_1_body = std::make_unique<ast::BlockStatement>(); auto case_1_body = create<ast::BlockStatement>();
case_1_body->append(std::make_unique<ast::AssignmentStatement>( case_1_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
case_1_body->append(std::make_unique<ast::FallthroughStatement>()); case_1_body->append(create<ast::FallthroughStatement>());
ast::CaseSelectorList selector_1; ast::CaseSelectorList selector_1;
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1)); selector_1.push_back(create<ast::SintLiteral>(&i32, 1));
ast::CaseStatementList cases; ast::CaseStatementList cases;
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1), cases.push_back(create<ast::CaseStatement>(std::move(selector_1),
std::move(case_1_body))); std::move(case_1_body)));
ast::SwitchStatement expr(std::make_unique<ast::IdentifierExpression>("a"), ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"),
std::move(cases)); std::move(cases));
td.RegisterVariableForTesting(v.get()); td.RegisterVariableForTesting(v.get());
@ -461,33 +448,31 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) {
// v = 1; // v = 1;
// } // }
auto v = auto v = create<ast::Variable>("v", ast::StorageClass::kPrivate, &i32);
std::make_unique<ast::Variable>("v", ast::StorageClass::kPrivate, &i32); auto a = create<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
auto a =
std::make_unique<ast::Variable>("a", ast::StorageClass::kPrivate, &i32);
auto if_body = std::make_unique<ast::BlockStatement>(); auto if_body = create<ast::BlockStatement>();
if_body->append(std::make_unique<ast::BreakStatement>()); if_body->append(create<ast::BreakStatement>());
auto case_1_body = std::make_unique<ast::BlockStatement>(); auto case_1_body = create<ast::BlockStatement>();
case_1_body->append(std::make_unique<ast::IfStatement>( case_1_body->append(
std::make_unique<ast::ScalarConstructorExpression>( create<ast::IfStatement>(create<ast::ScalarConstructorExpression>(
std::make_unique<ast::BoolLiteral>(&bool_type, true)), create<ast::BoolLiteral>(&bool_type, true)),
std::move(if_body))); std::move(if_body)));
case_1_body->append(std::make_unique<ast::AssignmentStatement>( case_1_body->append(
std::make_unique<ast::IdentifierExpression>("v"), create<ast::AssignmentStatement>(create<ast::IdentifierExpression>("v"),
std::make_unique<ast::ScalarConstructorExpression>( create<ast::ScalarConstructorExpression>(
std::make_unique<ast::SintLiteral>(&i32, 1)))); create<ast::SintLiteral>(&i32, 1))));
ast::CaseSelectorList selector_1; ast::CaseSelectorList selector_1;
selector_1.push_back(std::make_unique<ast::SintLiteral>(&i32, 1)); selector_1.push_back(create<ast::SintLiteral>(&i32, 1));
ast::CaseStatementList cases; ast::CaseStatementList cases;
cases.push_back(std::make_unique<ast::CaseStatement>(std::move(selector_1), cases.push_back(create<ast::CaseStatement>(std::move(selector_1),
std::move(case_1_body))); std::move(case_1_body)));
ast::SwitchStatement expr(std::make_unique<ast::IdentifierExpression>("a"), ast::SwitchStatement expr(create<ast::IdentifierExpression>("a"),
std::move(cases)); std::move(cases));
td.RegisterVariableForTesting(v.get()); td.RegisterVariableForTesting(v.get());

View File

@ -124,7 +124,7 @@ TEST_F(BuilderTest_Type, GenerateArray_WithStride) {
ast::type::I32Type i32; ast::type::I32Type i32;
ast::ArrayDecorationList decos; ast::ArrayDecorationList decos;
decos.push_back(std::make_unique<ast::StrideDecoration>(16u, Source{})); decos.push_back(create<ast::StrideDecoration>(16u, Source{}));
ast::type::ArrayType ary(&i32, 4); ast::type::ArrayType ary(&i32, 4);
ary.set_decorations(std::move(decos)); ary.set_decorations(std::move(decos));
@ -279,7 +279,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedPtr) {
} }
TEST_F(BuilderTest_Type, GenerateStruct_Empty) { TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
auto s = std::make_unique<ast::Struct>(); auto s = create<ast::Struct>();
ast::type::StructType s_type("S", std::move(s)); ast::type::StructType s_type("S", std::move(s));
auto id = b.GenerateTypeIfNeeded(&s_type); auto id = b.GenerateTypeIfNeeded(&s_type);
@ -298,10 +298,9 @@ TEST_F(BuilderTest_Type, GenerateStruct) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back( members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
std::make_unique<ast::StructMember>("a", &f32, std::move(decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("my_struct", std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
auto id = b.GenerateTypeIfNeeded(&s_type); auto id = b.GenerateTypeIfNeeded(&s_type);
@ -321,15 +320,12 @@ TEST_F(BuilderTest_Type, GenerateStruct_Decorated) {
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back( members.push_back(create<ast::StructMember>("a", &f32, std::move(decos)));
std::make_unique<ast::StructMember>("a", &f32, std::move(decos)));
ast::StructDecorationList struct_decos; ast::StructDecorationList struct_decos;
struct_decos.push_back( struct_decos.push_back(create<ast::StructBlockDecoration>(Source{}));
std::make_unique<ast::StructBlockDecoration>(Source{}));
auto s = std::make_unique<ast::Struct>(std::move(struct_decos), auto s = create<ast::Struct>(std::move(struct_decos), std::move(members));
std::move(members));
ast::type::StructType s_type("my_struct", std::move(s)); ast::type::StructType s_type("my_struct", std::move(s));
auto id = b.GenerateTypeIfNeeded(&s_type); auto id = b.GenerateTypeIfNeeded(&s_type);
@ -350,19 +346,15 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::StructMemberDecorationList a_decos; ast::StructMemberDecorationList a_decos;
a_decos.push_back( a_decos.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(0, Source{}));
ast::StructMemberDecorationList b_decos; ast::StructMemberDecorationList b_decos;
b_decos.push_back( b_decos.push_back(create<ast::StructMemberOffsetDecoration>(8, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(8, Source{}));
ast::StructMemberList members; ast::StructMemberList members;
members.push_back( members.push_back(create<ast::StructMember>("a", &f32, std::move(a_decos)));
std::make_unique<ast::StructMember>("a", &f32, std::move(a_decos))); members.push_back(create<ast::StructMember>("b", &f32, std::move(b_decos)));
members.push_back(
std::make_unique<ast::StructMember>("b", &f32, std::move(b_decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("S", std::move(s)); ast::type::StructType s_type("S", std::move(s));
auto id = b.GenerateTypeIfNeeded(&s_type); auto id = b.GenerateTypeIfNeeded(&s_type);
@ -392,14 +384,14 @@ TEST_F(BuilderTest_Type, GenerateStruct_NonLayout_Matrix) {
ast::StructMemberDecorationList empty_b; ast::StructMemberDecorationList empty_b;
ast::StructMemberDecorationList empty_c; ast::StructMemberDecorationList empty_c;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(std::make_unique<ast::StructMember>("a", &glsl_mat2x2, members.push_back(
std::move(empty_a))); create<ast::StructMember>("a", &glsl_mat2x2, std::move(empty_a)));
members.push_back(std::make_unique<ast::StructMember>("b", &glsl_mat2x3, members.push_back(
std::move(empty_b))); create<ast::StructMember>("b", &glsl_mat2x3, std::move(empty_b)));
members.push_back(std::make_unique<ast::StructMember>("c", &glsl_mat4x4, members.push_back(
std::move(empty_c))); create<ast::StructMember>("c", &glsl_mat4x4, std::move(empty_c)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("S", std::move(s)); ast::type::StructType s_type("S", std::move(s));
auto id = b.GenerateTypeIfNeeded(&s_type); auto id = b.GenerateTypeIfNeeded(&s_type);
@ -431,24 +423,21 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutMatrix) {
ast::type::MatrixType glsl_mat4x4(&f32, 4, 4); ast::type::MatrixType glsl_mat4x4(&f32, 4, 4);
ast::StructMemberDecorationList a_decos; ast::StructMemberDecorationList a_decos;
a_decos.push_back( a_decos.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(0, Source{}));
ast::StructMemberDecorationList b_decos; ast::StructMemberDecorationList b_decos;
b_decos.push_back( b_decos.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(16, Source{}));
ast::StructMemberDecorationList c_decos; ast::StructMemberDecorationList c_decos;
c_decos.push_back( c_decos.push_back(create<ast::StructMemberOffsetDecoration>(48, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(48, Source{}));
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(std::make_unique<ast::StructMember>("a", &glsl_mat2x2, members.push_back(
std::move(a_decos))); create<ast::StructMember>("a", &glsl_mat2x2, std::move(a_decos)));
members.push_back(std::make_unique<ast::StructMember>("b", &glsl_mat2x3, members.push_back(
std::move(b_decos))); create<ast::StructMember>("b", &glsl_mat2x3, std::move(b_decos)));
members.push_back(std::make_unique<ast::StructMember>("c", &glsl_mat4x4, members.push_back(
std::move(c_decos))); create<ast::StructMember>("c", &glsl_mat4x4, std::move(c_decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("S", std::move(s)); ast::type::StructType s_type("S", std::move(s));
auto id = b.GenerateTypeIfNeeded(&s_type); auto id = b.GenerateTypeIfNeeded(&s_type);
@ -498,24 +487,21 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_LayoutArraysOfMatrix) {
ast::type::ArrayType rtarr_mat4x4(&glsl_mat4x4); // Runtime array ast::type::ArrayType rtarr_mat4x4(&glsl_mat4x4); // Runtime array
ast::StructMemberDecorationList a_decos; ast::StructMemberDecorationList a_decos;
a_decos.push_back( a_decos.push_back(create<ast::StructMemberOffsetDecoration>(0, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(0, Source{}));
ast::StructMemberDecorationList b_decos; ast::StructMemberDecorationList b_decos;
b_decos.push_back( b_decos.push_back(create<ast::StructMemberOffsetDecoration>(16, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(16, Source{}));
ast::StructMemberDecorationList c_decos; ast::StructMemberDecorationList c_decos;
c_decos.push_back( c_decos.push_back(create<ast::StructMemberOffsetDecoration>(48, Source{}));
std::make_unique<ast::StructMemberOffsetDecoration>(48, Source{}));
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(std::make_unique<ast::StructMember>("a", &glsl_mat2x2, members.push_back(
std::move(a_decos))); create<ast::StructMember>("a", &glsl_mat2x2, std::move(a_decos)));
members.push_back(std::make_unique<ast::StructMember>("b", &glsl_mat2x3, members.push_back(
std::move(b_decos))); create<ast::StructMember>("b", &glsl_mat2x3, std::move(b_decos)));
members.push_back(std::make_unique<ast::StructMember>("c", &glsl_mat4x4, members.push_back(
std::move(c_decos))); create<ast::StructMember>("c", &glsl_mat4x4, std::move(c_decos)));
auto s = std::make_unique<ast::Struct>(std::move(members)); auto s = create<ast::Struct>(std::move(members));
ast::type::StructType s_type("S", std::move(s)); ast::type::StructType s_type("S", std::move(s));
auto id = b.GenerateTypeIfNeeded(&s_type); auto id = b.GenerateTypeIfNeeded(&s_type);

View File

@ -41,10 +41,9 @@ using BuilderTest = TestHelper;
TEST_F(BuilderTest, UnaryOp_Negation_Integer) { TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
ast::type::I32Type i32; ast::type::I32Type i32;
ast::UnaryOpExpression expr( ast::UnaryOpExpression expr(ast::UnaryOp::kNegation,
ast::UnaryOp::kNegation, create<ast::ScalarConstructorExpression>(
std::make_unique<ast::ScalarConstructorExpression>( create<ast::SintLiteral>(&i32, 1)));
std::make_unique<ast::SintLiteral>(&i32, 1)));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -61,10 +60,9 @@ TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
TEST_F(BuilderTest, UnaryOp_Negation_Float) { TEST_F(BuilderTest, UnaryOp_Negation_Float) {
ast::type::F32Type f32; ast::type::F32Type f32;
ast::UnaryOpExpression expr( ast::UnaryOpExpression expr(ast::UnaryOp::kNegation,
ast::UnaryOp::kNegation, create<ast::ScalarConstructorExpression>(
std::make_unique<ast::ScalarConstructorExpression>( create<ast::FloatLiteral>(&f32, 1)));
std::make_unique<ast::FloatLiteral>(&f32, 1)));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -81,10 +79,9 @@ TEST_F(BuilderTest, UnaryOp_Negation_Float) {
TEST_F(BuilderTest, UnaryOp_Not) { TEST_F(BuilderTest, UnaryOp_Not) {
ast::type::BoolType bool_type; ast::type::BoolType bool_type;
ast::UnaryOpExpression expr( ast::UnaryOpExpression expr(ast::UnaryOp::kNot,
ast::UnaryOp::kNot, create<ast::ScalarConstructorExpression>(
std::make_unique<ast::ScalarConstructorExpression>( create<ast::BoolLiteral>(&bool_type, false)));
std::make_unique<ast::BoolLiteral>(&bool_type, false)));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@ -104,9 +101,8 @@ TEST_F(BuilderTest, UnaryOp_LoadRequired) {
ast::Variable var("param", ast::StorageClass::kFunction, &vec); ast::Variable var("param", ast::StorageClass::kFunction, &vec);
ast::UnaryOpExpression expr( ast::UnaryOpExpression expr(ast::UnaryOp::kNegation,
ast::UnaryOp::kNegation, create<ast::IdentifierExpression>("param"));
std::make_unique<ast::IdentifierExpression>("param"));
td.RegisterVariableForTesting(&var); td.RegisterVariableForTesting(&var);
EXPECT_TRUE(td.DetermineResultType(&expr)) << td.error(); EXPECT_TRUE(td.DetermineResultType(&expr)) << td.error();

View File

@ -15,6 +15,9 @@
#ifndef SRC_WRITER_SPIRV_TEST_HELPER_H_ #ifndef SRC_WRITER_SPIRV_TEST_HELPER_H_
#define SRC_WRITER_SPIRV_TEST_HELPER_H_ #define SRC_WRITER_SPIRV_TEST_HELPER_H_
#include <memory>
#include <utility>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/module.h" #include "src/ast/module.h"
#include "src/context.h" #include "src/context.h"
@ -26,12 +29,19 @@ namespace writer {
namespace spirv { namespace spirv {
/// Helper class for testing /// Helper class for testing
template <typename T> template <typename BASE>
class TestHelperBase : public T { class TestHelperBase : public BASE {
public: public:
TestHelperBase() : td(&ctx, &mod), b(&ctx, &mod) {} TestHelperBase() : td(&ctx, &mod), b(&ctx, &mod) {}
~TestHelperBase() = default; ~TestHelperBase() = default;
/// @return a `std::unique_ptr` to a new `T` constructed with `args`
/// @param args the arguments to forward to the constructor for `T`
template <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