| 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" |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 bool has_error() const { return scanner_error_ != MessageTemplate::kNone; } | 364 bool has_error() const { return scanner_error_ != MessageTemplate::kNone; } |
| 365 MessageTemplate::Template error() const { return scanner_error_; } | 365 MessageTemplate::Template error() const { return scanner_error_; } |
| 366 Location error_location() const { return scanner_error_location_; } | 366 Location error_location() const { return scanner_error_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 Location peek_ahead_location() const { |
| 375 DCHECK(next_next_.token != Token::UNINITIALIZED); |
| 376 return next_next_.location; |
| 377 } |
| 374 | 378 |
| 375 bool literal_contains_escapes() const { | 379 bool literal_contains_escapes() const { |
| 376 return LiteralContainsEscapes(current_); | 380 return LiteralContainsEscapes(current_); |
| 377 } | 381 } |
| 378 bool next_literal_contains_escapes() const { | 382 bool next_literal_contains_escapes() const { |
| 379 return LiteralContainsEscapes(next_); | 383 return LiteralContainsEscapes(next_); |
| 380 } | 384 } |
| 381 bool is_literal_contextual_keyword(Vector<const char> keyword) { | 385 bool is_literal_contextual_keyword(Vector<const char> keyword) { |
| 382 DCHECK_NOT_NULL(current_.literal_chars); | 386 DCHECK_NOT_NULL(current_.literal_chars); |
| 383 return current_.literal_chars->is_contextual_keyword(keyword); | 387 return current_.literal_chars->is_contextual_keyword(keyword); |
| 384 } | 388 } |
| 385 bool is_next_contextual_keyword(Vector<const char> keyword) { | 389 bool is_next_contextual_keyword(Vector<const char> keyword) { |
| 386 DCHECK_NOT_NULL(next_.literal_chars); | 390 DCHECK_NOT_NULL(next_.literal_chars); |
| 387 return next_.literal_chars->is_contextual_keyword(keyword); | 391 return next_.literal_chars->is_contextual_keyword(keyword); |
| 388 } | 392 } |
| 389 | 393 |
| 394 bool is_next_next_contextual_keyword(Vector<const char> keyword) { |
| 395 DCHECK_NOT_NULL(next_next_.literal_chars); |
| 396 return next_next_.literal_chars->is_contextual_keyword(keyword); |
| 397 } |
| 398 |
| 390 const AstRawString* CurrentSymbol(AstValueFactory* ast_value_factory); | 399 const AstRawString* CurrentSymbol(AstValueFactory* ast_value_factory); |
| 391 const AstRawString* NextSymbol(AstValueFactory* ast_value_factory); | 400 const AstRawString* NextSymbol(AstValueFactory* ast_value_factory); |
| 401 const AstRawString* NextNextSymbol(AstValueFactory* ast_value_factory); |
| 392 const AstRawString* CurrentRawSymbol(AstValueFactory* ast_value_factory); | 402 const AstRawString* CurrentRawSymbol(AstValueFactory* ast_value_factory); |
| 393 | 403 |
| 394 double DoubleValue(); | 404 double DoubleValue(); |
| 395 bool ContainsDot(); | 405 bool ContainsDot(); |
| 396 bool LiteralMatches(const char* data, int length, bool allow_escapes = true) { | 406 bool LiteralMatches(const char* data, int length, bool allow_escapes = true) { |
| 397 if (is_literal_one_byte() && | 407 if (is_literal_one_byte() && |
| 398 literal_length() == length && | 408 literal_length() == length && |
| 399 (allow_escapes || !literal_contains_escapes())) { | 409 (allow_escapes || !literal_contains_escapes())) { |
| 400 const char* token = | 410 const char* token = |
| 401 reinterpret_cast<const char*>(literal_one_byte_string().start()); | 411 reinterpret_cast<const char*>(literal_one_byte_string().start()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 431 | 441 |
| 432 // Seek forward to the given position. This operation does not | 442 // Seek forward to the given position. This operation does not |
| 433 // work in general, for instance when there are pushed back | 443 // work in general, for instance when there are pushed back |
| 434 // characters, but works for seeking forward until simple delimiter | 444 // characters, but works for seeking forward until simple delimiter |
| 435 // tokens, which is what it is used for. | 445 // tokens, which is what it is used for. |
| 436 void SeekForward(int pos); | 446 void SeekForward(int pos); |
| 437 | 447 |
| 438 // Returns true if there was a line terminator before the peek'ed token, | 448 // Returns true if there was a line terminator before the peek'ed token, |
| 439 // possibly inside a multi-line comment. | 449 // possibly inside a multi-line comment. |
| 440 bool HasAnyLineTerminatorBeforeNext() const { | 450 bool HasAnyLineTerminatorBeforeNext() const { |
| 441 return has_line_terminator_before_next_ || | 451 return has_preceding_line_terminator_ || has_preceding_multiline_comment_; |
| 442 has_multiline_comment_before_next_; | 452 } |
| 453 |
| 454 bool HasAnyLineTerminatorAfterNext() { |
| 455 Token::Value ensure_next_next = PeekAhead(); |
| 456 USE(ensure_next_next); |
| 457 return next_has_preceding_line_terminator_; |
| 443 } | 458 } |
| 444 | 459 |
| 445 // Scans the input as a regular expression pattern, previous | 460 // Scans the input as a regular expression pattern, previous |
| 446 // character(s) must be /(=). Returns true if a pattern is scanned. | 461 // character(s) must be /(=). Returns true if a pattern is scanned. |
| 447 bool ScanRegExpPattern(bool seen_equal); | 462 bool ScanRegExpPattern(bool seen_equal); |
| 448 // Scans the input as regular expression flags. Returns the flags on success. | 463 // Scans the input as regular expression flags. Returns the flags on success. |
| 449 Maybe<RegExp::Flags> ScanRegExpFlags(); | 464 Maybe<RegExp::Flags> ScanRegExpFlags(); |
| 450 | 465 |
| 451 // Scans the input as a template literal | 466 // Scans the input as a template literal |
| 452 Token::Value ScanTemplateStart(); | 467 Token::Value ScanTemplateStart(); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 Utf16CharacterStream* source_; | 788 Utf16CharacterStream* source_; |
| 774 | 789 |
| 775 | 790 |
| 776 // Start position of the octal literal last scanned. | 791 // Start position of the octal literal last scanned. |
| 777 Location octal_pos_; | 792 Location octal_pos_; |
| 778 | 793 |
| 779 // One Unicode character look-ahead; c0_ < 0 at the end of the input. | 794 // One Unicode character look-ahead; c0_ < 0 at the end of the input. |
| 780 uc32 c0_; | 795 uc32 c0_; |
| 781 | 796 |
| 782 // Whether there is a line terminator whitespace character after | 797 // Whether there is a line terminator whitespace character after |
| 783 // the current token, and before the next. Does not count newlines | 798 // the current token, and before the next. |
| 784 // inside multiline comments. | 799 bool has_preceding_line_terminator_; |
| 785 bool has_line_terminator_before_next_; | 800 bool next_has_preceding_line_terminator_; |
| 786 // Whether there is a multi-line comment that contains a | 801 |
| 787 // line-terminator after the current token, and before the next. | 802 bool has_preceding_multiline_comment_; |
| 788 bool has_multiline_comment_before_next_; | |
| 789 | 803 |
| 790 // Whether this scanner encountered an HTML comment. | 804 // Whether this scanner encountered an HTML comment. |
| 791 bool found_html_comment_; | 805 bool found_html_comment_; |
| 792 | 806 |
| 793 bool allow_harmony_exponentiation_operator_; | 807 bool allow_harmony_exponentiation_operator_; |
| 794 | 808 |
| 795 MessageTemplate::Template scanner_error_; | 809 MessageTemplate::Template scanner_error_; |
| 796 Location scanner_error_location_; | 810 Location scanner_error_location_; |
| 797 }; | 811 }; |
| 798 | 812 |
| 799 } // namespace internal | 813 } // namespace internal |
| 800 } // namespace v8 | 814 } // namespace v8 |
| 801 | 815 |
| 802 #endif // V8_PARSING_SCANNER_H_ | 816 #endif // V8_PARSING_SCANNER_H_ |
| OLD | NEW |