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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 // Call this after setting source_ to the input. | 480 // Call this after setting source_ to the input. |
476 void Init() { | 481 void Init() { |
477 // Set c0_ (one character ahead) | 482 // Set c0_ (one character ahead) |
478 STATIC_ASSERT(kCharacterLookaheadBufferSize == 1); | 483 STATIC_ASSERT(kCharacterLookaheadBufferSize == 1); |
479 Advance(); | 484 Advance(); |
480 // Initialize current_ to not refer to a literal. | 485 // Initialize current_ to not refer to a literal. |
481 current_.literal_chars = NULL; | 486 current_.literal_chars = NULL; |
482 current_.raw_literal_chars = NULL; | 487 current_.raw_literal_chars = NULL; |
483 next_next_.token = Token::UNINITIALIZED; | 488 next_next_.token = Token::UNINITIALIZED; |
484 found_html_comment_ = false; | 489 found_html_comment_ = false; |
| 490 scanner_error_ = MessageTemplate::kNone; |
485 } | 491 } |
486 | 492 |
487 // Support BookmarkScope functionality. | 493 // Support BookmarkScope functionality. |
488 bool SetBookmark(); | 494 bool SetBookmark(); |
489 void ResetToBookmark(); | 495 void ResetToBookmark(); |
490 bool BookmarkHasBeenSet(); | 496 bool BookmarkHasBeenSet(); |
491 bool BookmarkHasBeenReset(); | 497 bool BookmarkHasBeenReset(); |
492 void DropBookmark(); | 498 void DropBookmark(); |
493 static void CopyTokenDesc(TokenDesc* to, TokenDesc* from); | 499 static void CopyTokenDesc(TokenDesc* to, TokenDesc* from); |
494 | 500 |
| 501 void ReportScannerError(const Location& location, |
| 502 MessageTemplate::Template error) { |
| 503 if (has_error()) return; |
| 504 scanner_error_ = error; |
| 505 scanner_error_location_ = location; |
| 506 } |
| 507 |
| 508 void ReportScannerError(int pos, MessageTemplate::Template error) { |
| 509 if (has_error()) return; |
| 510 scanner_error_ = error; |
| 511 scanner_error_location_ = Location(pos, pos + 1); |
| 512 } |
| 513 |
495 // Literal buffer support | 514 // Literal buffer support |
496 inline void StartLiteral() { | 515 inline void StartLiteral() { |
497 LiteralBuffer* free_buffer = | 516 LiteralBuffer* free_buffer = |
498 (current_.literal_chars == &literal_buffer0_) | 517 (current_.literal_chars == &literal_buffer0_) |
499 ? &literal_buffer1_ | 518 ? &literal_buffer1_ |
500 : (current_.literal_chars == &literal_buffer1_) ? &literal_buffer2_ | 519 : (current_.literal_chars == &literal_buffer1_) ? &literal_buffer2_ |
501 : &literal_buffer0_; | 520 : &literal_buffer0_; |
502 free_buffer->Reset(); | 521 free_buffer->Reset(); |
503 next_.literal_chars = free_buffer; | 522 next_.literal_chars = free_buffer; |
504 } | 523 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 } | 649 } |
631 Vector<const uint16_t> raw_literal_two_byte_string() { | 650 Vector<const uint16_t> raw_literal_two_byte_string() { |
632 DCHECK_NOT_NULL(current_.raw_literal_chars); | 651 DCHECK_NOT_NULL(current_.raw_literal_chars); |
633 return current_.raw_literal_chars->two_byte_literal(); | 652 return current_.raw_literal_chars->two_byte_literal(); |
634 } | 653 } |
635 bool is_raw_literal_one_byte() { | 654 bool is_raw_literal_one_byte() { |
636 DCHECK_NOT_NULL(current_.raw_literal_chars); | 655 DCHECK_NOT_NULL(current_.raw_literal_chars); |
637 return current_.raw_literal_chars->is_one_byte(); | 656 return current_.raw_literal_chars->is_one_byte(); |
638 } | 657 } |
639 | 658 |
640 template <bool capture_raw> | 659 template <bool capture_raw, bool unicode = false> |
641 uc32 ScanHexNumber(int expected_length); | 660 uc32 ScanHexNumber(int expected_length); |
642 // Scan a number of any length but not bigger than max_value. For example, the | 661 // Scan a number of any length but not bigger than max_value. For example, the |
643 // number can be 000000001, so it's very long in characters but its value is | 662 // number can be 000000001, so it's very long in characters but its value is |
644 // small. | 663 // small. |
645 template <bool capture_raw> | 664 template <bool capture_raw> |
646 uc32 ScanUnlimitedLengthHexNumber(int max_value); | 665 uc32 ScanUnlimitedLengthHexNumber(int max_value); |
647 | 666 |
648 // Scans a single JavaScript token. | 667 // Scans a single JavaScript token. |
649 void Scan(); | 668 void Scan(); |
650 | 669 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 // line-terminator after the current token, and before the next. | 781 // line-terminator after the current token, and before the next. |
763 bool has_multiline_comment_before_next_; | 782 bool has_multiline_comment_before_next_; |
764 // Whether to allow HTML comments (that is, skip over them, rather than | 783 // Whether to allow HTML comments (that is, skip over them, rather than |
765 // reporting the comment marker as a sequence of tokens.) | 784 // reporting the comment marker as a sequence of tokens.) |
766 bool allow_html_comments_; | 785 bool allow_html_comments_; |
767 | 786 |
768 // Whether this scanner encountered an HTML comment. | 787 // Whether this scanner encountered an HTML comment. |
769 bool found_html_comment_; | 788 bool found_html_comment_; |
770 | 789 |
771 bool allow_harmony_exponentiation_operator_; | 790 bool allow_harmony_exponentiation_operator_; |
| 791 |
| 792 MessageTemplate::Template scanner_error_; |
| 793 Location scanner_error_location_; |
772 }; | 794 }; |
773 | 795 |
774 } // namespace internal | 796 } // namespace internal |
775 } // namespace v8 | 797 } // namespace v8 |
776 | 798 |
777 #endif // V8_PARSING_SCANNER_H_ | 799 #endif // V8_PARSING_SCANNER_H_ |
OLD | NEW |