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