| 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_SCOPES_H_ | 5 #ifndef V8_SCOPES_H_ |
| 6 #define V8_SCOPES_H_ | 6 #define V8_SCOPES_H_ |
| 7 | 7 |
| 8 #include "src/ast.h" | 8 #include "src/ast.h" |
| 9 #include "src/pending-compilation-error-handler.h" | 9 #include "src/pending-compilation-error-handler.h" |
| 10 #include "src/zone.h" | 10 #include "src/zone.h" |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 | 14 |
| 15 class CompilationInfo; | 15 class ParseInfo; |
| 16 | |
| 17 | 16 |
| 18 // A hash map to support fast variable declaration and lookup. | 17 // A hash map to support fast variable declaration and lookup. |
| 19 class VariableMap: public ZoneHashMap { | 18 class VariableMap: public ZoneHashMap { |
| 20 public: | 19 public: |
| 21 explicit VariableMap(Zone* zone); | 20 explicit VariableMap(Zone* zone); |
| 22 | 21 |
| 23 virtual ~VariableMap(); | 22 virtual ~VariableMap(); |
| 24 | 23 |
| 25 Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode, | 24 Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode, |
| 26 bool is_valid_lhs, Variable::Kind kind, | 25 bool is_valid_lhs, Variable::Kind kind, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 public: | 70 public: |
| 72 // --------------------------------------------------------------------------- | 71 // --------------------------------------------------------------------------- |
| 73 // Construction | 72 // Construction |
| 74 | 73 |
| 75 Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, | 74 Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, |
| 76 AstValueFactory* value_factory); | 75 AstValueFactory* value_factory); |
| 77 | 76 |
| 78 // Compute top scope and allocate variables. For lazy compilation the top | 77 // Compute top scope and allocate variables. For lazy compilation the top |
| 79 // scope only contains the single lazily compiled function, so this | 78 // scope only contains the single lazily compiled function, so this |
| 80 // doesn't re-allocate variables repeatedly. | 79 // doesn't re-allocate variables repeatedly. |
| 81 static bool Analyze(CompilationInfo* info); | 80 static bool Analyze(ParseInfo* info); |
| 82 | 81 |
| 83 static Scope* DeserializeScopeChain(Isolate* isolate, Zone* zone, | 82 static Scope* DeserializeScopeChain(Isolate* isolate, Zone* zone, |
| 84 Context* context, Scope* script_scope); | 83 Context* context, Scope* script_scope); |
| 85 | 84 |
| 86 // The scope name is only used for printing/debugging. | 85 // The scope name is only used for printing/debugging. |
| 87 void SetScopeName(const AstRawString* scope_name) { | 86 void SetScopeName(const AstRawString* scope_name) { |
| 88 scope_name_ = scope_name; | 87 scope_name_ = scope_name; |
| 89 } | 88 } |
| 90 | 89 |
| 91 void Initialize(bool subclass_constructor = false); | 90 void Initialize(bool subclass_constructor = false); |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 // contains a 'with' context. | 644 // contains a 'with' context. |
| 646 DYNAMIC_LOOKUP | 645 DYNAMIC_LOOKUP |
| 647 }; | 646 }; |
| 648 | 647 |
| 649 // Lookup a variable reference given by name recursively starting with this | 648 // Lookup a variable reference given by name recursively starting with this |
| 650 // scope. If the code is executed because of a call to 'eval', the context | 649 // scope. If the code is executed because of a call to 'eval', the context |
| 651 // parameter should be set to the calling context of 'eval'. | 650 // parameter should be set to the calling context of 'eval'. |
| 652 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind, | 651 Variable* LookupRecursive(VariableProxy* proxy, BindingKind* binding_kind, |
| 653 AstNodeFactory* factory); | 652 AstNodeFactory* factory); |
| 654 MUST_USE_RESULT | 653 MUST_USE_RESULT |
| 655 bool ResolveVariable(CompilationInfo* info, VariableProxy* proxy, | 654 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy, |
| 656 AstNodeFactory* factory); | 655 AstNodeFactory* factory); |
| 657 MUST_USE_RESULT | 656 MUST_USE_RESULT |
| 658 bool ResolveVariablesRecursively(CompilationInfo* info, | 657 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory); |
| 659 AstNodeFactory* factory); | |
| 660 | 658 |
| 661 // Scope analysis. | 659 // Scope analysis. |
| 662 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); | 660 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); |
| 663 bool HasTrivialContext() const; | 661 bool HasTrivialContext() const; |
| 664 | 662 |
| 665 // Predicates. | 663 // Predicates. |
| 666 bool MustAllocate(Variable* var); | 664 bool MustAllocate(Variable* var); |
| 667 bool MustAllocateInContext(Variable* var); | 665 bool MustAllocateInContext(Variable* var); |
| 668 bool HasArgumentsParameter(Isolate* isolate); | 666 bool HasArgumentsParameter(Isolate* isolate); |
| 669 | 667 |
| 670 // Variable allocation. | 668 // Variable allocation. |
| 671 void AllocateStackSlot(Variable* var); | 669 void AllocateStackSlot(Variable* var); |
| 672 void AllocateHeapSlot(Variable* var); | 670 void AllocateHeapSlot(Variable* var); |
| 673 void AllocateParameterLocals(Isolate* isolate); | 671 void AllocateParameterLocals(Isolate* isolate); |
| 674 void AllocateNonParameterLocal(Isolate* isolate, Variable* var); | 672 void AllocateNonParameterLocal(Isolate* isolate, Variable* var); |
| 675 void AllocateNonParameterLocals(Isolate* isolate); | 673 void AllocateNonParameterLocals(Isolate* isolate); |
| 676 void AllocateVariablesRecursively(Isolate* isolate); | 674 void AllocateVariablesRecursively(Isolate* isolate); |
| 677 void AllocateModulesRecursively(Scope* host_scope); | 675 void AllocateModulesRecursively(Scope* host_scope); |
| 678 | 676 |
| 679 // Resolve and fill in the allocation information for all variables | 677 // Resolve and fill in the allocation information for all variables |
| 680 // in this scopes. Must be called *after* all scopes have been | 678 // in this scopes. Must be called *after* all scopes have been |
| 681 // processed (parsed) to ensure that unresolved variables can be | 679 // processed (parsed) to ensure that unresolved variables can be |
| 682 // resolved properly. | 680 // resolved properly. |
| 683 // | 681 // |
| 684 // In the case of code compiled and run using 'eval', the context | 682 // In the case of code compiled and run using 'eval', the context |
| 685 // parameter is the context in which eval was called. In all other | 683 // parameter is the context in which eval was called. In all other |
| 686 // cases the context parameter is an empty handle. | 684 // cases the context parameter is an empty handle. |
| 687 MUST_USE_RESULT | 685 MUST_USE_RESULT |
| 688 bool AllocateVariables(CompilationInfo* info, AstNodeFactory* factory); | 686 bool AllocateVariables(ParseInfo* info, AstNodeFactory* factory); |
| 689 | 687 |
| 690 private: | 688 private: |
| 691 // Construct a scope based on the scope info. | 689 // Construct a scope based on the scope info. |
| 692 Scope(Zone* zone, Scope* inner_scope, ScopeType type, | 690 Scope(Zone* zone, Scope* inner_scope, ScopeType type, |
| 693 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory); | 691 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory); |
| 694 | 692 |
| 695 // Construct a catch scope with a binding for the name. | 693 // Construct a catch scope with a binding for the name. |
| 696 Scope(Zone* zone, Scope* inner_scope, const AstRawString* catch_variable_name, | 694 Scope(Zone* zone, Scope* inner_scope, const AstRawString* catch_variable_name, |
| 697 AstValueFactory* value_factory); | 695 AstValueFactory* value_factory); |
| 698 | 696 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 709 | 707 |
| 710 AstValueFactory* ast_value_factory_; | 708 AstValueFactory* ast_value_factory_; |
| 711 Zone* zone_; | 709 Zone* zone_; |
| 712 | 710 |
| 713 PendingCompilationErrorHandler pending_error_handler_; | 711 PendingCompilationErrorHandler pending_error_handler_; |
| 714 }; | 712 }; |
| 715 | 713 |
| 716 } } // namespace v8::internal | 714 } } // namespace v8::internal |
| 717 | 715 |
| 718 #endif // V8_SCOPES_H_ | 716 #endif // V8_SCOPES_H_ |
| OLD | NEW |