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_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 return; | 662 return; |
663 } | 663 } |
664 if (scanner()->HasAnyLineTerminatorBeforeNext() || | 664 if (scanner()->HasAnyLineTerminatorBeforeNext() || |
665 tok == Token::RBRACE || | 665 tok == Token::RBRACE || |
666 tok == Token::EOS) { | 666 tok == Token::EOS) { |
667 return; | 667 return; |
668 } | 668 } |
669 Expect(Token::SEMICOLON, ok); | 669 Expect(Token::SEMICOLON, ok); |
670 } | 670 } |
671 | 671 |
672 bool peek_any_identifier() { | 672 bool is_any_identifier(Token::Value token) { |
673 Token::Value next = peek(); | 673 return token == Token::IDENTIFIER || token == Token::ENUM || |
674 return next == Token::IDENTIFIER || next == Token::ENUM || | 674 token == Token::AWAIT || token == Token::ASYNC || |
675 next == Token::AWAIT || next == Token::ASYNC || | 675 token == Token::FUTURE_STRICT_RESERVED_WORD || token == Token::LET || |
676 next == Token::FUTURE_STRICT_RESERVED_WORD || next == Token::LET || | 676 token == Token::STATIC || token == Token::YIELD; |
677 next == Token::STATIC || next == Token::YIELD; | |
678 } | 677 } |
| 678 bool peek_any_identifier() { return is_any_identifier(peek()); } |
679 | 679 |
680 bool CheckContextualKeyword(Vector<const char> keyword) { | 680 bool CheckContextualKeyword(Vector<const char> keyword) { |
681 if (PeekContextualKeyword(keyword)) { | 681 if (PeekContextualKeyword(keyword)) { |
682 Consume(Token::IDENTIFIER); | 682 Consume(Token::IDENTIFIER); |
683 return true; | 683 return true; |
684 } | 684 } |
685 return false; | 685 return false; |
686 } | 686 } |
687 | 687 |
688 bool PeekContextualKeyword(Vector<const char> keyword) { | 688 bool PeekContextualKeyword(Vector<const char> keyword) { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 !classifier->is_valid_formal_parameter_list_without_duplicates()) { | 881 !classifier->is_valid_formal_parameter_list_without_duplicates()) { |
882 ReportClassifierError(classifier->duplicate_formal_parameter_error()); | 882 ReportClassifierError(classifier->duplicate_formal_parameter_error()); |
883 *ok = false; | 883 *ok = false; |
884 } else if (is_strict(language_mode) && | 884 } else if (is_strict(language_mode) && |
885 !classifier->is_valid_strict_mode_formal_parameters()) { | 885 !classifier->is_valid_strict_mode_formal_parameters()) { |
886 ReportClassifierError(classifier->strict_mode_formal_parameter_error()); | 886 ReportClassifierError(classifier->strict_mode_formal_parameter_error()); |
887 *ok = false; | 887 *ok = false; |
888 } | 888 } |
889 } | 889 } |
890 | 890 |
| 891 bool IsValidArrowFormalParametersStart(Token::Value token) { |
| 892 return is_any_identifier(token) || token == Token::LPAREN; |
| 893 } |
| 894 |
891 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, | 895 void ValidateArrowFormalParameters(const ExpressionClassifier* classifier, |
892 ExpressionT expr, | 896 ExpressionT expr, |
893 bool parenthesized_formals, bool is_async, | 897 bool parenthesized_formals, bool is_async, |
894 bool* ok) { | 898 bool* ok) { |
895 if (classifier->is_valid_binding_pattern()) { | 899 if (classifier->is_valid_binding_pattern()) { |
896 // A simple arrow formal parameter: IDENTIFIER => BODY. | 900 // A simple arrow formal parameter: IDENTIFIER => BODY. |
897 if (!this->IsIdentifier(expr)) { | 901 if (!this->IsIdentifier(expr)) { |
898 Traits::ReportMessageAt(scanner()->location(), | 902 Traits::ReportMessageAt(scanner()->location(), |
899 MessageTemplate::kUnexpectedToken, | 903 MessageTemplate::kUnexpectedToken, |
900 Token::String(scanner()->current_token())); | 904 Token::String(scanner()->current_token())); |
(...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2224 if (peek() == Token::YIELD && is_generator()) { | 2228 if (peek() == Token::YIELD && is_generator()) { |
2225 return this->ParseYieldExpression(accept_IN, classifier, ok); | 2229 return this->ParseYieldExpression(accept_IN, classifier, ok); |
2226 } | 2230 } |
2227 | 2231 |
2228 FuncNameInferrer::State fni_state(fni_); | 2232 FuncNameInferrer::State fni_state(fni_); |
2229 ParserBase<Traits>::Checkpoint checkpoint(this); | 2233 ParserBase<Traits>::Checkpoint checkpoint(this); |
2230 ExpressionClassifier arrow_formals_classifier(this, | 2234 ExpressionClassifier arrow_formals_classifier(this, |
2231 classifier->duplicate_finder()); | 2235 classifier->duplicate_finder()); |
2232 | 2236 |
2233 bool is_async = allow_harmony_async_await() && peek() == Token::ASYNC && | 2237 bool is_async = allow_harmony_async_await() && peek() == Token::ASYNC && |
2234 !scanner()->HasAnyLineTerminatorAfterNext(); | 2238 !scanner()->HasAnyLineTerminatorAfterNext() && |
| 2239 IsValidArrowFormalParametersStart(PeekAhead()); |
2235 | 2240 |
2236 bool parenthesized_formals = peek() == Token::LPAREN; | 2241 bool parenthesized_formals = peek() == Token::LPAREN; |
2237 if (!is_async && !parenthesized_formals) { | 2242 if (!is_async && !parenthesized_formals) { |
2238 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); | 2243 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); |
2239 } | 2244 } |
2240 ExpressionT expression = this->ParseConditionalExpression( | 2245 ExpressionT expression = this->ParseConditionalExpression( |
2241 accept_IN, &arrow_formals_classifier, CHECK_OK); | 2246 accept_IN, &arrow_formals_classifier, CHECK_OK); |
2242 | 2247 |
2243 if (is_async && peek_any_identifier() && PeekAhead() == Token::ARROW) { | 2248 if (is_async && peek_any_identifier() && PeekAhead() == Token::ARROW) { |
2244 // async Identifier => AsyncConciseBody | 2249 // async Identifier => AsyncConciseBody |
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3622 has_seen_constructor_ = true; | 3627 has_seen_constructor_ = true; |
3623 return; | 3628 return; |
3624 } | 3629 } |
3625 } | 3630 } |
3626 | 3631 |
3627 | 3632 |
3628 } // namespace internal | 3633 } // namespace internal |
3629 } // namespace v8 | 3634 } // namespace v8 |
3630 | 3635 |
3631 #endif // V8_PARSING_PARSER_BASE_H | 3636 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |