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/hashmap.h" | 10 #include "src/hashmap.h" |
(...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 typename Traits::Type::PropertyList properties = | 1840 typename Traits::Type::PropertyList properties = |
1841 this->NewPropertyList(4, zone_); | 1841 this->NewPropertyList(4, zone_); |
1842 int number_of_boilerplate_properties = 0; | 1842 int number_of_boilerplate_properties = 0; |
1843 bool has_function = false; | 1843 bool has_function = false; |
1844 bool has_computed_names = false; | 1844 bool has_computed_names = false; |
1845 ObjectLiteralChecker checker(this); | 1845 ObjectLiteralChecker checker(this); |
1846 | 1846 |
1847 Expect(Token::LBRACE, CHECK_OK); | 1847 Expect(Token::LBRACE, CHECK_OK); |
1848 | 1848 |
1849 while (peek() != Token::RBRACE) { | 1849 while (peek() != Token::RBRACE) { |
1850 if (fni_ != nullptr) fni_->Enter(); | 1850 FuncNameInferrer::State fni_state(fni_); |
1851 | 1851 |
1852 const bool in_class = false; | 1852 const bool in_class = false; |
1853 const bool is_static = false; | 1853 const bool is_static = false; |
1854 const bool has_extends = false; | 1854 const bool has_extends = false; |
1855 bool is_computed_name = false; | 1855 bool is_computed_name = false; |
1856 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( | 1856 ObjectLiteralPropertyT property = this->ParsePropertyDefinition( |
1857 &checker, in_class, has_extends, is_static, &is_computed_name, NULL, | 1857 &checker, in_class, has_extends, is_static, &is_computed_name, NULL, |
1858 classifier, CHECK_OK); | 1858 classifier, CHECK_OK); |
1859 | 1859 |
1860 if (is_computed_name) { | 1860 if (is_computed_name) { |
(...skipping 10 matching lines...) Expand all Loading... |
1871 if (!has_computed_names && this->IsBoilerplateProperty(property)) { | 1871 if (!has_computed_names && this->IsBoilerplateProperty(property)) { |
1872 number_of_boilerplate_properties++; | 1872 number_of_boilerplate_properties++; |
1873 } | 1873 } |
1874 properties->Add(property, zone()); | 1874 properties->Add(property, zone()); |
1875 | 1875 |
1876 if (peek() != Token::RBRACE) { | 1876 if (peek() != Token::RBRACE) { |
1877 // Need {} because of the CHECK_OK macro. | 1877 // Need {} because of the CHECK_OK macro. |
1878 Expect(Token::COMMA, CHECK_OK); | 1878 Expect(Token::COMMA, CHECK_OK); |
1879 } | 1879 } |
1880 | 1880 |
1881 if (fni_ != nullptr) { | 1881 if (fni_ != nullptr) fni_->Infer(); |
1882 fni_->Infer(); | |
1883 fni_->Leave(); | |
1884 } | |
1885 } | 1882 } |
1886 Expect(Token::RBRACE, CHECK_OK); | 1883 Expect(Token::RBRACE, CHECK_OK); |
1887 | 1884 |
1888 // Computation of literal_index must happen before pre parse bailout. | 1885 // Computation of literal_index must happen before pre parse bailout. |
1889 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 1886 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
1890 | 1887 |
1891 return factory()->NewObjectLiteral(properties, | 1888 return factory()->NewObjectLiteral(properties, |
1892 literal_index, | 1889 literal_index, |
1893 number_of_boilerplate_properties, | 1890 number_of_boilerplate_properties, |
1894 has_function, | 1891 has_function, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1977 bool is_rhs = flags & kIsRightHandSide; | 1974 bool is_rhs = flags & kIsRightHandSide; |
1978 bool is_pattern_element = flags & kIsPatternElement; | 1975 bool is_pattern_element = flags & kIsPatternElement; |
1979 bool is_destructuring_assignment = false; | 1976 bool is_destructuring_assignment = false; |
1980 bool is_arrow_formals = flags & kIsPossibleArrowFormals; | 1977 bool is_arrow_formals = flags & kIsPossibleArrowFormals; |
1981 int lhs_beg_pos = peek_position(); | 1978 int lhs_beg_pos = peek_position(); |
1982 | 1979 |
1983 if (peek() == Token::YIELD && is_generator()) { | 1980 if (peek() == Token::YIELD && is_generator()) { |
1984 return this->ParseYieldExpression(classifier, ok); | 1981 return this->ParseYieldExpression(classifier, ok); |
1985 } | 1982 } |
1986 | 1983 |
1987 if (fni_ != NULL) fni_->Enter(); | 1984 FuncNameInferrer::State fni_state(fni_); |
1988 ParserBase<Traits>::Checkpoint checkpoint(this); | 1985 ParserBase<Traits>::Checkpoint checkpoint(this); |
1989 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); | 1986 ExpressionClassifier arrow_formals_classifier(classifier->duplicate_finder()); |
1990 bool parenthesized_formals = peek() == Token::LPAREN; | 1987 bool parenthesized_formals = peek() == Token::LPAREN; |
1991 if (!parenthesized_formals) { | 1988 if (!parenthesized_formals) { |
1992 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); | 1989 ArrowFormalParametersUnexpectedToken(&arrow_formals_classifier); |
1993 } | 1990 } |
1994 ExpressionT expression = this->ParseConditionalExpression( | 1991 ExpressionT expression = this->ParseConditionalExpression( |
1995 accept_IN, &arrow_formals_classifier, CHECK_OK); | 1992 accept_IN, &arrow_formals_classifier, CHECK_OK); |
1996 if (peek() == Token::ARROW) { | 1993 if (peek() == Token::ARROW) { |
1997 BindingPatternUnexpectedToken(classifier); | 1994 BindingPatternUnexpectedToken(classifier); |
(...skipping 23 matching lines...) Expand all Loading... |
2021 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2018 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
2022 duplicate_loc); | 2019 duplicate_loc); |
2023 } | 2020 } |
2024 expression = this->ParseArrowFunctionLiteral( | 2021 expression = this->ParseArrowFunctionLiteral( |
2025 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); | 2022 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); |
2026 if (is_pattern_element) { | 2023 if (is_pattern_element) { |
2027 classifier->RecordPatternError( | 2024 classifier->RecordPatternError( |
2028 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), | 2025 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), |
2029 MessageTemplate::kInvalidDestructuringTarget); | 2026 MessageTemplate::kInvalidDestructuringTarget); |
2030 } | 2027 } |
| 2028 |
| 2029 if (fni_ != nullptr) fni_->Infer(); |
| 2030 |
2031 return expression; | 2031 return expression; |
2032 } | 2032 } |
2033 | 2033 |
2034 if (this->IsValidReferenceExpression(expression)) { | 2034 if (this->IsValidReferenceExpression(expression)) { |
2035 arrow_formals_classifier.ForgiveAssignmentPatternError(); | 2035 arrow_formals_classifier.ForgiveAssignmentPatternError(); |
2036 } | 2036 } |
2037 | 2037 |
2038 // "expression" was not itself an arrow function parameter list, but it might | 2038 // "expression" was not itself an arrow function parameter list, but it might |
2039 // form part of one. Propagate speculative formal parameter error locations. | 2039 // form part of one. Propagate speculative formal parameter error locations. |
2040 classifier->Accumulate( | 2040 classifier->Accumulate( |
2041 arrow_formals_classifier, | 2041 arrow_formals_classifier, |
2042 ExpressionClassifier::StandardProductions | | 2042 ExpressionClassifier::StandardProductions | |
2043 ExpressionClassifier::FormalParametersProductions | | 2043 ExpressionClassifier::FormalParametersProductions | |
2044 ExpressionClassifier::CoverInitializedNameProduction); | 2044 ExpressionClassifier::CoverInitializedNameProduction); |
2045 | 2045 |
2046 bool maybe_pattern = | 2046 bool maybe_pattern = |
2047 expression->IsObjectLiteral() || expression->IsArrayLiteral(); | 2047 expression->IsObjectLiteral() || expression->IsArrayLiteral(); |
2048 // bool binding_pattern = | 2048 // bool binding_pattern = |
2049 // allow_harmony_destructuring_bind() && maybe_pattern && !is_rhs; | 2049 // allow_harmony_destructuring_bind() && maybe_pattern && !is_rhs; |
2050 | 2050 |
2051 if (!Token::IsAssignmentOp(peek())) { | 2051 if (!Token::IsAssignmentOp(peek())) { |
2052 if (fni_ != NULL) fni_->Leave(); | |
2053 // Parsed conditional expression only (no assignment). | 2052 // Parsed conditional expression only (no assignment). |
2054 if (is_pattern_element && !this->IsValidReferenceExpression(expression) && | 2053 if (is_pattern_element && !this->IsValidReferenceExpression(expression) && |
2055 !maybe_pattern) { | 2054 !maybe_pattern) { |
2056 classifier->RecordPatternError( | 2055 classifier->RecordPatternError( |
2057 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), | 2056 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), |
2058 MessageTemplate::kInvalidDestructuringTarget); | 2057 MessageTemplate::kInvalidDestructuringTarget); |
2059 } else if (is_rhs && maybe_pattern) { | 2058 } else if (is_rhs && maybe_pattern) { |
2060 ValidateExpression(classifier, CHECK_OK); | 2059 ValidateExpression(classifier, CHECK_OK); |
2061 } | 2060 } |
2062 | 2061 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2118 if (fni_ != NULL) { | 2117 if (fni_ != NULL) { |
2119 // Check if the right hand side is a call to avoid inferring a | 2118 // Check if the right hand side is a call to avoid inferring a |
2120 // name if we're dealing with "a = function(){...}();"-like | 2119 // name if we're dealing with "a = function(){...}();"-like |
2121 // expression. | 2120 // expression. |
2122 if ((op == Token::INIT || op == Token::ASSIGN) && | 2121 if ((op == Token::INIT || op == Token::ASSIGN) && |
2123 (!right->IsCall() && !right->IsCallNew())) { | 2122 (!right->IsCall() && !right->IsCallNew())) { |
2124 fni_->Infer(); | 2123 fni_->Infer(); |
2125 } else { | 2124 } else { |
2126 fni_->RemoveLastFunction(); | 2125 fni_->RemoveLastFunction(); |
2127 } | 2126 } |
2128 fni_->Leave(); | |
2129 } | 2127 } |
2130 | 2128 |
2131 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); | 2129 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); |
2132 | 2130 |
2133 if (is_destructuring_assignment) { | 2131 if (is_destructuring_assignment) { |
2134 result = factory()->NewRewritableAssignmentExpression(result); | 2132 result = factory()->NewRewritableAssignmentExpression(result); |
2135 Traits::QueueDestructuringAssignmentForRewriting(result); | 2133 Traits::QueueDestructuringAssignmentForRewriting(result); |
2136 } | 2134 } |
2137 | 2135 |
2138 return result; | 2136 return result; |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2597 | 2595 |
2598 | 2596 |
2599 template <class Traits> | 2597 template <class Traits> |
2600 typename ParserBase<Traits>::ExpressionT | 2598 typename ParserBase<Traits>::ExpressionT |
2601 ParserBase<Traits>::ParseStrongInitializationExpression( | 2599 ParserBase<Traits>::ParseStrongInitializationExpression( |
2602 ExpressionClassifier* classifier, bool* ok) { | 2600 ExpressionClassifier* classifier, bool* ok) { |
2603 // InitializationExpression :: (strong mode) | 2601 // InitializationExpression :: (strong mode) |
2604 // 'this' '.' IdentifierName '=' AssignmentExpression | 2602 // 'this' '.' IdentifierName '=' AssignmentExpression |
2605 // 'this' '[' Expression ']' '=' AssignmentExpression | 2603 // 'this' '[' Expression ']' '=' AssignmentExpression |
2606 | 2604 |
2607 if (fni_ != NULL) fni_->Enter(); | 2605 FuncNameInferrer::State fni_state(fni_); |
2608 | 2606 |
2609 Consume(Token::THIS); | 2607 Consume(Token::THIS); |
2610 int pos = position(); | 2608 int pos = position(); |
2611 function_state_->set_this_location(scanner()->location()); | 2609 function_state_->set_this_location(scanner()->location()); |
2612 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); | 2610 ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos); |
2613 | 2611 |
2614 ExpressionT left = this->EmptyExpression(); | 2612 ExpressionT left = this->EmptyExpression(); |
2615 switch (peek()) { | 2613 switch (peek()) { |
2616 case Token::LBRACK: { | 2614 case Token::LBRACK: { |
2617 Consume(Token::LBRACK); | 2615 Consume(Token::LBRACK); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2656 function_state_->AddProperty(); | 2654 function_state_->AddProperty(); |
2657 if (fni_ != NULL) { | 2655 if (fni_ != NULL) { |
2658 // Check if the right hand side is a call to avoid inferring a | 2656 // Check if the right hand side is a call to avoid inferring a |
2659 // name if we're dealing with "this.a = function(){...}();"-like | 2657 // name if we're dealing with "this.a = function(){...}();"-like |
2660 // expression. | 2658 // expression. |
2661 if (!right->IsCall() && !right->IsCallNew()) { | 2659 if (!right->IsCall() && !right->IsCallNew()) { |
2662 fni_->Infer(); | 2660 fni_->Infer(); |
2663 } else { | 2661 } else { |
2664 fni_->RemoveLastFunction(); | 2662 fni_->RemoveLastFunction(); |
2665 } | 2663 } |
2666 fni_->Leave(); | |
2667 } | 2664 } |
2668 | 2665 |
2669 if (function_state_->return_location().IsValid()) { | 2666 if (function_state_->return_location().IsValid()) { |
2670 ReportMessageAt(function_state_->return_location(), | 2667 ReportMessageAt(function_state_->return_location(), |
2671 MessageTemplate::kStrongConstructorReturnMisplaced); | 2668 MessageTemplate::kStrongConstructorReturnMisplaced); |
2672 *ok = false; | 2669 *ok = false; |
2673 return this->EmptyExpression(); | 2670 return this->EmptyExpression(); |
2674 } | 2671 } |
2675 | 2672 |
2676 return factory()->NewAssignment(Token::ASSIGN, left, right, pos); | 2673 return factory()->NewAssignment(Token::ASSIGN, left, right, pos); |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3352 return; | 3349 return; |
3353 } | 3350 } |
3354 has_seen_constructor_ = true; | 3351 has_seen_constructor_ = true; |
3355 return; | 3352 return; |
3356 } | 3353 } |
3357 } | 3354 } |
3358 } // namespace internal | 3355 } // namespace internal |
3359 } // namespace v8 | 3356 } // namespace v8 |
3360 | 3357 |
3361 #endif // V8_PARSING_PARSER_BASE_H | 3358 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |