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 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 void ValidateFormalParameterInitializer( | 922 void ValidateFormalParameterInitializer( |
923 const ExpressionClassifier* classifier, bool* ok) { | 923 const ExpressionClassifier* classifier, bool* ok) { |
924 if (!classifier->is_valid_formal_parameter_initializer()) { | 924 if (!classifier->is_valid_formal_parameter_initializer()) { |
925 ReportClassifierError(classifier->formal_parameter_initializer_error()); | 925 ReportClassifierError(classifier->formal_parameter_initializer_error()); |
926 *ok = false; | 926 *ok = false; |
927 } | 927 } |
928 } | 928 } |
929 | 929 |
930 void ValidateBindingPattern(const ExpressionClassifier* classifier, | 930 void ValidateBindingPattern(const ExpressionClassifier* classifier, |
931 bool* ok) { | 931 bool* ok) { |
932 if (!classifier->is_valid_binding_pattern() || | 932 if (!classifier->is_valid_binding_pattern()) { |
933 !classifier->is_valid_async_binding_pattern()) { | 933 ReportClassifierError(classifier->binding_pattern_error()); |
934 const Scanner::Location& a = classifier->binding_pattern_error().location; | |
935 const Scanner::Location& b = | |
936 classifier->async_binding_pattern_error().location; | |
937 if (a.beg_pos < 0 || (b.beg_pos >= 0 && a.beg_pos > b.beg_pos)) { | |
938 ReportClassifierError(classifier->async_binding_pattern_error()); | |
939 } else { | |
940 ReportClassifierError(classifier->binding_pattern_error()); | |
941 } | |
942 *ok = false; | 934 *ok = false; |
943 } | 935 } |
944 } | 936 } |
945 | 937 |
946 void ValidateAssignmentPattern(const ExpressionClassifier* classifier, | 938 void ValidateAssignmentPattern(const ExpressionClassifier* classifier, |
947 bool* ok) { | 939 bool* ok) { |
948 if (!classifier->is_valid_assignment_pattern()) { | 940 if (!classifier->is_valid_assignment_pattern()) { |
949 ReportClassifierError(classifier->assignment_pattern_error()); | 941 ReportClassifierError(classifier->assignment_pattern_error()); |
950 *ok = false; | 942 *ok = false; |
951 } | 943 } |
(...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2751 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); | 2743 MessageTemplate::kInvalidLhsInPrefixOp, CHECK_OK); |
2752 this->MarkExpressionAsAssigned(expression); | 2744 this->MarkExpressionAsAssigned(expression); |
2753 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2745 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2754 | 2746 |
2755 return factory()->NewCountOperation(op, | 2747 return factory()->NewCountOperation(op, |
2756 true /* prefix */, | 2748 true /* prefix */, |
2757 expression, | 2749 expression, |
2758 position()); | 2750 position()); |
2759 | 2751 |
2760 } else if (is_async_function() && peek() == Token::AWAIT) { | 2752 } else if (is_async_function() && peek() == Token::AWAIT) { |
2761 int beg_pos = peek_position(); | 2753 classifier->RecordFormalParameterInitializerError( |
2762 switch (PeekAhead()) { | 2754 scanner()->peek_location(), |
2763 case Token::RPAREN: | 2755 MessageTemplate::kAwaitExpressionFormalParameter); |
2764 case Token::RBRACK: | |
2765 case Token::RBRACE: | |
2766 case Token::ASSIGN: | |
2767 case Token::COMMA: { | |
2768 Next(); | |
2769 IdentifierT name = this->GetSymbol(scanner()); | |
2770 | |
2771 // Possibly async arrow formals --- record ExpressionError just in case. | |
2772 ExpressionUnexpectedToken(classifier); | |
2773 classifier->RecordAsyncBindingPatternError( | |
2774 Scanner::Location(beg_pos, scanner()->location().end_pos), | |
2775 MessageTemplate::kAwaitBindingIdentifier); | |
2776 classifier->RecordAsyncArrowFormalParametersError( | |
2777 Scanner::Location(beg_pos, scanner()->location().end_pos), | |
2778 MessageTemplate::kAwaitBindingIdentifier); | |
2779 | |
2780 return this->ExpressionFromIdentifier(name, beg_pos, | |
2781 scanner()->location().end_pos); | |
2782 } | |
2783 default: | |
2784 break; | |
2785 } | |
2786 | 2756 |
2787 int await_pos = peek_position(); | 2757 int await_pos = peek_position(); |
2788 Consume(Token::AWAIT); | 2758 Consume(Token::AWAIT); |
2789 | 2759 |
2790 ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK); | 2760 ExpressionT value = ParseUnaryExpression(classifier, CHECK_OK); |
2791 | 2761 |
2792 classifier->RecordFormalParameterInitializerError( | |
2793 Scanner::Location(beg_pos, scanner()->location().end_pos), | |
2794 MessageTemplate::kAwaitExpressionFormalParameter); | |
2795 return Traits::RewriteAwaitExpression(value, await_pos); | 2762 return Traits::RewriteAwaitExpression(value, await_pos); |
2796 } else { | 2763 } else { |
2797 return this->ParsePostfixExpression(classifier, ok); | 2764 return this->ParsePostfixExpression(classifier, ok); |
2798 } | 2765 } |
2799 } | 2766 } |
2800 | 2767 |
2801 | 2768 |
2802 template <class Traits> | 2769 template <class Traits> |
2803 typename ParserBase<Traits>::ExpressionT | 2770 typename ParserBase<Traits>::ExpressionT |
2804 ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier, | 2771 ParserBase<Traits>::ParsePostfixExpression(ExpressionClassifier* classifier, |
(...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3734 has_seen_constructor_ = true; | 3701 has_seen_constructor_ = true; |
3735 return; | 3702 return; |
3736 } | 3703 } |
3737 } | 3704 } |
3738 | 3705 |
3739 | 3706 |
3740 } // namespace internal | 3707 } // namespace internal |
3741 } // namespace v8 | 3708 } // namespace v8 |
3742 | 3709 |
3743 #endif // V8_PARSING_PARSER_BASE_H | 3710 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |