| 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/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 lhs = lhs | rhs; | 50 lhs = lhs | rhs; |
| 51 return lhs; | 51 return lhs; |
| 52 } | 52 } |
| 53 | 53 |
| 54 static inline bool operator&(ParseFunctionFlags bitfield, | 54 static inline bool operator&(ParseFunctionFlags bitfield, |
| 55 ParseFunctionFlags mask) { | 55 ParseFunctionFlags mask) { |
| 56 typedef unsigned char T; | 56 typedef unsigned char T; |
| 57 return static_cast<T>(bitfield) & static_cast<T>(mask); | 57 return static_cast<T>(bitfield) & static_cast<T>(mask); |
| 58 } | 58 } |
| 59 | 59 |
| 60 struct FormalParametersBase { | 60 struct FormalParametersBase : public ZoneObject { |
| 61 explicit FormalParametersBase(DeclarationScope* scope) : scope(scope) {} | 61 explicit FormalParametersBase(DeclarationScope* scope) : scope(scope) {} |
| 62 | 62 |
| 63 int num_parameters() const { | 63 int num_parameters() const { |
| 64 // Don't include the rest parameter into the function's formal parameter | 64 // Don't include the rest parameter into the function's formal parameter |
| 65 // count (esp. the SharedFunctionInfo::internal_formal_parameter_count, | 65 // count (esp. the SharedFunctionInfo::internal_formal_parameter_count, |
| 66 // which says whether we need to create an arguments adaptor frame). | 66 // which says whether we need to create an arguments adaptor frame). |
| 67 return arity - has_rest; | 67 return arity - has_rest; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void UpdateArityAndFunctionLength(bool is_optional, bool is_rest) { | 70 void UpdateArityAndFunctionLength(bool is_optional, bool is_rest) { |
| (...skipping 2580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2651 DeclarationScope* scope = | 2651 DeclarationScope* scope = |
| 2652 NewFunctionScope(is_async ? FunctionKind::kAsyncArrowFunction | 2652 NewFunctionScope(is_async ? FunctionKind::kAsyncArrowFunction |
| 2653 : FunctionKind::kArrowFunction); | 2653 : FunctionKind::kArrowFunction); |
| 2654 // Because the arrow's parameters were parsed in the outer scope, any | 2654 // Because the arrow's parameters were parsed in the outer scope, any |
| 2655 // usage flags that might have been triggered there need to be copied | 2655 // usage flags that might have been triggered there need to be copied |
| 2656 // to the arrow scope. | 2656 // to the arrow scope. |
| 2657 this->scope()->PropagateUsageFlagsToScope(scope); | 2657 this->scope()->PropagateUsageFlagsToScope(scope); |
| 2658 | 2658 |
| 2659 scope_snapshot.Reparent(scope); | 2659 scope_snapshot.Reparent(scope); |
| 2660 | 2660 |
| 2661 FormalParametersT parameters(scope); | 2661 FormalParametersT* parameters = new (zone()) FormalParametersT(scope); |
| 2662 if (!classifier()->is_simple_parameter_list()) { | 2662 if (!classifier()->is_simple_parameter_list()) { |
| 2663 scope->SetHasNonSimpleParameters(); | 2663 scope->SetHasNonSimpleParameters(); |
| 2664 parameters.is_simple = false; | 2664 parameters->is_simple = false; |
| 2665 } | 2665 } |
| 2666 | 2666 |
| 2667 checkpoint.Restore(¶meters.materialized_literals_count); | 2667 checkpoint.Restore(¶meters->materialized_literals_count); |
| 2668 | 2668 |
| 2669 scope->set_start_position(lhs_beg_pos); | 2669 scope->set_start_position(lhs_beg_pos); |
| 2670 Scanner::Location duplicate_loc = Scanner::Location::invalid(); | 2670 Scanner::Location duplicate_loc = Scanner::Location::invalid(); |
| 2671 impl()->DeclareArrowFunctionFormalParameters(¶meters, expression, loc, | 2671 impl()->DeclareArrowFunctionFormalParameters(parameters, expression, loc, |
| 2672 &duplicate_loc, CHECK_OK); | 2672 &duplicate_loc, CHECK_OK); |
| 2673 if (duplicate_loc.IsValid()) { | 2673 if (duplicate_loc.IsValid()) { |
| 2674 classifier()->RecordDuplicateFormalParameterError(duplicate_loc); | 2674 classifier()->RecordDuplicateFormalParameterError(duplicate_loc); |
| 2675 } | 2675 } |
| 2676 expression = ParseArrowFunctionLiteral(accept_IN, parameters, CHECK_OK); | 2676 expression = ParseArrowFunctionLiteral(accept_IN, *parameters, CHECK_OK); |
| 2677 impl()->Discard(); | 2677 impl()->Discard(); |
| 2678 classifier()->RecordPatternError(arrow_loc, | 2678 classifier()->RecordPatternError(arrow_loc, |
| 2679 MessageTemplate::kUnexpectedToken, | 2679 MessageTemplate::kUnexpectedToken, |
| 2680 Token::String(Token::ARROW)); | 2680 Token::String(Token::ARROW)); |
| 2681 | 2681 |
| 2682 if (fni_ != nullptr) fni_->Infer(); | 2682 if (fni_ != nullptr) fni_->Infer(); |
| 2683 | 2683 |
| 2684 return expression; | 2684 return expression; |
| 2685 } | 2685 } |
| 2686 | 2686 |
| (...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3493 break; | 3493 break; |
| 3494 } | 3494 } |
| 3495 if (!Check(Token::COMMA)) break; | 3495 if (!Check(Token::COMMA)) break; |
| 3496 if (allow_harmony_trailing_commas() && peek() == Token::RPAREN) { | 3496 if (allow_harmony_trailing_commas() && peek() == Token::RPAREN) { |
| 3497 // allow the trailing comma | 3497 // allow the trailing comma |
| 3498 break; | 3498 break; |
| 3499 } | 3499 } |
| 3500 } | 3500 } |
| 3501 } | 3501 } |
| 3502 | 3502 |
| 3503 for (int i = 0; i < parameters->arity; ++i) { | 3503 impl()->DeclareFormalParameters(parameters->scope, parameters->params); |
| 3504 auto parameter = parameters->at(i); | |
| 3505 impl()->DeclareFormalParameter(parameters->scope, parameter); | |
| 3506 } | |
| 3507 } | 3504 } |
| 3508 | 3505 |
| 3509 template <typename Impl> | 3506 template <typename Impl> |
| 3510 typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseVariableDeclarations( | 3507 typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseVariableDeclarations( |
| 3511 VariableDeclarationContext var_context, | 3508 VariableDeclarationContext var_context, |
| 3512 DeclarationParsingResult* parsing_result, | 3509 DeclarationParsingResult* parsing_result, |
| 3513 ZoneList<const AstRawString*>* names, bool* ok) { | 3510 ZoneList<const AstRawString*>* names, bool* ok) { |
| 3514 // VariableDeclarations :: | 3511 // VariableDeclarations :: |
| 3515 // ('var' | 'const' | 'let') (Identifier ('=' AssignmentExpression)?)+[','] | 3512 // ('var' | 'const' | 'let') (Identifier ('=' AssignmentExpression)?)+[','] |
| 3516 // | 3513 // |
| (...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5457 has_seen_constructor_ = true; | 5454 has_seen_constructor_ = true; |
| 5458 return; | 5455 return; |
| 5459 } | 5456 } |
| 5460 } | 5457 } |
| 5461 | 5458 |
| 5462 | 5459 |
| 5463 } // namespace internal | 5460 } // namespace internal |
| 5464 } // namespace v8 | 5461 } // namespace v8 |
| 5465 | 5462 |
| 5466 #endif // V8_PARSING_PARSER_BASE_H | 5463 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |