| 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 |
| 393 const AstRawString* CurrentSymbol(AstValueFactory* ast_value_factory); | 390 const AstRawString* CurrentSymbol(AstValueFactory* ast_value_factory); |
| 394 const AstRawString* NextSymbol(AstValueFactory* ast_value_factory); | 391 const AstRawString* NextSymbol(AstValueFactory* ast_value_factory); |
| 395 const AstRawString* CurrentRawSymbol(AstValueFactory* ast_value_factory); | 392 const AstRawString* CurrentRawSymbol(AstValueFactory* ast_value_factory); |
| 396 | 393 |
| 394 bool IsNextEscapedReservedWord(LanguageMode language_mode, bool is_generator); |
| 395 |
| 397 double DoubleValue(); | 396 double DoubleValue(); |
| 398 bool ContainsDot(); | 397 bool ContainsDot(); |
| 399 bool LiteralMatches(const char* data, int length, bool allow_escapes = true) { | 398 bool LiteralMatches(const char* data, int length, bool allow_escapes = true) { |
| 400 if (is_literal_one_byte() && | 399 if (is_literal_one_byte() && |
| 401 literal_length() == length && | 400 literal_length() == length && |
| 402 (allow_escapes || !literal_contains_escapes())) { | 401 (allow_escapes || !literal_contains_escapes())) { |
| 403 const char* token = | 402 const char* token = |
| 404 reinterpret_cast<const char*>(literal_one_byte_string().start()); | 403 reinterpret_cast<const char*>(literal_one_byte_string().start()); |
| 405 return !strncmp(token, data, length); | 404 return !strncmp(token, data, length); |
| 406 } | 405 } |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 template <bool capture_raw> | 681 template <bool capture_raw> |
| 683 uc32 ScanUnicodeEscape(); | 682 uc32 ScanUnicodeEscape(); |
| 684 | 683 |
| 685 Token::Value ScanTemplateSpan(); | 684 Token::Value ScanTemplateSpan(); |
| 686 | 685 |
| 687 // Return the current source position. | 686 // Return the current source position. |
| 688 int source_pos() { | 687 int source_pos() { |
| 689 return static_cast<int>(source_->pos()) - kCharacterLookaheadBufferSize; | 688 return static_cast<int>(source_->pos()) - kCharacterLookaheadBufferSize; |
| 690 } | 689 } |
| 691 | 690 |
| 691 static bool LiteralContainsEscapes(const TokenDesc& token) { |
| 692 Location location = token.location; |
| 693 int source_length = (location.end_pos - location.beg_pos); |
| 694 if (token.token == Token::STRING) { |
| 695 // Subtract delimiters. |
| 696 source_length -= 2; |
| 697 } |
| 698 return token.literal_chars->length() != source_length; |
| 699 } |
| 700 |
| 692 UnicodeCache* unicode_cache_; | 701 UnicodeCache* unicode_cache_; |
| 693 | 702 |
| 694 // Buffers collecting literal strings, numbers, etc. | 703 // Buffers collecting literal strings, numbers, etc. |
| 695 LiteralBuffer literal_buffer0_; | 704 LiteralBuffer literal_buffer0_; |
| 696 LiteralBuffer literal_buffer1_; | 705 LiteralBuffer literal_buffer1_; |
| 697 LiteralBuffer literal_buffer2_; | 706 LiteralBuffer literal_buffer2_; |
| 698 | 707 |
| 699 // Values parsed from magic comments. | 708 // Values parsed from magic comments. |
| 700 LiteralBuffer source_url_; | 709 LiteralBuffer source_url_; |
| 701 LiteralBuffer source_mapping_url_; | 710 LiteralBuffer source_mapping_url_; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 bool has_line_terminator_before_next_; | 765 bool has_line_terminator_before_next_; |
| 757 // Whether there is a multi-line comment that contains a | 766 // Whether there is a multi-line comment that contains a |
| 758 // line-terminator after the current token, and before the next. | 767 // line-terminator after the current token, and before the next. |
| 759 bool has_multiline_comment_before_next_; | 768 bool has_multiline_comment_before_next_; |
| 760 }; | 769 }; |
| 761 | 770 |
| 762 } // namespace internal | 771 } // namespace internal |
| 763 } // namespace v8 | 772 } // namespace v8 |
| 764 | 773 |
| 765 #endif // V8_SCANNER_H_ | 774 #endif // V8_SCANNER_H_ |
| OLD | NEW |