From e5e961722054a7d5a42f1997cb21e7e23e6a982f Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Sat, 14 Nov 2020 09:53:12 +0000 Subject: [PATCH] ast: Remove no-arg constructor for ast::ElseStatement 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: I6173a63a243fdcbdd8a53c91010e2f628248298f Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32678 Commit-Queue: Ben Clayton Reviewed-by: dan sinclair --- src/ast/else_statement.cc | 3 --- src/ast/else_statement.h | 2 -- src/ast/else_statement_test.cc | 6 +++--- src/ast/if_statement_test.cc | 22 +++++++++++----------- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/ast/else_statement.cc b/src/ast/else_statement.cc index d181caa4b1..f21614418a 100644 --- a/src/ast/else_statement.cc +++ b/src/ast/else_statement.cc @@ -17,9 +17,6 @@ namespace tint { namespace ast { -ElseStatement::ElseStatement() - : Statement(), body_(std::make_unique()) {} - ElseStatement::ElseStatement(std::unique_ptr body) : Statement(), body_(std::move(body)) {} diff --git a/src/ast/else_statement.h b/src/ast/else_statement.h index c79ffb8a2e..5fb38010ed 100644 --- a/src/ast/else_statement.h +++ b/src/ast/else_statement.h @@ -29,8 +29,6 @@ namespace ast { /// An else statement class ElseStatement : public Statement { public: - /// Constructor - ElseStatement(); /// Constructor /// @param body the else body explicit ElseStatement(std::unique_ptr body); diff --git a/src/ast/else_statement_test.cc b/src/ast/else_statement_test.cc index b8ae12ac71..826648ef7c 100644 --- a/src/ast/else_statement_test.cc +++ b/src/ast/else_statement_test.cc @@ -51,7 +51,7 @@ TEST_F(ElseStatementTest, Creation_WithSource) { } TEST_F(ElseStatementTest, IsElse) { - ElseStatement e; + ElseStatement e(create()); EXPECT_TRUE(e.IsElse()); } @@ -64,12 +64,12 @@ TEST_F(ElseStatementTest, HasCondition) { } TEST_F(ElseStatementTest, HasContition_NullCondition) { - ElseStatement e; + ElseStatement e(create()); EXPECT_FALSE(e.HasCondition()); } TEST_F(ElseStatementTest, IsValid) { - ElseStatement e; + ElseStatement e(create()); EXPECT_TRUE(e.IsValid()); } diff --git a/src/ast/if_statement_test.cc b/src/ast/if_statement_test.cc index d63368b0ad..20141ad826 100644 --- a/src/ast/if_statement_test.cc +++ b/src/ast/if_statement_test.cc @@ -70,9 +70,9 @@ TEST_F(IfStatementTest, IsValid_WithElseStatements) { body->append(create()); ElseStatementList else_stmts; - else_stmts.push_back(create()); + else_stmts.push_back(create(create())); else_stmts[0]->set_condition(create("Ident")); - else_stmts.push_back(create()); + else_stmts.push_back(create(create())); IfStatement stmt(std::move(cond), std::move(body)); stmt.set_else_statements(std::move(else_stmts)); @@ -122,9 +122,9 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) { body->append(create()); ElseStatementList else_stmts; - else_stmts.push_back(create()); + else_stmts.push_back(create(create())); else_stmts[0]->set_condition(create("Ident")); - else_stmts.push_back(create()); + else_stmts.push_back(create(create())); else_stmts.push_back(nullptr); IfStatement stmt(std::move(cond), std::move(body)); @@ -138,7 +138,7 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) { body->append(create()); ElseStatementList else_stmts; - else_stmts.push_back(create()); + else_stmts.push_back(create(create())); else_stmts[0]->set_condition(create("")); IfStatement stmt(std::move(cond), std::move(body)); @@ -152,8 +152,8 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) { body->append(create()); ElseStatementList else_stmts; - else_stmts.push_back(create()); - else_stmts.push_back(create()); + else_stmts.push_back(create(create())); + else_stmts.push_back(create(create())); IfStatement stmt(std::move(cond), std::move(body)); stmt.set_else_statements(std::move(else_stmts)); @@ -166,8 +166,8 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) { body->append(create()); ElseStatementList else_stmts; - else_stmts.push_back(create()); - else_stmts.push_back(create()); + else_stmts.push_back(create(create())); + else_stmts.push_back(create(create())); else_stmts[1]->set_condition(create("ident")); IfStatement stmt(std::move(cond), std::move(body)); @@ -208,10 +208,10 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) { else_body->append(create()); ElseStatementList else_stmts; - else_stmts.push_back(create()); + else_stmts.push_back(create(create())); else_stmts[0]->set_condition(create("ident")); else_stmts[0]->set_body(std::move(else_if_body)); - else_stmts.push_back(create()); + else_stmts.push_back(create(create())); else_stmts[1]->set_body(std::move(else_body)); IfStatement stmt(std::move(cond), std::move(body));