Commit f763a5e7 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Use fewer branches to accumulate errors, especially in the preparser

Change-Id: I8ab8e4f312d315a2f9d7b54ac894af87596fc51f
Reviewed-on: https://chromium-review.googlesource.com/c/1280303
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56651}
parent 0d91db0b
...@@ -183,26 +183,19 @@ class ExpressionClassifierBase { ...@@ -183,26 +183,19 @@ class ExpressionClassifierBase {
#endif #endif
// Propagate errors from inner, but don't overwrite already recorded // Propagate errors from inner, but don't overwrite already recorded
// errors. // errors.
unsigned non_arrow_inner_invalid_productions = unsigned filter = productions & ~this->invalid_productions_;
inner->invalid_productions_ & ~ArrowFormalParametersProduction; // Don't propagate ArrowFormalParameter error directly.
if (non_arrow_inner_invalid_productions) { unsigned errors =
unsigned errors = non_arrow_inner_invalid_productions & productions & ~ArrowFormalParametersProduction & inner->invalid_productions_ & filter;
~this->invalid_productions_; // Convert BindingPattern error to ArrowFormalParameter error.
// The result will continue to be a valid arrow formal parameters if the static const unsigned shift =
// inner expression is a valid binding pattern. kArrowFormalParametersProduction - kBindingPatternProduction;
if (productions & ArrowFormalParametersProduction) { unsigned binding_as_arrow =
if (is_valid_arrow_formal_parameters() && (inner->invalid_productions_ & BindingPatternProduction) << shift;
!inner->is_valid_binding_pattern()) { errors |= binding_as_arrow & filter;
errors |= ArrowFormalParametersProduction; static_cast<ErrorTracker*>(this)->AccumulateErrorImpl(inner, productions,
} errors);
} this->invalid_productions_ |= errors;
if (errors != 0) {
static_cast<ErrorTracker*>(this)->AccumulateErrorImpl(
inner, productions, errors);
this->invalid_productions_ |= errors;
}
}
static_cast<ErrorTracker*>(this)->RewindErrors(inner);
} }
protected: protected:
...@@ -297,16 +290,20 @@ class ExpressionClassifierErrorTracker ...@@ -297,16 +290,20 @@ class ExpressionClassifierErrorTracker
void AccumulateErrorImpl(ExpressionClassifier<Types>* const inner, void AccumulateErrorImpl(ExpressionClassifier<Types>* const inner,
unsigned productions, unsigned errors) { unsigned productions, unsigned errors) {
unsigned non_arrow_errors = errors & ~TP::ArrowFormalParametersProduction;
// Traverse the list of errors reported by the inner classifier // Traverse the list of errors reported by the inner classifier
// to copy what's necessary. // to copy what's necessary.
int binding_pattern_index = inner->reported_errors_end_; int binding_pattern_index = inner->reported_errors_end_;
for (int i = inner->reported_errors_begin_; i < inner->reported_errors_end_; for (int i = inner->reported_errors_begin_; errors != 0; i++) {
i++) { int mask = 1 << this->reported_errors_->at(i).kind;
int k = this->reported_errors_->at(i).kind; if ((non_arrow_errors & mask) != 0) {
if (errors & (1 << k)) this->Copy(i); errors ^= mask;
this->Copy(i);
}
// Check if it's a BP error that has to be copied to an AFP error. // Check if it's a BP error that has to be copied to an AFP error.
if (k == ErrorKind::kBindingPatternProduction && if (mask == TP::BindingPatternProduction &&
(errors & TP::ArrowFormalParametersProduction) != 0) { (errors & TP::ArrowFormalParametersProduction) != 0) {
errors ^= TP::ArrowFormalParametersProduction;
if (this->reported_errors_end_ <= i) { if (this->reported_errors_end_ <= i) {
// If the BP error itself has not already been copied, // If the BP error itself has not already been copied,
// copy it now and change it to an AFP error. // copy it now and change it to an AFP error.
...@@ -334,6 +331,8 @@ class ExpressionClassifierErrorTracker ...@@ -334,6 +331,8 @@ class ExpressionClassifierErrorTracker
this->reported_errors_->at(this->reported_errors_end_ - 1).kind = this->reported_errors_->at(this->reported_errors_end_ - 1).kind =
ErrorKind::kArrowFormalParametersProduction; ErrorKind::kArrowFormalParametersProduction;
} }
RewindErrors(inner);
} }
private: private:
...@@ -383,7 +382,6 @@ class ExpressionClassifierEmptyErrorTracker ...@@ -383,7 +382,6 @@ class ExpressionClassifierEmptyErrorTracker
V8_INLINE void CheckErrorPositions(ExpressionClassifier<Types>* const inner) { V8_INLINE void CheckErrorPositions(ExpressionClassifier<Types>* const inner) {
} }
#endif #endif
V8_INLINE void RewindErrors(ExpressionClassifier<Types>* const inner) {}
V8_INLINE void AccumulateErrorImpl(ExpressionClassifier<Types>* const inner, V8_INLINE void AccumulateErrorImpl(ExpressionClassifier<Types>* const inner,
unsigned productions, unsigned errors) {} unsigned productions, unsigned errors) {}
......
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