Start cleaning up tests (5/N)

Remove Source{} with ast::Builder::create<>
Use Builder helpers where possible

Change-Id: Ife7da25a4171cce404d496cb63acc34522316d81
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35742
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-12-15 14:11:48 +00:00 committed by Commit Bot service account
parent 7e805ba44a
commit 9df857de9a
30 changed files with 1272 additions and 3271 deletions

View File

@ -29,8 +29,7 @@ namespace {
using HlslGeneratorImplTest_Alias = TestHelper; using HlslGeneratorImplTest_Alias = TestHelper;
TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_F32) { TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_F32) {
ast::type::F32 f32; ast::type::Alias alias(mod->RegisterSymbol("a"), "a", ty.f32);
ast::type::Alias alias(mod.RegisterSymbol("a"), "a", &f32);
ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error(); ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error();
EXPECT_EQ(result(), R"(typedef float a; EXPECT_EQ(result(), R"(typedef float a;
@ -38,8 +37,7 @@ TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_F32) {
} }
TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_NameCollision) { TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_NameCollision) {
ast::type::F32 f32; ast::type::Alias alias(mod->RegisterSymbol("float"), "float", ty.f32);
ast::type::Alias alias(mod.RegisterSymbol("float"), "float", &f32);
ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error(); ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error();
EXPECT_EQ(result(), R"(typedef float float_tint_0; EXPECT_EQ(result(), R"(typedef float float_tint_0;
@ -47,23 +45,20 @@ TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_NameCollision) {
} }
TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_Struct) { TEST_F(HlslGeneratorImplTest_Alias, EmitAlias_Struct) {
ast::type::I32 i32;
ast::type::F32 f32;
auto* str = create<ast::Struct>( auto* str = create<ast::Struct>(
Source{},
ast::StructMemberList{ ast::StructMemberList{
create<ast::StructMember>(Source{}, "a", &f32, create<ast::StructMember>("a", ty.f32,
ast::StructMemberDecorationList{}), ast::StructMemberDecorationList{}),
create<ast::StructMember>( create<ast::StructMember>(
Source{}, "b", &i32, "b", ty.i32,
ast::StructMemberDecorationList{ ast::StructMemberDecorationList{
create<ast::StructMemberOffsetDecoration>(Source{}, 4)}), create<ast::StructMemberOffsetDecoration>(4)}),
}, },
ast::StructDecorationList{}); ast::StructDecorationList{});
ast::type::Struct s(mod.RegisterSymbol("A"), "A", str); ast::type::Struct s(mod->RegisterSymbol("A"), "A", str);
ast::type::Alias alias(mod.RegisterSymbol("B"), "B", &s); ast::type::Alias alias(mod->RegisterSymbol("B"), "B", &s);
ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error(); ASSERT_TRUE(gen.EmitConstructedType(out, &alias)) << gen.error();
EXPECT_EQ(result(), R"(struct B { EXPECT_EQ(result(), R"(struct B {

View File

@ -30,27 +30,16 @@ namespace {
using HlslGeneratorImplTest_Expression = TestHelper; using HlslGeneratorImplTest_Expression = TestHelper;
TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) { TEST_F(HlslGeneratorImplTest_Expression, EmitExpression_ArrayAccessor) {
ast::type::I32 i32; auto* expr = Index("ary", 5);
auto* lit = create<ast::SintLiteral>(Source{}, &i32, 5);
auto* idx = create<ast::ScalarConstructorExpression>(Source{}, lit);
auto* ary = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("ary"), "ary");
ast::ArrayAccessorExpression expr(Source{}, ary, idx); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "ary[5]"); EXPECT_EQ(result(), "ary[5]");
} }
TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) { TEST_F(HlslGeneratorImplTest_Expression, EmitArrayAccessor) {
auto* ary = create<ast::IdentifierExpression>( auto* expr = Index("ary", "idx");
Source{}, mod.RegisterSymbol("ary"), "ary");
auto* idx = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("idx"), "idx");
ast::ArrayAccessorExpression expr(Source{}, ary, idx); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "ary[idx]"); EXPECT_EQ(result(), "ary[idx]");
} }

View File

@ -28,15 +28,13 @@ namespace {
using HlslGeneratorImplTest_Assign = TestHelper; using HlslGeneratorImplTest_Assign = TestHelper;
TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) { TEST_F(HlslGeneratorImplTest_Assign, Emit_Assign) {
auto* lhs = create<ast::IdentifierExpression>( auto* lhs = Expr("lhs");
Source{}, mod.RegisterSymbol("lhs"), "lhs"); auto* rhs = Expr("rhs");
auto* rhs = create<ast::IdentifierExpression>( auto* assign = create<ast::AssignmentStatement>(lhs, rhs);
Source{}, mod.RegisterSymbol("rhs"), "rhs");
ast::AssignmentStatement assign(Source{}, lhs, rhs);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &assign)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, assign)) << gen.error();
EXPECT_EQ(result(), " lhs = rhs;\n"); EXPECT_EQ(result(), " lhs = rhs;\n");
} }

View File

@ -58,111 +58,57 @@ inline std::ostream& operator<<(std::ostream& out, BinaryData data) {
using HlslBinaryTest = TestParamHelper<BinaryData>; using HlslBinaryTest = TestParamHelper<BinaryData>;
TEST_P(HlslBinaryTest, Emit_f32) { TEST_P(HlslBinaryTest, Emit_f32) {
ast::type::F32 f32;
auto params = GetParam(); auto params = GetParam();
auto* left_var = auto* left_var = Var("left", ast::StorageClass::kFunction, ty.f32);
create<ast::Variable>(Source{}, // source auto* right_var = Var("right", ast::StorageClass::kFunction, ty.f32);
"left", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* right_var =
create<ast::Variable>(Source{}, // source
"right", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* left = create<ast::IdentifierExpression>( auto* left = Expr("left");
Source{}, mod.RegisterSymbol("left"), "left"); auto* right = Expr("right");
auto* right = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("right"), "right");
td.RegisterVariableForTesting(left_var); td.RegisterVariableForTesting(left_var);
td.RegisterVariableForTesting(right_var); td.RegisterVariableForTesting(right_var);
ast::BinaryExpression expr(Source{}, params.op, left, right); auto* expr = create<ast::BinaryExpression>(params.op, left, right);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), params.result); EXPECT_EQ(result(), params.result);
} }
TEST_P(HlslBinaryTest, Emit_u32) { TEST_P(HlslBinaryTest, Emit_u32) {
ast::type::U32 u32;
auto params = GetParam(); auto params = GetParam();
auto* left_var = auto* left_var = Var("left", ast::StorageClass::kFunction, ty.u32);
create<ast::Variable>(Source{}, // source auto* right_var = Var("right", ast::StorageClass::kFunction, ty.u32);
"left", // name
ast::StorageClass::kFunction, // storage_class
&u32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* right_var =
create<ast::Variable>(Source{}, // source
"right", // name
ast::StorageClass::kFunction, // storage_class
&u32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* left = create<ast::IdentifierExpression>( auto* left = Expr("left");
Source{}, mod.RegisterSymbol("left"), "left"); auto* right = Expr("right");
auto* right = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("right"), "right");
td.RegisterVariableForTesting(left_var); td.RegisterVariableForTesting(left_var);
td.RegisterVariableForTesting(right_var); td.RegisterVariableForTesting(right_var);
ast::BinaryExpression expr(Source{}, params.op, left, right); auto* expr = create<ast::BinaryExpression>(params.op, left, right);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), params.result); EXPECT_EQ(result(), params.result);
} }
TEST_P(HlslBinaryTest, Emit_i32) { TEST_P(HlslBinaryTest, Emit_i32) {
ast::type::I32 i32;
auto params = GetParam(); auto params = GetParam();
auto* left_var = auto* left_var = Var("left", ast::StorageClass::kFunction, ty.i32);
create<ast::Variable>(Source{}, // source auto* right_var = Var("right", ast::StorageClass::kFunction, ty.i32);
"left", // name
ast::StorageClass::kFunction, // storage_class
&i32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* right_var =
create<ast::Variable>(Source{}, // source
"right", // name
ast::StorageClass::kFunction, // storage_class
&i32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* left = create<ast::IdentifierExpression>( auto* left = Expr("left");
Source{}, mod.RegisterSymbol("left"), "left"); auto* right = Expr("right");
auto* right = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("right"), "right");
td.RegisterVariableForTesting(left_var); td.RegisterVariableForTesting(left_var);
td.RegisterVariableForTesting(right_var); td.RegisterVariableForTesting(right_var);
ast::BinaryExpression expr(Source{}, params.op, left, right); auto* expr = create<ast::BinaryExpression>(params.op, left, right);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), params.result); EXPECT_EQ(result(), params.result);
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@ -187,214 +133,116 @@ INSTANTIATE_TEST_SUITE_P(
BinaryData{"(left % right)", ast::BinaryOp::kModulo})); BinaryData{"(left % right)", ast::BinaryOp::kModulo}));
TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorScalar) { TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorScalar) {
ast::type::F32 f32; auto* lhs = vec3<f32>(1.f, 1.f, 1.f);
ast::type::Vector vec3(&f32, 3); auto* rhs = Expr(1.f);
auto* lhs = create<ast::TypeConstructorExpression>( auto* expr =
Source{}, &vec3, create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
});
auto* rhs = create<ast::ScalarConstructorExpression>( ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)); EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), EXPECT_EQ(result(),
"(float3(1.0f, 1.0f, 1.0f) * " "(float3(1.0f, 1.0f, 1.0f) * "
"1.0f)"); "1.0f)");
} }
TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarVector) { TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarVector) {
ast::type::F32 f32; auto* lhs = Expr(1.f);
ast::type::Vector vec3(&f32, 3); auto* rhs = vec3<f32>(1.f, 1.f, 1.f);
auto* lhs = create<ast::ScalarConstructorExpression>( auto* expr =
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)); create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ast::ExpressionList vals; ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
vals.push_back(create<ast::ScalarConstructorExpression>( EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &vec3, vals);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), EXPECT_EQ(result(),
"(1.0f * float3(1.0f, 1.0f, " "(1.0f * float3(1.0f, 1.0f, "
"1.0f))"); "1.0f))");
} }
TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixScalar) { TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixScalar) {
ast::type::F32 f32; auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
ast::type::Matrix mat3(&f32, 3, 3); auto* lhs = Expr("mat");
auto* rhs = Expr(1.f);
auto* var =
create<ast::Variable>(Source{}, // source
"mat", // name
ast::StorageClass::kFunction, // storage_class
&mat3, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mat"), "mat");
auto* rhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f));
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs); auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(mat * 1.0f)"); EXPECT_EQ(result(), "(mat * 1.0f)");
} }
TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarMatrix) { TEST_F(HlslGeneratorImplTest_Binary, Multiply_ScalarMatrix) {
ast::type::F32 f32; auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
ast::type::Matrix mat3(&f32, 3, 3); auto* lhs = Expr(1.f);
auto* rhs = Expr("mat");
auto* var =
create<ast::Variable>(Source{}, // source
"mat", // name
ast::StorageClass::kFunction, // storage_class
&mat3, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f));
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mat"), "mat");
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs); auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(1.0f * mat)"); EXPECT_EQ(result(), "(1.0f * mat)");
} }
TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixVector) { TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixVector) {
ast::type::F32 f32; auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
ast::type::Vector vec3(&f32, 3); auto* lhs = Expr("mat");
ast::type::Matrix mat3(&f32, 3, 3); auto* rhs = vec3<f32>(1.f, 1.f, 1.f);
auto* var =
create<ast::Variable>(Source{}, // source
"mat", // name
ast::StorageClass::kFunction, // storage_class
&mat3, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mat"), "mat");
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
auto* rhs = create<ast::TypeConstructorExpression>(Source{}, &vec3, vals);
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs); auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "mul(mat, float3(1.0f, 1.0f, 1.0f))"); EXPECT_EQ(result(), "mul(mat, float3(1.0f, 1.0f, 1.0f))");
} }
TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorMatrix) { TEST_F(HlslGeneratorImplTest_Binary, Multiply_VectorMatrix) {
ast::type::F32 f32; auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
ast::type::Vector vec3(&f32, 3); auto* lhs = vec3<f32>(1.f, 1.f, 1.f);
ast::type::Matrix mat3(&f32, 3, 3); auto* rhs = Expr("mat");
auto* var =
create<ast::Variable>(Source{}, // source
"mat", // name
ast::StorageClass::kFunction, // storage_class
&mat3, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::ExpressionList vals;
vals.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
vals.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
auto* lhs = create<ast::TypeConstructorExpression>(Source{}, &vec3, vals);
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mat"), "mat");
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs); auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "mul(float3(1.0f, 1.0f, 1.0f), mat)"); EXPECT_EQ(result(), "mul(float3(1.0f, 1.0f, 1.0f), mat)");
} }
TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixMatrix) { TEST_F(HlslGeneratorImplTest_Binary, Multiply_MatrixMatrix) {
ast::type::F32 f32; auto* var = Var("mat", ast::StorageClass::kFunction, ty.mat3x3<f32>());
ast::type::Vector vec3(&f32, 3); auto* lhs = Expr("mat");
ast::type::Matrix mat3(&f32, 3, 3); auto* rhs = Expr("mat");
auto* var =
create<ast::Variable>(Source{}, // source
"mat", // name
ast::StorageClass::kFunction, // storage_class
&mat3, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* lhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mat"), "mat");
auto* rhs = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("mat"), "mat");
td.RegisterVariableForTesting(var); td.RegisterVariableForTesting(var);
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kMultiply, lhs, rhs); auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kMultiply, lhs, rhs);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
EXPECT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); EXPECT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "mul(mat, mat)"); EXPECT_EQ(result(), "mul(mat, mat)");
} }
TEST_F(HlslGeneratorImplTest_Binary, Logical_And) { TEST_F(HlslGeneratorImplTest_Binary, Logical_And) {
auto* left = create<ast::IdentifierExpression>( auto* left = Expr("left");
Source{}, mod.RegisterSymbol("left"), "left"); auto* right = Expr("right");
auto* right = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("right"), "right");
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kLogicalAnd, left, right); auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, left, right);
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp)"); EXPECT_EQ(result(), "(_tint_tmp)");
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = left; EXPECT_EQ(pre_result(), R"(bool _tint_tmp = left;
if (_tint_tmp) { if (_tint_tmp) {
@ -405,21 +253,17 @@ if (_tint_tmp) {
TEST_F(HlslGeneratorImplTest_Binary, Logical_Multi) { TEST_F(HlslGeneratorImplTest_Binary, Logical_Multi) {
// (a && b) || (c || d) // (a && b) || (c || d)
auto* a = auto* a = Expr("a");
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"), "a"); auto* b = Expr("b");
auto* b = auto* c = Expr("c");
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b"); auto* d = Expr("d");
auto* c =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"), "c");
auto* d =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"), "d");
ast::BinaryExpression expr( auto* expr = create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalOr, ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kLogicalAnd, a, b), create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, a, b),
create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kLogicalOr, c, d)); create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, c, d));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp_0)"); EXPECT_EQ(result(), "(_tint_tmp_0)");
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = a; EXPECT_EQ(pre_result(), R"(bool _tint_tmp = a;
if (_tint_tmp) { if (_tint_tmp) {
@ -437,14 +281,13 @@ if (!_tint_tmp_0) {
} }
TEST_F(HlslGeneratorImplTest_Binary, Logical_Or) { TEST_F(HlslGeneratorImplTest_Binary, Logical_Or) {
auto* left = create<ast::IdentifierExpression>( auto* left = Expr("left");
Source{}, mod.RegisterSymbol("left"), "left"); auto* right = Expr("right");
auto* right = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("right"), "right");
ast::BinaryExpression expr(Source{}, ast::BinaryOp::kLogicalOr, left, right); auto* expr =
create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, left, right);
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "(_tint_tmp)"); EXPECT_EQ(result(), "(_tint_tmp)");
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = left; EXPECT_EQ(pre_result(), R"(bool _tint_tmp = left;
if (!_tint_tmp) { if (!_tint_tmp) {
@ -462,56 +305,33 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) {
// return 3; // return 3;
// } // }
ast::type::I32 i32; auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(Expr(3)),
});
auto* else_stmt = create<ast::ElseStatement>(nullptr, body);
auto* body = create<ast::BlockStatement>( body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::ReturnStatement>(Expr(2)),
create<ast::ReturnStatement>( });
Source{}, create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(
Source{}, &i32, 3))),
});
auto* else_stmt = create<ast::ElseStatement>(Source{}, nullptr, body);
body = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::ReturnStatement>(
Source{}, create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(
Source{}, &i32, 2))),
});
auto* else_if_stmt = create<ast::ElseStatement>( auto* else_if_stmt = create<ast::ElseStatement>(
Source{}, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr("b"),
create<ast::BinaryExpression>( Expr("c")),
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"),
"c")),
body); body);
body = create<ast::BlockStatement>( body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::ReturnStatement>(Expr(1)),
create<ast::ReturnStatement>( });
Source{}, create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(
Source{}, &i32, 1))),
});
ast::IfStatement expr(Source{}, auto* expr = create<ast::IfStatement>(
create<ast::BinaryExpression>( create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, Expr("a"),
Source{}, ast::BinaryOp::kLogicalAnd, Expr("b")),
create<ast::IdentifierExpression>( body,
Source{}, mod.RegisterSymbol("a"), "a"), ast::ElseStatementList{
create<ast::IdentifierExpression>( else_if_stmt,
Source{}, mod.RegisterSymbol("b"), "b")), else_stmt,
body, });
{
else_if_stmt,
else_stmt,
});
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a; EXPECT_EQ(result(), R"(bool _tint_tmp = a;
if (_tint_tmp) { if (_tint_tmp) {
_tint_tmp = b; _tint_tmp = b;
@ -534,21 +354,15 @@ if ((_tint_tmp)) {
TEST_F(HlslGeneratorImplTest_Binary, Return_WithLogical) { TEST_F(HlslGeneratorImplTest_Binary, Return_WithLogical) {
// return (a && b) || c; // return (a && b) || c;
auto* a = auto* a = Expr("a");
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"), "a"); auto* b = Expr("b");
auto* b = auto* c = Expr("c");
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b");
auto* c =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"), "c");
ast::ReturnStatement expr(Source{}, auto* expr = create<ast::ReturnStatement>(create<ast::BinaryExpression>(
create<ast::BinaryExpression>( ast::BinaryOp::kLogicalOr,
Source{}, ast::BinaryOp::kLogicalOr, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, a, b), c));
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalAnd, a, b),
c));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a; EXPECT_EQ(result(), R"(bool _tint_tmp = a;
if (_tint_tmp) { if (_tint_tmp) {
_tint_tmp = b; _tint_tmp = b;
@ -563,24 +377,18 @@ return (_tint_tmp_0);
TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) { TEST_F(HlslGeneratorImplTest_Binary, Assign_WithLogical) {
// a = (b || c) && d; // a = (b || c) && d;
auto* a = auto* a = Expr("a");
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"), "a"); auto* b = Expr("b");
auto* b = auto* c = Expr("c");
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b"); auto* d = Expr("d");
auto* c =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"), "c");
auto* d =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"), "d");
ast::AssignmentStatement expr( auto* expr = create<ast::AssignmentStatement>(
Source{}, a, a,
create<ast::BinaryExpression>( create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalAnd, ast::BinaryOp::kLogicalAnd,
create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kLogicalOr, b, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, b, c), d));
c),
d));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = b; EXPECT_EQ(result(), R"(bool _tint_tmp = b;
if (!_tint_tmp) { if (!_tint_tmp) {
_tint_tmp = c; _tint_tmp = c;
@ -595,31 +403,21 @@ a = (_tint_tmp_0);
TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) { TEST_F(HlslGeneratorImplTest_Binary, Decl_WithLogical) {
// var a : bool = (b && c) || d; // var a : bool = (b && c) || d;
ast::type::Bool bool_type;
auto* b = auto* b = Expr("b");
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b"); auto* c = Expr("c");
auto* c = auto* d = Expr("d");
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"), "c");
auto* d =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"), "d");
auto* var = auto* var = Var(
create<ast::Variable>(Source{}, // source "a", ast::StorageClass::kFunction, ty.bool_,
"a", // name create<ast::BinaryExpression>(
ast::StorageClass::kFunction, // storage_class ast::BinaryOp::kLogicalOr,
&bool_type, // type create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd, b, c), d),
false, // is_const ast::VariableDecorationList{});
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalAnd, b, c),
d), // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement expr(Source{}, var); auto* expr = create<ast::VariableDeclStatement>(var);
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = b; EXPECT_EQ(result(), R"(bool _tint_tmp = b;
if (_tint_tmp) { if (_tint_tmp) {
_tint_tmp = c; _tint_tmp = c;
@ -634,23 +432,18 @@ bool a = (_tint_tmp_0);
TEST_F(HlslGeneratorImplTest_Binary, Bitcast_WithLogical) { TEST_F(HlslGeneratorImplTest_Binary, Bitcast_WithLogical) {
// as<i32>(a && (b || c)) // as<i32>(a && (b || c))
ast::type::I32 i32;
auto* a = auto* a = Expr("a");
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"), "a"); auto* b = Expr("b");
auto* b = auto* c = Expr("c");
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), "b");
auto* c =
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"), "c");
ast::BitcastExpression expr( auto* expr = create<ast::BitcastExpression>(
Source{}, &i32, ty.i32,
create<ast::BinaryExpression>( create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalAnd, a, ast::BinaryOp::kLogicalAnd, a,
create<ast::BinaryExpression>(Source{}, ast::BinaryOp::kLogicalOr, b, create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, b, c)));
c)));
ASSERT_TRUE(gen.EmitExpression(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, expr)) << gen.error();
EXPECT_EQ(pre_result(), R"(bool _tint_tmp = a; EXPECT_EQ(pre_result(), R"(bool _tint_tmp = a;
if (_tint_tmp) { if (_tint_tmp) {
bool _tint_tmp_0 = b; bool _tint_tmp_0 = b;
@ -666,48 +459,27 @@ if (_tint_tmp) {
TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) { TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) {
// foo(a && b, c || d, (a || c) && (b || d)) // foo(a && b, c || d, (a || c) && (b || d))
ast::type::Void void_type;
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("foo"), "foo", ast::VariableList{}, mod->RegisterSymbol("foo"), "foo", ast::VariableList{}, ty.void_,
&void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}), create<ast::BlockStatement>(ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod->AddFunction(func);
ast::ExpressionList params; ast::ExpressionList params;
params.push_back(create<ast::BinaryExpression>(ast::BinaryOp::kLogicalAnd,
Expr("a"), Expr("b")));
params.push_back(create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr,
Expr("c"), Expr("d")));
params.push_back(create<ast::BinaryExpression>( params.push_back(create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalAnd, ast::BinaryOp::kLogicalAnd,
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"), "a"), create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr("a"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"), Expr("c")),
"b"))); create<ast::BinaryExpression>(ast::BinaryOp::kLogicalOr, Expr("b"),
params.push_back(create<ast::BinaryExpression>( Expr("d"))));
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"), "c"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"),
"d")));
params.push_back(create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalAnd,
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("a"),
"a"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("c"),
"c")),
create<ast::BinaryExpression>(
Source{}, ast::BinaryOp::kLogicalOr,
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("b"),
"b"),
create<ast::IdentifierExpression>(Source{}, mod.RegisterSymbol("d"),
"d"))));
ast::CallStatement expr(Source{}, auto* expr = create<ast::CallStatement>(Call("foo", params));
create<ast::CallExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo"),
params));
ASSERT_TRUE(gen.EmitStatement(out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, expr)) << gen.error();
EXPECT_EQ(result(), R"(bool _tint_tmp = a; EXPECT_EQ(result(), R"(bool _tint_tmp = a;
if (_tint_tmp) { if (_tint_tmp) {
_tint_tmp = b; _tint_tmp = b;

View File

@ -30,32 +30,26 @@ namespace {
using HlslGeneratorImplTest_Bitcast = TestHelper; using HlslGeneratorImplTest_Bitcast = TestHelper;
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) { TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) {
ast::type::F32 f32; auto* id = Expr("id");
auto* id = create<ast::IdentifierExpression>(Source{}, auto* bitcast = create<ast::BitcastExpression>(ty.f32, id);
mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(Source{}, &f32, id);
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, bitcast)) << gen.error();
EXPECT_EQ(result(), "asfloat(id)"); EXPECT_EQ(result(), "asfloat(id)");
} }
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) { TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) {
ast::type::I32 i32; auto* id = Expr("id");
auto* id = create<ast::IdentifierExpression>(Source{}, auto* bitcast = create<ast::BitcastExpression>(ty.i32, id);
mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(Source{}, &i32, id);
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, bitcast)) << gen.error();
EXPECT_EQ(result(), "asint(id)"); EXPECT_EQ(result(), "asint(id)");
} }
TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) { TEST_F(HlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) {
ast::type::U32 u32; auto* id = Expr("id");
auto* id = create<ast::IdentifierExpression>(Source{}, auto* bitcast = create<ast::BitcastExpression>(ty.u32, id);
mod.RegisterSymbol("id"), "id");
ast::BitcastExpression bitcast(Source{}, &u32, id);
ASSERT_TRUE(gen.EmitExpression(pre, out, &bitcast)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, bitcast)) << gen.error();
EXPECT_EQ(result(), "asuint(id)"); EXPECT_EQ(result(), "asuint(id)");
} }

View File

@ -26,12 +26,12 @@ namespace {
using HlslGeneratorImplTest_Block = TestHelper; using HlslGeneratorImplTest_Block = TestHelper;
TEST_F(HlslGeneratorImplTest_Block, Emit_Block) { TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
ast::BlockStatement b(Source{}, ast::StatementList{ auto* b = create<ast::BlockStatement>(ast::StatementList{
create<ast::DiscardStatement>(Source{}), create<ast::DiscardStatement>(),
}); });
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &b)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, b)) << gen.error();
EXPECT_EQ(result(), R"( { EXPECT_EQ(result(), R"( {
discard; discard;
} }
@ -39,12 +39,12 @@ TEST_F(HlslGeneratorImplTest_Block, Emit_Block) {
} }
TEST_F(HlslGeneratorImplTest_Block, Emit_Block_WithoutNewline) { TEST_F(HlslGeneratorImplTest_Block, Emit_Block_WithoutNewline) {
ast::BlockStatement b(Source{}, ast::StatementList{ auto* b = create<ast::BlockStatement>(ast::StatementList{
create<ast::DiscardStatement>(Source{}), create<ast::DiscardStatement>(),
}); });
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitBlock(out, &b)) << gen.error(); ASSERT_TRUE(gen.EmitBlock(out, b)) << gen.error();
EXPECT_EQ(result(), R"({ EXPECT_EQ(result(), R"({
discard; discard;
})"); })");

View File

@ -27,11 +27,11 @@ namespace {
using HlslGeneratorImplTest_Break = TestHelper; using HlslGeneratorImplTest_Break = TestHelper;
TEST_F(HlslGeneratorImplTest_Break, Emit_Break) { TEST_F(HlslGeneratorImplTest_Break, Emit_Break) {
ast::BreakStatement b(Source{}); auto* b = create<ast::BreakStatement>();
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &b)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, b)) << gen.error();
EXPECT_EQ(result(), " break;\n"); EXPECT_EQ(result(), " break;\n");
} }

View File

@ -30,64 +30,41 @@ namespace {
using HlslGeneratorImplTest_Call = TestHelper; using HlslGeneratorImplTest_Call = TestHelper;
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) { TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) {
ast::type::Void void_type; auto* call = Call("my_func");
auto* id = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::CallExpression call(Source{}, id, {});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_,
&void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}), create<ast::BlockStatement>(ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod->AddFunction(func);
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_EQ(result(), "my_func()"); EXPECT_EQ(result(), "my_func()");
} }
TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) { TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) {
ast::type::Void void_type; auto* call = Call("my_func", "param1", "param2");
auto* id = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(Source{}, id, params);
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_,
&void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}), create<ast::BlockStatement>(ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod->AddFunction(func);
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_EQ(result(), "my_func(param1, param2)"); EXPECT_EQ(result(), "my_func(param1, param2)");
} }
TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) { TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) {
ast::type::Void void_type; auto* call = create<ast::CallStatement>(Call("my_func", "param1", "param2"));
auto* id = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("my_func"), "my_func");
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallStatement call(Source{},
create<ast::CallExpression>(Source{}, id, params));
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{}, ty.void_,
&void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}), create<ast::BlockStatement>(ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod->AddFunction(func);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &call)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, call)) << gen.error();
EXPECT_EQ(result(), " my_func(param1, param2);\n"); EXPECT_EQ(result(), " my_func(param1, param2);\n");
} }

View File

@ -31,19 +31,16 @@ namespace {
using HlslGeneratorImplTest_Case = TestHelper; using HlslGeneratorImplTest_Case = TestHelper;
TEST_F(HlslGeneratorImplTest_Case, Emit_Case) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case) {
ast::type::I32 i32; auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::BreakStatement>(),
auto* body = create<ast::BlockStatement>( });
Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(Literal(5));
ast::CaseStatement c(Source{}, lit, body); auto* c = create<ast::CaseStatement>(lit, body);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(out, &c)) << gen.error(); ASSERT_TRUE(gen.EmitCase(out, c)) << gen.error();
EXPECT_EQ(result(), R"( case 5: { EXPECT_EQ(result(), R"( case 5: {
break; break;
} }
@ -51,17 +48,14 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case) {
} }
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
ast::type::I32 i32;
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(Literal(5));
ast::CaseStatement c( auto* c = create<ast::CaseStatement>(
Source{}, lit, lit, create<ast::BlockStatement>(ast::StatementList{}));
create<ast::BlockStatement>(Source{}, ast::StatementList{}));
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(out, &c)) << gen.error(); ASSERT_TRUE(gen.EmitCase(out, c)) << gen.error();
EXPECT_EQ(result(), R"( case 5: { EXPECT_EQ(result(), R"( case 5: {
break; break;
} }
@ -69,19 +63,16 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) {
} }
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
ast::type::I32 i32; auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::FallthroughStatement>(),
auto* body = create<ast::BlockStatement>( });
Source{}, ast::StatementList{
create<ast::FallthroughStatement>(Source{}),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(Literal(5));
ast::CaseStatement c(Source{}, lit, body); auto* c = create<ast::CaseStatement>(lit, body);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(out, &c)) << gen.error(); ASSERT_TRUE(gen.EmitCase(out, c)) << gen.error();
EXPECT_EQ(result(), R"( case 5: { EXPECT_EQ(result(), R"( case 5: {
/* fallthrough */ /* fallthrough */
} }
@ -89,20 +80,17 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) {
} }
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
ast::type::I32 i32; auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::BreakStatement>(),
auto* body = create<ast::BlockStatement>( });
Source{}, ast::StatementList{
create<ast::BreakStatement>(Source{}),
});
ast::CaseSelectorList lit; ast::CaseSelectorList lit;
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); lit.push_back(Literal(5));
lit.push_back(create<ast::SintLiteral>(Source{}, &i32, 6)); lit.push_back(Literal(6));
ast::CaseStatement c(Source{}, lit, body); auto* c = create<ast::CaseStatement>(lit, body);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(out, &c)) << gen.error(); ASSERT_TRUE(gen.EmitCase(out, c)) << gen.error();
EXPECT_EQ(result(), R"( case 5: EXPECT_EQ(result(), R"( case 5:
case 6: { case 6: {
break; break;
@ -111,15 +99,14 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
} }
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) {
auto* body = create<ast::BlockStatement>( auto* body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::BreakStatement>(),
create<ast::BreakStatement>(Source{}), });
}); auto* c = create<ast::CaseStatement>(ast::CaseSelectorList{}, body);
ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitCase(out, &c)) << gen.error(); ASSERT_TRUE(gen.EmitCase(out, c)) << gen.error();
EXPECT_EQ(result(), R"( default: { EXPECT_EQ(result(), R"( default: {
break; break;
} }

View File

@ -29,29 +29,14 @@ namespace {
using HlslGeneratorImplTest_Cast = TestHelper; using HlslGeneratorImplTest_Cast = TestHelper;
TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Scalar) { TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Scalar) {
ast::type::F32 f32; auto* cast = Construct<f32>("id");
ASSERT_TRUE(gen.EmitExpression(pre, out, cast)) << gen.error();
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("id"), "id"));
ast::TypeConstructorExpression cast(Source{}, &f32, params);
ASSERT_TRUE(gen.EmitExpression(pre, out, &cast)) << gen.error();
EXPECT_EQ(result(), "float(id)"); EXPECT_EQ(result(), "float(id)");
} }
TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Vector) { TEST_F(HlslGeneratorImplTest_Cast, EmitExpression_Cast_Vector) {
ast::type::F32 f32; auto* cast = vec3<f32>("id");
ast::type::Vector vec3(&f32, 3); ASSERT_TRUE(gen.EmitExpression(pre, out, cast)) << gen.error();
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("id"), "id"));
ast::TypeConstructorExpression cast(Source{}, &vec3, params);
ASSERT_TRUE(gen.EmitExpression(pre, out, &cast)) << gen.error();
EXPECT_EQ(result(), "float3(id)"); EXPECT_EQ(result(), "float3(id)");
} }

View File

@ -36,154 +36,83 @@ namespace {
using HlslGeneratorImplTest_Constructor = TestHelper; using HlslGeneratorImplTest_Constructor = TestHelper;
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Bool) {
ast::type::Bool bool_type; auto* expr = Expr(false);
auto* lit = create<ast::BoolLiteral>(Source{}, &bool_type, false);
ast::ScalarConstructorExpression expr(Source{}, lit);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitConstructor(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "false"); EXPECT_EQ(result(), "false");
} }
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Int) {
ast::type::I32 i32; auto* expr = Expr(-12345);
auto* lit = create<ast::SintLiteral>(Source{}, &i32, -12345);
ast::ScalarConstructorExpression expr(Source{}, lit);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitConstructor(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "-12345"); EXPECT_EQ(result(), "-12345");
} }
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_UInt) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_UInt) {
ast::type::U32 u32; auto* expr = Expr(56779u);
auto* lit = create<ast::UintLiteral>(Source{}, &u32, 56779);
ast::ScalarConstructorExpression expr(Source{}, lit);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitConstructor(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "56779u"); EXPECT_EQ(result(), "56779u");
} }
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Float) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Float) {
ast::type::F32 f32;
// Use a number close to 1<<30 but whose decimal representation ends in 0. // Use a number close to 1<<30 but whose decimal representation ends in 0.
auto* lit = create<ast::FloatLiteral>(Source{}, &f32, auto* expr = Expr(static_cast<float>((1 << 30) - 4));
static_cast<float>((1 << 30) - 4));
ast::ScalarConstructorExpression expr(Source{}, lit);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitConstructor(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), "1073741824.0f"); EXPECT_EQ(result(), "1073741824.0f");
} }
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Float) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Float) {
ast::type::F32 f32; auto* expr = Construct<f32>(-1.2e-5f);
auto* lit = create<ast::FloatLiteral>(Source{}, &f32, -1.2e-5); ASSERT_TRUE(gen.EmitConstructor(pre, out, expr)) << gen.error();
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
ast::TypeConstructorExpression expr(Source{}, &f32, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "float(-0.000012f)"); EXPECT_EQ(result(), "float(-0.000012f)");
} }
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Bool) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Bool) {
ast::type::Bool b; auto* expr = Construct<bool>(true);
auto* lit = create<ast::BoolLiteral>(Source{}, &b, true); ASSERT_TRUE(gen.EmitConstructor(pre, out, expr)) << gen.error();
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
ast::TypeConstructorExpression expr(Source{}, &b, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "bool(true)"); EXPECT_EQ(result(), "bool(true)");
} }
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Int) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Int) {
ast::type::I32 i32; auto* expr = Construct<i32>(-12345);
auto* lit = create<ast::SintLiteral>(Source{}, &i32, -12345); ASSERT_TRUE(gen.EmitConstructor(pre, out, expr)) << gen.error();
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
ast::TypeConstructorExpression expr(Source{}, &i32, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "int(-12345)"); EXPECT_EQ(result(), "int(-12345)");
} }
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Uint) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Uint) {
ast::type::U32 u32; auto* expr = Construct<u32>(12345u);
auto* lit = create<ast::UintLiteral>(Source{}, &u32, 12345); ASSERT_TRUE(gen.EmitConstructor(pre, out, expr)) << gen.error();
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit));
ast::TypeConstructorExpression expr(Source{}, &u32, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "uint(12345u)"); EXPECT_EQ(result(), "uint(12345u)");
} }
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec) {
ast::type::F32 f32; auto* expr = vec3<f32>(1.f, 2.f, 3.f);
ast::type::Vector vec(&f32, 3);
auto* lit1 = create<ast::FloatLiteral>(Source{}, &f32, 1.f); ASSERT_TRUE(gen.EmitConstructor(pre, out, expr)) << gen.error();
auto* lit2 = create<ast::FloatLiteral>(Source{}, &f32, 2.f);
auto* lit3 = create<ast::FloatLiteral>(Source{}, &f32, 3.f);
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
ast::TypeConstructorExpression expr(Source{}, &vec, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "float3(1.0f, 2.0f, 3.0f)"); EXPECT_EQ(result(), "float3(1.0f, 2.0f, 3.0f)");
} }
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec_Empty) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Vec_Empty) {
ast::type::F32 f32; auto* expr = vec3<f32>();
ast::type::Vector vec(&f32, 3);
ast::ExpressionList values; ASSERT_TRUE(gen.EmitConstructor(pre, out, expr)) << gen.error();
ast::TypeConstructorExpression expr(Source{}, &vec, values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), "float3(0.0f)"); EXPECT_EQ(result(), "float3(0.0f)");
} }
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) {
ast::type::F32 f32;
ast::type::Matrix mat(&f32, 3, 2); // 3 ROWS, 2 COLUMNS
ast::type::Vector vec(&f32, 3);
// WGSL matrix is mat2x3 (it flips for AST, sigh). With a type constructor // WGSL matrix is mat2x3 (it flips for AST, sigh). With a type constructor
// of <vec3, vec3> // of <vec3, vec3>
ast::ExpressionList mat_values; auto* expr = mat2x3<f32>(vec3<f32>(1.f, 2.f, 3.f), vec3<f32>(3.f, 4.f, 5.f));
for (size_t i = 0; i < 2; i++) { ASSERT_TRUE(gen.EmitConstructor(pre, out, expr)) << gen.error();
auto* lit1 = create<ast::FloatLiteral>(Source{}, &f32,
static_cast<float>(1 + (i * 2)));
auto* lit2 = create<ast::FloatLiteral>(Source{}, &f32,
static_cast<float>(2 + (i * 2)));
auto* lit3 = create<ast::FloatLiteral>(Source{}, &f32,
static_cast<float>(3 + (i * 2)));
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
mat_values.push_back(
create<ast::TypeConstructorExpression>(Source{}, &vec, values));
}
ast::TypeConstructorExpression expr(Source{}, &mat, mat_values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
// A matrix of type T with n columns and m rows can also be constructed from // A matrix of type T with n columns and m rows can also be constructed from
// n vectors of type T with m components. // n vectors of type T with m components.
@ -192,32 +121,10 @@ TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Mat) {
} }
TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Array) { TEST_F(HlslGeneratorImplTest_Constructor, EmitConstructor_Type_Array) {
ast::type::F32 f32; auto* expr = Construct(ty.array(ty.vec3<f32>(), 3), vec3<f32>(1.f, 2.f, 3.f),
ast::type::Vector vec(&f32, 3); vec3<f32>(4.f, 5.f, 6.f), vec3<f32>(7.f, 8.f, 9.f));
ast::type::Array ary(&vec, 3, ast::ArrayDecorationList{});
ast::ExpressionList ary_values; ASSERT_TRUE(gen.EmitConstructor(pre, out, expr)) << gen.error();
for (size_t i = 0; i < 3; i++) {
auto* lit1 = create<ast::FloatLiteral>(Source{}, &f32,
static_cast<float>(1 + (i * 3)));
auto* lit2 = create<ast::FloatLiteral>(Source{}, &f32,
static_cast<float>(2 + (i * 3)));
auto* lit3 = create<ast::FloatLiteral>(Source{}, &f32,
static_cast<float>(3 + (i * 3)));
ast::ExpressionList values;
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit1));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit2));
values.push_back(create<ast::ScalarConstructorExpression>(Source{}, lit3));
ary_values.push_back(
create<ast::TypeConstructorExpression>(Source{}, &vec, values));
}
ast::TypeConstructorExpression expr(Source{}, &ary, ary_values);
ASSERT_TRUE(gen.EmitConstructor(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), EXPECT_EQ(result(),
"{float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f)," "{float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f),"
" float3(7.0f, 8.0f, 9.0f)}"); " float3(7.0f, 8.0f, 9.0f)}");

View File

@ -27,11 +27,11 @@ namespace {
using HlslGeneratorImplTest_Continue = TestHelper; using HlslGeneratorImplTest_Continue = TestHelper;
TEST_F(HlslGeneratorImplTest_Continue, Emit_Continue) { TEST_F(HlslGeneratorImplTest_Continue, Emit_Continue) {
ast::ContinueStatement c(Source{}); auto* c = create<ast::ContinueStatement>();
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &c)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, c)) << gen.error();
EXPECT_EQ(result(), " continue;\n"); EXPECT_EQ(result(), " continue;\n");
} }

View File

@ -24,11 +24,11 @@ namespace {
using HlslGeneratorImplTest_Discard = TestHelper; using HlslGeneratorImplTest_Discard = TestHelper;
TEST_F(HlslGeneratorImplTest_Discard, Emit_Discard) { TEST_F(HlslGeneratorImplTest_Discard, Emit_Discard) {
ast::DiscardStatement stmt(Source{}); auto* stmt = create<ast::DiscardStatement>();
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
EXPECT_EQ(result(), " discard;\n"); EXPECT_EQ(result(), " discard;\n");
} }

View File

@ -23,10 +23,6 @@
#include "src/ast/pipeline_stage.h" #include "src/ast/pipeline_stage.h"
#include "src/ast/return_statement.h" #include "src/ast/return_statement.h"
#include "src/ast/stage_decoration.h" #include "src/ast/stage_decoration.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/vector_type.h"
#include "src/ast/type/void_type.h"
#include "src/ast/variable.h" #include "src/ast/variable.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
#include "src/writer/hlsl/test_helper.h" #include "src/writer/hlsl/test_helper.h"
@ -48,62 +44,34 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// int bar : TEXCOORD1; // int bar : TEXCOORD1;
// }; // };
ast::type::F32 f32; auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32, nullptr,
ast::type::I32 i32; ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* foo_var = auto* bar_var = Var("bar", ast::StorageClass::kInput, ty.i32, nullptr,
create<ast::Variable>(Source{}, // source ast::VariableDecorationList{
"foo", // name create<ast::LocationDecoration>(1),
ast::StorageClass::kInput, // storage_class });
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::LocationDecoration>(Source{}, 0),
});
auto* bar_var =
create<ast::Variable>(Source{}, // source
"bar", // name
ast::StorageClass::kInput, // storage_class
&i32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::LocationDecoration>(Source{}, 1),
});
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(foo_var); mod->AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var); mod->AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>( auto* body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
Source{}, });
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, mod->RegisterSymbol("vtx_main"), "vtx_main", params, ty.f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod.AddFunction(func); mod->AddFunction(func);
std::unordered_set<std::string> globals; std::unordered_set<std::string> globals;
@ -127,63 +95,35 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// int bar : TEXCOORD1; // int bar : TEXCOORD1;
// }; // };
ast::type::F32 f32; auto* foo_var = Var("foo", ast::StorageClass::kOutput, ty.f32, nullptr,
ast::type::I32 i32; ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* foo_var = auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.i32, nullptr,
create<ast::Variable>(Source{}, // source ast::VariableDecorationList{
"foo", // name create<ast::LocationDecoration>(1),
ast::StorageClass::kOutput, // storage_class });
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::LocationDecoration>(Source{}, 0),
});
auto* bar_var =
create<ast::Variable>(Source{}, // source
"bar", // name
ast::StorageClass::kOutput, // storage_class
&i32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::LocationDecoration>(Source{}, 1),
});
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(foo_var); mod->AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var); mod->AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>( auto* body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
Source{}, });
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, mod->RegisterSymbol("vtx_main"), "vtx_main", params, ty.f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod.AddFunction(func); mod->AddFunction(func);
std::unordered_set<std::string> globals; std::unordered_set<std::string> globals;
@ -207,63 +147,35 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// int bar : TEXCOORD1; // int bar : TEXCOORD1;
// }; // };
ast::type::F32 f32; auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32, nullptr,
ast::type::I32 i32; ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* foo_var = auto* bar_var = Var("bar", ast::StorageClass::kInput, ty.i32, nullptr,
create<ast::Variable>(Source{}, // source ast::VariableDecorationList{
"foo", // name create<ast::LocationDecoration>(1),
ast::StorageClass::kInput, // storage_class });
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::LocationDecoration>(Source{}, 0),
});
auto* bar_var =
create<ast::Variable>(Source{}, // source
"bar", // name
ast::StorageClass::kInput, // storage_class
&i32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::LocationDecoration>(Source{}, 1),
});
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(foo_var); mod->AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var); mod->AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>( auto* body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
Source{}, });
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, mod->RegisterSymbol("main"), "main", params, ty.f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kVertex), create<ast::StageDecoration>(ast::PipelineStage::kVertex),
}); });
mod.AddFunction(func); mod->AddFunction(func);
std::unordered_set<std::string> globals; std::unordered_set<std::string> globals;
@ -287,62 +199,34 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// int bar : SV_Target1; // int bar : SV_Target1;
// }; // };
ast::type::F32 f32; auto* foo_var = Var("foo", ast::StorageClass::kOutput, ty.f32, nullptr,
ast::type::I32 i32; ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* foo_var = auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.i32, nullptr,
create<ast::Variable>(Source{}, // source ast::VariableDecorationList{
"foo", // name create<ast::LocationDecoration>(1),
ast::StorageClass::kOutput, // storage_class });
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::LocationDecoration>(Source{}, 0),
});
auto* bar_var =
create<ast::Variable>(Source{}, // source
"bar", // name
ast::StorageClass::kOutput, // storage_class
&i32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::LocationDecoration>(Source{}, 1),
});
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(foo_var); mod->AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var); mod->AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>( auto* body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
Source{}, });
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, mod->RegisterSymbol("main"), "main", params, ty.f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod.AddFunction(func); mod->AddFunction(func);
std::unordered_set<std::string> globals; std::unordered_set<std::string> globals;
@ -363,62 +247,34 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// //
// -> Error, not allowed // -> Error, not allowed
ast::type::F32 f32; auto* foo_var = Var("foo", ast::StorageClass::kInput, ty.f32, nullptr,
ast::type::I32 i32; ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* foo_var = auto* bar_var = Var("bar", ast::StorageClass::kInput, ty.i32, nullptr,
create<ast::Variable>(Source{}, // source ast::VariableDecorationList{
"foo", // name create<ast::LocationDecoration>(1),
ast::StorageClass::kInput, // storage_class });
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::LocationDecoration>(Source{}, 0),
});
auto* bar_var =
create<ast::Variable>(Source{}, // source
"bar", // name
ast::StorageClass::kInput, // storage_class
&i32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::LocationDecoration>(Source{}, 1),
});
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(foo_var); mod->AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var); mod->AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>( auto* body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
Source{}, });
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, mod->RegisterSymbol("main"), "main", params, ty.f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod.AddFunction(func); mod->AddFunction(func);
std::unordered_set<std::string> globals; std::unordered_set<std::string> globals;
@ -434,62 +290,34 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// //
// -> Error not allowed // -> Error not allowed
ast::type::F32 f32; auto* foo_var = Var("foo", ast::StorageClass::kOutput, ty.f32, nullptr,
ast::type::I32 i32; ast::VariableDecorationList{
create<ast::LocationDecoration>(0),
});
auto* foo_var = auto* bar_var = Var("bar", ast::StorageClass::kOutput, ty.i32, nullptr,
create<ast::Variable>(Source{}, // source ast::VariableDecorationList{
"foo", // name create<ast::LocationDecoration>(1),
ast::StorageClass::kOutput, // storage_class });
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::LocationDecoration>(Source{}, 0),
});
auto* bar_var =
create<ast::Variable>(Source{}, // source
"bar", // name
ast::StorageClass::kOutput, // storage_class
&i32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::LocationDecoration>(Source{}, 1),
});
td.RegisterVariableForTesting(foo_var); td.RegisterVariableForTesting(foo_var);
td.RegisterVariableForTesting(bar_var); td.RegisterVariableForTesting(bar_var);
mod.AddGlobalVariable(foo_var); mod->AddGlobalVariable(foo_var);
mod.AddGlobalVariable(bar_var); mod->AddGlobalVariable(bar_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>( auto* body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::AssignmentStatement>(Expr("foo"), Expr("foo")),
create<ast::AssignmentStatement>( create<ast::AssignmentStatement>(Expr("bar"), Expr("bar")),
Source{}, });
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("foo"), "foo")),
create<ast::AssignmentStatement>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("bar"), "bar")),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, mod->RegisterSymbol("main"), "main", params, ty.f32, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kCompute), create<ast::StageDecoration>(ast::PipelineStage::kCompute),
}); });
mod.AddFunction(func); mod->AddFunction(func);
std::unordered_set<std::string> globals; std::unordered_set<std::string> globals;
@ -511,61 +339,35 @@ TEST_F(HlslGeneratorImplTest_EntryPoint,
// float depth : SV_Depth; // float depth : SV_Depth;
// }; // };
ast::type::F32 f32; auto* coord_var =
ast::type::Void void_type; Var("coord", ast::StorageClass::kInput, ty.vec4<f32>(), nullptr,
ast::type::Vector vec4(&f32, 4); ast::VariableDecorationList{
create<ast::BuiltinDecoration>(ast::Builtin::kFragCoord),
});
auto* coord_var = create<ast::Variable>( auto* depth_var =
Source{}, // source Var("depth", ast::StorageClass::kOutput, ty.f32, nullptr,
"coord", // name ast::VariableDecorationList{
ast::StorageClass::kInput, // storage_class create<ast::BuiltinDecoration>(ast::Builtin::kFragDepth),
&vec4, // type });
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::BuiltinDecoration>(Source{}, ast::Builtin::kFragCoord),
});
auto* depth_var = create<ast::Variable>(
Source{}, // source
"depth", // name
ast::StorageClass::kOutput, // storage_class
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::BuiltinDecoration>(Source{}, ast::Builtin::kFragDepth),
});
td.RegisterVariableForTesting(coord_var); td.RegisterVariableForTesting(coord_var);
td.RegisterVariableForTesting(depth_var); td.RegisterVariableForTesting(depth_var);
mod.AddGlobalVariable(coord_var); mod->AddGlobalVariable(coord_var);
mod.AddGlobalVariable(depth_var); mod->AddGlobalVariable(depth_var);
ast::VariableList params; ast::VariableList params;
auto* body = create<ast::BlockStatement>( auto* body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::AssignmentStatement>(Expr("depth"), Member("coord", "x")),
create<ast::AssignmentStatement>( });
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("depth"), "depth"),
create<ast::MemberAccessorExpression>(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("coord"), "coord"),
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("x"), "x"))),
});
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body, mod->RegisterSymbol("main"), "main", params, ty.void_, body,
ast::FunctionDecorationList{ ast::FunctionDecorationList{
create<ast::StageDecoration>(Source{}, ast::PipelineStage::kFragment), create<ast::StageDecoration>(ast::PipelineStage::kFragment),
}); });
mod.AddFunction(func); mod->AddFunction(func);
std::unordered_set<std::string> globals; std::unordered_set<std::string> globals;

File diff suppressed because it is too large Load Diff

View File

@ -24,16 +24,15 @@ namespace {
using HlslGeneratorImplTest_Identifier = TestHelper; using HlslGeneratorImplTest_Identifier = TestHelper;
TEST_F(HlslGeneratorImplTest_Identifier, EmitIdentifierExpression) { TEST_F(HlslGeneratorImplTest_Identifier, EmitIdentifierExpression) {
ast::IdentifierExpression i(Source{}, mod.RegisterSymbol("foo"), "foo"); auto* i = Expr("foo");
ASSERT_TRUE(gen.EmitExpression(pre, out, &i)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, i)) << gen.error();
EXPECT_EQ(result(), "foo"); EXPECT_EQ(result(), "foo");
} }
TEST_F(HlslGeneratorImplTest_Identifier, TEST_F(HlslGeneratorImplTest_Identifier,
EmitIdentifierExpression_Single_WithCollision) { EmitIdentifierExpression_Single_WithCollision) {
ast::IdentifierExpression i(Source{}, mod.RegisterSymbol("virtual"), auto* i = Expr("virtual");
"virtual"); ASSERT_TRUE(gen.EmitExpression(pre, out, i)) << gen.error();
ASSERT_TRUE(gen.EmitExpression(pre, out, &i)) << gen.error();
EXPECT_EQ(result(), "virtual_tint_0"); EXPECT_EQ(result(), "virtual_tint_0");
} }

View File

@ -27,16 +27,14 @@ namespace {
using HlslGeneratorImplTest_If = TestHelper; using HlslGeneratorImplTest_If = TestHelper;
TEST_F(HlslGeneratorImplTest_If, Emit_If) { TEST_F(HlslGeneratorImplTest_If, Emit_If) {
auto* cond = create<ast::IdentifierExpression>( auto* cond = Expr("cond");
Source{}, mod.RegisterSymbol("cond"), "cond"); auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* body = create<ast::BlockStatement>( create<ast::ReturnStatement>(),
Source{}, ast::StatementList{ });
create<ast::ReturnStatement>(Source{}), auto* i = create<ast::IfStatement>(cond, body, ast::ElseStatementList{});
});
ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{});
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &i)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, i)) << gen.error();
EXPECT_EQ(result(), R"( if (cond) { EXPECT_EQ(result(), R"( if (cond) {
return; return;
} }
@ -44,26 +42,22 @@ TEST_F(HlslGeneratorImplTest_If, Emit_If) {
} }
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
auto* else_cond = create<ast::IdentifierExpression>( auto* else_cond = Expr("else_cond");
Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); auto* else_body = create<ast::BlockStatement>(ast::StatementList{
auto* else_body = create<ast::BlockStatement>( create<ast::ReturnStatement>(),
Source{}, ast::StatementList{ });
create<ast::ReturnStatement>(Source{}),
});
auto* cond = create<ast::IdentifierExpression>( auto* cond = Expr("cond");
Source{}, mod.RegisterSymbol("cond"), "cond"); auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* body = create<ast::BlockStatement>( create<ast::ReturnStatement>(),
Source{}, ast::StatementList{ });
create<ast::ReturnStatement>(Source{}), auto* i = create<ast::IfStatement>(
}); cond, body,
ast::IfStatement i( ast::ElseStatementList{create<ast::ElseStatement>(else_cond, else_body)});
Source{}, cond, body,
{create<ast::ElseStatement>(Source{}, else_cond, else_body)});
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &i)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, i)) << gen.error();
EXPECT_EQ(result(), R"( if (cond) { EXPECT_EQ(result(), R"( if (cond) {
return; return;
} else { } else {
@ -75,24 +69,21 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) {
} }
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
auto* else_body = create<ast::BlockStatement>( auto* else_body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::ReturnStatement>(),
create<ast::ReturnStatement>(Source{}), });
});
auto* cond = create<ast::IdentifierExpression>( auto* cond = Expr("cond");
Source{}, mod.RegisterSymbol("cond"), "cond"); auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* body = create<ast::BlockStatement>( create<ast::ReturnStatement>(),
Source{}, ast::StatementList{ });
create<ast::ReturnStatement>(Source{}), auto* i = create<ast::IfStatement>(
}); cond, body,
ast::IfStatement i( ast::ElseStatementList{create<ast::ElseStatement>(nullptr, else_body)});
Source{}, cond, body,
{create<ast::ElseStatement>(Source{}, nullptr, else_body)});
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &i)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, i)) << gen.error();
EXPECT_EQ(result(), R"( if (cond) { EXPECT_EQ(result(), R"( if (cond) {
return; return;
} else { } else {
@ -102,35 +93,30 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) {
} }
TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) {
auto* else_cond = create<ast::IdentifierExpression>( auto* else_cond = Expr("else_cond");
Source{}, mod.RegisterSymbol("else_cond"), "else_cond");
auto* else_body = create<ast::BlockStatement>( auto* else_body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::ReturnStatement>(),
create<ast::ReturnStatement>(Source{}), });
});
auto* else_body_2 = create<ast::BlockStatement>( auto* else_body_2 = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::ReturnStatement>(),
create<ast::ReturnStatement>(Source{}), });
});
auto* cond = create<ast::IdentifierExpression>( auto* cond = Expr("cond");
Source{}, mod.RegisterSymbol("cond"), "cond"); auto* body = create<ast::BlockStatement>(ast::StatementList{
auto* body = create<ast::BlockStatement>( create<ast::ReturnStatement>(),
Source{}, ast::StatementList{ });
create<ast::ReturnStatement>(Source{}), auto* i = create<ast::IfStatement>(
}); cond, body,
ast::IfStatement i( ast::ElseStatementList{
Source{}, cond, body, create<ast::ElseStatement>(else_cond, else_body),
{ create<ast::ElseStatement>(nullptr, else_body_2),
create<ast::ElseStatement>(Source{}, else_cond, else_body),
create<ast::ElseStatement>(Source{}, nullptr, else_body_2),
}); });
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &i)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, i)) << gen.error();
EXPECT_EQ(result(), R"( if (cond) { EXPECT_EQ(result(), R"( if (cond) {
return; return;
} else { } else {

View File

@ -50,18 +50,11 @@ using HlslImportData_SingleParamTest = TestParamHelper<HlslImportData>;
TEST_P(HlslImportData_SingleParamTest, FloatScalar) { TEST_P(HlslImportData_SingleParamTest, FloatScalar) {
auto param = GetParam(); auto param = GetParam();
ast::type::F32 f32; auto* ident = Expr(param.name);
auto* expr = Call(ident, 1.f);
ast::ExpressionList params; ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
params.push_back(create<ast::ScalarConstructorExpression>( ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
auto* ident = create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name);
ast::CallExpression expr(Source{}, ident, params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1.0f)"); EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1.0f)");
} }
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import, INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
@ -96,20 +89,10 @@ using HlslImportData_SingleIntParamTest = TestParamHelper<HlslImportData>;
TEST_P(HlslImportData_SingleIntParamTest, IntScalar) { TEST_P(HlslImportData_SingleIntParamTest, IntScalar) {
auto param = GetParam(); auto param = GetParam();
ast::type::I32 i32; auto* expr = Call(param.name, Expr(1));
ast::ExpressionList params; ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
params.push_back(create<ast::ScalarConstructorExpression>( ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)));
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1)"); EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1)");
} }
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import, INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
@ -120,22 +103,10 @@ using HlslImportData_DualParamTest = TestParamHelper<HlslImportData>;
TEST_P(HlslImportData_DualParamTest, FloatScalar) { TEST_P(HlslImportData_DualParamTest, FloatScalar) {
auto param = GetParam(); auto param = GetParam();
ast::type::F32 f32; auto* expr = Call(param.name, 1.f, 2.f);
ast::ExpressionList params; ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
params.push_back(create<ast::ScalarConstructorExpression>( ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f)));
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1.0f, 2.0f)"); EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1.0f, 2.0f)");
} }
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import, INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
@ -152,40 +123,11 @@ using HlslImportData_DualParam_VectorTest = TestParamHelper<HlslImportData>;
TEST_P(HlslImportData_DualParam_VectorTest, FloatVector) { TEST_P(HlslImportData_DualParam_VectorTest, FloatVector) {
auto param = GetParam(); auto param = GetParam();
ast::type::F32 f32; auto* expr =
ast::type::Vector vec(&f32, 3); Call(param.name, vec3<f32>(1.f, 2.f, 3.f), vec3<f32>(4.f, 5.f, 6.f));
ast::ExpressionList params; ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
params.push_back(create<ast::TypeConstructorExpression>( ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
Source{}, &vec,
ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.f)),
}));
params.push_back(create<ast::TypeConstructorExpression>(
Source{}, &vec,
ast::ExpressionList{
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 4.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 5.f)),
create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 6.f)),
}));
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), EXPECT_EQ(result(),
std::string(param.hlsl_name) + std::string(param.hlsl_name) +
"(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f))"); "(float3(1.0f, 2.0f, 3.0f), float3(4.0f, 5.0f, 6.0f))");
@ -198,22 +140,10 @@ using HlslImportData_DualParam_Int_Test = TestParamHelper<HlslImportData>;
TEST_P(HlslImportData_DualParam_Int_Test, IntScalar) { TEST_P(HlslImportData_DualParam_Int_Test, IntScalar) {
auto param = GetParam(); auto param = GetParam();
ast::type::I32 i32; auto* expr = Call(param.name, 1, 2);
ast::ExpressionList params; ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
params.push_back(create<ast::ScalarConstructorExpression>( ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)));
params.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1, 2)"); EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1, 2)");
} }
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import, INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
@ -225,24 +155,10 @@ using HlslImportData_TripleParamTest = TestParamHelper<HlslImportData>;
TEST_P(HlslImportData_TripleParamTest, FloatScalar) { TEST_P(HlslImportData_TripleParamTest, FloatScalar) {
auto param = GetParam(); auto param = GetParam();
ast::type::F32 f32; auto* expr = Call(param.name, 1.f, 2.f, 3.f);
ast::ExpressionList params; ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
params.push_back(create<ast::ScalarConstructorExpression>( ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.f)));
params.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.f)));
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1.0f, 2.0f, 3.0f)"); EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1.0f, 2.0f, 3.0f)");
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
@ -261,24 +177,10 @@ using HlslImportData_TripleParam_Int_Test = TestParamHelper<HlslImportData>;
TEST_P(HlslImportData_TripleParam_Int_Test, IntScalar) { TEST_P(HlslImportData_TripleParam_Int_Test, IntScalar) {
auto param = GetParam(); auto param = GetParam();
ast::type::I32 i32; auto* expr = Call(param.name, 1, 2, 3);
ast::ExpressionList params; ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
params.push_back(create<ast::ScalarConstructorExpression>( ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
Source{}, create<ast::SintLiteral>(Source{}, &i32, 1)));
params.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 2)));
params.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::SintLiteral>(Source{}, &i32, 3)));
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol(param.name), param.name),
params);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error();
EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1, 2, 3)"); EXPECT_EQ(result(), std::string(param.hlsl_name) + "(1, 2, 3)");
} }
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import, INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
@ -286,34 +188,16 @@ INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Import,
testing::Values(HlslImportData{"clamp", "clamp"})); testing::Values(HlslImportData{"clamp", "clamp"}));
TEST_F(HlslGeneratorImplTest_Import, HlslImportData_Determinant) { TEST_F(HlslGeneratorImplTest_Import, HlslImportData_Determinant) {
ast::type::F32 f32; auto* var = Var("var", ast::StorageClass::kFunction, ty.mat3x3<f32>());
ast::type::Matrix mat(&f32, 3, 3);
auto* var = auto* expr = Call("determinant", "var");
create<ast::Variable>(Source{}, // source
"var", // name
ast::StorageClass::kFunction, // storage_class
&mat, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::ExpressionList params; mod->AddGlobalVariable(var);
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("var"), "var"));
ast::CallExpression expr(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("determinant"), "determinant"),
params);
mod.AddGlobalVariable(var);
// Register the global // Register the global
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); ASSERT_TRUE(td.DetermineResultType(expr)) << td.error();
ASSERT_TRUE(gen.EmitCall(pre, out, &expr)) << gen.error(); ASSERT_TRUE(gen.EmitCall(pre, out, expr)) << gen.error();
EXPECT_EQ(result(), std::string("determinant(var)")); EXPECT_EQ(result(), std::string("determinant(var)"));
} }

View File

@ -71,50 +71,22 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, DISABLED_Intrinsic_Select) {
} }
TEST_F(HlslGeneratorImplTest_Intrinsic, DISABLED_Intrinsic_OuterProduct) { TEST_F(HlslGeneratorImplTest_Intrinsic, DISABLED_Intrinsic_OuterProduct) {
ast::type::F32 f32; auto* a = Var("a", ast::StorageClass::kNone, ty.vec2<f32>());
ast::type::Vector vec2(&f32, 2); auto* b = Var("b", ast::StorageClass::kNone, ty.vec3<f32>());
ast::type::Vector vec3(&f32, 3);
auto* a = auto* call = Call("outer_product", "a", "b");
create<ast::Variable>(Source{}, // source
"a", // name
ast::StorageClass::kNone, // storage_class
&vec2, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
auto* b =
create<ast::Variable>(Source{}, // source
"b", // name
ast::StorageClass::kNone, // storage_class
&vec3, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::ExpressionList params;
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("a"), "a"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("b"), "b"));
ast::CallExpression call(
Source{},
create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("outer_product"), "outer_product"),
params);
td.RegisterVariableForTesting(a); td.RegisterVariableForTesting(a);
td.RegisterVariableForTesting(b); td.RegisterVariableForTesting(b);
mod.AddGlobalVariable(a); mod->AddGlobalVariable(a);
mod.AddGlobalVariable(b); mod->AddGlobalVariable(b);
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error(); ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_EQ(result(), " float3x2(a * b[0], a * b[1], a * b[2])"); EXPECT_EQ(result(), " float3x2(a * b[0], a * b[1], a * b[2])");
} }
@ -123,32 +95,18 @@ TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Bad_Name) {
} }
TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) { TEST_F(HlslGeneratorImplTest_Intrinsic, Intrinsic_Call) {
ast::type::F32 f32; auto* call = Call("dot", "param1", "param2");
ast::type::Vector vec(&f32, 3);
ast::ExpressionList params; auto* v1 = Var("param1", ast::StorageClass::kFunction, ty.vec3<f32>());
params.push_back(create<ast::IdentifierExpression>( auto* v2 = Var("param2", ast::StorageClass::kFunction, ty.vec3<f32>());
Source{}, mod.RegisterSymbol("param1"), "param1"));
params.push_back(create<ast::IdentifierExpression>(
Source{}, mod.RegisterSymbol("param2"), "param2"));
ast::CallExpression call(Source{}, td.RegisterVariableForTesting(v1);
create<ast::IdentifierExpression>( td.RegisterVariableForTesting(v2);
Source{}, mod.RegisterSymbol("dot"), "dot"),
params);
ast::Variable v1(Source{}, "param1", ast::StorageClass::kFunction, &vec, ASSERT_TRUE(td.DetermineResultType(call)) << td.error();
false, nullptr, ast::VariableDecorationList{});
ast::Variable v2(Source{}, "param2", ast::StorageClass::kFunction, &vec,
false, nullptr, ast::VariableDecorationList{});
td.RegisterVariableForTesting(&v1);
td.RegisterVariableForTesting(&v2);
ASSERT_TRUE(td.DetermineResultType(&call)) << td.error();
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, call)) << gen.error();
EXPECT_EQ(result(), " dot(param1, param2)"); EXPECT_EQ(result(), " dot(param1, param2)");
} }

View File

@ -272,8 +272,7 @@ TEST_P(HlslGeneratorIntrinsicTextureTest, Call) {
param.buildTextureVariable(this); param.buildTextureVariable(this);
param.buildSamplerVariable(this); param.buildSamplerVariable(this);
auto* call = auto* call = Call(param.function, param.args(this));
create<ast::CallExpression>(Expr(param.function), param.args(this));
ASSERT_TRUE(td.Determine()) << td.error(); ASSERT_TRUE(td.Determine()) << td.error();
ASSERT_TRUE(td.DetermineResultType(call)) << td.error(); ASSERT_TRUE(td.DetermineResultType(call)) << td.error();

View File

@ -34,14 +34,13 @@ namespace {
using HlslGeneratorImplTest_Loop = TestHelper; using HlslGeneratorImplTest_Loop = TestHelper;
TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) { TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
auto* body = create<ast::BlockStatement>( auto* body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::DiscardStatement>(),
create<ast::DiscardStatement>(Source{}), });
}); auto* l = create<ast::LoopStatement>(body, nullptr);
ast::LoopStatement l(Source{}, body, {});
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, l)) << gen.error();
EXPECT_EQ(result(), R"( for(;;) { EXPECT_EQ(result(), R"( for(;;) {
discard; discard;
} }
@ -49,18 +48,16 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) {
} }
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) { TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
auto* body = create<ast::BlockStatement>( auto* body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::DiscardStatement>(),
create<ast::DiscardStatement>(Source{}), });
}); auto* continuing = create<ast::BlockStatement>(ast::StatementList{
auto* continuing = create<ast::BlockStatement>( create<ast::ReturnStatement>(),
Source{}, ast::StatementList{ });
create<ast::ReturnStatement>(Source{}), auto* l = create<ast::LoopStatement>(body, continuing);
});
ast::LoopStatement l(Source{}, body, continuing);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &l)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, l)) << gen.error();
EXPECT_EQ(result(), R"( { EXPECT_EQ(result(), R"( {
bool tint_hlsl_is_first_1 = true; bool tint_hlsl_is_first_1 = true;
for(;;) { for(;;) {
@ -76,36 +73,29 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) {
} }
TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) { TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) {
ast::type::F32 f32; auto* body = create<ast::BlockStatement>(ast::StatementList{
create<ast::DiscardStatement>(),
});
auto* continuing = create<ast::BlockStatement>(ast::StatementList{
create<ast::ReturnStatement>(),
});
auto* inner = create<ast::LoopStatement>(body, continuing);
auto* body = create<ast::BlockStatement>( body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ inner,
create<ast::DiscardStatement>(Source{}), });
});
auto* continuing = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::ReturnStatement>(Source{}),
});
auto* inner = create<ast::LoopStatement>(Source{}, body, continuing);
body = create<ast::BlockStatement>(Source{}, ast::StatementList{ auto* lhs = Expr("lhs");
inner, auto* rhs = Expr("rhs");
});
auto* lhs = create<ast::IdentifierExpression>( continuing = create<ast::BlockStatement>(ast::StatementList{
Source{}, mod.RegisterSymbol("lhs"), "lhs"); create<ast::AssignmentStatement>(lhs, rhs),
auto* rhs = create<ast::IdentifierExpression>( });
Source{}, mod.RegisterSymbol("rhs"), "rhs");
continuing = create<ast::BlockStatement>( auto* outer = create<ast::LoopStatement>(body, continuing);
Source{}, ast::StatementList{
create<ast::AssignmentStatement>(Source{}, lhs, rhs),
});
ast::LoopStatement outer(Source{}, body, continuing);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &outer)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, outer)) << gen.error();
EXPECT_EQ(result(), R"( { EXPECT_EQ(result(), R"( {
bool tint_hlsl_is_first_1 = true; bool tint_hlsl_is_first_1 = true;
for(;;) { for(;;) {
@ -152,47 +142,25 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) {
// } // }
// } // }
ast::type::F32 f32; auto* var = Var("lhs", ast::StorageClass::kFunction, ty.f32, Expr(2.4f),
ast::VariableDecorationList{});
auto* var = create<ast::Variable>( auto* body = create<ast::BlockStatement>(ast::StatementList{
Source{}, // source create<ast::VariableDeclStatement>(var),
"lhs", // name create<ast::VariableDeclStatement>(
ast::StorageClass::kFunction, // storage_class Var("other", ast::StorageClass::kFunction, ty.f32)),
&f32, // type });
false, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 2.4)), // constructor
ast::VariableDecorationList{}); // decorations
auto* body = create<ast::BlockStatement>( auto* lhs = Expr("lhs");
Source{}, auto* rhs = Expr("rhs");
ast::StatementList{
create<ast::VariableDeclStatement>(Source{}, var),
create<ast::VariableDeclStatement>(
Source{}, create<ast::Variable>(
Source{}, // source
"other", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{})),
});
auto* lhs = create<ast::IdentifierExpression>( auto* continuing = create<ast::BlockStatement>(ast::StatementList{
Source{}, mod.RegisterSymbol("lhs"), "lhs"); create<ast::AssignmentStatement>(lhs, rhs),
auto* rhs = create<ast::IdentifierExpression>( });
Source{}, mod.RegisterSymbol("rhs"), "rhs"); auto* outer = create<ast::LoopStatement>(body, continuing);
auto* continuing = create<ast::BlockStatement>(
Source{}, ast::StatementList{
create<ast::AssignmentStatement>(Source{}, lhs, rhs),
});
ast::LoopStatement outer(Source{}, body, continuing);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &outer)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, outer)) << gen.error();
EXPECT_EQ(result(), R"( { EXPECT_EQ(result(), R"( {
bool tint_hlsl_is_first_1 = true; bool tint_hlsl_is_first_1 = true;
float lhs; float lhs;

File diff suppressed because it is too large Load Diff

View File

@ -33,47 +33,19 @@ namespace {
using HlslGeneratorImplTest_ModuleConstant = TestHelper; using HlslGeneratorImplTest_ModuleConstant = TestHelper;
TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) { TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_ModuleConstant) {
ast::type::F32 f32;
ast::type::Array ary(&f32, 3, ast::ArrayDecorationList{});
ast::ExpressionList exprs;
exprs.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 1.0f)));
exprs.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 2.0f)));
exprs.push_back(create<ast::ScalarConstructorExpression>(
Source{}, create<ast::FloatLiteral>(Source{}, &f32, 3.0f)));
auto* var = auto* var =
create<ast::Variable>(Source{}, // source Const("pos", ast::StorageClass::kNone, ty.array<f32, 3>(),
"pos", // name array<f32, 3>(1.f, 2.f, 3.f), ast::VariableDecorationList{});
ast::StorageClass::kNone, // storage_class
&ary, // type
true, // is_const
create<ast::TypeConstructorExpression>(
Source{}, &ary, exprs), // constructor
ast::VariableDecorationList{}); // decorations
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var)) << gen.error(); ASSERT_TRUE(gen.EmitProgramConstVariable(out, var)) << gen.error();
EXPECT_EQ(result(), "static const float pos[3] = {1.0f, 2.0f, 3.0f};\n"); EXPECT_EQ(result(), "static const float pos[3] = {1.0f, 2.0f, 3.0f};\n");
} }
TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant) { TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant) {
ast::type::F32 f32; auto* var = Const("pos", ast::StorageClass::kNone, ty.f32, Expr(3.0f),
ast::VariableDecorationList{
auto* var = create<ast::Variable>( create<ast::ConstantIdDecoration>(23),
Source{}, // source });
"pos", // name
ast::StorageClass::kNone, // storage_class
&f32, // type
true, // is_const
create<ast::ScalarConstructorExpression>(
Source{},
create<ast::FloatLiteral>(Source{}, &f32, 3.0f)), // constructor
ast::VariableDecorationList{
// decorations
create<ast::ConstantIdDecoration>(Source{}, 23),
});
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var)) << gen.error(); ASSERT_TRUE(gen.EmitProgramConstVariable(out, var)) << gen.error();
EXPECT_EQ(result(), R"(#ifndef WGSL_SPEC_CONSTANT_23 EXPECT_EQ(result(), R"(#ifndef WGSL_SPEC_CONSTANT_23
@ -85,19 +57,10 @@ static const float pos = WGSL_SPEC_CONSTANT_23;
} }
TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant_NoConstructor) { TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_SpecConstant_NoConstructor) {
ast::type::F32 f32; auto* var = Const("pos", ast::StorageClass::kNone, ty.f32, nullptr,
ast::VariableDecorationList{
auto* var = create<ast::ConstantIdDecoration>(23),
create<ast::Variable>(Source{}, // source });
"pos", // name
ast::StorageClass::kNone, // storage_class
&f32, // type
true, // is_const
nullptr, // constructor
ast::VariableDecorationList{
// decorations
create<ast::ConstantIdDecoration>(Source{}, 23),
});
ASSERT_TRUE(gen.EmitProgramConstVariable(out, var)) << gen.error(); ASSERT_TRUE(gen.EmitProgramConstVariable(out, var)) << gen.error();
EXPECT_EQ(result(), R"(#ifndef WGSL_SPEC_CONSTANT_23 EXPECT_EQ(result(), R"(#ifndef WGSL_SPEC_CONSTANT_23

View File

@ -28,20 +28,18 @@ namespace {
using HlslGeneratorImplTest_Return = TestHelper; using HlslGeneratorImplTest_Return = TestHelper;
TEST_F(HlslGeneratorImplTest_Return, Emit_Return) { TEST_F(HlslGeneratorImplTest_Return, Emit_Return) {
ast::ReturnStatement r(Source{}); auto* r = create<ast::ReturnStatement>();
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &r)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, r)) << gen.error();
EXPECT_EQ(result(), " return;\n"); EXPECT_EQ(result(), " return;\n");
} }
TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) { TEST_F(HlslGeneratorImplTest_Return, Emit_ReturnWithValue) {
auto* expr = create<ast::IdentifierExpression>( auto* r = create<ast::ReturnStatement>(Expr("expr"));
Source{}, mod.RegisterSymbol("expr"), "expr");
ast::ReturnStatement r(Source{}, expr);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &r)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, r)) << gen.error();
EXPECT_EQ(result(), " return expr;\n"); EXPECT_EQ(result(), " return expr;\n");
} }

View File

@ -31,34 +31,29 @@ namespace {
using HlslGeneratorImplTest_Switch = TestHelper; using HlslGeneratorImplTest_Switch = TestHelper;
TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) { TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
auto* def_body = create<ast::BlockStatement>( auto* def_body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::BreakStatement>(),
create<ast::BreakStatement>(Source{}), });
}); auto* def = create<ast::CaseStatement>(ast::CaseSelectorList{}, def_body);
auto* def =
create<ast::CaseStatement>(Source{}, ast::CaseSelectorList{}, def_body);
ast::type::I32 i32;
ast::CaseSelectorList case_val; ast::CaseSelectorList case_val;
case_val.push_back(create<ast::SintLiteral>(Source{}, &i32, 5)); case_val.push_back(Literal(5));
auto* case_body = create<ast::BlockStatement>( auto* case_body = create<ast::BlockStatement>(ast::StatementList{
Source{}, ast::StatementList{ create<ast::BreakStatement>(),
create<ast::BreakStatement>(Source{}), });
});
auto* case_stmt = create<ast::CaseStatement>(Source{}, case_val, case_body); auto* case_stmt = create<ast::CaseStatement>(case_val, case_body);
ast::CaseStatementList body; ast::CaseStatementList body;
body.push_back(case_stmt); body.push_back(case_stmt);
body.push_back(def); body.push_back(def);
auto* cond = create<ast::IdentifierExpression>( auto* cond = Expr("cond");
Source{}, mod.RegisterSymbol("cond"), "cond"); auto* s = create<ast::SwitchStatement>(cond, body);
ast::SwitchStatement s(Source{}, cond, body);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &s)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, s)) << gen.error();
EXPECT_EQ(result(), R"( switch(cond) { EXPECT_EQ(result(), R"( switch(cond) {
case 5: { case 5: {
break; break;

View File

@ -30,10 +30,10 @@ using HlslGeneratorImplTest = TestHelper;
TEST_F(HlslGeneratorImplTest, Generate) { TEST_F(HlslGeneratorImplTest, Generate) {
ast::type::Void void_type; ast::type::Void void_type;
auto* func = create<ast::Function>( auto* func = create<ast::Function>(
Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, mod->RegisterSymbol("my_func"), "my_func", ast::VariableList{},
&void_type, create<ast::BlockStatement>(Source{}, ast::StatementList{}), &void_type, create<ast::BlockStatement>(ast::StatementList{}),
ast::FunctionDecorationList{}); ast::FunctionDecorationList{});
mod.AddFunction(func); mod->AddFunction(func);
ASSERT_TRUE(gen.Generate(out)) << gen.error(); ASSERT_TRUE(gen.Generate(out)) << gen.error();
EXPECT_EQ(result(), R"(void my_func() { EXPECT_EQ(result(), R"(void my_func() {
@ -57,9 +57,7 @@ TEST_F(HlslGeneratorImplTest, InputStructName_ConflictWithExisting) {
TEST_F(HlslGeneratorImplTest, NameConflictWith_InputStructName) { TEST_F(HlslGeneratorImplTest, NameConflictWith_InputStructName) {
ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in"); ASSERT_EQ(gen.generate_name("func_main_in"), "func_main_in");
ast::IdentifierExpression ident(Source{}, mod.RegisterSymbol("func_main_in"), ASSERT_TRUE(gen.EmitIdentifier(pre, out, Expr("func_main_in")));
"func_main_in");
ASSERT_TRUE(gen.EmitIdentifier(pre, out, &ident));
EXPECT_EQ(result(), "func_main_in_0"); EXPECT_EQ(result(), "func_main_in_0");
} }

View File

@ -44,147 +44,105 @@ namespace {
using HlslGeneratorImplTest_Type = TestHelper; using HlslGeneratorImplTest_Type = TestHelper;
TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias) { TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias) {
ast::type::F32 f32; ast::type::Alias alias(mod->RegisterSymbol("alias"), "alias", ty.f32);
ast::type::Alias alias(mod.RegisterSymbol("alias"), "alias", &f32);
ASSERT_TRUE(gen.EmitType(out, &alias, "")) << gen.error(); ASSERT_TRUE(gen.EmitType(out, &alias, "")) << gen.error();
EXPECT_EQ(result(), "alias"); EXPECT_EQ(result(), "alias");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias_NameCollision) { TEST_F(HlslGeneratorImplTest_Type, EmitType_Alias_NameCollision) {
ast::type::F32 f32; ast::type::Alias alias(mod->RegisterSymbol("bool"), "bool", ty.f32);
ast::type::Alias alias(mod.RegisterSymbol("bool"), "bool", &f32);
ASSERT_TRUE(gen.EmitType(out, &alias, "")) << gen.error(); ASSERT_TRUE(gen.EmitType(out, &alias, "")) << gen.error();
EXPECT_EQ(result(), "bool_tint_0"); EXPECT_EQ(result(), "bool_tint_0");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_Array) { TEST_F(HlslGeneratorImplTest_Type, EmitType_Array) {
ast::type::Bool b; ASSERT_TRUE(gen.EmitType(out, ty.array<bool, 4>(), "ary")) << gen.error();
ast::type::Array a(&b, 4, ast::ArrayDecorationList{});
ASSERT_TRUE(gen.EmitType(out, &a, "ary")) << gen.error();
EXPECT_EQ(result(), "bool ary[4]"); EXPECT_EQ(result(), "bool ary[4]");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArray) { TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArray) {
ast::type::Bool b; auto* arr = ty.array(ty.array<bool, 4>(), 5);
ast::type::Array a(&b, 4, ast::ArrayDecorationList{}); ASSERT_TRUE(gen.EmitType(out, arr, "ary")) << gen.error();
ast::type::Array c(&a, 5, ast::ArrayDecorationList{});
ASSERT_TRUE(gen.EmitType(out, &c, "ary")) << gen.error();
EXPECT_EQ(result(), "bool ary[5][4]"); EXPECT_EQ(result(), "bool ary[5][4]");
} }
// TODO(dsinclair): Is this possible? What order should it output in? // TODO(dsinclair): Is this possible? What order should it output in?
TEST_F(HlslGeneratorImplTest_Type, TEST_F(HlslGeneratorImplTest_Type,
DISABLED_EmitType_ArrayOfArrayOfRuntimeArray) { DISABLED_EmitType_ArrayOfArrayOfRuntimeArray) {
ast::type::Bool b; auto* arr = ty.array(ty.array(ty.array<bool, 4>(), 5), 0);
ast::type::Array a(&b, 4, ast::ArrayDecorationList{}); ASSERT_TRUE(gen.EmitType(out, arr, "ary")) << gen.error();
ast::type::Array c(&a, 5, ast::ArrayDecorationList{});
ast::type::Array d(&c, 0, ast::ArrayDecorationList{});
ASSERT_TRUE(gen.EmitType(out, &c, "ary")) << gen.error();
EXPECT_EQ(result(), "bool ary[5][4][1]"); EXPECT_EQ(result(), "bool ary[5][4][1]");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) { TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) {
ast::type::Bool b; auto* arr = ty.array(ty.array(ty.array<bool, 4>(), 5), 6);
ast::type::Array a(&b, 4, ast::ArrayDecorationList{}); ASSERT_TRUE(gen.EmitType(out, arr, "ary")) << gen.error();
ast::type::Array c(&a, 5, ast::ArrayDecorationList{});
ast::type::Array d(&c, 6, ast::ArrayDecorationList{});
ASSERT_TRUE(gen.EmitType(out, &d, "ary")) << gen.error();
EXPECT_EQ(result(), "bool ary[6][5][4]"); EXPECT_EQ(result(), "bool ary[6][5][4]");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_NameCollision) { TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_NameCollision) {
ast::type::Bool b; ASSERT_TRUE(gen.EmitType(out, ty.array<bool, 4>(), "bool")) << gen.error();
ast::type::Array a(&b, 4, ast::ArrayDecorationList{});
ASSERT_TRUE(gen.EmitType(out, &a, "bool")) << gen.error();
EXPECT_EQ(result(), "bool bool_tint_0[4]"); EXPECT_EQ(result(), "bool bool_tint_0[4]");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_WithoutName) { TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_WithoutName) {
ast::type::Bool b; ASSERT_TRUE(gen.EmitType(out, ty.array<bool, 4>(), "")) << gen.error();
ast::type::Array a(&b, 4, ast::ArrayDecorationList{});
ASSERT_TRUE(gen.EmitType(out, &a, "")) << gen.error();
EXPECT_EQ(result(), "bool[4]"); EXPECT_EQ(result(), "bool[4]");
} }
TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_RuntimeArray) { TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_RuntimeArray) {
ast::type::Bool b; ASSERT_TRUE(gen.EmitType(out, ty.array<bool>(), "ary")) << gen.error();
ast::type::Array a(&b, 0, ast::ArrayDecorationList{});
ASSERT_TRUE(gen.EmitType(out, &a, "ary")) << gen.error();
EXPECT_EQ(result(), "bool ary[]"); EXPECT_EQ(result(), "bool ary[]");
} }
TEST_F(HlslGeneratorImplTest_Type, TEST_F(HlslGeneratorImplTest_Type,
DISABLED_EmitType_RuntimeArray_NameCollision) { DISABLED_EmitType_RuntimeArray_NameCollision) {
ast::type::Bool b; ASSERT_TRUE(gen.EmitType(out, ty.array<bool>(), "double")) << gen.error();
ast::type::Array a(&b, 0, ast::ArrayDecorationList{});
ASSERT_TRUE(gen.EmitType(out, &a, "double")) << gen.error();
EXPECT_EQ(result(), "bool double_tint_0[]"); EXPECT_EQ(result(), "bool double_tint_0[]");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) { TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) {
ast::type::Bool b; ASSERT_TRUE(gen.EmitType(out, ty.bool_, "")) << gen.error();
ASSERT_TRUE(gen.EmitType(out, &b, "")) << gen.error();
EXPECT_EQ(result(), "bool"); EXPECT_EQ(result(), "bool");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_F32) { TEST_F(HlslGeneratorImplTest_Type, EmitType_F32) {
ast::type::F32 f32; ASSERT_TRUE(gen.EmitType(out, ty.f32, "")) << gen.error();
ASSERT_TRUE(gen.EmitType(out, &f32, "")) << gen.error();
EXPECT_EQ(result(), "float"); EXPECT_EQ(result(), "float");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_I32) { TEST_F(HlslGeneratorImplTest_Type, EmitType_I32) {
ast::type::I32 i32; ASSERT_TRUE(gen.EmitType(out, ty.i32, "")) << gen.error();
ASSERT_TRUE(gen.EmitType(out, &i32, "")) << gen.error();
EXPECT_EQ(result(), "int"); EXPECT_EQ(result(), "int");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix) { TEST_F(HlslGeneratorImplTest_Type, EmitType_Matrix) {
ast::type::F32 f32; ASSERT_TRUE(gen.EmitType(out, ty.mat2x3<f32>(), "")) << gen.error();
ast::type::Matrix m(&f32, 3, 2);
ASSERT_TRUE(gen.EmitType(out, &m, "")) << gen.error();
EXPECT_EQ(result(), "float3x2"); EXPECT_EQ(result(), "float3x2");
} }
// TODO(dsinclair): How to annotate as workgroup? // TODO(dsinclair): How to annotate as workgroup?
TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Pointer) { TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Pointer) {
ast::type::F32 f32; ast::type::Pointer p(ty.f32, ast::StorageClass::kWorkgroup);
ast::type::Pointer p(&f32, ast::StorageClass::kWorkgroup);
ASSERT_TRUE(gen.EmitType(out, &p, "")) << gen.error(); ASSERT_TRUE(gen.EmitType(out, &p, "")) << gen.error();
EXPECT_EQ(result(), "float*"); EXPECT_EQ(result(), "float*");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl) { TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl) {
ast::type::I32 i32;
ast::type::F32 f32;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(create<ast::StructMember>( members.push_back(create<ast::StructMember>(
Source{}, "a", &i32, ast::StructMemberDecorationList{})); "a", ty.i32, ast::StructMemberDecorationList{}));
ast::StructMemberDecorationList b_deco; ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(Source{}, 4)); b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4));
members.push_back(create<ast::StructMember>(Source{}, "b", &f32, b_deco)); members.push_back(create<ast::StructMember>("b", ty.f32, b_deco));
auto* str = auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
ast::type::Struct s(mod.RegisterSymbol("S"), "S", str); ast::type::Struct s(mod->RegisterSymbol("S"), "S", str);
ASSERT_TRUE(gen.EmitStructType(out, &s, "S")) << gen.error(); ASSERT_TRUE(gen.EmitStructType(out, &s, "S")) << gen.error();
EXPECT_EQ(result(), R"(struct S { EXPECT_EQ(result(), R"(struct S {
@ -195,46 +153,38 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_StructDecl) {
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) { TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct) {
ast::type::I32 i32;
ast::type::F32 f32;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(create<ast::StructMember>( members.push_back(create<ast::StructMember>(
Source{}, "a", &i32, ast::StructMemberDecorationList{})); "a", ty.i32, ast::StructMemberDecorationList{}));
ast::StructMemberDecorationList b_deco; ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(Source{}, 4)); b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4));
members.push_back(create<ast::StructMember>(Source{}, "b", &f32, b_deco)); members.push_back(create<ast::StructMember>("b", ty.f32, b_deco));
auto* str = auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
ast::type::Struct s(mod.RegisterSymbol("S"), "S", str); ast::type::Struct s(mod->RegisterSymbol("S"), "S", str);
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error(); ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
EXPECT_EQ(result(), "S"); EXPECT_EQ(result(), "S");
} }
TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_InjectPadding) { TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_InjectPadding) {
ast::type::I32 i32;
ast::type::F32 f32;
ast::StructMemberDecorationList decos; ast::StructMemberDecorationList decos;
decos.push_back(create<ast::StructMemberOffsetDecoration>(Source{}, 4)); decos.push_back(create<ast::StructMemberOffsetDecoration>(4));
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(create<ast::StructMember>(Source{}, "a", &i32, decos)); members.push_back(create<ast::StructMember>("a", ty.i32, decos));
decos.push_back(create<ast::StructMemberOffsetDecoration>(Source{}, 32)); decos.push_back(create<ast::StructMemberOffsetDecoration>(32));
members.push_back(create<ast::StructMember>(Source{}, "b", &f32, decos)); members.push_back(create<ast::StructMember>("b", ty.f32, decos));
decos.push_back(create<ast::StructMemberOffsetDecoration>(Source{}, 128)); decos.push_back(create<ast::StructMemberOffsetDecoration>(128));
members.push_back(create<ast::StructMember>(Source{}, "c", &f32, decos)); members.push_back(create<ast::StructMember>("c", ty.f32, decos));
auto* str = auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
ast::type::Struct s(mod.RegisterSymbol("S"), "S", str); ast::type::Struct s(mod->RegisterSymbol("S"), "S", str);
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error(); ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
EXPECT_EQ(result(), R"(struct { EXPECT_EQ(result(), R"(struct {
@ -248,20 +198,16 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_InjectPadding) {
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) { TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
ast::type::I32 i32;
ast::type::F32 f32;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(create<ast::StructMember>( members.push_back(create<ast::StructMember>(
Source{}, "double", &i32, ast::StructMemberDecorationList{})); "double", ty.i32, ast::StructMemberDecorationList{}));
ast::StructMemberDecorationList b_deco; ast::StructMemberDecorationList b_deco;
members.push_back(create<ast::StructMember>(Source{}, "float", &f32, b_deco)); members.push_back(create<ast::StructMember>("float", ty.f32, b_deco));
auto* str = auto* str = create<ast::Struct>(members, ast::StructDecorationList{});
create<ast::Struct>(Source{}, members, ast::StructDecorationList{});
ast::type::Struct s(mod.RegisterSymbol("S"), "S", str); ast::type::Struct s(mod->RegisterSymbol("S"), "S", str);
ASSERT_TRUE(gen.EmitStructType(out, &s, "S")) << gen.error(); ASSERT_TRUE(gen.EmitStructType(out, &s, "S")) << gen.error();
EXPECT_EQ(result(), R"(struct S { EXPECT_EQ(result(), R"(struct S {
@ -273,23 +219,20 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) {
// TODO(dsinclair): How to translate [[block]] // TODO(dsinclair): How to translate [[block]]
TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) { TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) {
ast::type::I32 i32;
ast::type::F32 f32;
ast::StructMemberList members; ast::StructMemberList members;
members.push_back(create<ast::StructMember>( members.push_back(create<ast::StructMember>(
Source{}, "a", &i32, ast::StructMemberDecorationList{})); "a", ty.i32, ast::StructMemberDecorationList{}));
ast::StructMemberDecorationList b_deco; ast::StructMemberDecorationList b_deco;
b_deco.push_back(create<ast::StructMemberOffsetDecoration>(Source{}, 4)); b_deco.push_back(create<ast::StructMemberOffsetDecoration>(4));
members.push_back(create<ast::StructMember>(Source{}, "b", &f32, b_deco)); members.push_back(create<ast::StructMember>("b", ty.f32, b_deco));
ast::StructDecorationList decos; ast::StructDecorationList decos;
decos.push_back(create<ast::StructBlockDecoration>(Source{})); decos.push_back(create<ast::StructBlockDecoration>());
auto* str = create<ast::Struct>(Source{}, members, decos); auto* str = create<ast::Struct>(members, decos);
ast::type::Struct s(mod.RegisterSymbol("S"), "S", str); ast::type::Struct s(mod->RegisterSymbol("S"), "S", str);
ASSERT_TRUE(gen.EmitStructType(out, &s, "B")) << gen.error(); ASSERT_TRUE(gen.EmitStructType(out, &s, "B")) << gen.error();
EXPECT_EQ(result(), R"(struct B { EXPECT_EQ(result(), R"(struct B {
@ -299,24 +242,17 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) {
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_U32) { TEST_F(HlslGeneratorImplTest_Type, EmitType_U32) {
ast::type::U32 u32; ASSERT_TRUE(gen.EmitType(out, ty.u32, "")) << gen.error();
ASSERT_TRUE(gen.EmitType(out, &u32, "")) << gen.error();
EXPECT_EQ(result(), "uint"); EXPECT_EQ(result(), "uint");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_Vector) { TEST_F(HlslGeneratorImplTest_Type, EmitType_Vector) {
ast::type::F32 f32; ASSERT_TRUE(gen.EmitType(out, ty.vec3<f32>(), "")) << gen.error();
ast::type::Vector v(&f32, 3);
ASSERT_TRUE(gen.EmitType(out, &v, "")) << gen.error();
EXPECT_EQ(result(), "float3"); EXPECT_EQ(result(), "float3");
} }
TEST_F(HlslGeneratorImplTest_Type, EmitType_Void) { TEST_F(HlslGeneratorImplTest_Type, EmitType_Void) {
ast::type::Void v; ASSERT_TRUE(gen.EmitType(out, ty.void_, "")) << gen.error();
ASSERT_TRUE(gen.EmitType(out, &v, "")) << gen.error();
EXPECT_EQ(result(), "void"); EXPECT_EQ(result(), "void");
} }
@ -374,8 +310,7 @@ using HlslSampledtexturesTest = TestParamHelper<HlslTextureData>;
TEST_P(HlslSampledtexturesTest, Emit) { TEST_P(HlslSampledtexturesTest, Emit) {
auto params = GetParam(); auto params = GetParam();
ast::type::F32 f32; ast::type::SampledTexture s(params.dim, ty.f32);
ast::type::SampledTexture s(params.dim, &f32);
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error(); ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
EXPECT_EQ(result(), params.result); EXPECT_EQ(result(), params.result);
@ -396,8 +331,7 @@ INSTANTIATE_TEST_SUITE_P(
"TextureCubeArray"})); "TextureCubeArray"}));
TEST_F(HlslGeneratorImplTest_Type, EmitMultisampledTexture) { TEST_F(HlslGeneratorImplTest_Type, EmitMultisampledTexture) {
ast::type::F32 f32; ast::type::MultisampledTexture s(ast::type::TextureDimension::k2d, ty.f32);
ast::type::MultisampledTexture s(ast::type::TextureDimension::k2d, &f32);
ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error(); ASSERT_TRUE(gen.EmitType(out, &s, "")) << gen.error();
EXPECT_EQ(result(), "Texture2D"); EXPECT_EQ(result(), "Texture2D");

View File

@ -37,11 +37,10 @@ using HlslUnaryOpTest = TestParamHelper<UnaryOpData>;
TEST_P(HlslUnaryOpTest, Emit) { TEST_P(HlslUnaryOpTest, Emit) {
auto params = GetParam(); auto params = GetParam();
auto* expr = create<ast::IdentifierExpression>( auto* expr = Expr("expr");
Source{}, mod.RegisterSymbol("expr"), "expr"); auto* op = create<ast::UnaryOpExpression>(params.op, expr);
ast::UnaryOpExpression op(Source{}, params.op, expr);
ASSERT_TRUE(gen.EmitExpression(pre, out, &op)) << gen.error(); ASSERT_TRUE(gen.EmitExpression(pre, out, op)) << gen.error();
EXPECT_EQ(result(), std::string(params.name) + "(expr)"); EXPECT_EQ(result(), std::string(params.name) + "(expr)");
} }
INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_UnaryOp, INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_UnaryOp,

View File

@ -33,163 +33,85 @@ namespace {
using HlslGeneratorImplTest_VariableDecl = TestHelper; using HlslGeneratorImplTest_VariableDecl = TestHelper;
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) { TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) {
ast::type::F32 f32; auto* var = Var("a", ast::StorageClass::kNone, ty.f32);
auto* var =
create<ast::Variable>(Source{}, // source
"a", // name
ast::StorageClass::kNone, // storage_class
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(Source{}, var); auto* stmt = create<ast::VariableDeclStatement>(var);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
EXPECT_EQ(result(), " float a;\n"); EXPECT_EQ(result(), " float a;\n");
} }
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) { TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) {
ast::type::F32 f32; auto* var = Const("a", ast::StorageClass::kNone, ty.f32);
auto* var =
create<ast::Variable>(Source{}, // source
"a", // name
ast::StorageClass::kNone, // storage_class
&f32, // type
true, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(Source{}, var); auto* stmt = create<ast::VariableDeclStatement>(var);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
EXPECT_EQ(result(), " const float a;\n"); EXPECT_EQ(result(), " const float a;\n");
} }
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Array) { TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Array) {
ast::type::F32 f32; auto* var = Var("a", ast::StorageClass::kNone, ty.array<f32, 5>());
ast::type::Array ary(&f32, 5, ast::ArrayDecorationList{});
auto* var = auto* stmt = create<ast::VariableDeclStatement>(var);
create<ast::Variable>(Source{}, // source
"a", // name
ast::StorageClass::kNone, // storage_class
&ary, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(Source{}, var);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
EXPECT_EQ(result(), " float a[5];\n"); EXPECT_EQ(result(), " float a[5];\n");
} }
TEST_F(HlslGeneratorImplTest_VariableDecl, TEST_F(HlslGeneratorImplTest_VariableDecl,
Emit_VariableDeclStatement_Function) { Emit_VariableDeclStatement_Function) {
ast::type::F32 f32; auto* var = Var("a", ast::StorageClass::kFunction, ty.f32);
auto* var =
create<ast::Variable>(Source{}, // source
"a", // name
ast::StorageClass::kFunction, // storage_class
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(Source{}, var); auto* stmt = create<ast::VariableDeclStatement>(var);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
EXPECT_EQ(result(), " float a;\n"); EXPECT_EQ(result(), " float a;\n");
} }
TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) { TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) {
ast::type::F32 f32; auto* var = Var("a", ast::StorageClass::kPrivate, ty.f32);
auto* var =
create<ast::Variable>(Source{}, // source
"a", // name
ast::StorageClass::kPrivate, // storage_class
&f32, // type
false, // is_const
nullptr, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(Source{}, var); auto* stmt = create<ast::VariableDeclStatement>(var);
gen.increment_indent(); gen.increment_indent();
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error(); ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
EXPECT_EQ(result(), " float a;\n"); EXPECT_EQ(result(), " float a;\n");
} }
TEST_F(HlslGeneratorImplTest_VariableDecl, TEST_F(HlslGeneratorImplTest_VariableDecl,
Emit_VariableDeclStatement_Initializer_Private) { Emit_VariableDeclStatement_Initializer_Private) {
auto* ident = create<ast::IdentifierExpression>( auto* var = Var("a", ast::StorageClass::kNone, ty.f32, Expr("initializer"),
Source{}, mod.RegisterSymbol("initializer"), "initializer"); ast::VariableDecorationList{});
ast::type::F32 f32; auto* stmt = create<ast::VariableDeclStatement>(var);
auto* var = ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
create<ast::Variable>(Source{}, // source
"a", // name
ast::StorageClass::kNone, // storage_class
&f32, // type
false, // is_const
ident, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(Source{}, var);
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
EXPECT_EQ(result(), R"(float a = initializer; EXPECT_EQ(result(), R"(float a = initializer;
)"); )");
} }
TEST_F(HlslGeneratorImplTest_VariableDecl, TEST_F(HlslGeneratorImplTest_VariableDecl,
Emit_VariableDeclStatement_Initializer_ZeroVec) { Emit_VariableDeclStatement_Initializer_ZeroVec) {
ast::type::F32 f32; auto* var = Var("a", ast::StorageClass::kNone, ty.vec3<f32>(), vec3<f32>(),
ast::type::Vector vec(&f32, 3); ast::VariableDecorationList{});
ast::ExpressionList values; auto* stmt = create<ast::VariableDeclStatement>(var);
auto* zero_vec = ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
create<ast::TypeConstructorExpression>(Source{}, &vec, values);
auto* var =
create<ast::Variable>(Source{}, // source
"a", // name
ast::StorageClass::kNone, // storage_class
&vec, // type
false, // is_const
zero_vec, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(Source{}, var);
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
EXPECT_EQ(result(), R"(float3 a = float3(0.0f); EXPECT_EQ(result(), R"(float3 a = float3(0.0f);
)"); )");
} }
TEST_F(HlslGeneratorImplTest_VariableDecl, TEST_F(HlslGeneratorImplTest_VariableDecl,
Emit_VariableDeclStatement_Initializer_ZeroMat) { Emit_VariableDeclStatement_Initializer_ZeroMat) {
ast::type::F32 f32; auto* var = Var("a", ast::StorageClass::kNone, ty.mat2x3<f32>(),
ast::type::Matrix mat(&f32, 3, 2); mat2x3<f32>(), ast::VariableDecorationList{});
ast::ExpressionList values; auto* stmt = create<ast::VariableDeclStatement>(var);
auto* zero_mat = ASSERT_TRUE(gen.EmitStatement(out, stmt)) << gen.error();
create<ast::TypeConstructorExpression>(Source{}, &mat, values);
auto* var =
create<ast::Variable>(Source{}, // source
"a", // name
ast::StorageClass::kNone, // storage_class
&mat, // type
false, // is_const
zero_mat, // constructor
ast::VariableDecorationList{}); // decorations
ast::VariableDeclStatement stmt(Source{}, var);
ASSERT_TRUE(gen.EmitStatement(out, &stmt)) << gen.error();
EXPECT_EQ(result(), EXPECT_EQ(result(),
R"(float3x2 a = float3x2(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); R"(float3x2 a = float3x2(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
)"); )");

View File

@ -21,7 +21,7 @@
#include <utility> #include <utility>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/ast/module.h" #include "src/ast/builder.h"
#include "src/type_determiner.h" #include "src/type_determiner.h"
#include "src/writer/hlsl/generator_impl.h" #include "src/writer/hlsl/generator_impl.h"
@ -31,9 +31,9 @@ namespace hlsl {
/// Helper class for testing /// Helper class for testing
template <typename BODY> template <typename BODY>
class TestHelperBase : public BODY { class TestHelperBase : public BODY, public ast::BuilderWithModule {
public: public:
TestHelperBase() : td(&mod), gen(&mod) {} TestHelperBase() : td(mod), gen(mod) {}
~TestHelperBase() = default; ~TestHelperBase() = default;
/// @returns the result string /// @returns the result string
@ -42,17 +42,6 @@ class TestHelperBase : public BODY {
/// @returns the pre result string /// @returns the pre result string
std::string pre_result() const { return pre.str(); } std::string pre_result() const { return pre.str(); }
/// Creates a new `ast::Node` owned by the Module. When the Module is
/// destructed, the `ast::Node` will also be destructed.
/// @param args the arguments to pass to the type constructor
/// @returns the node pointer template <typename T, typename... ARGS>
template <typename T, typename... ARGS>
T* create(ARGS&&... args) {
return mod.create<T>(std::forward<ARGS>(args)...);
}
/// The module
ast::Module mod;
/// The type determiner /// The type determiner
TypeDeterminer td; TypeDeterminer td;
/// The generator /// The generator