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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 const Impl* impl() const { return static_cast<const Impl*>(this); } | 191 const Impl* impl() const { return static_cast<const Impl*>(this); } |
192 | 192 |
193 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, | 193 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, |
194 v8::Extension* extension, AstValueFactory* ast_value_factory) | 194 v8::Extension* extension, AstValueFactory* ast_value_factory) |
195 : scope_state_(nullptr), | 195 : scope_state_(nullptr), |
196 function_state_(nullptr), | 196 function_state_(nullptr), |
197 extension_(extension), | 197 extension_(extension), |
198 fni_(nullptr), | 198 fni_(nullptr), |
199 ast_value_factory_(ast_value_factory), | 199 ast_value_factory_(ast_value_factory), |
200 ast_node_factory_(ast_value_factory), | 200 ast_node_factory_(ast_value_factory), |
201 mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly. | |
202 parsing_module_(false), | 201 parsing_module_(false), |
203 stack_limit_(stack_limit), | 202 stack_limit_(stack_limit), |
204 zone_(zone), | 203 zone_(zone), |
205 classifier_(nullptr), | 204 classifier_(nullptr), |
206 scanner_(scanner), | 205 scanner_(scanner), |
207 stack_overflow_(false), | 206 stack_overflow_(false), |
208 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), | 207 default_eager_compile_hint_(FunctionLiteral::kShouldLazyCompile), |
209 allow_lazy_(false), | 208 allow_lazy_(false), |
210 allow_natives_(false), | 209 allow_natives_(false), |
211 allow_tailcalls_(false), | 210 allow_tailcalls_(false), |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 next_materialized_literal_index_; | 583 next_materialized_literal_index_; |
585 function_state_->expected_property_count_ = expected_property_count_; | 584 function_state_->expected_property_count_ = expected_property_count_; |
586 } | 585 } |
587 | 586 |
588 private: | 587 private: |
589 FunctionState* function_state_; | 588 FunctionState* function_state_; |
590 int next_materialized_literal_index_; | 589 int next_materialized_literal_index_; |
591 int expected_property_count_; | 590 int expected_property_count_; |
592 }; | 591 }; |
593 | 592 |
594 class ParsingModeScope BASE_EMBEDDED { | |
595 public: | |
596 ParsingModeScope(ParserBase* parser, Mode mode) | |
597 : parser_(parser), | |
598 old_mode_(parser->mode()) { | |
599 parser_->mode_ = mode; | |
600 } | |
601 ~ParsingModeScope() { | |
602 parser_->mode_ = old_mode_; | |
603 } | |
604 | |
605 private: | |
606 ParserBase* parser_; | |
607 Mode old_mode_; | |
608 }; | |
609 | |
610 struct DeclarationDescriptor { | 593 struct DeclarationDescriptor { |
611 enum Kind { NORMAL, PARAMETER }; | 594 enum Kind { NORMAL, PARAMETER }; |
612 Scope* scope; | 595 Scope* scope; |
613 Scope* hoist_scope; | 596 Scope* hoist_scope; |
614 VariableMode mode; | 597 VariableMode mode; |
615 int declaration_pos; | 598 int declaration_pos; |
616 int initialization_pos; | 599 int initialization_pos; |
617 Kind declaration_kind; | 600 Kind declaration_kind; |
618 }; | 601 }; |
619 | 602 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
746 V8_INLINE DeclarationScope* GetClosureScope() const { | 729 V8_INLINE DeclarationScope* GetClosureScope() const { |
747 return scope()->GetClosureScope(); | 730 return scope()->GetClosureScope(); |
748 } | 731 } |
749 | 732 |
750 Scanner* scanner() const { return scanner_; } | 733 Scanner* scanner() const { return scanner_; } |
751 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } | 734 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } |
752 int position() const { return scanner_->location().beg_pos; } | 735 int position() const { return scanner_->location().beg_pos; } |
753 int peek_position() const { return scanner_->peek_location().beg_pos; } | 736 int peek_position() const { return scanner_->peek_location().beg_pos; } |
754 bool stack_overflow() const { return stack_overflow_; } | 737 bool stack_overflow() const { return stack_overflow_; } |
755 void set_stack_overflow() { stack_overflow_ = true; } | 738 void set_stack_overflow() { stack_overflow_ = true; } |
756 Mode mode() const { return mode_; } | |
757 | 739 |
758 INLINE(Token::Value peek()) { | 740 INLINE(Token::Value peek()) { |
759 if (stack_overflow_) return Token::ILLEGAL; | 741 if (stack_overflow_) return Token::ILLEGAL; |
760 return scanner()->peek(); | 742 return scanner()->peek(); |
761 } | 743 } |
762 | 744 |
763 INLINE(Token::Value PeekAhead()) { | 745 INLINE(Token::Value PeekAhead()) { |
764 if (stack_overflow_) return Token::ILLEGAL; | 746 if (stack_overflow_) return Token::ILLEGAL; |
765 return scanner()->PeekAhead(); | 747 return scanner()->PeekAhead(); |
766 } | 748 } |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1433 } | 1415 } |
1434 | 1416 |
1435 // Parser base's protected field members. | 1417 // Parser base's protected field members. |
1436 | 1418 |
1437 ScopeState* scope_state_; // Scope stack. | 1419 ScopeState* scope_state_; // Scope stack. |
1438 FunctionState* function_state_; // Function state stack. | 1420 FunctionState* function_state_; // Function state stack. |
1439 v8::Extension* extension_; | 1421 v8::Extension* extension_; |
1440 FuncNameInferrer* fni_; | 1422 FuncNameInferrer* fni_; |
1441 AstValueFactory* ast_value_factory_; // Not owned. | 1423 AstValueFactory* ast_value_factory_; // Not owned. |
1442 typename Types::Factory ast_node_factory_; | 1424 typename Types::Factory ast_node_factory_; |
1443 Mode mode_; | |
1444 bool parsing_module_; | 1425 bool parsing_module_; |
1445 uintptr_t stack_limit_; | 1426 uintptr_t stack_limit_; |
1446 | 1427 |
1447 // Parser base's private field members. | 1428 // Parser base's private field members. |
1448 | 1429 |
1449 private: | 1430 private: |
1450 Zone* zone_; | 1431 Zone* zone_; |
1451 ExpressionClassifier* classifier_; | 1432 ExpressionClassifier* classifier_; |
1452 | 1433 |
1453 Scanner* scanner_; | 1434 Scanner* scanner_; |
(...skipping 2463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3917 return impl()->EmptyExpression(); | 3898 return impl()->EmptyExpression(); |
3918 } | 3899 } |
3919 | 3900 |
3920 StatementListT body = impl()->NullStatementList(); | 3901 StatementListT body = impl()->NullStatementList(); |
3921 int materialized_literal_count = -1; | 3902 int materialized_literal_count = -1; |
3922 int expected_property_count = -1; | 3903 int expected_property_count = -1; |
3923 | 3904 |
3924 FunctionKind kind = formal_parameters.scope->function_kind(); | 3905 FunctionKind kind = formal_parameters.scope->function_kind(); |
3925 FunctionLiteral::EagerCompileHint eager_compile_hint = | 3906 FunctionLiteral::EagerCompileHint eager_compile_hint = |
3926 default_eager_compile_hint_; | 3907 default_eager_compile_hint_; |
3927 bool can_preparse = mode() == PARSE_LAZILY && | 3908 bool can_preparse = impl()->mode() == PARSE_LAZILY && |
3928 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; | 3909 eager_compile_hint == FunctionLiteral::kShouldLazyCompile; |
3929 // TODO(marja): consider lazy-parsing inner arrow functions too. is_this | 3910 // TODO(marja): consider lazy-parsing inner arrow functions too. is_this |
3930 // handling in Scope::ResolveVariable needs to change. | 3911 // handling in Scope::ResolveVariable needs to change. |
3931 bool is_lazy_top_level_function = | 3912 bool is_lazy_top_level_function = |
3932 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); | 3913 can_preparse && impl()->AllowsLazyParsingWithoutUnresolvedVariables(); |
3933 bool should_be_used_once_hint = false; | 3914 bool should_be_used_once_hint = false; |
3934 { | 3915 { |
3935 FunctionState function_state(&function_state_, &scope_state_, | 3916 FunctionState function_state(&function_state_, &scope_state_, |
3936 formal_parameters.scope); | 3917 formal_parameters.scope); |
3937 | 3918 |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4398 if (!scope()->HasSimpleParameters()) { | 4379 if (!scope()->HasSimpleParameters()) { |
4399 // TC39 deemed "use strict" directives to be an error when occurring | 4380 // TC39 deemed "use strict" directives to be an error when occurring |
4400 // in the body of a function with non-simple parameter list, on | 4381 // in the body of a function with non-simple parameter list, on |
4401 // 29/7/2015. https://goo.gl/ueA7Ln | 4382 // 29/7/2015. https://goo.gl/ueA7Ln |
4402 impl()->ReportMessageAt( | 4383 impl()->ReportMessageAt( |
4403 token_loc, MessageTemplate::kIllegalLanguageModeDirective, | 4384 token_loc, MessageTemplate::kIllegalLanguageModeDirective, |
4404 "use strict"); | 4385 "use strict"); |
4405 *ok = false; | 4386 *ok = false; |
4406 return kLazyParsingComplete; | 4387 return kLazyParsingComplete; |
4407 } | 4388 } |
4408 // Because declarations in strict eval code don't leak into the scope | |
4409 // of the eval call, it is likely that functions declared in strict | |
4410 // eval code will be used within the eval code, so lazy parsing is | |
4411 // probably not a win. | |
4412 if (scope()->is_eval_scope()) mode_ = PARSE_EAGERLY; | |
Toon Verwaest
2016/11/07 14:38:13
There is no equivalent in the new version. We're t
vogelheim
2016/11/07 14:56:17
Thanks for the comment; I wouldn't have understood
| |
4413 } else if (impl()->IsUseAsmDirective(stat) && | 4389 } else if (impl()->IsUseAsmDirective(stat) && |
4414 token_loc.end_pos - token_loc.beg_pos == | 4390 token_loc.end_pos - token_loc.beg_pos == |
4415 sizeof("use asm") + 1) { | 4391 sizeof("use asm") + 1) { |
4416 // Directive "use asm". | 4392 // Directive "use asm". |
4417 impl()->SetAsmModule(); | 4393 impl()->SetAsmModule(); |
4418 } else if (impl()->IsStringLiteral(stat)) { | 4394 } else if (impl()->IsStringLiteral(stat)) { |
4419 // Possibly an unknown directive. | 4395 // Possibly an unknown directive. |
4420 // Should not change mode, but will increment usage counters | 4396 // Should not change mode, but will increment usage counters |
4421 // as appropriate. Ditto usages below. | 4397 // as appropriate. Ditto usages below. |
4422 RaiseLanguageMode(SLOPPY); | 4398 RaiseLanguageMode(SLOPPY); |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5462 has_seen_constructor_ = true; | 5438 has_seen_constructor_ = true; |
5463 return; | 5439 return; |
5464 } | 5440 } |
5465 } | 5441 } |
5466 | 5442 |
5467 | 5443 |
5468 } // namespace internal | 5444 } // namespace internal |
5469 } // namespace v8 | 5445 } // namespace v8 |
5470 | 5446 |
5471 #endif // V8_PARSING_PARSER_BASE_H | 5447 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |