Remove BlockStatement::append()

Bug: tint:396
Bug: tint:390
Change-Id: I3b558a8961f9890f24d1aa3d6647ec095e5fe1cb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35421
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-12-14 20:25:27 +00:00
committed by Commit Bot service account
parent ed70caf6a5
commit db5ce658b5
60 changed files with 2696 additions and 2046 deletions

View File

@@ -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<BlockStatement>(ctx->Clone(source()));
cloned->statements_ = ctx->Clone(statements_);
return cloned;
return ctx->mod->create<BlockStatement>(ctx->Clone(source()),
ctx->Clone(statements_));
}
bool BlockStatement::IsValid() const {

View File

@@ -29,19 +29,12 @@ class BlockStatement : public Castable<BlockStatement, Statement> {
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<BlockStatement, Statement> {
const Statement* operator[](size_t idx) const { return statements_[idx]; }
/// @returns the beginning iterator
std::vector<Statement*>::const_iterator begin() const {
return statements_.begin();
}
StatementList::const_iterator begin() const { return statements_.begin(); }
/// @returns the ending iterator
std::vector<Statement*>::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<BlockStatement, Statement> {
private:
BlockStatement(const BlockStatement&) = delete;
std::vector<Statement*> statements_;
StatementList statements_;
};
} // namespace ast

View File

@@ -31,8 +31,7 @@ TEST_F(BlockStatementTest, Creation) {
auto* d = create<DiscardStatement>(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<DiscardStatement>(Source{});
auto* s3 = create<DiscardStatement>(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<BlockStatement>());
}
TEST_F(BlockStatementTest, IsValid) {
BlockStatement b(Source{});
b.append(create<DiscardStatement>(Source{}));
BlockStatement b(Source{}, ast::StatementList{
create<DiscardStatement>(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<DiscardStatement>(Source{}));
b.append(nullptr);
BlockStatement b(Source{}, ast::StatementList{
create<DiscardStatement>(Source{}),
nullptr,
});
EXPECT_FALSE(b.IsValid());
}
TEST_F(BlockStatementTest, IsValid_InvalidBodyStatement) {
BlockStatement b(Source{});
b.append(create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}),
ElseStatementList{}));
BlockStatement b(
Source{},
ast::StatementList{
create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}),
ElseStatementList{}),
});
EXPECT_FALSE(b.IsValid());
}
TEST_F(BlockStatementTest, ToStr) {
BlockStatement b(Source{});
b.append(create<DiscardStatement>(Source{}));
BlockStatement b(Source{}, ast::StatementList{
create<DiscardStatement>(Source{}),
});
std::ostringstream out;
b.to_str(out, 2);

View File

@@ -35,9 +35,8 @@ TEST_F(CaseStatementTest, Creation_i32) {
auto* selector = create<SintLiteral>(Source{}, &i32, 2);
b.push_back(selector);
auto* body = create<BlockStatement>(Source{});
auto* discard = create<DiscardStatement>(Source{});
body->append(discard);
auto* body = create<BlockStatement>(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<SintLiteral>(Source{}, &u32, 2);
b.push_back(selector);
auto* body = create<BlockStatement>(Source{});
auto* discard = create<DiscardStatement>(Source{});
body->append(discard);
auto* body = create<BlockStatement>(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<SintLiteral>(Source{}, &i32, 2));
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<SintLiteral>(Source{}, &i32, 2));
CaseStatement c(Source{}, b, create<BlockStatement>(Source{}));
CaseStatement c(Source{}, b,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_FALSE(c.IsDefault());
}
TEST_F(CaseStatementTest, IsCase) {
CaseStatement c(Source{}, CaseSelectorList{},
create<BlockStatement>(Source{}));
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(c.Is<CaseStatement>());
}
TEST_F(CaseStatementTest, IsValid) {
CaseStatement c(Source{}, CaseSelectorList{},
create<BlockStatement>(Source{}));
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(c.IsValid());
}
@@ -112,10 +113,11 @@ TEST_F(CaseStatementTest, IsValid_NullBodyStatement) {
CaseSelectorList b;
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(nullptr);
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<SintLiteral>(Source{}, &i32, 2));
auto* body = create<BlockStatement>(Source{});
body->append(create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}),
ElseStatementList{}));
auto* body = create<BlockStatement>(
Source{},
StatementList{
create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(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<SintLiteral>(Source{}, &i32, -2));
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<UintLiteral>(Source{}, &u32, 2));
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
CaseStatement c(Source{}, {b}, body);
std::ostringstream out;
@@ -175,8 +183,10 @@ TEST_F(CaseStatementTest, ToStr_WithMultipleSelectors) {
b.push_back(create<SintLiteral>(Source{}, &i32, 1));
b.push_back(create<SintLiteral>(Source{}, &i32, 2));
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
CaseStatement c(Source{}, CaseSelectorList{}, body);
std::ostringstream out;

View File

@@ -31,9 +31,10 @@ TEST_F(ElseStatementTest, Creation) {
type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>(
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<BlockStatement>(Source{}));
create<BlockStatement>(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<BlockStatement>(Source{}));
ElseStatement e(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(e.Is<ElseStatement>());
}
@@ -59,49 +61,57 @@ TEST_F(ElseStatementTest, HasCondition) {
type::Bool bool_type;
auto* cond = create<ScalarConstructorExpression>(
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
ElseStatement e(Source{}, cond, create<BlockStatement>(Source{}));
ElseStatement e(Source{}, cond,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(e.HasCondition());
}
TEST_F(ElseStatementTest, HasContition_NullCondition) {
ElseStatement e(Source{}, nullptr, create<BlockStatement>(Source{}));
ElseStatement e(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_FALSE(e.HasCondition());
}
TEST_F(ElseStatementTest, IsValid) {
ElseStatement e(Source{}, nullptr, create<BlockStatement>(Source{}));
ElseStatement e(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(e.IsValid());
}
TEST_F(ElseStatementTest, IsValid_WithBody) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
ElseStatement e(Source{}, nullptr, body);
EXPECT_TRUE(e.IsValid());
}
TEST_F(ElseStatementTest, IsValid_WithNullBodyStatement) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(nullptr);
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
nullptr,
});
ElseStatement e(Source{}, nullptr, body);
EXPECT_FALSE(e.IsValid());
}
TEST_F(ElseStatementTest, IsValid_InvalidCondition) {
auto* cond = create<ScalarConstructorExpression>(Source{}, nullptr);
ElseStatement e(Source{}, cond, create<BlockStatement>(Source{}));
ElseStatement e(Source{}, cond,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_FALSE(e.IsValid());
}
TEST_F(ElseStatementTest, IsValid_InvalidBodyStatement) {
auto* body = create<BlockStatement>(Source{});
body->append(create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}),
ElseStatementList{}));
auto* body = create<BlockStatement>(
Source{},
StatementList{
create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(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<ScalarConstructorExpression>(
Source{}, create<BoolLiteral>(Source{}, &bool_type, true));
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
ElseStatement e(Source{}, nullptr, body);
std::ostringstream out;
e.to_str(out, 2);

View File

@@ -44,7 +44,8 @@ TEST_F(FunctionTest, Creation) {
auto* var = params[0];
Function f(Source{}, func_sym, "func", params, &void_type,
create<BlockStatement>(Source{}), FunctionDecorationList{});
create<BlockStatement>(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<BlockStatement>(Source{}),
&void_type, create<BlockStatement>(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<BlockStatement>(Source{}), FunctionDecorationList{});
create<BlockStatement>(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<BlockStatement>(Source{}), FunctionDecorationList{});
create<BlockStatement>(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<BlockStatement>(Source{}), FunctionDecorationList{});
create<BlockStatement>(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<BlockStatement>(Source{}), FunctionDecorationList{});
create<BlockStatement>(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<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
Function f(Source{}, func_sym, "", params, &void_type, body,
Function f(Source{}, func_sym, "", params, &void_type,
create<BlockStatement>(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<BlockStatement>(Source{}), FunctionDecorationList{});
create<BlockStatement>(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<BlockStatement>(Source{}), FunctionDecorationList{});
create<BlockStatement>(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<BlockStatement>(Source{}), FunctionDecorationList{});
create<BlockStatement>(Source{}, StatementList{}),
FunctionDecorationList{});
EXPECT_FALSE(f.IsValid());
}
@@ -304,9 +312,11 @@ TEST_F(FunctionTest, IsValid_NullBodyStatement) {
false, nullptr,
ast::VariableDecorationList{}));
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(nullptr);
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(nullptr);
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
});
Function f(
Source{}, func_sym, "func", {}, &void_type, body,
FunctionDecorationList{create<WorkgroupDecoration>(2, 4, 6, Source{})});
@@ -391,9 +406,10 @@ TEST_F(FunctionTest, ToStr_WithParams) {
false, nullptr,
ast::VariableDecorationList{}));
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<BlockStatement>(Source{}), FunctionDecorationList{});
create<BlockStatement>(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<BlockStatement>(Source{}), FunctionDecorationList{});
create<BlockStatement>(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<BlockStatement>(Source{});
auto* stmt = create<DiscardStatement>(Source{});
body->append(stmt);
auto* body = create<BlockStatement>(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<BlockStatement>(Source{});
auto* body = create<BlockStatement>(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<BlockStatement>(Source{}), FunctionDecorationList{});
create<BlockStatement>(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<BlockStatement>(Source{}),
create<BlockStatement>(Source{}, StatementList{}),
{create<WorkgroupDecoration>(2u, 4u, 6u, Source{})});
uint32_t x = 0;

View File

@@ -27,9 +27,8 @@ using IfStatementTest = TestHelper;
TEST_F(IfStatementTest, Creation) {
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(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<BlockStatement>(Source{}),
IfStatement stmt(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}),
ElseStatementList{});
EXPECT_TRUE(stmt.Is<IfStatement>());
}
@@ -46,9 +46,8 @@ TEST_F(IfStatementTest, IsIf) {
TEST_F(IfStatementTest, IsValid) {
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(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<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body,
{
create<ElseStatement>(
Source{},
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("Ident"), "Ident"),
create<BlockStatement>(Source{})),
create<ElseStatement>(Source{}, nullptr,
create<BlockStatement>(Source{})),
create<BlockStatement>(Source{}, StatementList{})),
create<ElseStatement>(
Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{})),
});
EXPECT_TRUE(stmt.IsValid());
}
TEST_F(IfStatementTest, IsValid_MissingCondition) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(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<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(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<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(nullptr);
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(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<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}),
ast::ElseStatementList{}));
auto* body = create<BlockStatement>(
Source{},
StatementList{
create<DiscardStatement>(Source{}),
create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(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<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body,
{
create<ElseStatement>(
Source{},
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("Ident"), "Ident"),
create<BlockStatement>(Source{})),
create<ElseStatement>(Source{}, nullptr,
create<BlockStatement>(Source{})),
create<BlockStatement>(Source{}, StatementList{})),
create<ElseStatement>(
Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{})),
nullptr,
});
EXPECT_FALSE(stmt.IsValid());
@@ -137,32 +137,32 @@ TEST_F(IfStatementTest, IsValid_NullElseStatement) {
TEST_F(IfStatementTest, IsValid_InvalidElseStatement) {
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
IfStatement stmt(
Source{}, cond, body,
{
create<ElseStatement>(Source{},
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol(""), ""),
create<BlockStatement>(Source{})),
});
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body,
{
create<ElseStatement>(
Source{},
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol(""), ""),
create<BlockStatement>(Source{}, StatementList{})),
});
EXPECT_FALSE(stmt.IsValid());
}
TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body,
{
create<ElseStatement>(Source{}, nullptr,
create<BlockStatement>(Source{})),
create<ElseStatement>(Source{}, nullptr,
create<BlockStatement>(Source{})),
create<ElseStatement>(
Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{})),
create<ElseStatement>(
Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{})),
});
EXPECT_FALSE(stmt.IsValid());
}
@@ -170,18 +170,18 @@ TEST_F(IfStatementTest, IsValid_MultipleElseWiththoutCondition) {
TEST_F(IfStatementTest, IsValid_ElseNotLast) {
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body,
{
create<ElseStatement>(Source{}, nullptr,
create<BlockStatement>(Source{})),
create<ElseStatement>(
Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{})),
create<ElseStatement>(
Source{},
create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident"),
create<BlockStatement>(Source{})),
Source{}, mod.RegisterSymbol("Ident"), "Ident"),
create<BlockStatement>(Source{}, StatementList{})),
});
EXPECT_FALSE(stmt.IsValid());
}
@@ -189,9 +189,8 @@ TEST_F(IfStatementTest, IsValid_ElseNotLast) {
TEST_F(IfStatementTest, ToStr) {
auto* cond = create<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(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<IdentifierExpression>(Source{},
mod.RegisterSymbol("cond"), "cond");
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* else_if_body = create<BlockStatement>(Source{});
else_if_body->append(create<DiscardStatement>(Source{}));
auto* else_body = create<BlockStatement>(Source{});
else_body->append(create<DiscardStatement>(Source{}));
else_body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* else_if_body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* else_body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{}),
create<DiscardStatement>(Source{})});
IfStatement stmt(Source{}, cond, body,
{
create<ElseStatement>(

View File

@@ -28,12 +28,12 @@ namespace {
using LoopStatementTest = TestHelper;
TEST_F(LoopStatementTest, Creation) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* b = body->last();
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(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<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(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<BlockStatement>(Source{}),
create<BlockStatement>(Source{}));
LoopStatement l(Source{}, create<BlockStatement>(Source{}, StatementList{}),
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(l.Is<LoopStatement>());
}
TEST_F(LoopStatementTest, HasContinuing_WithoutContinuing) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, {});
EXPECT_FALSE(l.has_continuing());
}
TEST_F(LoopStatementTest, HasContinuing_WithContinuing) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, continuing);
EXPECT_TRUE(l.has_continuing());
}
TEST_F(LoopStatementTest, IsValid) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, continuing);
EXPECT_TRUE(l.IsValid());
}
TEST_F(LoopStatementTest, IsValid_WithoutContinuing) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, create<BlockStatement>(Source{}));
LoopStatement l(Source{}, body,
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(l.IsValid());
}
TEST_F(LoopStatementTest, IsValid_WithoutBody) {
LoopStatement l(Source{}, create<BlockStatement>(Source{}),
create<BlockStatement>(Source{}));
LoopStatement l(Source{}, create<BlockStatement>(Source{}, StatementList{}),
create<BlockStatement>(Source{}, StatementList{}));
EXPECT_TRUE(l.IsValid());
}
TEST_F(LoopStatementTest, IsValid_NullBodyStatement) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(nullptr);
auto* body =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
nullptr,
});
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, continuing);
EXPECT_FALSE(l.IsValid());
}
TEST_F(LoopStatementTest, IsValid_InvalidBodyStatement) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
body->append(create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}),
ElseStatementList{}));
auto* body = create<BlockStatement>(
Source{},
StatementList{
create<DiscardStatement>(Source{}),
create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}),
ElseStatementList{}),
});
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, continuing);
EXPECT_FALSE(l.IsValid());
}
TEST_F(LoopStatementTest, IsValid_NullContinuingStatement) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
continuing->append(nullptr);
auto* continuing =
create<BlockStatement>(Source{}, StatementList{
create<DiscardStatement>(Source{}),
nullptr,
});
LoopStatement l(Source{}, body, continuing);
EXPECT_FALSE(l.IsValid());
}
TEST_F(LoopStatementTest, IsValid_InvalidContinuingStatement) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
continuing->append(create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}),
ElseStatementList{}));
auto* continuing = create<BlockStatement>(
Source{},
StatementList{
create<DiscardStatement>(Source{}),
create<IfStatement>(Source{}, nullptr,
create<BlockStatement>(Source{}, StatementList{}),
ElseStatementList{}),
});
LoopStatement l(Source{}, body, continuing);
EXPECT_FALSE(l.IsValid());
}
TEST_F(LoopStatementTest, ToStr) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, {});
std::ostringstream out;
@@ -171,11 +182,11 @@ TEST_F(LoopStatementTest, ToStr) {
}
TEST_F(LoopStatementTest, ToStr_WithContinuing) {
auto* body = create<BlockStatement>(Source{});
body->append(create<DiscardStatement>(Source{}));
auto* body = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
auto* continuing = create<BlockStatement>(Source{});
continuing->append(create<DiscardStatement>(Source{}));
auto* continuing = create<BlockStatement>(
Source{}, StatementList{create<DiscardStatement>(Source{})});
LoopStatement l(Source{}, body, continuing);
std::ostringstream out;

View File

@@ -49,9 +49,10 @@ TEST_F(ModuleTest, LookupFunction) {
Module m;
auto func_sym = m.RegisterSymbol("main");
auto* func = create<Function>(Source{}, func_sym, "main", VariableList{},
&f32, create<BlockStatement>(Source{}),
ast::FunctionDecorationList{});
auto* func =
create<Function>(Source{}, func_sym, "main", VariableList{}, &f32,
create<BlockStatement>(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<Function>(
Source{}, m.RegisterSymbol("main"), "main", VariableList(), &f32,
create<BlockStatement>(Source{}), ast::FunctionDecorationList{});
create<BlockStatement>(Source{}, StatementList{}),
ast::FunctionDecorationList{});
m.AddFunction(func);
EXPECT_TRUE(m.IsValid());
}

View File

@@ -37,8 +37,8 @@ TEST_F(SwitchStatementTest, Creation) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
auto* case_stmt =
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{}));
auto* case_stmt = create<CaseStatement>(
Source{}, lit, create<BlockStatement>(Source{}, StatementList{}));
body.push_back(case_stmt);
SwitchStatement stmt(Source{}, ident, body);
@@ -67,8 +67,8 @@ TEST_F(SwitchStatementTest, IsSwitch) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
body.push_back(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
body.push_back(create<CaseStatement>(
Source{}, lit, create<BlockStatement>(Source{}, StatementList{})));
SwitchStatement stmt(Source{}, ident, body);
EXPECT_TRUE(stmt.Is<SwitchStatement>());
@@ -83,8 +83,8 @@ TEST_F(SwitchStatementTest, IsValid) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
body.push_back(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
body.push_back(create<CaseStatement>(
Source{}, lit, create<BlockStatement>(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<SintLiteral>(Source{}, &i32, 2));
CaseStatementList body;
body.push_back(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
body.push_back(create<CaseStatement>(
Source{}, lit, create<BlockStatement>(Source{}, StatementList{})));
SwitchStatement stmt(Source{}, nullptr, body);
EXPECT_FALSE(stmt.IsValid());
@@ -113,8 +113,8 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_Condition) {
auto* ident =
create<IdentifierExpression>(Source{}, mod.RegisterSymbol(""), "");
CaseStatementList body;
body.push_back(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
body.push_back(create<CaseStatement>(
Source{}, lit, create<BlockStatement>(Source{}, StatementList{})));
SwitchStatement stmt(Source{}, ident, body);
EXPECT_FALSE(stmt.IsValid());
@@ -129,8 +129,8 @@ TEST_F(SwitchStatementTest, IsValid_Null_BodyStatement) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
body.push_back(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
body.push_back(create<CaseStatement>(
Source{}, lit, create<BlockStatement>(Source{}, StatementList{})));
body.push_back(nullptr);
SwitchStatement stmt(Source{}, ident, body);
@@ -141,9 +141,9 @@ TEST_F(SwitchStatementTest, IsValid_Invalid_BodyStatement) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
auto* case_body = create<BlockStatement>(Source{});
case_body->append(nullptr);
auto* case_body = create<BlockStatement>(Source{}, StatementList{
nullptr,
});
CaseStatementList body;
body.push_back(
create<CaseStatement>(Source{}, CaseSelectorList{}, case_body));
@@ -176,8 +176,8 @@ TEST_F(SwitchStatementTest, ToStr) {
auto* ident = create<IdentifierExpression>(
Source{}, mod.RegisterSymbol("ident"), "ident");
CaseStatementList body;
body.push_back(
create<CaseStatement>(Source{}, lit, create<BlockStatement>(Source{})));
body.push_back(create<CaseStatement>(
Source{}, lit, create<BlockStatement>(Source{}, StatementList{})));
SwitchStatement stmt(Source{}, ident, body);
std::ostringstream out;