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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 } | 495 } |
496 | 496 |
497 void ReportMessageAt(Scanner::Location location, | 497 void ReportMessageAt(Scanner::Location location, |
498 MessageTemplate::Template message, | 498 MessageTemplate::Template message, |
499 ParseErrorType error_type = kSyntaxError) { | 499 ParseErrorType error_type = kSyntaxError) { |
500 Traits::ReportMessageAt(location, message, reinterpret_cast<const char*>(0), | 500 Traits::ReportMessageAt(location, message, reinterpret_cast<const char*>(0), |
501 error_type); | 501 error_type); |
502 } | 502 } |
503 | 503 |
504 void ReportUnexpectedToken(Token::Value token); | 504 void ReportUnexpectedToken(Token::Value token); |
505 void ReportUnexpectedTokenAt(Scanner::Location location, Token::Value token); | 505 void ReportUnexpectedTokenAt( |
| 506 Scanner::Location location, Token::Value token, |
| 507 MessageTemplate::Template message = MessageTemplate::kUnexpectedToken); |
506 | 508 |
507 | 509 |
508 void ReportClassifierError(const ExpressionClassifier::Error& error) { | 510 void ReportClassifierError(const ExpressionClassifier::Error& error) { |
509 Traits::ReportMessageAt(error.location, error.message, error.arg, | 511 Traits::ReportMessageAt(error.location, error.message, error.arg, |
510 kSyntaxError); | 512 kSyntaxError); |
511 } | 513 } |
512 | 514 |
513 void ValidateExpression(const ExpressionClassifier* classifier, bool* ok) { | 515 void ValidateExpression(const ExpressionClassifier* classifier, bool* ok) { |
514 if (!classifier->is_valid_expression()) { | 516 if (!classifier->is_valid_expression()) { |
515 ReportClassifierError(classifier->expression_error()); | 517 ReportClassifierError(classifier->expression_error()); |
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 *function_state_stack_ = outer_function_state_; | 1809 *function_state_stack_ = outer_function_state_; |
1808 } | 1810 } |
1809 | 1811 |
1810 | 1812 |
1811 template<class Traits> | 1813 template<class Traits> |
1812 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { | 1814 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { |
1813 return ReportUnexpectedTokenAt(scanner_->location(), token); | 1815 return ReportUnexpectedTokenAt(scanner_->location(), token); |
1814 } | 1816 } |
1815 | 1817 |
1816 | 1818 |
1817 template<class Traits> | 1819 template <class Traits> |
1818 void ParserBase<Traits>::ReportUnexpectedTokenAt( | 1820 void ParserBase<Traits>::ReportUnexpectedTokenAt( |
1819 Scanner::Location source_location, Token::Value token) { | 1821 Scanner::Location source_location, Token::Value token, |
1820 | 1822 MessageTemplate::Template message) { |
1821 // Four of the tokens are treated specially | 1823 // Four of the tokens are treated specially |
1822 switch (token) { | 1824 switch (token) { |
1823 case Token::EOS: | 1825 case Token::EOS: |
1824 return ReportMessageAt(source_location, MessageTemplate::kUnexpectedEOS); | 1826 return ReportMessageAt(source_location, MessageTemplate::kUnexpectedEOS); |
1825 case Token::SMI: | 1827 case Token::SMI: |
1826 case Token::NUMBER: | 1828 case Token::NUMBER: |
1827 return ReportMessageAt(source_location, | 1829 return ReportMessageAt(source_location, |
1828 MessageTemplate::kUnexpectedTokenNumber); | 1830 MessageTemplate::kUnexpectedTokenNumber); |
1829 case Token::STRING: | 1831 case Token::STRING: |
1830 return ReportMessageAt(source_location, | 1832 return ReportMessageAt(source_location, |
(...skipping 12 matching lines...) Expand all Loading... |
1843 is_strict(language_mode()) | 1845 is_strict(language_mode()) |
1844 ? MessageTemplate::kUnexpectedStrictReserved | 1846 ? MessageTemplate::kUnexpectedStrictReserved |
1845 : MessageTemplate::kUnexpectedTokenIdentifier); | 1847 : MessageTemplate::kUnexpectedTokenIdentifier); |
1846 case Token::TEMPLATE_SPAN: | 1848 case Token::TEMPLATE_SPAN: |
1847 case Token::TEMPLATE_TAIL: | 1849 case Token::TEMPLATE_TAIL: |
1848 return Traits::ReportMessageAt( | 1850 return Traits::ReportMessageAt( |
1849 source_location, MessageTemplate::kUnexpectedTemplateString); | 1851 source_location, MessageTemplate::kUnexpectedTemplateString); |
1850 default: | 1852 default: |
1851 const char* name = Token::String(token); | 1853 const char* name = Token::String(token); |
1852 DCHECK(name != NULL); | 1854 DCHECK(name != NULL); |
1853 Traits::ReportMessageAt(source_location, | 1855 Traits::ReportMessageAt(source_location, message, name); |
1854 MessageTemplate::kUnexpectedToken, name); | |
1855 } | 1856 } |
1856 } | 1857 } |
1857 | 1858 |
1858 | 1859 |
1859 template <class Traits> | 1860 template <class Traits> |
1860 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier( | 1861 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier( |
1861 AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) { | 1862 AllowRestrictedIdentifiers allow_restricted_identifiers, bool* ok) { |
1862 ExpressionClassifier classifier; | 1863 ExpressionClassifier classifier; |
1863 auto result = ParseAndClassifyIdentifier(&classifier, ok); | 1864 auto result = ParseAndClassifyIdentifier(&classifier, ok); |
1864 if (!*ok) return Traits::EmptyIdentifier(); | 1865 if (!*ok) return Traits::EmptyIdentifier(); |
(...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3603 int num_parameters = scope->num_parameters(); | 3604 int num_parameters = scope->num_parameters(); |
3604 int materialized_literal_count = -1; | 3605 int materialized_literal_count = -1; |
3605 int expected_property_count = -1; | 3606 int expected_property_count = -1; |
3606 Scanner::Location super_loc; | 3607 Scanner::Location super_loc; |
3607 | 3608 |
3608 { | 3609 { |
3609 typename Traits::Type::Factory function_factory(ast_value_factory()); | 3610 typename Traits::Type::Factory function_factory(ast_value_factory()); |
3610 FunctionState function_state(&function_state_, &scope_, scope, | 3611 FunctionState function_state(&function_state_, &scope_, scope, |
3611 kArrowFunction, &function_factory); | 3612 kArrowFunction, &function_factory); |
3612 | 3613 |
3613 Expect(Token::ARROW, CHECK_OK); | 3614 // ParseArrowFunctionLiteral can be called in two ways: after seeing a |
| 3615 // formal parameter list that *must* be followed by an arrow, to wit "()" or |
| 3616 // "(...x)", or after reading a comma expression that is followed by =>. In |
| 3617 // the former cases we want to give a good error to the user who might have |
| 3618 // typed e.g. "return();". |
| 3619 if (!Check(Token::ARROW)) { |
| 3620 ReportUnexpectedTokenAt(scanner_->peek_location(), peek(), |
| 3621 MessageTemplate::kMissingArrow); |
| 3622 *ok = false; |
| 3623 return this->EmptyExpression(); |
| 3624 } |
3614 | 3625 |
3615 if (peek() == Token::LBRACE) { | 3626 if (peek() == Token::LBRACE) { |
3616 // Multiple statement body | 3627 // Multiple statement body |
3617 Consume(Token::LBRACE); | 3628 Consume(Token::LBRACE); |
3618 bool is_lazily_parsed = | 3629 bool is_lazily_parsed = |
3619 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); | 3630 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); |
3620 if (is_lazily_parsed) { | 3631 if (is_lazily_parsed) { |
3621 body = this->NewStatementList(0, zone()); | 3632 body = this->NewStatementList(0, zone()); |
3622 this->SkipLazyFunctionBody(&materialized_literal_count, | 3633 this->SkipLazyFunctionBody(&materialized_literal_count, |
3623 &expected_property_count, CHECK_OK); | 3634 &expected_property_count, CHECK_OK); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3864 *ok = false; | 3875 *ok = false; |
3865 return; | 3876 return; |
3866 } | 3877 } |
3867 has_seen_constructor_ = true; | 3878 has_seen_constructor_ = true; |
3868 return; | 3879 return; |
3869 } | 3880 } |
3870 } | 3881 } |
3871 } } // v8::internal | 3882 } } // v8::internal |
3872 | 3883 |
3873 #endif // V8_PREPARSER_H | 3884 #endif // V8_PREPARSER_H |
OLD | NEW |