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_AST_SCOPES_H_ | 5 #ifndef V8_AST_SCOPES_H_ |
6 #define V8_AST_SCOPES_H_ | 6 #define V8_AST_SCOPES_H_ |
7 | 7 |
8 #include "src/base/hashmap.h" | 8 #include "src/base/hashmap.h" |
9 #include "src/globals.h" | 9 #include "src/globals.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 // --------------------------------------------------------------------------- | 67 // --------------------------------------------------------------------------- |
68 // Construction | 68 // Construction |
69 | 69 |
70 Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type); | 70 Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type); |
71 | 71 |
72 #ifdef DEBUG | 72 #ifdef DEBUG |
73 // The scope name is only used for printing/debugging. | 73 // The scope name is only used for printing/debugging. |
74 void SetScopeName(const AstRawString* scope_name) { | 74 void SetScopeName(const AstRawString* scope_name) { |
75 scope_name_ = scope_name; | 75 scope_name_ = scope_name; |
76 } | 76 } |
77 void set_needs_migration() { needs_migration_ = true; } | |
77 #endif | 78 #endif |
78 | 79 |
79 // TODO(verwaest): Is this needed on Scope? | 80 // TODO(verwaest): Is this needed on Scope? |
80 int num_parameters() const; | 81 int num_parameters() const; |
81 | 82 |
82 DeclarationScope* AsDeclarationScope(); | 83 DeclarationScope* AsDeclarationScope(); |
83 const DeclarationScope* AsDeclarationScope() const; | 84 const DeclarationScope* AsDeclarationScope() const; |
84 ModuleScope* AsModuleScope(); | 85 ModuleScope* AsModuleScope(); |
85 const ModuleScope* AsModuleScope() const; | 86 const ModuleScope* AsModuleScope() const; |
86 | 87 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 | 409 |
409 // Check that all Scopes in the scope tree use the same Zone. | 410 // Check that all Scopes in the scope tree use the same Zone. |
410 void CheckZones(); | 411 void CheckZones(); |
411 #endif | 412 #endif |
412 | 413 |
413 // Retrieve `IsSimpleParameterList` of current or outer function. | 414 // Retrieve `IsSimpleParameterList` of current or outer function. |
414 bool HasSimpleParameters(); | 415 bool HasSimpleParameters(); |
415 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } | 416 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } |
416 bool is_debug_evaluate_scope() const { return is_debug_evaluate_scope_; } | 417 bool is_debug_evaluate_scope() const { return is_debug_evaluate_scope_; } |
417 | 418 |
418 void set_is_lazily_parsed(bool is_lazily_parsed) { | 419 bool is_lazily_parsed() const { return is_lazily_parsed_; } |
419 is_lazily_parsed_ = is_lazily_parsed; | |
420 } | |
421 | 420 |
422 protected: | 421 protected: |
423 explicit Scope(Zone* zone); | 422 explicit Scope(Zone* zone); |
424 | 423 |
425 void set_language_mode(LanguageMode language_mode) { | 424 void set_language_mode(LanguageMode language_mode) { |
426 is_strict_ = is_strict(language_mode); | 425 is_strict_ = is_strict(language_mode); |
427 } | 426 } |
428 | 427 |
429 private: | 428 private: |
430 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, | 429 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 | 478 |
480 // Serialized scope info support. | 479 // Serialized scope info support. |
481 Handle<ScopeInfo> scope_info_; | 480 Handle<ScopeInfo> scope_info_; |
482 // Debugging support. | 481 // Debugging support. |
483 #ifdef DEBUG | 482 #ifdef DEBUG |
484 const AstRawString* scope_name_; | 483 const AstRawString* scope_name_; |
485 | 484 |
486 // True if it doesn't need scope resolution (e.g., if the scope was | 485 // True if it doesn't need scope resolution (e.g., if the scope was |
487 // constructed based on a serialized scope info or a catch context). | 486 // constructed based on a serialized scope info or a catch context). |
488 bool already_resolved_ : 1; | 487 bool already_resolved_ : 1; |
488 // True if this scope may contain objects from a temp zone that needs to be | |
489 // fixed up. | |
490 bool needs_migration_ : 1; | |
adamk
2016/09/27 20:33:17
Can we remove these ": 1"s from these debug-only f
| |
489 #endif | 491 #endif |
490 | 492 |
491 // Source positions. | 493 // Source positions. |
492 int start_position_; | 494 int start_position_; |
493 int end_position_; | 495 int end_position_; |
494 | 496 |
495 // Computed via AllocateVariables. | 497 // Computed via AllocateVariables. |
496 int num_stack_slots_; | 498 int num_stack_slots_; |
497 int num_heap_slots_; | 499 int num_heap_slots_; |
498 | 500 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 MaybeHandle<ScopeInfo> outer_scope); | 561 MaybeHandle<ScopeInfo> outer_scope); |
560 | 562 |
561 // Construct a scope based on the scope info. | 563 // Construct a scope based on the scope info. |
562 Scope(Zone* zone, ScopeType type, Handle<ScopeInfo> scope_info); | 564 Scope(Zone* zone, ScopeType type, Handle<ScopeInfo> scope_info); |
563 | 565 |
564 // Construct a catch scope with a binding for the name. | 566 // Construct a catch scope with a binding for the name. |
565 Scope(Zone* zone, const AstRawString* catch_variable_name, | 567 Scope(Zone* zone, const AstRawString* catch_variable_name, |
566 Handle<ScopeInfo> scope_info); | 568 Handle<ScopeInfo> scope_info); |
567 | 569 |
568 void AddInnerScope(Scope* inner_scope) { | 570 void AddInnerScope(Scope* inner_scope) { |
571 DCHECK(!needs_migration_ || inner_scope->zone() != zone()); | |
marja
2016/09/27 18:54:41
Hmm? Why not DCHECK(needs_migration_ || inner_scop
| |
569 inner_scope->sibling_ = inner_scope_; | 572 inner_scope->sibling_ = inner_scope_; |
570 inner_scope_ = inner_scope; | 573 inner_scope_ = inner_scope; |
571 inner_scope->outer_scope_ = this; | 574 inner_scope->outer_scope_ = this; |
572 } | 575 } |
573 | 576 |
574 void RemoveInnerScope(Scope* inner_scope) { | 577 void RemoveInnerScope(Scope* inner_scope) { |
575 DCHECK_NOT_NULL(inner_scope); | 578 DCHECK_NOT_NULL(inner_scope); |
576 if (inner_scope == inner_scope_) { | 579 if (inner_scope == inner_scope_) { |
577 inner_scope_ = inner_scope_->sibling_; | 580 inner_scope_ = inner_scope_->sibling_; |
578 return; | 581 return; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 // Compute top scope and allocate variables. For lazy compilation the top | 775 // Compute top scope and allocate variables. For lazy compilation the top |
773 // scope only contains the single lazily compiled function, so this | 776 // scope only contains the single lazily compiled function, so this |
774 // doesn't re-allocate variables repeatedly. | 777 // doesn't re-allocate variables repeatedly. |
775 static void Analyze(ParseInfo* info, AnalyzeMode mode); | 778 static void Analyze(ParseInfo* info, AnalyzeMode mode); |
776 | 779 |
777 // To be called during parsing. Do just enough scope analysis that we can | 780 // To be called during parsing. Do just enough scope analysis that we can |
778 // discard the Scope for lazily compiled functions. In particular, this | 781 // discard the Scope for lazily compiled functions. In particular, this |
779 // records variables which cannot be resolved inside the Scope (we don't yet | 782 // records variables which cannot be resolved inside the Scope (we don't yet |
780 // know what they will resolve to since the outer Scopes are incomplete) and | 783 // know what they will resolve to since the outer Scopes are incomplete) and |
781 // migrates them into migrate_to. | 784 // migrates them into migrate_to. |
782 void AnalyzePartially(DeclarationScope* migrate_to, | 785 void AnalyzePartially(AstNodeFactory* ast_node_factory); |
783 AstNodeFactory* ast_node_factory); | |
784 | 786 |
785 Handle<StringSet> CollectNonLocals(ParseInfo* info, | 787 Handle<StringSet> CollectNonLocals(ParseInfo* info, |
786 Handle<StringSet> non_locals); | 788 Handle<StringSet> non_locals); |
787 | 789 |
788 // Determine if we can use lazy compilation for this scope. | 790 // Determine if we can use lazy compilation for this scope. |
789 bool AllowsLazyCompilation() const; | 791 bool AllowsLazyCompilation() const; |
790 | 792 |
791 // Determine if we can use lazy compilation for this scope without a context. | 793 // Determine if we can use lazy compilation for this scope without a context. |
792 bool AllowsLazyCompilationWithoutContext() const; | 794 bool AllowsLazyCompilationWithoutContext() const; |
793 | 795 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 void AllocateModuleVariables(); | 883 void AllocateModuleVariables(); |
882 | 884 |
883 private: | 885 private: |
884 ModuleDescriptor* module_descriptor_; | 886 ModuleDescriptor* module_descriptor_; |
885 }; | 887 }; |
886 | 888 |
887 } // namespace internal | 889 } // namespace internal |
888 } // namespace v8 | 890 } // namespace v8 |
889 | 891 |
890 #endif // V8_AST_SCOPES_H_ | 892 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |