From 4ad0019df0f02cdc41fccdac3730a7f0896a6629 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 16 Nov 2020 14:25:27 +0000 Subject: [PATCH] ast: Remove no-arg constructor for ast::CastStatement In a near-future change, AST nodes, such as ast::BlockStatement will no longer be std::unique_ptrs, and will have to be constructed and owned by an external class. This means AST nodes can no longer allocate default child nodes. Bug: tint:322 Change-Id: I2a571d0a4727d6dc3d6c38e8b6602e131292f49c Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32676 Reviewed-by: dan sinclair Commit-Queue: dan sinclair --- src/ast/case_statement.cc | 3 --- src/ast/case_statement.h | 2 -- src/ast/case_statement_test.cc | 8 ++++---- src/reader/spirv/function.cc | 6 +++--- src/reader/wgsl/parser_impl.cc | 3 ++- src/writer/hlsl/generator_impl_case_test.cc | 4 +--- src/writer/hlsl/generator_impl_switch_test.cc | 3 +-- src/writer/msl/generator_impl_case_test.cc | 4 +--- src/writer/msl/generator_impl_switch_test.cc | 3 +-- src/writer/wgsl/generator_impl_case_test.cc | 4 +--- src/writer/wgsl/generator_impl_switch_test.cc | 3 +-- 11 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/ast/case_statement.cc b/src/ast/case_statement.cc index ab4cb3536f..3b137aafd2 100644 --- a/src/ast/case_statement.cc +++ b/src/ast/case_statement.cc @@ -17,9 +17,6 @@ namespace tint { namespace ast { -CaseStatement::CaseStatement() - : Statement(), body_(std::make_unique()) {} - CaseStatement::CaseStatement(std::unique_ptr body) : Statement(), body_(std::move(body)) {} diff --git a/src/ast/case_statement.h b/src/ast/case_statement.h index 0b3cf7a6b3..b15c93bc61 100644 --- a/src/ast/case_statement.h +++ b/src/ast/case_statement.h @@ -33,8 +33,6 @@ using CaseSelectorList = std::vector>; /// A case statement class CaseStatement : public Statement { public: - /// Constructor - CaseStatement(); /// Constructor /// Creates a default case statement /// @param body the case body diff --git a/src/ast/case_statement_test.cc b/src/ast/case_statement_test.cc index 1d61291d01..0a67de374e 100644 --- a/src/ast/case_statement_test.cc +++ b/src/ast/case_statement_test.cc @@ -85,7 +85,7 @@ TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) { auto body = create(); body->append(create()); - CaseStatement c; + CaseStatement c(create()); c.set_body(std::move(body)); EXPECT_TRUE(c.IsDefault()); } @@ -95,18 +95,18 @@ TEST_F(CaseStatementTest, IsDefault_WithSelectors) { CaseSelectorList b; b.push_back(create(&i32, 2)); - CaseStatement c; + CaseStatement c(create()); c.set_selectors(std::move(b)); EXPECT_FALSE(c.IsDefault()); } TEST_F(CaseStatementTest, IsCase) { - CaseStatement c; + CaseStatement c(create()); EXPECT_TRUE(c.IsCase()); } TEST_F(CaseStatementTest, IsValid) { - CaseStatement c; + CaseStatement c(create()); EXPECT_TRUE(c.IsValid()); } diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index c37f7ee99b..f2e90d0d1a 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -2150,7 +2150,8 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) { for (size_t i = last_clause_index;; --i) { // Create the case clause. Temporarily put it in the wrong order // on the case statement list. - cases->emplace_back(std::make_unique()); + cases->emplace_back(std::make_unique( + std::make_unique())); auto* clause = cases->back().get(); // Create a list of integer literals for the selector values leading to @@ -2189,8 +2190,7 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) { // Generate a default clause with a just fallthrough. auto stmts = std::make_unique(); stmts->append(std::make_unique()); - auto case_stmt = std::make_unique(); - case_stmt->set_body(std::move(stmts)); + auto case_stmt = std::make_unique(std::move(stmts)); cases->emplace_back(std::move(case_stmt)); } diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index e70d2a4d31..ac1b00484f 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -1653,7 +1653,8 @@ Maybe> ParserImpl::switch_body() { auto source = t.source(); next(); // Consume the peek - auto stmt = std::make_unique(); + auto stmt = std::make_unique( + std::make_unique()); stmt->set_source(source); if (t.IsCase()) { auto selectors = expect_case_selectors(); diff --git a/src/writer/hlsl/generator_impl_case_test.cc b/src/writer/hlsl/generator_impl_case_test.cc index 8da7d20f96..bffb1e5624 100644 --- a/src/writer/hlsl/generator_impl_case_test.cc +++ b/src/writer/hlsl/generator_impl_case_test.cc @@ -106,11 +106,9 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) { } TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) { - ast::CaseStatement c; - auto body = create(); body->append(create()); - c.set_body(std::move(body)); + ast::CaseStatement c(std::move(body)); gen.increment_indent(); diff --git a/src/writer/hlsl/generator_impl_switch_test.cc b/src/writer/hlsl/generator_impl_switch_test.cc index 005f3d3789..a80d7e9a79 100644 --- a/src/writer/hlsl/generator_impl_switch_test.cc +++ b/src/writer/hlsl/generator_impl_switch_test.cc @@ -31,10 +31,9 @@ namespace { using HlslGeneratorImplTest_Switch = TestHelper; TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) { - auto def = create(); auto def_body = create(); def_body->append(create()); - def->set_body(std::move(def_body)); + auto def = create(std::move(def_body)); ast::type::I32Type i32; ast::CaseSelectorList case_val; diff --git a/src/writer/msl/generator_impl_case_test.cc b/src/writer/msl/generator_impl_case_test.cc index 9902a4d604..0ffaa217cf 100644 --- a/src/writer/msl/generator_impl_case_test.cc +++ b/src/writer/msl/generator_impl_case_test.cc @@ -108,11 +108,9 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) { } TEST_F(MslGeneratorImplTest, Emit_Case_Default) { - ast::CaseStatement c; - auto body = create(); body->append(create()); - c.set_body(std::move(body)); + ast::CaseStatement c(std::move(body)); gen.increment_indent(); diff --git a/src/writer/msl/generator_impl_switch_test.cc b/src/writer/msl/generator_impl_switch_test.cc index 9b85f23976..d71b5346dd 100644 --- a/src/writer/msl/generator_impl_switch_test.cc +++ b/src/writer/msl/generator_impl_switch_test.cc @@ -33,10 +33,9 @@ namespace { using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, Emit_Switch) { - auto def = create(); auto def_body = create(); def_body->append(create()); - def->set_body(std::move(def_body)); + auto def = create(std::move(def_body)); ast::type::I32Type i32; ast::CaseSelectorList case_val; diff --git a/src/writer/wgsl/generator_impl_case_test.cc b/src/writer/wgsl/generator_impl_case_test.cc index 3830b51254..a6705e2daf 100644 --- a/src/writer/wgsl/generator_impl_case_test.cc +++ b/src/writer/wgsl/generator_impl_case_test.cc @@ -70,11 +70,9 @@ TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) { } TEST_F(WgslGeneratorImplTest, Emit_Case_Default) { - ast::CaseStatement c; - auto body = create(); body->append(create()); - c.set_body(std::move(body)); + ast::CaseStatement c(std::move(body)); gen.increment_indent(); diff --git a/src/writer/wgsl/generator_impl_switch_test.cc b/src/writer/wgsl/generator_impl_switch_test.cc index 491e2f0e96..2319a879a1 100644 --- a/src/writer/wgsl/generator_impl_switch_test.cc +++ b/src/writer/wgsl/generator_impl_switch_test.cc @@ -32,10 +32,9 @@ namespace { using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, Emit_Switch) { - auto def = create(); auto def_body = create(); def_body->append(create()); - def->set_body(std::move(def_body)); + auto def = create(std::move(def_body)); ast::type::I32Type i32; ast::CaseSelectorList case_val;