Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Features shared by parsing and pre-parsing scanners. | 5 // Features shared by parsing and pre-parsing scanners. |
| 6 | 6 |
| 7 #ifndef V8_SCANNER_H_ | 7 #ifndef V8_SCANNER_H_ |
| 8 #define V8_SCANNER_H_ | 8 #define V8_SCANNER_H_ |
| 9 | 9 |
| 10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 | 392 |
| 393 // -1 is outside of the range of any real source code. | 393 // -1 is outside of the range of any real source code. |
| 394 static const int kNoOctalLocation = -1; | 394 static const int kNoOctalLocation = -1; |
| 395 | 395 |
| 396 explicit Scanner(UnicodeCache* scanner_contants); | 396 explicit Scanner(UnicodeCache* scanner_contants); |
| 397 | 397 |
| 398 void Initialize(Utf16CharacterStream* source); | 398 void Initialize(Utf16CharacterStream* source); |
| 399 | 399 |
| 400 // Returns the next token and advances input. | 400 // Returns the next token and advances input. |
| 401 Token::Value Next(); | 401 Token::Value Next(); |
| 402 // Returns the token following peek() | |
| 403 Token::Value PeekAhead(); | |
| 402 // Returns the current token again. | 404 // Returns the current token again. |
| 403 Token::Value current_token() { return current_.token; } | 405 Token::Value current_token() { return current_.token; } |
| 404 // Returns the location information for the current token | 406 // Returns the location information for the current token |
| 405 // (the token last returned by Next()). | 407 // (the token last returned by Next()). |
| 406 Location location() const { return current_.location; } | 408 Location location() const { return current_.location; } |
| 407 | 409 |
| 408 // Similar functions for the upcoming token. | 410 // Similar functions for the upcoming token. |
| 409 | 411 |
| 410 // One token look-ahead (past the token returned by Next()). | 412 // One token look-ahead (past the token returned by Next()). |
| 411 Token::Value peek() const { return next_.token; } | 413 Token::Value peek() const { return next_.token; } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 uc32 ScanOctalEscape(uc32 c, int length); | 522 uc32 ScanOctalEscape(uc32 c, int length); |
| 521 | 523 |
| 522 // Call this after setting source_ to the input. | 524 // Call this after setting source_ to the input. |
| 523 void Init() { | 525 void Init() { |
| 524 // Set c0_ (one character ahead) | 526 // Set c0_ (one character ahead) |
| 525 STATIC_ASSERT(kCharacterLookaheadBufferSize == 1); | 527 STATIC_ASSERT(kCharacterLookaheadBufferSize == 1); |
| 526 Advance(); | 528 Advance(); |
| 527 // Initialize current_ to not refer to a literal. | 529 // Initialize current_ to not refer to a literal. |
| 528 current_.literal_chars = NULL; | 530 current_.literal_chars = NULL; |
| 529 current_.raw_literal_chars = NULL; | 531 current_.raw_literal_chars = NULL; |
| 532 uber_next_.token = Token::UNINITIALIZED; | |
| 533 prev_.token = Token::UNINITIALIZED; | |
| 530 } | 534 } |
| 531 | 535 |
| 532 // Support BookmarkScope functionality. | 536 // Support BookmarkScope functionality. |
| 533 bool SetBookmark(); | 537 bool SetBookmark(); |
| 534 void ResetToBookmark(); | 538 void ResetToBookmark(); |
| 535 bool BookmarkHasBeenSet(); | 539 bool BookmarkHasBeenSet(); |
| 536 bool BookmarkHasBeenReset(); | 540 bool BookmarkHasBeenReset(); |
| 537 void DropBookmark(); | 541 void DropBookmark(); |
| 538 static void CopyTokenDesc(TokenDesc* to, TokenDesc* from); | 542 static void CopyTokenDesc(TokenDesc* to, TokenDesc* from); |
| 539 | 543 |
| 540 // Literal buffer support | 544 // Literal buffer support |
| 541 inline void StartLiteral() { | 545 inline void StartLiteral() { |
| 542 LiteralBuffer* free_buffer = (current_.literal_chars == &literal_buffer1_) ? | 546 LiteralBuffer* free_buffer = |
| 543 &literal_buffer2_ : &literal_buffer1_; | 547 (current_.literal_chars == &literal_buffers_[0]) |
|
adamk
2015/08/15 00:28:31
Why switch to using an array for this? The advanta
adamk
2015/08/17 18:24:39
I didn't see this addressed in the latest patch.
Dan Ehrenberg
2015/08/17 18:35:19
Oops, fixed.
| |
| 548 ? &literal_buffers_[1] | |
| 549 : (current_.literal_chars == &literal_buffers_[1]) | |
| 550 ? &literal_buffers_[2] | |
| 551 : &literal_buffers_[0]; | |
| 544 free_buffer->Reset(); | 552 free_buffer->Reset(); |
| 545 next_.literal_chars = free_buffer; | 553 next_.literal_chars = free_buffer; |
| 546 } | 554 } |
| 547 | 555 |
| 548 inline void StartRawLiteral() { | 556 inline void StartRawLiteral() { |
| 549 LiteralBuffer* free_buffer = | 557 LiteralBuffer* free_buffer = |
| 550 (current_.raw_literal_chars == &raw_literal_buffer1_) ? | 558 (current_.raw_literal_chars == &raw_literal_buffers_[0]) |
| 551 &raw_literal_buffer2_ : &raw_literal_buffer1_; | 559 ? &raw_literal_buffers_[1] |
| 560 : (current_.raw_literal_chars == &raw_literal_buffers_[1]) | |
| 561 ? &raw_literal_buffers_[2] | |
| 562 : &raw_literal_buffers_[0]; | |
| 552 free_buffer->Reset(); | 563 free_buffer->Reset(); |
| 553 next_.raw_literal_chars = free_buffer; | 564 next_.raw_literal_chars = free_buffer; |
| 554 } | 565 } |
| 555 | 566 |
| 556 INLINE(void AddLiteralChar(uc32 c)) { | 567 INLINE(void AddLiteralChar(uc32 c)) { |
| 557 DCHECK_NOT_NULL(next_.literal_chars); | 568 DCHECK_NOT_NULL(next_.literal_chars); |
| 558 next_.literal_chars->AddChar(c); | 569 next_.literal_chars->AddChar(c); |
| 559 } | 570 } |
| 560 | 571 |
| 561 INLINE(void AddRawLiteralChar(uc32 c)) { | 572 INLINE(void AddRawLiteralChar(uc32 c)) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 Token::Value ScanTemplateSpan(); | 729 Token::Value ScanTemplateSpan(); |
| 719 | 730 |
| 720 // Return the current source position. | 731 // Return the current source position. |
| 721 int source_pos() { | 732 int source_pos() { |
| 722 return static_cast<int>(source_->pos()) - kCharacterLookaheadBufferSize; | 733 return static_cast<int>(source_->pos()) - kCharacterLookaheadBufferSize; |
| 723 } | 734 } |
| 724 | 735 |
| 725 UnicodeCache* unicode_cache_; | 736 UnicodeCache* unicode_cache_; |
| 726 | 737 |
| 727 // Buffers collecting literal strings, numbers, etc. | 738 // Buffers collecting literal strings, numbers, etc. |
| 728 LiteralBuffer literal_buffer1_; | 739 LiteralBuffer literal_buffers_[3]; |
| 729 LiteralBuffer literal_buffer2_; | |
| 730 | 740 |
| 731 // Values parsed from magic comments. | 741 // Values parsed from magic comments. |
| 732 LiteralBuffer source_url_; | 742 LiteralBuffer source_url_; |
| 733 LiteralBuffer source_mapping_url_; | 743 LiteralBuffer source_mapping_url_; |
| 734 | 744 |
| 735 // Buffer to store raw string values | 745 // Buffer to store raw string values |
| 736 LiteralBuffer raw_literal_buffer1_; | 746 LiteralBuffer raw_literal_buffers_[3]; |
| 737 LiteralBuffer raw_literal_buffer2_; | |
| 738 | 747 |
| 739 TokenDesc current_; // desc for current token (as returned by Next()) | 748 TokenDesc current_; // desc for current token (as returned by Next()) |
| 740 TokenDesc next_; // desc for next token (one token look-ahead) | 749 TokenDesc next_; // desc for next token (one token look-ahead) |
| 750 TokenDesc uber_next_; // desc for the token after next (push-back) | |
|
adamk
2015/08/15 00:28:31
I think "next_next_" is clearer in English. That's
| |
| 751 TokenDesc prev_; // desc for the previous token (stash for pushback) | |
| 741 | 752 |
| 742 // Variables for Scanner::BookmarkScope and the *Bookmark implementation. | 753 // Variables for Scanner::BookmarkScope and the *Bookmark implementation. |
| 743 // These variables contain the scanner state when a bookmark is set. | 754 // These variables contain the scanner state when a bookmark is set. |
| 744 // | 755 // |
| 745 // We will use bookmark_c0_ as a 'control' variable, where: | 756 // We will use bookmark_c0_ as a 'control' variable, where: |
| 746 // - bookmark_c0_ >= 0: A bookmark has been set and this contains c0_. | 757 // - bookmark_c0_ >= 0: A bookmark has been set and this contains c0_. |
| 747 // - bookmark_c0_ == -1: No bookmark has been set. | 758 // - bookmark_c0_ == -1: No bookmark has been set. |
| 748 // - bookmark_c0_ == -2: The bookmark has been applied (ResetToBookmark). | 759 // - bookmark_c0_ == -2: The bookmark has been applied (ResetToBookmark). |
| 749 // | 760 // |
| 750 // Which state is being bookmarked? The parser state is distributed over | 761 // Which state is being bookmarked? The parser state is distributed over |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 // inside multiline comments. | 796 // inside multiline comments. |
| 786 bool has_line_terminator_before_next_; | 797 bool has_line_terminator_before_next_; |
| 787 // Whether there is a multi-line comment that contains a | 798 // Whether there is a multi-line comment that contains a |
| 788 // line-terminator after the current token, and before the next. | 799 // line-terminator after the current token, and before the next. |
| 789 bool has_multiline_comment_before_next_; | 800 bool has_multiline_comment_before_next_; |
| 790 }; | 801 }; |
| 791 | 802 |
| 792 } } // namespace v8::internal | 803 } } // namespace v8::internal |
| 793 | 804 |
| 794 #endif // V8_SCANNER_H_ | 805 #endif // V8_SCANNER_H_ |
| OLD | NEW |