Commit 6627bdb1 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Use has_error rather than has_parser_error and inline.

Bug: v8:7926
Change-Id: Icbdd05b799afd26a8eaaa67905516d82f4b1d2bd
Reviewed-on: https://chromium-review.googlesource.com/c/1309815
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57168}
parent ed2dd240
...@@ -98,7 +98,7 @@ class SourceRangeScope final { ...@@ -98,7 +98,7 @@ class SourceRangeScope final {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// The RETURN_IF_PARSE_ERROR macro is a convenient macro to enforce error // The RETURN_IF_PARSE_ERROR macro is a convenient macro to enforce error
// handling for functions that may fail (by returning if there was an parser // handling for functions that may fail (by returning if there was an parser
// error scanner()->has_parser_error()). // error).
// //
// Usage: // Usage:
// foo = ParseFoo(); // may fail // foo = ParseFoo(); // may fail
...@@ -274,7 +274,7 @@ class ParserBase { ...@@ -274,7 +274,7 @@ class ParserBase {
#undef ALLOW_ACCESSORS #undef ALLOW_ACCESSORS
bool has_error() const { return scanner()->has_parser_error(); } V8_INLINE bool has_error() const { return scanner()->has_parser_error(); }
bool allow_harmony_numeric_separator() const { bool allow_harmony_numeric_separator() const {
return scanner()->allow_harmony_numeric_separator(); return scanner()->allow_harmony_numeric_separator();
} }
......
...@@ -139,7 +139,7 @@ void Parser::GetUnexpectedTokenMessage(Token::Value token, ...@@ -139,7 +139,7 @@ void Parser::GetUnexpectedTokenMessage(Token::Value token,
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// The RETURN_IF_PARSE_ERROR macro is a convenient macro to enforce error // The RETURN_IF_PARSE_ERROR macro is a convenient macro to enforce error
// handling for functions that may fail (by returning if there was an parser // handling for functions that may fail (by returning if there was an parser
// error scanner()->has_parser_error()). // error).
// //
// Usage: // Usage:
// foo = ParseFoo(); // may fail // foo = ParseFoo(); // may fail
...@@ -148,13 +148,11 @@ void Parser::GetUnexpectedTokenMessage(Token::Value token, ...@@ -148,13 +148,11 @@ void Parser::GetUnexpectedTokenMessage(Token::Value token,
// SAFE_USE(foo); // SAFE_USE(foo);
#define RETURN_IF_PARSE_ERROR_VALUE(x) \ #define RETURN_IF_PARSE_ERROR_VALUE(x) \
if (scanner()->has_parser_error()) { \ if (has_error()) return x;
return x; \
}
#define RETURN_IF_PARSE_ERROR RETURN_IF_PARSE_ERROR_VALUE(nullptr) #define RETURN_IF_PARSE_ERROR RETURN_IF_PARSE_ERROR_VALUE(nullptr)
#define RETURN_IF_PARSE_ERROR_VOID \ #define RETURN_IF_PARSE_ERROR_VOID \
if (scanner()->has_parser_error()) return; if (has_error()) return;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Implementation of Parser // Implementation of Parser
...@@ -590,9 +588,8 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) { ...@@ -590,9 +588,8 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
zone()); zone());
ParseModuleItemList(body); ParseModuleItemList(body);
ok = !scanner_.has_parser_error() && ok = !has_error() && module()->Validate(this->scope()->AsModuleScope(),
module()->Validate(this->scope()->AsModuleScope(), pending_error_handler(), zone());
pending_error_handler(), zone());
} else if (info->is_wrapped_as_function()) { } else if (info->is_wrapped_as_function()) {
ParseWrapped(isolate, info, body, scope, zone(), &ok); ParseWrapped(isolate, info, body, scope, zone(), &ok);
} else { } else {
...@@ -601,7 +598,7 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) { ...@@ -601,7 +598,7 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
this->scope()->SetLanguageMode(info->language_mode()); this->scope()->SetLanguageMode(info->language_mode());
ParseStatementList(body, Token::EOS); ParseStatementList(body, Token::EOS);
} }
ok = ok && !scanner_.has_parser_error(); ok = ok && !has_error();
// The parser will peek but not consume EOS. Our scope logically goes all // The parser will peek but not consume EOS. Our scope logically goes all
// the way to the EOS, though. // the way to the EOS, though.
...@@ -609,7 +606,7 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) { ...@@ -609,7 +606,7 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
if (ok && is_strict(language_mode())) { if (ok && is_strict(language_mode())) {
CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos); CheckStrictOctalLiteral(beg_pos, scanner()->location().end_pos);
ok = !scanner_.has_parser_error(); ok = !has_error();
} }
if (ok && is_sloppy(language_mode())) { if (ok && is_sloppy(language_mode())) {
// TODO(littledan): Function bindings on the global object that modify // TODO(littledan): Function bindings on the global object that modify
...@@ -620,7 +617,7 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) { ...@@ -620,7 +617,7 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
} }
if (ok) { if (ok) {
CheckConflictingVarDeclarations(scope); CheckConflictingVarDeclarations(scope);
ok = !scanner_.has_parser_error(); ok = !has_error();
} }
if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
...@@ -816,12 +813,12 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info, ...@@ -816,12 +813,12 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
if (Check(Token::LPAREN)) { if (Check(Token::LPAREN)) {
// '(' StrictFormalParameters ')' // '(' StrictFormalParameters ')'
ParseFormalParameterList(&formals); ParseFormalParameterList(&formals);
ok = !scanner_.has_parser_error(); ok = !has_error();
if (ok) ok = Check(Token::RPAREN); if (ok) ok = Check(Token::RPAREN);
} else { } else {
// BindingIdentifier // BindingIdentifier
ParseFormalParameter(&formals); ParseFormalParameter(&formals);
ok = !scanner_.has_parser_error(); ok = !has_error();
if (ok) { if (ok) {
DeclareFormalParameters(&formals); DeclareFormalParameters(&formals);
} }
...@@ -854,7 +851,7 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info, ...@@ -854,7 +851,7 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
const int rewritable_length = 0; const int rewritable_length = 0;
Expression* expression = Expression* expression =
ParseArrowFunctionLiteral(accept_IN, formals, rewritable_length); ParseArrowFunctionLiteral(accept_IN, formals, rewritable_length);
ok = !scanner_.has_parser_error(); ok = !has_error();
if (ok) { if (ok) {
// Scanning must end at the same position that was recorded // Scanning must end at the same position that was recorded
// previously. If not, parsing has been interrupted due to a stack // previously. If not, parsing has been interrupted due to a stack
...@@ -885,10 +882,10 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info, ...@@ -885,10 +882,10 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind, raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind,
kNoSourcePosition, function_type, info->language_mode(), kNoSourcePosition, function_type, info->language_mode(),
arguments_for_wrapped_function); arguments_for_wrapped_function);
ok = !scanner_.has_parser_error(); ok = !has_error();
} }
DCHECK_EQ(ok, !scanner_.has_parser_error()); DCHECK_EQ(ok, !has_error());
if (ok) { if (ok) {
result->set_requires_instance_fields_initializer( result->set_requires_instance_fields_initializer(
info->requires_instance_fields_initializer()); info->requires_instance_fields_initializer());
...@@ -1735,7 +1732,7 @@ void Parser::ParseAndRewriteGeneratorFunctionBody( ...@@ -1735,7 +1732,7 @@ void Parser::ParseAndRewriteGeneratorFunctionBody(
Expression* initial_yield = BuildInitialYield(pos, kind); Expression* initial_yield = BuildInitialYield(pos, kind);
body->Add(factory()->NewExpressionStatement(initial_yield, kNoSourcePosition), body->Add(factory()->NewExpressionStatement(initial_yield, kNoSourcePosition),
zone()); zone());
ParseStatementList(body, Token::RBRACE, !scanner()->has_parser_error()); ParseStatementList(body, Token::RBRACE, !has_error());
} }
void Parser::ParseAndRewriteAsyncGeneratorFunctionBody( void Parser::ParseAndRewriteAsyncGeneratorFunctionBody(
...@@ -1767,8 +1764,7 @@ void Parser::ParseAndRewriteAsyncGeneratorFunctionBody( ...@@ -1767,8 +1764,7 @@ void Parser::ParseAndRewriteAsyncGeneratorFunctionBody(
try_block->statements()->Add( try_block->statements()->Add(
factory()->NewExpressionStatement(initial_yield, kNoSourcePosition), factory()->NewExpressionStatement(initial_yield, kNoSourcePosition),
zone()); zone());
ParseStatementList(try_block->statements(), Token::RBRACE, ParseStatementList(try_block->statements(), Token::RBRACE, !has_error());
!scanner()->has_parser_error());
// Don't create iterator result for async generators, as the resume methods // Don't create iterator result for async generators, as the resume methods
// will create it. // will create it.
...@@ -2780,7 +2776,7 @@ bool Parser::SkipFunction( ...@@ -2780,7 +2776,7 @@ bool Parser::SkipFunction(
return false; return false;
} else if (pending_error_handler()->has_pending_error()) { } else if (pending_error_handler()->has_pending_error()) {
DCHECK(!pending_error_handler()->stack_overflow()); DCHECK(!pending_error_handler()->stack_overflow());
DCHECK(scanner()->has_parser_error()); DCHECK(has_error());
} else { } else {
DCHECK(!pending_error_handler()->stack_overflow()); DCHECK(!pending_error_handler()->stack_overflow());
set_allow_eval_cache(reusable_preparser()->allow_eval_cache()); set_allow_eval_cache(reusable_preparser()->allow_eval_cache());
......
...@@ -237,7 +237,7 @@ void PatternRewriter::VisitVariableProxy(VariableProxy* pattern) { ...@@ -237,7 +237,7 @@ void PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
declaration, descriptor_->declaration_kind, descriptor_->mode, declaration, descriptor_->declaration_kind, descriptor_->mode,
Variable::DefaultInitializationFlag(descriptor_->mode), Variable::DefaultInitializationFlag(descriptor_->mode),
outer_function_scope); outer_function_scope);
if (parser_->scanner_.has_parser_error()) return; if (parser_->has_error()) return;
DCHECK_NOT_NULL(var); DCHECK_NOT_NULL(var);
DCHECK(proxy->is_resolved()); DCHECK(proxy->is_resolved());
DCHECK_NE(initializer_position_, kNoSourcePosition); DCHECK_NE(initializer_position_, kNoSourcePosition);
......
...@@ -85,7 +85,7 @@ PreParser::PreParseResult PreParser::PreParseProgram() { ...@@ -85,7 +85,7 @@ PreParser::PreParseResult PreParser::PreParseProgram() {
int start_position = scanner()->peek_location().beg_pos; int start_position = scanner()->peek_location().beg_pos;
PreParserStatementList body; PreParserStatementList body;
ParseStatementList(body, Token::EOS); ParseStatementList(body, Token::EOS);
ok = !scanner()->has_parser_error(); ok = !has_error();
original_scope_ = nullptr; original_scope_ = nullptr;
if (stack_overflow()) return kPreParseStackOverflow; if (stack_overflow()) return kPreParseStackOverflow;
if (!ok) { if (!ok) {
...@@ -190,7 +190,7 @@ PreParser::PreParseResult PreParser::PreParseFunction( ...@@ -190,7 +190,7 @@ PreParser::PreParseResult PreParser::PreParseFunction(
return kPreParseStackOverflow; return kPreParseStackOverflow;
} else if (pending_error_handler()->has_error_unidentifiable_by_preparser()) { } else if (pending_error_handler()->has_error_unidentifiable_by_preparser()) {
return kPreParseNotIdentifiableError; return kPreParseNotIdentifiableError;
} else if (scanner()->has_parser_error()) { } else if (has_error()) {
DCHECK(pending_error_handler()->has_pending_error()); DCHECK(pending_error_handler()->has_pending_error());
} else if (result == kLazyParsingAborted) { } else if (result == kLazyParsingAborted) {
DCHECK(!pending_error_handler()->has_error_unidentifiable_by_preparser()); DCHECK(!pending_error_handler()->has_error_unidentifiable_by_preparser());
...@@ -203,7 +203,7 @@ PreParser::PreParseResult PreParser::PreParseFunction( ...@@ -203,7 +203,7 @@ PreParser::PreParseResult PreParser::PreParseFunction(
// Validate parameter names. We can do this only after parsing the // Validate parameter names. We can do this only after parsing the
// function, since the function can declare itself strict. // function, since the function can declare itself strict.
ValidateFormalParameters(language_mode(), allow_duplicate_parameters); ValidateFormalParameters(language_mode(), allow_duplicate_parameters);
if (scanner()->has_parser_error()) { if (has_error()) {
if (pending_error_handler()->has_error_unidentifiable_by_preparser()) { if (pending_error_handler()->has_error_unidentifiable_by_preparser()) {
return kPreParseNotIdentifiableError; return kPreParseNotIdentifiableError;
} else { } else {
......
...@@ -239,7 +239,7 @@ class Scanner { ...@@ -239,7 +239,7 @@ class Scanner {
// Sets the Scanner into an error state to stop further scanning and terminate // Sets the Scanner into an error state to stop further scanning and terminate
// the parsing by only returning ILLEGAL tokens after that. // the parsing by only returning ILLEGAL tokens after that.
V8_INLINE void set_parser_error() { V8_INLINE void set_parser_error() {
if (!source_->has_parser_error()) { if (!has_parser_error()) {
c0_ = kEndOfInput; c0_ = kEndOfInput;
source_->set_parser_error(); source_->set_parser_error();
for (TokenDesc& desc : token_storage_) { for (TokenDesc& desc : token_storage_) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment