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 <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
6a788df30e
commit
e5e9617220
|
@ -17,9 +17,6 @@
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
ElseStatement::ElseStatement()
|
|
||||||
: Statement(), body_(std::make_unique<ast::BlockStatement>()) {}
|
|
||||||
|
|
||||||
ElseStatement::ElseStatement(std::unique_ptr<BlockStatement> body)
|
ElseStatement::ElseStatement(std::unique_ptr<BlockStatement> body)
|
||||||
: Statement(), body_(std::move(body)) {}
|
: Statement(), body_(std::move(body)) {}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,6 @@ namespace ast {
|
||||||
/// An else statement
|
/// An else statement
|
||||||
class ElseStatement : public Statement {
|
class ElseStatement : public Statement {
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
|
||||||
ElseStatement();
|
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param body the else body
|
/// @param body the else body
|
||||||
explicit ElseStatement(std::unique_ptr<BlockStatement> body);
|
explicit ElseStatement(std::unique_ptr<BlockStatement> body);
|
||||||
|
|
|
@ -51,7 +51,7 @@ TEST_F(ElseStatementTest, Creation_WithSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, IsElse) {
|
TEST_F(ElseStatementTest, IsElse) {
|
||||||
ElseStatement e;
|
ElseStatement e(create<BlockStatement>());
|
||||||
EXPECT_TRUE(e.IsElse());
|
EXPECT_TRUE(e.IsElse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,12 +64,12 @@ TEST_F(ElseStatementTest, HasCondition) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, HasContition_NullCondition) {
|
TEST_F(ElseStatementTest, HasContition_NullCondition) {
|
||||||
ElseStatement e;
|
ElseStatement e(create<BlockStatement>());
|
||||||
EXPECT_FALSE(e.HasCondition());
|
EXPECT_FALSE(e.HasCondition());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ElseStatementTest, IsValid) {
|
TEST_F(ElseStatementTest, IsValid) {
|
||||||
ElseStatement e;
|
ElseStatement e(create<BlockStatement>());
|
||||||
EXPECT_TRUE(e.IsValid());
|
EXPECT_TRUE(e.IsValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,9 +70,9 @@ TEST_F(IfStatementTest, IsValid_WithElseStatements) {
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>());
|
||||||
|
|
||||||
ElseStatementList else_stmts;
|
ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(create<ElseStatement>());
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
else_stmts[0]->set_condition(create<IdentifierExpression>("Ident"));
|
else_stmts[0]->set_condition(create<IdentifierExpression>("Ident"));
|
||||||
else_stmts.push_back(create<ElseStatement>());
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
|
|
||||||
IfStatement stmt(std::move(cond), std::move(body));
|
IfStatement stmt(std::move(cond), std::move(body));
|
||||||
stmt.set_else_statements(std::move(else_stmts));
|
stmt.set_else_statements(std::move(else_stmts));
|
||||||
|
@ -122,9 +122,9 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) {
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>());
|
||||||
|
|
||||||
ElseStatementList else_stmts;
|
ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(create<ElseStatement>());
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
else_stmts[0]->set_condition(create<IdentifierExpression>("Ident"));
|
else_stmts[0]->set_condition(create<IdentifierExpression>("Ident"));
|
||||||
else_stmts.push_back(create<ElseStatement>());
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
else_stmts.push_back(nullptr);
|
else_stmts.push_back(nullptr);
|
||||||
|
|
||||||
IfStatement stmt(std::move(cond), std::move(body));
|
IfStatement stmt(std::move(cond), std::move(body));
|
||||||
|
@ -138,7 +138,7 @@ TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>());
|
||||||
|
|
||||||
ElseStatementList else_stmts;
|
ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(create<ElseStatement>());
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
else_stmts[0]->set_condition(create<IdentifierExpression>(""));
|
else_stmts[0]->set_condition(create<IdentifierExpression>(""));
|
||||||
|
|
||||||
IfStatement stmt(std::move(cond), std::move(body));
|
IfStatement stmt(std::move(cond), std::move(body));
|
||||||
|
@ -152,8 +152,8 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>());
|
||||||
|
|
||||||
ElseStatementList else_stmts;
|
ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(create<ElseStatement>());
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
else_stmts.push_back(create<ElseStatement>());
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
|
|
||||||
IfStatement stmt(std::move(cond), std::move(body));
|
IfStatement stmt(std::move(cond), std::move(body));
|
||||||
stmt.set_else_statements(std::move(else_stmts));
|
stmt.set_else_statements(std::move(else_stmts));
|
||||||
|
@ -166,8 +166,8 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) {
|
||||||
body->append(create<DiscardStatement>());
|
body->append(create<DiscardStatement>());
|
||||||
|
|
||||||
ElseStatementList else_stmts;
|
ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(create<ElseStatement>());
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
else_stmts.push_back(create<ElseStatement>());
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
else_stmts[1]->set_condition(create<IdentifierExpression>("ident"));
|
else_stmts[1]->set_condition(create<IdentifierExpression>("ident"));
|
||||||
|
|
||||||
IfStatement stmt(std::move(cond), std::move(body));
|
IfStatement stmt(std::move(cond), std::move(body));
|
||||||
|
@ -208,10 +208,10 @@ TEST_F(IfStatementTest, ToStr_WithElseStatements) {
|
||||||
else_body->append(create<DiscardStatement>());
|
else_body->append(create<DiscardStatement>());
|
||||||
|
|
||||||
ElseStatementList else_stmts;
|
ElseStatementList else_stmts;
|
||||||
else_stmts.push_back(create<ElseStatement>());
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
else_stmts[0]->set_condition(create<IdentifierExpression>("ident"));
|
else_stmts[0]->set_condition(create<IdentifierExpression>("ident"));
|
||||||
else_stmts[0]->set_body(std::move(else_if_body));
|
else_stmts[0]->set_body(std::move(else_if_body));
|
||||||
else_stmts.push_back(create<ElseStatement>());
|
else_stmts.push_back(create<ElseStatement>(create<BlockStatement>()));
|
||||||
else_stmts[1]->set_body(std::move(else_body));
|
else_stmts[1]->set_body(std::move(else_body));
|
||||||
|
|
||||||
IfStatement stmt(std::move(cond), std::move(body));
|
IfStatement stmt(std::move(cond), std::move(body));
|
||||||
|
|
Loading…
Reference in New Issue