Commit 25f1fe91 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Avoid expression classifier branches in the preparser

In the preparser we don't need to worry about adding duplicate error objects to
the list, so we can simply unconditionally set the error flag. Restructure the
accumulator so we can also guarantee that we're checking the same flag as we're
setting.

Change-Id: I6a22cae468e77e5c6283c6fe937ca655f73991ac
Reviewed-on: https://chromium-review.googlesource.com/c/1275813Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56561}
parent 681bf59c
...@@ -195,9 +195,9 @@ class ExpressionClassifierBase { ...@@ -195,9 +195,9 @@ class ExpressionClassifierBase {
} }
} }
if (errors != 0 || copy_BP_to_AFP) { if (errors != 0 || copy_BP_to_AFP) {
this->invalid_productions_ |= errors;
static_cast<ErrorTracker*>(this)->AccumulateErrorImpl( static_cast<ErrorTracker*>(this)->AccumulateErrorImpl(
inner, productions, errors, copy_BP_to_AFP); inner, productions, errors, copy_BP_to_AFP);
this->invalid_productions_ |= errors;
} }
} }
static_cast<ErrorTracker*>(this)->RewindErrors(inner); static_cast<ErrorTracker*>(this)->RewindErrors(inner);
...@@ -258,7 +258,9 @@ class ExpressionClassifierErrorTracker ...@@ -258,7 +258,9 @@ class ExpressionClassifierErrorTracker
// Adds e to the end of the list of reported errors for this classifier. // Adds e to the end of the list of reported errors for this classifier.
// It is expected that this classifier is the last one in the stack. // It is expected that this classifier is the last one in the stack.
V8_INLINE void Add(const Error& e) { V8_INLINE void Add(TP production, const Error& e) {
if ((this->invalid_productions_ & production) != 0) return;
this->invalid_productions_ |= production;
DCHECK_EQ(reported_errors_end_, reported_errors_->length()); DCHECK_EQ(reported_errors_end_, reported_errors_->length());
reported_errors_->Add(e, this->base_->impl()->zone()); reported_errors_->Add(e, this->base_->impl()->zone());
reported_errors_end_++; reported_errors_end_++;
...@@ -325,7 +327,8 @@ class ExpressionClassifierErrorTracker ...@@ -325,7 +327,8 @@ class ExpressionClassifierErrorTracker
if (this->reported_errors_end_ < inner->reported_errors_end_) if (this->reported_errors_end_ < inner->reported_errors_end_)
this->Copy(binding_pattern_index); this->Copy(binding_pattern_index);
else else
Add(this->reported_errors_->at(binding_pattern_index)); Add(TP::ArrowFormalParametersProduction,
this->reported_errors_->at(binding_pattern_index));
this->reported_errors_->at(this->reported_errors_end_ - 1).kind = this->reported_errors_->at(this->reported_errors_end_ - 1).kind =
ErrorKind::kArrowFormalParametersProduction; ErrorKind::kArrowFormalParametersProduction;
} }
...@@ -369,7 +372,9 @@ class ExpressionClassifierEmptyErrorTracker ...@@ -369,7 +372,9 @@ class ExpressionClassifierEmptyErrorTracker
return none; return none;
} }
V8_INLINE void Add(const Error& e) {} V8_INLINE void Add(TP production, const Error& e) {
this->invalid_productions_ |= production;
}
private: private:
#ifdef DEBUG #ifdef DEBUG
...@@ -459,34 +464,30 @@ class ExpressionClassifier ...@@ -459,34 +464,30 @@ class ExpressionClassifier
void RecordExpressionError(const Scanner::Location& loc, void RecordExpressionError(const Scanner::Location& loc,
MessageTemplate::Template message, MessageTemplate::Template message,
const char* arg = nullptr) { const char* arg = nullptr) {
if (!this->is_valid_expression()) return; this->Add(TP::ExpressionProduction,
this->invalid_productions_ |= TP::ExpressionProduction; Error(loc, message, ErrorKind::kExpressionProduction, arg));
this->Add(Error(loc, message, ErrorKind::kExpressionProduction, arg));
} }
void RecordFormalParameterInitializerError(const Scanner::Location& loc, void RecordFormalParameterInitializerError(const Scanner::Location& loc,
MessageTemplate::Template message, MessageTemplate::Template message,
const char* arg = nullptr) { const char* arg = nullptr) {
if (!this->is_valid_formal_parameter_initializer()) return; this->Add(TP::FormalParameterInitializerProduction,
this->invalid_productions_ |= TP::FormalParameterInitializerProduction; Error(loc, message,
this->Add(Error(loc, message,
ErrorKind::kFormalParameterInitializerProduction, arg)); ErrorKind::kFormalParameterInitializerProduction, arg));
} }
void RecordBindingPatternError(const Scanner::Location& loc, void RecordBindingPatternError(const Scanner::Location& loc,
MessageTemplate::Template message, MessageTemplate::Template message,
const char* arg = nullptr) { const char* arg = nullptr) {
if (!this->is_valid_binding_pattern()) return; this->Add(TP::BindingPatternProduction,
this->invalid_productions_ |= TP::BindingPatternProduction; Error(loc, message, ErrorKind::kBindingPatternProduction, arg));
this->Add(Error(loc, message, ErrorKind::kBindingPatternProduction, arg));
} }
void RecordAssignmentPatternError(const Scanner::Location& loc, void RecordAssignmentPatternError(const Scanner::Location& loc,
MessageTemplate::Template message, MessageTemplate::Template message,
const char* arg = nullptr) { const char* arg = nullptr) {
if (!this->is_valid_assignment_pattern()) return;
this->invalid_productions_ |= TP::AssignmentPatternProduction;
this->Add( this->Add(
TP::AssignmentPatternProduction,
Error(loc, message, ErrorKind::kAssignmentPatternProduction, arg)); Error(loc, message, ErrorKind::kAssignmentPatternProduction, arg));
} }
...@@ -500,25 +501,22 @@ class ExpressionClassifier ...@@ -500,25 +501,22 @@ class ExpressionClassifier
void RecordArrowFormalParametersError(const Scanner::Location& loc, void RecordArrowFormalParametersError(const Scanner::Location& loc,
MessageTemplate::Template message, MessageTemplate::Template message,
const char* arg = nullptr) { const char* arg = nullptr) {
if (!this->is_valid_arrow_formal_parameters()) return;
this->invalid_productions_ |= TP::ArrowFormalParametersProduction;
this->Add( this->Add(
TP::ArrowFormalParametersProduction,
Error(loc, message, ErrorKind::kArrowFormalParametersProduction, arg)); Error(loc, message, ErrorKind::kArrowFormalParametersProduction, arg));
} }
void RecordAsyncArrowFormalParametersError(const Scanner::Location& loc, void RecordAsyncArrowFormalParametersError(const Scanner::Location& loc,
MessageTemplate::Template message, MessageTemplate::Template message,
const char* arg = nullptr) { const char* arg = nullptr) {
if (!this->is_valid_async_arrow_formal_parameters()) return; this->Add(TP::AsyncArrowFormalParametersProduction,
this->invalid_productions_ |= TP::AsyncArrowFormalParametersProduction; Error(loc, message,
this->Add(Error(loc, message,
ErrorKind::kAsyncArrowFormalParametersProduction, arg)); ErrorKind::kAsyncArrowFormalParametersProduction, arg));
} }
void RecordDuplicateFormalParameterError(const Scanner::Location& loc) { void RecordDuplicateFormalParameterError(const Scanner::Location& loc) {
if (!this->is_valid_formal_parameter_list_without_duplicates()) return; this->Add(TP::DistinctFormalParametersProduction,
this->invalid_productions_ |= TP::DistinctFormalParametersProduction; Error(loc, MessageTemplate::kParamDupe,
this->Add(Error(loc, MessageTemplate::kParamDupe,
ErrorKind::kDistinctFormalParametersProduction)); ErrorKind::kDistinctFormalParametersProduction));
} }
...@@ -528,18 +526,16 @@ class ExpressionClassifier ...@@ -528,18 +526,16 @@ class ExpressionClassifier
void RecordStrictModeFormalParameterError(const Scanner::Location& loc, void RecordStrictModeFormalParameterError(const Scanner::Location& loc,
MessageTemplate::Template message, MessageTemplate::Template message,
const char* arg = nullptr) { const char* arg = nullptr) {
if (!this->is_valid_strict_mode_formal_parameters()) return; this->Add(TP::StrictModeFormalParametersProduction,
this->invalid_productions_ |= TP::StrictModeFormalParametersProduction; Error(loc, message,
this->Add(Error(loc, message,
ErrorKind::kStrictModeFormalParametersProduction, arg)); ErrorKind::kStrictModeFormalParametersProduction, arg));
} }
void RecordLetPatternError(const Scanner::Location& loc, void RecordLetPatternError(const Scanner::Location& loc,
MessageTemplate::Template message, MessageTemplate::Template message,
const char* arg = nullptr) { const char* arg = nullptr) {
if (!this->is_valid_let_pattern()) return; this->Add(TP::LetPatternProduction,
this->invalid_productions_ |= TP::LetPatternProduction; Error(loc, message, ErrorKind::kLetPatternProduction, arg));
this->Add(Error(loc, message, ErrorKind::kLetPatternProduction, arg));
} }
ExpressionClassifier* previous() const { return previous_; } ExpressionClassifier* previous() const { return previous_; }
......
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