Commit 6392442e authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Only validate expressions when we have to

Since ValidateExpression just throws the only queued (first) expression error,
we can delay throwing it until the latest possible moment. That's right before
the matching expression classifier dies (goes out of scope or accumulates).

Change-Id: I4538de333b789ae786278b94b76b4799ccdf4903
Reviewed-on: https://chromium-review.googlesource.com/c/1286678
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56785}
parent b2b7e8de
...@@ -1080,9 +1080,7 @@ class ParserBase { ...@@ -1080,9 +1080,7 @@ class ParserBase {
bool* is_rest_property, bool* ok); bool* is_rest_property, bool* ok);
ExpressionListT ParseArguments(bool* has_spread, bool maybe_arrow, bool* ok); ExpressionListT ParseArguments(bool* has_spread, bool maybe_arrow, bool* ok);
ExpressionListT ParseArguments(bool* has_spread, bool* ok) { ExpressionListT ParseArguments(bool* has_spread, bool* ok) {
ExpressionListT result = ParseArguments(has_spread, false, ok); return ParseArguments(has_spread, false, ok);
ValidateExpression(CHECK_OK_CUSTOM(NullExpressionList));
return result;
} }
ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok); ExpressionT ParseAssignmentExpression(bool accept_IN, bool* ok);
...@@ -2917,7 +2915,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseYieldExpression( ...@@ -2917,7 +2915,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseYieldExpression(
V8_FALLTHROUGH; V8_FALLTHROUGH;
default: default:
expression = ParseAssignmentExpression(accept_IN, CHECK_OK); expression = ParseAssignmentExpression(accept_IN, CHECK_OK);
ValidateExpression(CHECK_OK);
break; break;
} }
} }
...@@ -2966,7 +2963,6 @@ ParserBase<Impl>::ParseConditionalContinuation(ExpressionT expression, ...@@ -2966,7 +2963,6 @@ ParserBase<Impl>::ParseConditionalContinuation(ExpressionT expression,
bool accept_IN, int pos, bool accept_IN, int pos,
bool* ok) { bool* ok) {
SourceRange then_range, else_range; SourceRange then_range, else_range;
ValidateExpression(CHECK_OK);
BindingPatternUnexpectedToken(); BindingPatternUnexpectedToken();
ArrowFormalParametersUnexpectedToken(); ArrowFormalParametersUnexpectedToken();
...@@ -2981,7 +2977,6 @@ ParserBase<Impl>::ParseConditionalContinuation(ExpressionT expression, ...@@ -2981,7 +2977,6 @@ ParserBase<Impl>::ParseConditionalContinuation(ExpressionT expression,
left = ParseAssignmentExpression(true, CHECK_OK); left = ParseAssignmentExpression(true, CHECK_OK);
AccumulateNonBindingPatternErrors(); AccumulateNonBindingPatternErrors();
} }
ValidateExpression(CHECK_OK);
ExpressionT right; ExpressionT right;
{ {
SourceRangeScope range_scope(scanner(), &else_range); SourceRangeScope range_scope(scanner(), &else_range);
...@@ -2990,7 +2985,6 @@ ParserBase<Impl>::ParseConditionalContinuation(ExpressionT expression, ...@@ -2990,7 +2985,6 @@ ParserBase<Impl>::ParseConditionalContinuation(ExpressionT expression,
right = ParseAssignmentExpression(accept_IN, CHECK_OK); right = ParseAssignmentExpression(accept_IN, CHECK_OK);
AccumulateNonBindingPatternErrors(); AccumulateNonBindingPatternErrors();
} }
ValidateExpression(CHECK_OK);
ExpressionT expr = factory()->NewConditional(expression, left, right, pos); ExpressionT expr = factory()->NewConditional(expression, left, right, pos);
impl()->RecordConditionalSourceRange(expr, then_range, else_range); impl()->RecordConditionalSourceRange(expr, then_range, else_range);
return expr; return expr;
...@@ -3008,8 +3002,6 @@ ParserBase<Impl>::ParseBinaryContinuation(ExpressionT x, int prec, int prec1, ...@@ -3008,8 +3002,6 @@ ParserBase<Impl>::ParseBinaryContinuation(ExpressionT x, int prec, int prec1,
do { do {
// prec1 >= 4 // prec1 >= 4
while (Token::Precedence(peek()) == prec1) { while (Token::Precedence(peek()) == prec1) {
ValidateExpression(CHECK_OK);
SourceRange right_range; SourceRange right_range;
int pos = peek_position(); int pos = peek_position();
ExpressionT y; ExpressionT y;
...@@ -3022,7 +3014,6 @@ ParserBase<Impl>::ParseBinaryContinuation(ExpressionT x, int prec, int prec1, ...@@ -3022,7 +3014,6 @@ ParserBase<Impl>::ParseBinaryContinuation(ExpressionT x, int prec, int prec1,
const int next_prec = is_right_associative ? prec1 : prec1 + 1; const int next_prec = is_right_associative ? prec1 : prec1 + 1;
y = ParseBinaryExpression(next_prec, accept_IN, CHECK_OK); y = ParseBinaryExpression(next_prec, accept_IN, CHECK_OK);
} }
ValidateExpression(CHECK_OK);
// For now we distinguish between comparisons and other binary // For now we distinguish between comparisons and other binary
// operations. (We could combine the two and get rid of this // operations. (We could combine the two and get rid of this
...@@ -3085,7 +3076,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseUnaryOpExpression( ...@@ -3085,7 +3076,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseUnaryOpExpression(
} }
ExpressionT expression = ParseUnaryExpression(CHECK_OK); ExpressionT expression = ParseUnaryExpression(CHECK_OK);
ValidateExpression(CHECK_OK);
if (op == Token::DELETE) { if (op == Token::DELETE) {
if (impl()->IsIdentifier(expression) && is_strict(language_mode())) { if (impl()->IsIdentifier(expression) && is_strict(language_mode())) {
...@@ -3124,7 +3114,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrefixExpression( ...@@ -3124,7 +3114,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrefixExpression(
expression, beg_pos, end_position(), expression, beg_pos, end_position(),
MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK);
impl()->MarkExpressionAsAssigned(expression); impl()->MarkExpressionAsAssigned(expression);
ValidateExpression(CHECK_OK);
return factory()->NewCountOperation(op, true /* prefix */, expression, return factory()->NewCountOperation(op, true /* prefix */, expression,
position()); position());
...@@ -3192,7 +3181,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePostfixExpression( ...@@ -3192,7 +3181,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePostfixExpression(
expression, lhs_beg_pos, end_position(), expression, lhs_beg_pos, end_position(),
MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK); MessageTemplate::kInvalidLhsInPostfixOp, CHECK_OK);
impl()->MarkExpressionAsAssigned(expression); impl()->MarkExpressionAsAssigned(expression);
ValidateExpression(CHECK_OK);
Token::Value next = Next(); Token::Value next = Next();
expression = expression =
...@@ -3324,7 +3312,6 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result, bool* ok) { ...@@ -3324,7 +3312,6 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result, bool* ok) {
break; break;
} }
} while (Token::IsPropertyOrCall(peek())); } while (Token::IsPropertyOrCall(peek()));
ValidateExpression(CHECK_OK);
return result; return result;
} }
...@@ -3370,7 +3357,6 @@ ParserBase<Impl>::ParseMemberWithPresentNewPrefixesExpression(bool* ok) { ...@@ -3370,7 +3357,6 @@ ParserBase<Impl>::ParseMemberWithPresentNewPrefixesExpression(bool* ok) {
} else { } else {
result = ParseMemberWithNewPrefixesExpression(CHECK_OK); result = ParseMemberWithNewPrefixesExpression(CHECK_OK);
} }
ValidateExpression(CHECK_OK);
if (peek() == Token::LPAREN) { if (peek() == Token::LPAREN) {
// NewExpression with arguments. // NewExpression with arguments.
bool has_spread; bool has_spread;
...@@ -3610,7 +3596,6 @@ ParserBase<Impl>::DoParseMemberExpressionContinuation(ExpressionT expression, ...@@ -3610,7 +3596,6 @@ ParserBase<Impl>::DoParseMemberExpressionContinuation(ExpressionT expression,
} }
} }
} while (Token::IsProperty(peek())); } while (Token::IsProperty(peek()));
ValidateExpression(CHECK_OK);
return expression; return expression;
} }
...@@ -4545,7 +4530,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral( ...@@ -4545,7 +4530,6 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseTemplateLiteral(
int expr_pos = peek_position(); int expr_pos = peek_position();
ExpressionT expression = ParseExpressionCoverGrammar(true, CHECK_OK); ExpressionT expression = ParseExpressionCoverGrammar(true, CHECK_OK);
ValidateExpression(CHECK_OK);
impl()->AddTemplateExpression(&ts, expression); impl()->AddTemplateExpression(&ts, expression);
if (peek() != Token::RBRACE) { if (peek() != Token::RBRACE) {
......
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