From 4e9ac0a60c6b185f572c4f5206953be16128f5ba Mon Sep 17 00:00:00 2001 From: Toon Verwaest Date: Tue, 28 Aug 2018 11:14:02 +0200 Subject: [PATCH] [scanner] Simplify Scan Change-Id: I331ff09ee06db39e2ca051db0a91823f5b8fb402 Reviewed-on: https://chromium-review.googlesource.com/1193262 Reviewed-by: Igor Sheludko Commit-Queue: Toon Verwaest Cr-Commit-Position: refs/heads/master@{#55445} --- src/parsing/scanner.cc | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/parsing/scanner.cc b/src/parsing/scanner.cc index 781832c2e6..299e25af3d 100644 --- a/src/parsing/scanner.cc +++ b/src/parsing/scanner.cc @@ -540,23 +540,20 @@ void Scanner::Scan() { next().invalid_template_escape_message = MessageTemplate::kNone; Token::Value token; - do { - if (static_cast(c0_) <= 0x7F) { - Token::Value token = static_cast(one_char_tokens[c0_]); - if (token != Token::ILLEGAL) { - int pos = source_pos(); - next().token = token; - next().contextual_token = Token::UNINITIALIZED; - next().location.beg_pos = pos; - next().location.end_pos = pos + 1; - Advance(); - return; - } - } + Token::Value contextual_token = Token::UNINITIALIZED; + do { // Remember the position of the next token next().location.beg_pos = source_pos(); + if (static_cast(c0_) <= 0x7F) { + token = static_cast(one_char_tokens[c0_]); + if (token != Token::ILLEGAL) { + Advance(); + break; + } + } + switch (c0_) { case '"': case '\'': @@ -747,13 +744,16 @@ void Scanner::Scan() { (CombineSurrogatePair() && unicode_cache_->IsIdentifierStart(c0_))) { token = ScanIdentifierOrKeyword(); + if (Token::IsContextualKeyword(token)) { + contextual_token = token; + token = Token::IDENTIFIER; + } } else if (IsDecimalDigit(c0_)) { token = ScanNumber(false); } else if (c0_ == kEndOfInput) { token = Token::EOS; } else { token = SkipWhiteSpace(); - if (token == Token::ILLEGAL) Advance(); } break; } @@ -763,13 +763,8 @@ void Scanner::Scan() { } while (token == Token::WHITESPACE); next().location.end_pos = source_pos(); - if (Token::IsContextualKeyword(token)) { - next().token = Token::IDENTIFIER; - next().contextual_token = token; - } else { - next().token = token; - next().contextual_token = Token::UNINITIALIZED; - } + next().token = token; + next().contextual_token = contextual_token; #ifdef DEBUG SanityCheckTokenDesc(current());