Commit 339bb225 authored by Florian Sattler's avatar Florian Sattler Committed by Commit Bot

[parser] Remove explicit ok status tracking.

Replace the explicit ok tracing by setting the scanner to fail, allowing us to
return automatically. RETURN_IF_PARSE_ERROR is now used instead of CHECK_OK to
verify if the parser failed.

In a follow-up CL we'll merge RETURN_IF_PARSE_ERROR after Expect* into an
EXPECT* macro. We'll keep (for now) RETURN_IF_PARSE_ERROR that guard uses of
possible NullExpression (e.g., impl()->IsIdentifier(...)). All other RETURN_IF*
will be removed. Uses after failure can likely later be fixed too by introducing
a FailureExpression.

Bug: v8:8363 ,v8:7926

Change-Id: I9896449eb9be476c453da4417a0bfd17c169ff38
Reviewed-on: https://chromium-review.googlesource.com/c/1294649
Commit-Queue: Florian Sattler <sattlerf@google.com>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56972}
parent 9929a238
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
......@@ -29,7 +29,7 @@ class PatternRewriter final : public AstVisitor<PatternRewriter> {
Parser* parser, Block* block,
const DeclarationDescriptor* declaration_descriptor,
const Parser::DeclarationParsingResult::Declaration* declaration,
ZonePtrList<const AstRawString>* names, bool* ok);
ZonePtrList<const AstRawString>* names);
static Expression* RewriteDestructuringAssignment(Parser* parser,
Assignment* to_rewrite,
......@@ -50,7 +50,6 @@ class PatternRewriter final : public AstVisitor<PatternRewriter> {
descriptor_(descriptor),
names_(names),
current_value_(nullptr),
ok_(nullptr),
initializer_position_(initializer_position),
value_beg_position_(value_beg_position),
context_(context),
......@@ -122,7 +121,6 @@ class PatternRewriter final : public AstVisitor<PatternRewriter> {
const DeclarationDescriptor* descriptor_;
ZonePtrList<const AstRawString>* names_;
Expression* current_value_;
bool* ok_;
const int initializer_position_;
const int value_beg_position_;
PatternContext context_;
......@@ -135,9 +133,9 @@ class PatternRewriter final : public AstVisitor<PatternRewriter> {
void Parser::DeclareAndInitializeVariables(
Block* block, const DeclarationDescriptor* declaration_descriptor,
const DeclarationParsingResult::Declaration* declaration,
ZonePtrList<const AstRawString>* names, bool* ok) {
ZonePtrList<const AstRawString>* names) {
PatternRewriter::DeclareAndInitializeVariables(
this, block, declaration_descriptor, declaration, names, ok);
this, block, declaration_descriptor, declaration, names);
}
void Parser::RewriteDestructuringAssignment(RewritableExpression* to_rewrite) {
......@@ -159,7 +157,7 @@ void PatternRewriter::DeclareAndInitializeVariables(
Parser* parser, Block* block,
const DeclarationDescriptor* declaration_descriptor,
const Parser::DeclarationParsingResult::Declaration* declaration,
ZonePtrList<const AstRawString>* names, bool* ok) {
ZonePtrList<const AstRawString>* names) {
DCHECK(block->ignore_completion_value());
Scope* scope = declaration_descriptor->scope;
......@@ -170,7 +168,6 @@ void PatternRewriter::DeclareAndInitializeVariables(
DeclarationDescriptor::PARAMETER &&
scope->is_block_scope());
rewriter.block_ = block;
rewriter.ok_ = ok;
rewriter.RecurseIntoSubpattern(declaration->pattern,
declaration->initializer);
......@@ -199,7 +196,6 @@ void PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
DCHECK_NOT_NULL(block_);
DCHECK_NOT_NULL(descriptor_);
DCHECK_NOT_NULL(ok_);
Scope* outer_function_scope = nullptr;
bool success;
......@@ -239,9 +235,9 @@ void PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
// scope which will be used for the initializer expression.
Variable* var = parser_->Declare(
declaration, descriptor_->declaration_kind, descriptor_->mode,
Variable::DefaultInitializationFlag(descriptor_->mode), ok_,
Variable::DefaultInitializationFlag(descriptor_->mode),
outer_function_scope);
if (!*ok_) return;
if (parser_->scanner_.has_parser_error_set()) return;
DCHECK_NOT_NULL(var);
DCHECK(proxy->is_resolved());
DCHECK_NE(initializer_position_, kNoSourcePosition);
......@@ -254,7 +250,6 @@ void PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
: scope()->GetDeclarationScope());
if (declaration_scope->num_var() > kMaxNumFunctionLocals) {
parser_->ReportMessage(MessageTemplate::kTooManyVariables);
*ok_ = false;
return;
}
if (names_) {
......
This diff is collapsed.
This diff is collapsed.
......@@ -42,12 +42,12 @@ class Utf16CharacterStream {
virtual ~Utf16CharacterStream() = default;
void set_parser_error() {
V8_INLINE void set_parser_error() {
buffer_cursor_ = buffer_end_;
has_parser_error_ = true;
}
void reset_parser_error_flag() { has_parser_error_ = false; }
bool has_parser_error() const { return has_parser_error_; }
V8_INLINE void reset_parser_error_flag() { has_parser_error_ = false; }
V8_INLINE bool has_parser_error() const { return has_parser_error_; }
inline uc32 Peek() {
if (V8_LIKELY(buffer_cursor_ < buffer_end_)) {
......@@ -238,9 +238,13 @@ class Scanner {
// Sets the Scanner into an error state to stop further scanning and terminate
// the parsing by only returning ILLEGAL tokens after that.
void set_parser_error() { source_->set_parser_error(); }
void reset_parser_error_flag() { source_->reset_parser_error_flag(); }
bool has_parser_error_set() { return source_->has_parser_error(); }
V8_INLINE void set_parser_error() { source_->set_parser_error(); }
V8_INLINE void reset_parser_error_flag() {
source_->reset_parser_error_flag();
}
V8_INLINE bool has_parser_error_set() const {
return source_->has_parser_error();
}
// Representation of an interval of source positions.
struct Location {
......
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