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 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 Traits::ReportMessageAt(source_location, message, arg, error_type); | 531 Traits::ReportMessageAt(source_location, message, arg, error_type); |
532 } | 532 } |
533 | 533 |
534 void ReportMessageAt(Scanner::Location location, const char* message, | 534 void ReportMessageAt(Scanner::Location location, const char* message, |
535 ParseErrorType error_type = kSyntaxError) { | 535 ParseErrorType error_type = kSyntaxError) { |
536 Traits::ReportMessageAt(location, message, reinterpret_cast<const char*>(0), | 536 Traits::ReportMessageAt(location, message, reinterpret_cast<const char*>(0), |
537 error_type); | 537 error_type); |
538 } | 538 } |
539 | 539 |
540 void ReportUnexpectedToken(Token::Value token); | 540 void ReportUnexpectedToken(Token::Value token); |
| 541 void ReportUnexpectedTokenAt(Scanner::Location location, Token::Value token); |
541 | 542 |
542 // Recursive descent functions: | 543 // Recursive descent functions: |
543 | 544 |
544 // Parses an identifier that is valid for the current scope, in particular it | 545 // Parses an identifier that is valid for the current scope, in particular it |
545 // fails on strict mode future reserved keywords in a strict scope. If | 546 // fails on strict mode future reserved keywords in a strict scope. If |
546 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or | 547 // allow_eval_or_arguments is kAllowEvalOrArguments, we allow "eval" or |
547 // "arguments" as identifier even in strict mode (this is needed in cases like | 548 // "arguments" as identifier even in strict mode (this is needed in cases like |
548 // "var foo = eval;"). | 549 // "var foo = eval;"). |
549 IdentifierT ParseIdentifier( | 550 IdentifierT ParseIdentifier( |
550 AllowEvalOrArgumentsAsIdentifier, | 551 AllowEvalOrArgumentsAsIdentifier, |
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 | 1675 |
1675 template <class Traits> | 1676 template <class Traits> |
1676 ParserBase<Traits>::FunctionState::~FunctionState() { | 1677 ParserBase<Traits>::FunctionState::~FunctionState() { |
1677 *scope_stack_ = outer_scope_; | 1678 *scope_stack_ = outer_scope_; |
1678 *function_state_stack_ = outer_function_state_; | 1679 *function_state_stack_ = outer_function_state_; |
1679 } | 1680 } |
1680 | 1681 |
1681 | 1682 |
1682 template<class Traits> | 1683 template<class Traits> |
1683 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { | 1684 void ParserBase<Traits>::ReportUnexpectedToken(Token::Value token) { |
1684 Scanner::Location source_location = scanner()->location(); | 1685 return ReportUnexpectedTokenAt(scanner_->location(), token); |
| 1686 } |
| 1687 |
| 1688 |
| 1689 template<class Traits> |
| 1690 void ParserBase<Traits>::ReportUnexpectedTokenAt( |
| 1691 Scanner::Location source_location, Token::Value token) { |
1685 | 1692 |
1686 // Four of the tokens are treated specially | 1693 // Four of the tokens are treated specially |
1687 switch (token) { | 1694 switch (token) { |
1688 case Token::EOS: | 1695 case Token::EOS: |
1689 return ReportMessageAt(source_location, "unexpected_eos"); | 1696 return ReportMessageAt(source_location, "unexpected_eos"); |
1690 case Token::SMI: | 1697 case Token::SMI: |
1691 case Token::NUMBER: | 1698 case Token::NUMBER: |
1692 return ReportMessageAt(source_location, "unexpected_token_number"); | 1699 return ReportMessageAt(source_location, "unexpected_token_number"); |
1693 case Token::STRING: | 1700 case Token::STRING: |
1694 return ReportMessageAt(source_location, "unexpected_token_string"); | 1701 return ReportMessageAt(source_location, "unexpected_token_string"); |
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2839 DCHECK(false); | 2846 DCHECK(false); |
2840 return this->EmptyExpression(); | 2847 return this->EmptyExpression(); |
2841 } | 2848 } |
2842 | 2849 |
2843 | 2850 |
2844 template <class Traits> | 2851 template <class Traits> |
2845 typename ParserBase<Traits>::ExpressionT | 2852 typename ParserBase<Traits>::ExpressionT |
2846 ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos, | 2853 ParserBase<Traits>::ParseArrowFunctionLiteral(int start_pos, |
2847 ExpressionT params_ast, | 2854 ExpressionT params_ast, |
2848 bool* ok) { | 2855 bool* ok) { |
| 2856 if (peek() == Token::ARROW && scanner_->HasAnyLineTerminatorBeforeNext()) { |
| 2857 // ASI inserts `;` after arrow parameters if a line terminator is found. |
| 2858 // `=> ...` is never a valid expression, so report as syntax error. |
| 2859 // If next token is not `=>`, it's a syntax error anyways. |
| 2860 ReportUnexpectedTokenAt(scanner_->peek_location(), Token::ARROW); |
| 2861 *ok = false; |
| 2862 return this->EmptyExpression(); |
| 2863 } |
| 2864 |
2849 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); | 2865 Scope* scope = this->NewScope(scope_, ARROW_SCOPE); |
2850 typename Traits::Type::StatementList body; | 2866 typename Traits::Type::StatementList body; |
2851 int num_parameters = -1; | 2867 int num_parameters = -1; |
2852 int materialized_literal_count = -1; | 2868 int materialized_literal_count = -1; |
2853 int expected_property_count = -1; | 2869 int expected_property_count = -1; |
2854 int handler_count = 0; | 2870 int handler_count = 0; |
2855 | 2871 |
2856 { | 2872 { |
2857 typename Traits::Type::Factory function_factory(ast_value_factory()); | 2873 typename Traits::Type::Factory function_factory(ast_value_factory()); |
2858 FunctionState function_state(&function_state_, &scope_, scope, | 2874 FunctionState function_state(&function_state_, &scope_, scope, |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3116 *ok = false; | 3132 *ok = false; |
3117 return; | 3133 return; |
3118 } | 3134 } |
3119 has_seen_constructor_ = true; | 3135 has_seen_constructor_ = true; |
3120 return; | 3136 return; |
3121 } | 3137 } |
3122 } | 3138 } |
3123 } } // v8::internal | 3139 } } // v8::internal |
3124 | 3140 |
3125 #endif // V8_PREPARSER_H | 3141 #endif // V8_PREPARSER_H |
OLD | NEW |