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 <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-16 14:25:27 +00:00 committed by Commit Bot service account
parent e5e9617220
commit 4ad0019df0
11 changed files with 15 additions and 28 deletions

View File

@ -17,9 +17,6 @@
namespace tint { namespace tint {
namespace ast { namespace ast {
CaseStatement::CaseStatement()
: Statement(), body_(std::make_unique<BlockStatement>()) {}
CaseStatement::CaseStatement(std::unique_ptr<BlockStatement> body) CaseStatement::CaseStatement(std::unique_ptr<BlockStatement> body)
: Statement(), body_(std::move(body)) {} : Statement(), body_(std::move(body)) {}

View File

@ -33,8 +33,6 @@ using CaseSelectorList = std::vector<std::unique_ptr<ast::IntLiteral>>;
/// A case statement /// A case statement
class CaseStatement : public Statement { class CaseStatement : public Statement {
public: public:
/// Constructor
CaseStatement();
/// Constructor /// Constructor
/// Creates a default case statement /// Creates a default case statement
/// @param body the case body /// @param body the case body

View File

@ -85,7 +85,7 @@ TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
auto body = create<BlockStatement>(); auto body = create<BlockStatement>();
body->append(create<DiscardStatement>()); body->append(create<DiscardStatement>());
CaseStatement c; CaseStatement c(create<ast::BlockStatement>());
c.set_body(std::move(body)); c.set_body(std::move(body));
EXPECT_TRUE(c.IsDefault()); EXPECT_TRUE(c.IsDefault());
} }
@ -95,18 +95,18 @@ TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
CaseSelectorList b; CaseSelectorList b;
b.push_back(create<SintLiteral>(&i32, 2)); b.push_back(create<SintLiteral>(&i32, 2));
CaseStatement c; CaseStatement c(create<ast::BlockStatement>());
c.set_selectors(std::move(b)); c.set_selectors(std::move(b));
EXPECT_FALSE(c.IsDefault()); EXPECT_FALSE(c.IsDefault());
} }
TEST_F(CaseStatementTest, IsCase) { TEST_F(CaseStatementTest, IsCase) {
CaseStatement c; CaseStatement c(create<ast::BlockStatement>());
EXPECT_TRUE(c.IsCase()); EXPECT_TRUE(c.IsCase());
} }
TEST_F(CaseStatementTest, IsValid) { TEST_F(CaseStatementTest, IsValid) {
CaseStatement c; CaseStatement c(create<ast::BlockStatement>());
EXPECT_TRUE(c.IsValid()); EXPECT_TRUE(c.IsValid());
} }

View File

@ -2150,7 +2150,8 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
for (size_t i = last_clause_index;; --i) { for (size_t i = last_clause_index;; --i) {
// Create the case clause. Temporarily put it in the wrong order // Create the case clause. Temporarily put it in the wrong order
// on the case statement list. // on the case statement list.
cases->emplace_back(std::make_unique<ast::CaseStatement>()); cases->emplace_back(std::make_unique<ast::CaseStatement>(
std::make_unique<ast::BlockStatement>()));
auto* clause = cases->back().get(); auto* clause = cases->back().get();
// Create a list of integer literals for the selector values leading to // 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. // Generate a default clause with a just fallthrough.
auto stmts = std::make_unique<ast::BlockStatement>(); auto stmts = std::make_unique<ast::BlockStatement>();
stmts->append(std::make_unique<ast::FallthroughStatement>()); stmts->append(std::make_unique<ast::FallthroughStatement>());
auto case_stmt = std::make_unique<ast::CaseStatement>(); auto case_stmt = std::make_unique<ast::CaseStatement>(std::move(stmts));
case_stmt->set_body(std::move(stmts));
cases->emplace_back(std::move(case_stmt)); cases->emplace_back(std::move(case_stmt));
} }

View File

@ -1653,7 +1653,8 @@ Maybe<std::unique_ptr<ast::CaseStatement>> ParserImpl::switch_body() {
auto source = t.source(); auto source = t.source();
next(); // Consume the peek next(); // Consume the peek
auto stmt = std::make_unique<ast::CaseStatement>(); auto stmt = std::make_unique<ast::CaseStatement>(
std::make_unique<ast::BlockStatement>());
stmt->set_source(source); stmt->set_source(source);
if (t.IsCase()) { if (t.IsCase()) {
auto selectors = expect_case_selectors(); auto selectors = expect_case_selectors();

View File

@ -106,11 +106,9 @@ TEST_F(HlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) {
} }
TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) { TEST_F(HlslGeneratorImplTest_Case, Emit_Case_Default) {
ast::CaseStatement c;
auto body = create<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(create<ast::BreakStatement>()); body->append(create<ast::BreakStatement>());
c.set_body(std::move(body)); ast::CaseStatement c(std::move(body));
gen.increment_indent(); gen.increment_indent();

View File

@ -31,10 +31,9 @@ namespace {
using HlslGeneratorImplTest_Switch = TestHelper; using HlslGeneratorImplTest_Switch = TestHelper;
TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) { TEST_F(HlslGeneratorImplTest_Switch, Emit_Switch) {
auto def = create<ast::CaseStatement>();
auto def_body = create<ast::BlockStatement>(); auto def_body = create<ast::BlockStatement>();
def_body->append(create<ast::BreakStatement>()); def_body->append(create<ast::BreakStatement>());
def->set_body(std::move(def_body)); auto def = create<ast::CaseStatement>(std::move(def_body));
ast::type::I32Type i32; ast::type::I32Type i32;
ast::CaseSelectorList case_val; ast::CaseSelectorList case_val;

View File

@ -108,11 +108,9 @@ TEST_F(MslGeneratorImplTest, Emit_Case_MultipleSelectors) {
} }
TEST_F(MslGeneratorImplTest, Emit_Case_Default) { TEST_F(MslGeneratorImplTest, Emit_Case_Default) {
ast::CaseStatement c;
auto body = create<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(create<ast::BreakStatement>()); body->append(create<ast::BreakStatement>());
c.set_body(std::move(body)); ast::CaseStatement c(std::move(body));
gen.increment_indent(); gen.increment_indent();

View File

@ -33,10 +33,9 @@ namespace {
using MslGeneratorImplTest = TestHelper; using MslGeneratorImplTest = TestHelper;
TEST_F(MslGeneratorImplTest, Emit_Switch) { TEST_F(MslGeneratorImplTest, Emit_Switch) {
auto def = create<ast::CaseStatement>();
auto def_body = create<ast::BlockStatement>(); auto def_body = create<ast::BlockStatement>();
def_body->append(create<ast::BreakStatement>()); def_body->append(create<ast::BreakStatement>());
def->set_body(std::move(def_body)); auto def = create<ast::CaseStatement>(std::move(def_body));
ast::type::I32Type i32; ast::type::I32Type i32;
ast::CaseSelectorList case_val; ast::CaseSelectorList case_val;

View File

@ -70,11 +70,9 @@ TEST_F(WgslGeneratorImplTest, Emit_Case_MultipleSelectors) {
} }
TEST_F(WgslGeneratorImplTest, Emit_Case_Default) { TEST_F(WgslGeneratorImplTest, Emit_Case_Default) {
ast::CaseStatement c;
auto body = create<ast::BlockStatement>(); auto body = create<ast::BlockStatement>();
body->append(create<ast::BreakStatement>()); body->append(create<ast::BreakStatement>());
c.set_body(std::move(body)); ast::CaseStatement c(std::move(body));
gen.increment_indent(); gen.increment_indent();

View File

@ -32,10 +32,9 @@ namespace {
using WgslGeneratorImplTest = TestHelper; using WgslGeneratorImplTest = TestHelper;
TEST_F(WgslGeneratorImplTest, Emit_Switch) { TEST_F(WgslGeneratorImplTest, Emit_Switch) {
auto def = create<ast::CaseStatement>();
auto def_body = create<ast::BlockStatement>(); auto def_body = create<ast::BlockStatement>();
def_body->append(create<ast::BreakStatement>()); def_body->append(create<ast::BreakStatement>());
def->set_body(std::move(def_body)); auto def = create<ast::CaseStatement>(std::move(def_body));
ast::type::I32Type i32; ast::type::I32Type i32;
ast::CaseSelectorList case_val; ast::CaseSelectorList case_val;