Commit 8baea46e authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[scanner] Merge after_multiline_comment into after_line_terminator

Change-Id: I228bbd81807fdfac9e760576f89aeb133e45cf61
Reviewed-on: https://chromium-review.googlesource.com/1186326
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55399}
parent 0b87c570
......@@ -748,8 +748,7 @@ class ParserBase {
Next();
return;
}
if (scanner()->HasAnyLineTerminatorBeforeNext() ||
tok == Token::RBRACE ||
if (scanner()->HasLineTerminatorBeforeNext() || tok == Token::RBRACE ||
tok == Token::EOS) {
return;
}
......@@ -1890,7 +1889,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePrimaryExpression(
return impl()->ExpressionFromLiteral(Next(), beg_pos);
case Token::ASYNC:
if (!scanner()->HasAnyLineTerminatorAfterNext() &&
if (!scanner()->HasLineTerminatorAfterNext() &&
PeekAhead() == Token::FUNCTION) {
BindingPatternUnexpectedToken();
Consume(Token::ASYNC);
......@@ -2194,10 +2193,10 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
int pos = peek_position();
if (!*is_generator && token == Token::ASYNC &&
!scanner()->HasAnyLineTerminatorAfterNext()) {
!scanner()->HasLineTerminatorAfterNext()) {
Consume(Token::ASYNC);
token = peek();
if (token == Token::MUL && !scanner()->HasAnyLineTerminatorBeforeNext()) {
if (token == Token::MUL && !scanner()->HasLineTerminatorBeforeNext()) {
Consume(Token::MUL);
token = peek();
*is_generator = true;
......@@ -2893,7 +2892,7 @@ ParserBase<Impl>::ParseAssignmentExpression(bool accept_IN, bool* ok) {
function_state_->destructuring_assignments_to_rewrite().size());
bool is_async = peek() == Token::ASYNC &&
!scanner()->HasAnyLineTerminatorAfterNext() &&
!scanner()->HasLineTerminatorAfterNext() &&
IsValidArrowFormalParametersStart(PeekAhead());
bool parenthesized_formals = peek() == Token::LPAREN;
......@@ -3070,7 +3069,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseYieldExpression(
// The following initialization is necessary.
ExpressionT expression = impl()->NullExpression();
bool delegating = false; // yield*
if (!scanner()->HasAnyLineTerminatorBeforeNext()) {
if (!scanner()->HasLineTerminatorBeforeNext()) {
if (Check(Token::MUL)) delegating = true;
switch (peek()) {
case Token::EOS:
......@@ -3321,8 +3320,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePostfixExpression(
int lhs_beg_pos = peek_position();
ExpressionT expression = ParseLeftHandSideExpression(CHECK_OK);
if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
Token::IsCountOp(peek())) {
if (!scanner()->HasLineTerminatorBeforeNext() && Token::IsCountOp(peek())) {
BindingPatternUnexpectedToken();
ArrowFormalParametersUnexpectedToken();
......@@ -4183,7 +4181,7 @@ ParserBase<Impl>::ParseAsyncFunctionDeclaration(
// ( FormalParameters[Await] ) { AsyncFunctionBody }
DCHECK_EQ(scanner()->current_token(), Token::ASYNC);
int pos = position();
if (scanner()->HasAnyLineTerminatorBeforeNext()) {
if (scanner()->HasLineTerminatorBeforeNext()) {
*ok = false;
impl()->ReportUnexpectedToken(scanner()->current_token());
return impl()->NullStatement();
......@@ -4375,7 +4373,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
base::ElapsedTimer timer;
if (V8_UNLIKELY(FLAG_log_function_events)) timer.Start();
if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) {
if (peek() == Token::ARROW && scanner_->HasLineTerminatorBeforeNext()) {
// ASI inserts `;` after arrow parameters if a line terminator is found.
// `=> ...` is never a valid expression, so report as syntax error.
// If next token is not `=>`, it's a syntax error anyways.
......@@ -4985,7 +4983,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatementListItem(
break;
case Token::ASYNC:
if (PeekAhead() == Token::FUNCTION &&
!scanner()->HasAnyLineTerminatorAfterNext()) {
!scanner()->HasLineTerminatorAfterNext()) {
Consume(Token::ASYNC);
return ParseAsyncFunctionDeclaration(nullptr, false, ok);
}
......@@ -5086,7 +5084,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatement(
case Token::VAR:
return ParseVariableStatement(kStatement, nullptr, ok);
case Token::ASYNC:
if (!scanner()->HasAnyLineTerminatorAfterNext() &&
if (!scanner()->HasLineTerminatorAfterNext() &&
PeekAhead() == Token::FUNCTION) {
impl()->ReportMessageAt(
scanner()->peek_location(),
......@@ -5223,7 +5221,7 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement(
// However, ASI may insert a line break before an identifier or a brace.
if (next_next != Token::LBRACK &&
((next_next != Token::LBRACE && next_next != Token::IDENTIFIER) ||
scanner_->HasAnyLineTerminatorAfterNext())) {
scanner_->HasLineTerminatorAfterNext())) {
break;
}
impl()->ReportMessageAt(scanner()->peek_location(),
......@@ -5256,7 +5254,7 @@ ParserBase<Impl>::ParseExpressionOrLabelledStatement(
// A native function declaration starts with "native function" with
// no line-terminator between the two words.
if (extension_ != nullptr && peek() == Token::FUNCTION &&
!scanner()->HasAnyLineTerminatorBeforeNext() && impl()->IsNative(expr) &&
!scanner()->HasLineTerminatorBeforeNext() && impl()->IsNative(expr) &&
!scanner()->literal_contains_escapes()) {
return ParseNativeDeclaration(ok);
}
......@@ -5309,7 +5307,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseContinueStatement(
Expect(Token::CONTINUE, CHECK_OK);
IdentifierT label = impl()->NullIdentifier();
Token::Value tok = peek();
if (!scanner()->HasAnyLineTerminatorBeforeNext() && tok != Token::SEMICOLON &&
if (!scanner()->HasLineTerminatorBeforeNext() && tok != Token::SEMICOLON &&
tok != Token::RBRACE && tok != Token::EOS) {
// ECMA allows "eval" or "arguments" as labels even in strict mode.
label = ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
......@@ -5346,7 +5344,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseBreakStatement(
Expect(Token::BREAK, CHECK_OK);
IdentifierT label = impl()->NullIdentifier();
Token::Value tok = peek();
if (!scanner()->HasAnyLineTerminatorBeforeNext() && tok != Token::SEMICOLON &&
if (!scanner()->HasLineTerminatorBeforeNext() && tok != Token::SEMICOLON &&
tok != Token::RBRACE && tok != Token::EOS) {
// ECMA allows "eval" or "arguments" as labels even in strict mode.
label = ParseIdentifier(kAllowRestrictedIdentifiers, CHECK_OK);
......@@ -5400,7 +5398,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseReturnStatement(
Token::Value tok = peek();
ExpressionT return_value = impl()->NullExpression();
if (scanner()->HasAnyLineTerminatorBeforeNext() || tok == Token::SEMICOLON ||
if (scanner()->HasLineTerminatorBeforeNext() || tok == Token::SEMICOLON ||
tok == Token::RBRACE || tok == Token::EOS) {
if (IsDerivedConstructor(function_state_->kind())) {
return_value = impl()->ThisExpression(loc.beg_pos);
......@@ -5520,7 +5518,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseThrowStatement(
Expect(Token::THROW, CHECK_OK);
int pos = position();
if (scanner()->HasAnyLineTerminatorBeforeNext()) {
if (scanner()->HasLineTerminatorBeforeNext()) {
ReportMessage(MessageTemplate::kNewlineAfterThrow);
*ok = false;
return impl()->NullStatement();
......
......@@ -776,7 +776,7 @@ FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
if (IsArrowFunction(kind)) {
if (IsAsyncFunction(kind)) {
DCHECK(!scanner()->HasAnyLineTerminatorAfterNext());
DCHECK(!scanner()->HasLineTerminatorAfterNext());
if (!Check(Token::ASYNC)) {
CHECK(stack_overflow());
return nullptr;
......@@ -1179,7 +1179,7 @@ Statement* Parser::ParseExportDefault(bool* ok) {
case Token::ASYNC:
if (PeekAhead() == Token::FUNCTION &&
!scanner()->HasAnyLineTerminatorAfterNext()) {
!scanner()->HasLineTerminatorAfterNext()) {
Consume(Token::ASYNC);
result = ParseAsyncFunctionDeclaration(&local_names, true, CHECK_OK);
break;
......
......@@ -384,7 +384,6 @@ Token::Value Scanner::Next() {
if (V8_LIKELY(next_next().token == Token::UNINITIALIZED)) {
next_ = previous;
next().after_line_terminator = false;
next().after_multiline_comment = false;
Scan();
} else {
next_ = next_next_;
......@@ -407,7 +406,6 @@ Token::Value Scanner::PeekAhead() {
TokenDesc* temp = next_;
next_ = next_next_;
next().after_line_terminator = false;
next().after_multiline_comment = false;
Scan();
next_next_ = next_;
next_ = temp;
......@@ -502,10 +500,10 @@ Token::Value Scanner::SkipMultiLineComment() {
while (c0_ != kEndOfInput) {
DCHECK(!unibrow::IsLineTerminator(kEndOfInput));
if (!next().after_multiline_comment && unibrow::IsLineTerminator(c0_)) {
if (!HasLineTerminatorBeforeNext() && unibrow::IsLineTerminator(c0_)) {
// Following ECMA-262, section 7.4, a comment containing
// a newline will make the comment count as a line-terminator.
next().after_multiline_comment = true;
next().after_line_terminator = true;
}
while (V8_UNLIKELY(c0_ == '*')) {
......@@ -638,7 +636,7 @@ void Scanner::Scan() {
Advance();
if (c0_ == '-') {
Advance();
if (c0_ == '>' && HasAnyLineTerminatorBeforeNext()) {
if (c0_ == '>' && HasLineTerminatorBeforeNext()) {
// For compatibility with SpiderMonkey, we skip lines that
// start with an HTML comment end '-->'.
token = SkipSingleHTMLComment();
......@@ -845,7 +843,6 @@ void Scanner::SeekForward(int pos) {
// of the end of a function (at the "}" token). It doesn't matter
// whether there was a line terminator in the part we skip.
next().after_line_terminator = false;
next().after_multiline_comment = false;
}
Scan();
}
......@@ -1806,7 +1803,6 @@ void Scanner::SeekNext(size_t position) {
// 3, re-scan, by scanning the look-ahead char + 1 token (next_).
c0_ = source_->Advance();
next().after_line_terminator = false;
next().after_multiline_comment = false;
Scan();
DCHECK_EQ(next().location.beg_pos, static_cast<int>(position));
}
......
......@@ -345,11 +345,11 @@ class Scanner {
// Returns true if there was a line terminator before the peek'ed token,
// possibly inside a multi-line comment.
bool HasAnyLineTerminatorBeforeNext() const {
return next().after_line_terminator || next().after_multiline_comment;
bool HasLineTerminatorBeforeNext() const {
return next().after_line_terminator;
}
bool HasAnyLineTerminatorAfterNext() {
bool HasLineTerminatorAfterNext() {
Token::Value ensure_next_next = PeekAhead();
USE(ensure_next_next);
return next_next().after_line_terminator;
......@@ -526,7 +526,6 @@ class Scanner {
Token::Value contextual_token = Token::UNINITIALIZED;
uint32_t smi_value_ = 0;
bool after_line_terminator = false;
bool after_multiline_comment = false;
};
enum NumberKind {
......
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