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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 Location location() const { return current_.location; } | 366 Location location() const { return current_.location; } |
367 | 367 |
368 // Similar functions for the upcoming token. | 368 // Similar functions for the upcoming token. |
369 | 369 |
370 // One token look-ahead (past the token returned by Next()). | 370 // One token look-ahead (past the token returned by Next()). |
371 Token::Value peek() const { return next_.token; } | 371 Token::Value peek() const { return next_.token; } |
372 | 372 |
373 Location peek_location() const { return next_.location; } | 373 Location peek_location() const { return next_.location; } |
374 | 374 |
375 bool literal_contains_escapes() const { | 375 bool literal_contains_escapes() const { |
376 Location location = current_.location; | 376 return LiteralContainsEscapes(current_); |
377 int source_length = (location.end_pos - location.beg_pos); | 377 } |
378 if (current_.token == Token::STRING) { | 378 bool next_literal_contains_escapes() const { |
379 // Subtract delimiters. | 379 return LiteralContainsEscapes(next_); |
380 source_length -= 2; | |
381 } | |
382 return current_.literal_chars->length() != source_length; | |
383 } | 380 } |
384 bool is_literal_contextual_keyword(Vector<const char> keyword) { | 381 bool is_literal_contextual_keyword(Vector<const char> keyword) { |
385 DCHECK_NOT_NULL(current_.literal_chars); | 382 DCHECK_NOT_NULL(current_.literal_chars); |
386 return current_.literal_chars->is_contextual_keyword(keyword); | 383 return current_.literal_chars->is_contextual_keyword(keyword); |
387 } | 384 } |
388 bool is_next_contextual_keyword(Vector<const char> keyword) { | 385 bool is_next_contextual_keyword(Vector<const char> keyword) { |
389 DCHECK_NOT_NULL(next_.literal_chars); | 386 DCHECK_NOT_NULL(next_.literal_chars); |
390 return next_.literal_chars->is_contextual_keyword(keyword); | 387 return next_.literal_chars->is_contextual_keyword(keyword); |
391 } | 388 } |
392 | 389 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 Token::Value SkipSingleLineComment(); | 655 Token::Value SkipSingleLineComment(); |
659 Token::Value SkipSourceURLComment(); | 656 Token::Value SkipSourceURLComment(); |
660 void TryToParseSourceURLComment(); | 657 void TryToParseSourceURLComment(); |
661 Token::Value SkipMultiLineComment(); | 658 Token::Value SkipMultiLineComment(); |
662 // Scans a possible HTML comment -- begins with '<!'. | 659 // Scans a possible HTML comment -- begins with '<!'. |
663 Token::Value ScanHtmlComment(); | 660 Token::Value ScanHtmlComment(); |
664 | 661 |
665 void ScanDecimalDigits(); | 662 void ScanDecimalDigits(); |
666 Token::Value ScanNumber(bool seen_period); | 663 Token::Value ScanNumber(bool seen_period); |
667 Token::Value ScanIdentifierOrKeyword(); | 664 Token::Value ScanIdentifierOrKeyword(); |
668 Token::Value ScanIdentifierSuffix(LiteralScope* literal); | 665 Token::Value ScanIdentifierSuffix(LiteralScope* literal, bool escaped); |
669 | 666 |
670 Token::Value ScanString(); | 667 Token::Value ScanString(); |
671 | 668 |
672 // Scans an escape-sequence which is part of a string and adds the | 669 // Scans an escape-sequence which is part of a string and adds the |
673 // decoded character to the current literal. Returns true if a pattern | 670 // decoded character to the current literal. Returns true if a pattern |
674 // is scanned. | 671 // is scanned. |
675 template <bool capture_raw, bool in_template_literal> | 672 template <bool capture_raw, bool in_template_literal> |
676 bool ScanEscape(); | 673 bool ScanEscape(); |
677 | 674 |
678 // Decodes a Unicode escape-sequence which is part of an identifier. | 675 // Decodes a Unicode escape-sequence which is part of an identifier. |
679 // If the escape sequence cannot be decoded the result is kBadChar. | 676 // If the escape sequence cannot be decoded the result is kBadChar. |
680 uc32 ScanIdentifierUnicodeEscape(); | 677 uc32 ScanIdentifierUnicodeEscape(); |
681 // Helper for the above functions. | 678 // Helper for the above functions. |
682 template <bool capture_raw> | 679 template <bool capture_raw> |
683 uc32 ScanUnicodeEscape(); | 680 uc32 ScanUnicodeEscape(); |
684 | 681 |
685 Token::Value ScanTemplateSpan(); | 682 Token::Value ScanTemplateSpan(); |
686 | 683 |
687 // Return the current source position. | 684 // Return the current source position. |
688 int source_pos() { | 685 int source_pos() { |
689 return static_cast<int>(source_->pos()) - kCharacterLookaheadBufferSize; | 686 return static_cast<int>(source_->pos()) - kCharacterLookaheadBufferSize; |
690 } | 687 } |
691 | 688 |
| 689 static bool LiteralContainsEscapes(const TokenDesc& token) { |
| 690 Location location = token.location; |
| 691 int source_length = (location.end_pos - location.beg_pos); |
| 692 if (token.token == Token::STRING) { |
| 693 // Subtract delimiters. |
| 694 source_length -= 2; |
| 695 } |
| 696 return token.literal_chars->length() != source_length; |
| 697 } |
| 698 |
692 UnicodeCache* unicode_cache_; | 699 UnicodeCache* unicode_cache_; |
693 | 700 |
694 // Buffers collecting literal strings, numbers, etc. | 701 // Buffers collecting literal strings, numbers, etc. |
695 LiteralBuffer literal_buffer0_; | 702 LiteralBuffer literal_buffer0_; |
696 LiteralBuffer literal_buffer1_; | 703 LiteralBuffer literal_buffer1_; |
697 LiteralBuffer literal_buffer2_; | 704 LiteralBuffer literal_buffer2_; |
698 | 705 |
699 // Values parsed from magic comments. | 706 // Values parsed from magic comments. |
700 LiteralBuffer source_url_; | 707 LiteralBuffer source_url_; |
701 LiteralBuffer source_mapping_url_; | 708 LiteralBuffer source_mapping_url_; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 bool has_line_terminator_before_next_; | 763 bool has_line_terminator_before_next_; |
757 // Whether there is a multi-line comment that contains a | 764 // Whether there is a multi-line comment that contains a |
758 // line-terminator after the current token, and before the next. | 765 // line-terminator after the current token, and before the next. |
759 bool has_multiline_comment_before_next_; | 766 bool has_multiline_comment_before_next_; |
760 }; | 767 }; |
761 | 768 |
762 } // namespace internal | 769 } // namespace internal |
763 } // namespace v8 | 770 } // namespace v8 |
764 | 771 |
765 #endif // V8_SCANNER_H_ | 772 #endif // V8_SCANNER_H_ |
OLD | NEW |