Commit 60cbde18 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[scanner] Reduce reliance on PushBack by Peeking more

Change-Id: I50f729eac8d8b0c25a1f83f2b1f86800f21a8a8b
Reviewed-on: https://chromium-review.googlesource.com/1183301
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55272}
parent eedc7dbf
...@@ -672,12 +672,12 @@ void Scanner::Scan() { ...@@ -672,12 +672,12 @@ void Scanner::Scan() {
// / // /* /= // / // /* /=
Advance(); Advance();
if (c0_ == '/') { if (c0_ == '/') {
uc32 c = Peek();
if (c == '#' || c == '@') {
Advance(); Advance();
if (c0_ == '#' || c0_ == '@') {
Advance(); Advance();
token = SkipSourceURLComment(); token = SkipSourceURLComment();
} else { } else {
PushBack(c0_);
token = SkipSingleLineComment(); token = SkipSingleLineComment();
} }
} else if (c0_ == '*') { } else if (c0_ == '*') {
...@@ -726,12 +726,10 @@ void Scanner::Scan() { ...@@ -726,12 +726,10 @@ void Scanner::Scan() {
} else { } else {
token = Token::PERIOD; token = Token::PERIOD;
if (c0_ == '.') { if (c0_ == '.') {
if (Peek() == '.') {
Advance(); Advance();
if (c0_ == '.') {
Advance(); Advance();
token = Token::ELLIPSIS; token = Token::ELLIPSIS;
} else {
PushBack('.');
} }
} }
} }
...@@ -963,15 +961,14 @@ Token::Value Scanner::ScanPrivateName() { ...@@ -963,15 +961,14 @@ Token::Value Scanner::ScanPrivateName() {
LiteralScope literal(this); LiteralScope literal(this);
DCHECK_EQ(c0_, '#'); DCHECK_EQ(c0_, '#');
AddLiteralCharAdvance();
DCHECK(!unicode_cache_->IsIdentifierStart(kEndOfInput)); DCHECK(!unicode_cache_->IsIdentifierStart(kEndOfInput));
if (!unicode_cache_->IsIdentifierStart(c0_)) { if (!unicode_cache_->IsIdentifierStart(Peek())) {
PushBack(c0_);
ReportScannerError(source_pos(), ReportScannerError(source_pos(),
MessageTemplate::kInvalidOrUnexpectedToken); MessageTemplate::kInvalidOrUnexpectedToken);
return Token::ILLEGAL; return Token::ILLEGAL;
} }
AddLiteralCharAdvance();
Token::Value token = ScanIdentifierOrKeywordInner(&literal); Token::Value token = ScanIdentifierOrKeywordInner(&literal);
return token == Token::ILLEGAL ? Token::ILLEGAL : Token::PRIVATE_NAME; return token == Token::ILLEGAL ? Token::ILLEGAL : Token::PRIVATE_NAME;
} }
...@@ -1002,14 +999,16 @@ Token::Value Scanner::ScanTemplateSpan() { ...@@ -1002,14 +999,16 @@ Token::Value Scanner::ScanTemplateSpan() {
const bool capture_raw = true; const bool capture_raw = true;
while (true) { while (true) {
uc32 c = c0_; uc32 c = c0_;
Advance();
if (c == '`') { if (c == '`') {
Advance(); // Consume '`'
result = Token::TEMPLATE_TAIL; result = Token::TEMPLATE_TAIL;
break; break;
} else if (c == '$' && c0_ == '{') { } else if (c == '$' && Peek() == '{') {
Advance(); // Consume '$'
Advance(); // Consume '{' Advance(); // Consume '{'
break; break;
} else if (c == '\\') { } else if (c == '\\') {
Advance(); // Consume '\\'
DCHECK(!unibrow::IsLineTerminator(kEndOfInput)); DCHECK(!unibrow::IsLineTerminator(kEndOfInput));
if (capture_raw) AddRawLiteralChar('\\'); if (capture_raw) AddRawLiteralChar('\\');
if (unibrow::IsLineTerminator(c0_)) { if (unibrow::IsLineTerminator(c0_)) {
...@@ -1034,14 +1033,14 @@ Token::Value Scanner::ScanTemplateSpan() { ...@@ -1034,14 +1033,14 @@ Token::Value Scanner::ScanTemplateSpan() {
} }
} else if (c < 0) { } else if (c < 0) {
// Unterminated template literal // Unterminated template literal
PushBack(c);
break; break;
} else { } else {
Advance(); // Consume c.
// The TRV of LineTerminatorSequence :: <CR> is the CV 0x000A. // The TRV of LineTerminatorSequence :: <CR> is the CV 0x000A.
// The TRV of LineTerminatorSequence :: <CR><LF> is the sequence // The TRV of LineTerminatorSequence :: <CR><LF> is the sequence
// consisting of the CV 0x000A. // consisting of the CV 0x000A.
if (c == '\r') { if (c == '\r') {
if (c0_ == '\n') Advance(); // Skip \n if (c0_ == '\n') Advance(); // Consume '\n'
c = '\n'; c = '\n';
} }
if (capture_raw) AddRawLiteralChar(c); if (capture_raw) AddRawLiteralChar(c);
......
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