Replace Statement::(Is|As)* with Castable

Change-Id: I5520752a4b5844be0ecac7921616893d123b246a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34315
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-30 23:30:58 +00:00
parent 4d3ca7f132
commit 1d8098ae94
75 changed files with 331 additions and 671 deletions

View File

@@ -561,8 +561,8 @@ void FunctionEmitter::PushGuard(const std::string& guard_name,
const auto& top = statements_stack_.back();
auto* cond = create<ast::IdentifierExpression>(guard_name);
auto* body = create<ast::BlockStatement>();
auto* const guard_stmt =
AddStatement(create<ast::IfStatement>(cond, body))->AsIf();
auto* const guard_stmt = AddStatement(create<ast::IfStatement>(cond, body))
->As<ast::IfStatement>();
PushNewStatementBlock(top.construct_, end_id,
[guard_stmt](StatementBlock* s) {
guard_stmt->set_body(s->statements_);
@@ -574,8 +574,8 @@ void FunctionEmitter::PushTrueGuard(uint32_t end_id) {
const auto& top = statements_stack_.back();
auto* cond = MakeTrue();
auto* body = create<ast::BlockStatement>();
auto* const guard_stmt =
AddStatement(create<ast::IfStatement>(cond, body))->AsIf();
auto* const guard_stmt = AddStatement(create<ast::IfStatement>(cond, body))
->As<ast::IfStatement>();
guard_stmt->set_condition(MakeTrue());
PushNewStatementBlock(top.construct_, end_id,
[guard_stmt](StatementBlock* s) {
@@ -2023,8 +2023,8 @@ bool FunctionEmitter::EmitIfStart(const BlockInfo& block_info) {
block_info.basic_block->terminator()->GetSingleWordInOperand(0);
auto* cond = MakeExpression(condition_id).expr;
auto* body = create<ast::BlockStatement>();
auto* const if_stmt =
AddStatement(create<ast::IfStatement>(cond, body))->AsIf();
auto* const if_stmt = AddStatement(create<ast::IfStatement>(cond, body))
->As<ast::IfStatement>();
// Generate the code for the condition.
@@ -2137,7 +2137,7 @@ bool FunctionEmitter::EmitSwitchStart(const BlockInfo& block_info) {
const auto* branch = block_info.basic_block->terminator();
auto* const switch_stmt =
AddStatement(create<ast::SwitchStatement>())->AsSwitch();
AddStatement(create<ast::SwitchStatement>())->As<ast::SwitchStatement>();
const auto selector_id = branch->GetSingleWordInOperand(0);
// Generate the code for the selector.
auto selector = MakeExpression(selector_id);
@@ -2255,7 +2255,7 @@ bool FunctionEmitter::EmitLoopStart(const Construct* construct) {
auto* loop =
AddStatement(create<ast::LoopStatement>(create<ast::BlockStatement>(),
create<ast::BlockStatement>()))
->AsLoop();
->As<ast::LoopStatement>();
PushNewStatementBlock(
construct, construct->end_id,
[loop](StatementBlock* s) { loop->set_body(s->statements_); });
@@ -2266,11 +2266,11 @@ bool FunctionEmitter::EmitContinuingStart(const Construct* construct) {
// A continue construct has the same depth as its associated loop
// construct. Start a continue construct.
auto* loop_candidate = LastStatement();
if (!loop_candidate->IsLoop()) {
if (!loop_candidate->Is<ast::LoopStatement>()) {
return Fail() << "internal error: starting continue construct, "
"expected loop on top of stack";
}
auto* loop = loop_candidate->AsLoop();
auto* loop = loop_candidate->As<ast::LoopStatement>();
PushNewStatementBlock(
construct, construct->end_id,
[loop](StatementBlock* s) { loop->set_continuing(s->statements_); });

View File

@@ -27,16 +27,21 @@
#include "src/ast/access_control.h"
#include "src/ast/array_decoration.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/break_statement.h"
#include "src/ast/builtin.h"
#include "src/ast/call_statement.h"
#include "src/ast/case_statement.h"
#include "src/ast/constructor_expression.h"
#include "src/ast/continue_statement.h"
#include "src/ast/else_statement.h"
#include "src/ast/switch_statement.h"
#include "src/ast/function.h"
#include "src/ast/if_statement.h"
#include "src/ast/literal.h"
#include "src/ast/loop_statement.h"
#include "src/ast/module.h"
#include "src/ast/pipeline_stage.h"
#include "src/ast/return_statement.h"
#include "src/ast/statement.h"
#include "src/ast/storage_class.h"
#include "src/ast/struct.h"
@@ -44,10 +49,11 @@
#include "src/ast/struct_member.h"
#include "src/ast/struct_member_decoration.h"
#include "src/ast/type/storage_texture_type.h"
#include "src/ast/type/struct_type.h"
#include "src/ast/type/texture_type.h"
#include "src/ast/type/type.h"
#include "src/ast/type/struct_type.h"
#include "src/ast/variable.h"
#include "src/ast/variable_decl_statement.h"
#include "src/ast/variable_decoration.h"
#include "src/context.h"
#include "src/diagnostic/diagnostic.h"

View File

@@ -36,7 +36,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToVariable) {
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsAssign());
ASSERT_TRUE(e->Is<ast::AssignmentStatement>());
ASSERT_NE(e->lhs(), nullptr);
ASSERT_NE(e->rhs(), nullptr);
@@ -61,7 +61,7 @@ TEST_F(ParserImplTest, AssignmentStmt_Parses_ToMember) {
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsAssign());
ASSERT_TRUE(e->Is<ast::AssignmentStatement>());
ASSERT_NE(e->lhs(), nullptr);
ASSERT_NE(e->rhs(), nullptr);

View File

@@ -13,6 +13,7 @@
// limitations under the License.
#include "gtest/gtest.h"
#include "src/ast/discard_statement.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -30,8 +31,8 @@ TEST_F(ParserImplTest, BodyStmt) {
ASSERT_FALSE(p->has_error()) << p->error();
ASSERT_FALSE(e.errored);
ASSERT_EQ(e->size(), 2u);
EXPECT_TRUE(e->get(0)->IsDiscard());
EXPECT_TRUE(e->get(1)->IsReturn());
EXPECT_TRUE(e->get(0)->Is<ast::DiscardStatement>());
EXPECT_TRUE(e->get(1)->Is<ast::ReturnStatement>());
}
TEST_F(ParserImplTest, BodyStmt_Empty) {

View File

@@ -28,7 +28,7 @@ TEST_F(ParserImplTest, BreakStmt) {
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsBreak());
ASSERT_TRUE(e->Is<ast::BreakStatement>());
}
} // namespace

View File

@@ -32,8 +32,8 @@ TEST_F(ParserImplTest, Statement_Call) {
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsCall());
auto* c = e->AsCall()->expr();
ASSERT_TRUE(e->Is<ast::CallStatement>());
auto* c = e->As<ast::CallStatement>()->expr();
ASSERT_TRUE(c->func()->IsIdentifier());
auto* func = c->func()->AsIdentifier();
@@ -50,8 +50,8 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) {
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsCall());
auto* c = e->AsCall()->expr();
ASSERT_TRUE(e->Is<ast::CallStatement>());
auto* c = e->As<ast::CallStatement>()->expr();
ASSERT_TRUE(c->func()->IsIdentifier());
auto* func = c->func()->AsIdentifier();

View File

@@ -13,6 +13,7 @@
// limitations under the License.
#include "gtest/gtest.h"
#include "src/ast/fallthrough_statement.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -40,8 +41,8 @@ TEST_F(ParserImplTest, CaseBody_Statements) {
EXPECT_FALSE(e.errored);
EXPECT_TRUE(e.matched);
ASSERT_EQ(e->size(), 2u);
EXPECT_TRUE(e->get(0)->IsVariableDecl());
EXPECT_TRUE(e->get(1)->IsAssign());
EXPECT_TRUE(e->get(0)->Is<ast::VariableDeclStatement>());
EXPECT_TRUE(e->get(1)->Is<ast::AssignmentStatement>());
}
TEST_F(ParserImplTest, CaseBody_InvalidStatement) {
@@ -60,7 +61,7 @@ TEST_F(ParserImplTest, CaseBody_Fallthrough) {
EXPECT_FALSE(e.errored);
EXPECT_TRUE(e.matched);
ASSERT_EQ(e->size(), 1u);
EXPECT_TRUE(e->get(0)->IsFallthrough());
EXPECT_TRUE(e->get(0)->Is<ast::FallthroughStatement>());
}
TEST_F(ParserImplTest, CaseBody_Fallthrough_MissingSemicolon) {

View File

@@ -28,7 +28,7 @@ TEST_F(ParserImplTest, ContinueStmt) {
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsContinue());
ASSERT_TRUE(e->Is<ast::ContinueStatement>());
}
} // namespace

View File

@@ -13,6 +13,7 @@
// limitations under the License.
#include "gtest/gtest.h"
#include "src/ast/discard_statement.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -28,7 +29,7 @@ TEST_F(ParserImplTest, ContinuingStmt) {
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_EQ(e->size(), 1u);
ASSERT_TRUE(e->get(0)->IsDiscard());
ASSERT_TRUE(e->get(0)->Is<ast::DiscardStatement>());
}
TEST_F(ParserImplTest, ContinuingStmt_InvalidBody) {

View File

@@ -29,7 +29,7 @@ TEST_F(ParserImplTest, ElseStmt) {
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsElse());
ASSERT_TRUE(e->Is<ast::ElseStatement>());
ASSERT_EQ(e->condition(), nullptr);
EXPECT_EQ(e->body()->size(), 2u);
}

View File

@@ -30,7 +30,7 @@ TEST_F(ParserImplTest, ElseIfStmt) {
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_EQ(e.value.size(), 1u);
ASSERT_TRUE(e.value[0]->IsElse());
ASSERT_TRUE(e.value[0]->Is<ast::ElseStatement>());
ASSERT_NE(e.value[0]->condition(), nullptr);
ASSERT_TRUE(e.value[0]->condition()->IsBinary());
EXPECT_EQ(e.value[0]->body()->size(), 2u);
@@ -44,12 +44,12 @@ TEST_F(ParserImplTest, ElseIfStmt_Multiple) {
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_EQ(e.value.size(), 2u);
ASSERT_TRUE(e.value[0]->IsElse());
ASSERT_TRUE(e.value[0]->Is<ast::ElseStatement>());
ASSERT_NE(e.value[0]->condition(), nullptr);
ASSERT_TRUE(e.value[0]->condition()->IsBinary());
EXPECT_EQ(e.value[0]->body()->size(), 2u);
ASSERT_TRUE(e.value[1]->IsElse());
ASSERT_TRUE(e.value[1]->Is<ast::ElseStatement>());
ASSERT_NE(e.value[1]->condition(), nullptr);
ASSERT_TRUE(e.value[1]->condition()->IsIdentifier());
EXPECT_EQ(e.value[1]->body()->size(), 1u);

View File

@@ -50,7 +50,7 @@ TEST_F(ParserImplTest, FunctionDecl) {
auto* body = f->body();
ASSERT_EQ(body->size(), 1u);
EXPECT_TRUE(body->get(0)->IsReturn());
EXPECT_TRUE(body->get(0)->Is<ast::ReturnStatement>());
}
TEST_F(ParserImplTest, FunctionDecl_DecorationList) {
@@ -86,7 +86,7 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) {
auto* body = f->body();
ASSERT_EQ(body->size(), 1u);
EXPECT_TRUE(body->get(0)->IsReturn());
EXPECT_TRUE(body->get(0)->Is<ast::ReturnStatement>());
}
TEST_F(ParserImplTest, FunctionDecl_DecorationList_MultipleEntries) {
@@ -130,7 +130,7 @@ fn main() -> void { return; })");
auto* body = f->body();
ASSERT_EQ(body->size(), 1u);
EXPECT_TRUE(body->get(0)->IsReturn());
EXPECT_TRUE(body->get(0)->Is<ast::ReturnStatement>());
}
TEST_F(ParserImplTest, FunctionDecl_DecorationList_MultipleLists) {
@@ -175,7 +175,7 @@ fn main() -> void { return; })");
auto* body = f->body();
ASSERT_EQ(body->size(), 1u);
EXPECT_TRUE(body->get(0)->IsReturn());
EXPECT_TRUE(body->get(0)->Is<ast::ReturnStatement>());
}
TEST_F(ParserImplTest, FunctionDecl_InvalidHeader) {

View File

@@ -31,7 +31,7 @@ TEST_F(ParserImplTest, IfStmt) {
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsIf());
ASSERT_TRUE(e->Is<ast::IfStatement>());
ASSERT_NE(e->condition(), nullptr);
ASSERT_TRUE(e->condition()->IsBinary());
EXPECT_EQ(e->body()->size(), 2u);
@@ -46,7 +46,7 @@ TEST_F(ParserImplTest, IfStmt_WithElse) {
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsIf());
ASSERT_TRUE(e->Is<ast::IfStatement>());
ASSERT_NE(e->condition(), nullptr);
ASSERT_TRUE(e->condition()->IsBinary());
EXPECT_EQ(e->body()->size(), 2u);

View File

@@ -13,6 +13,7 @@
// limitations under the License.
#include "gtest/gtest.h"
#include "src/ast/discard_statement.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -30,7 +31,7 @@ TEST_F(ParserImplTest, LoopStmt_BodyNoContinuing) {
ASSERT_NE(e.value, nullptr);
ASSERT_EQ(e->body()->size(), 1u);
EXPECT_TRUE(e->body()->get(0)->IsDiscard());
EXPECT_TRUE(e->body()->get(0)->Is<ast::DiscardStatement>());
EXPECT_EQ(e->continuing()->size(), 0u);
}
@@ -44,10 +45,10 @@ TEST_F(ParserImplTest, LoopStmt_BodyWithContinuing) {
ASSERT_NE(e.value, nullptr);
ASSERT_EQ(e->body()->size(), 1u);
EXPECT_TRUE(e->body()->get(0)->IsDiscard());
EXPECT_TRUE(e->body()->get(0)->Is<ast::DiscardStatement>());
EXPECT_EQ(e->continuing()->size(), 1u);
EXPECT_TRUE(e->continuing()->get(0)->IsDiscard());
EXPECT_TRUE(e->continuing()->get(0)->Is<ast::DiscardStatement>());
}
TEST_F(ParserImplTest, LoopStmt_NoBodyNoContinuing) {
@@ -70,7 +71,7 @@ TEST_F(ParserImplTest, LoopStmt_NoBodyWithContinuing) {
ASSERT_NE(e.value, nullptr);
ASSERT_EQ(e->body()->size(), 0u);
ASSERT_EQ(e->continuing()->size(), 1u);
EXPECT_TRUE(e->continuing()->get(0)->IsDiscard());
EXPECT_TRUE(e->continuing()->get(0)->Is<ast::DiscardStatement>());
}
TEST_F(ParserImplTest, LoopStmt_MissingBracketLeft) {

View File

@@ -13,6 +13,7 @@
// limitations under the License.
#include "gtest/gtest.h"
#include "src/ast/discard_statement.h"
#include "src/ast/return_statement.h"
#include "src/ast/statement.h"
#include "src/reader/wgsl/parser_impl.h"
@@ -29,7 +30,7 @@ TEST_F(ParserImplTest, Statement) {
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsReturn());
ASSERT_TRUE(e->Is<ast::ReturnStatement>());
}
TEST_F(ParserImplTest, Statement_Semicolon) {
@@ -44,8 +45,8 @@ TEST_F(ParserImplTest, Statement_Return_NoValue) {
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsReturn());
auto* ret = e->AsReturn();
ASSERT_TRUE(e->Is<ast::ReturnStatement>());
auto* ret = e->As<ast::ReturnStatement>();
ASSERT_EQ(ret->value(), nullptr);
}
@@ -56,8 +57,8 @@ TEST_F(ParserImplTest, Statement_Return_Value) {
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsReturn());
auto* ret = e->AsReturn();
ASSERT_TRUE(e->Is<ast::ReturnStatement>());
auto* ret = e->As<ast::ReturnStatement>();
ASSERT_NE(ret->value(), nullptr);
EXPECT_TRUE(ret->value()->IsBinary());
}
@@ -88,7 +89,7 @@ TEST_F(ParserImplTest, Statement_If) {
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsIf());
ASSERT_TRUE(e->Is<ast::IfStatement>());
}
TEST_F(ParserImplTest, Statement_If_Invalid) {
@@ -107,7 +108,7 @@ TEST_F(ParserImplTest, Statement_Variable) {
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsVariableDecl());
ASSERT_TRUE(e->Is<ast::VariableDeclStatement>());
}
TEST_F(ParserImplTest, Statement_Variable_Invalid) {
@@ -136,7 +137,7 @@ TEST_F(ParserImplTest, Statement_Switch) {
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsSwitch());
ASSERT_TRUE(e->Is<ast::SwitchStatement>());
}
TEST_F(ParserImplTest, Statement_Switch_Invalid) {
@@ -155,7 +156,7 @@ TEST_F(ParserImplTest, Statement_Loop) {
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsLoop());
ASSERT_TRUE(e->Is<ast::LoopStatement>());
}
TEST_F(ParserImplTest, Statement_Loop_Invalid) {
@@ -174,7 +175,7 @@ TEST_F(ParserImplTest, Statement_Assignment) {
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsAssign());
ASSERT_TRUE(e->Is<ast::AssignmentStatement>());
}
TEST_F(ParserImplTest, Statement_Assignment_Invalid) {
@@ -203,7 +204,7 @@ TEST_F(ParserImplTest, Statement_Break) {
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsBreak());
ASSERT_TRUE(e->Is<ast::BreakStatement>());
}
TEST_F(ParserImplTest, Statement_Break_MissingSemicolon) {
@@ -222,7 +223,7 @@ TEST_F(ParserImplTest, Statement_Continue) {
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsContinue());
ASSERT_TRUE(e->Is<ast::ContinueStatement>());
}
TEST_F(ParserImplTest, Statement_Continue_MissingSemicolon) {
@@ -242,7 +243,7 @@ TEST_F(ParserImplTest, Statement_Discard) {
ASSERT_NE(e.value, nullptr);
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsDiscard());
ASSERT_TRUE(e->Is<ast::DiscardStatement>());
}
TEST_F(ParserImplTest, Statement_Discard_MissingSemicolon) {
@@ -261,8 +262,9 @@ TEST_F(ParserImplTest, Statement_Body) {
ASSERT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_TRUE(e->IsBlock());
EXPECT_TRUE(e->AsBlock()->get(0)->IsVariableDecl());
ASSERT_TRUE(e->Is<ast::BlockStatement>());
EXPECT_TRUE(
e->As<ast::BlockStatement>()->get(0)->Is<ast::VariableDeclStatement>());
}
TEST_F(ParserImplTest, Statement_Body_Invalid) {

View File

@@ -13,6 +13,7 @@
// limitations under the License.
#include "gtest/gtest.h"
#include "src/ast/discard_statement.h"
#include "src/ast/statement.h"
#include "src/reader/wgsl/parser_impl.h"
#include "src/reader/wgsl/parser_impl_test_helper.h"
@@ -28,8 +29,8 @@ TEST_F(ParserImplTest, Statements) {
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_EQ(e->size(), 2u);
EXPECT_TRUE(e->get(0)->IsDiscard());
EXPECT_TRUE(e->get(1)->IsReturn());
EXPECT_TRUE(e->get(0)->Is<ast::DiscardStatement>());
EXPECT_TRUE(e->get(1)->Is<ast::ReturnStatement>());
}
TEST_F(ParserImplTest, Statements_Empty) {

View File

@@ -29,10 +29,10 @@ TEST_F(ParserImplTest, SwitchBody_Case) {
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsCase());
ASSERT_TRUE(e->Is<ast::CaseStatement>());
EXPECT_FALSE(e->IsDefault());
ASSERT_EQ(e->body()->size(), 1u);
EXPECT_TRUE(e->body()->get(0)->IsAssign());
EXPECT_TRUE(e->body()->get(0)->Is<ast::AssignmentStatement>());
}
TEST_F(ParserImplTest, SwitchBody_Case_InvalidConstLiteral) {
@@ -112,10 +112,10 @@ TEST_F(ParserImplTest, SwitchBody_Default) {
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsCase());
ASSERT_TRUE(e->Is<ast::CaseStatement>());
EXPECT_TRUE(e->IsDefault());
ASSERT_EQ(e->body()->size(), 1u);
EXPECT_TRUE(e->body()->get(0)->IsAssign());
EXPECT_TRUE(e->body()->get(0)->Is<ast::AssignmentStatement>());
}
TEST_F(ParserImplTest, SwitchBody_Default_MissingColon) {

View File

@@ -33,7 +33,7 @@ TEST_F(ParserImplTest, SwitchStmt_WithoutDefault) {
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsSwitch());
ASSERT_TRUE(e->Is<ast::SwitchStatement>());
ASSERT_EQ(e->body().size(), 2u);
EXPECT_FALSE(e->body()[0]->IsDefault());
EXPECT_FALSE(e->body()[1]->IsDefault());
@@ -46,7 +46,7 @@ TEST_F(ParserImplTest, SwitchStmt_Empty) {
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsSwitch());
ASSERT_TRUE(e->Is<ast::SwitchStatement>());
ASSERT_EQ(e->body().size(), 0u);
}
@@ -61,7 +61,7 @@ TEST_F(ParserImplTest, SwitchStmt_DefaultInMiddle) {
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsSwitch());
ASSERT_TRUE(e->Is<ast::SwitchStatement>());
ASSERT_EQ(e->body().size(), 3u);
ASSERT_FALSE(e->body()[0]->IsDefault());

View File

@@ -30,7 +30,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl) {
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsVariableDecl());
ASSERT_TRUE(e->Is<ast::VariableDeclStatement>());
ASSERT_NE(e->variable(), nullptr);
EXPECT_EQ(e->variable()->name(), "a");
@@ -49,7 +49,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) {
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsVariableDecl());
ASSERT_TRUE(e->Is<ast::VariableDeclStatement>());
ASSERT_NE(e->variable(), nullptr);
EXPECT_EQ(e->variable()->name(), "a");
@@ -89,7 +89,7 @@ TEST_F(ParserImplTest, VariableStmt_Const) {
EXPECT_FALSE(e.errored);
EXPECT_FALSE(p->has_error()) << p->error();
ASSERT_NE(e.value, nullptr);
ASSERT_TRUE(e->IsVariableDecl());
ASSERT_TRUE(e->Is<ast::VariableDeclStatement>());
ASSERT_EQ(e->source().range.begin.line, 1u);
ASSERT_EQ(e->source().range.begin.column, 7u);