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_PARSING_SCANNER_H_ | 7 #ifndef V8_PARSING_SCANNER_H_ |
| 8 #define V8_PARSING_SCANNER_H_ | 8 #define V8_PARSING_SCANNER_H_ |
| 9 | 9 |
| 10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
| 11 #include "src/base/logging.h" | 11 #include "src/base/logging.h" |
| 12 #include "src/char-predicates.h" | 12 #include "src/char-predicates.h" |
| 13 #include "src/collector.h" | 13 #include "src/collector.h" |
| 14 #include "src/globals.h" | 14 #include "src/globals.h" |
| 15 #include "src/hashmap.h" | 15 #include "src/hashmap.h" |
| 16 #include "src/list.h" | 16 #include "src/list.h" |
| 17 #include "src/messages.h" | |
| 17 #include "src/parsing/token.h" | 18 #include "src/parsing/token.h" |
| 18 #include "src/unicode.h" | 19 #include "src/unicode.h" |
| 19 #include "src/unicode-decoder.h" | 20 #include "src/unicode-decoder.h" |
| 20 | 21 |
| 21 namespace v8 { | 22 namespace v8 { |
| 22 namespace internal { | 23 namespace internal { |
| 23 | 24 |
| 24 | 25 |
| 25 class AstRawString; | 26 class AstRawString; |
| 26 class AstValueFactory; | 27 class AstValueFactory; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 // Returns the next token and advances input. | 348 // Returns the next token and advances input. |
| 348 Token::Value Next(); | 349 Token::Value Next(); |
| 349 // Returns the token following peek() | 350 // Returns the token following peek() |
| 350 Token::Value PeekAhead(); | 351 Token::Value PeekAhead(); |
| 351 // Returns the current token again. | 352 // Returns the current token again. |
| 352 Token::Value current_token() { return current_.token; } | 353 Token::Value current_token() { return current_.token; } |
| 353 // Returns the location information for the current token | 354 // Returns the location information for the current token |
| 354 // (the token last returned by Next()). | 355 // (the token last returned by Next()). |
| 355 Location location() const { return current_.location; } | 356 Location location() const { return current_.location; } |
| 356 | 357 |
| 358 bool has_error() const { return scanner_error_ != MessageTemplate::kNone; } | |
| 359 MessageTemplate::Template error() const { return scanner_error_; } | |
| 360 Location error_location() const { return scanner_error_location_; } | |
| 361 | |
| 357 // Similar functions for the upcoming token. | 362 // Similar functions for the upcoming token. |
| 358 | 363 |
| 359 // One token look-ahead (past the token returned by Next()). | 364 // One token look-ahead (past the token returned by Next()). |
| 360 Token::Value peek() const { return next_.token; } | 365 Token::Value peek() const { return next_.token; } |
| 361 | 366 |
| 362 Location peek_location() const { return next_.location; } | 367 Location peek_location() const { return next_.location; } |
| 363 | 368 |
| 364 bool literal_contains_escapes() const { | 369 bool literal_contains_escapes() const { |
| 365 return LiteralContainsEscapes(current_); | 370 return LiteralContainsEscapes(current_); |
| 366 } | 371 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 // Call this after setting source_ to the input. | 474 // Call this after setting source_ to the input. |
| 470 void Init() { | 475 void Init() { |
| 471 // Set c0_ (one character ahead) | 476 // Set c0_ (one character ahead) |
| 472 STATIC_ASSERT(kCharacterLookaheadBufferSize == 1); | 477 STATIC_ASSERT(kCharacterLookaheadBufferSize == 1); |
| 473 Advance(); | 478 Advance(); |
| 474 // Initialize current_ to not refer to a literal. | 479 // Initialize current_ to not refer to a literal. |
| 475 current_.literal_chars = NULL; | 480 current_.literal_chars = NULL; |
| 476 current_.raw_literal_chars = NULL; | 481 current_.raw_literal_chars = NULL; |
| 477 next_next_.token = Token::UNINITIALIZED; | 482 next_next_.token = Token::UNINITIALIZED; |
| 478 found_html_comment_ = false; | 483 found_html_comment_ = false; |
| 484 scanner_error_ = MessageTemplate::kNone; | |
| 479 } | 485 } |
| 480 | 486 |
| 481 // Support BookmarkScope functionality. | 487 // Support BookmarkScope functionality. |
| 482 bool SetBookmark(); | 488 bool SetBookmark(); |
| 483 void ResetToBookmark(); | 489 void ResetToBookmark(); |
| 484 bool BookmarkHasBeenSet(); | 490 bool BookmarkHasBeenSet(); |
| 485 bool BookmarkHasBeenReset(); | 491 bool BookmarkHasBeenReset(); |
| 486 void DropBookmark(); | 492 void DropBookmark(); |
| 487 static void CopyTokenDesc(TokenDesc* to, TokenDesc* from); | 493 static void CopyTokenDesc(TokenDesc* to, TokenDesc* from); |
| 488 | 494 |
| 495 void ReportScannerError(MessageTemplate::Template error, int begin, int end) { | |
|
adamk
2016/03/18 18:21:55
Please put the location before |error| (same below
caitp (gmail)
2016/03/21 16:15:03
Done.
| |
| 496 if (has_error()) return; | |
| 497 scanner_error_ = error; | |
| 498 scanner_error_location_ = Location(begin, end); | |
| 499 } | |
| 500 | |
| 501 void ReportScannerError(MessageTemplate::Template error, int begin) { | |
| 502 if (has_error()) return; | |
| 503 scanner_error_ = error; | |
| 504 scanner_error_location_ = Location(begin, begin + 1); | |
| 505 } | |
| 506 | |
| 489 // Literal buffer support | 507 // Literal buffer support |
| 490 inline void StartLiteral() { | 508 inline void StartLiteral() { |
| 491 LiteralBuffer* free_buffer = | 509 LiteralBuffer* free_buffer = |
| 492 (current_.literal_chars == &literal_buffer0_) | 510 (current_.literal_chars == &literal_buffer0_) |
| 493 ? &literal_buffer1_ | 511 ? &literal_buffer1_ |
| 494 : (current_.literal_chars == &literal_buffer1_) ? &literal_buffer2_ | 512 : (current_.literal_chars == &literal_buffer1_) ? &literal_buffer2_ |
| 495 : &literal_buffer0_; | 513 : &literal_buffer0_; |
| 496 free_buffer->Reset(); | 514 free_buffer->Reset(); |
| 497 next_.literal_chars = free_buffer; | 515 next_.literal_chars = free_buffer; |
| 498 } | 516 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 } | 642 } |
| 625 Vector<const uint16_t> raw_literal_two_byte_string() { | 643 Vector<const uint16_t> raw_literal_two_byte_string() { |
| 626 DCHECK_NOT_NULL(current_.raw_literal_chars); | 644 DCHECK_NOT_NULL(current_.raw_literal_chars); |
| 627 return current_.raw_literal_chars->two_byte_literal(); | 645 return current_.raw_literal_chars->two_byte_literal(); |
| 628 } | 646 } |
| 629 bool is_raw_literal_one_byte() { | 647 bool is_raw_literal_one_byte() { |
| 630 DCHECK_NOT_NULL(current_.raw_literal_chars); | 648 DCHECK_NOT_NULL(current_.raw_literal_chars); |
| 631 return current_.raw_literal_chars->is_one_byte(); | 649 return current_.raw_literal_chars->is_one_byte(); |
| 632 } | 650 } |
| 633 | 651 |
| 634 template <bool capture_raw> | 652 template <bool capture_raw, bool unicode = false> |
| 635 uc32 ScanHexNumber(int expected_length); | 653 uc32 ScanHexNumber(int expected_length); |
| 636 // Scan a number of any length but not bigger than max_value. For example, the | 654 // Scan a number of any length but not bigger than max_value. For example, the |
| 637 // number can be 000000001, so it's very long in characters but its value is | 655 // number can be 000000001, so it's very long in characters but its value is |
| 638 // small. | 656 // small. |
| 639 template <bool capture_raw> | 657 template <bool capture_raw> |
| 640 uc32 ScanUnlimitedLengthHexNumber(int max_value); | 658 uc32 ScanUnlimitedLengthHexNumber(int max_value, bool& bad_codepoint); |
| 641 | 659 |
| 642 // Scans a single JavaScript token. | 660 // Scans a single JavaScript token. |
| 643 void Scan(); | 661 void Scan(); |
| 644 | 662 |
| 645 bool SkipWhiteSpace(); | 663 bool SkipWhiteSpace(); |
| 646 Token::Value SkipSingleLineComment(); | 664 Token::Value SkipSingleLineComment(); |
| 647 Token::Value SkipSourceURLComment(); | 665 Token::Value SkipSourceURLComment(); |
| 648 void TryToParseSourceURLComment(); | 666 void TryToParseSourceURLComment(); |
| 649 Token::Value SkipMultiLineComment(); | 667 Token::Value SkipMultiLineComment(); |
| 650 // Scans a possible HTML comment -- begins with '<!'. | 668 // Scans a possible HTML comment -- begins with '<!'. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 // Whether there is a line terminator whitespace character after | 769 // Whether there is a line terminator whitespace character after |
| 752 // the current token, and before the next. Does not count newlines | 770 // the current token, and before the next. Does not count newlines |
| 753 // inside multiline comments. | 771 // inside multiline comments. |
| 754 bool has_line_terminator_before_next_; | 772 bool has_line_terminator_before_next_; |
| 755 // Whether there is a multi-line comment that contains a | 773 // Whether there is a multi-line comment that contains a |
| 756 // line-terminator after the current token, and before the next. | 774 // line-terminator after the current token, and before the next. |
| 757 bool has_multiline_comment_before_next_; | 775 bool has_multiline_comment_before_next_; |
| 758 | 776 |
| 759 // Whether this scanner encountered an HTML comment. | 777 // Whether this scanner encountered an HTML comment. |
| 760 bool found_html_comment_; | 778 bool found_html_comment_; |
| 779 | |
| 780 MessageTemplate::Template scanner_error_; | |
| 781 Location scanner_error_location_; | |
| 761 }; | 782 }; |
| 762 | 783 |
| 763 } // namespace internal | 784 } // namespace internal |
| 764 } // namespace v8 | 785 } // namespace v8 |
| 765 | 786 |
| 766 #endif // V8_PARSING_SCANNER_H_ | 787 #endif // V8_PARSING_SCANNER_H_ |
| OLD | NEW |