| 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 13 matching lines...) Expand all Loading... |
| 24 kFunctionNameValidityUnknown | 24 kFunctionNameValidityUnknown |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 | 27 |
| 28 struct FormalParametersBase { | 28 struct FormalParametersBase { |
| 29 explicit FormalParametersBase(Scope* scope) : scope(scope) {} | 29 explicit FormalParametersBase(Scope* scope) : scope(scope) {} |
| 30 Scope* scope; | 30 Scope* scope; |
| 31 bool has_rest = false; | 31 bool has_rest = false; |
| 32 bool is_simple = true; | 32 bool is_simple = true; |
| 33 int materialized_literals_count = 0; | 33 int materialized_literals_count = 0; |
| 34 mutable int rest_array_literal_index = -1; | |
| 35 }; | 34 }; |
| 36 | 35 |
| 37 | 36 |
| 38 // Common base class shared between parser and pre-parser. Traits encapsulate | 37 // Common base class shared between parser and pre-parser. Traits encapsulate |
| 39 // the differences between Parser and PreParser: | 38 // the differences between Parser and PreParser: |
| 40 | 39 |
| 41 // - Return types: For example, Parser functions return Expression* and | 40 // - Return types: For example, Parser functions return Expression* and |
| 42 // PreParser functions return PreParserExpression. | 41 // PreParser functions return PreParserExpression. |
| 43 | 42 |
| 44 // - Creating parse tree nodes: Parser generates an AST during the recursive | 43 // - Creating parse tree nodes: Parser generates an AST during the recursive |
| (...skipping 1948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1993 // Because the arrow's parameters were parsed in the outer scope, any | 1992 // Because the arrow's parameters were parsed in the outer scope, any |
| 1994 // usage flags that might have been triggered there need to be copied | 1993 // usage flags that might have been triggered there need to be copied |
| 1995 // to the arrow scope. | 1994 // to the arrow scope. |
| 1996 scope_->PropagateUsageFlagsToScope(scope); | 1995 scope_->PropagateUsageFlagsToScope(scope); |
| 1997 FormalParametersT parameters(scope); | 1996 FormalParametersT parameters(scope); |
| 1998 if (!arrow_formals_classifier.is_simple_parameter_list()) { | 1997 if (!arrow_formals_classifier.is_simple_parameter_list()) { |
| 1999 scope->SetHasNonSimpleParameters(); | 1998 scope->SetHasNonSimpleParameters(); |
| 2000 parameters.is_simple = false; | 1999 parameters.is_simple = false; |
| 2001 } | 2000 } |
| 2002 | 2001 |
| 2003 Scanner::Location duplicate_loc = Scanner::Location::invalid(); | |
| 2004 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, | |
| 2005 &duplicate_loc, CHECK_OK); | |
| 2006 | |
| 2007 checkpoint.Restore(¶meters.materialized_literals_count); | 2002 checkpoint.Restore(¶meters.materialized_literals_count); |
| 2008 | 2003 |
| 2009 scope->set_start_position(lhs_beg_pos); | 2004 scope->set_start_position(lhs_beg_pos); |
| 2005 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
| 2006 this->ParseArrowFunctionFormalParameterList(¶meters, expression, loc, |
| 2007 &duplicate_loc, CHECK_OK); |
| 2010 if (duplicate_loc.IsValid()) { | 2008 if (duplicate_loc.IsValid()) { |
| 2011 arrow_formals_classifier.RecordDuplicateFormalParameterError( | 2009 arrow_formals_classifier.RecordDuplicateFormalParameterError( |
| 2012 duplicate_loc); | 2010 duplicate_loc); |
| 2013 } | 2011 } |
| 2014 expression = this->ParseArrowFunctionLiteral( | 2012 expression = this->ParseArrowFunctionLiteral( |
| 2015 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); | 2013 accept_IN, parameters, arrow_formals_classifier, CHECK_OK); |
| 2016 if (is_pattern_element) { | 2014 if (is_pattern_element) { |
| 2017 classifier->RecordPatternError( | 2015 classifier->RecordPatternError( |
| 2018 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), | 2016 Scanner::Location(lhs_beg_pos, scanner()->location().end_pos), |
| 2019 MessageTemplate::kInvalidDestructuringTarget); | 2017 MessageTemplate::kInvalidDestructuringTarget); |
| (...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2867 ReportUnexpectedToken(next); | 2865 ReportUnexpectedToken(next); |
| 2868 *ok = false; | 2866 *ok = false; |
| 2869 return; | 2867 return; |
| 2870 } | 2868 } |
| 2871 parameters->is_simple = false; | 2869 parameters->is_simple = false; |
| 2872 ValidateFormalParameterInitializer(classifier, ok); | 2870 ValidateFormalParameterInitializer(classifier, ok); |
| 2873 if (!*ok) return; | 2871 if (!*ok) return; |
| 2874 classifier->RecordNonSimpleParameter(); | 2872 classifier->RecordNonSimpleParameter(); |
| 2875 } | 2873 } |
| 2876 | 2874 |
| 2877 if (is_rest) { | |
| 2878 parameters->rest_array_literal_index = | |
| 2879 function_state_->NextMaterializedLiteralIndex(); | |
| 2880 ++parameters->materialized_literals_count; | |
| 2881 } | |
| 2882 | |
| 2883 ExpressionT initializer = Traits::EmptyExpression(); | 2875 ExpressionT initializer = Traits::EmptyExpression(); |
| 2884 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) { | 2876 if (!is_rest && allow_harmony_default_parameters() && Check(Token::ASSIGN)) { |
| 2885 ExpressionClassifier init_classifier; | 2877 ExpressionClassifier init_classifier; |
| 2886 initializer = ParseAssignmentExpression(true, &init_classifier, ok); | 2878 initializer = ParseAssignmentExpression(true, &init_classifier, ok); |
| 2887 if (!*ok) return; | 2879 if (!*ok) return; |
| 2888 ValidateExpression(&init_classifier, ok); | 2880 ValidateExpression(&init_classifier, ok); |
| 2889 ValidateFormalParameterInitializer(&init_classifier, ok); | 2881 ValidateFormalParameterInitializer(&init_classifier, ok); |
| 2890 if (!*ok) return; | 2882 if (!*ok) return; |
| 2891 parameters->is_simple = false; | 2883 parameters->is_simple = false; |
| 2892 classifier->RecordNonSimpleParameter(); | 2884 classifier->RecordNonSimpleParameter(); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3033 | 3025 |
| 3034 if (peek() == Token::LBRACE) { | 3026 if (peek() == Token::LBRACE) { |
| 3035 // Multiple statement body | 3027 // Multiple statement body |
| 3036 Consume(Token::LBRACE); | 3028 Consume(Token::LBRACE); |
| 3037 bool is_lazily_parsed = | 3029 bool is_lazily_parsed = |
| 3038 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); | 3030 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); |
| 3039 if (is_lazily_parsed) { | 3031 if (is_lazily_parsed) { |
| 3040 body = this->NewStatementList(0, zone()); | 3032 body = this->NewStatementList(0, zone()); |
| 3041 this->SkipLazyFunctionBody(&materialized_literal_count, | 3033 this->SkipLazyFunctionBody(&materialized_literal_count, |
| 3042 &expected_property_count, CHECK_OK); | 3034 &expected_property_count, CHECK_OK); |
| 3043 | |
| 3044 if (formal_parameters.materialized_literals_count > 0) { | 3035 if (formal_parameters.materialized_literals_count > 0) { |
| 3045 materialized_literal_count += | 3036 materialized_literal_count += |
| 3046 formal_parameters.materialized_literals_count; | 3037 formal_parameters.materialized_literals_count; |
| 3047 } | 3038 } |
| 3048 } else { | 3039 } else { |
| 3049 body = this->ParseEagerFunctionBody( | 3040 body = this->ParseEagerFunctionBody( |
| 3050 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, | 3041 this->EmptyIdentifier(), RelocInfo::kNoPosition, formal_parameters, |
| 3051 kArrowFunction, FunctionLiteral::ANONYMOUS_EXPRESSION, CHECK_OK); | 3042 kArrowFunction, FunctionLiteral::ANONYMOUS_EXPRESSION, CHECK_OK); |
| 3052 materialized_literal_count = | 3043 materialized_literal_count = |
| 3053 function_state.materialized_literal_count(); | 3044 function_state.materialized_literal_count(); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3342 return; | 3333 return; |
| 3343 } | 3334 } |
| 3344 has_seen_constructor_ = true; | 3335 has_seen_constructor_ = true; |
| 3345 return; | 3336 return; |
| 3346 } | 3337 } |
| 3347 } | 3338 } |
| 3348 } // namespace internal | 3339 } // namespace internal |
| 3349 } // namespace v8 | 3340 } // namespace v8 |
| 3350 | 3341 |
| 3351 #endif // V8_PARSING_PARSER_BASE_H | 3342 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |