| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
| 6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 Traits::ReportMessageAt(source_location, message, arg, error_type); | 496 Traits::ReportMessageAt(source_location, message, arg, error_type); |
| 497 } | 497 } |
| 498 | 498 |
| 499 void ReportMessageAt(Scanner::Location location, | 499 void ReportMessageAt(Scanner::Location location, |
| 500 MessageTemplate::Template message, | 500 MessageTemplate::Template message, |
| 501 ParseErrorType error_type = kSyntaxError) { | 501 ParseErrorType error_type = kSyntaxError) { |
| 502 Traits::ReportMessageAt(location, message, reinterpret_cast<const char*>(0), | 502 Traits::ReportMessageAt(location, message, reinterpret_cast<const char*>(0), |
| 503 error_type); | 503 error_type); |
| 504 } | 504 } |
| 505 | 505 |
| 506 void GetUnexpectedTokenMessage( |
| 507 Token::Value token, MessageTemplate::Template* message, const char** arg, |
| 508 MessageTemplate::Template default_ = MessageTemplate::kUnexpectedToken); |
| 509 |
| 506 void ReportUnexpectedToken(Token::Value token); | 510 void ReportUnexpectedToken(Token::Value token); |
| 507 void ReportUnexpectedTokenAt( | 511 void ReportUnexpectedTokenAt( |
| 508 Scanner::Location location, Token::Value token, | 512 Scanner::Location location, Token::Value token, |
| 509 MessageTemplate::Template message = MessageTemplate::kUnexpectedToken); | 513 MessageTemplate::Template message = MessageTemplate::kUnexpectedToken); |
| 510 | 514 |
| 511 | 515 |
| 512 void ReportClassifierError(const ExpressionClassifier::Error& error) { | 516 void ReportClassifierError(const ExpressionClassifier::Error& error) { |
| 513 Traits::ReportMessageAt(error.location, error.message, error.arg, | 517 Traits::ReportMessageAt(error.location, error.message, error.arg, |
| 514 kSyntaxError); | 518 kSyntaxError); |
| 515 } | 519 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 Token::String(scanner()->current_token())); | 569 Token::String(scanner()->current_token())); |
| 566 *ok = false; | 570 *ok = false; |
| 567 } | 571 } |
| 568 } else if (!classifier->is_valid_arrow_formal_parameters()) { | 572 } else if (!classifier->is_valid_arrow_formal_parameters()) { |
| 569 ReportClassifierError(classifier->arrow_formal_parameters_error()); | 573 ReportClassifierError(classifier->arrow_formal_parameters_error()); |
| 570 *ok = false; | 574 *ok = false; |
| 571 } | 575 } |
| 572 } | 576 } |
| 573 | 577 |
| 574 void ExpressionUnexpectedToken(ExpressionClassifier* classifier) { | 578 void ExpressionUnexpectedToken(ExpressionClassifier* classifier) { |
| 575 classifier->RecordExpressionError(scanner()->peek_location(), | 579 MessageTemplate::Template message = MessageTemplate::kUnexpectedToken; |
| 576 MessageTemplate::kUnexpectedToken, | 580 const char* arg; |
| 577 Token::String(peek())); | 581 GetUnexpectedTokenMessage(peek(), &message, &arg); |
| 582 classifier->RecordExpressionError(scanner()->peek_location(), message, arg); |
| 578 } | 583 } |
| 579 | 584 |
| 580 void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) { | 585 void BindingPatternUnexpectedToken(ExpressionClassifier* classifier) { |
| 581 classifier->RecordBindingPatternError(scanner()->peek_location(), | 586 MessageTemplate::Template message = MessageTemplate::kUnexpectedToken; |
| 582 MessageTemplate::kUnexpectedToken, | 587 const char* arg; |
| 583 Token::String(peek())); | 588 GetUnexpectedTokenMessage(peek(), &message, &arg); |
| 589 classifier->RecordBindingPatternError(scanner()->peek_location(), message, |
| 590 arg); |
| 584 } | 591 } |
| 585 | 592 |
| 586 void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) { | 593 void ArrowFormalParametersUnexpectedToken(ExpressionClassifier* classifier) { |
| 587 classifier->RecordArrowFormalParametersError( | 594 MessageTemplate::Template message = MessageTemplate::kUnexpectedToken; |
| 588 scanner()->peek_location(), MessageTemplate::kUnexpectedToken, | 595 const char* arg; |
| 589 Token::String(peek())); | 596 GetUnexpectedTokenMessage(peek(), &message, &arg); |
| 597 classifier->RecordArrowFormalParametersError(scanner()->peek_location(), |
| 598 message, arg); |
| 590 } | 599 } |
| 591 | 600 |
| 592 // Recursive descent functions: | 601 // Recursive descent functions: |
| 593 | 602 |
| 594 // Parses an identifier that is valid for the current scope, in particular it | 603 // Parses an identifier that is valid for the current scope, in particular it |
| 595 // fails on strict mode future reserved keywords in a strict scope. If | 604 // fails on strict mode future reserved keywords in a strict scope. If |
| 596 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or | 605 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or |
| 597 // "arguments" as identifier even in strict mode (this is needed in cases like | 606 // "arguments" as identifier even in strict mode (this is needed in cases like |
| 598 // "var foo = eval;"). | 607 // "var foo = eval;"). |
| 599 IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok); | 608 IdentifierT ParseIdentifier(AllowRestrictedIdentifiers, bool* ok); |
| (...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 } | 1832 } |
| 1824 | 1833 |
| 1825 | 1834 |
| 1826 template <class Traits> | 1835 template <class Traits> |
| 1827 ParserBase<Traits>::FunctionState::~FunctionState() { | 1836 ParserBase<Traits>::FunctionState::~FunctionState() { |
| 1828 *scope_stack_ = outer_scope_; | 1837 *scope_stack_ = outer_scope_; |
| 1829 *function_state_stack_ = outer_function_state_; | 1838 *function_state_stack_ = outer_function_state_; |
| 1830 } | 1839 } |
| 1831 | 1840 |
| 1832 | 1841 |
| 1833 template<class Traits> | 1842 template <class Traits> |
| 1843 void ParserBase<Traits>::GetUnexpectedTokenMessage( |
| 1844 Token::Value token, MessageTemplate::Template* message, const char** arg, |
| 1845 MessageTemplate::Template default_) { |
| 1846 // Four of the tokens are treated specially |
| 1847 switch (token) { |
| 1848 case Token::EOS: |
| 1849 *message = MessageTemplate::kUnexpectedEOS; |
| 1850 *arg = nullptr; |
| 1851 break; |
| 1852 case Token::SMI: |
| 1853 case Token::NUMBER: |
| 1854 *message = MessageTemplate::kUnexpectedTokenNumber; |
| 1855 *arg = nullptr; |
| 1856 break; |
| 1857 case Token::STRING: |
| 1858 *message = MessageTemplate::kUnexpectedTokenString; |
| 1859 *arg = nullptr; |
| 1860 break; |
| 1861 case Token::IDENTIFIER: |
| 1862 *message = MessageTemplate::kUnexpectedTokenIdentifier; |
| 1863 *arg = nullptr; |
| 1864 break; |
| 1865 case Token::FUTURE_RESERVED_WORD: |
| 1866 *message = MessageTemplate::kUnexpectedReserved; |
| 1867 *arg = nullptr; |
| 1868 break; |
| 1869 case Token::LET: |
| 1870 case Token::STATIC: |
| 1871 case Token::YIELD: |
| 1872 case Token::FUTURE_STRICT_RESERVED_WORD: |
| 1873 *message = is_strict(language_mode()) |
| 1874 ? MessageTemplate::kUnexpectedStrictReserved |
| 1875 : MessageTemplate::kUnexpectedTokenIdentifier; |
| 1876 *arg = nullptr; |
| 1877 break; |
| 1878 case Token::TEMPLATE_SPAN: |
| 1879 case Token::TEMPLATE_TAIL: |
| 1880 *message = MessageTemplate::kUnexpectedTemplateString; |
| 1881 *arg = nullptr; |
| 1882 break; |
| 1883 default: |
| 1884 const char* name = Token::String(token); |
| 1885 DCHECK(name != NULL); |
| 1886 *arg = name; |
| 1887 break; |
| 1888 } |
| 1889 } |
| 1890 |
| 1891 |
| 1892 template <class Traits> |
| 1834 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { | 1893 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { |
| 1835 return ReportUnexpectedTokenAt(scanner_->location(), token); | 1894 return ReportUnexpectedTokenAt(scanner_->location(), token); |
| 1836 } | 1895 } |
| 1837 | 1896 |
| 1838 | 1897 |
| 1839 template <class Traits> | 1898 template <class Traits> |
| 1840 void ParserBase<Traits>::ReportUnexpectedTokenAt( | 1899 void ParserBase<Traits>::ReportUnexpectedTokenAt( |
| 1841 Scanner::Location source_location, Token::Value token, | 1900 Scanner::Location source_location, Token::Value token, |
| 1842 MessageTemplate::Template message) { | 1901 MessageTemplate::Template message) { |
| 1843 // Four of the tokens are treated specially | 1902 const char* arg; |
| 1844 switch (token) { | 1903 GetUnexpectedTokenMessage(token, &message, &arg); |
| 1845 case Token::EOS: | 1904 Traits::ReportMessageAt(source_location, message, arg); |
| 1846 return ReportMessageAt(source_location, MessageTemplate::kUnexpectedEOS); | |
| 1847 case Token::SMI: | |
| 1848 case Token::NUMBER: | |
| 1849 return ReportMessageAt(source_location, | |
| 1850 MessageTemplate::kUnexpectedTokenNumber); | |
| 1851 case Token::STRING: | |
| 1852 return ReportMessageAt(source_location, | |
| 1853 MessageTemplate::kUnexpectedTokenString); | |
| 1854 case Token::IDENTIFIER: | |
| 1855 return ReportMessageAt(source_location, | |
| 1856 MessageTemplate::kUnexpectedTokenIdentifier); | |
| 1857 case Token::FUTURE_RESERVED_WORD: | |
| 1858 return ReportMessageAt(source_location, | |
| 1859 MessageTemplate::kUnexpectedReserved); | |
| 1860 case Token::LET: | |
| 1861 case Token::STATIC: | |
| 1862 case Token::YIELD: | |
| 1863 case Token::FUTURE_STRICT_RESERVED_WORD: | |
| 1864 return ReportMessageAt(source_location, | |
| 1865 is_strict(language_mode()) | |
| 1866 ? MessageTemplate::kUnexpectedStrictReserved | |
| 1867 : MessageTemplate::kUnexpectedTokenIdentifier); | |
| 1868 case Token::TEMPLATE_SPAN: | |
| 1869 case Token::TEMPLATE_TAIL: | |
| 1870 return Traits::ReportMessageAt( | |
| 1871 source_location, MessageTemplate::kUnexpectedTemplateString); | |
| 1872 default: | |
| 1873 const char* name = Token::String(token); | |
| 1874 DCHECK(name != NULL); | |
| 1875 Traits::ReportMessageAt(source_location, message, name); | |
| 1876 } | |
| 1877 } | 1905 } |
| 1878 | 1906 |
| 1879 | 1907 |
| 1880 template <class Traits> | 1908 template <class Traits> |
| 1881 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier( | 1909 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier( |
| 1882 AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) { | 1910 AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) { |
| 1883 ExpressionClassifier classifier; | 1911 ExpressionClassifier classifier; |
| 1884 auto result = ParseAndClassifyIdentifier(&classifier, ok); | 1912 auto result = ParseAndClassifyIdentifier(&classifier, ok); |
| 1885 if (!*ok) return Traits::EmptyIdentifier(); | 1913 if (!*ok) return Traits::EmptyIdentifier(); |
| 1886 | 1914 |
| (...skipping 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3914 *ok = false; | 3942 *ok = false; |
| 3915 return; | 3943 return; |
| 3916 } | 3944 } |
| 3917 has_seen_constructor_ = true; | 3945 has_seen_constructor_ = true; |
| 3918 return; | 3946 return; |
| 3919 } | 3947 } |
| 3920 } | 3948 } |
| 3921 } } // v8::internal | 3949 } } // v8::internal |
| 3922 | 3950 |
| 3923 #endif // V8_PREPARSER_H | 3951 #endif // V8_PREPARSER_H |
| OLD | NEW |