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

[parser] Remove RETURN_IF* part 7

Bug: v8:8363, v8:7926
Change-Id: I0722a30dc201b04f212d49dc96b8e4353a0201ad
Reviewed-on: https://chromium-review.googlesource.com/c/1299024Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56999}
parent 267e6b0c
...@@ -679,7 +679,7 @@ class ParserBase { ...@@ -679,7 +679,7 @@ class ParserBase {
Token::Value next = scanner()->Next(); Token::Value next = scanner()->Next();
USE(next); USE(next);
USE(token); USE(token);
DCHECK_EQ(next, token); DCHECK_IMPLIES(!scanner_->has_parser_error_set(), next == token);
} }
V8_INLINE bool Check(Token::Value token) { V8_INLINE bool Check(Token::Value token) {
...@@ -4902,7 +4902,6 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock( ...@@ -4902,7 +4902,6 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock(
// Parse the statements and collect escaping labels. // Parse the statements and collect escaping labels.
Expect(Token::LBRACE); Expect(Token::LBRACE);
RETURN_IF_PARSE_ERROR_CUSTOM(NullStatement);
CheckStackOverflow(); CheckStackOverflow();
...@@ -4920,7 +4919,6 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock( ...@@ -4920,7 +4919,6 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock(
} }
Expect(Token::RBRACE); Expect(Token::RBRACE);
RETURN_IF_PARSE_ERROR_CUSTOM(NullStatement);
int end_pos = end_position(); int end_pos = end_position();
scope()->set_end_position(end_pos); scope()->set_end_position(end_pos);
impl()->RecordBlockSourceRange(body, end_pos); impl()->RecordBlockSourceRange(body, end_pos);
...@@ -4941,7 +4939,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseScopedStatement( ...@@ -4941,7 +4939,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseScopedStatement(
scope()->set_start_position(scanner()->location().beg_pos); scope()->set_start_position(scanner()->location().beg_pos);
BlockT block = factory()->NewBlock(1, false); BlockT block = factory()->NewBlock(1, false);
StatementT body = ParseFunctionDeclaration(); StatementT body = ParseFunctionDeclaration();
RETURN_IF_PARSE_ERROR;
block->statements()->Add(body, zone()); block->statements()->Add(body, zone());
scope()->set_end_position(end_position()); scope()->set_end_position(end_position());
block->set_scope(scope()->FinalizeBlockScope()); block->set_scope(scope()->FinalizeBlockScope());
...@@ -4971,7 +4968,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseVariableStatement( ...@@ -4971,7 +4968,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseVariableStatement(
DeclarationParsingResult parsing_result; DeclarationParsingResult parsing_result;
StatementT result = StatementT result =
ParseVariableDeclarations(var_context, &parsing_result, names); ParseVariableDeclarations(var_context, &parsing_result, names);
RETURN_IF_PARSE_ERROR;
ExpectSemicolon(); ExpectSemicolon();
return result; return result;
} }
...@@ -4988,7 +4984,6 @@ ParserBase<Impl>::ParseDebuggerStatement() { ...@@ -4988,7 +4984,6 @@ ParserBase<Impl>::ParseDebuggerStatement() {
int pos = peek_position(); int pos = peek_position();
Consume(Token::DEBUGGER); Consume(Token::DEBUGGER);
ExpectSemicolon(); ExpectSemicolon();
RETURN_IF_PARSE_ERROR;
return factory()->NewDebuggerStatement(pos); return factory()->NewDebuggerStatement(pos);
} }
...@@ -5034,6 +5029,7 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement( ...@@ -5034,6 +5029,7 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement(
bool starts_with_identifier = peek_any_identifier(); bool starts_with_identifier = peek_any_identifier();
ExpressionT expr = ParseExpression(); ExpressionT expr = ParseExpression();
// TODO(verwaest): Remove once we have FailureExpression.
RETURN_IF_PARSE_ERROR; RETURN_IF_PARSE_ERROR;
if (peek() == Token::COLON && starts_with_identifier && if (peek() == Token::COLON && starts_with_identifier &&
impl()->IsIdentifier(expr)) { impl()->IsIdentifier(expr)) {
...@@ -5041,7 +5037,6 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement( ...@@ -5041,7 +5037,6 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement(
// something starting with an identifier or a parenthesized identifier. // something starting with an identifier or a parenthesized identifier.
impl()->DeclareLabel(&labels, &own_labels, impl()->DeclareLabel(&labels, &own_labels,
impl()->AsIdentifierExpression(expr)); impl()->AsIdentifierExpression(expr));
RETURN_IF_PARSE_ERROR;
Consume(Token::COLON); Consume(Token::COLON);
// ES#sec-labelled-function-declarations Labelled Function Declarations // ES#sec-labelled-function-declarations Labelled Function Declarations
if (peek() == Token::FUNCTION && is_sloppy(language_mode()) && if (peek() == Token::FUNCTION && is_sloppy(language_mode()) &&
...@@ -5062,7 +5057,6 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement( ...@@ -5062,7 +5057,6 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement(
// Parsed expression statement, followed by semicolon. // Parsed expression statement, followed by semicolon.
ExpectSemicolon(); ExpectSemicolon();
RETURN_IF_PARSE_ERROR;
return factory()->NewExpressionStatement(expr, pos); return factory()->NewExpressionStatement(expr, pos);
} }
...@@ -5075,24 +5069,19 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement( ...@@ -5075,24 +5069,19 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseIfStatement(
int pos = peek_position(); int pos = peek_position();
Consume(Token::IF); Consume(Token::IF);
Expect(Token::LPAREN); Expect(Token::LPAREN);
RETURN_IF_PARSE_ERROR;
ExpressionT condition = ParseExpression(); ExpressionT condition = ParseExpression();
RETURN_IF_PARSE_ERROR;
Expect(Token::RPAREN); Expect(Token::RPAREN);
RETURN_IF_PARSE_ERROR;
SourceRange then_range, else_range; SourceRange then_range, else_range;
StatementT then_statement = impl()->NullStatement(); StatementT then_statement = impl()->NullStatement();
{ {
SourceRangeScope range_scope(scanner(), &then_range); SourceRangeScope range_scope(scanner(), &then_range);
then_statement = ParseScopedStatement(labels); then_statement = ParseScopedStatement(labels);
RETURN_IF_PARSE_ERROR
} }
StatementT else_statement = impl()->NullStatement(); StatementT else_statement = impl()->NullStatement();
if (Check(Token::ELSE)) { if (Check(Token::ELSE)) {
else_statement = ParseScopedStatement(labels); else_statement = ParseScopedStatement(labels);
RETURN_IF_PARSE_ERROR;
else_range = SourceRange::ContinuationOf(then_range, end_position()); else_range = SourceRange::ContinuationOf(then_range, end_position());
} else { } else {
else_statement = factory()->NewEmptyStatement(kNoSourcePosition); else_statement = factory()->NewEmptyStatement(kNoSourcePosition);
...@@ -5117,17 +5106,15 @@ ParserBase<Impl>::ParseContinueStatement() { ...@@ -5117,17 +5106,15 @@ ParserBase<Impl>::ParseContinueStatement() {
!Token::IsAutoSemicolon(tok)) { !Token::IsAutoSemicolon(tok)) {
// ECMA allows "eval" or "arguments" as labels even in strict mode. // ECMA allows "eval" or "arguments" as labels even in strict mode.
label = ParseIdentifier(kAllowRestrictedIdentifiers); label = ParseIdentifier(kAllowRestrictedIdentifiers);
RETURN_IF_PARSE_ERROR;
} }
RETURN_IF_PARSE_ERROR;
typename Types::IterationStatement target = typename Types::IterationStatement target =
impl()->LookupContinueTarget(label); impl()->LookupContinueTarget(label);
RETURN_IF_PARSE_ERROR;
if (impl()->IsNull(target)) { if (impl()->IsNull(target)) {
// Illegal continue statement. // Illegal continue statement.
MessageTemplate message = MessageTemplate::kIllegalContinue; MessageTemplate message = MessageTemplate::kIllegalContinue;
typename Types::BreakableStatement breakable_target = typename Types::BreakableStatement breakable_target =
impl()->LookupBreakTarget(label); impl()->LookupBreakTarget(label);
RETURN_IF_PARSE_ERROR;
if (impl()->IsNull(label)) { if (impl()->IsNull(label)) {
message = MessageTemplate::kNoIterationStatement; message = MessageTemplate::kNoIterationStatement;
} else if (impl()->IsNull(breakable_target)) { } else if (impl()->IsNull(breakable_target)) {
...@@ -5137,7 +5124,6 @@ ParserBase<Impl>::ParseContinueStatement() { ...@@ -5137,7 +5124,6 @@ ParserBase<Impl>::ParseContinueStatement() {
return impl()->NullStatement(); return impl()->NullStatement();
} }
ExpectSemicolon(); ExpectSemicolon();
RETURN_IF_PARSE_ERROR;
StatementT stmt = factory()->NewContinueStatement(target, pos); StatementT stmt = factory()->NewContinueStatement(target, pos);
impl()->RecordJumpStatementSourceRange(stmt, end_position()); impl()->RecordJumpStatementSourceRange(stmt, end_position());
return stmt; return stmt;
...@@ -5157,17 +5143,14 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseBreakStatement( ...@@ -5157,17 +5143,14 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseBreakStatement(
!Token::IsAutoSemicolon(tok)) { !Token::IsAutoSemicolon(tok)) {
// ECMA allows "eval" or "arguments" as labels even in strict mode. // ECMA allows "eval" or "arguments" as labels even in strict mode.
label = ParseIdentifier(kAllowRestrictedIdentifiers); label = ParseIdentifier(kAllowRestrictedIdentifiers);
RETURN_IF_PARSE_ERROR;
} }
// Parse labeled break statements that target themselves into // Parse labeled break statements that target themselves into
// empty statements, e.g. 'l1: l2: l3: break l2;' // empty statements, e.g. 'l1: l2: l3: break l2;'
if (!impl()->IsNull(label) && impl()->ContainsLabel(labels, label)) { if (!impl()->IsNull(label) && impl()->ContainsLabel(labels, label)) {
ExpectSemicolon(); ExpectSemicolon();
RETURN_IF_PARSE_ERROR;
return factory()->NewEmptyStatement(pos); return factory()->NewEmptyStatement(pos);
} }
typename Types::BreakableStatement target = impl()->LookupBreakTarget(label); typename Types::BreakableStatement target = impl()->LookupBreakTarget(label);
RETURN_IF_PARSE_ERROR;
if (impl()->IsNull(target)) { if (impl()->IsNull(target)) {
// Illegal break statement. // Illegal break statement.
MessageTemplate message = MessageTemplate::kIllegalBreak; MessageTemplate message = MessageTemplate::kIllegalBreak;
...@@ -5178,7 +5161,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseBreakStatement( ...@@ -5178,7 +5161,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseBreakStatement(
return impl()->NullStatement(); return impl()->NullStatement();
} }
ExpectSemicolon(); ExpectSemicolon();
RETURN_IF_PARSE_ERROR;
StatementT stmt = factory()->NewBreakStatement(target, pos); StatementT stmt = factory()->NewBreakStatement(target, pos);
impl()->RecordJumpStatementSourceRange(stmt, end_position()); impl()->RecordJumpStatementSourceRange(stmt, end_position());
return stmt; return stmt;
...@@ -5213,10 +5195,9 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseReturnStatement() { ...@@ -5213,10 +5195,9 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseReturnStatement() {
} }
} else { } else {
return_value = ParseExpression(); return_value = ParseExpression();
RETURN_IF_PARSE_ERROR;
} }
ExpectSemicolon(); ExpectSemicolon();
RETURN_IF_PARSE_ERROR;
return_value = impl()->RewriteReturn(return_value, loc.beg_pos); return_value = impl()->RewriteReturn(return_value, loc.beg_pos);
int continuation_pos = end_position(); int continuation_pos = end_position();
StatementT stmt = StatementT stmt =
...@@ -5240,11 +5221,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement( ...@@ -5240,11 +5221,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement(
} }
Expect(Token::LPAREN); Expect(Token::LPAREN);
RETURN_IF_PARSE_ERROR;
ExpressionT expr = ParseExpression(); ExpressionT expr = ParseExpression();
RETURN_IF_PARSE_ERROR;
Expect(Token::RPAREN); Expect(Token::RPAREN);
RETURN_IF_PARSE_ERROR;
Scope* with_scope = NewScope(WITH_SCOPE); Scope* with_scope = NewScope(WITH_SCOPE);
StatementT body = impl()->NullStatement(); StatementT body = impl()->NullStatement();
...@@ -5252,7 +5230,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement( ...@@ -5252,7 +5230,6 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement(
BlockState block_state(&scope_, with_scope); BlockState block_state(&scope_, with_scope);
with_scope->set_start_position(scanner()->peek_location().beg_pos); with_scope->set_start_position(scanner()->peek_location().beg_pos);
body = ParseStatement(labels, nullptr); body = ParseStatement(labels, nullptr);
RETURN_IF_PARSE_ERROR;
with_scope->set_end_position(end_position()); with_scope->set_end_position(end_position());
} }
return factory()->NewWithStatement(with_scope, expr, body, pos); return factory()->NewWithStatement(with_scope, expr, body, pos);
...@@ -5277,17 +5254,12 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseDoWhileStatement( ...@@ -5277,17 +5254,12 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseDoWhileStatement(
{ {
SourceRangeScope range_scope(scanner(), &body_range); SourceRangeScope range_scope(scanner(), &body_range);
body = ParseStatement(nullptr, nullptr); body = ParseStatement(nullptr, nullptr);
RETURN_IF_PARSE_ERROR;
} }
Expect(Token::WHILE); Expect(Token::WHILE);
RETURN_IF_PARSE_ERROR;
Expect(Token::LPAREN); Expect(Token::LPAREN);
RETURN_IF_PARSE_ERROR;
ExpressionT cond = ParseExpression(); ExpressionT cond = ParseExpression();
RETURN_IF_PARSE_ERROR
Expect(Token::RPAREN); Expect(Token::RPAREN);
RETURN_IF_PARSE_ERROR;
// Allow do-statements to be terminated with and without // Allow do-statements to be terminated with and without
// semi-colons. This allows code such as 'do;while(0)return' to // semi-colons. This allows code such as 'do;while(0)return' to
...@@ -5316,15 +5288,11 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWhileStatement( ...@@ -5316,15 +5288,11 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWhileStatement(
Consume(Token::WHILE); Consume(Token::WHILE);
Expect(Token::LPAREN); Expect(Token::LPAREN);
RETURN_IF_PARSE_ERROR;
ExpressionT cond = ParseExpression(); ExpressionT cond = ParseExpression();
RETURN_IF_PARSE_ERROR
Expect(Token::RPAREN); Expect(Token::RPAREN);
RETURN_IF_PARSE_ERROR;
{ {
SourceRangeScope range_scope(scanner(), &body_range); SourceRangeScope range_scope(scanner(), &body_range);
body = ParseStatement(nullptr, nullptr); body = ParseStatement(nullptr, nullptr);
RETURN_IF_PARSE_ERROR;
} }
loop->Initialize(cond, body); loop->Initialize(cond, body);
...@@ -5345,9 +5313,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseThrowStatement() { ...@@ -5345,9 +5313,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseThrowStatement() {
return impl()->NullStatement(); return impl()->NullStatement();
} }
ExpressionT exception = ParseExpression(); ExpressionT exception = ParseExpression();
RETURN_IF_PARSE_ERROR;
ExpectSemicolon(); ExpectSemicolon();
RETURN_IF_PARSE_ERROR;
StatementT stmt = impl()->NewThrowStatement(exception, pos); StatementT stmt = impl()->NewThrowStatement(exception, pos);
impl()->RecordThrowSourceRange(stmt, end_position()); impl()->RecordThrowSourceRange(stmt, end_position());
......
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