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 ParseInfo; | 15 class ParseInfo; |
16 | 16 |
17 // A hash map to support fast variable declaration and lookup. | 17 // A hash map to support fast variable declaration and lookup. |
18 class VariableMap: public ZoneHashMap { | 18 class VariableMap: public ZoneHashMap { |
19 public: | 19 public: |
20 explicit VariableMap(Zone* zone); | 20 explicit VariableMap(Zone* zone); |
21 | 21 |
22 virtual ~VariableMap(); | 22 virtual ~VariableMap(); |
23 | 23 |
24 Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode, | 24 Variable* Declare(Scope* scope, const AstRawString* name, VariableMode mode, |
25 Variable::Kind kind, InitializationFlag initialization_flag, | 25 Variable::Kind kind, InitializationFlag initialization_flag, |
26 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 26 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, |
| 27 int declaration_group_start = -1); |
27 | 28 |
28 Variable* Lookup(const AstRawString* name); | 29 Variable* Lookup(const AstRawString* name); |
29 | 30 |
30 Zone* zone() const { return zone_; } | 31 Zone* zone() const { return zone_; } |
31 | 32 |
32 private: | 33 private: |
33 Zone* zone_; | 34 Zone* zone_; |
34 }; | 35 }; |
35 | 36 |
36 | 37 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // Declare a parameter in this scope. When there are duplicated | 125 // Declare a parameter in this scope. When there are duplicated |
125 // parameters the rightmost one 'wins'. However, the implementation | 126 // parameters the rightmost one 'wins'. However, the implementation |
126 // expects all parameters to be declared and from left to right. | 127 // expects all parameters to be declared and from left to right. |
127 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, | 128 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, |
128 bool is_rest, bool* is_duplicate); | 129 bool is_rest, bool* is_duplicate); |
129 | 130 |
130 // Declare a local variable in this scope. If the variable has been | 131 // Declare a local variable in this scope. If the variable has been |
131 // declared before, the previously declared variable is returned. | 132 // declared before, the previously declared variable is returned. |
132 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, | 133 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, |
133 InitializationFlag init_flag, Variable::Kind kind, | 134 InitializationFlag init_flag, Variable::Kind kind, |
134 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 135 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, |
| 136 int declaration_group_start = -1); |
135 | 137 |
136 // Declare an implicit global variable in this scope which must be a | 138 // Declare an implicit global variable in this scope which must be a |
137 // script scope. The variable was introduced (possibly from an inner | 139 // script scope. The variable was introduced (possibly from an inner |
138 // scope) by a reference to an unresolved variable with no intervening | 140 // scope) by a reference to an unresolved variable with no intervening |
139 // with statements or eval calls. | 141 // with statements or eval calls. |
140 Variable* DeclareDynamicGlobal(const AstRawString* name); | 142 Variable* DeclareDynamicGlobal(const AstRawString* name); |
141 | 143 |
142 // Create a new unresolved variable. | 144 // Create a new unresolved variable. |
143 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 145 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
144 const AstRawString* name, | 146 const AstRawString* name, |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 | 406 |
405 // Inner scope list. | 407 // Inner scope list. |
406 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } | 408 ZoneList<Scope*>* inner_scopes() { return &inner_scopes_; } |
407 | 409 |
408 // The scope immediately surrounding this scope, or NULL. | 410 // The scope immediately surrounding this scope, or NULL. |
409 Scope* outer_scope() const { return outer_scope_; } | 411 Scope* outer_scope() const { return outer_scope_; } |
410 | 412 |
411 // The ModuleDescriptor for this scope; only for module scopes. | 413 // The ModuleDescriptor for this scope; only for module scopes. |
412 ModuleDescriptor* module() const { return module_descriptor_; } | 414 ModuleDescriptor* module() const { return module_descriptor_; } |
413 | 415 |
| 416 |
| 417 void set_class_declaration_group_start(int position) { |
| 418 class_declaration_group_start_ = position; |
| 419 } |
| 420 |
| 421 int class_declaration_group_start() const { |
| 422 return class_declaration_group_start_; |
| 423 } |
| 424 |
414 // --------------------------------------------------------------------------- | 425 // --------------------------------------------------------------------------- |
415 // Variable allocation. | 426 // Variable allocation. |
416 | 427 |
417 // Collect stack and context allocated local variables in this scope. Note | 428 // Collect stack and context allocated local variables in this scope. Note |
418 // that the function variable - if present - is not collected and should be | 429 // that the function variable - if present - is not collected and should be |
419 // handled separately. | 430 // handled separately. |
420 void CollectStackAndContextLocals( | 431 void CollectStackAndContextLocals( |
421 ZoneList<Variable*>* stack_locals, ZoneList<Variable*>* context_locals, | 432 ZoneList<Variable*>* stack_locals, ZoneList<Variable*>* context_locals, |
422 ZoneList<Variable*>* strong_mode_free_variables = nullptr); | 433 ZoneList<Variable*>* strong_mode_free_variables = nullptr); |
423 | 434 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 MUST_USE_RESULT | 681 MUST_USE_RESULT |
671 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy, | 682 bool ResolveVariable(ParseInfo* info, VariableProxy* proxy, |
672 AstNodeFactory* factory); | 683 AstNodeFactory* factory); |
673 MUST_USE_RESULT | 684 MUST_USE_RESULT |
674 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory); | 685 bool ResolveVariablesRecursively(ParseInfo* info, AstNodeFactory* factory); |
675 | 686 |
676 bool CheckStrongModeDeclaration(VariableProxy* proxy, Variable* var); | 687 bool CheckStrongModeDeclaration(VariableProxy* proxy, Variable* var); |
677 | 688 |
678 // If this scope is a method scope of a class, return the corresponding | 689 // If this scope is a method scope of a class, return the corresponding |
679 // class variable, otherwise nullptr. | 690 // class variable, otherwise nullptr. |
680 Variable* ClassVariableForMethod() const; | 691 ClassVariable* ClassVariableForMethod() const; |
681 | 692 |
682 // Scope analysis. | 693 // Scope analysis. |
683 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); | 694 void PropagateScopeInfo(bool outer_scope_calls_sloppy_eval); |
684 bool HasTrivialContext() const; | 695 bool HasTrivialContext() const; |
685 | 696 |
686 // Predicates. | 697 // Predicates. |
687 bool MustAllocate(Variable* var); | 698 bool MustAllocate(Variable* var); |
688 bool MustAllocateInContext(Variable* var); | 699 bool MustAllocateInContext(Variable* var); |
689 bool HasArgumentsParameter(Isolate* isolate); | 700 bool HasArgumentsParameter(Isolate* isolate); |
690 | 701 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 } | 736 } |
726 | 737 |
727 void SetDefaults(ScopeType type, Scope* outer_scope, | 738 void SetDefaults(ScopeType type, Scope* outer_scope, |
728 Handle<ScopeInfo> scope_info, | 739 Handle<ScopeInfo> scope_info, |
729 FunctionKind function_kind = kNormalFunction); | 740 FunctionKind function_kind = kNormalFunction); |
730 | 741 |
731 AstValueFactory* ast_value_factory_; | 742 AstValueFactory* ast_value_factory_; |
732 Zone* zone_; | 743 Zone* zone_; |
733 | 744 |
734 PendingCompilationErrorHandler pending_error_handler_; | 745 PendingCompilationErrorHandler pending_error_handler_; |
| 746 |
| 747 // For tracking which classes are declared consecutively. Needed for strong |
| 748 // mode. |
| 749 int class_declaration_group_start_; |
735 }; | 750 }; |
736 | 751 |
737 } } // namespace v8::internal | 752 } } // namespace v8::internal |
738 | 753 |
739 #endif // V8_SCOPES_H_ | 754 #endif // V8_SCOPES_H_ |
OLD | NEW |