From 2194a842bac20c032740e2dd14fbd275e2bd2c4c Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 12 Nov 2021 13:53:49 +0000 Subject: [PATCH] ProgramBuilder: Remove Literal() helpers Now that all LiteralExpressions derive from Expression, and Expr() already handles literals, there's no reason to have this duplicated functionality. Bug: tint:888 Change-Id: I677b04a3cc325311ef25f6b9983fee7548e830f4 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69105 Kokoro: Kokoro Reviewed-by: James Price --- src/ast/switch_statement_test.cc | 6 +- src/program_builder.h | 56 +-------- src/resolver/compound_statement_test.cc | 5 +- src/resolver/control_block_validation_test.cc | 51 ++++---- src/resolver/function_validation_test.cc | 6 +- src/resolver/resolver_test.cc | 2 +- .../type_constructor_validation_test.cc | 117 +++++++++--------- src/resolver/validation_test.cc | 6 +- src/writer/glsl/generator_impl_case_test.cc | 15 ++- src/writer/glsl/generator_impl_switch_test.cc | 2 +- src/writer/hlsl/generator_impl_case_test.cc | 16 +-- src/writer/hlsl/generator_impl_switch_test.cc | 6 +- src/writer/msl/generator_impl_case_test.cc | 15 ++- src/writer/msl/generator_impl_switch_test.cc | 2 +- src/writer/spirv/builder_switch_test.cc | 31 +++-- src/writer/wgsl/generator_impl_case_test.cc | 8 +- src/writer/wgsl/generator_impl_switch_test.cc | 2 +- 17 files changed, 143 insertions(+), 203 deletions(-) diff --git a/src/ast/switch_statement_test.cc b/src/ast/switch_statement_test.cc index ed2f8406b1..593f0aa3d5 100644 --- a/src/ast/switch_statement_test.cc +++ b/src/ast/switch_statement_test.cc @@ -66,7 +66,7 @@ TEST_F(SwitchStatementTest, Assert_Null_Condition) { ProgramBuilder b; CaseStatementList cases; cases.push_back( - b.create(CaseSelectorList{b.Literal(1)}, b.Block())); + b.create(CaseSelectorList{b.Expr(1)}, b.Block())); b.create(nullptr, cases); }, "internal compiler error"); @@ -89,7 +89,7 @@ TEST_F(SwitchStatementTest, Assert_DifferentProgramID_Condition) { b1.create(b2.Expr(true), CaseStatementList{ b1.create( CaseSelectorList{ - b1.Literal(1), + b1.Expr(1), }, b1.Block()), }); @@ -105,7 +105,7 @@ TEST_F(SwitchStatementTest, Assert_DifferentProgramID_CaseStatement) { b1.create(b1.Expr(true), CaseStatementList{ b2.create( CaseSelectorList{ - b2.Literal(1), + b2.Expr(1), }, b2.Block()), }); diff --git a/src/program_builder.h b/src/program_builder.h index fd8b19479a..6d87945ef6 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -1037,7 +1037,7 @@ class ProgramBuilder { /// @param source the source information /// @param value the boolean value /// @return a Scalar constructor for the given value - const ast::LiteralExpression* Expr(const Source& source, bool value) { + const ast::BoolLiteralExpression* Expr(const Source& source, bool value) { return create(source, value); } @@ -1063,7 +1063,7 @@ class ProgramBuilder { /// @param source the source information /// @param value the integer value /// @return a Scalar constructor for the given value - const ast::LiteralExpression* Expr(const Source& source, i32 value) { + const ast::SintLiteralExpression* Expr(const Source& source, i32 value) { return create(source, value); } @@ -1124,58 +1124,6 @@ class ProgramBuilder { /// @return `list` ast::ExpressionList ExprList(ast::ExpressionList list) { return list; } - /// @param source the source location for the literal - /// @param val the boolan value - /// @return a boolean literal with the given value - const ast::BoolLiteralExpression* Literal(const Source& source, bool val) { - return create(source, val); - } - - /// @param val the boolan value - /// @return a boolean literal with the given value - const ast::BoolLiteralExpression* Literal(bool val) { - return create(val); - } - - /// @param source the source location for the literal - /// @param val the float value - /// @return a float literal with the given value - const ast::FloatLiteralExpression* Literal(const Source& source, f32 val) { - return create(source, val); - } - - /// @param val the float value - /// @return a float literal with the given value - const ast::FloatLiteralExpression* Literal(f32 val) { - return create(val); - } - - /// @param source the source location for the literal - /// @param val the unsigned int value - /// @return a ast::UintLiteral with the given value - const ast::UintLiteralExpression* Literal(const Source& source, u32 val) { - return create(source, val); - } - - /// @param val the unsigned int value - /// @return a ast::UintLiteral with the given value - const ast::UintLiteralExpression* Literal(u32 val) { - return create(val); - } - - /// @param source the source location for the literal - /// @param val the integer value - /// @return the ast::SintLiteral with the given value - const ast::SintLiteralExpression* Literal(const Source& source, i32 val) { - return create(source, val); - } - - /// @param val the integer value - /// @return the ast::SintLiteral with the given value - const ast::SintLiteralExpression* Literal(i32 val) { - return create(val); - } - /// @param args the arguments for the type constructor /// @return an `ast::TypeConstructorExpression` of type `ty`, with the values /// of `args` converted to `ast::Expression`s using `Expr()` diff --git a/src/resolver/compound_statement_test.cc b/src/resolver/compound_statement_test.cc index 2ace78e4b0..db91d7cc6c 100644 --- a/src/resolver/compound_statement_test.cc +++ b/src/resolver/compound_statement_test.cc @@ -318,9 +318,8 @@ TEST_F(ResolverCompoundStatementTest, Switch) { auto* stmt_a = Ignore(1); auto* stmt_b = Ignore(1); auto* stmt_c = Ignore(1); - auto* swi = - Switch(expr, Case(Literal(1), Block(stmt_a)), - Case(Literal(2), Block(stmt_b)), DefaultCase(Block(stmt_c))); + auto* swi = Switch(expr, Case(Expr(1), Block(stmt_a)), + Case(Expr(2), Block(stmt_b)), DefaultCase(Block(stmt_c))); WrapInFunction(swi); ASSERT_TRUE(r()->Resolve()) << r()->error(); diff --git a/src/resolver/control_block_validation_test.cc b/src/resolver/control_block_validation_test.cc index c317a42b91..890892e3b8 100644 --- a/src/resolver/control_block_validation_test.cc +++ b/src/resolver/control_block_validation_test.cc @@ -52,7 +52,7 @@ TEST_F(ResolverControlBlockValidationTest, SwitchWithoutDefault_Fail) { auto* block = Block(Decl(var), // Switch(Source{{12, 34}}, "a", // - Case(Literal(1)))); + Case(Expr(1)))); WrapInFunction(block); @@ -70,10 +70,10 @@ TEST_F(ResolverControlBlockValidationTest, SwitchWithTwoDefault_Fail) { // } auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2)); - auto* block = Block(Decl(var), // - Switch("a", // - DefaultCase(), // - Case(Literal(1)), // + auto* block = Block(Decl(var), // + Switch("a", // + DefaultCase(), // + Case(Expr(1)), // DefaultCase(Source{{12, 34}}))); WrapInFunction(block); @@ -155,9 +155,9 @@ TEST_F(ResolverControlBlockValidationTest, UnreachableCode_break) { auto* decl = Decl(Source{{12, 34}}, Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2))); - WrapInFunction( // - Loop(Block(Switch(1, // - Case(Literal(1), Block(Break(), decl)), // + WrapInFunction( // + Loop(Block(Switch(1, // + Case(Expr(1), Block(Break(), decl)), // DefaultCase())))); EXPECT_FALSE(r()->Resolve()); @@ -176,7 +176,7 @@ TEST_F(ResolverControlBlockValidationTest, UnreachableCode_break_InBlocks) { WrapInFunction(Loop( Block(Switch(1, // - Case(Literal(1), Block(Block(Block(Block(Break()))), decl)), + Case(Expr(1), Block(Block(Block(Block(Break()))), decl)), DefaultCase())))); EXPECT_FALSE(r()->Resolve()); @@ -192,10 +192,9 @@ TEST_F(ResolverControlBlockValidationTest, // } auto* var = Var("a", ty.i32(), ast::StorageClass::kNone, Expr(2)); - auto* block = - Block(Decl(var), Switch("a", // - Case(Source{{12, 34}}, {Literal(1u)}), // - DefaultCase())); + auto* block = Block(Decl(var), Switch("a", // + Case(Source{{12, 34}}, {Expr(1u)}), // + DefaultCase())); WrapInFunction(block); EXPECT_FALSE(r()->Resolve()); @@ -213,9 +212,9 @@ TEST_F(ResolverControlBlockValidationTest, // } auto* var = Var("a", ty.u32(), ast::StorageClass::kNone, Expr(2u)); - auto* block = Block(Decl(var), // - Switch("a", // - Case(Source{{12, 34}}, {Literal(-1)}), // + auto* block = Block(Decl(var), // + Switch("a", // + Case(Source{{12, 34}}, {Expr(-1)}), // DefaultCase())); WrapInFunction(block); @@ -237,11 +236,11 @@ TEST_F(ResolverControlBlockValidationTest, auto* block = Block(Decl(var), // Switch("a", // - Case(Literal(0u)), + Case(Expr(0u)), Case({ - Literal(Source{{12, 34}}, 2u), - Literal(3u), - Literal(Source{{56, 78}}, 2u), + Expr(Source{{12, 34}}, 2u), + Expr(3u), + Expr(Source{{56, 78}}, 2u), }), DefaultCase())); WrapInFunction(block); @@ -264,12 +263,12 @@ TEST_F(ResolverControlBlockValidationTest, auto* block = Block(Decl(var), // Switch("a", // - Case(Literal(Source{{12, 34}}, -10)), + Case(Expr(Source{{12, 34}}, -10)), Case({ - Literal(0), - Literal(1), - Literal(2), - Literal(Source{{56, 78}}, -10), + Expr(0), + Expr(1), + Expr(2), + Expr(Source{{56, 78}}, -10), }), DefaultCase())); WrapInFunction(block); @@ -310,7 +309,7 @@ TEST_F(ResolverControlBlockValidationTest, SwitchCase_Pass) { auto* block = Block(Decl(var), // Switch("a", // DefaultCase(Source{{12, 34}}), // - Case(Literal(5)))); + Case(Expr(5)))); WrapInFunction(block); EXPECT_TRUE(r()->Resolve()) << r()->error(); diff --git a/src/resolver/function_validation_test.cc b/src/resolver/function_validation_test.cc index 825b9cae0f..93a9b3ff87 100644 --- a/src/resolver/function_validation_test.cc +++ b/src/resolver/function_validation_test.cc @@ -582,7 +582,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_Literal_BadType) { Func("main", {}, ty.void_(), {}, {Stage(ast::PipelineStage::kCompute), - WorkgroupSize(Literal(Source{{12, 34}}, 64.f))}); + WorkgroupSize(Expr(Source{{12, 34}}, 64.f))}); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -596,7 +596,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_Literal_Negative) { Func("main", {}, ty.void_(), {}, {Stage(ast::PipelineStage::kCompute), - WorkgroupSize(Literal(Source{{12, 34}}, -2))}); + WorkgroupSize(Expr(Source{{12, 34}}, -2))}); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -609,7 +609,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_Literal_Zero) { Func("main", {}, ty.void_(), {}, {Stage(ast::PipelineStage::kCompute), - WorkgroupSize(Literal(Source{{12, 34}}, 0))}); + WorkgroupSize(Expr(Source{{12, 34}}, 0))}); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), diff --git a/src/resolver/resolver_test.cc b/src/resolver/resolver_test.cc index f6d465b219..a1a3f5bdc0 100644 --- a/src/resolver/resolver_test.cc +++ b/src/resolver/resolver_test.cc @@ -248,7 +248,7 @@ TEST_F(ResolverTest, Stmt_Switch) { auto* lhs = Expr("v"); auto* rhs = Expr(2.3f); auto* case_block = Block(Assign(lhs, rhs)); - auto* stmt = Switch(Expr(2), Case(Literal(3), case_block), DefaultCase()); + auto* stmt = Switch(Expr(2), Case(Expr(3), case_block), DefaultCase()); WrapInFunction(v, stmt); EXPECT_TRUE(r()->Resolve()) << r()->error(); diff --git a/src/resolver/type_constructor_validation_test.cc b/src/resolver/type_constructor_validation_test.cc index 764d2ed8b9..10d86e5474 100644 --- a/src/resolver/type_constructor_validation_test.cc +++ b/src/resolver/type_constructor_validation_test.cc @@ -424,7 +424,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Array_type_match) { // array(0u, 10u. 20u); - auto* tc = array(Literal(0u), Literal(10u), Literal(20u)); + auto* tc = array(Expr(0u), Expr(10u), Expr(20u)); WrapInFunction(tc); EXPECT_TRUE(r()->Resolve()); @@ -433,8 +433,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Array_type_Mismatch_U32F32) { // array(0u, 1.0f, 20u); - auto* tc = - array(Literal(0u), Literal(Source{{12, 34}}, 1.0f), Literal(20u)); + auto* tc = array(Expr(0u), Expr(Source{{12, 34}}, 1.0f), Expr(20u)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -446,7 +445,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Array_ScalarArgumentTypeMismatch_F32I32) { // array(1); - auto* tc = array(Literal(Source{{12, 34}}, 1)); + auto* tc = array(Expr(Source{{12, 34}}, 1)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -458,8 +457,8 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Array_ScalarArgumentTypeMismatch_U32I32) { // array(1, 0u, 0u, 0u, 0u, 0u); - auto* tc = array(Literal(Source{{12, 34}}, 1), Literal(0u), - Literal(0u), Literal(0u), Literal(0u)); + auto* tc = array(Expr(Source{{12, 34}}, 1), Expr(0u), Expr(0u), + Expr(0u), Expr(0u)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -471,9 +470,9 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Array_ScalarArgumentTypeMismatch_Vec2) { // array(1, vec2()); - auto* tc = array(Literal(1), - create( - Source{{12, 34}}, ty.vec2(), ExprList())); + auto* tc = + array(Expr(1), create( + Source{{12, 34}}, ty.vec2(), ExprList())); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -545,7 +544,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Array_TooFewElements) { // array(1, 2, 3); SetSource(Source::Location({12, 34})); - auto* tc = array(Literal(1), Literal(2), Literal(3)); + auto* tc = array(Expr(1), Expr(2), Expr(3)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -558,8 +557,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Array_TooManyElements) { // array(1, 2, 3, 4, 5); SetSource(Source::Location({12, 34})); - auto* tc = - array(Literal(1), Literal(2), Literal(3), Literal(4), Literal(5)); + auto* tc = array(Expr(1), Expr(2), Expr(3), Expr(4), Expr(5)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -571,7 +569,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Array_Runtime) { // array(1); - auto* tc = array(ty.i32(), nullptr, Literal(Source{{12, 34}}, 1)); + auto* tc = array(ty.i32(), nullptr, Expr(Source{{12, 34}}, 1)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -594,7 +592,7 @@ namespace VectorConstructor { TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2F32_Error_ScalarArgumentTypeMismatch) { - auto* tc = vec2(Literal(Source{{12, 34}}, 1), 1.0f); + auto* tc = vec2(Expr(Source{{12, 34}}, 1), 1.0f); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -605,7 +603,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2U32_Error_ScalarArgumentTypeMismatch) { - auto* tc = vec2(1u, Literal(Source{{12, 34}}, 1)); + auto* tc = vec2(1u, Expr(Source{{12, 34}}, 1)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -616,7 +614,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2I32_Error_ScalarArgumentTypeMismatch) { - auto* tc = vec2(Literal(Source{{12, 34}}, 1u), 1); + auto* tc = vec2(Expr(Source{{12, 34}}, 1u), 1); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -627,7 +625,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2Bool_Error_ScalarArgumentTypeMismatch) { - auto* tc = vec2(true, Literal(Source{{12, 34}}, 1)); + auto* tc = vec2(true, Expr(Source{{12, 34}}, 1)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -662,9 +660,9 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2_Error_TooManyArgumentsScalar) { - auto* tc = vec2(Literal(Source{{12, 34}}, 1.0f), - Literal(Source{{12, 40}}, 1.0f), - Literal(Source{{12, 46}}, 1.0f)); + auto* tc = + vec2(Expr(Source{{12, 34}}, 1.0f), Expr(Source{{12, 40}}, 1.0f), + Expr(Source{{12, 46}}, 1.0f)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -691,7 +689,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec2_Error_TooManyArgumentsVectorAndScalar) { auto* tc = vec2(create( Source{{12, 34}}, ty.vec2(), ExprList()), - Literal(Source{{12, 40}}, 1.0f)); + Expr(Source{{12, 40}}, 1.0f)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -805,7 +803,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3F32_Error_ScalarArgumentTypeMismatch) { - auto* tc = vec3(1.0f, 1.0f, Literal(Source{{12, 34}}, 1)); + auto* tc = vec3(1.0f, 1.0f, Expr(Source{{12, 34}}, 1)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -816,7 +814,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3U32_Error_ScalarArgumentTypeMismatch) { - auto* tc = vec3(1u, Literal(Source{{12, 34}}, 1), 1u); + auto* tc = vec3(1u, Expr(Source{{12, 34}}, 1), 1u); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -827,7 +825,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3I32_Error_ScalarArgumentTypeMismatch) { - auto* tc = vec3(1, Literal(Source{{12, 34}}, 1u), 1); + auto* tc = vec3(1, Expr(Source{{12, 34}}, 1u), 1); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -838,7 +836,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3Bool_Error_ScalarArgumentTypeMismatch) { - auto* tc = vec3(true, Literal(Source{{12, 34}}, 1), false); + auto* tc = vec3(true, Expr(Source{{12, 34}}, 1), false); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -861,8 +859,8 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3_Error_TooFewArgumentsScalar) { - auto* tc = vec3(Literal(Source{{12, 34}}, 1.0f), - Literal(Source{{12, 40}}, 1.0f)); + auto* tc = + vec3(Expr(Source{{12, 34}}, 1.0f), Expr(Source{{12, 40}}, 1.0f)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -873,9 +871,9 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3_Error_TooManyArgumentsScalar) { - auto* tc = vec3( - Literal(Source{{12, 34}}, 1.0f), Literal(Source{{12, 40}}, 1.0f), - Literal(Source{{12, 46}}, 1.0f), Literal(Source{{12, 52}}, 1.0f)); + auto* tc = + vec3(Expr(Source{{12, 34}}, 1.0f), Expr(Source{{12, 40}}, 1.0f), + Expr(Source{{12, 46}}, 1.0f), Expr(Source{{12, 52}}, 1.0f)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -912,10 +910,10 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3_Error_TooManyArgumentsVec2AndScalar) { - auto* tc = vec3(create( - Source{{12, 34}}, ty.vec2(), ExprList()), - Literal(Source{{12, 40}}, 1.0f), - Literal(Source{{12, 46}}, 1.0f)); + auto* tc = + vec3(create( + Source{{12, 34}}, ty.vec2(), ExprList()), + Expr(Source{{12, 40}}, 1.0f), Expr(Source{{12, 46}}, 1.0f)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -928,7 +926,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec3_Error_TooManyArgumentsVec3) { auto* tc = vec3(create( Source{{12, 34}}, ty.vec3(), ExprList()), - Literal(Source{{12, 40}}, 1.0f)); + Expr(Source{{12, 40}}, 1.0f)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1068,7 +1066,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec4F32_Error_ScalarArgumentTypeMismatch) { - auto* tc = vec4(1.0f, 1.0f, Literal(Source{{12, 34}}, 1), 1.0f); + auto* tc = vec4(1.0f, 1.0f, Expr(Source{{12, 34}}, 1), 1.0f); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1079,7 +1077,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec4U32_Error_ScalarArgumentTypeMismatch) { - auto* tc = vec4(1u, 1u, Literal(Source{{12, 34}}, 1), 1u); + auto* tc = vec4(1u, 1u, Expr(Source{{12, 34}}, 1), 1u); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1090,7 +1088,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec4I32_Error_ScalarArgumentTypeMismatch) { - auto* tc = vec4(1, 1, Literal(Source{{12, 34}}, 1u), 1); + auto* tc = vec4(1, 1, Expr(Source{{12, 34}}, 1u), 1); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1101,7 +1099,7 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec4Bool_Error_ScalarArgumentTypeMismatch) { - auto* tc = vec4(true, false, Literal(Source{{12, 34}}, 1), true); + auto* tc = vec4(true, false, Expr(Source{{12, 34}}, 1), true); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1112,9 +1110,9 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec4_Error_TooFewArgumentsScalar) { - auto* tc = vec4(Literal(Source{{12, 34}}, 1.0f), - Literal(Source{{12, 40}}, 1.0f), - Literal(Source{{12, 46}}, 1.0f)); + auto* tc = + vec4(Expr(Source{{12, 34}}, 1.0f), Expr(Source{{12, 40}}, 1.0f), + Expr(Source{{12, 46}}, 1.0f)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1125,10 +1123,10 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec4_Error_TooManyArgumentsScalar) { - auto* tc = vec4( - Literal(Source{{12, 34}}, 1.0f), Literal(Source{{12, 40}}, 1.0f), - Literal(Source{{12, 46}}, 1.0f), Literal(Source{{12, 52}}, 1.0f), - Literal(Source{{12, 58}}, 1.0f)); + auto* tc = + vec4(Expr(Source{{12, 34}}, 1.0f), Expr(Source{{12, 40}}, 1.0f), + Expr(Source{{12, 46}}, 1.0f), Expr(Source{{12, 52}}, 1.0f), + Expr(Source{{12, 58}}, 1.0f)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1141,7 +1139,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec4_Error_TooFewArgumentsVec2AndScalar) { auto* tc = vec4(create( Source{{12, 34}}, ty.vec2(), ExprList()), - Literal(Source{{12, 40}}, 1.0f)); + Expr(Source{{12, 40}}, 1.0f)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1152,11 +1150,11 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec4_Error_TooManyArgumentsVec2AndScalars) { - auto* tc = vec4(create( - Source{{12, 34}}, ty.vec2(), ExprList()), - Literal(Source{{12, 40}}, 1.0f), - Literal(Source{{12, 46}}, 1.0f), - Literal(Source{{12, 52}}, 1.0f)); + auto* tc = + vec4(create( + Source{{12, 34}}, ty.vec2(), ExprList()), + Expr(Source{{12, 40}}, 1.0f), Expr(Source{{12, 46}}, 1.0f), + Expr(Source{{12, 52}}, 1.0f)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1171,7 +1169,7 @@ TEST_F(ResolverTypeConstructorValidationTest, Source{{12, 34}}, ty.vec2(), ExprList()), create( Source{{12, 40}}, ty.vec2(), ExprList()), - Literal(Source{{12, 46}}, 1.0f)); + Expr(Source{{12, 46}}, 1.0f)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1210,10 +1208,10 @@ TEST_F(ResolverTypeConstructorValidationTest, TEST_F(ResolverTypeConstructorValidationTest, Expr_Constructor_Vec4_Error_TooManyArgumentsVec3AndScalars) { - auto* tc = vec4(create( - Source{{12, 34}}, ty.vec3(), ExprList()), - Literal(Source{{12, 40}}, 1.0f), - Literal(Source{{12, 46}}, 1.0f)); + auto* tc = + vec4(create( + Source{{12, 34}}, ty.vec3(), ExprList()), + Expr(Source{{12, 40}}, 1.0f), Expr(Source{{12, 46}}, 1.0f)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1505,8 +1503,7 @@ TEST_F(ResolverTypeConstructorValidationTest, // vec2(1.0f, 1u) auto* vec_type = ty.vec(ty.Of(f32_alias), 2); auto* tc = create( - Source{{12, 34}}, vec_type, - ExprList(1.0f, Literal(Source{{12, 40}}, 1u))); + Source{{12, 34}}, vec_type, ExprList(1.0f, Expr(Source{{12, 40}}, 1u))); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1696,7 +1693,7 @@ TEST_P(MatrixConstructorTest, ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns; i++) { - args.push_back(Literal(Source{{12, i}}, 1u)); + args.push_back(Expr(Source{{12, i}}, 1u)); } auto* matrix_type = ty.mat(param.columns, param.rows); diff --git a/src/resolver/validation_test.cc b/src/resolver/validation_test.cc index 01f52d025b..3d27e0392f 100644 --- a/src/resolver/validation_test.cc +++ b/src/resolver/validation_test.cc @@ -129,7 +129,7 @@ TEST_F(ResolverValidationTest, Stmt_Error_Unknown) { TEST_F(ResolverValidationTest, Stmt_If_NonBool) { // if (1.23f) {} - WrapInFunction(If(Literal(Source{{12, 34}}, 1.23f), Block())); + WrapInFunction(If(Expr(Source{{12, 34}}, 1.23f), Block())); EXPECT_FALSE(r()->Resolve()); @@ -141,7 +141,7 @@ TEST_F(ResolverValidationTest, Stmt_Else_NonBool) { // else (1.23f) {} WrapInFunction( - If(Expr(true), Block(), Else(Literal(Source{{12, 34}}, 1.23f), Block()))); + If(Expr(true), Block(), Else(Expr(Source{{12, 34}}, 1.23f), Block()))); EXPECT_FALSE(r()->Resolve()); @@ -931,7 +931,7 @@ TEST_F(ResolverValidationTest, Stmt_BreakInLoop) { TEST_F(ResolverValidationTest, Stmt_BreakInSwitch) { WrapInFunction(Loop(Block(Switch( Expr(1), - Case(Literal(1), Block(create(Source{{12, 34}}))), + Case(Expr(1), Block(create(Source{{12, 34}}))), DefaultCase())))); EXPECT_TRUE(r()->Resolve()) << r()->error(); } diff --git a/src/writer/glsl/generator_impl_case_test.cc b/src/writer/glsl/generator_impl_case_test.cc index e12a4966e6..fbeb873a76 100644 --- a/src/writer/glsl/generator_impl_case_test.cc +++ b/src/writer/glsl/generator_impl_case_test.cc @@ -23,7 +23,7 @@ namespace { using GlslGeneratorImplTest_Case = TestHelper; TEST_F(GlslGeneratorImplTest_Case, Emit_Case) { - auto* s = Switch(1, Case(Literal(5), Block(create())), + auto* s = Switch(1, Case(Expr(5), Block(create())), DefaultCase()); WrapInFunction(s); @@ -39,7 +39,7 @@ TEST_F(GlslGeneratorImplTest_Case, Emit_Case) { } TEST_F(GlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) { - auto* s = Switch(1, Case(Literal(5), Block()), DefaultCase()); + auto* s = Switch(1, Case(Expr(5), Block()), DefaultCase()); WrapInFunction(s); GeneratorImpl& gen = Build(); @@ -54,9 +54,8 @@ TEST_F(GlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) { } TEST_F(GlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) { - auto* s = - Switch(1, Case(Literal(5), Block(create())), - DefaultCase()); + auto* s = Switch(1, Case(Expr(5), Block(create())), + DefaultCase()); WrapInFunction(s); GeneratorImpl& gen = Build(); @@ -71,9 +70,9 @@ TEST_F(GlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) { } TEST_F(GlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) { - auto* s = Switch( - 1, Case({Literal(5), Literal(6)}, Block(create())), - DefaultCase()); + auto* s = + Switch(1, Case({Expr(5), Expr(6)}, Block(create())), + DefaultCase()); WrapInFunction(s); GeneratorImpl& gen = Build(); diff --git a/src/writer/glsl/generator_impl_switch_test.cc b/src/writer/glsl/generator_impl_switch_test.cc index 9ebe45bb5b..abcd1ee260 100644 --- a/src/writer/glsl/generator_impl_switch_test.cc +++ b/src/writer/glsl/generator_impl_switch_test.cc @@ -28,7 +28,7 @@ TEST_F(GlslGeneratorImplTest_Switch, Emit_Switch) { auto* def = create(ast::CaseSelectorList{}, def_body); ast::CaseSelectorList case_val; - case_val.push_back(Literal(5)); + case_val.push_back(Expr(5)); auto* case_body = Block(create()); diff --git a/src/writer/hlsl/generator_impl_case_test.cc b/src/writer/hlsl/generator_impl_case_test.cc index 7fe6e3191f..1d29dc5727 100644 --- a/src/writer/hlsl/generator_impl_case_test.cc +++ b/src/writer/hlsl/generator_impl_case_test.cc @@ -23,7 +23,7 @@ namespace { using HlslGeneratorImplTest_Case = TestHelper; TEST_F(HlslGeneratorImplTest_Case, Emit_Case) { - auto* s = Switch(1, Case(Literal(5), Block(create())), + auto* s = Switch(1, Case(Expr(5), Block(create())), DefaultCase()); WrapInFunction(s); @@ -39,7 +39,7 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case) { } TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) { - auto* s = Switch(1, Case(Literal(5), Block()), DefaultCase()); + auto* s = Switch(1, Case(Expr(5), Block()), DefaultCase()); WrapInFunction(s); GeneratorImpl& gen = Build(); @@ -55,9 +55,9 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) { auto* s = - Switch(1, // - Case(Literal(4), Block(create())), // - Case(Literal(5), Block(create())), // + Switch(1, // + Case(Expr(4), Block(create())), // + Case(Expr(5), Block(create())), // DefaultCase()); WrapInFunction(s); @@ -77,9 +77,9 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) { } TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) { - auto* s = Switch( - 1, Case({Literal(5), Literal(6)}, Block(create())), - DefaultCase()); + auto* s = + Switch(1, Case({Expr(5), Expr(6)}, Block(create())), + DefaultCase()); WrapInFunction(s); GeneratorImpl& gen = Build(); diff --git a/src/writer/hlsl/generator_impl_switch_test.cc b/src/writer/hlsl/generator_impl_switch_test.cc index 89d69bcc16..1f65348a55 100644 --- a/src/writer/hlsl/generator_impl_switch_test.cc +++ b/src/writer/hlsl/generator_impl_switch_test.cc @@ -23,9 +23,9 @@ using HlslGeneratorImplTest_Switch = TestHelper; TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) { Global("cond", ty.i32(), ast::StorageClass::kPrivate); - auto* s = Switch( // - Expr("cond"), // - Case(Literal(5), Block(Break())), // + auto* s = Switch( // + Expr("cond"), // + Case(Expr(5), Block(Break())), // DefaultCase()); WrapInFunction(s); diff --git a/src/writer/msl/generator_impl_case_test.cc b/src/writer/msl/generator_impl_case_test.cc index 7aff22148f..ece2370df3 100644 --- a/src/writer/msl/generator_impl_case_test.cc +++ b/src/writer/msl/generator_impl_case_test.cc @@ -23,7 +23,7 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Case) { - auto* s = Switch(1, Case(Literal(5), Block(create())), + auto* s = Switch(1, Case(Expr(5), Block(create())), DefaultCase()); WrapInFunction(s); @@ -39,7 +39,7 @@ TEST_F(MslGeneratorImplTest, Emit_Case) { } TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) { - auto* s = Switch(1, Case(Literal(5), Block()), DefaultCase()); + auto* s = Switch(1, Case(Expr(5), Block()), DefaultCase()); WrapInFunction(s); GeneratorImpl& gen = Build(); @@ -54,9 +54,8 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) { } TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) { - auto* s = - Switch(1, Case(Literal(5), Block(create())), - DefaultCase()); + auto* s = Switch(1, Case(Expr(5), Block(create())), + DefaultCase()); WrapInFunction(s); GeneratorImpl& gen = Build(); @@ -71,9 +70,9 @@ TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) { } TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) { - auto* s = Switch( - 1, Case({Literal(5), Literal(6)}, Block(create())), - DefaultCase()); + auto* s = + Switch(1, Case({Expr(5), Expr(6)}, Block(create())), + DefaultCase()); WrapInFunction(s); GeneratorImpl& gen = Build(); diff --git a/src/writer/msl/generator_impl_switch_test.cc b/src/writer/msl/generator_impl_switch_test.cc index e707eb9952..c6f56720a1 100644 --- a/src/writer/msl/generator_impl_switch_test.cc +++ b/src/writer/msl/generator_impl_switch_test.cc @@ -28,7 +28,7 @@ TEST_F(MslGeneratorImplTest, Emit_Switch) { auto* def = create(ast::CaseSelectorList{}, def_body); ast::CaseSelectorList case_val; - case_val.push_back(Literal(5)); + case_val.push_back(Expr(5)); auto* case_body = Block(create()); diff --git a/src/writer/spirv/builder_switch_test.cc b/src/writer/spirv/builder_switch_test.cc index d99853e811..462ce25563 100644 --- a/src/writer/spirv/builder_switch_test.cc +++ b/src/writer/spirv/builder_switch_test.cc @@ -61,8 +61,8 @@ TEST_F(BuilderTest, Switch_WithCase) { auto* a = Global("a", ty.i32(), ast::StorageClass::kPrivate); auto* expr = Switch("a", /**/ - Case(Literal(1), Block(Assign("v", 1))), - Case(Literal(2), Block(Assign("v", 2))), DefaultCase()); + Case(Expr(1), Block(Assign("v", 1))), + Case(Expr(2), Block(Assign("v", 2))), DefaultCase()); WrapInFunction(expr); auto* func = Func("a_func", {}, ty.void_(), ast::StatementList{}, @@ -119,8 +119,8 @@ TEST_F(BuilderTest, Switch_WithCase_Unsigned) { auto* v = Global("v", ty.i32(), ast::StorageClass::kPrivate); auto* a = Global("a", ty.u32(), ast::StorageClass::kPrivate); - auto* expr = Switch("a", Case(Literal(1u), Block(Assign("v", 1))), - Case(Literal(2u), Block(Assign("v", 2))), DefaultCase()); + auto* expr = Switch("a", Case(Expr(1u), Block(Assign("v", 1))), + Case(Expr(2u), Block(Assign("v", 2))), DefaultCase()); WrapInFunction(expr); @@ -244,11 +244,11 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) { auto* default_body = Block(Assign("v", Expr(3))); ast::CaseSelectorList selector_1; - selector_1.push_back(Literal(1)); + selector_1.push_back(Expr(1)); ast::CaseSelectorList selector_2; - selector_2.push_back(Literal(2)); - selector_2.push_back(Literal(3)); + selector_2.push_back(Expr(2)); + selector_2.push_back(Expr(3)); ast::CaseStatementList cases; cases.push_back(create(selector_1, case_1_body)); @@ -326,10 +326,10 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) { auto* default_body = Block(Assign("v", Expr(3))); ast::CaseSelectorList selector_1; - selector_1.push_back(Literal(1)); + selector_1.push_back(Expr(1)); ast::CaseSelectorList selector_2; - selector_2.push_back(Literal(2)); + selector_2.push_back(Expr(2)); ast::CaseStatementList cases; cases.push_back(create(selector_1, case_1_body)); @@ -398,13 +398,12 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) { auto* v = Global("v", ty.i32(), ast::StorageClass::kPrivate); auto* a = Global("a", ty.i32(), ast::StorageClass::kPrivate); - auto* expr = - Switch("a", /**/ - Case(Literal(1), - Block(/**/ - If(Expr(true), Block(create())), - Assign("v", 1))), - DefaultCase()); + auto* expr = Switch( + "a", /**/ + Case(Expr(1), Block(/**/ + If(Expr(true), Block(create())), + Assign("v", 1))), + DefaultCase()); WrapInFunction(expr); diff --git a/src/writer/wgsl/generator_impl_case_test.cc b/src/writer/wgsl/generator_impl_case_test.cc index 92b20db8d9..95851e006e 100644 --- a/src/writer/wgsl/generator_impl_case_test.cc +++ b/src/writer/wgsl/generator_impl_case_test.cc @@ -22,7 +22,7 @@ namespace { using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, Emit_Case) { - auto* s = Switch(1, Case(Literal(5), Block(create())), + auto* s = Switch(1, Case(Expr(5), Block(create())), DefaultCase()); WrapInFunction(s); @@ -38,9 +38,9 @@ TEST_F(WgslGeneratorImplTest, Emit_Case) { } TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) { - auto* s = Switch( - 1, Case({Literal(5), Literal(6)}, Block(create())), - DefaultCase()); + auto* s = + Switch(1, Case({Expr(5), Expr(6)}, Block(create())), + DefaultCase()); WrapInFunction(s); GeneratorImpl& gen = Build(); diff --git a/src/writer/wgsl/generator_impl_switch_test.cc b/src/writer/wgsl/generator_impl_switch_test.cc index e90a31929c..c39dbb5605 100644 --- a/src/writer/wgsl/generator_impl_switch_test.cc +++ b/src/writer/wgsl/generator_impl_switch_test.cc @@ -28,7 +28,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Switch) { auto* def = create(ast::CaseSelectorList{}, def_body); ast::CaseSelectorList case_val; - case_val.push_back(Literal(5)); + case_val.push_back(Expr(5)); auto* case_body = Block(create());