diff --git a/src/ast/block_statement.cc b/src/ast/block_statement.cc index d952a22a85..cbaa0a6593 100644 --- a/src/ast/block_statement.cc +++ b/src/ast/block_statement.cc @@ -22,8 +22,6 @@ TINT_INSTANTIATE_CLASS_ID(tint::ast::BlockStatement); namespace tint { namespace ast { -BlockStatement::BlockStatement(const Source& source) : Base(source) {} - BlockStatement::BlockStatement(const Source& source, const StatementList& statements) : Base(source), statements_(std::move(statements)) {} @@ -33,9 +31,8 @@ BlockStatement::BlockStatement(BlockStatement&&) = default; BlockStatement::~BlockStatement() = default; BlockStatement* BlockStatement::Clone(CloneContext* ctx) const { - auto* cloned = ctx->mod->create(ctx->Clone(source())); - cloned->statements_ = ctx->Clone(statements_); - return cloned; + return ctx->mod->create(ctx->Clone(source()), + ctx->Clone(statements_)); } bool BlockStatement::IsValid() const { diff --git a/src/ast/block_statement.h b/src/ast/block_statement.h index 730f7bf4f3..9b5417af16 100644 --- a/src/ast/block_statement.h +++ b/src/ast/block_statement.h @@ -29,19 +29,12 @@ class BlockStatement : public Castable { public: /// Constructor /// @param source the block statement source - explicit BlockStatement(const Source& source); - /// Constructor - /// @param source the block statement source - /// @param statements the block statements + /// @param statements the statements BlockStatement(const Source& source, const StatementList& statements); /// Move constructor BlockStatement(BlockStatement&&); ~BlockStatement() override; - /// Appends a statement to the block - /// @param stmt the statement to append - void append(Statement* stmt) { statements_.push_back(stmt); } - /// Insert a statement to the block /// @param index the index to insert at /// @param stmt the statement to insert @@ -79,13 +72,9 @@ class BlockStatement : public Castable { const Statement* operator[](size_t idx) const { return statements_[idx]; } /// @returns the beginning iterator - std::vector::const_iterator begin() const { - return statements_.begin(); - } + StatementList::const_iterator begin() const { return statements_.begin(); } /// @returns the ending iterator - std::vector::const_iterator end() const { - return statements_.end(); - } + StatementList::const_iterator end() const { return statements_.end(); } /// Clones this node and all transitive child nodes using the `CloneContext` /// `ctx`. @@ -106,7 +95,7 @@ class BlockStatement : public Castable { private: BlockStatement(const BlockStatement&) = delete; - std::vector statements_; + StatementList statements_; }; } // namespace ast diff --git a/src/ast/block_statement_test.cc b/src/ast/block_statement_test.cc index 086931ca28..71b71d20d8 100644 --- a/src/ast/block_statement_test.cc +++ b/src/ast/block_statement_test.cc @@ -31,8 +31,7 @@ TEST_F(BlockStatementTest, Creation) { auto* d = create(Source{}); auto* ptr = d; - BlockStatement b(Source{}); - b.append(d); + BlockStatement b(Source{}, StatementList{d}); ASSERT_EQ(b.size(), 1u); EXPECT_EQ(b[0], ptr); @@ -43,7 +42,7 @@ TEST_F(BlockStatementTest, Creation_WithInsert) { auto* s2 = create(Source{}); auto* s3 = create(Source{}); - BlockStatement b(Source{}); + BlockStatement b(Source{}, StatementList{}); b.insert(0, s1); b.insert(0, s2); b.insert(1, s3); @@ -57,46 +56,53 @@ TEST_F(BlockStatementTest, Creation_WithInsert) { } TEST_F(BlockStatementTest, Creation_WithSource) { - BlockStatement b(Source{Source::Location{20, 2}}); + BlockStatement b(Source{Source::Location{20, 2}}, ast::StatementList{}); auto src = b.source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(BlockStatementTest, IsBlock) { - BlockStatement b(Source{}); + BlockStatement b(Source{}, ast::StatementList{}); EXPECT_TRUE(b.Is()); } TEST_F(BlockStatementTest, IsValid) { - BlockStatement b(Source{}); - b.append(create(Source{})); + BlockStatement b(Source{}, ast::StatementList{ + create(Source{}), + }); EXPECT_TRUE(b.IsValid()); } TEST_F(BlockStatementTest, IsValid_Empty) { - BlockStatement b(Source{}); + BlockStatement b(Source{}, ast::StatementList{}); EXPECT_TRUE(b.IsValid()); } TEST_F(BlockStatementTest, IsValid_NullBodyStatement) { - BlockStatement b(Source{}); - b.append(create(Source{})); - b.append(nullptr); + BlockStatement b(Source{}, ast::StatementList{ + create(Source{}), + nullptr, + }); + EXPECT_FALSE(b.IsValid()); } TEST_F(BlockStatementTest, IsValid_InvalidBodyStatement) { - BlockStatement b(Source{}); - b.append(create(Source{}, nullptr, - create(Source{}), - ElseStatementList{})); + BlockStatement b( + Source{}, + ast::StatementList{ + create(Source{}, nullptr, + create(Source{}, StatementList{}), + ElseStatementList{}), + }); EXPECT_FALSE(b.IsValid()); } TEST_F(BlockStatementTest, ToStr) { - BlockStatement b(Source{}); - b.append(create(Source{})); + BlockStatement b(Source{}, ast::StatementList{ + create(Source{}), + }); std::ostringstream out; b.to_str(out, 2); diff --git a/src/ast/case_statement_test.cc b/src/ast/case_statement_test.cc index 0473418133..95714ad8bb 100644 --- a/src/ast/case_statement_test.cc +++ b/src/ast/case_statement_test.cc @@ -35,9 +35,8 @@ TEST_F(CaseStatementTest, Creation_i32) { auto* selector = create(Source{}, &i32, 2); b.push_back(selector); - auto* body = create(Source{}); auto* discard = create(Source{}); - body->append(discard); + auto* body = create(Source{}, StatementList{discard}); CaseStatement c(Source{}, b, body); ASSERT_EQ(c.selectors().size(), 1u); @@ -53,9 +52,8 @@ TEST_F(CaseStatementTest, Creation_u32) { auto* selector = create(Source{}, &u32, 2); b.push_back(selector); - auto* body = create(Source{}); auto* discard = create(Source{}); - body->append(discard); + auto* body = create(Source{}, StatementList{discard}); CaseStatement c(Source{}, b, body); ASSERT_EQ(c.selectors().size(), 1u); @@ -69,9 +67,10 @@ TEST_F(CaseStatementTest, Creation_WithSource) { CaseSelectorList b; b.push_back(create(Source{}, &i32, 2)); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); CaseStatement c(Source{Source::Location{20, 2}}, b, body); auto src = c.source(); EXPECT_EQ(src.range.begin.line, 20u); @@ -79,9 +78,10 @@ TEST_F(CaseStatementTest, Creation_WithSource) { } TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) { - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); CaseStatement c(Source{}, CaseSelectorList{}, body); EXPECT_TRUE(c.IsDefault()); } @@ -91,19 +91,20 @@ TEST_F(CaseStatementTest, IsDefault_WithSelectors) { CaseSelectorList b; b.push_back(create(Source{}, &i32, 2)); - CaseStatement c(Source{}, b, create(Source{})); + CaseStatement c(Source{}, b, + create(Source{}, StatementList{})); EXPECT_FALSE(c.IsDefault()); } TEST_F(CaseStatementTest, IsCase) { CaseStatement c(Source{}, CaseSelectorList{}, - create(Source{})); + create(Source{}, StatementList{})); EXPECT_TRUE(c.Is()); } TEST_F(CaseStatementTest, IsValid) { CaseStatement c(Source{}, CaseSelectorList{}, - create(Source{})); + create(Source{}, StatementList{})); EXPECT_TRUE(c.IsValid()); } @@ -112,10 +113,11 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) { CaseSelectorList b; b.push_back(create(Source{}, &i32, 2)); - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(nullptr); - + auto* body = + create(Source{}, StatementList{ + create(Source{}), + nullptr, + }); CaseStatement c(Source{}, b, body); EXPECT_FALSE(c.IsValid()); } @@ -125,11 +127,13 @@ TEST_F(CaseStatementTest, IsValid_InvalidBodyStatement) { CaseSelectorList b; b.push_back(create(Source{}, &i32, 2)); - auto* body = create(Source{}); - body->append(create(Source{}, nullptr, - create(Source{}), - ElseStatementList{})); - + auto* body = create( + Source{}, + StatementList{ + create(Source{}, nullptr, + create(Source{}, StatementList{}), + ElseStatementList{}), + }); CaseStatement c(Source{}, {b}, body); EXPECT_FALSE(c.IsValid()); } @@ -139,8 +143,10 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_i32) { CaseSelectorList b; b.push_back(create(Source{}, &i32, -2)); - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); CaseStatement c(Source{}, {b}, body); std::ostringstream out; @@ -156,8 +162,10 @@ TEST_F(CaseStatementTest, ToStr_WithSelectors_u32) { CaseSelectorList b; b.push_back(create(Source{}, &u32, 2)); - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); CaseStatement c(Source{}, {b}, body); std::ostringstream out; @@ -175,8 +183,10 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) { b.push_back(create(Source{}, &i32, 1)); b.push_back(create(Source{}, &i32, 2)); - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); CaseStatement c(Source{}, b, body); std::ostringstream out; @@ -188,8 +198,10 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) { } TEST_F(CaseStatementTest, ToStr_WithoutSelectors) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); CaseStatement c(Source{}, CaseSelectorList{}, body); std::ostringstream out; diff --git a/src/ast/else_statement_test.cc b/src/ast/else_statement_test.cc index c2ea1e891b..f1b681cb4e 100644 --- a/src/ast/else_statement_test.cc +++ b/src/ast/else_statement_test.cc @@ -31,9 +31,10 @@ TEST_F(ElseStatementTest, Creation) { type::Bool bool_type; auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); auto* discard = body->get(0); ElseStatement e(Source{}, cond, body); @@ -44,14 +45,15 @@ TEST_F(ElseStatementTest, Creation) { TEST_F(ElseStatementTest, Creation_WithSource) { ElseStatement e(Source{Source::Location{20, 2}}, nullptr, - create(Source{})); + create(Source{}, StatementList{})); auto src = e.source(); EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } TEST_F(ElseStatementTest, IsElse) { - ElseStatement e(Source{}, nullptr, create(Source{})); + ElseStatement e(Source{}, nullptr, + create(Source{}, StatementList{})); EXPECT_TRUE(e.Is()); } @@ -59,49 +61,57 @@ TEST_F(ElseStatementTest, HasCondition) { type::Bool bool_type; auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - ElseStatement e(Source{}, cond, create(Source{})); + ElseStatement e(Source{}, cond, + create(Source{}, StatementList{})); EXPECT_TRUE(e.HasCondition()); } TEST_F(ElseStatementTest, HasContition_NullCondition) { - ElseStatement e(Source{}, nullptr, create(Source{})); + ElseStatement e(Source{}, nullptr, + create(Source{}, StatementList{})); EXPECT_FALSE(e.HasCondition()); } TEST_F(ElseStatementTest, IsValid) { - ElseStatement e(Source{}, nullptr, create(Source{})); + ElseStatement e(Source{}, nullptr, + create(Source{}, StatementList{})); EXPECT_TRUE(e.IsValid()); } TEST_F(ElseStatementTest, IsValid_WithBody) { - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); ElseStatement e(Source{}, nullptr, body); EXPECT_TRUE(e.IsValid()); } TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) { - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(nullptr); - + auto* body = + create(Source{}, StatementList{ + create(Source{}), + nullptr, + }); ElseStatement e(Source{}, nullptr, body); EXPECT_FALSE(e.IsValid()); } TEST_F(ElseStatementTest, IsValid_InvalidCondition) { auto* cond = create(Source{}, nullptr); - ElseStatement e(Source{}, cond, create(Source{})); + ElseStatement e(Source{}, cond, + create(Source{}, StatementList{})); EXPECT_FALSE(e.IsValid()); } TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) { - auto* body = create(Source{}); - body->append(create(Source{}, nullptr, - create(Source{}), - ElseStatementList{})); - + auto* body = create( + Source{}, + StatementList{ + create(Source{}, nullptr, + create(Source{}, StatementList{}), + ElseStatementList{}), + }); ElseStatement e(Source{}, nullptr, body); EXPECT_FALSE(e.IsValid()); } @@ -110,9 +120,10 @@ TEST_F(ElseStatementTest, ToStr) { type::Bool bool_type; auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); ElseStatement e(Source{}, cond, body); std::ostringstream out; e.to_str(out, 2); @@ -128,9 +139,10 @@ TEST_F(ElseStatementTest, ToStr) { } TEST_F(ElseStatementTest, ToStr_NoCondition) { - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); ElseStatement e(Source{}, nullptr, body); std::ostringstream out; e.to_str(out, 2); diff --git a/src/ast/function_test.cc b/src/ast/function_test.cc index f3439cc797..546e9697a5 100644 --- a/src/ast/function_test.cc +++ b/src/ast/function_test.cc @@ -44,7 +44,8 @@ TEST_F(FunctionTest, Creation) { auto* var = params[0]; Function f(Source{}, func_sym, "func", params, &void_type, - create(Source{}), FunctionDecorationList{}); + create(Source{}, StatementList{}), + FunctionDecorationList{}); EXPECT_EQ(f.symbol(), func_sym); EXPECT_EQ(f.name(), "func"); ASSERT_EQ(f.params().size(), 1u); @@ -64,7 +65,7 @@ TEST_F(FunctionTest, Creation_WithSource) { ast::VariableDecorationList{})); Function f(Source{Source::Location{20, 2}}, func_sym, "func", params, - &void_type, create(Source{}), + &void_type, create(Source{}, StatementList{}), FunctionDecorationList{}); auto src = f.source(); EXPECT_EQ(src.range.begin.line, 20u); @@ -80,7 +81,8 @@ TEST_F(FunctionTest, AddDuplicateReferencedVariables) { Variable v(Source{}, "var", StorageClass::kInput, &i32, false, nullptr, ast::VariableDecorationList{}); Function f(Source{}, func_sym, "func", VariableList{}, &void_type, - create(Source{}), FunctionDecorationList{}); + create(Source{}, StatementList{}), + FunctionDecorationList{}); f.add_referenced_module_variable(&v); ASSERT_EQ(f.referenced_module_variables().size(), 1u); @@ -127,7 +129,8 @@ TEST_F(FunctionTest, GetReferenceLocations) { }); Function f(Source{}, func_sym, "func", VariableList{}, &void_type, - create(Source{}), FunctionDecorationList{}); + create(Source{}, StatementList{}), + FunctionDecorationList{}); f.add_referenced_module_variable(loc1); f.add_referenced_module_variable(builtin1); @@ -174,7 +177,8 @@ TEST_F(FunctionTest, GetReferenceBuiltins) { }); Function f(Source{}, func_sym, "func", VariableList{}, &void_type, - create(Source{}), FunctionDecorationList{}); + create(Source{}, StatementList{}), + FunctionDecorationList{}); f.add_referenced_module_variable(loc1); f.add_referenced_module_variable(builtin1); @@ -197,7 +201,8 @@ TEST_F(FunctionTest, AddDuplicateEntryPoints) { auto main_sym = mod.RegisterSymbol("main"); Function f(Source{}, func_sym, "func", VariableList{}, &void_type, - create(Source{}), FunctionDecorationList{}); + create(Source{}, StatementList{}), + FunctionDecorationList{}); f.add_ancestor_entry_point(main_sym); ASSERT_EQ(1u, f.ancestor_entry_points().size()); @@ -219,8 +224,10 @@ TEST_F(FunctionTest, IsValid) { false, nullptr, ast::VariableDecorationList{})); - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); Function f(Source{}, func_sym, "func", params, &void_type, body, FunctionDecorationList{}); @@ -238,10 +245,8 @@ TEST_F(FunctionTest, IsValid_InvalidName) { false, nullptr, ast::VariableDecorationList{})); - auto* body = create(Source{}); - body->append(create(Source{})); - - Function f(Source{}, func_sym, "", params, &void_type, body, + Function f(Source{}, func_sym, "", params, &void_type, + create(Source{}, StatementList{}), FunctionDecorationList{}); EXPECT_FALSE(f.IsValid()); } @@ -257,7 +262,8 @@ TEST_F(FunctionTest, IsValid_MissingReturnType) { ast::VariableDecorationList{})); Function f(Source{}, func_sym, "func", params, nullptr, - create(Source{}), FunctionDecorationList{}); + create(Source{}, StatementList{}), + FunctionDecorationList{}); EXPECT_FALSE(f.IsValid()); } @@ -274,7 +280,8 @@ TEST_F(FunctionTest, IsValid_NullParam) { params.push_back(nullptr); Function f(Source{}, func_sym, "func", params, &void_type, - create(Source{}), FunctionDecorationList{}); + create(Source{}, StatementList{}), + FunctionDecorationList{}); EXPECT_FALSE(f.IsValid()); } @@ -289,7 +296,8 @@ TEST_F(FunctionTest, IsValid_InvalidParam) { ast::VariableDecorationList{})); Function f(Source{}, func_sym, "func", params, &void_type, - create(Source{}), FunctionDecorationList{}); + create(Source{}, StatementList{}), + FunctionDecorationList{}); EXPECT_FALSE(f.IsValid()); } @@ -304,9 +312,11 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) { false, nullptr, ast::VariableDecorationList{})); - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(nullptr); + auto* body = + create(Source{}, StatementList{ + create(Source{}), + nullptr, + }); Function f(Source{}, func_sym, "func", params, &void_type, body, FunctionDecorationList{}); @@ -325,9 +335,11 @@ TEST_F(FunctionTest, IsValid_InvalidBodyStatement) { false, nullptr, ast::VariableDecorationList{})); - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(nullptr); + auto* body = + create(Source{}, StatementList{ + create(Source{}), + nullptr, + }); Function f(Source{}, func_sym, "func", params, &void_type, body, FunctionDecorationList{}); @@ -340,8 +352,10 @@ TEST_F(FunctionTest, ToStr) { auto func_sym = mod.RegisterSymbol("func"); - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); Function f(Source{}, func_sym, "func", {}, &void_type, body, FunctionDecorationList{}); @@ -362,9 +376,10 @@ TEST_F(FunctionTest, ToStr_WithDecoration) { auto func_sym = mod.RegisterSymbol("func"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); Function f( Source{}, func_sym, "func", {}, &void_type, body, FunctionDecorationList{create(2, 4, 6, Source{})}); @@ -391,9 +406,10 @@ TEST_F(FunctionTest, ToStr_WithParams) { false, nullptr, ast::VariableDecorationList{})); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = + create(Source{}, StatementList{ + create(Source{}), + }); Function f(Source{}, func_sym, "func", params, &void_type, body, FunctionDecorationList{}); @@ -419,7 +435,8 @@ TEST_F(FunctionTest, TypeName) { auto func_sym = mod.RegisterSymbol("func"); Function f(Source{}, func_sym, "func", {}, &void_type, - create(Source{}), FunctionDecorationList{}); + create(Source{}, StatementList{}), + FunctionDecorationList{}); EXPECT_EQ(f.type_name(), "__func__void"); } @@ -439,7 +456,8 @@ TEST_F(FunctionTest, TypeName_WithParams) { ast::VariableDecorationList{})); Function f(Source{}, func_sym, "func", params, &void_type, - create(Source{}), FunctionDecorationList{}); + create(Source{}, StatementList{}), + FunctionDecorationList{}); EXPECT_EQ(f.type_name(), "__func__void__i32__f32"); } @@ -449,9 +467,8 @@ TEST_F(FunctionTest, GetLastStatement) { auto func_sym = mod.RegisterSymbol("func"); VariableList params; - auto* body = create(Source{}); auto* stmt = create(Source{}); - body->append(stmt); + auto* body = create(Source{}, StatementList{stmt}); Function f(Source{}, func_sym, "func", params, &void_type, body, FunctionDecorationList{}); @@ -464,7 +481,7 @@ TEST_F(FunctionTest, GetLastStatement_nullptr) { auto func_sym = mod.RegisterSymbol("func"); VariableList params; - auto* body = create(Source{}); + auto* body = create(Source{}, StatementList{}); Function f(Source{}, func_sym, "func", params, &void_type, body, FunctionDecorationList{}); @@ -477,7 +494,8 @@ TEST_F(FunctionTest, WorkgroupSize_NoneSet) { auto func_sym = mod.RegisterSymbol("func"); Function f(Source{}, func_sym, "func", {}, &void_type, - create(Source{}), FunctionDecorationList{}); + create(Source{}, StatementList{}), + FunctionDecorationList{}); uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; @@ -493,7 +511,7 @@ TEST_F(FunctionTest, WorkgroupSize) { auto func_sym = mod.RegisterSymbol("func"); Function f(Source{}, func_sym, "func", {}, &void_type, - create(Source{}), + create(Source{}, StatementList{}), {create(2u, 4u, 6u, Source{})}); uint32_t x = 0; diff --git a/src/ast/if_statement_test.cc b/src/ast/if_statement_test.cc index 7c7c777549..250c145706 100644 --- a/src/ast/if_statement_test.cc +++ b/src/ast/if_statement_test.cc @@ -27,9 +27,8 @@ using IfStatementTest = TestHelper; TEST_F(IfStatementTest, Creation) { auto* cond = create(Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, StatementList{create(Source{})}); IfStatement stmt(Source{Source::Location{20, 2}}, cond, body, ElseStatementList{}); auto src = stmt.source(); @@ -38,7 +37,8 @@ TEST_F(IfStatementTest, Creation) { } TEST_F(IfStatementTest, IsIf) { - IfStatement stmt(Source{}, nullptr, create(Source{}), + IfStatement stmt(Source{}, nullptr, + create(Source{}, StatementList{}), ElseStatementList{}); EXPECT_TRUE(stmt.Is()); } @@ -46,9 +46,8 @@ TEST_F(IfStatementTest, IsIf) { TEST_F(IfStatementTest, IsValid) { auto* cond = create(Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, StatementList{create(Source{})}); IfStatement stmt(Source{}, cond, body, ElseStatementList{}); EXPECT_TRUE(stmt.IsValid()); } @@ -56,26 +55,25 @@ TEST_F(IfStatementTest, IsValid) { TEST_F(IfStatementTest, IsValid_WithElseStatements) { auto* cond = create(Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, StatementList{create(Source{})}); IfStatement stmt(Source{}, cond, body, { create( Source{}, create( Source{}, mod.RegisterSymbol("Ident"), "Ident"), - create(Source{})), - create(Source{}, nullptr, - create(Source{})), + create(Source{}, StatementList{})), + create( + Source{}, nullptr, + create(Source{}, StatementList{})), }); EXPECT_TRUE(stmt.IsValid()); } TEST_F(IfStatementTest, IsValid_MissingCondition) { - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, StatementList{create(Source{})}); IfStatement stmt(Source{}, nullptr, body, ElseStatementList{}); EXPECT_FALSE(stmt.IsValid()); } @@ -83,9 +81,8 @@ TEST_F(IfStatementTest, IsValid_MissingCondition) { TEST_F(IfStatementTest, IsValid_InvalidCondition) { auto* cond = create(Source{}, mod.RegisterSymbol(""), ""); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, StatementList{create(Source{})}); IfStatement stmt(Source{}, cond, body, ElseStatementList{}); EXPECT_FALSE(stmt.IsValid()); } @@ -93,10 +90,11 @@ TEST_F(IfStatementTest, IsValid_InvalidCondition) { TEST_F(IfStatementTest, IsValid_NullBodyStatement) { auto* cond = create(Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(nullptr); - + auto* body = + create(Source{}, StatementList{ + create(Source{}), + nullptr, + }); IfStatement stmt(Source{}, cond, body, ElseStatementList{}); EXPECT_FALSE(stmt.IsValid()); } @@ -104,12 +102,14 @@ TEST_F(IfStatementTest, IsValid_NullBodyStatement) { TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) { auto* cond = create(Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(create(Source{}, nullptr, - create(Source{}), - ast::ElseStatementList{})); - + auto* body = create( + Source{}, + StatementList{ + create(Source{}), + create(Source{}, nullptr, + create(Source{}, StatementList{}), + ast::ElseStatementList{}), + }); IfStatement stmt(Source{}, cond, body, ElseStatementList{}); EXPECT_FALSE(stmt.IsValid()); } @@ -117,18 +117,18 @@ TEST_F(IfStatementTest, IsValid_InvalidBodyStatement) { TEST_F(IfStatementTest, IsValid_NullElseStatement) { auto* cond = create(Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, StatementList{create(Source{})}); IfStatement stmt(Source{}, cond, body, { create( Source{}, create( Source{}, mod.RegisterSymbol("Ident"), "Ident"), - create(Source{})), - create(Source{}, nullptr, - create(Source{})), + create(Source{}, StatementList{})), + create( + Source{}, nullptr, + create(Source{}, StatementList{})), nullptr, }); EXPECT_FALSE(stmt.IsValid()); @@ -137,32 +137,32 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) { TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { auto* cond = create(Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - - IfStatement stmt( - Source{}, cond, body, - { - create(Source{}, - create( - Source{}, mod.RegisterSymbol(""), ""), - create(Source{})), - }); + auto* body = create( + Source{}, StatementList{create(Source{})}); + IfStatement stmt(Source{}, cond, body, + { + create( + Source{}, + create( + Source{}, mod.RegisterSymbol(""), ""), + create(Source{}, StatementList{})), + }); EXPECT_FALSE(stmt.IsValid()); } TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { auto* cond = create(Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, StatementList{create(Source{})}); IfStatement stmt(Source{}, cond, body, { - create(Source{}, nullptr, - create(Source{})), - create(Source{}, nullptr, - create(Source{})), + create( + Source{}, nullptr, + create(Source{}, StatementList{})), + create( + Source{}, nullptr, + create(Source{}, StatementList{})), }); EXPECT_FALSE(stmt.IsValid()); } @@ -170,18 +170,18 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { TEST_F(IfStatementTest, IsValid_ElseNotLast) { auto* cond = create(Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, StatementList{create(Source{})}); IfStatement stmt(Source{}, cond, body, { - create(Source{}, nullptr, - create(Source{})), + create( + Source{}, nullptr, + create(Source{}, StatementList{})), create( Source{}, create( - Source{}, mod.RegisterSymbol("ident"), "ident"), - create(Source{})), + Source{}, mod.RegisterSymbol("Ident"), "Ident"), + create(Source{}, StatementList{})), }); EXPECT_FALSE(stmt.IsValid()); } @@ -189,9 +189,8 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) { TEST_F(IfStatementTest, ToStr) { auto* cond = create(Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, StatementList{create(Source{})}); IfStatement stmt(Source{}, cond, body, ElseStatementList{}); std::ostringstream out; @@ -210,16 +209,13 @@ TEST_F(IfStatementTest, ToStr) { TEST_F(IfStatementTest, ToStr_WithElseStatements) { auto* cond = create(Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - - auto* else_if_body = create(Source{}); - else_if_body->append(create(Source{})); - - auto* else_body = create(Source{}); - else_body->append(create(Source{})); - else_body->append(create(Source{})); - + auto* body = create( + Source{}, StatementList{create(Source{})}); + auto* else_if_body = create( + Source{}, StatementList{create(Source{})}); + auto* else_body = create( + Source{}, StatementList{create(Source{}), + create(Source{})}); IfStatement stmt(Source{}, cond, body, { create( diff --git a/src/ast/loop_statement_test.cc b/src/ast/loop_statement_test.cc index 4588d0135a..58e4b79ef3 100644 --- a/src/ast/loop_statement_test.cc +++ b/src/ast/loop_statement_test.cc @@ -28,12 +28,12 @@ namespace { using LoopStatementTest = TestHelper; TEST_F(LoopStatementTest, Creation) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, StatementList{create(Source{})}); auto* b = body->last(); - auto* continuing = create(Source{}); - continuing->append(create(Source{})); + auto* continuing = create( + Source{}, StatementList{create(Source{})}); LoopStatement l(Source{}, body, continuing); ASSERT_EQ(l.body()->size(), 1u); @@ -43,11 +43,11 @@ TEST_F(LoopStatementTest, Creation) { } TEST_F(LoopStatementTest, Creation_WithSource) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, StatementList{create(Source{})}); - auto* continuing = create(Source{}); - continuing->append(create(Source{})); + auto* continuing = create( + Source{}, StatementList{create(Source{})}); LoopStatement l(Source{Source::Location{20, 2}}, body, continuing); auto src = l.source(); @@ -56,110 +56,121 @@ TEST_F(LoopStatementTest, Creation_WithSource) { } TEST_F(LoopStatementTest, IsLoop) { - LoopStatement l(Source{}, create(Source{}), - create(Source{})); + LoopStatement l(Source{}, create(Source{}, StatementList{}), + create(Source{}, StatementList{})); EXPECT_TRUE(l.Is()); } TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, StatementList{create(Source{})}); LoopStatement l(Source{}, body, {}); EXPECT_FALSE(l.has_continuing()); } TEST_F(LoopStatementTest, HasContinuing_WithContinuing) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, StatementList{create(Source{})}); - auto* continuing = create(Source{}); - continuing->append(create(Source{})); + auto* continuing = create( + Source{}, StatementList{create(Source{})}); LoopStatement l(Source{}, body, continuing); EXPECT_TRUE(l.has_continuing()); } TEST_F(LoopStatementTest, IsValid) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, StatementList{create(Source{})}); - auto* continuing = create(Source{}); - continuing->append(create(Source{})); + auto* continuing = create( + Source{}, StatementList{create(Source{})}); LoopStatement l(Source{}, body, continuing); EXPECT_TRUE(l.IsValid()); } TEST_F(LoopStatementTest, IsValid_WithoutContinuing) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, StatementList{create(Source{})}); - LoopStatement l(Source{}, body, create(Source{})); + LoopStatement l(Source{}, body, + create(Source{}, StatementList{})); EXPECT_TRUE(l.IsValid()); } TEST_F(LoopStatementTest, IsValid_WithoutBody) { - LoopStatement l(Source{}, create(Source{}), - create(Source{})); + LoopStatement l(Source{}, create(Source{}, StatementList{}), + create(Source{}, StatementList{})); EXPECT_TRUE(l.IsValid()); } TEST_F(LoopStatementTest, IsValid_NullBodyStatement) { - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(nullptr); + auto* body = + create(Source{}, StatementList{ + create(Source{}), + nullptr, + }); - auto* continuing = create(Source{}); - continuing->append(create(Source{})); + auto* continuing = create( + Source{}, StatementList{create(Source{})}); LoopStatement l(Source{}, body, continuing); EXPECT_FALSE(l.IsValid()); } TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) { - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(create(Source{}, nullptr, - create(Source{}), - ElseStatementList{})); + auto* body = create( + Source{}, + StatementList{ + create(Source{}), + create(Source{}, nullptr, + create(Source{}, StatementList{}), + ElseStatementList{}), + }); - auto* continuing = create(Source{}); - continuing->append(create(Source{})); + auto* continuing = create( + Source{}, StatementList{create(Source{})}); LoopStatement l(Source{}, body, continuing); EXPECT_FALSE(l.IsValid()); } TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, StatementList{create(Source{})}); - auto* continuing = create(Source{}); - continuing->append(create(Source{})); - continuing->append(nullptr); + auto* continuing = + create(Source{}, StatementList{ + create(Source{}), + nullptr, + }); LoopStatement l(Source{}, body, continuing); EXPECT_FALSE(l.IsValid()); } TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, StatementList{create(Source{})}); - auto* continuing = create(Source{}); - continuing->append(create(Source{})); - continuing->append(create(Source{}, nullptr, - create(Source{}), - ElseStatementList{})); + auto* continuing = create( + Source{}, + StatementList{ + create(Source{}), + create(Source{}, nullptr, + create(Source{}, StatementList{}), + ElseStatementList{}), + }); LoopStatement l(Source{}, body, continuing); EXPECT_FALSE(l.IsValid()); } TEST_F(LoopStatementTest, ToStr) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, StatementList{create(Source{})}); LoopStatement l(Source{}, body, {}); std::ostringstream out; @@ -171,11 +182,11 @@ TEST_F(LoopStatementTest, ToStr) { } TEST_F(LoopStatementTest, ToStr_WithContinuing) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, StatementList{create(Source{})}); - auto* continuing = create(Source{}); - continuing->append(create(Source{})); + auto* continuing = create( + Source{}, StatementList{create(Source{})}); LoopStatement l(Source{}, body, continuing); std::ostringstream out; diff --git a/src/ast/module_test.cc b/src/ast/module_test.cc index 75a4d3c548..03be7eb7eb 100644 --- a/src/ast/module_test.cc +++ b/src/ast/module_test.cc @@ -49,9 +49,10 @@ TEST_F(ModuleTest, LookupFunction) { Module m; auto func_sym = m.RegisterSymbol("main"); - auto* func = create(Source{}, func_sym, "main", VariableList{}, - &f32, create(Source{}), - ast::FunctionDecorationList{}); + auto* func = + create(Source{}, func_sym, "main", VariableList{}, &f32, + create(Source{}, StatementList{}), + ast::FunctionDecorationList{}); m.AddFunction(func); EXPECT_EQ(func, m.FindFunctionBySymbol(func_sym)); } @@ -133,7 +134,9 @@ TEST_F(ModuleTest, IsValid_Function) { auto* func = create( Source{}, m.RegisterSymbol("main"), "main", VariableList(), &f32, - create(Source{}), ast::FunctionDecorationList{}); + create(Source{}, StatementList{}), + ast::FunctionDecorationList{}); + m.AddFunction(func); EXPECT_TRUE(m.IsValid()); } diff --git a/src/ast/switch_statement_test.cc b/src/ast/switch_statement_test.cc index 9a73e39aad..bb5ce31676 100644 --- a/src/ast/switch_statement_test.cc +++ b/src/ast/switch_statement_test.cc @@ -37,8 +37,8 @@ TEST_F(SwitchStatementTest, Creation) { auto* ident = create( Source{}, mod.RegisterSymbol("ident"), "ident"); CaseStatementList body; - auto* case_stmt = - create(Source{}, lit, create(Source{})); + auto* case_stmt = create( + Source{}, lit, create(Source{}, StatementList{})); body.push_back(case_stmt); SwitchStatement stmt(Source{}, ident, body); @@ -67,8 +67,8 @@ TEST_F(SwitchStatementTest, IsSwitch) { auto* ident = create( Source{}, mod.RegisterSymbol("ident"), "ident"); CaseStatementList body; - body.push_back( - create(Source{}, lit, create(Source{}))); + body.push_back(create( + Source{}, lit, create(Source{}, StatementList{}))); SwitchStatement stmt(Source{}, ident, body); EXPECT_TRUE(stmt.Is()); @@ -83,8 +83,8 @@ TEST_F(SwitchStatementTest, IsValid) { auto* ident = create( Source{}, mod.RegisterSymbol("ident"), "ident"); CaseStatementList body; - body.push_back( - create(Source{}, lit, create(Source{}))); + body.push_back(create( + Source{}, lit, create(Source{}, StatementList{}))); SwitchStatement stmt(Source{}, ident, body); EXPECT_TRUE(stmt.IsValid()); @@ -97,8 +97,8 @@ TEST_F(SwitchStatementTest, IsValid_Null_Condition) { lit.push_back(create(Source{}, &i32, 2)); CaseStatementList body; - body.push_back( - create(Source{}, lit, create(Source{}))); + body.push_back(create( + Source{}, lit, create(Source{}, StatementList{}))); SwitchStatement stmt(Source{}, nullptr, body); EXPECT_FALSE(stmt.IsValid()); @@ -113,8 +113,8 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) { auto* ident = create(Source{}, mod.RegisterSymbol(""), ""); CaseStatementList body; - body.push_back( - create(Source{}, lit, create(Source{}))); + body.push_back(create( + Source{}, lit, create(Source{}, StatementList{}))); SwitchStatement stmt(Source{}, ident, body); EXPECT_FALSE(stmt.IsValid()); @@ -129,8 +129,8 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) { auto* ident = create( Source{}, mod.RegisterSymbol("ident"), "ident"); CaseStatementList body; - body.push_back( - create(Source{}, lit, create(Source{}))); + body.push_back(create( + Source{}, lit, create(Source{}, StatementList{}))); body.push_back(nullptr); SwitchStatement stmt(Source{}, ident, body); @@ -141,9 +141,9 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) { auto* ident = create( Source{}, mod.RegisterSymbol("ident"), "ident"); - auto* case_body = create(Source{}); - case_body->append(nullptr); - + auto* case_body = create(Source{}, StatementList{ + nullptr, + }); CaseStatementList body; body.push_back( create(Source{}, CaseSelectorList{}, case_body)); @@ -176,8 +176,8 @@ TEST_F(SwitchStatementTest, ToStr) { auto* ident = create( Source{}, mod.RegisterSymbol("ident"), "ident"); CaseStatementList body; - body.push_back( - create(Source{}, lit, create(Source{}))); + body.push_back(create( + Source{}, lit, create(Source{}, StatementList{}))); SwitchStatement stmt(Source{}, ident, body); std::ostringstream out; diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index 2341b84b08..d14992917d 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -81,8 +81,10 @@ class InspectorHelper { ast::Function* MakeEmptyBodyFunction( std::string name, ast::FunctionDecorationList decorations = {}) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); return create(Source{}, mod()->RegisterSymbol(name), name, ast::VariableList(), void_type(), body, decorations); @@ -97,13 +99,15 @@ class InspectorHelper { std::string caller, std::string callee, ast::FunctionDecorationList decorations = {}) { - auto* body = create(Source{}); auto* ident_expr = create( Source{}, mod()->RegisterSymbol(callee), callee); auto* call_expr = create(Source{}, ident_expr, ast::ExpressionList()); - body->append(create(Source{}, call_expr)); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, call_expr), + create(Source{}), + }); return create(Source{}, mod()->RegisterSymbol(caller), caller, ast::VariableList(), void_type(), body, decorations); @@ -148,18 +152,19 @@ class InspectorHelper { std::string name, std::vector> inout_vars, ast::FunctionDecorationList decorations = {}) { - auto* body = create(Source{}); + ast::StatementList stmts; for (auto inout : inout_vars) { std::string in, out; std::tie(in, out) = inout; - body->append(create( + stmts.emplace_back(create( Source{}, create(Source{}, mod()->RegisterSymbol(out), out), create(Source{}, mod()->RegisterSymbol(in), in))); } - body->append(create(Source{})); + stmts.emplace_back(create(Source{})); + auto* body = create(Source{}, stmts); return create(Source{}, mod()->RegisterSymbol(name), name, ast::VariableList(), void_type(), body, decorations); @@ -178,11 +183,11 @@ class InspectorHelper { std::string callee, std::vector> inout_vars, ast::FunctionDecorationList decorations = {}) { - auto* body = create(Source{}); + ast::StatementList stmts; for (auto inout : inout_vars) { std::string in, out; std::tie(in, out) = inout; - body->append(create( + stmts.emplace_back(create( Source{}, create(Source{}, mod()->RegisterSymbol(out), out), @@ -193,8 +198,9 @@ class InspectorHelper { Source{}, mod()->RegisterSymbol(callee), callee); auto* call_expr = create(Source{}, ident_expr, ast::ExpressionList()); - body->append(create(Source{}, call_expr)); - body->append(create(Source{})); + stmts.emplace_back(create(Source{}, call_expr)); + stmts.emplace_back(create(Source{})); + auto* body = create(Source{}, stmts); return create(Source{}, mod()->RegisterSymbol(caller), caller, ast::VariableList(), void_type(), body, decorations); @@ -428,14 +434,13 @@ class InspectorHelper { std::string func_name, std::string struct_name, std::vector> members) { - auto* body = create(Source{}); - + ast::StatementList stmts; for (auto member : members) { size_t member_idx; ast::type::Type* member_type; std::tie(member_idx, member_type) = member; std::string member_name = StructMemberName(member_idx, member_type); - body->append(create( + stmts.emplace_back(create( Source{}, create( Source{}, // source "local" + member_name, // name @@ -451,7 +456,7 @@ class InspectorHelper { ast::type::Type* member_type; std::tie(member_idx, member_type) = member; std::string member_name = StructMemberName(member_idx, member_type); - body->append(create( + stmts.emplace_back(create( Source{}, create( Source{}, mod()->RegisterSymbol("local" + member_name), @@ -464,7 +469,8 @@ class InspectorHelper { Source{}, mod()->RegisterSymbol(member_name), member_name)))); } - body->append(create(Source{})); + stmts.emplace_back(create(Source{})); + auto* body = create(Source{}, stmts); return create(Source{}, mod()->RegisterSymbol(func_name), func_name, ast::VariableList(), void_type(), body, ast::FunctionDecorationList{}); @@ -584,8 +590,7 @@ class InspectorHelper { ast::FunctionDecorationList decorations = {}) { std::string result_name = "sampler_result"; - auto* body = create(Source{}); - + ast::StatementList stmts; auto* call_result = create(Source{}, // source "sampler_result", // name @@ -594,7 +599,8 @@ class InspectorHelper { false, // is_const nullptr, // constructor ast::VariableDecorationList{}); // decorations - body->append(create(Source{}, call_result)); + stmts.emplace_back( + create(Source{}, call_result)); ast::ExpressionList call_params; call_params.push_back(create( @@ -609,14 +615,15 @@ class InspectorHelper { Source{}, mod()->RegisterSymbol("textureSample"), "textureSample"), call_params); - body->append(create( + stmts.emplace_back(create( Source{}, create( Source{}, mod()->RegisterSymbol("sampler_result"), "sampler_result"), call_expr)); - body->append(create(Source{})); + stmts.emplace_back(create(Source{})); + auto* body = create(Source{}, stmts); return create(Source{}, mod()->RegisterSymbol(func_name), func_name, ast::VariableList(), void_type(), body, decorations); @@ -641,7 +648,7 @@ class InspectorHelper { ast::FunctionDecorationList decorations = {}) { std::string result_name = "sampler_result"; - auto* body = create(Source{}); + ast::StatementList stmts; auto* call_result = create(Source{}, // source @@ -651,7 +658,8 @@ class InspectorHelper { false, // is_const nullptr, // constructor ast::VariableDecorationList{}); // decorations - body->append(create(Source{}, call_result)); + stmts.emplace_back( + create(Source{}, call_result)); ast::ExpressionList call_params; call_params.push_back(create( @@ -668,14 +676,15 @@ class InspectorHelper { Source{}, mod()->RegisterSymbol("textureSample"), "textureSample"), call_params); - body->append(create( + stmts.emplace_back(create( Source{}, create( Source{}, mod()->RegisterSymbol("sampler_result"), "sampler_result"), call_expr)); - body->append(create(Source{})); + stmts.emplace_back(create(Source{})); + auto* body = create(Source{}, stmts); return create(Source{}, mod()->RegisterSymbol(func_name), func_name, ast::VariableList(), void_type(), body, decorations); @@ -701,7 +710,7 @@ class InspectorHelper { ast::FunctionDecorationList decorations = {}) { std::string result_name = "sampler_result"; - auto* body = create(Source{}); + ast::StatementList stmts; auto* call_result = create(Source{}, // source @@ -711,7 +720,8 @@ class InspectorHelper { false, // is_const nullptr, // constructor ast::VariableDecorationList{}); // decorations - body->append(create(Source{}, call_result)); + stmts.emplace_back( + create(Source{}, call_result)); ast::ExpressionList call_params; call_params.push_back(create( @@ -729,14 +739,15 @@ class InspectorHelper { "textureSampleCompare"), call_params); - body->append(create( + stmts.emplace_back(create( Source{}, create( Source{}, mod()->RegisterSymbol("sampler_result"), "sampler_result"), call_expr)); - body->append(create(Source{})); + stmts.emplace_back(create(Source{})); + auto* body = create(Source{}, stmts); return create(Source{}, mod()->RegisterSymbol(func_name), func_name, ast::VariableList(), void_type(), body, decorations); @@ -1557,20 +1568,21 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MultipleUniformBuffers) { AddReferenceFunc("ub_bar_func", "ub_bar"); AddReferenceFunc("ub_baz_func", "ub_baz"); - auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) { + auto FuncCall = [&](const std::string& callee) { auto* ident_expr = create( Source{}, mod()->RegisterSymbol(callee), callee); auto* call_expr = create(Source{}, ident_expr, ast::ExpressionList()); - body->append(create(Source{}, call_expr)); + return create(Source{}, call_expr); }; - auto* body = create(Source{}); + auto* body = create( + Source{}, ast::StatementList{ + FuncCall("ub_foo_func"), + FuncCall("ub_bar_func"), + FuncCall("ub_baz_func"), + create(Source{}), + }); - AddFuncCall(body, "ub_foo_func"); - AddFuncCall(body, "ub_bar_func"); - AddFuncCall(body, "ub_baz_func"); - - body->append(create(Source{})); ast::Function* func = create( Source{}, mod()->RegisterSymbol("ep_func"), "ep_func", ast::VariableList(), void_type(), body, @@ -1705,20 +1717,21 @@ TEST_F(InspectorGetStorageBufferResourceBindingsTest, MultipleStorageBuffers) { AddReferenceFunc("sb_bar_func", "sb_bar"); AddReferenceFunc("sb_baz_func", "sb_baz"); - auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) { + auto FuncCall = [&](const std::string& callee) { auto* ident_expr = create( Source{}, mod()->RegisterSymbol(callee), callee); auto* call_expr = create(Source{}, ident_expr, ast::ExpressionList()); - body->append(create(Source{}, call_expr)); + return create(Source{}, call_expr); }; - auto* body = create(Source{}); + auto* body = create( + Source{}, ast::StatementList{ + FuncCall("sb_foo_func"), + FuncCall("sb_bar_func"), + FuncCall("sb_baz_func"), + create(Source{}), + }); - AddFuncCall(body, "sb_foo_func"); - AddFuncCall(body, "sb_bar_func"); - AddFuncCall(body, "sb_baz_func"); - - body->append(create(Source{})); ast::Function* func = create( Source{}, mod()->RegisterSymbol("ep_func"), "ep_func", ast::VariableList(), void_type(), body, @@ -1880,20 +1893,21 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, AddReferenceFunc("sb_bar_func", "sb_bar"); AddReferenceFunc("sb_baz_func", "sb_baz"); - auto AddFuncCall = [&](ast::BlockStatement* body, const std::string& callee) { + auto FuncCall = [&](const std::string& callee) { auto* ident_expr = create( Source{}, mod()->RegisterSymbol(callee), callee); auto* call_expr = create(Source{}, ident_expr, ast::ExpressionList()); - body->append(create(Source{}, call_expr)); + return create(Source{}, call_expr); }; - auto* body = create(Source{}); + auto* body = create( + Source{}, ast::StatementList{ + FuncCall("sb_foo_func"), + FuncCall("sb_bar_func"), + FuncCall("sb_baz_func"), + create(Source{}), + }); - AddFuncCall(body, "sb_foo_func"); - AddFuncCall(body, "sb_bar_func"); - AddFuncCall(body, "sb_baz_func"); - - body->append(create(Source{})); ast::Function* func = create( Source{}, mod()->RegisterSymbol("ep_func"), "ep_func", ast::VariableList(), void_type(), body, diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 29907dfc26..386fdf1cb2 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -608,7 +608,7 @@ class StructuredTraverser { std::unordered_set visited_; }; -/// A StatementBuilder for ast::SwitchStatment +/// A StatementBuilder for ast::SwitchStatement /// @see StatementBuilder struct SwitchStatementBuilder : public Castable { @@ -730,32 +730,17 @@ FunctionEmitter::StatementBlock::StatementBlock( completion_action_(completion_action), cases_(cases) {} -FunctionEmitter::StatementBlock::StatementBlock(StatementBlock&& other) - : construct_(other.construct_), - end_id_(other.end_id_), - completion_action_(std::move(other.completion_action_)), - statements_(std::move(other.statements_)), - cases_(std::move(other.cases_)) { - other.statements_.clear(); -} +FunctionEmitter::StatementBlock::StatementBlock(StatementBlock&& other) = + default; -FunctionEmitter::StatementBlock::~StatementBlock() { - if (!finalized_) { - // Delete builders that have not been built with Finalize() - for (auto* statement : statements_) { - if (auto* builder = statement->As()) { - delete builder; - } - } - } -} +FunctionEmitter::StatementBlock::~StatementBlock() = default; void FunctionEmitter::StatementBlock::Finalize(ast::Module* mod) { assert(!finalized_ /* Finalize() must only be called once */); + for (size_t i = 0; i < statements_.size(); i++) { if (auto* builder = statements_[i]->As()) { statements_[i] = builder->Build(mod); - delete builder; } } @@ -820,12 +805,10 @@ const ast::StatementList FunctionEmitter::ast_body() { ast::Statement* FunctionEmitter::AddStatement(ast::Statement* statement) { assert(!statements_stack_.empty()); - auto* result = statement; - if (result != nullptr) { - auto& block = statements_stack_.back(); - block.Add(statement); + if (statement != nullptr) { + statements_stack_.back().Add(statement); } - return result; + return statement; } ast::Statement* FunctionEmitter::LastStatement() { diff --git a/src/reader/spirv/function.h b/src/reader/spirv/function.h index e1f0968358..533c7eb91e 100644 --- a/src/reader/spirv/function.h +++ b/src/reader/spirv/function.h @@ -834,12 +834,15 @@ class FunctionEmitter { /// @returns a pointer to the statement. ast::Statement* AddStatement(ast::Statement* statement); + /// AddStatementBuilder() constructs and adds the StatementBuilder of type + /// `T` to the top of the statement stack. + /// @param args the arguments forwarded to the T constructor + /// @return the built StatementBuilder template T* AddStatementBuilder(ARGS&&... args) { - // The builder is temporary and is not owned by the module. - auto builder = new T(std::forward(args)...); - AddStatement(builder); - return builder; + assert(!statements_stack_.empty()); + return statements_stack_.back().AddStatementBuilder( + std::forward(args)...); } /// Returns the source record for the given instruction. @@ -876,6 +879,20 @@ class FunctionEmitter { /// Add() must not be called after calling Finalize(). void Add(ast::Statement* statement); + /// AddStatementBuilder() constructs and adds the StatementBuilder of type + /// `T` to the block. + /// Add() must not be called after calling Finalize(). + /// @param args the arguments forwarded to the T constructor + /// @return the built StatementBuilder + template + T* AddStatementBuilder(ARGS&&... args) { + auto builder = std::make_unique(std::forward(args)...); + auto* ptr = builder.get(); + Add(ptr); + builders_.emplace_back(std::move(builder)); + return ptr; + } + /// @param construct the construct which this construct constributes to void SetConstruct(const Construct* construct) { construct_ = construct; } @@ -883,7 +900,7 @@ class FunctionEmitter { const Construct* Construct() const { return construct_; } /// @return the ID of the block at which the completion action should be - /// triggerd and this statement block discarded. This is often the `end_id` + /// triggered and this statement block discarded. This is often the `end_id` /// of `construct` itself. uint32_t EndId() const { return end_id_; } @@ -901,7 +918,7 @@ class FunctionEmitter { private: /// The construct to which this construct constributes. const spirv::Construct* construct_; - /// The ID of the block at which the completion action should be triggerd + /// The ID of the block at which the completion action should be triggered /// and this statement block discarded. This is often the `end_id` of /// `construct` itself. uint32_t const end_id_; @@ -914,6 +931,9 @@ class FunctionEmitter { ast::StatementList statements_; /// The list of switch cases being built, if this construct is a switch. ast::CaseStatementList* cases_ = nullptr; + + /// Owned statement builders + std::vector> builders_; /// True if Finalize() has been called. bool finalized_ = false; }; diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 637ab83f41..6219b32f12 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -1439,14 +1439,14 @@ Expect ParserImpl::expect_paren_rhs_stmt() { // : statement* Expect ParserImpl::expect_statements() { bool errored = false; - auto* ret = create(Source{}); + ast::StatementList stmts; while (synchronized_) { auto stmt = statement(); if (stmt.errored) { errored = true; } else if (stmt.matched) { - ret->append(stmt.value); + stmts.emplace_back(stmt.value); } else { break; } @@ -1455,7 +1455,7 @@ Expect ParserImpl::expect_statements() { if (errored) return Failure::kErrored; - return ret; + return create(Source{}, stmts); } // statement @@ -1828,14 +1828,14 @@ Expect ParserImpl::expect_case_selectors() { // | statement case_body // | FALLTHROUGH SEMICOLON Maybe ParserImpl::case_body() { - auto* ret = create(Source{}); + ast::StatementList stmts; for (;;) { Source source; if (match(Token::Type::kFallthrough, &source)) { if (!expect("fallthrough statement", Token::Type::kSemicolon)) return Failure::kErrored; - ret->append(create(source)); + stmts.emplace_back(create(source)); break; } @@ -1845,10 +1845,10 @@ Maybe ParserImpl::case_body() { if (!stmt.matched) break; - ret->append(stmt.value); + stmts.emplace_back(stmt.value); } - return ret; + return create(Source{}, stmts); } // loop_stmt @@ -1972,8 +1972,10 @@ Maybe ParserImpl::for_stmt() { header->condition->source(), ast::UnaryOp::kNot, header->condition); // { break; } auto* break_stmt = create(not_condition->source()); - auto* break_body = create(not_condition->source()); - break_body->append(break_stmt); + auto* break_body = + create(not_condition->source(), ast::StatementList{ + break_stmt, + }); // if (!condition) { break; } auto* break_if_not_condition = create(not_condition->source(), not_condition, @@ -1983,17 +1985,19 @@ Maybe ParserImpl::for_stmt() { ast::BlockStatement* continuing_body = nullptr; if (header->continuing != nullptr) { - continuing_body = create(header->continuing->source()); - continuing_body->append(header->continuing); + continuing_body = create(header->continuing->source(), + ast::StatementList{ + header->continuing, + }); } auto* loop = create(source, body.value, continuing_body); if (header->initializer != nullptr) { - auto* result = create(source); - result->append(header->initializer); - result->append(loop); - return result; + return create(source, ast::StatementList{ + header->initializer, + loop, + }); } return loop; @@ -2059,7 +2063,7 @@ Maybe ParserImpl::continue_stmt() { // : CONTINUING body_stmt Maybe ParserImpl::continuing_stmt() { if (!match(Token::Type::kContinuing)) - return create(Source{}); + return create(Source{}, ast::StatementList{}); return expect_body_stmt(); } diff --git a/src/transform/bound_array_accessors_test.cc b/src/transform/bound_array_accessors_test.cc index 2f878d025d..1f152f25d5 100644 --- a/src/transform/bound_array_accessors_test.cc +++ b/src/transform/bound_array_accessors_test.cc @@ -91,24 +91,21 @@ class BoundArrayAccessorsTest : public testing::Test { }; struct ModuleBuilder : public ast::BuilderWithModule { - ModuleBuilder() : body_(create(Source{})) { - mod->AddFunction(create( - Source{}, mod->RegisterSymbol("func"), "func", ast::VariableList{}, - ty.void_, body_, ast::FunctionDecorationList{})); - } - ast::Module Module() { Build(); + auto* body = create(Source{}, statements); + mod->AddFunction(create( + Source{}, mod->RegisterSymbol("func"), "func", ast::VariableList{}, + ty.void_, body, ast::FunctionDecorationList{})); return std::move(*mod); } protected: virtual void Build() = 0; void OnVariableBuilt(ast::Variable* var) override { - ASSERT_NE(body_, nullptr); - body_->append(create(Source{}, var)); + statements.emplace_back(create(Source{}, var)); } - ast::BlockStatement* body_ = nullptr; + ast::StatementList statements; }; TEST_F(BoundArrayAccessorsTest, Ptrs_Clamp) { diff --git a/src/transform/emit_vertex_point_size_test.cc b/src/transform/emit_vertex_point_size_test.cc index d6f56273bd..a089d3e596 100644 --- a/src/transform/emit_vertex_point_size_test.cc +++ b/src/transform/emit_vertex_point_size_test.cc @@ -53,16 +53,18 @@ struct ModuleBuilder : public ast::BuilderWithModule { TEST_F(EmitVertexPointSizeTest, VertexStageBasic) { struct Builder : ModuleBuilder { void Build() override { - auto* block = create(Source{}); - - block->append(create( - Source{}, Var("builtin_assignments_should_happen_before_this", - tint::ast::StorageClass::kFunction, ty.f32))); + auto* block = create( + Source{}, + ast::StatementList{ + create( + Source{}, Var("builtin_assignments_should_happen_before_this", + tint::ast::StorageClass::kFunction, ty.f32)), + }); auto a_sym = mod->RegisterSymbol("non_entry_a"); mod->AddFunction(create( Source{}, a_sym, "non_entry_a", ast::VariableList{}, ty.void_, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{})); auto entry_sym = mod->RegisterSymbol("entry"); @@ -77,7 +79,7 @@ TEST_F(EmitVertexPointSizeTest, VertexStageBasic) { auto b_sym = mod->RegisterSymbol("non_entry_b"); mod->AddFunction(create( Source{}, b_sym, "non_entry_b", ast::VariableList{}, ty.void_, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{})); } }; @@ -131,13 +133,13 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) { auto a_sym = mod->RegisterSymbol("non_entry_a"); mod->AddFunction(create( Source{}, a_sym, "non_entry_a", ast::VariableList{}, ty.void_, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{})); auto entry_sym = mod->RegisterSymbol("entry"); mod->AddFunction(create( Source{}, entry_sym, "entry", ast::VariableList{}, ty.void_, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex, Source{}), @@ -146,7 +148,7 @@ TEST_F(EmitVertexPointSizeTest, VertexStageEmpty) { auto b_sym = mod->RegisterSymbol("non_entry_b"); mod->AddFunction(create( Source{}, b_sym, "non_entry_b", ast::VariableList{}, ty.void_, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{})); } }; @@ -193,7 +195,7 @@ TEST_F(EmitVertexPointSizeTest, NonVertexStage) { auto frag_sym = mod->RegisterSymbol("fragment_entry"); auto* fragment_entry = create( Source{}, frag_sym, "fragment_entry", ast::VariableList{}, ty.void_, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kFragment, Source{}), @@ -203,7 +205,7 @@ TEST_F(EmitVertexPointSizeTest, NonVertexStage) { auto comp_sym = mod->RegisterSymbol("compute_entry"); auto* compute_entry = create( Source{}, comp_sym, "compute_entry", ast::VariableList{}, ty.void_, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kCompute, Source{}), diff --git a/src/transform/first_index_offset.cc b/src/transform/first_index_offset.cc index 5168e6588a..97c7670c72 100644 --- a/src/transform/first_index_offset.cc +++ b/src/transform/first_index_offset.cc @@ -154,24 +154,25 @@ Transform::Output FirstIndexOffset::Run(ast::Module* in) { if (buffer_var == nullptr) { return nullptr; // no transform need, just clone func } - auto* body = ctx.mod->create( - ctx.Clone(func->body()->source())); + ast::StatementList statements; for (const auto& data : func->local_referenced_builtin_variables()) { if (data.second->value() == ast::Builtin::kVertexIdx) { - body->append(CreateFirstIndexOffset( + statements.emplace_back(CreateFirstIndexOffset( vertex_index_name, kFirstVertexName, buffer_var, ctx.mod)); } else if (data.second->value() == ast::Builtin::kInstanceIdx) { - body->append(CreateFirstIndexOffset( + statements.emplace_back(CreateFirstIndexOffset( instance_index_name, kFirstInstanceName, buffer_var, ctx.mod)); } } for (auto* s : *func->body()) { - body->append(ctx.Clone(s)); + statements.emplace_back(ctx.Clone(s)); } return ctx.mod->create( ctx.Clone(func->source()), func->symbol(), func->name(), ctx.Clone(func->params()), ctx.Clone(func->return_type()), - ctx.Clone(body), ctx.Clone(func->decorations())); + ctx.mod->create( + ctx.Clone(func->body()->source()), statements), + ctx.Clone(func->decorations())); }); in->Clone(&ctx); diff --git a/src/transform/first_index_offset_test.cc b/src/transform/first_index_offset_test.cc index 88196b39cd..2e8164ada2 100644 --- a/src/transform/first_index_offset_test.cc +++ b/src/transform/first_index_offset_test.cc @@ -58,10 +58,11 @@ struct ModuleBuilder : public ast::BuilderWithModule { } ast::Function* AddFunction(const std::string& name, - ast::VariableList params = {}) { + ast::StatementList stmts) { auto* func = create( - Source{}, mod->RegisterSymbol(name), name, std::move(params), ty.u32, - create(Source{}), ast::FunctionDecorationList()); + Source{}, mod->RegisterSymbol(name), name, ast::VariableList{}, ty.u32, + create(Source{}, stmts), + ast::FunctionDecorationList{}); mod->AddFunction(func); return func; } @@ -73,10 +74,14 @@ TEST_F(FirstIndexOffsetTest, Error_AlreadyTransformed) { struct Builder : public ModuleBuilder { void Build() override { AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx); - AddFunction("test")->body()->append(create( - Source{}, - create( - Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx"))); + AddFunction( + "test", + { + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx")), + }); } }; @@ -116,10 +121,14 @@ TEST_F(FirstIndexOffsetTest, BasicModuleVertexIndex) { struct Builder : public ModuleBuilder { void Build() override { AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx); - AddFunction("test")->body()->append(create( - Source{}, - create( - Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx"))); + AddFunction( + "test", + { + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx")), + }); } }; @@ -194,10 +203,14 @@ TEST_F(FirstIndexOffsetTest, BasicModuleInstanceIndex) { struct Builder : public ModuleBuilder { void Build() override { AddBuiltinInput("inst_idx", ast::Builtin::kInstanceIdx); - AddFunction("test")->body()->append(create( - Source{}, - create( - Source{}, mod->RegisterSymbol("inst_idx"), "inst_idx"))); + AddFunction( + "test", + { + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("inst_idx"), "inst_idx")), + }); } }; @@ -272,8 +285,9 @@ TEST_F(FirstIndexOffsetTest, BasicModuleBothIndex) { void Build() override { AddBuiltinInput("inst_idx", ast::Builtin::kInstanceIdx); AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx); - AddFunction("test")->body()->append( - create(Source{}, Expr(1u))); + AddFunction("test", { + create(Source{}, Expr(1u)), + }); } }; @@ -348,18 +362,25 @@ TEST_F(FirstIndexOffsetTest, NestedCalls) { struct Builder : public ModuleBuilder { void Build() override { AddBuiltinInput("vert_idx", ast::Builtin::kVertexIdx); - ast::Function* func1 = AddFunction("func1"); - func1->body()->append(create( - Source{}, - create( - Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx"))); - ast::Function* func2 = AddFunction("func2"); - func2->body()->append(create( - Source{}, create( - Source{}, - create( - Source{}, mod->RegisterSymbol("func1"), "func1"), - ast::ExpressionList{}))); + AddFunction( + "func1", + { + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("vert_idx"), "vert_idx")), + }); + AddFunction( + "func2", + { + create( + Source{}, + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("func1"), "func1"), + ast::ExpressionList{})), + }); } }; diff --git a/src/transform/vertex_pulling.cc b/src/transform/vertex_pulling.cc index 23b9763d08..163d875e61 100644 --- a/src/transform/vertex_pulling.cc +++ b/src/transform/vertex_pulling.cc @@ -105,7 +105,7 @@ Transform::Output VertexPulling::Run(ast::Module* in) { state.FindOrInsertInstanceIndexIfUsed(); state.ConvertVertexInputVariablesToPrivate(); state.AddVertexStorageBuffers(); - state.AddVertexPullingPreamble(func); + func->body()->insert(0, state.CreateVertexPullingPreamble()); return out; } @@ -286,13 +286,11 @@ void VertexPulling::State::AddVertexStorageBuffers() { mod->AddConstructedType(struct_type); } -void VertexPulling::State::AddVertexPullingPreamble( - ast::Function* vertex_func) { +ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() { // Assign by looking at the vertex descriptor to find attributes with matching // location. - // A block statement allowing us to use append instead of insert - auto* block = mod->create(Source{}); + ast::StatementList stmts; // Declare the |kPullingPosVarName| variable in the shader auto* pos_declaration = mod->create( @@ -308,7 +306,7 @@ void VertexPulling::State::AddVertexPullingPreamble( // |kPullingPosVarName| refers to the byte location of the current read. We // declare a variable in the shader to avoid having to reuse Expression // objects. - block->append(pos_declaration); + stmts.emplace_back(pos_declaration); for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) { const VertexBufferLayoutDescriptor& buffer_layout = cfg.vertex_state[i]; @@ -339,9 +337,9 @@ void VertexPulling::State::AddVertexPullingPreamble( // Update position of the read auto* set_pos_expr = mod->create( Source{}, CreatePullingPositionIdent(), pos_value); - block->append(set_pos_expr); + stmts.emplace_back(set_pos_expr); - block->append(mod->create( + stmts.emplace_back(mod->create( Source{}, mod->create( Source{}, mod->RegisterSymbol(v->name()), v->name()), @@ -349,7 +347,7 @@ void VertexPulling::State::AddVertexPullingPreamble( } } - vertex_func->body()->insert(0, block); + return mod->create(Source{}, stmts); } ast::Expression* VertexPulling::State::GenUint(uint32_t value) { diff --git a/src/transform/vertex_pulling.h b/src/transform/vertex_pulling.h index be3f9ca7c4..4f55b1fef4 100644 --- a/src/transform/vertex_pulling.h +++ b/src/transform/vertex_pulling.h @@ -197,8 +197,8 @@ class VertexPulling : public Transform { /// Adds storage buffer decorated variables for the vertex buffers void AddVertexStorageBuffers(); - /// Adds assignment to the variables from the buffers - void AddVertexPullingPreamble(ast::Function* vertex_func); + /// Creates and returns the assignment to the variables from the buffers + ast::BlockStatement* CreateVertexPullingPreamble(); /// Generates an expression holding a constant uint /// @param value uint value diff --git a/src/transform/vertex_pulling_test.cc b/src/transform/vertex_pulling_test.cc index b066e16563..30145ce9c1 100644 --- a/src/transform/vertex_pulling_test.cc +++ b/src/transform/vertex_pulling_test.cc @@ -47,8 +47,9 @@ class VertexPullingHelper { // Create basic module with an entry point and vertex function void InitBasicModule() { auto* func = create( - Source{}, mod_->RegisterSymbol("main"), "main", ast::VariableList{}, - mod_->create(), create(Source{}), + Source{}, mod()->RegisterSymbol("main"), "main", ast::VariableList{}, + mod_->create(), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{create( ast::PipelineStage::kVertex, Source{})}); mod()->AddFunction(func); @@ -135,7 +136,8 @@ TEST_F(VertexPullingTest, Error_InvalidEntryPoint) { TEST_F(VertexPullingTest, Error_EntryPointWrongStage) { auto* func = create( Source{}, mod()->RegisterSymbol("main"), "main", ast::VariableList{}, - mod()->create(), create(Source{}), + mod()->create(), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kFragment, Source{}), }); diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index db04d8f92a..36eb700471 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -151,9 +151,10 @@ TEST_F(TypeDeterminerTest, Stmt_Case) { auto* rhs = create( Source{}, create(Source{}, &f32, 2.3f)); - auto* body = create(Source{}); - body->append(create(Source{}, lhs, rhs)); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, lhs, rhs), + }); ast::CaseSelectorList lit; lit.push_back(create(Source{}, &i32, 3)); ast::CaseStatement cse(Source{}, lit, body); @@ -174,8 +175,10 @@ TEST_F(TypeDeterminerTest, Stmt_Block) { auto* rhs = create( Source{}, create(Source{}, &f32, 2.3f)); - ast::BlockStatement block(Source{}); - block.append(create(Source{}, lhs, rhs)); + ast::BlockStatement block( + Source{}, ast::StatementList{ + create(Source{}, lhs, rhs), + }); EXPECT_TRUE(td()->DetermineResultType(&block)); ASSERT_NE(lhs->result_type(), nullptr); @@ -193,9 +196,10 @@ TEST_F(TypeDeterminerTest, Stmt_Else) { auto* rhs = create( Source{}, create(Source{}, &f32, 2.3f)); - auto* body = create(Source{}); - body->append(create(Source{}, lhs, rhs)); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, lhs, rhs), + }); ast::ElseStatement stmt( Source{}, create( @@ -220,9 +224,11 @@ TEST_F(TypeDeterminerTest, Stmt_If) { auto* else_rhs = create( Source{}, create(Source{}, &f32, 2.3f)); - auto* else_body = create(Source{}); - else_body->append( - create(Source{}, else_lhs, else_rhs)); + auto* else_body = create( + Source{}, + ast::StatementList{ + create(Source{}, else_lhs, else_rhs), + }); auto* else_stmt = create( Source{}, @@ -235,9 +241,10 @@ TEST_F(TypeDeterminerTest, Stmt_If) { auto* rhs = create( Source{}, create(Source{}, &f32, 2.3f)); - auto* body = create(Source{}); - body->append(create(Source{}, lhs, rhs)); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, lhs, rhs), + }); ast::IfStatement stmt( Source{}, create( @@ -266,18 +273,21 @@ TEST_F(TypeDeterminerTest, Stmt_Loop) { auto* body_rhs = create( Source{}, create(Source{}, &f32, 2.3f)); - auto* body = create(Source{}); - body->append(create(Source{}, body_lhs, body_rhs)); - + auto* body = create( + Source{}, + ast::StatementList{ + create(Source{}, body_lhs, body_rhs), + }); auto* continuing_lhs = create( Source{}, create(Source{}, &i32, 2)); auto* continuing_rhs = create( Source{}, create(Source{}, &f32, 2.3f)); - auto* continuing = create(Source{}); - continuing->append(create(Source{}, continuing_lhs, - continuing_rhs)); - + auto* continuing = create( + Source{}, ast::StatementList{ + create(Source{}, continuing_lhs, + continuing_rhs), + }); ast::LoopStatement stmt(Source{}, body, continuing); EXPECT_TRUE(td()->DetermineResultType(&stmt)); @@ -319,9 +329,10 @@ TEST_F(TypeDeterminerTest, Stmt_Switch) { auto* rhs = create( Source{}, create(Source{}, &f32, 2.3f)); - auto* body = create(Source{}); - body->append(create(Source{}, lhs, rhs)); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, lhs, rhs), + }); ast::CaseSelectorList lit; lit.push_back(create(Source{}, &i32, 3)); @@ -350,7 +361,8 @@ TEST_F(TypeDeterminerTest, Stmt_Call) { ast::VariableList params; auto* func = create( Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32, - create(Source{}), ast::FunctionDecorationList{}); + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); mod->AddFunction(func); // Register the function @@ -380,16 +392,21 @@ TEST_F(TypeDeterminerTest, Stmt_Call_undeclared) { mod->RegisterSymbol("func"), "func"), call_params); ast::VariableList params0; - auto* main_body = create(Source{}); - main_body->append(create(Source{}, call_expr)); - main_body->append(create(Source{})); + auto* main_body = create( + Source{}, ast::StatementList{ + create(Source{}, call_expr), + create(Source{}), + }); + auto* func_main = create(Source{}, mod->RegisterSymbol("main"), "main", params0, &f32, main_body, ast::FunctionDecorationList{}); mod->AddFunction(func_main); - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* func = create(Source{}, mod->RegisterSymbol("func"), "func", params0, &f32, body, ast::FunctionDecorationList{}); @@ -675,7 +692,8 @@ TEST_F(TypeDeterminerTest, Expr_Call) { ast::VariableList params; auto* func = create( Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32, - create(Source{}), ast::FunctionDecorationList{}); + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); mod->AddFunction(func); // Register the function @@ -698,7 +716,8 @@ TEST_F(TypeDeterminerTest, Expr_Call_WithParams) { ast::VariableList params; auto* func = create( Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32, - create(Source{}), ast::FunctionDecorationList{}); + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); mod->AddFunction(func); // Register the function @@ -851,13 +870,14 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable_Const) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create( - Source{}, my_var, - create(Source{}, mod->RegisterSymbol("my_var"), - "my_var"))); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create( + Source{}, my_var, + create( + Source{}, mod->RegisterSymbol("my_var"), "my_var")), + }); ast::Function f(Source{}, mod->RegisterSymbol("my_func"), "my_func", {}, &f32, body, ast::FunctionDecorationList{}); @@ -873,21 +893,23 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable) { auto* my_var = create( Source{}, mod->RegisterSymbol("my_var"), "my_var"); - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, // source - "my_var", // name - ast::StorageClass::kNone, // storage_class - &f32, // type - false, // is_const - nullptr, // constructor - ast::VariableDecorationList{}))); // decorations - - body->append(create( - Source{}, my_var, - create(Source{}, mod->RegisterSymbol("my_var"), - "my_var"))); + ast::StatementList{ + create( + Source{}, create( + Source{}, // source + "my_var", // name + ast::StorageClass::kNone, // storage_class + &f32, // type + false, // is_const + nullptr, // constructor + ast::VariableDecorationList{})), // decorations + create( + Source{}, my_var, + create( + Source{}, mod->RegisterSymbol("my_var"), "my_var")), + }); ast::Function f(Source{}, mod->RegisterSymbol("myfunc"), "my_func", {}, &f32, body, ast::FunctionDecorationList{}); @@ -909,21 +931,23 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) { auto* my_var = create( Source{}, mod->RegisterSymbol("my_var"), "my_var"); - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, // source - "my_var", // name - ast::StorageClass::kNone, // storage_class - &ptr, // type - false, // is_const - nullptr, // constructor - ast::VariableDecorationList{}))); // decorations - - body->append(create( - Source{}, my_var, - create(Source{}, mod->RegisterSymbol("my_var"), - "my_var"))); + ast::StatementList{ + create( + Source{}, create( + Source{}, // source + "my_var", // name + ast::StorageClass::kNone, // storage_class + &ptr, // type + false, // is_const + nullptr, // constructor + ast::VariableDecorationList{})), // decorations + create( + Source{}, my_var, + create( + Source{}, mod->RegisterSymbol("my_var"), "my_var")), + }); ast::Function f(Source{}, mod->RegisterSymbol("my_func"), "my_func", {}, &f32, body, ast::FunctionDecorationList{}); @@ -944,7 +968,8 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_Function) { ast::VariableList params; auto* func = create( Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32, - create(Source{}), ast::FunctionDecorationList{}); + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); mod->AddFunction(func); // Register the function @@ -1013,31 +1038,34 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables) { mod->AddGlobalVariable(priv_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create( - Source{}, mod->RegisterSymbol("out_var"), "out_var"), - create(Source{}, mod->RegisterSymbol("in_var"), - "in_var"))); - body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("wg_var"), - "wg_var"), - create(Source{}, mod->RegisterSymbol("wg_var"), - "wg_var"))); - body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("sb_var"), - "sb_var"), - create(Source{}, mod->RegisterSymbol("sb_var"), - "sb_var"))); - body->append(create( - Source{}, - create( - Source{}, mod->RegisterSymbol("priv_var"), "priv_var"), - create( - Source{}, mod->RegisterSymbol("priv_var"), "priv_var"))); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("out_var"), "out_var"), + create( + Source{}, mod->RegisterSymbol("in_var"), "in_var")), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("wg_var"), "wg_var"), + create( + Source{}, mod->RegisterSymbol("wg_var"), "wg_var")), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("sb_var"), "sb_var"), + create( + Source{}, mod->RegisterSymbol("sb_var"), "sb_var")), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("priv_var"), "priv_var"), + create( + Source{}, mod->RegisterSymbol("priv_var"), "priv_var")), + }); auto* func = create(Source{}, mod->RegisterSymbol("my_func"), "my_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -1106,31 +1134,34 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) { mod->AddGlobalVariable(wg_var); mod->AddGlobalVariable(priv_var); - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create( - Source{}, mod->RegisterSymbol("out_var"), "out_var"), - create(Source{}, mod->RegisterSymbol("in_var"), - "in_var"))); - body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("wg_var"), - "wg_var"), - create(Source{}, mod->RegisterSymbol("wg_var"), - "wg_var"))); - body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("sb_var"), - "sb_var"), - create(Source{}, mod->RegisterSymbol("sb_var"), - "sb_var"))); - body->append(create( - Source{}, - create( - Source{}, mod->RegisterSymbol("priv_var"), "priv_var"), - create( - Source{}, mod->RegisterSymbol("priv_var"), "priv_var"))); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("out_var"), "out_var"), + create( + Source{}, mod->RegisterSymbol("in_var"), "in_var")), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("wg_var"), "wg_var"), + create( + Source{}, mod->RegisterSymbol("wg_var"), "wg_var")), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("sb_var"), "sb_var"), + create( + Source{}, mod->RegisterSymbol("sb_var"), "sb_var")), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("priv_var"), "priv_var"), + create( + Source{}, mod->RegisterSymbol("priv_var"), "priv_var")), + }); ast::VariableList params; auto* func = create(Source{}, mod->RegisterSymbol("my_func"), "my_func", @@ -1138,16 +1169,20 @@ TEST_F(TypeDeterminerTest, Function_RegisterInputOutputVariables_SubFunction) { mod->AddFunction(func); - body = create(Source{}); - body->append(create( + body = create( Source{}, - create( - Source{}, mod->RegisterSymbol("out_var"), "out_var"), - create( - Source{}, - create( - Source{}, mod->RegisterSymbol("my_func"), "my_func"), - ast::ExpressionList{}))); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("out_var"), "out_var"), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("my_func"), "my_func"), + ast::ExpressionList{})), + }); + auto* func2 = create(Source{}, mod->RegisterSymbol("func"), "func", params, &f32, body, ast::FunctionDecorationList{}); @@ -1178,15 +1213,17 @@ TEST_F(TypeDeterminerTest, Function_NotRegisterFunctionVariable) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create( + auto* body = create( Source{}, - create(Source{}, mod->RegisterSymbol("var"), - "var"), - create( - Source{}, create(Source{}, &f32, 1.f)))); - + ast::StatementList{ + create(Source{}, var), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("var"), "var"), + create( + Source{}, create(Source{}, &f32, 1.f))), + }); ast::VariableList params; auto* func = create(Source{}, mod->RegisterSymbol("my_func"), "my_func", @@ -2869,8 +2906,9 @@ TEST_F(TypeDeterminerTest, StorageClass_SetsIfMissing) { ast::VariableDecorationList{}); // decorations auto* stmt = create(Source{}, var); - auto* body = create(Source{}); - body->append(stmt); + auto* body = create(Source{}, ast::StatementList{ + stmt, + }); auto* func = create(Source{}, mod->RegisterSymbol("func"), "func", ast::VariableList{}, &i32, body, ast::FunctionDecorationList{}); @@ -2894,8 +2932,9 @@ TEST_F(TypeDeterminerTest, StorageClass_DoesNotSetOnConst) { ast::VariableDecorationList{}); // decorations auto* stmt = create(Source{}, var); - auto* body = create(Source{}); - body->append(stmt); + auto* body = create(Source{}, ast::StatementList{ + stmt, + }); auto* func = create(Source{}, mod->RegisterSymbol("func"), "func", ast::VariableList{}, &i32, body, ast::FunctionDecorationList{}); @@ -2919,8 +2958,9 @@ TEST_F(TypeDeterminerTest, StorageClass_NonFunctionClassError) { ast::VariableDecorationList{}); // decorations auto* stmt = create(Source{}, var); - auto* body = create(Source{}); - body->append(stmt); + auto* body = create(Source{}, ast::StatementList{ + stmt, + }); auto* func = create(Source{}, mod->RegisterSymbol("func"), "func", ast::VariableList{}, &i32, body, ast::FunctionDecorationList{}); @@ -5237,69 +5277,82 @@ TEST_F(TypeDeterminerTest, Function_EntryPoints_StageDecoration) { // ep_2 -> {} ast::VariableList params; - auto* body = create(Source{}); + auto* body = create(Source{}, ast::StatementList{}); auto* func_b = create(Source{}, mod->RegisterSymbol("b"), "b", params, &f32, body, ast::FunctionDecorationList{}); - body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("second"), - "second"), - create(Source{}, - create( - Source{}, mod->RegisterSymbol("b"), "b"), - ast::ExpressionList{}))); + body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("second"), "second"), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("b"), "b"), + ast::ExpressionList{})), + }); auto* func_c = create(Source{}, mod->RegisterSymbol("c"), "c", params, &f32, body, ast::FunctionDecorationList{}); - body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("first"), - "first"), - create(Source{}, - create( - Source{}, mod->RegisterSymbol("c"), "c"), - ast::ExpressionList{}))); + body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("first"), "first"), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("c"), "c"), + ast::ExpressionList{})), + }); auto* func_a = create(Source{}, mod->RegisterSymbol("a"), "a", params, &f32, body, ast::FunctionDecorationList{}); - body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("call_a"), - "call_a"), - create(Source{}, - create( - Source{}, mod->RegisterSymbol("a"), "a"), - ast::ExpressionList{}))); - body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("call_b"), - "call_b"), - create(Source{}, - create( - Source{}, mod->RegisterSymbol("b"), "b"), - ast::ExpressionList{}))); + body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("call_a"), "call_a"), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("a"), "a"), + ast::ExpressionList{})), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("call_b"), "call_b"), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("b"), "b"), + ast::ExpressionList{})), + }); auto* ep_1 = create( Source{}, mod->RegisterSymbol("ep_1"), "ep_1", params, &f32, body, ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex, Source{}), }); - body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("call_c"), - "call_c"), - create(Source{}, - create( - Source{}, mod->RegisterSymbol("c"), "c"), - ast::ExpressionList{}))); + body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("call_c"), "call_c"), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("c"), "c"), + ast::ExpressionList{})), + }); auto* ep_2 = create( Source{}, mod->RegisterSymbol("ep_2"), "ep_2", params, &f32, body, ast::FunctionDecorationList{ diff --git a/src/validator/validator_control_block_test.cc b/src/validator/validator_control_block_test.cc index 55a44acef9..0cbd07b2f9 100644 --- a/src/validator/validator_control_block_test.cc +++ b/src/validator/validator_control_block_test.cc @@ -57,14 +57,17 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) { auto* cond = create( Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a"); ast::CaseSelectorList default_csl; - auto* block_default = create(Source{}); + auto* block_default = + create(Source{}, ast::StatementList{}); ast::CaseStatementList body; body.push_back( create(Source{}, default_csl, block_default)); - auto* block = create(Source{}); - block->append(create(Source{}, var)); - block->append(create(Source{}, cond, body)); + auto* block = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}, cond, body), + }); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_FALSE(v()->ValidateStatements(block)); @@ -96,12 +99,15 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) { csl.push_back(create(Source{}, &i32, 1)); ast::CaseStatementList body; body.push_back(create( - Source{}, csl, create(Source{}))); + Source{}, csl, + create(Source{}, ast::StatementList{}))); - auto* block = create(Source{}); - block->append(create(Source{}, var)); - block->append(create(Source{Source::Location{12, 34}}, - cond, body)); + auto* block = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create( + Source{Source::Location{12, 34}}, cond, body), + }); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_FALSE(v()->ValidateStatements(block)); @@ -134,25 +140,30 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) { Source{}, mod()->RegisterSymbol("a"), "a"); ast::CaseSelectorList default_csl_1; - auto* block_default_1 = create(Source{}); + auto* block_default_1 = + create(Source{}, ast::StatementList{}); switch_body.push_back( create(Source{}, default_csl_1, block_default_1)); ast::CaseSelectorList csl_case_1; csl_case_1.push_back(create(Source{}, &i32, 1)); - auto* block_case_1 = create(Source{}); + auto* block_case_1 = + create(Source{}, ast::StatementList{}); switch_body.push_back( create(Source{}, csl_case_1, block_case_1)); ast::CaseSelectorList default_csl_2; - auto* block_default_2 = create(Source{}); + auto* block_default_2 = + create(Source{}, ast::StatementList{}); switch_body.push_back( create(Source{}, default_csl_2, block_default_2)); - auto* block = create(Source{}); - block->append(create(Source{}, var)); - block->append(create(Source{Source::Location{12, 34}}, - cond, switch_body)); + auto* block = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create( + Source{Source::Location{12, 34}}, cond, switch_body), + }); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_FALSE(v()->ValidateStatements(block)); @@ -187,19 +198,21 @@ TEST_F(ValidateControlBlockTest, ast::CaseSelectorList csl; csl.push_back(create(Source{}, &u32, 1)); - switch_body.push_back( - create(Source{Source::Location{12, 34}}, csl, - create(Source{}))); + switch_body.push_back(create( + Source{Source::Location{12, 34}}, csl, + create(Source{}, ast::StatementList{}))); ast::CaseSelectorList default_csl; - auto* block_default = create(Source{}); + auto* block_default = + create(Source{}, ast::StatementList{}); switch_body.push_back( create(Source{}, default_csl, block_default)); - auto* block = create(Source{}); - block->append(create(Source{}, var)); - block->append(create(Source{}, cond, switch_body)); - + auto* block = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}, cond, switch_body), + }); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_EQ(v()->error(), @@ -233,19 +246,21 @@ TEST_F(ValidateControlBlockTest, ast::CaseSelectorList csl; csl.push_back(create(Source{}, &i32, -1)); - switch_body.push_back( - create(Source{Source::Location{12, 34}}, csl, - create(Source{}))); + switch_body.push_back(create( + Source{Source::Location{12, 34}}, csl, + create(Source{}, ast::StatementList{}))); ast::CaseSelectorList default_csl; - auto* block_default = create(Source{}); + auto* block_default = + create(Source{}, ast::StatementList{}); switch_body.push_back( create(Source{}, default_csl, block_default)); - auto* block = create(Source{}); - block->append(create(Source{}, var)); - block->append(create(Source{}, cond, switch_body)); - + auto* block = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}, cond, switch_body), + }); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_EQ(v()->error(), @@ -279,24 +294,27 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) { ast::CaseSelectorList csl_1; csl_1.push_back(create(Source{}, &u32, 0)); switch_body.push_back(create( - Source{}, csl_1, create(Source{}))); + Source{}, csl_1, + create(Source{}, ast::StatementList{}))); ast::CaseSelectorList csl_2; csl_2.push_back(create(Source{}, &u32, 2)); csl_2.push_back(create(Source{}, &u32, 2)); - switch_body.push_back( - create(Source{Source::Location{12, 34}}, csl_2, - create(Source{}))); + switch_body.push_back(create( + Source{Source::Location{12, 34}}, csl_2, + create(Source{}, ast::StatementList{}))); ast::CaseSelectorList default_csl; - auto* block_default = create(Source{}); + auto* block_default = + create(Source{}, ast::StatementList{}); switch_body.push_back( create(Source{}, default_csl, block_default)); - auto* block = create(Source{}); - block->append(create(Source{}, var)); - block->append(create(Source{}, cond, switch_body)); - + auto* block = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}, cond, switch_body), + }); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_EQ(v()->error(), @@ -330,26 +348,29 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) { ast::CaseSelectorList csl_1; csl_1.push_back(create(Source{}, &i32, 10)); switch_body.push_back(create( - Source{}, csl_1, create(Source{}))); + Source{}, csl_1, + create(Source{}, ast::StatementList{}))); ast::CaseSelectorList csl_2; csl_2.push_back(create(Source{}, &i32, 0)); csl_2.push_back(create(Source{}, &i32, 1)); csl_2.push_back(create(Source{}, &i32, 2)); csl_2.push_back(create(Source{}, &i32, 10)); - switch_body.push_back( - create(Source{Source::Location{12, 34}}, csl_2, - create(Source{}))); + switch_body.push_back(create( + Source{Source::Location{12, 34}}, csl_2, + create(Source{}, ast::StatementList{}))); ast::CaseSelectorList default_csl; - auto* block_default = create(Source{}); + auto* block_default = + create(Source{}, ast::StatementList{}); switch_body.push_back( create(Source{}, default_csl, block_default)); - auto* block = create(Source{}); - block->append(create(Source{}, var)); - block->append(create(Source{}, cond, switch_body)); - + auto* block = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}, cond, switch_body), + }); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_EQ(v()->error(), @@ -377,17 +398,20 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) { auto* cond = create( Source{}, mod()->RegisterSymbol("a"), "a"); ast::CaseSelectorList default_csl; - auto* block_default = create(Source{}); - block_default->append( - create(Source{Source::Location{12, 34}})); + auto* block_default = create( + Source{}, + ast::StatementList{ + create(Source{Source::Location{12, 34}}), + }); ast::CaseStatementList body; body.push_back( create(Source{}, default_csl, block_default)); - auto* block = create(Source{}); - block->append(create(Source{}, var)); - block->append(create(Source{}, cond, body)); - + auto* block = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}, cond, body), + }); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_FALSE(v()->ValidateStatements(block)); EXPECT_EQ(v()->error(), @@ -416,19 +440,22 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) { auto* cond = create( Source{}, mod()->RegisterSymbol("a"), "a"); ast::CaseSelectorList default_csl; - auto* block_default = create(Source{}); + auto* block_default = + create(Source{}, ast::StatementList{}); ast::CaseStatementList body; body.push_back(create(Source{Source::Location{12, 34}}, default_csl, block_default)); ast::CaseSelectorList case_csl; case_csl.push_back(create(Source{}, &i32, 5)); - auto* block_case = create(Source{}); + auto* block_case = + create(Source{}, ast::StatementList{}); body.push_back(create(Source{}, case_csl, block_case)); - auto* block = create(Source{}); - block->append(create(Source{}, var)); - block->append(create(Source{}, cond, body)); - + auto* block = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}, cond, body), + }); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); EXPECT_TRUE(v()->ValidateStatements(block)) << v()->error(); } @@ -457,15 +484,17 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) { auto* cond = create( Source{}, mod()->RegisterSymbol("a"), "a"); ast::CaseSelectorList default_csl; - auto* block_default = create(Source{}); + auto* block_default = + create(Source{}, ast::StatementList{}); ast::CaseStatementList body; body.push_back(create(Source{Source::Location{12, 34}}, default_csl, block_default)); - auto* block = create(Source{}); - block->append(create(Source{}, var)); - block->append(create(Source{}, cond, body)); - + auto* block = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}, cond, body), + }); mod()->AddConstructedType(&my_int); EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error(); diff --git a/src/validator/validator_function_test.cc b/src/validator/validator_function_test.cc index 50420bc249..561caf58d5 100644 --- a/src/validator/validator_function_test.cc +++ b/src/validator/validator_function_test.cc @@ -52,8 +52,10 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) { ast::VariableList params; ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{}, var)); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + }); auto* func = create( Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func", params, &void_type, body, @@ -74,7 +76,8 @@ TEST_F(ValidateFunctionTest, ast::VariableList params; auto* func = create( Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func", - params, &void_type, create(Source{}), + params, &void_type, + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex, Source{}), }); @@ -101,8 +104,10 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) { ast::VariableList params; ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{}, var)); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + }); auto* func = create( Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func", params, &i32, body, ast::FunctionDecorationList{}); @@ -121,7 +126,7 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) { ast::VariableList params; auto* func = create( Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func", - params, &i32, create(Source{}), + params, &i32, create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{}); mod()->AddFunction(func); @@ -137,8 +142,10 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) { ast::type::Void void_type; ast::VariableList params; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* func = create( Source{}, mod()->RegisterSymbol("func"), "func", params, &void_type, body, ast::FunctionDecorationList{ @@ -155,12 +162,15 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) { ast::type::Void void_type; ast::type::I32 i32; ast::VariableList params; - auto* body = create(Source{}); auto* return_expr = create( Source{}, create(Source{}, &i32, 2)); - body->append(create(Source{Source::Location{12, 34}}, - return_expr)); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{Source::Location{12, 34}}, return_expr), + }); + auto* func = create(Source{}, mod()->RegisterSymbol("func"), "func", params, &void_type, body, ast::FunctionDecorationList{}); @@ -179,12 +189,15 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) { ast::type::I32 i32; ast::type::F32 f32; ast::VariableList params; - auto* body = create(Source{}); auto* return_expr = create( Source{}, create(Source{}, &i32, 2)); - body->append(create(Source{Source::Location{12, 34}}, - return_expr)); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{Source::Location{12, 34}}, return_expr), + }); + auto* func = create(Source{}, mod()->RegisterSymbol("func"), "func", params, &f32, body, ast::FunctionDecorationList{}); @@ -205,21 +218,25 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) { ast::type::I32 i32; ast::VariableList params; - auto* body = create(Source{}); auto* return_expr = create( Source{}, create(Source{}, &i32, 2)); - body->append(create(Source{}, return_expr)); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, return_expr), + }); auto* func = create(Source{}, mod()->RegisterSymbol("func"), "func", params, &i32, body, ast::FunctionDecorationList{}); ast::VariableList params_copy; - auto* body_copy = create(Source{}); auto* return_expr_copy = create( Source{}, create(Source{}, &i32, 2)); + auto* body_copy = create( + Source{}, ast::StatementList{ + create(Source{}, return_expr_copy), + }); - body_copy->append(create(Source{}, return_expr_copy)); auto* func_copy = create( Source{Source::Location{12, 34}}, mod()->RegisterSymbol("func"), "func", params_copy, &i32, body_copy, ast::FunctionDecorationList{}); @@ -243,9 +260,11 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) { "func"), call_params); ast::VariableList params0; - auto* body0 = create(Source{}); - body0->append(create(Source{}, call_expr)); - body0->append(create(Source{})); + auto* body0 = create( + Source{}, ast::StatementList{ + create(Source{}, call_expr), + create(Source{}), + }); auto* func0 = create(Source{}, mod()->RegisterSymbol("func"), "func", params0, &f32, body0, ast::FunctionDecorationList{}); @@ -275,12 +294,15 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) { ast::VariableDecorationList{}); // decorations ast::VariableList params0; - auto* body0 = create(Source{}); - body0->append(create(Source{}, var)); auto* return_expr = create( Source{}, create(Source{}, &i32, 2)); - body0->append(create(Source{}, return_expr)); + auto* body0 = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}, return_expr), + }); + auto* func0 = create(Source{}, mod()->RegisterSymbol("func"), "func", params0, &i32, body0, ast::FunctionDecorationList{}); @@ -299,8 +321,10 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) { auto* return_expr = create( Source{}, create(Source{}, &i32, 0)); - auto* body = create(Source{}); - body->append(create(Source{}, return_expr)); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, return_expr), + }); auto* func = create( Source{Source::Location{12, 34}}, mod()->RegisterSymbol("vtx_main"), "vtx_main", params, &i32, body, @@ -329,8 +353,10 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) { false, // is_const nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* func = create( Source{Source::Location{12, 34}}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params, &void_type, body, @@ -352,8 +378,10 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) { // fn main() -> void { return; } ast::type::Void void_type; ast::VariableList params; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* func = create( Source{Source::Location{12, 34}}, mod()->RegisterSymbol("main"), "main", params, &void_type, body, @@ -375,8 +403,10 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) { // fn vtx_func() -> void { return; } ast::type::Void void_type; ast::VariableList params; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* func = create( Source{}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params, &void_type, body, @@ -393,8 +423,10 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) { // fn vtx_func() -> void { return; } ast::type::Void void_type; ast::VariableList params; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* func = create( Source{}, mod()->RegisterSymbol("vtx_func"), "vtx_func", params, &void_type, body, ast::FunctionDecorationList{}); diff --git a/src/validator/validator_test.cc b/src/validator/validator_test.cc index 765ebee210..876fb832b4 100644 --- a/src/validator/validator_test.cc +++ b/src/validator/validator_test.cc @@ -103,9 +103,11 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) { auto* rhs = create( Source{}, create(Source{}, &i32, 2)); - auto* body = create(Source{}); - body->append(create( - Source{Source::Location{12, 34}}, lhs, rhs)); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{Source::Location{12, 34}}, lhs, rhs), + }); EXPECT_FALSE(td()->DetermineStatements(body)); EXPECT_EQ(td()->error(), @@ -199,10 +201,12 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) { auto* rhs = create( Source{}, create(Source{}, &i32, 2)); - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create( - Source{Source::Location{12, 34}}, lhs, rhs)); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create( + Source{Source::Location{12, 34}}, lhs, rhs), + }); EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error(); ASSERT_NE(lhs->result_type(), nullptr); @@ -234,10 +238,12 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) { auto* rhs = create( Source{}, create(Source{}, &f32, 2.3f)); - ast::BlockStatement block(Source{}); - block.append(create(Source{}, var)); - block.append(create( - Source{Source::Location{12, 34}}, lhs, rhs)); + ast::BlockStatement block( + Source{}, ast::StatementList{ + create(Source{}, var), + create( + Source{Source::Location{12, 34}}, lhs, rhs), + }); EXPECT_TRUE(td()->DetermineStatements(&block)) << td()->error(); ASSERT_NE(lhs->result_type(), nullptr); @@ -339,9 +345,11 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) { Source{}, create(Source{}, &f32, 3.14f)); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{Source::Location{12, 34}}, lhs, rhs)); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{Source::Location{12, 34}}, lhs, rhs), + }); auto* func = create(Source{}, mod()->RegisterSymbol("my_func"), "my_func", params, &f32, body, @@ -379,10 +387,13 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) { ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{Source::Location{12, 34}}, lhs, rhs)); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{Source::Location{12, 34}}, lhs, rhs), + create(Source{}), + }); + auto* func = create( Source{}, mod()->RegisterSymbol("my_func"), "my_func", params, &void_type, body, @@ -415,19 +426,23 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) { ast::type::Bool bool_type; auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - auto* body = create(Source{}); - body->append(create(Source{}, var)); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + }); auto* lhs = create( Source{Source::Location{12, 34}}, mod()->RegisterSymbol("a"), "a"); auto* rhs = create( Source{}, create(Source{}, &f32, 3.14f)); - auto* outer_body = create(Source{}); - outer_body->append( - create(Source{}, cond, body, ast::ElseStatementList{})); - outer_body->append(create( - Source{Source::Location{12, 34}}, lhs, rhs)); + auto* outer_body = create( + Source{}, ast::StatementList{ + create(Source{}, cond, body, + ast::ElseStatementList{}), + create( + Source{Source::Location{12, 34}}, lhs, rhs), + }); EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error(); ASSERT_NE(lhs->result_type(), nullptr); @@ -461,14 +476,19 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) { ast::type::Bool bool_type; auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - auto* body = create(Source{}); - body->append(create( - Source{Source::Location{12, 34}}, lhs, rhs)); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{Source::Location{12, 34}}, lhs, rhs), + }); + + auto* outer_body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}, cond, body, + ast::ElseStatementList{}), + }); - auto* outer_body = create(Source{}); - outer_body->append(create(Source{}, var)); - outer_body->append( - create(Source{}, cond, body, ast::ElseStatementList{})); EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error(); ASSERT_NE(lhs->result_type(), nullptr); ASSERT_NE(rhs->result_type(), nullptr); @@ -564,10 +584,12 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) { auto* rhs = create( Source{}, create(Source{}, &i32, 2)); - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create( - Source{Source::Location{12, 34}}, lhs, rhs)); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create( + Source{Source::Location{12, 34}}, lhs, rhs), + }); EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error(); ASSERT_NE(lhs->result_type(), nullptr); @@ -609,9 +631,12 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) { create(Source{}, &f32, 2.0)), // constructor ast::VariableDecorationList{}); // decorations ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{Source::Location{12, 34}}, var)); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{Source::Location{12, 34}}, var), + }); + auto* func = create(Source{}, mod()->RegisterSymbol("my_func"), "my_func", params, &void_type, body, ast::FunctionDecorationList{}); @@ -655,10 +680,13 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) { ast::VariableDecorationList{}); // decorations ast::VariableList params; - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create( - Source{Source::Location{12, 34}}, var_a_float)); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create( + Source{Source::Location{12, 34}}, var_a_float), + }); + auto* func = create(Source{}, mod()->RegisterSymbol("my_func"), "my_func", params, &void_type, body, ast::FunctionDecorationList{}); @@ -691,8 +719,10 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) { ast::type::Bool bool_type; auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - auto* body = create(Source{}); - body->append(create(Source{}, var)); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + }); auto* var_a_float = create( Source{}, // source @@ -705,11 +735,13 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) { create(Source{}, &f32, 3.14)), // constructor ast::VariableDecorationList{}); // decorations - auto* outer_body = create(Source{}); - outer_body->append( - create(Source{}, cond, body, ast::ElseStatementList{})); - outer_body->append(create( - Source{Source::Location{12, 34}}, var_a_float)); + auto* outer_body = create( + Source{}, ast::StatementList{ + create(Source{}, cond, body, + ast::ElseStatementList{}), + create( + Source{Source::Location{12, 34}}, var_a_float), + }); EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error(); EXPECT_TRUE(v()->ValidateStatements(outer_body)) << v()->error(); @@ -748,14 +780,18 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) { ast::type::Bool bool_type; auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - auto* body = create(Source{}); - body->append(create( - Source{Source::Location{12, 34}}, var)); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{Source::Location{12, 34}}, var), + }); - auto* outer_body = create(Source{}); - outer_body->append(create(Source{}, var_a_float)); - outer_body->append( - create(Source{}, cond, body, ast::ElseStatementList{})); + auto* outer_body = create( + Source{}, ast::StatementList{ + create(Source{}, var_a_float), + create(Source{}, cond, body, + ast::ElseStatementList{}), + }); EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error(); EXPECT_FALSE(v()->ValidateStatements(outer_body)); @@ -790,19 +826,24 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) { ast::VariableDecorationList{}); // decorations ast::VariableList params0; - auto* body0 = create(Source{}); - body0->append(create( - Source{Source::Location{12, 34}}, var0)); - body0->append(create(Source{})); + auto* body0 = create( + Source{}, ast::StatementList{ + create( + Source{Source::Location{12, 34}}, var0), + create(Source{}), + }); + auto* func0 = create(Source{}, mod()->RegisterSymbol("func0"), "func0", params0, &void_type, body0, ast::FunctionDecorationList{}); ast::VariableList params1; - auto* body1 = create(Source{}); - body1->append(create( - Source{Source::Location{13, 34}}, var1)); - body1->append(create(Source{})); + auto* body1 = create( + Source{}, ast::StatementList{ + create( + Source{Source::Location{13, 34}}, var1), + create(Source{}), + }); auto* func1 = create( Source{}, mod()->RegisterSymbol("func1"), "func1", params1, &void_type, body1, @@ -838,10 +879,12 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) { auto* rhs = create( Source{}, create(Source{}, &i32, 2)); - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create( - Source{Source::Location{12, 34}}, lhs, rhs)); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create( + Source{Source::Location{12, 34}}, lhs, rhs), + }); EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error(); ASSERT_NE(lhs->result_type(), nullptr); diff --git a/src/validator/validator_type_test.cc b/src/validator/validator_type_test.cc index a7f84ae8a3..4950b33ce5 100644 --- a/src/validator/validator_type_test.cc +++ b/src/validator/validator_type_test.cc @@ -203,10 +203,11 @@ TEST_F(ValidatorTypeTest, RuntimeArrayInFunction_Fail) { ast::VariableDecorationList{}); // decorations ast::VariableList params; ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create( - Source{Source::Location{12, 34}}, var)); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{Source::Location{12, 34}}, var), + }); auto* func = create( Source{}, mod()->RegisterSymbol("func"), "func", params, &void_type, body, ast::FunctionDecorationList{ diff --git a/src/writer/hlsl/generator_impl_binary_test.cc b/src/writer/hlsl/generator_impl_binary_test.cc index 3c52f9de5d..9b7a4a0cbb 100644 --- a/src/writer/hlsl/generator_impl_binary_test.cc +++ b/src/writer/hlsl/generator_impl_binary_test.cc @@ -464,16 +464,22 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) { ast::type::I32 i32; - auto* body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, create(Source{}, &i32, 3)))); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, create( + Source{}, create( + Source{}, &i32, 3))), + }); auto* else_stmt = create(Source{}, nullptr, body); - body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, create(Source{}, &i32, 2)))); + body = create( + Source{}, ast::StatementList{ + create( + Source{}, create( + Source{}, create( + Source{}, &i32, 2))), + }); auto* else_if_stmt = create( Source{}, create( @@ -484,10 +490,13 @@ TEST_F(HlslGeneratorImplTest_Binary, If_WithLogical) { "c")), body); - body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, create(Source{}, &i32, 1)))); + body = create( + Source{}, ast::StatementList{ + create( + Source{}, create( + Source{}, create( + Source{}, &i32, 1))), + }); ast::IfStatement expr(Source{}, create( @@ -659,10 +668,10 @@ TEST_F(HlslGeneratorImplTest_Binary, Call_WithLogical) { ast::type::Void void_type; - auto* func = create(Source{}, mod.RegisterSymbol("foo"), "foo", - ast::VariableList{}, &void_type, - create(Source{}), - ast::FunctionDecorationList{}); + auto* func = create( + Source{}, mod.RegisterSymbol("foo"), "foo", ast::VariableList{}, + &void_type, create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); mod.AddFunction(func); ast::ExpressionList params; diff --git a/src/writer/hlsl/generator_impl_block_test.cc b/src/writer/hlsl/generator_impl_block_test.cc index 01865880cd..c7fa1e2273 100644 --- a/src/writer/hlsl/generator_impl_block_test.cc +++ b/src/writer/hlsl/generator_impl_block_test.cc @@ -26,9 +26,9 @@ namespace { using HlslGeneratorImplTest_Block = TestHelper; TEST_F(HlslGeneratorImplTest_Block, Emit_Block) { - ast::BlockStatement b(Source{}); - b.append(create(Source{})); - + ast::BlockStatement b(Source{}, ast::StatementList{ + create(Source{}), + }); gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(out, &b)) << gen.error(); @@ -39,9 +39,9 @@ TEST_F(HlslGeneratorImplTest_Block, Emit_Block) { } TEST_F(HlslGeneratorImplTest_Block, Emit_Block_WithoutNewline) { - ast::BlockStatement b(Source{}); - b.append(create(Source{})); - + ast::BlockStatement b(Source{}, ast::StatementList{ + create(Source{}), + }); gen.increment_indent(); ASSERT_TRUE(gen.EmitBlock(out, &b)) << gen.error(); diff --git a/src/writer/hlsl/generator_impl_call_test.cc b/src/writer/hlsl/generator_impl_call_test.cc index 50d06d6002..225c962b99 100644 --- a/src/writer/hlsl/generator_impl_call_test.cc +++ b/src/writer/hlsl/generator_impl_call_test.cc @@ -36,10 +36,10 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) { Source{}, mod.RegisterSymbol("my_func"), "my_func"); ast::CallExpression call(Source{}, id, {}); - auto* func = create(Source{}, mod.RegisterSymbol("my_func"), - "my_func", ast::VariableList{}, &void_type, - create(Source{}), - ast::FunctionDecorationList{}); + auto* func = create( + Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, + &void_type, create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); mod.AddFunction(func); ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error(); @@ -58,10 +58,10 @@ TEST_F(HlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) { Source{}, mod.RegisterSymbol("param2"), "param2")); ast::CallExpression call(Source{}, id, params); - auto* func = create(Source{}, mod.RegisterSymbol("my_func"), - "my_func", ast::VariableList{}, &void_type, - create(Source{}), - ast::FunctionDecorationList{}); + auto* func = create( + Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, + &void_type, create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); mod.AddFunction(func); ASSERT_TRUE(gen.EmitExpression(pre, out, &call)) << gen.error(); @@ -81,10 +81,10 @@ TEST_F(HlslGeneratorImplTest_Call, EmitStatement_Call) { ast::CallStatement call(Source{}, create(Source{}, id, params)); - auto* func = create(Source{}, mod.RegisterSymbol("my_func"), - "my_func", ast::VariableList{}, &void_type, - create(Source{}), - ast::FunctionDecorationList{}); + auto* func = create( + Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, + &void_type, create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); mod.AddFunction(func); gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(out, &call)) << gen.error(); diff --git a/src/writer/hlsl/generator_impl_case_test.cc b/src/writer/hlsl/generator_impl_case_test.cc index 55105f8e2a..8970ce9e3b 100644 --- a/src/writer/hlsl/generator_impl_case_test.cc +++ b/src/writer/hlsl/generator_impl_case_test.cc @@ -33,9 +33,10 @@ using HlslGeneratorImplTest_Case = TestHelper; TEST_F(HlslGeneratorImplTest_Case, Emit_Case) { ast::type::I32 i32; - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::CaseSelectorList lit; lit.push_back(create(Source{}, &i32, 5)); ast::CaseStatement c(Source{}, lit, body); @@ -54,7 +55,9 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) { ast::CaseSelectorList lit; lit.push_back(create(Source{}, &i32, 5)); - ast::CaseStatement c(Source{}, lit, create(Source{})); + ast::CaseStatement c( + Source{}, lit, + create(Source{}, ast::StatementList{})); gen.increment_indent(); @@ -68,9 +71,10 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) { ast::type::I32 i32; - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::CaseSelectorList lit; lit.push_back(create(Source{}, &i32, 5)); ast::CaseStatement c(Source{}, lit, body); @@ -87,9 +91,10 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_WithFallthrough) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) { ast::type::I32 i32; - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::CaseSelectorList lit; lit.push_back(create(Source{}, &i32, 5)); lit.push_back(create(Source{}, &i32, 6)); @@ -106,8 +111,10 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) { } TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body); gen.increment_indent(); diff --git a/src/writer/hlsl/generator_impl_function_entry_point_data_test.cc b/src/writer/hlsl/generator_impl_function_entry_point_data_test.cc index 2deaf623ff..d869cc0e7b 100644 --- a/src/writer/hlsl/generator_impl_function_entry_point_data_test.cc +++ b/src/writer/hlsl/generator_impl_function_entry_point_data_test.cc @@ -82,20 +82,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("foo"), - "foo"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("bar"), - "bar"))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("foo"), "foo"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("bar"), "bar")), + }); auto* func = create( Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, ast::FunctionDecorationList{ @@ -161,20 +162,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("foo"), - "foo"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("bar"), - "bar"))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("foo"), "foo"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("bar"), "bar")), + }); auto* func = create( Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, ast::FunctionDecorationList{ @@ -240,20 +242,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("foo"), - "foo"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("bar"), - "bar"))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("foo"), "foo"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("bar"), "bar")), + }); auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, ast::FunctionDecorationList{ @@ -318,20 +321,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("foo"), - "foo"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("bar"), - "bar"))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("foo"), "foo"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("bar"), "bar")), + }); auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, ast::FunctionDecorationList{ @@ -393,20 +397,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("foo"), - "foo"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("bar"), - "bar"))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("foo"), "foo"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("bar"), "bar")), + }); auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, ast::FunctionDecorationList{ @@ -463,20 +468,21 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("foo"), - "foo"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("bar"), - "bar"))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("foo"), "foo"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("bar"), "bar")), + }); auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, ast::FunctionDecorationList{ @@ -540,18 +546,19 @@ TEST_F(HlslGeneratorImplTest_EntryPoint, mod.AddGlobalVariable(depth_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("depth"), - "depth"), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("coord"), "coord"), - create(Source{}, mod.RegisterSymbol("x"), - "x")))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("depth"), "depth"), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("coord"), "coord"), + create( + Source{}, mod.RegisterSymbol("x"), "x"))), + }); auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body, ast::FunctionDecorationList{ diff --git a/src/writer/hlsl/generator_impl_function_test.cc b/src/writer/hlsl/generator_impl_function_test.cc index d1dee24d78..5668225609 100644 --- a/src/writer/hlsl/generator_impl_function_test.cc +++ b/src/writer/hlsl/generator_impl_function_test.cc @@ -55,8 +55,10 @@ using HlslGeneratorImplTest_Function = TestHelper; TEST_F(HlslGeneratorImplTest_Function, Emit_Function) { ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* func = create(Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{}); @@ -75,8 +77,10 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function) { TEST_F(HlslGeneratorImplTest_Function, Emit_Function_Name_Collision) { ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("GeometryShader"), "GeometryShader", ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{}); @@ -116,8 +120,10 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithParams) { ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* func = create(Source{}, mod.RegisterSymbol("my_func"), "my_func", params, &void_type, body, ast::FunctionDecorationList{}); @@ -169,14 +175,16 @@ TEST_F(HlslGeneratorImplTest_Function, mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -242,18 +250,20 @@ TEST_F(HlslGeneratorImplTest_Function, mod.AddGlobalVariable(depth_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("depth"), - "depth"), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("coord"), "coord"), - create(Source{}, mod.RegisterSymbol("x"), - "x")))); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("depth"), "depth"), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("coord"), "coord"), + create( + Source{}, mod.RegisterSymbol("x"), "x"))), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -319,9 +329,11 @@ TEST_F(HlslGeneratorImplTest_Function, "x")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -397,9 +409,11 @@ TEST_F(HlslGeneratorImplTest_Function, "x")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -477,9 +491,11 @@ TEST_F(HlslGeneratorImplTest_Function, "b")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -553,9 +569,11 @@ TEST_F(HlslGeneratorImplTest_Function, "b")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -615,24 +633,25 @@ TEST_F(HlslGeneratorImplTest_Function, mod.AddGlobalVariable(coord_var); - ast::VariableList params; - auto* assign = create( + auto* body = create( Source{}, - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("coord"), "coord"), - create(Source{}, mod.RegisterSymbol("b"), - "b")), - create( - Source{}, create(Source{}, &f32, 2.0f))); + ast::StatementList{ + create( + Source{}, + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("coord"), "coord"), + create( + Source{}, mod.RegisterSymbol("b"), "b")), + create( + Source{}, create(Source{}, &f32, 2.0f))), + create(Source{}), + }); - auto* body = create(Source{}); - body->append(assign); - body->append(create(Source{})); auto* func = create( - Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, - &void_type, body, + Source{}, mod.RegisterSymbol("frag_main"), "frag_main", + ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{ create(ast::PipelineStage::kFragment, Source{}), }); @@ -711,22 +730,25 @@ TEST_F( nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("val"), - "val"), - create(Source{}, mod.RegisterSymbol("param"), - "param"))); - body->append(create( - Source{}, create( - Source{}, mod.RegisterSymbol("foo"), "foo"))); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("val"), "val"), + create( + Source{}, mod.RegisterSymbol("param"), "param")), + create( + Source{}, create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + }); auto* sub_func = create( Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -737,17 +759,20 @@ TEST_F( expr.push_back(create( Source{}, create(Source{}, &f32, 1.0f))); - body = create(Source{}); - body->append(create( + body = create( Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), - expr))); - body->append(create(Source{})); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), + expr)), + create(Source{}), + }); auto* func_1 = create( Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, ast::FunctionDecorationList{ @@ -814,10 +839,13 @@ TEST_F(HlslGeneratorImplTest_Function, nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, mod.RegisterSymbol("param"), "param"))); + auto* body = create( + Source{}, + ast::StatementList{ + create( + Source{}, create( + Source{}, mod.RegisterSymbol("param"), "param")), + }); auto* sub_func = create( Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -828,17 +856,20 @@ TEST_F(HlslGeneratorImplTest_Function, expr.push_back(create( Source{}, create(Source{}, &f32, 1.0f))); - body = create(Source{}); - body->append(create( + body = create( Source{}, - create(Source{}, mod.RegisterSymbol("depth"), - "depth"), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), - expr))); - body->append(create(Source{})); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("depth"), "depth"), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), + expr)), + create(Source{}), + }); auto* func_1 = create( Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, ast::FunctionDecorationList{ @@ -913,20 +944,23 @@ TEST_F( nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, mod.RegisterSymbol("depth"), - "depth"), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("coord"), "coord"), - create(Source{}, mod.RegisterSymbol("x"), - "x")))); - body->append(create( - Source{}, create( - Source{}, mod.RegisterSymbol("param"), "param"))); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("depth"), "depth"), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("coord"), "coord"), + create( + Source{}, mod.RegisterSymbol("x"), "x"))), + create( + Source{}, create( + Source{}, mod.RegisterSymbol("param"), "param")), + }); auto* sub_func = create( Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -937,17 +971,20 @@ TEST_F( expr.push_back(create( Source{}, create(Source{}, &f32, 1.0f))); - body = create(Source{}); - body->append(create( + body = create( Source{}, - create(Source{}, mod.RegisterSymbol("depth"), - "depth"), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), - expr))); - body->append(create(Source{})); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("depth"), "depth"), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), + expr)), + create(Source{}), + }); auto* func_1 = create( Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, ast::FunctionDecorationList{ @@ -1013,14 +1050,18 @@ TEST_F(HlslGeneratorImplTest_Function, nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, - create( - Source{}, mod.RegisterSymbol("coord"), "coord"), - create( - Source{}, mod.RegisterSymbol("x"), "x")))); + auto* body = create( + Source{}, + ast::StatementList{ + create( + Source{}, create( + Source{}, + create( + Source{}, mod.RegisterSymbol("coord"), "coord"), + create( + Source{}, mod.RegisterSymbol("x"), "x"))), + }); + auto* sub_func = create( Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -1044,9 +1085,12 @@ TEST_F(HlslGeneratorImplTest_Function, expr), // constructor ast::VariableDecorationList{}); // decorations - body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); + body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); + auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -1107,14 +1151,18 @@ TEST_F(HlslGeneratorImplTest_Function, nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, - create( - Source{}, mod.RegisterSymbol("coord"), "coord"), - create( - Source{}, mod.RegisterSymbol("x"), "x")))); + auto* body = create( + Source{}, + ast::StatementList{ + create( + Source{}, create( + Source{}, + create( + Source{}, mod.RegisterSymbol("coord"), "coord"), + create( + Source{}, mod.RegisterSymbol("x"), "x"))), + }); + auto* sub_func = create( Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -1138,9 +1186,12 @@ TEST_F(HlslGeneratorImplTest_Function, expr), // constructor ast::VariableDecorationList{}); // decorations - body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); + body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); + auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -1187,29 +1238,33 @@ TEST_F(HlslGeneratorImplTest_Function, td.RegisterVariableForTesting(bar_var); mod.AddGlobalVariable(bar_var); + auto* list = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + ast::VariableList params; - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create( - Source{}, create(Source{}, &f32, 1.0f)))); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, create(Source{}, &f32, 1.0f))), + create( + Source{}, + create( + Source{}, ast::BinaryOp::kEqual, + create( + Source{}, create(Source{}, &i32, 1)), + create( + Source{}, create(Source{}, &i32, 1))), + list, ast::ElseStatementList{}), + create(Source{}), + }); - auto* list = create(Source{}); - list->append(create(Source{})); - - body->append(create( - Source{}, - create( - Source{}, ast::BinaryOp::kEqual, - create( - Source{}, create(Source{}, &i32, 1)), - create( - Source{}, create(Source{}, &i32, 1))), - list, ast::ElseStatementList{})); - - body->append(create(Source{})); auto* func_1 = create( Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, ast::FunctionDecorationList{ @@ -1242,7 +1297,8 @@ TEST_F(HlslGeneratorImplTest_Function, auto* func = create( Source{}, mod.RegisterSymbol("GeometryShader"), "GeometryShader", - ast::VariableList{}, &void_type, create(Source{}), + ast::VariableList{}, &void_type, + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kFragment, Source{}), }); @@ -1261,8 +1317,11 @@ TEST_F(HlslGeneratorImplTest_Function, ast::type::Void void_type; ast::VariableList params; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body, ast::FunctionDecorationList{ @@ -1286,8 +1345,11 @@ TEST_F(HlslGeneratorImplTest_Function, ast::type::Void void_type; ast::VariableList params; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body, ast::FunctionDecorationList{ @@ -1323,8 +1385,10 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) { ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* func = create(Source{}, mod.RegisterSymbol("my_func"), "my_func", params, &void_type, body, ast::FunctionDecorationList{}); @@ -1407,9 +1471,12 @@ TEST_F(HlslGeneratorImplTest_Function, "d")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); + auto* func = create( Source{}, mod.RegisterSymbol("a"), "a", params, &void_type, body, ast::FunctionDecorationList{ @@ -1436,9 +1503,12 @@ TEST_F(HlslGeneratorImplTest_Function, "d")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); + auto* func = create( Source{}, mod.RegisterSymbol("b"), "b", params, &void_type, body, ast::FunctionDecorationList{ diff --git a/src/writer/hlsl/generator_impl_if_test.cc b/src/writer/hlsl/generator_impl_if_test.cc index 664a76ac99..0b1105cfca 100644 --- a/src/writer/hlsl/generator_impl_if_test.cc +++ b/src/writer/hlsl/generator_impl_if_test.cc @@ -29,9 +29,10 @@ using HlslGeneratorImplTest_If = TestHelper; TEST_F(HlslGeneratorImplTest_If, Emit_If) { auto* cond = create( Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{}); gen.increment_indent(); @@ -45,14 +46,17 @@ TEST_F(HlslGeneratorImplTest_If, Emit_If) { TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) { auto* else_cond = create( Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); - auto* else_body = create(Source{}); - else_body->append(create(Source{})); + auto* else_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* cond = create( Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement i( Source{}, cond, body, {create(Source{}, else_cond, else_body)}); @@ -71,14 +75,17 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElseIf) { } TEST_F(HlslGeneratorImplTest_If, Emit_IfWithElse) { - auto* else_body = create(Source{}); - else_body->append(create(Source{})); + auto* else_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* cond = create( Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement i( Source{}, cond, body, {create(Source{}, nullptr, else_body)}); @@ -98,17 +105,22 @@ TEST_F(HlslGeneratorImplTest_If, Emit_IfWithMultiple) { auto* else_cond = create( Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); - auto* else_body = create(Source{}); - else_body->append(create(Source{})); + auto* else_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); - auto* else_body_2 = create(Source{}); - else_body_2->append(create(Source{})); + auto* else_body_2 = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* cond = create( Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement i( Source{}, cond, body, { diff --git a/src/writer/hlsl/generator_impl_loop_test.cc b/src/writer/hlsl/generator_impl_loop_test.cc index c413a5283a..bbd3a4e286 100644 --- a/src/writer/hlsl/generator_impl_loop_test.cc +++ b/src/writer/hlsl/generator_impl_loop_test.cc @@ -34,9 +34,10 @@ namespace { using HlslGeneratorImplTest_Loop = TestHelper; TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) { - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::LoopStatement l(Source{}, body, {}); gen.increment_indent(); @@ -48,12 +49,14 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_Loop) { } TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) { - auto* body = create(Source{}); - body->append(create(Source{})); - - auto* continuing = create(Source{}); - continuing->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + auto* continuing = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::LoopStatement l(Source{}, body, continuing); gen.increment_indent(); @@ -75,24 +78,29 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) { TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) { ast::type::F32 f32; - auto* body = create(Source{}); - body->append(create(Source{})); - - auto* continuing = create(Source{}); - continuing->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + auto* continuing = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* inner = create(Source{}, body, continuing); - body = create(Source{}); - body->append(inner); + body = create(Source{}, ast::StatementList{ + inner, + }); auto* lhs = create( Source{}, mod.RegisterSymbol("lhs"), "lhs"); auto* rhs = create( Source{}, mod.RegisterSymbol("rhs"), "rhs"); - continuing = create(Source{}); - continuing->append(create(Source{}, lhs, rhs)); + continuing = create( + Source{}, ast::StatementList{ + create(Source{}, lhs, rhs), + }); ast::LoopStatement outer(Source{}, body, continuing); gen.increment_indent(); @@ -157,26 +165,30 @@ TEST_F(HlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) { create(Source{}, &f32, 2.4)), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create( + auto* body = create( Source{}, - create(Source{}, // source - "other", // name - ast::StorageClass::kFunction, // storage_class - &f32, // type - false, // is_const - nullptr, // constructor - ast::VariableDecorationList{}))); // decorations + ast::StatementList{ + create(Source{}, var), + create( + Source{}, create( + Source{}, // source + "other", // name + ast::StorageClass::kFunction, // storage_class + &f32, // type + false, // is_const + nullptr, // constructor + ast::VariableDecorationList{})), + }); auto* lhs = create( Source{}, mod.RegisterSymbol("lhs"), "lhs"); auto* rhs = create( Source{}, mod.RegisterSymbol("rhs"), "rhs"); - auto* continuing = create(Source{}); - continuing->append(create(Source{}, lhs, rhs)); - + auto* continuing = create( + Source{}, ast::StatementList{ + create(Source{}, lhs, rhs), + }); ast::LoopStatement outer(Source{}, body, continuing); gen.increment_indent(); diff --git a/src/writer/hlsl/generator_impl_switch_test.cc b/src/writer/hlsl/generator_impl_switch_test.cc index aed18332f3..6bbec6aaa8 100644 --- a/src/writer/hlsl/generator_impl_switch_test.cc +++ b/src/writer/hlsl/generator_impl_switch_test.cc @@ -31,8 +31,10 @@ namespace { using HlslGeneratorImplTest_Switch = TestHelper; TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) { - auto* def_body = create(Source{}); - def_body->append(create(Source{})); + auto* def_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* def = create(Source{}, ast::CaseSelectorList{}, def_body); @@ -40,8 +42,10 @@ TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) { ast::CaseSelectorList case_val; case_val.push_back(create(Source{}, &i32, 5)); - auto* case_body = create(Source{}); - case_body->append(create(Source{})); + auto* case_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* case_stmt = create(Source{}, case_val, case_body); diff --git a/src/writer/hlsl/generator_impl_test.cc b/src/writer/hlsl/generator_impl_test.cc index 19931af240..db93f62c59 100644 --- a/src/writer/hlsl/generator_impl_test.cc +++ b/src/writer/hlsl/generator_impl_test.cc @@ -29,10 +29,10 @@ using HlslGeneratorImplTest = TestHelper; TEST_F(HlslGeneratorImplTest, Generate) { ast::type::Void void_type; - auto* func = create(Source{}, mod.RegisterSymbol("my_func"), - "my_func", ast::VariableList{}, &void_type, - create(Source{}), - ast::FunctionDecorationList{}); + auto* func = create( + Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, + &void_type, create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); mod.AddFunction(func); ASSERT_TRUE(gen.Generate(out)) << gen.error(); diff --git a/src/writer/msl/generator_impl_block_test.cc b/src/writer/msl/generator_impl_block_test.cc index a7b8ec312b..f50bb3ef5f 100644 --- a/src/writer/msl/generator_impl_block_test.cc +++ b/src/writer/msl/generator_impl_block_test.cc @@ -28,9 +28,9 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Block) { - ast::BlockStatement b(Source{}); - b.append(create(Source{})); - + ast::BlockStatement b(Source{}, ast::StatementList{ + create(Source{}), + }); gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(&b)) << gen.error(); @@ -41,9 +41,9 @@ TEST_F(MslGeneratorImplTest, Emit_Block) { } TEST_F(MslGeneratorImplTest, Emit_Block_WithoutNewline) { - ast::BlockStatement b(Source{}); - b.append(create(Source{})); - + ast::BlockStatement b(Source{}, ast::StatementList{ + create(Source{}), + }); gen.increment_indent(); ASSERT_TRUE(gen.EmitBlock(&b)) << gen.error(); diff --git a/src/writer/msl/generator_impl_call_test.cc b/src/writer/msl/generator_impl_call_test.cc index 4092f73052..85efb042fa 100644 --- a/src/writer/msl/generator_impl_call_test.cc +++ b/src/writer/msl/generator_impl_call_test.cc @@ -38,10 +38,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithoutParams) { Source{}, mod.RegisterSymbol("my_func"), "my_func"); ast::CallExpression call(Source{}, id, {}); - auto* func = create(Source{}, mod.RegisterSymbol("my_func"), - "my_func", ast::VariableList{}, &void_type, - create(Source{}), - ast::FunctionDecorationList{}); + auto* func = create( + Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, + &void_type, create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); mod.AddFunction(func); ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error(); @@ -60,10 +60,10 @@ TEST_F(MslGeneratorImplTest, EmitExpression_Call_WithParams) { Source{}, mod.RegisterSymbol("param2"), "param2")); ast::CallExpression call(Source{}, id, params); - auto* func = create(Source{}, mod.RegisterSymbol("my_func"), - "my_func", ast::VariableList{}, &void_type, - create(Source{}), - ast::FunctionDecorationList{}); + auto* func = create( + Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, + &void_type, create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); mod.AddFunction(func); ASSERT_TRUE(gen.EmitExpression(&call)) << gen.error(); @@ -83,10 +83,10 @@ TEST_F(MslGeneratorImplTest, EmitStatement_Call) { ast::CallStatement call(Source{}, create(Source{}, id, params)); - auto* func = create(Source{}, mod.RegisterSymbol("my_func"), - "my_func", ast::VariableList{}, &void_type, - create(Source{}), - ast::FunctionDecorationList{}); + auto* func = create( + Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, + &void_type, create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); mod.AddFunction(func); gen.increment_indent(); diff --git a/src/writer/msl/generator_impl_case_test.cc b/src/writer/msl/generator_impl_case_test.cc index f8570c699e..cf868c8d2c 100644 --- a/src/writer/msl/generator_impl_case_test.cc +++ b/src/writer/msl/generator_impl_case_test.cc @@ -35,9 +35,10 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Case) { ast::type::I32 i32; - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::CaseSelectorList lit; lit.push_back(create(Source{}, &i32, 5)); ast::CaseStatement c(Source{}, lit, body); @@ -56,7 +57,9 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) { ast::CaseSelectorList lit; lit.push_back(create(Source{}, &i32, 5)); - ast::CaseStatement c(Source{}, lit, create(Source{})); + ast::CaseStatement c( + Source{}, lit, + create(Source{}, ast::StatementList{})); gen.increment_indent(); @@ -70,9 +73,10 @@ TEST_F(MslGeneratorImplTest, Emit_Case_BreaksByDefault) { TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) { ast::type::I32 i32; - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::CaseSelectorList lit; lit.push_back(create(Source{}, &i32, 5)); ast::CaseStatement c(Source{}, lit, body); @@ -89,9 +93,10 @@ TEST_F(MslGeneratorImplTest, Emit_Case_WithFallthrough) { TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) { ast::type::I32 i32; - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::CaseSelectorList lit; lit.push_back(create(Source{}, &i32, 5)); lit.push_back(create(Source{}, &i32, 6)); @@ -108,8 +113,10 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) { } TEST_F(MslGeneratorImplTest, Emit_Case_Default) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body); gen.increment_indent(); diff --git a/src/writer/msl/generator_impl_function_entry_point_data_test.cc b/src/writer/msl/generator_impl_function_entry_point_data_test.cc index 2d2c6282a1..49dd561900 100644 --- a/src/writer/msl/generator_impl_function_entry_point_data_test.cc +++ b/src/writer/msl/generator_impl_function_entry_point_data_test.cc @@ -81,20 +81,21 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Input) { mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("foo"), - "foo"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("bar"), - "bar"))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("foo"), "foo"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("bar"), "bar")), + }); auto* func = create( Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, ast::FunctionDecorationList{ @@ -157,20 +158,21 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Vertex_Output) { mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("foo"), - "foo"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("bar"), - "bar"))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("foo"), "foo"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("bar"), "bar")), + }); auto* func = create( Source{}, mod.RegisterSymbol("vtx_main"), "vtx_main", params, &f32, body, ast::FunctionDecorationList{ @@ -233,19 +235,21 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Input) { mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("foo"), - "foo"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("bar"), - "bar"))); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("foo"), "foo"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("bar"), "bar")), + }); auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, ast::FunctionDecorationList{ @@ -308,20 +312,21 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Fragment_Output) { mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("foo"), - "foo"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("bar"), - "bar"))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("foo"), "foo"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("bar"), "bar")), + }); auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, ast::FunctionDecorationList{ @@ -381,20 +386,21 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Input) { mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("foo"), - "foo"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("bar"), - "bar"))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("foo"), "foo"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("bar"), "bar")), + }); auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, ast::FunctionDecorationList{ @@ -449,20 +455,21 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Compute_Output) { mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("foo"), - "foo"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("bar"), - "bar"))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("foo"), "foo"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("bar"), "bar")), + }); auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", params, &f32, body, ast::FunctionDecorationList{ @@ -524,18 +531,19 @@ TEST_F(MslGeneratorImplTest, Emit_Function_EntryPointData_Builtins) { ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("depth"), - "depth"), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("coord"), "coord"), - create(Source{}, mod.RegisterSymbol("x"), - "x")))); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("depth"), "depth"), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("coord"), "coord"), + create( + Source{}, mod.RegisterSymbol("x"), "x"))), + }); auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", params, &void_type, body, ast::FunctionDecorationList{ diff --git a/src/writer/msl/generator_impl_function_test.cc b/src/writer/msl/generator_impl_function_test.cc index e4bf9dc1b0..c328b9eb83 100644 --- a/src/writer/msl/generator_impl_function_test.cc +++ b/src/writer/msl/generator_impl_function_test.cc @@ -58,8 +58,11 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Function) { ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + auto* func = create(Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{}); @@ -80,8 +83,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function) { TEST_F(MslGeneratorImplTest, Emit_Function_Name_Collision) { ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + auto* func = create(Source{}, mod.RegisterSymbol("main"), "main", ast::VariableList{}, &void_type, body, ast::FunctionDecorationList{}); @@ -123,8 +129,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithParams) { ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + auto* func = create(Source{}, mod.RegisterSymbol("my_func"), "my_func", params, &void_type, body, ast::FunctionDecorationList{}); @@ -177,15 +186,16 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_WithInOutVars) { mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -253,19 +263,20 @@ TEST_F(MslGeneratorImplTest, mod.AddGlobalVariable(depth_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("depth"), - "depth"), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("coord"), "coord"), - create(Source{}, mod.RegisterSymbol("x"), - "x")))); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("depth"), "depth"), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("coord"), "coord"), + create( + Source{}, mod.RegisterSymbol("x"), "x"))), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -330,10 +341,11 @@ TEST_F(MslGeneratorImplTest, Emit_FunctionDecoration_EntryPoint_With_Uniform) { "x")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -411,10 +423,11 @@ TEST_F(MslGeneratorImplTest, "b")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -497,10 +510,11 @@ TEST_F(MslGeneratorImplTest, "b")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, &void_type, body, @@ -588,22 +602,25 @@ TEST_F( nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create(Source{}, mod.RegisterSymbol("foo"), - "foo"))); - body->append(create( - Source{}, - create(Source{}, mod.RegisterSymbol("val"), - "val"), - create(Source{}, mod.RegisterSymbol("param"), - "param"))); - body->append(create( - Source{}, create( - Source{}, mod.RegisterSymbol("foo"), "foo"))); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("val"), "val"), + create( + Source{}, mod.RegisterSymbol("param"), "param")), + create( + Source{}, create( + Source{}, mod.RegisterSymbol("foo"), "foo")), + }); auto* sub_func = create( Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -614,17 +631,20 @@ TEST_F( expr.push_back(create( Source{}, create(Source{}, &f32, 1.0f))); - body = create(Source{}); - body->append(create( + body = create( Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), - expr))); - body->append(create(Source{})); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), + expr)), + create(Source{}), + }); auto* func_1 = create( Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, ast::FunctionDecorationList{ @@ -694,10 +714,13 @@ TEST_F(MslGeneratorImplTest, nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, mod.RegisterSymbol("param"), "param"))); + auto* body = create( + Source{}, + ast::StatementList{ + create( + Source{}, create( + Source{}, mod.RegisterSymbol("param"), "param")), + }); auto* sub_func = create( Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -708,17 +731,20 @@ TEST_F(MslGeneratorImplTest, expr.push_back(create( Source{}, create(Source{}, &f32, 1.0f))); - body = create(Source{}); - body->append(create( + body = create( Source{}, - create(Source{}, mod.RegisterSymbol("depth"), - "depth"), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), - expr))); - body->append(create(Source{})); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("depth"), "depth"), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), + expr)), + create(Source{}), + }); auto* func_1 = create( Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, @@ -797,20 +823,23 @@ TEST_F( nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, mod.RegisterSymbol("depth"), - "depth"), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("coord"), "coord"), - create(Source{}, mod.RegisterSymbol("x"), - "x")))); - body->append(create( - Source{}, create( - Source{}, mod.RegisterSymbol("param"), "param"))); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("depth"), "depth"), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("coord"), "coord"), + create( + Source{}, mod.RegisterSymbol("x"), "x"))), + create( + Source{}, create( + Source{}, mod.RegisterSymbol("param"), "param")), + }); auto* sub_func = create( Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -821,17 +850,20 @@ TEST_F( expr.push_back(create( Source{}, create(Source{}, &f32, 1.0f))); - body = create(Source{}); - body->append(create( + body = create( Source{}, - create(Source{}, mod.RegisterSymbol("depth"), - "depth"), - create( - Source{}, - create( - Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), - expr))); - body->append(create(Source{})); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("depth"), "depth"), + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("sub_func"), "sub_func"), + expr)), + create(Source{}), + }); auto* func_1 = create( Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, ast::FunctionDecorationList{ @@ -895,14 +927,17 @@ TEST_F(MslGeneratorImplTest, nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, - create( - Source{}, mod.RegisterSymbol("coord"), "coord"), - create( - Source{}, mod.RegisterSymbol("x"), "x")))); + auto* body = create( + Source{}, + ast::StatementList{ + create( + Source{}, create( + Source{}, + create( + Source{}, mod.RegisterSymbol("coord"), "coord"), + create( + Source{}, mod.RegisterSymbol("x"), "x"))), + }); auto* sub_func = create( Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -926,9 +961,11 @@ TEST_F(MslGeneratorImplTest, expr), // constructor ast::VariableDecorationList{}); // decorations - body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); + body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, @@ -1004,14 +1041,17 @@ TEST_F(MslGeneratorImplTest, nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, - create( - Source{}, mod.RegisterSymbol("coord"), "coord"), - create( - Source{}, mod.RegisterSymbol("b"), "b")))); + auto* body = create( + Source{}, + ast::StatementList{ + create( + Source{}, create( + Source{}, + create( + Source{}, mod.RegisterSymbol("coord"), "coord"), + create( + Source{}, mod.RegisterSymbol("b"), "b"))), + }); auto* sub_func = create( Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -1035,9 +1075,11 @@ TEST_F(MslGeneratorImplTest, expr), // constructor ast::VariableDecorationList{}); // decorations - body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); + body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, @@ -1119,14 +1161,17 @@ TEST_F(MslGeneratorImplTest, nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, - create( - Source{}, mod.RegisterSymbol("coord"), "coord"), - create( - Source{}, mod.RegisterSymbol("b"), "b")))); + auto* body = create( + Source{}, + ast::StatementList{ + create( + Source{}, create( + Source{}, + create( + Source{}, mod.RegisterSymbol("coord"), "coord"), + create( + Source{}, mod.RegisterSymbol("b"), "b"))), + }); auto* sub_func = create( Source{}, mod.RegisterSymbol("sub_func"), "sub_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -1150,9 +1195,11 @@ TEST_F(MslGeneratorImplTest, expr), // constructor ast::VariableDecorationList{}); // decorations - body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); + body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("frag_main"), "frag_main", params, @@ -1207,28 +1254,31 @@ TEST_F(MslGeneratorImplTest, mod.AddGlobalVariable(bar_var); ast::VariableList params; - auto* body = create(Source{}); - body->append(create( + auto* list = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + + auto* body = create( Source{}, - create(Source{}, mod.RegisterSymbol("bar"), - "bar"), - create( - Source{}, create(Source{}, &f32, 1.0f)))); - - auto* list = create(Source{}); - list->append(create(Source{})); - - body->append(create( - Source{}, - create( - Source{}, ast::BinaryOp::kEqual, - create( - Source{}, create(Source{}, &i32, 1)), - create( - Source{}, create(Source{}, &i32, 1))), - list, ast::ElseStatementList{})); - - body->append(create(Source{})); + ast::StatementList{ + create( + Source{}, + create( + Source{}, mod.RegisterSymbol("bar"), "bar"), + create( + Source{}, create(Source{}, &f32, 1.0f))), + create( + Source{}, + create( + Source{}, ast::BinaryOp::kEqual, + create( + Source{}, create(Source{}, &i32, 1)), + create( + Source{}, create(Source{}, &i32, 1))), + list, ast::ElseStatementList{}), + create(Source{}), + }); auto* func_1 = create( Source{}, mod.RegisterSymbol("ep_1"), "ep_1", params, &void_type, body, @@ -1264,7 +1314,7 @@ TEST_F(MslGeneratorImplTest, auto* func = create( Source{}, mod.RegisterSymbol("main"), "main", ast::VariableList{}, - &void_type, create(Source{}), + &void_type, create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kCompute, Source{}), }); @@ -1296,8 +1346,11 @@ TEST_F(MslGeneratorImplTest, Emit_Function_WithArrayParams) { ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + auto* func = create(Source{}, mod.RegisterSymbol("my_func"), "my_func", params, &void_type, body, ast::FunctionDecorationList{}); @@ -1384,10 +1437,11 @@ TEST_F(MslGeneratorImplTest, "d")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("a"), "a", params, &void_type, body, ast::FunctionDecorationList{ @@ -1414,10 +1468,11 @@ TEST_F(MslGeneratorImplTest, "d")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("b"), "b", params, &void_type, body, ast::FunctionDecorationList{ diff --git a/src/writer/msl/generator_impl_if_test.cc b/src/writer/msl/generator_impl_if_test.cc index 3ded7e3bb7..772dee9945 100644 --- a/src/writer/msl/generator_impl_if_test.cc +++ b/src/writer/msl/generator_impl_if_test.cc @@ -31,9 +31,10 @@ using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_If) { auto* cond = create( Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{}); gen.increment_indent(); @@ -48,14 +49,17 @@ TEST_F(MslGeneratorImplTest, Emit_If) { TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) { auto* else_cond = create( Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); - auto* else_body = create(Source{}); - else_body->append(create(Source{})); + auto* else_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* cond = create( Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement i( Source{}, cond, body, {create(Source{}, else_cond, else_body)}); @@ -72,14 +76,17 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithElseIf) { } TEST_F(MslGeneratorImplTest, Emit_IfWithElse) { - auto* else_body = create(Source{}); - else_body->append(create(Source{})); + auto* else_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* cond = create( Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement i( Source{}, cond, body, {create(Source{}, nullptr, else_body)}); @@ -99,17 +106,22 @@ TEST_F(MslGeneratorImplTest, Emit_IfWithMultiple) { auto* else_cond = create( Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); - auto* else_body = create(Source{}); - else_body->append(create(Source{})); + auto* else_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); - auto* else_body_2 = create(Source{}); - else_body_2->append(create(Source{})); + auto* else_body_2 = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* cond = create( Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement i( Source{}, cond, body, { diff --git a/src/writer/msl/generator_impl_loop_test.cc b/src/writer/msl/generator_impl_loop_test.cc index 94ecdb5796..b8b0a29723 100644 --- a/src/writer/msl/generator_impl_loop_test.cc +++ b/src/writer/msl/generator_impl_loop_test.cc @@ -36,9 +36,10 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Loop) { - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::LoopStatement l(Source{}, body, {}); gen.increment_indent(); @@ -51,12 +52,14 @@ TEST_F(MslGeneratorImplTest, Emit_Loop) { } TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) { - auto* body = create(Source{}); - body->append(create(Source{})); - - auto* continuing = create(Source{}); - continuing->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + auto* continuing = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::LoopStatement l(Source{}, body, continuing); gen.increment_indent(); @@ -79,24 +82,29 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithContinuing) { TEST_F(MslGeneratorImplTest, Emit_LoopNestedWithContinuing) { ast::type::F32 f32; - auto* body = create(Source{}); - body->append(create(Source{})); - - auto* continuing = create(Source{}); - continuing->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + auto* continuing = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* inner = create(Source{}, body, continuing); - body = create(Source{}); - body->append(inner); + body = create(Source{}, ast::StatementList{ + inner, + }); auto* lhs = create( Source{}, mod.RegisterSymbol("lhs"), "lhs"); auto* rhs = create( Source{}, mod.RegisterSymbol("rhs"), "rhs"); - continuing = create(Source{}); - continuing->append(create(Source{}, lhs, rhs)); + continuing = create( + Source{}, ast::StatementList{ + create(Source{}, lhs, rhs), + }); ast::LoopStatement outer(Source{}, body, continuing); @@ -162,26 +170,30 @@ TEST_F(MslGeneratorImplTest, Emit_LoopWithVarUsedInContinuing) { create(Source{}, &f32, 2.4)), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create( + auto* body = create( Source{}, - create(Source{}, // source - "other", // name - ast::StorageClass::kFunction, // storage_class - &f32, // type - false, // is_const - nullptr, // constructor - ast::VariableDecorationList{}))); // decorations + ast::StatementList{ + create(Source{}, var), + create( + Source{}, create( + Source{}, // source + "other", // name + ast::StorageClass::kFunction, // storage_class + &f32, // type + false, // is_const + nullptr, // constructor + ast::VariableDecorationList{})), // decorations + }); auto* lhs = create( Source{}, mod.RegisterSymbol("lhs"), "lhs"); auto* rhs = create( Source{}, mod.RegisterSymbol("rhs"), "rhs"); - auto* continuing = create(Source{}); - continuing->append(create(Source{}, lhs, rhs)); - + auto* continuing = create( + Source{}, ast::StatementList{ + create(Source{}, lhs, rhs), + }); gen.increment_indent(); ast::LoopStatement outer(Source{}, body, continuing); diff --git a/src/writer/msl/generator_impl_switch_test.cc b/src/writer/msl/generator_impl_switch_test.cc index 0b825672a1..eb7f766823 100644 --- a/src/writer/msl/generator_impl_switch_test.cc +++ b/src/writer/msl/generator_impl_switch_test.cc @@ -33,8 +33,10 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Switch) { - auto* def_body = create(Source{}); - def_body->append(create(Source{})); + auto* def_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* def = create(Source{}, ast::CaseSelectorList{}, def_body); @@ -42,8 +44,10 @@ TEST_F(MslGeneratorImplTest, Emit_Switch) { ast::CaseSelectorList case_val; case_val.push_back(create(Source{}, &i32, 5)); - auto* case_body = create(Source{}); - case_body->append(create(Source{})); + auto* case_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* case_stmt = create(Source{}, case_val, case_body); diff --git a/src/writer/msl/generator_impl_test.cc b/src/writer/msl/generator_impl_test.cc index 10cd631aa2..72e0cd316a 100644 --- a/src/writer/msl/generator_impl_test.cc +++ b/src/writer/msl/generator_impl_test.cc @@ -52,7 +52,7 @@ TEST_F(MslGeneratorImplTest, Generate) { auto* func = create( Source{}, mod.RegisterSymbol("my_func"), "my_func", ast::VariableList{}, - &void_type, create(Source{}), + &void_type, create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kCompute, Source{}), }); diff --git a/src/writer/spirv/builder_block_test.cc b/src/writer/spirv/builder_block_test.cc index 30dc6babda..3f8e8ae611 100644 --- a/src/writer/spirv/builder_block_test.cc +++ b/src/writer/spirv/builder_block_test.cc @@ -39,48 +39,51 @@ TEST_F(BuilderTest, Block) { // Note, this test uses shadow variables which aren't allowed in WGSL but // serves to prove the block code is pushing new scopes as needed. - ast::BlockStatement outer(Source{}); - - outer.append(create( + auto* inner = create( Source{}, - create(Source{}, // source - "var", // name - ast::StorageClass::kFunction, // storage_class - &f32, // type - false, // is_const - nullptr, // constructor - ast::VariableDecorationList{}))); // decorations - outer.append(create( + ast::StatementList{ + create( + Source{}, create( + Source{}, // source + "var", // name + ast::StorageClass::kFunction, // storage_class + &f32, // type + false, // is_const + nullptr, // constructor + ast::VariableDecorationList{})), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("var"), "var"), + create( + Source{}, create(Source{}, &f32, 2.0f))), + }); // decorations + ast::BlockStatement outer( Source{}, - create(Source{}, mod->RegisterSymbol("var"), - "var"), - create( - Source{}, create(Source{}, &f32, 1.0f)))); - - auto* inner = create(Source{}); - inner->append(create( - Source{}, - create(Source{}, // source - "var", // name - ast::StorageClass::kFunction, // storage_class - &f32, // type - false, // is_const - nullptr, // constructor - ast::VariableDecorationList{}))); // decorations - inner->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("var"), - "var"), - create( - Source{}, create(Source{}, &f32, 2.0f)))); - - outer.append(inner); - outer.append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("var"), - "var"), - create( - Source{}, create(Source{}, &f32, 3.0f)))); + ast::StatementList{ + create( + Source{}, create( + Source{}, // source + "var", // name + ast::StorageClass::kFunction, // storage_class + &f32, // type + false, // is_const + nullptr, // constructor + ast::VariableDecorationList{})), // decorations + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("var"), "var"), + create( + Source{}, create(Source{}, &f32, 1.0f))), + inner, + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("var"), "var"), + create( + Source{}, create(Source{}, &f32, 3.0f))), + }); ASSERT_TRUE(td.DetermineResultType(&outer)) << td.error(); diff --git a/src/writer/spirv/builder_call_test.cc b/src/writer/spirv/builder_call_test.cc index de09ffb031..76f4fd641d 100644 --- a/src/writer/spirv/builder_call_test.cc +++ b/src/writer/spirv/builder_call_test.cc @@ -61,20 +61,24 @@ TEST_F(BuilderTest, Expression_Call) { nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, ast::BinaryOp::kAdd, - create( - Source{}, mod->RegisterSymbol("a"), "a"), - create( - Source{}, mod->RegisterSymbol("b"), "b")))); + auto* body = create( + Source{}, + ast::StatementList{ + create( + Source{}, create( + Source{}, ast::BinaryOp::kAdd, + create( + Source{}, mod->RegisterSymbol("a"), "a"), + create( + Source{}, mod->RegisterSymbol("b"), "b"))), + }); ast::Function a_func(Source{}, mod->RegisterSymbol("a_func"), "a_func", func_params, &f32, body, ast::FunctionDecorationList{}); - ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {}, - &void_type, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ast::ExpressionList call_params; call_params.push_back(create( @@ -144,22 +148,25 @@ TEST_F(BuilderTest, Statement_Call) { nullptr, // constructor ast::VariableDecorationList{})); // decorations - auto* body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, ast::BinaryOp::kAdd, - create( - Source{}, mod->RegisterSymbol("a"), "a"), - create( - Source{}, mod->RegisterSymbol("b"), "b")))); - + auto* body = create( + Source{}, + ast::StatementList{ + create( + Source{}, create( + Source{}, ast::BinaryOp::kAdd, + create( + Source{}, mod->RegisterSymbol("a"), "a"), + create( + Source{}, mod->RegisterSymbol("b"), "b"))), + }); ast::Function a_func(Source{}, mod->RegisterSymbol("a_func"), "a_func", func_params, &void_type, body, ast::FunctionDecorationList{}); - ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {}, - &void_type, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ast::ExpressionList call_params; call_params.push_back(create( diff --git a/src/writer/spirv/builder_function_decoration_test.cc b/src/writer/spirv/builder_function_decoration_test.cc index c9f1725527..6ca5f03313 100644 --- a/src/writer/spirv/builder_function_decoration_test.cc +++ b/src/writer/spirv/builder_function_decoration_test.cc @@ -43,7 +43,7 @@ TEST_F(BuilderTest, FunctionDecoration_Stage) { ast::Function func( Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex, Source{}), }); @@ -68,11 +68,12 @@ TEST_P(FunctionDecoration_StageTest, Emit) { ast::type::Void void_type; - ast::Function func(Source{}, mod->RegisterSymbol("main"), "main", {}, - &void_type, create(Source{}), - ast::FunctionDecorationList{ - create(params.stage, Source{}), - }); + ast::Function func( + Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{ + create(params.stage, Source{}), + }); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -99,7 +100,7 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUnusedInterfaceIds) { ast::Function func( Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kVertex, Source{}), }); @@ -163,26 +164,29 @@ TEST_F(BuilderTest, FunctionDecoration_Stage_WithUsedInterfaceIds) { ast::type::F32 f32; ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("my_out"), - "my_out"), - create(Source{}, mod->RegisterSymbol("my_in"), - "my_in"))); - body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("my_wg"), - "my_wg"), - create(Source{}, mod->RegisterSymbol("my_wg"), - "my_wg"))); - // Add duplicate usages so we show they don't get output multiple times. - body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("my_out"), - "my_out"), - create(Source{}, mod->RegisterSymbol("my_in"), - "my_in"))); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("my_out"), "my_out"), + create( + Source{}, mod->RegisterSymbol("my_in"), "my_in")), + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("my_wg"), "my_wg"), + create( + Source{}, mod->RegisterSymbol("my_wg"), "my_wg")), + // Add duplicate usages so we show they don't get output + // multiple times. + create( + Source{}, + create( + Source{}, mod->RegisterSymbol("my_out"), "my_out"), + create( + Source{}, mod->RegisterSymbol("my_in"), "my_in")), + }); ast::Function func( Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, body, @@ -256,7 +260,7 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_Fragment_OriginUpperLeft) { ast::Function func( Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kFragment, Source{}), }); @@ -272,7 +276,7 @@ TEST_F(BuilderTest, FunctionDecoration_WorkgroupSize_Default) { ast::Function func( Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kCompute, Source{}), }); @@ -288,7 +292,7 @@ TEST_F(BuilderTest, FunctionDecoration_WorkgroupSize) { ast::Function func( Source{}, mod->RegisterSymbol("main"), "main", {}, &void_type, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(2u, 4u, 6u, Source{}), create(ast::PipelineStage::kCompute, Source{}), @@ -305,14 +309,14 @@ TEST_F(BuilderTest, FunctionDecoration_ExecutionMode_MultipleFragment) { ast::Function func1( Source{}, mod->RegisterSymbol("main1"), "main1", {}, &void_type, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kFragment, Source{}), }); ast::Function func2( Source{}, mod->RegisterSymbol("main2"), "main2", {}, &void_type, - create(Source{}), + create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{ create(ast::PipelineStage::kFragment, Source{}), }); diff --git a/src/writer/spirv/builder_function_test.cc b/src/writer/spirv/builder_function_test.cc index 04a5a95128..c386df2c8a 100644 --- a/src/writer/spirv/builder_function_test.cc +++ b/src/writer/spirv/builder_function_test.cc @@ -47,9 +47,10 @@ using BuilderTest = TestHelper; TEST_F(BuilderTest, Function_Empty) { ast::type::Void void_type; - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - &void_type, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &void_type, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)); EXPECT_EQ(DumpBuilder(b), R"(OpName %3 "a_func" @@ -65,9 +66,10 @@ OpFunctionEnd TEST_F(BuilderTest, Function_Terminator_Return) { ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &void_type, body, ast::FunctionDecorationList{}); @@ -96,10 +98,12 @@ TEST_F(BuilderTest, Function_Terminator_ReturnValue) { ast::VariableDecorationList{}); // decorations td.RegisterVariableForTesting(var_a); - auto* body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, mod->RegisterSymbol("a"), "a"))); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, create( + Source{}, mod->RegisterSymbol("a"), "a")), + }); ASSERT_TRUE(td.DetermineResultType(body)) << td.error(); ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, @@ -126,9 +130,10 @@ OpFunctionEnd TEST_F(BuilderTest, Function_Terminator_Discard) { ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &void_type, body, ast::FunctionDecorationList{}); @@ -166,10 +171,12 @@ TEST_F(BuilderTest, Function_WithParams) { ast::VariableDecorationList{}), // decorations }; - auto* body = create(Source{}); - body->append(create( - Source{}, create( - Source{}, mod->RegisterSymbol("a"), "a"))); + auto* body = create( + Source{}, ast::StatementList{ + create( + Source{}, create( + Source{}, mod->RegisterSymbol("a"), "a")), + }); ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", params, &f32, body, ast::FunctionDecorationList{}); @@ -196,9 +203,10 @@ OpFunctionEnd TEST_F(BuilderTest, Function_WithBody) { ast::type::Void void_type; - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &void_type, body, ast::FunctionDecorationList{}); @@ -215,9 +223,10 @@ OpFunctionEnd TEST_F(BuilderTest, FunctionType) { ast::type::Void void_type; - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - &void_type, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &void_type, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid @@ -227,12 +236,14 @@ TEST_F(BuilderTest, FunctionType) { TEST_F(BuilderTest, FunctionType_DeDuplicate) { ast::type::Void void_type; - ast::Function func1(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - &void_type, create(Source{}), - ast::FunctionDecorationList{}); - ast::Function func2(Source{}, mod->RegisterSymbol("b_func"), "b_func", {}, - &void_type, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func1( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &void_type, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); + ast::Function func2( + Source{}, mod->RegisterSymbol("b_func"), "b_func", {}, &void_type, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func1)); ASSERT_TRUE(b.GenerateFunction(&func2)); @@ -309,10 +320,11 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) { "d")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod->RegisterSymbol("a"), "a", params, &void_type, body, ast::FunctionDecorationList{ @@ -340,10 +352,11 @@ TEST_F(BuilderTest, Emit_Multiple_EntryPoint_With_Same_ModuleVar) { "d")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod->RegisterSymbol("b"), "b", params, &void_type, body, ast::FunctionDecorationList{ diff --git a/src/writer/spirv/builder_if_test.cc b/src/writer/spirv/builder_if_test.cc index b5c8b8b765..65af67c38b 100644 --- a/src/writer/spirv/builder_if_test.cc +++ b/src/writer/spirv/builder_if_test.cc @@ -48,8 +48,10 @@ TEST_F(BuilderTest, If_Empty) { auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - ast::IfStatement expr(Source{}, cond, create(Source{}), - ast::ElseStatementList{}); + ast::IfStatement expr( + Source{}, cond, + create(Source{}, ast::StatementList{}), + ast::ElseStatementList{}); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); @@ -84,14 +86,16 @@ TEST_F(BuilderTest, If_WithStatements) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 2)))); - + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 2))), + }); auto* cond = create( Source{}, create(Source{}, &bool_type, true)); @@ -140,21 +144,26 @@ TEST_F(BuilderTest, If_WithElse) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 2)))); - - auto* else_body = create(Source{}); - else_body->append(create( + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 2))), + }); + auto* else_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 3)))); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 3))), + }); auto* cond = create( Source{}, create(Source{}, &bool_type, true)); @@ -211,21 +220,26 @@ TEST_F(BuilderTest, If_WithElseIf) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 2)))); - - auto* else_body = create(Source{}); - else_body->append(create( + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 2))), + }); + auto* else_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 3)))); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 3))), + }); auto* else_cond = create( Source{}, create(Source{}, &bool_type, true)); @@ -294,34 +308,46 @@ TEST_F(BuilderTest, If_WithMultiple) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 2)))); - auto* elseif_1_body = create(Source{}); - elseif_1_body->append(create( + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 2))), + }); + auto* elseif_1_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 3)))); - auto* elseif_2_body = create(Source{}); - elseif_2_body->append(create( + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 3))), + }); + auto* elseif_2_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 4)))); - auto* else_body = create(Source{}); - else_body->append(create( + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 4))), + }); + auto* else_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 5)))); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 5))), + }); auto* elseif_1_cond = create( Source{}, create(Source{}, &bool_type, true)); @@ -398,17 +424,21 @@ TEST_F(BuilderTest, If_WithBreak) { auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - auto* if_body = create(Source{}); - if_body->append(create(Source{})); + auto* if_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* if_stmt = create(Source{}, cond, if_body, ast::ElseStatementList{}); - auto* loop_body = create(Source{}); - loop_body->append(if_stmt); + auto* loop_body = create(Source{}, ast::StatementList{ + if_stmt, + }); - ast::LoopStatement expr(Source{}, loop_body, - create(Source{})); + ast::LoopStatement expr( + Source{}, loop_body, + create(Source{}, ast::StatementList{})); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); @@ -447,19 +477,24 @@ TEST_F(BuilderTest, If_WithElseBreak) { auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - auto* else_body = create(Source{}); - else_body->append(create(Source{})); + auto* else_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* if_stmt = create( - Source{}, cond, create(Source{}), + Source{}, cond, + create(Source{}, ast::StatementList{}), ast::ElseStatementList{ create(Source{}, nullptr, else_body)}); - auto* loop_body = create(Source{}); - loop_body->append(if_stmt); + auto* loop_body = create(Source{}, ast::StatementList{ + if_stmt, + }); - ast::LoopStatement expr(Source{}, loop_body, - create(Source{})); + ast::LoopStatement expr( + Source{}, loop_body, + create(Source{}, ast::StatementList{})); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); @@ -499,17 +534,21 @@ TEST_F(BuilderTest, If_WithContinue) { auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - auto* if_body = create(Source{}); - if_body->append(create(Source{})); + auto* if_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* if_stmt = create(Source{}, cond, if_body, ast::ElseStatementList{}); - auto* loop_body = create(Source{}); - loop_body->append(if_stmt); + auto* loop_body = create(Source{}, ast::StatementList{ + if_stmt, + }); - ast::LoopStatement expr(Source{}, loop_body, - create(Source{})); + ast::LoopStatement expr( + Source{}, loop_body, + create(Source{}, ast::StatementList{})); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); @@ -548,19 +587,24 @@ TEST_F(BuilderTest, If_WithElseContinue) { auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - auto* else_body = create(Source{}); - else_body->append(create(Source{})); + auto* else_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* if_stmt = create( - Source{}, cond, create(Source{}), + Source{}, cond, + create(Source{}, ast::StatementList{}), ast::ElseStatementList{ create(Source{}, nullptr, else_body)}); - auto* loop_body = create(Source{}); - loop_body->append(if_stmt); + auto* loop_body = create(Source{}, ast::StatementList{ + if_stmt, + }); - ast::LoopStatement expr(Source{}, loop_body, - create(Source{})); + ast::LoopStatement expr( + Source{}, loop_body, + create(Source{}, ast::StatementList{})); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); @@ -598,8 +642,10 @@ TEST_F(BuilderTest, If_WithReturn) { auto* cond = create( Source{}, create(Source{}, &bool_type, true)); - auto* if_body = create(Source{}); - if_body->append(create(Source{})); + auto* if_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{}); @@ -630,8 +676,10 @@ TEST_F(BuilderTest, If_WithReturnValue) { auto* cond2 = create( Source{}, create(Source{}, &bool_type, false)); - auto* if_body = create(Source{}); - if_body->append(create(Source{}, cond2)); + auto* if_body = create( + Source{}, ast::StatementList{ + create(Source{}, cond2), + }); ast::IfStatement expr(Source{}, cond, if_body, ast::ElseStatementList{}); @@ -669,11 +717,12 @@ TEST_F(BuilderTest, If_WithLoad_Bug327) { ast::VariableDecorationList{}); // decorations td.RegisterVariableForTesting(var); - ast::IfStatement expr(Source{}, - create( - Source{}, mod->RegisterSymbol("a"), "a"), - create(Source{}), - ast::ElseStatementList{}); + ast::IfStatement expr( + Source{}, + create(Source{}, mod->RegisterSymbol("a"), + "a"), + create(Source{}, ast::StatementList{}), + ast::ElseStatementList{}); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); diff --git a/src/writer/spirv/builder_intrinsic_test.cc b/src/writer/spirv/builder_intrinsic_test.cc index 83d1f618f1..1d4b8a0ef1 100644 --- a/src/writer/spirv/builder_intrinsic_test.cc +++ b/src/writer/spirv/builder_intrinsic_test.cc @@ -471,9 +471,10 @@ TEST_F(IntrinsicBuilderTest, Call_GLSLMethod_WithLoad) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -505,9 +506,10 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Scalar) { auto expr = Call(param.name, 1.0f); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -533,9 +535,10 @@ TEST_P(Intrinsic_Builtin_SingleParam_Float_Test, Call_Vector) { auto expr = Call(param.name, vec2(1.0f, 1.0f)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -587,9 +590,10 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Scalar) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -612,9 +616,10 @@ TEST_F(IntrinsicBuilderTest, Call_Length_Vector) { auto expr = Call("length", vec2(1.0f, 1.0f)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -639,9 +644,10 @@ TEST_F(IntrinsicBuilderTest, Call_Normalize) { auto expr = Call("normalize", vec2(1.0f, 1.0f)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -671,9 +677,10 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Scalar) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -700,9 +707,10 @@ TEST_P(Intrinsic_Builtin_DualParam_Float_Test, Call_Vector) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -737,9 +745,10 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Scalar) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -763,9 +772,10 @@ TEST_F(IntrinsicBuilderTest, Call_Distance_Vector) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -792,9 +802,10 @@ TEST_F(IntrinsicBuilderTest, Call_Cross) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -823,9 +834,10 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Scalar) { auto expr = Call(param.name, 1.0f, 1.0f, 1.0f); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -853,9 +865,10 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Float_Test, Call_Vector) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -894,9 +907,10 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Scalar) { auto expr = Call(param.name, 1); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -922,9 +936,10 @@ TEST_P(Intrinsic_Builtin_SingleParam_Sint_Test, Call_Vector) { auto expr = Call(param.name, vec2(1, 1)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -957,9 +972,10 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Scalar) { auto expr = Call(param.name, 1u); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -985,9 +1001,10 @@ TEST_P(Intrinsic_Builtin_SingleParam_Uint_Test, Call_Vector) { auto expr = Call(param.name, vec2(1u, 1u)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -1020,9 +1037,10 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Scalar) { auto expr = Call(param.name, 1, 1); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -1048,9 +1066,10 @@ TEST_P(Intrinsic_Builtin_DualParam_SInt_Test, Call_Vector) { auto expr = Call(param.name, vec2(1, 1), vec2(1, 1)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -1084,9 +1103,10 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Scalar) { auto expr = Call(param.name, 1u, 1u); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -1112,9 +1132,10 @@ TEST_P(Intrinsic_Builtin_DualParam_UInt_Test, Call_Vector) { auto expr = Call(param.name, vec2(1u, 1u), vec2(1u, 1u)); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -1148,9 +1169,10 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Scalar) { auto expr = Call(param.name, 1, 1, 1); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -1178,9 +1200,10 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Sint_Test, Call_Vector) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -1213,9 +1236,10 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Scalar) { auto expr = Call(param.name, 1u, 1u, 1u); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -1243,9 +1267,10 @@ TEST_P(Intrinsic_Builtin_ThreeParam_Uint_Test, Call_Vector) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -1276,9 +1301,10 @@ TEST_F(IntrinsicBuilderTest, Call_Determinant) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); @@ -1321,9 +1347,10 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); @@ -1362,9 +1389,10 @@ TEST_F(IntrinsicBuilderTest, Call_ArrayLength_OtherMembersInStruct) { ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); @@ -1409,9 +1437,10 @@ TEST_F(IntrinsicBuilderTest, DISABLED_Call_ArrayLength_Ptr) { auto expr = Call("arrayLength", "ptr_var"); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - ty.void_, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, ty.void_, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateFunction(&func)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error(); diff --git a/src/writer/spirv/builder_loop_test.cc b/src/writer/spirv/builder_loop_test.cc index 5943521c97..cf6fa6b89b 100644 --- a/src/writer/spirv/builder_loop_test.cc +++ b/src/writer/spirv/builder_loop_test.cc @@ -39,8 +39,9 @@ TEST_F(BuilderTest, Loop_Empty) { // loop { // } - ast::LoopStatement loop(Source{}, create(Source{}), - create(Source{})); + ast::LoopStatement loop( + Source{}, create(Source{}, ast::StatementList{}), + create(Source{}, ast::StatementList{})); ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error(); b.push_function(Function{}); @@ -74,16 +75,19 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 2)))); - - ast::LoopStatement loop(Source{}, body, - create(Source{})); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 2))), + }); + ast::LoopStatement loop( + Source{}, body, + create(Source{}, ast::StatementList{})); td.RegisterVariableForTesting(var); ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error(); @@ -130,21 +134,26 @@ TEST_F(BuilderTest, Loop_WithContinuing) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create( + auto* body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 2)))); - - auto* continuing = create(Source{}); - continuing->append(create( + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 2))), + }); + auto* continuing = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 3)))); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 3))), + }); ast::LoopStatement loop(Source{}, body, continuing); td.RegisterVariableForTesting(var); @@ -180,11 +189,13 @@ TEST_F(BuilderTest, Loop_WithContinue) { // loop { // continue; // } - auto* body = create(Source{}); - body->append(create(Source{})); - - ast::LoopStatement loop(Source{}, body, - create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + ast::LoopStatement loop( + Source{}, body, + create(Source{}, ast::StatementList{})); ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error(); @@ -208,11 +219,13 @@ TEST_F(BuilderTest, Loop_WithBreak) { // loop { // break; // } - auto* body = create(Source{}); - body->append(create(Source{})); - - ast::LoopStatement loop(Source{}, body, - create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + ast::LoopStatement loop( + Source{}, body, + create(Source{}, ast::StatementList{})); ASSERT_TRUE(td.DetermineResultType(&loop)) << td.error(); diff --git a/src/writer/spirv/builder_switch_test.cc b/src/writer/spirv/builder_switch_test.cc index 3e99d19f97..efc1355a8b 100644 --- a/src/writer/spirv/builder_switch_test.cc +++ b/src/writer/spirv/builder_switch_test.cc @@ -93,21 +93,27 @@ TEST_F(BuilderTest, Switch_WithCase) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* case_1_body = create(Source{}); - case_1_body->append(create( + auto* case_1_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 1)))); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 1))), + }); - auto* case_2_body = create(Source{}); - case_2_body->append(create( + auto* case_2_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 2)))); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 2))), + }); ast::CaseSelectorList selector_1; selector_1.push_back(create(Source{}, &i32, 1)); @@ -130,9 +136,10 @@ TEST_F(BuilderTest, Switch_WithCase) { td.RegisterVariableForTesting(a); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - &i32, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &i32, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(a)) << b.error(); @@ -195,13 +202,16 @@ TEST_F(BuilderTest, Switch_WithDefault) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* default_body = create(Source{}); - default_body->append(create( + auto* default_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 1)))); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 1))), + }); ast::CaseStatementList cases; cases.push_back(create(Source{}, ast::CaseSelectorList{}, @@ -216,9 +226,10 @@ TEST_F(BuilderTest, Switch_WithDefault) { td.RegisterVariableForTesting(a); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - &i32, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &i32, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(a)) << b.error(); @@ -279,29 +290,38 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* case_1_body = create(Source{}); - case_1_body->append(create( + auto* case_1_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 1)))); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 1))), + }); - auto* case_2_body = create(Source{}); - case_2_body->append(create( + auto* case_2_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 2)))); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 2))), + }); - auto* default_body = create(Source{}); - default_body->append(create( + auto* default_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 3)))); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 3))), + }); ast::CaseSelectorList selector_1; selector_1.push_back(create(Source{}, &i32, 1)); @@ -327,9 +347,10 @@ TEST_F(BuilderTest, Switch_WithCaseAndDefault) { td.RegisterVariableForTesting(a); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - &i32, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &i32, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(a)) << b.error(); @@ -399,30 +420,38 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* case_1_body = create(Source{}); - case_1_body->append(create( + auto* case_1_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 1)))); - case_1_body->append(create(Source{})); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 1))), + create(Source{})}); - auto* case_2_body = create(Source{}); - case_2_body->append(create( + auto* case_2_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 2)))); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 2))), + }); - auto* default_body = create(Source{}); - default_body->append(create( + auto* default_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 3)))); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 3))), + }); ast::CaseSelectorList selector_1; selector_1.push_back(create(Source{}, &i32, 1)); @@ -447,9 +476,10 @@ TEST_F(BuilderTest, Switch_CaseWithFallthrough) { td.RegisterVariableForTesting(a); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - &i32, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &i32, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(a)) << b.error(); @@ -515,14 +545,16 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* case_1_body = create(Source{}); - case_1_body->append(create( + auto* case_1_body = create( Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 1)))); - case_1_body->append(create(Source{})); + ast::StatementList{ + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 1))), + create(Source{})}); ast::CaseSelectorList selector_1; selector_1.push_back(create(Source{}, &i32, 1)); @@ -540,9 +572,10 @@ TEST_F(BuilderTest, Switch_CaseFallthroughLastStatement) { td.RegisterVariableForTesting(a); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - &i32, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &i32, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(a)) << b.error(); @@ -581,22 +614,26 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) { nullptr, // constructor ast::VariableDecorationList{}); // decorations - auto* if_body = create(Source{}); - if_body->append(create(Source{})); + auto* if_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); - auto* case_1_body = create(Source{}); - case_1_body->append(create( + auto* case_1_body = create( Source{}, - create( - Source{}, create(Source{}, &bool_type, true)), - if_body, ast::ElseStatementList{})); - - case_1_body->append(create( - Source{}, - create(Source{}, mod->RegisterSymbol("v"), - "v"), - create( - Source{}, create(Source{}, &i32, 1)))); + ast::StatementList{ + create( + Source{}, + create( + Source{}, + create(Source{}, &bool_type, true)), + if_body, ast::ElseStatementList{}), + create( + Source{}, + create(Source{}, + mod->RegisterSymbol("v"), "v"), + create( + Source{}, create(Source{}, &i32, 1)))}); ast::CaseSelectorList selector_1; selector_1.push_back(create(Source{}, &i32, 1)); @@ -614,9 +651,10 @@ TEST_F(BuilderTest, Switch_WithNestedBreak) { td.RegisterVariableForTesting(a); ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error(); - ast::Function func(Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, - &i32, create(Source{}), - ast::FunctionDecorationList{}); + ast::Function func( + Source{}, mod->RegisterSymbol("a_func"), "a_func", {}, &i32, + create(Source{}, ast::StatementList{}), + ast::FunctionDecorationList{}); ASSERT_TRUE(b.GenerateGlobalVariable(v)) << b.error(); ASSERT_TRUE(b.GenerateGlobalVariable(a)) << b.error(); diff --git a/src/writer/wgsl/generator_impl_block_test.cc b/src/writer/wgsl/generator_impl_block_test.cc index b7e88b1291..ad15b5daf6 100644 --- a/src/writer/wgsl/generator_impl_block_test.cc +++ b/src/writer/wgsl/generator_impl_block_test.cc @@ -28,9 +28,9 @@ namespace { using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, Emit_Block) { - ast::BlockStatement b(Source{}); - b.append(create(Source{})); - + ast::BlockStatement b(Source{}, ast::StatementList{ + create(Source{}), + }); gen.increment_indent(); ASSERT_TRUE(gen.EmitStatement(&b)) << gen.error(); @@ -41,9 +41,9 @@ TEST_F(WgslGeneratorImplTest, Emit_Block) { } TEST_F(WgslGeneratorImplTest, Emit_Block_WithoutNewline) { - ast::BlockStatement b(Source{}); - b.append(create(Source{})); - + ast::BlockStatement b(Source{}, ast::StatementList{ + create(Source{}), + }); gen.increment_indent(); ASSERT_TRUE(gen.EmitBlock(&b)) << gen.error(); diff --git a/src/writer/wgsl/generator_impl_case_test.cc b/src/writer/wgsl/generator_impl_case_test.cc index 271ab692d3..aa31215dc6 100644 --- a/src/writer/wgsl/generator_impl_case_test.cc +++ b/src/writer/wgsl/generator_impl_case_test.cc @@ -33,9 +33,10 @@ using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, Emit_Case) { ast::type::I32 i32; - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::CaseSelectorList lit; lit.push_back(create(Source{}, &i32, 5)); ast::CaseStatement c(Source{}, lit, body); @@ -52,9 +53,10 @@ TEST_F(WgslGeneratorImplTest, Emit_Case) { TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) { ast::type::I32 i32; - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::CaseSelectorList lit; lit.push_back(create(Source{}, &i32, 5)); lit.push_back(create(Source{}, &i32, 6)); @@ -70,8 +72,10 @@ TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) { } TEST_F(WgslGeneratorImplTest, Emit_Case_Default) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::CaseStatement c(Source{}, ast::CaseSelectorList{}, body); gen.increment_indent(); diff --git a/src/writer/wgsl/generator_impl_function_test.cc b/src/writer/wgsl/generator_impl_function_test.cc index e47cae54dd..061a623515 100644 --- a/src/writer/wgsl/generator_impl_function_test.cc +++ b/src/writer/wgsl/generator_impl_function_test.cc @@ -41,10 +41,11 @@ namespace { using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, Emit_Function) { - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + create(Source{}), + }); ast::type::Void void_type; ast::Function func(Source{}, mod.RegisterSymbol("my_func"), "my_func", {}, &void_type, body, ast::FunctionDecorationList{}); @@ -60,10 +61,11 @@ TEST_F(WgslGeneratorImplTest, Emit_Function) { } TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) { - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + create(Source{}), + }); ast::type::F32 f32; ast::type::I32 i32; ast::VariableList params; @@ -99,10 +101,11 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithParams) { } TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) { - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + create(Source{}), + }); ast::type::Void void_type; ast::Function func(Source{}, mod.RegisterSymbol("my_func"), "my_func", {}, &void_type, body, @@ -122,10 +125,11 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_WorkgroupSize) { } TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) { - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + create(Source{}), + }); ast::type::Void void_type; ast::Function func( Source{}, mod.RegisterSymbol("my_func"), "my_func", {}, &void_type, body, @@ -145,10 +149,11 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Stage) { } TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) { - auto* body = create(Source{}); - body->append(create(Source{})); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + create(Source{}), + }); ast::type::Void void_type; ast::Function func( Source{}, mod.RegisterSymbol("my_func"), "my_func", {}, &void_type, body, @@ -237,10 +242,11 @@ TEST_F(WgslGeneratorImplTest, "d")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("a"), "a", params, &void_type, body, ast::FunctionDecorationList{ @@ -267,10 +273,11 @@ TEST_F(WgslGeneratorImplTest, "d")), // constructor ast::VariableDecorationList{}); // decorations - auto* body = create(Source{}); - body->append(create(Source{}, var)); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}, var), + create(Source{}), + }); auto* func = create( Source{}, mod.RegisterSymbol("b"), "b", params, &void_type, body, ast::FunctionDecorationList{ diff --git a/src/writer/wgsl/generator_impl_if_test.cc b/src/writer/wgsl/generator_impl_if_test.cc index 75d0694f8c..38a8f5d2d7 100644 --- a/src/writer/wgsl/generator_impl_if_test.cc +++ b/src/writer/wgsl/generator_impl_if_test.cc @@ -30,9 +30,10 @@ using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, Emit_If) { auto* cond = create( Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement i(Source{}, cond, body, ast::ElseStatementList{}); gen.increment_indent(); @@ -47,14 +48,17 @@ TEST_F(WgslGeneratorImplTest, Emit_If) { TEST_F(WgslGeneratorImplTest, Emit_IfWithElseIf) { auto* else_cond = create( Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); - auto* else_body = create(Source{}); - else_body->append(create(Source{})); + auto* else_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* cond = create( Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement i( Source{}, cond, body, {create(Source{}, else_cond, else_body)}); @@ -71,14 +75,17 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithElseIf) { } TEST_F(WgslGeneratorImplTest, Emit_IfWithElse) { - auto* else_body = create(Source{}); - else_body->append(create(Source{})); + auto* else_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* cond = create( Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement i( Source{}, cond, body, {create(Source{}, nullptr, else_body)}); @@ -98,17 +105,22 @@ TEST_F(WgslGeneratorImplTest, Emit_IfWithMultiple) { auto* else_cond = create( Source{}, mod.RegisterSymbol("else_cond"), "else_cond"); - auto* else_body = create(Source{}); - else_body->append(create(Source{})); + auto* else_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); - auto* else_body_2 = create(Source{}); - else_body_2->append(create(Source{})); + auto* else_body_2 = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* cond = create( Source{}, mod.RegisterSymbol("cond"), "cond"); - auto* body = create(Source{}); - body->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::IfStatement i( Source{}, cond, body, { diff --git a/src/writer/wgsl/generator_impl_loop_test.cc b/src/writer/wgsl/generator_impl_loop_test.cc index 4c0b11e43e..94cc1e1b3d 100644 --- a/src/writer/wgsl/generator_impl_loop_test.cc +++ b/src/writer/wgsl/generator_impl_loop_test.cc @@ -28,8 +28,10 @@ namespace { using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, Emit_Loop) { - auto* body = create(Source{}); - body->append(create(Source{})); + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::LoopStatement l(Source{}, body, {}); gen.increment_indent(); @@ -42,12 +44,14 @@ TEST_F(WgslGeneratorImplTest, Emit_Loop) { } TEST_F(WgslGeneratorImplTest, Emit_LoopWithContinuing) { - auto* body = create(Source{}); - body->append(create(Source{})); - - auto* continuing = create(Source{}); - continuing->append(create(Source{})); - + auto* body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); + auto* continuing = create( + Source{}, ast::StatementList{ + create(Source{}), + }); ast::LoopStatement l(Source{}, body, continuing); gen.increment_indent(); diff --git a/src/writer/wgsl/generator_impl_switch_test.cc b/src/writer/wgsl/generator_impl_switch_test.cc index f8bd646bb1..495d924cd4 100644 --- a/src/writer/wgsl/generator_impl_switch_test.cc +++ b/src/writer/wgsl/generator_impl_switch_test.cc @@ -32,8 +32,10 @@ namespace { using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, Emit_Switch) { - auto* def_body = create(Source{}); - def_body->append(create(Source{})); + auto* def_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* def = create(Source{}, ast::CaseSelectorList{}, def_body); @@ -41,8 +43,10 @@ TEST_F(WgslGeneratorImplTest, Emit_Switch) { ast::CaseSelectorList case_val; case_val.push_back(create(Source{}, &i32, 5)); - auto* case_body = create(Source{}); - case_body->append(create(Source{})); + auto* case_body = create( + Source{}, ast::StatementList{ + create(Source{}), + }); auto* case_stmt = create(Source{}, case_val, case_body); diff --git a/src/writer/wgsl/generator_impl_test.cc b/src/writer/wgsl/generator_impl_test.cc index e1780131ae..f2ea0f3e6e 100644 --- a/src/writer/wgsl/generator_impl_test.cc +++ b/src/writer/wgsl/generator_impl_test.cc @@ -34,7 +34,7 @@ TEST_F(WgslGeneratorImplTest, Generate) { mod.AddFunction(create( Source{}, mod.RegisterSymbol("a_func"), "my_func", ast::VariableList{}, - &void_type, create(Source{}), + &void_type, create(Source{}, ast::StatementList{}), ast::FunctionDecorationList{})); ASSERT_TRUE(gen.Generate(mod)) << gen.error();