Chromium Code Reviews| Index: src/scanner.h |
| diff --git a/src/scanner.h b/src/scanner.h |
| index 87ff20b753a0f4314dc0553d2ea3ac7847789811..76c313eb749e01368396fe97336f1d8d188940bb 100644 |
| --- a/src/scanner.h |
| +++ b/src/scanner.h |
| @@ -322,10 +322,8 @@ class Scanner { |
| // if aborting the scanning before it's complete. |
| class LiteralScope { |
| public: |
| - explicit LiteralScope(Scanner* self, bool capture_raw = false) |
| - : scanner_(self), complete_(false) { |
| + explicit LiteralScope(Scanner* self) : scanner_(self), complete_(false) { |
| scanner_->StartLiteral(); |
| - if (capture_raw) scanner_->StartRawLiteral(); |
| } |
| ~LiteralScope() { |
| if (!complete_) scanner_->DropLiteral(); |
| @@ -506,6 +504,7 @@ class Scanner { |
| static const int kCharacterLookaheadBufferSize = 1; |
| // Scans octal escape sequence. Also accepts "\0" decimal escape sequence. |
| + template <bool capture_raw> |
| uc32 ScanOctalEscape(uc32 c, int length); |
| // Call this after setting source_ to the input. |
| @@ -529,7 +528,6 @@ class Scanner { |
| inline void StartRawLiteral() { |
| raw_literal_buffer_.Reset(); |
| next_.raw_literal_chars = &raw_literal_buffer_; |
| - capturing_raw_literal_ = true; |
| } |
| INLINE(void AddLiteralChar(uc32 c)) { |
| @@ -538,26 +536,25 @@ class Scanner { |
| } |
| INLINE(void AddRawLiteralChar(uc32 c)) { |
| - DCHECK(capturing_raw_literal_); |
| DCHECK_NOT_NULL(next_.raw_literal_chars); |
| next_.raw_literal_chars->AddChar(c); |
| } |
| INLINE(void ReduceRawLiteralLength(int delta)) { |
| - DCHECK(capturing_raw_literal_); |
| DCHECK_NOT_NULL(next_.raw_literal_chars); |
| next_.raw_literal_chars->ReduceLength(delta); |
| } |
| // Complete scanning of a literal. |
| - inline void TerminateLiteral() { capturing_raw_literal_ = false; } |
| + inline void TerminateLiteral() { |
|
Dmitry Lomov (no reviews)
2014/12/04 18:04:23
Nit: if it does nothing, why not remove it?
arv (Not doing code reviews)
2014/12/04 18:07:09
Old code... I guess at some point it did something
|
| + // Does nothing in the current implementation. |
| + } |
| // Stops scanning of a literal and drop the collected characters, |
| // e.g., due to an encountered error. |
| inline void DropLiteral() { |
| next_.literal_chars = NULL; |
| next_.raw_literal_chars = NULL; |
| - capturing_raw_literal_ = false; |
| } |
| inline void AddLiteralCharAdvance() { |
| @@ -566,8 +563,9 @@ class Scanner { |
| } |
| // Low-level scanning support. |
| + template <bool capture_raw> |
| void Advance() { |
| - if (capturing_raw_literal_) { |
| + if (capture_raw) { |
| AddRawLiteralChar(c0_); |
| } |
| c0_ = source_->Advance(); |
| @@ -581,14 +579,14 @@ class Scanner { |
| } |
| } |
| + void Advance() { Advance<false>(); } |
| + |
| void PushBack(uc32 ch) { |
| if (ch > static_cast<uc32>(unibrow::Utf16::kMaxNonSurrogateCharCode)) { |
| source_->PushBack(unibrow::Utf16::TrailSurrogate(c0_)); |
| source_->PushBack(unibrow::Utf16::LeadSurrogate(c0_)); |
| - if (capturing_raw_literal_) ReduceRawLiteralLength(2); |
| } else { |
| source_->PushBack(c0_); |
| - if (capturing_raw_literal_) ReduceRawLiteralLength(1); |
| } |
| c0_ = ch; |
| } |
| @@ -658,11 +656,12 @@ class Scanner { |
| return current_.raw_literal_chars->is_one_byte(); |
| } |
| - |
| + template <bool capture_raw> |
| uc32 ScanHexNumber(int expected_length); |
| // Scan a number of any length but not bigger than max_value. For example, the |
| // number can be 000000001, so it's very long in characters but its value is |
| // small. |
| + template <bool capture_raw> |
| uc32 ScanUnlimitedLengthHexNumber(int max_value); |
| // Scans a single JavaScript token. |
| @@ -686,11 +685,13 @@ class Scanner { |
| // Scans an escape-sequence which is part of a string and adds the |
| // decoded character to the current literal. Returns true if a pattern |
| // is scanned. |
| + template <bool capture_raw> |
| bool ScanEscape(); |
| // Decodes a Unicode escape-sequence which is part of an identifier. |
| // If the escape sequence cannot be decoded the result is kBadChar. |
| uc32 ScanIdentifierUnicodeEscape(); |
| // Helper for the above functions. |
| + template <bool capture_raw> |
| uc32 ScanUnicodeEscape(); |
| Token::Value ScanTemplateSpan(); |
| @@ -713,10 +714,6 @@ class Scanner { |
| // Buffer to store raw string values |
| LiteralBuffer raw_literal_buffer_; |
| - // We only need to capture the raw literal when we are scanning template |
| - // literal spans. |
| - bool capturing_raw_literal_; |
| - |
| TokenDesc current_; // desc for current token (as returned by Next()) |
| TokenDesc next_; // desc for next token (one token look-ahead) |