wsgl parser: Remove pointless nullptr checks
The `expect_` prefixes now clearly indicate when a method will internally error, or produce a valid AST object. Verified by code coverage. Bug: tint:282 Change-Id: Icbdae9db02bd48c69aec010a4f8fdc5a496125f8 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32002 Reviewed-by: dan sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
7b750dc733
commit
cd477e6b7b
|
@ -306,11 +306,6 @@ std::unique_ptr<ast::Variable> ParserImpl::global_variable_decl(
|
||||||
auto expr = expect_const_expr();
|
auto expr = expect_const_expr();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (expr == nullptr) {
|
|
||||||
add_error(peek(), "invalid expression");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
var->set_constructor(std::move(expr));
|
var->set_constructor(std::move(expr));
|
||||||
}
|
}
|
||||||
return var;
|
return var;
|
||||||
|
@ -343,10 +338,6 @@ std::unique_ptr<ast::Variable> ParserImpl::global_constant_decl() {
|
||||||
auto init = expect_const_expr();
|
auto init = expect_const_expr();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (init == nullptr) {
|
|
||||||
add_error(peek(), "error parsing scalar constructor");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
var->set_constructor(std::move(init));
|
var->set_constructor(std::move(init));
|
||||||
|
|
||||||
return var;
|
return var;
|
||||||
|
@ -1163,10 +1154,6 @@ ast::StructMemberList ParserImpl::expect_struct_body_decl() {
|
||||||
auto mem = expect_struct_member(decos);
|
auto mem = expect_struct_member(decos);
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return ast::StructMemberList{};
|
return ast::StructMemberList{};
|
||||||
if (mem == nullptr) {
|
|
||||||
add_error(peek(), "invalid struct member");
|
|
||||||
return ast::StructMemberList{};
|
|
||||||
}
|
|
||||||
|
|
||||||
members.push_back(std::move(mem));
|
members.push_back(std::move(mem));
|
||||||
}
|
}
|
||||||
|
@ -1593,10 +1580,6 @@ std::unique_ptr<ast::IfStatement> ParserImpl::if_stmt() {
|
||||||
auto condition = expect_paren_rhs_stmt();
|
auto condition = expect_paren_rhs_stmt();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (condition == nullptr) {
|
|
||||||
add_error(peek(), "unable to parse if condition");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto body = expect_body_stmt();
|
auto body = expect_body_stmt();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
|
@ -1635,10 +1618,6 @@ ast::ElseStatementList ParserImpl::elseif_stmt() {
|
||||||
auto condition = expect_paren_rhs_stmt();
|
auto condition = expect_paren_rhs_stmt();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return {};
|
return {};
|
||||||
if (condition == nullptr) {
|
|
||||||
add_error(peek(), "unable to parse condition expression");
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto body = expect_body_stmt();
|
auto body = expect_body_stmt();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
|
@ -1682,10 +1661,6 @@ std::unique_ptr<ast::SwitchStatement> ParserImpl::switch_stmt() {
|
||||||
auto condition = expect_paren_rhs_stmt();
|
auto condition = expect_paren_rhs_stmt();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (condition == nullptr) {
|
|
||||||
add_error(peek(), "unable to parse switch expression");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ast::CaseStatementList body;
|
ast::CaseStatementList body;
|
||||||
bool ok = expect_brace_block("switch statement", [&] {
|
bool ok = expect_brace_block("switch statement", [&] {
|
||||||
|
@ -2063,10 +2038,6 @@ std::unique_ptr<ast::Expression> ParserImpl::primary_expression() {
|
||||||
auto params = expect_paren_rhs_stmt();
|
auto params = expect_paren_rhs_stmt();
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
if (params == nullptr) {
|
|
||||||
add_error(peek(), "unable to parse parameters");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::make_unique<ast::BitcastExpression>(source, type,
|
return std::make_unique<ast::BitcastExpression>(source, type,
|
||||||
std::move(params));
|
std::move(params));
|
||||||
|
@ -2749,19 +2720,11 @@ ParserImpl::expect_const_expr_internal(uint32_t depth) {
|
||||||
auto param = expect_const_expr_internal(depth + 1);
|
auto param = expect_const_expr_internal(depth + 1);
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return false;
|
return false;
|
||||||
if (param == nullptr) {
|
|
||||||
add_error(peek(), "unable to parse constant expression");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
params.push_back(std::move(param));
|
params.push_back(std::move(param));
|
||||||
while (match(Token::Type::kComma)) {
|
while (match(Token::Type::kComma)) {
|
||||||
param = expect_const_expr_internal(depth + 1);
|
param = expect_const_expr_internal(depth + 1);
|
||||||
if (has_error())
|
if (has_error())
|
||||||
return false;
|
return false;
|
||||||
if (param == nullptr) {
|
|
||||||
add_error(peek(), "unable to parse constant expression");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
params.push_back(std::move(param));
|
params.push_back(std::move(param));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -2810,10 +2773,6 @@ bool ParserImpl::decoration_bracketed_list(ast::DecorationList& decos) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_error()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match(Token::Type::kComma)) {
|
if (match(Token::Type::kComma)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue