| 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 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 void CheckArityRestrictions(int param_count, FunctionKind function_type, | 1206 void CheckArityRestrictions(int param_count, FunctionKind function_type, |
| 1207 bool has_rest, int formals_start_pos, | 1207 bool has_rest, int formals_start_pos, |
| 1208 int formals_end_pos, bool* ok); | 1208 int formals_end_pos, bool* ok); |
| 1209 | 1209 |
| 1210 BlockT ParseVariableDeclarations(VariableDeclarationContext var_context, | 1210 BlockT ParseVariableDeclarations(VariableDeclarationContext var_context, |
| 1211 DeclarationParsingResult* parsing_result, | 1211 DeclarationParsingResult* parsing_result, |
| 1212 ZoneList<const AstRawString*>* names, | 1212 ZoneList<const AstRawString*>* names, |
| 1213 bool* ok); | 1213 bool* ok); |
| 1214 StatementT ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, | 1214 StatementT ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, |
| 1215 bool default_export, bool* ok); | 1215 bool default_export, bool* ok); |
| 1216 StatementT ParseFunctionDeclaration(bool* ok); |
| 1216 StatementT ParseHoistableDeclaration(ZoneList<const AstRawString*>* names, | 1217 StatementT ParseHoistableDeclaration(ZoneList<const AstRawString*>* names, |
| 1217 bool default_export, bool* ok); | 1218 bool default_export, bool* ok); |
| 1218 StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, | 1219 StatementT ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, |
| 1219 ZoneList<const AstRawString*>* names, | 1220 ZoneList<const AstRawString*>* names, |
| 1220 bool default_export, bool* ok); | 1221 bool default_export, bool* ok); |
| 1221 StatementT ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 1222 StatementT ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
| 1222 bool default_export, bool* ok); | 1223 bool default_export, bool* ok); |
| 1223 StatementT ParseNativeDeclaration(bool* ok); | 1224 StatementT ParseNativeDeclaration(bool* ok); |
| 1224 | 1225 |
| 1225 // Under some circumstances, we allow preparsing to abort if the preparsed | 1226 // Under some circumstances, we allow preparsing to abort if the preparsed |
| (...skipping 2433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3659 | 3660 |
| 3660 parsing_result->bindings_loc = | 3661 parsing_result->bindings_loc = |
| 3661 Scanner::Location(bindings_start, scanner()->location().end_pos); | 3662 Scanner::Location(bindings_start, scanner()->location().end_pos); |
| 3662 | 3663 |
| 3663 DCHECK(*ok); | 3664 DCHECK(*ok); |
| 3664 return init_block; | 3665 return init_block; |
| 3665 } | 3666 } |
| 3666 | 3667 |
| 3667 template <typename Impl> | 3668 template <typename Impl> |
| 3668 typename ParserBase<Impl>::StatementT | 3669 typename ParserBase<Impl>::StatementT |
| 3670 ParserBase<Impl>::ParseFunctionDeclaration(bool* ok) { |
| 3671 Consume(Token::FUNCTION); |
| 3672 int pos = position(); |
| 3673 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; |
| 3674 if (Check(Token::MUL)) { |
| 3675 flags |= ParseFunctionFlags::kIsGenerator; |
| 3676 if (allow_harmony_restrictive_declarations()) { |
| 3677 impl()->ReportMessageAt(scanner()->location(), |
| 3678 MessageTemplate::kGeneratorInLegacyContext); |
| 3679 *ok = false; |
| 3680 return impl()->NullStatement(); |
| 3681 } |
| 3682 } |
| 3683 return ParseHoistableDeclaration(pos, flags, nullptr, false, ok); |
| 3684 } |
| 3685 |
| 3686 template <typename Impl> |
| 3687 typename ParserBase<Impl>::StatementT |
| 3669 ParserBase<Impl>::ParseHoistableDeclaration( | 3688 ParserBase<Impl>::ParseHoistableDeclaration( |
| 3670 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { | 3689 ZoneList<const AstRawString*>* names, bool default_export, bool* ok) { |
| 3671 Expect(Token::FUNCTION, CHECK_OK_CUSTOM(NullStatement)); | 3690 Expect(Token::FUNCTION, CHECK_OK_CUSTOM(NullStatement)); |
| 3672 int pos = position(); | 3691 int pos = position(); |
| 3673 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; | 3692 ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal; |
| 3674 if (Check(Token::MUL)) { | 3693 if (Check(Token::MUL)) { |
| 3675 flags |= ParseFunctionFlags::kIsGenerator; | 3694 flags |= ParseFunctionFlags::kIsGenerator; |
| 3676 } | 3695 } |
| 3677 return ParseHoistableDeclaration(pos, flags, names, default_export, ok); | 3696 return ParseHoistableDeclaration(pos, flags, names, default_export, ok); |
| 3678 } | 3697 } |
| (...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4609 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); | 4628 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); |
| 4610 } else { | 4629 } else { |
| 4611 if (legacy) { | 4630 if (legacy) { |
| 4612 impl()->CountUsage(v8::Isolate::kLegacyFunctionDeclaration); | 4631 impl()->CountUsage(v8::Isolate::kLegacyFunctionDeclaration); |
| 4613 } | 4632 } |
| 4614 // Make a block around the statement for a lexical binding | 4633 // Make a block around the statement for a lexical binding |
| 4615 // is introduced by a FunctionDeclaration. | 4634 // is introduced by a FunctionDeclaration. |
| 4616 BlockState block_state(zone(), &scope_state_); | 4635 BlockState block_state(zone(), &scope_state_); |
| 4617 block_state.set_start_position(scanner()->location().beg_pos); | 4636 block_state.set_start_position(scanner()->location().beg_pos); |
| 4618 BlockT block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); | 4637 BlockT block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition); |
| 4619 StatementT body = impl()->ParseFunctionDeclaration(CHECK_OK); | 4638 StatementT body = ParseFunctionDeclaration(CHECK_OK); |
| 4620 block->statements()->Add(body, zone()); | 4639 block->statements()->Add(body, zone()); |
| 4621 block_state.set_end_position(scanner()->location().end_pos); | 4640 block_state.set_end_position(scanner()->location().end_pos); |
| 4622 block->set_scope(block_state.FinalizedBlockScope()); | 4641 block->set_scope(block_state.FinalizedBlockScope()); |
| 4623 return block; | 4642 return block; |
| 4624 } | 4643 } |
| 4625 } | 4644 } |
| 4626 | 4645 |
| 4627 template <typename Impl> | 4646 template <typename Impl> |
| 4628 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseVariableStatement( | 4647 typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseVariableStatement( |
| 4629 VariableDeclarationContext var_context, | 4648 VariableDeclarationContext var_context, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4696 if (peek() == Token::COLON && starts_with_identifier && | 4715 if (peek() == Token::COLON && starts_with_identifier && |
| 4697 impl()->IsIdentifier(expr)) { | 4716 impl()->IsIdentifier(expr)) { |
| 4698 // The whole expression was a single identifier, and not, e.g., | 4717 // The whole expression was a single identifier, and not, e.g., |
| 4699 // something starting with an identifier or a parenthesized identifier. | 4718 // something starting with an identifier or a parenthesized identifier. |
| 4700 labels = impl()->DeclareLabel(labels, impl()->AsIdentifierExpression(expr), | 4719 labels = impl()->DeclareLabel(labels, impl()->AsIdentifierExpression(expr), |
| 4701 CHECK_OK); | 4720 CHECK_OK); |
| 4702 Consume(Token::COLON); | 4721 Consume(Token::COLON); |
| 4703 // ES#sec-labelled-function-declarations Labelled Function Declarations | 4722 // ES#sec-labelled-function-declarations Labelled Function Declarations |
| 4704 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { | 4723 if (peek() == Token::FUNCTION && is_sloppy(language_mode())) { |
| 4705 if (allow_function == kAllowLabelledFunctionStatement) { | 4724 if (allow_function == kAllowLabelledFunctionStatement) { |
| 4706 return impl()->ParseFunctionDeclaration(ok); | 4725 return ParseFunctionDeclaration(ok); |
| 4707 } else { | 4726 } else { |
| 4708 return ParseScopedStatement(labels, true, ok); | 4727 return ParseScopedStatement(labels, true, ok); |
| 4709 } | 4728 } |
| 4710 } | 4729 } |
| 4711 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); | 4730 return ParseStatement(labels, kDisallowLabelledFunctionStatement, ok); |
| 4712 } | 4731 } |
| 4713 | 4732 |
| 4714 // If we have an extension, we allow a native function declaration. | 4733 // If we have an extension, we allow a native function declaration. |
| 4715 // A native function declaration starts with "native function" with | 4734 // A native function declaration starts with "native function" with |
| 4716 // no line-terminator between the two words. | 4735 // no line-terminator between the two words. |
| (...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5437 has_seen_constructor_ = true; | 5456 has_seen_constructor_ = true; |
| 5438 return; | 5457 return; |
| 5439 } | 5458 } |
| 5440 } | 5459 } |
| 5441 | 5460 |
| 5442 | 5461 |
| 5443 } // namespace internal | 5462 } // namespace internal |
| 5444 } // namespace v8 | 5463 } // namespace v8 |
| 5445 | 5464 |
| 5446 #endif // V8_PARSING_PARSER_BASE_H | 5465 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |