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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_line_terminator_before_next_ || |
442 has_multiline_comment_before_next_; | 452 has_multiline_comment_before_next_; |
443 } | 453 } |
444 | 454 |
| 455 bool HasAnyLineTerminatorAfterNext() { |
| 456 Token::Value ensure_next_next = PeekAhead(); |
| 457 USE(ensure_next_next); |
| 458 return has_line_terminator_before_next2_ || |
| 459 has_multiline_comment_before_next2_; |
| 460 } |
| 461 |
445 // Scans the input as a regular expression pattern, previous | 462 // Scans the input as a regular expression pattern, previous |
446 // character(s) must be /(=). Returns true if a pattern is scanned. | 463 // character(s) must be /(=). Returns true if a pattern is scanned. |
447 bool ScanRegExpPattern(bool seen_equal); | 464 bool ScanRegExpPattern(bool seen_equal); |
448 // Scans the input as regular expression flags. Returns the flags on success. | 465 // Scans the input as regular expression flags. Returns the flags on success. |
449 Maybe<RegExp::Flags> ScanRegExpFlags(); | 466 Maybe<RegExp::Flags> ScanRegExpFlags(); |
450 | 467 |
451 // Scans the input as a template literal | 468 // Scans the input as a template literal |
452 Token::Value ScanTemplateStart(); | 469 Token::Value ScanTemplateStart(); |
453 Token::Value ScanTemplateContinuation(); | 470 Token::Value ScanTemplateContinuation(); |
454 | 471 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 uc32 c0_; | 797 uc32 c0_; |
781 | 798 |
782 // Whether there is a line terminator whitespace character after | 799 // Whether there is a line terminator whitespace character after |
783 // the current token, and before the next. Does not count newlines | 800 // the current token, and before the next. Does not count newlines |
784 // inside multiline comments. | 801 // inside multiline comments. |
785 bool has_line_terminator_before_next_; | 802 bool has_line_terminator_before_next_; |
786 // Whether there is a multi-line comment that contains a | 803 // Whether there is a multi-line comment that contains a |
787 // line-terminator after the current token, and before the next. | 804 // line-terminator after the current token, and before the next. |
788 bool has_multiline_comment_before_next_; | 805 bool has_multiline_comment_before_next_; |
789 | 806 |
| 807 // For use with PeekAhead() |
| 808 bool has_line_terminator_before_next2_; |
| 809 bool has_multiline_comment_before_next2_; |
| 810 |
790 // Whether this scanner encountered an HTML comment. | 811 // Whether this scanner encountered an HTML comment. |
791 bool found_html_comment_; | 812 bool found_html_comment_; |
792 | 813 |
793 bool allow_harmony_exponentiation_operator_; | 814 bool allow_harmony_exponentiation_operator_; |
794 | 815 |
795 MessageTemplate::Template scanner_error_; | 816 MessageTemplate::Template scanner_error_; |
796 Location scanner_error_location_; | 817 Location scanner_error_location_; |
797 }; | 818 }; |
798 | 819 |
799 } // namespace internal | 820 } // namespace internal |
800 } // namespace v8 | 821 } // namespace v8 |
801 | 822 |
802 #endif // V8_PARSING_SCANNER_H_ | 823 #endif // V8_PARSING_SCANNER_H_ |
OLD | NEW |