Commit 1bf95207 authored by adamk's avatar adamk Committed by Commit bot

[cleanup] Eliminate Forgive* methods on ExpressionClassifier

The only two places where these Forgive methods were called
was in ParseAssignmentExpression just at the time we were
calling Accumulate(). So instead of Forgiving, we can simply
not accumulate the bits that would have been forgiven.

Also slightly restructures the nearby code in
ParseAssignmentExpression, and removes the use of non-const
references in ExpressionClassifier.

Review-Url: https://codereview.chromium.org/2267223002
Cr-Commit-Position: refs/heads/master@{#38839}
parent a60e1822
......@@ -311,20 +311,6 @@ class ExpressionClassifier {
Add(Error(loc, message, kTailCallExpressionProduction, arg));
}
void ForgiveObjectLiteralError() {
if (!(invalid_productions_ & ObjectLiteralProduction)) return;
Error& e = reported_error(kObjectLiteralProduction);
e.kind = kUnusedError;
invalid_productions_ &= ~ObjectLiteralProduction;
}
void ForgiveAssignmentPatternError() {
if (!(invalid_productions_ & AssignmentPatternProduction)) return;
Error& e = reported_error(kAssignmentPatternProduction);
e.kind = kUnusedError;
invalid_productions_ &= ~AssignmentPatternProduction;
}
void Accumulate(ExpressionClassifier* inner, unsigned productions,
bool merge_non_patterns = true) {
DCHECK_EQ(inner->reported_errors_, reported_errors_);
......@@ -413,7 +399,7 @@ class ExpressionClassifier {
}
private:
V8_INLINE Error& reported_error(ErrorKind kind) const {
V8_INLINE const Error& reported_error(ErrorKind kind) const {
if (invalid_productions_ & (1 << kind)) {
for (int i = reported_errors_begin_; i < reported_errors_end_; i++) {
if (reported_errors_->at(i).kind == kind)
......
......@@ -2309,7 +2309,6 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN,
// ArrowFunction
// YieldExpression
// LeftHandSideExpression AssignmentOperator AssignmentExpression
bool is_destructuring_assignment = false;
int lhs_beg_pos = peek_position();
if (peek() == Token::YIELD && is_generator()) {
......@@ -2404,21 +2403,38 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN,
return expression;
}
if (this->IsValidReferenceExpression(expression)) {
arrow_formals_classifier.ForgiveAssignmentPatternError();
}
// "expression" was not itself an arrow function parameter list, but it might
// form part of one. Propagate speculative formal parameter error locations.
// form part of one. Propagate speculative formal parameter error locations
// (including those for binding patterns, since formal parameters can
// themselves contain binding patterns).
// Do not merge pending non-pattern expressions yet!
classifier->Accumulate(
&arrow_formals_classifier,
ExpressionClassifier::ExpressionProductions |
ExpressionClassifier::PatternProductions |
unsigned productions =
ExpressionClassifier::FormalParametersProductions |
ExpressionClassifier::ObjectLiteralProduction |
ExpressionClassifier::AsyncArrowFormalParametersProduction,
false);
ExpressionClassifier::AsyncArrowFormalParametersProduction |
ExpressionClassifier::FormalParameterInitializerProduction;
// Parenthesized identifiers and property references are allowed as part
// of a larger binding pattern, even though parenthesized patterns
// themselves are not allowed, e.g., "[(x)] = []". Only accumulate
// assignment pattern errors if the parsed expression is more complex.
if (this->IsValidReferenceExpression(expression)) {
productions |= ExpressionClassifier::PatternProductions &
~ExpressionClassifier::AssignmentPatternProduction;
} else {
productions |= ExpressionClassifier::PatternProductions;
}
const bool is_destructuring_assignment =
IsValidPattern(expression) && peek() == Token::ASSIGN;
if (!is_destructuring_assignment) {
// This may be an expression or a pattern, so we must continue to
// accumulate expression-related errors.
productions |= ExpressionClassifier::ExpressionProduction |
ExpressionClassifier::TailCallExpressionProduction |
ExpressionClassifier::ObjectLiteralProduction;
}
classifier->Accumulate(&arrow_formals_classifier, productions, false);
if (!Token::IsAssignmentOp(peek())) {
// Parsed conditional expression only (no assignment).
......@@ -2432,10 +2448,8 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN,
CheckNoTailCallExpressions(classifier, CHECK_OK);
if (IsValidPattern(expression) && peek() == Token::ASSIGN) {
classifier->ForgiveObjectLiteralError();
if (is_destructuring_assignment) {
ValidateAssignmentPattern(classifier, CHECK_OK);
is_destructuring_assignment = true;
} else {
expression = this->CheckAndRewriteReferenceExpression(
expression, lhs_beg_pos, scanner()->location().end_pos,
......
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