| 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/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/base/hashmap.h" | 9 #include "src/base/hashmap.h" |
| 10 #include "src/globals.h" | 10 #include "src/globals.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 159 |
| 160 // Create a new unresolved variable. | 160 // Create a new unresolved variable. |
| 161 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 161 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
| 162 const AstRawString* name, | 162 const AstRawString* name, |
| 163 int start_position = kNoSourcePosition, | 163 int start_position = kNoSourcePosition, |
| 164 int end_position = kNoSourcePosition, | 164 int end_position = kNoSourcePosition, |
| 165 Variable::Kind kind = Variable::NORMAL) { | 165 Variable::Kind kind = Variable::NORMAL) { |
| 166 // Note that we must not share the unresolved variables with | 166 // Note that we must not share the unresolved variables with |
| 167 // the same name because they may be removed selectively via | 167 // the same name because they may be removed selectively via |
| 168 // RemoveUnresolved(). | 168 // RemoveUnresolved(). |
| 169 DCHECK(!already_resolved()); | 169 DCHECK(!already_resolved_); |
| 170 DCHECK_EQ(factory->zone(), zone()); | 170 DCHECK_EQ(factory->zone(), zone()); |
| 171 VariableProxy* proxy = | 171 VariableProxy* proxy = |
| 172 factory->NewVariableProxy(name, kind, start_position, end_position); | 172 factory->NewVariableProxy(name, kind, start_position, end_position); |
| 173 proxy->set_next_unresolved(unresolved_); | 173 proxy->set_next_unresolved(unresolved_); |
| 174 unresolved_ = proxy; | 174 unresolved_ = proxy; |
| 175 return proxy; | 175 return proxy; |
| 176 } | 176 } |
| 177 | 177 |
| 178 void AddUnresolved(VariableProxy* proxy) { | 178 void AddUnresolved(VariableProxy* proxy) { |
| 179 DCHECK(!already_resolved()); | 179 DCHECK(!already_resolved_); |
| 180 DCHECK(!proxy->is_resolved()); | 180 DCHECK(!proxy->is_resolved()); |
| 181 proxy->set_next_unresolved(unresolved_); | 181 proxy->set_next_unresolved(unresolved_); |
| 182 unresolved_ = proxy; | 182 unresolved_ = proxy; |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Remove a unresolved variable. During parsing, an unresolved variable | 185 // Remove a unresolved variable. During parsing, an unresolved variable |
| 186 // may have been added optimistically, but then only the variable name | 186 // may have been added optimistically, but then only the variable name |
| 187 // was used (typically for labels). If the variable was not declared, the | 187 // was used (typically for labels). If the variable was not declared, the |
| 188 // addition introduced a new unresolved variable which may end up being | 188 // addition introduced a new unresolved variable which may end up being |
| 189 // allocated globally as a "ghost" variable. RemoveUnresolved removes | 189 // allocated globally as a "ghost" variable. RemoveUnresolved removes |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 void set_end_position(int statement_pos) { | 282 void set_end_position(int statement_pos) { |
| 283 end_position_ = statement_pos; | 283 end_position_ = statement_pos; |
| 284 } | 284 } |
| 285 | 285 |
| 286 // Scopes created for desugaring are hidden. I.e. not visible to the debugger. | 286 // Scopes created for desugaring are hidden. I.e. not visible to the debugger. |
| 287 bool is_hidden() const { return is_hidden_; } | 287 bool is_hidden() const { return is_hidden_; } |
| 288 void set_is_hidden() { is_hidden_ = true; } | 288 void set_is_hidden() { is_hidden_ = true; } |
| 289 | 289 |
| 290 // In some cases we want to force context allocation for a whole scope. | 290 // In some cases we want to force context allocation for a whole scope. |
| 291 void ForceContextAllocation() { | 291 void ForceContextAllocation() { |
| 292 DCHECK(!already_resolved()); | 292 DCHECK(!already_resolved_); |
| 293 force_context_allocation_ = true; | 293 force_context_allocation_ = true; |
| 294 } | 294 } |
| 295 bool has_forced_context_allocation() const { | 295 bool has_forced_context_allocation() const { |
| 296 return force_context_allocation_; | 296 return force_context_allocation_; |
| 297 } | 297 } |
| 298 | 298 |
| 299 // --------------------------------------------------------------------------- | 299 // --------------------------------------------------------------------------- |
| 300 // Predicates. | 300 // Predicates. |
| 301 | 301 |
| 302 // Specific scope types. | 302 // Specific scope types. |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 // form a linked list of all unresolved proxies. | 464 // form a linked list of all unresolved proxies. |
| 465 VariableProxy* unresolved_; | 465 VariableProxy* unresolved_; |
| 466 // Declarations. | 466 // Declarations. |
| 467 ZoneList<Declaration*> decls_; | 467 ZoneList<Declaration*> decls_; |
| 468 | 468 |
| 469 // Serialized scope info support. | 469 // Serialized scope info support. |
| 470 Handle<ScopeInfo> scope_info_; | 470 Handle<ScopeInfo> scope_info_; |
| 471 // Debugging support. | 471 // Debugging support. |
| 472 #ifdef DEBUG | 472 #ifdef DEBUG |
| 473 const AstRawString* scope_name_; | 473 const AstRawString* scope_name_; |
| 474 |
| 475 // True if it doesn't need scope resolution (e.g., if the scope was |
| 476 // constructed based on a serialized scope info or a catch context). |
| 477 bool already_resolved_ : 1; |
| 474 #endif | 478 #endif |
| 475 | 479 |
| 476 // Source positions. | 480 // Source positions. |
| 477 int start_position_; | 481 int start_position_; |
| 478 int end_position_; | 482 int end_position_; |
| 479 | 483 |
| 480 // Computed via AllocateVariables. | 484 // Computed via AllocateVariables. |
| 481 int num_stack_slots_; | 485 int num_stack_slots_; |
| 482 int num_heap_slots_; | 486 int num_heap_slots_; |
| 483 int num_global_slots_; | 487 int num_global_slots_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 508 bool is_hidden_ : 1; | 512 bool is_hidden_ : 1; |
| 509 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. | 513 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. |
| 510 bool is_debug_evaluate_scope_ : 1; | 514 bool is_debug_evaluate_scope_ : 1; |
| 511 | 515 |
| 512 // Computed via PropagateScopeInfo. | 516 // Computed via PropagateScopeInfo. |
| 513 bool outer_scope_calls_sloppy_eval_ : 1; | 517 bool outer_scope_calls_sloppy_eval_ : 1; |
| 514 bool inner_scope_calls_eval_ : 1; | 518 bool inner_scope_calls_eval_ : 1; |
| 515 bool force_eager_compilation_ : 1; | 519 bool force_eager_compilation_ : 1; |
| 516 bool force_context_allocation_ : 1; | 520 bool force_context_allocation_ : 1; |
| 517 | 521 |
| 518 // True if it doesn't need scope resolution (e.g., if the scope was | |
| 519 // constructed based on a serialized scope info or a catch context). | |
| 520 bool already_resolved_ : 1; | |
| 521 bool already_resolved() { return already_resolved_; } | |
| 522 | |
| 523 // True if it holds 'var' declarations. | 522 // True if it holds 'var' declarations. |
| 524 bool is_declaration_scope_ : 1; | 523 bool is_declaration_scope_ : 1; |
| 525 | 524 |
| 526 // Create a non-local variable with a given name. | 525 // Create a non-local variable with a given name. |
| 527 // These variables are looked up dynamically at runtime. | 526 // These variables are looked up dynamically at runtime. |
| 528 Variable* NonLocal(const AstRawString* name, VariableMode mode); | 527 Variable* NonLocal(const AstRawString* name, VariableMode mode); |
| 529 | 528 |
| 530 // Variable resolution. | 529 // Variable resolution. |
| 531 // Possible results of a recursive variable lookup telling if and how a | 530 // Possible results of a recursive variable lookup telling if and how a |
| 532 // variable is bound. These are returned in the output parameter *binding_kind | 531 // variable is bound. These are returned in the output parameter *binding_kind |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 (is_function_scope() && (IsClassConstructor(function_kind()) || | 795 (is_function_scope() && (IsClassConstructor(function_kind()) || |
| 797 IsConciseMethod(function_kind()) || | 796 IsConciseMethod(function_kind()) || |
| 798 IsAccessorFunction(function_kind())))); | 797 IsAccessorFunction(function_kind())))); |
| 799 return this_function_; | 798 return this_function_; |
| 800 } | 799 } |
| 801 | 800 |
| 802 // Adds a temporary variable in this scope's TemporaryScope. This is for | 801 // Adds a temporary variable in this scope's TemporaryScope. This is for |
| 803 // adjusting the scope of temporaries used when desugaring parameter | 802 // adjusting the scope of temporaries used when desugaring parameter |
| 804 // initializers. | 803 // initializers. |
| 805 void AddTemporary(Variable* var) { | 804 void AddTemporary(Variable* var) { |
| 806 DCHECK(!already_resolved()); | 805 DCHECK(!already_resolved_); |
| 807 // Temporaries are only placed in ClosureScopes. | 806 // Temporaries are only placed in ClosureScopes. |
| 808 DCHECK_EQ(GetClosureScope(), this); | 807 DCHECK_EQ(GetClosureScope(), this); |
| 809 temps_.Add(var, zone()); | 808 temps_.Add(var, zone()); |
| 810 } | 809 } |
| 811 | 810 |
| 812 ZoneList<Variable*>* temps() { return &temps_; } | 811 ZoneList<Variable*>* temps() { return &temps_; } |
| 813 | 812 |
| 814 void DeclareSloppyBlockFunction(const AstRawString* name, | 813 void DeclareSloppyBlockFunction(const AstRawString* name, |
| 815 SloppyBlockFunctionStatement* statement) { | 814 SloppyBlockFunctionStatement* statement) { |
| 816 sloppy_block_function_map_.Declare(zone(), name, statement); | 815 sloppy_block_function_map_.Declare(zone(), name, statement); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 // Convenience variable; Subclass constructor only | 882 // Convenience variable; Subclass constructor only |
| 884 Variable* this_function_; | 883 Variable* this_function_; |
| 885 // Module descriptor; module scopes only. | 884 // Module descriptor; module scopes only. |
| 886 ModuleDescriptor* module_descriptor_; | 885 ModuleDescriptor* module_descriptor_; |
| 887 }; | 886 }; |
| 888 | 887 |
| 889 } // namespace internal | 888 } // namespace internal |
| 890 } // namespace v8 | 889 } // namespace v8 |
| 891 | 890 |
| 892 #endif // V8_AST_SCOPES_H_ | 891 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |