| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 // Declare a local variable in this scope. If the variable has been | 138 // Declare a local variable in this scope. If the variable has been |
| 139 // declared before, the previously declared variable is returned. | 139 // declared before, the previously declared variable is returned. |
| 140 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, | 140 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, |
| 141 InitializationFlag init_flag, Variable::Kind kind, | 141 InitializationFlag init_flag, Variable::Kind kind, |
| 142 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 142 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); |
| 143 | 143 |
| 144 // Declarations list. | 144 // Declarations list. |
| 145 ZoneList<Declaration*>* declarations() { return &decls_; } | 145 ZoneList<Declaration*>* declarations() { return &decls_; } |
| 146 | 146 |
| 147 ZoneList<Variable*>* locals() { return &locals_; } |
| 148 |
| 147 // Create a new unresolved variable. | 149 // Create a new unresolved variable. |
| 148 VariableProxy* NewUnresolved(AstNodeFactory* factory, | 150 VariableProxy* NewUnresolved(AstNodeFactory* factory, |
| 149 const AstRawString* name, | 151 const AstRawString* name, |
| 150 int start_position = kNoSourcePosition, | 152 int start_position = kNoSourcePosition, |
| 151 int end_position = kNoSourcePosition, | 153 int end_position = kNoSourcePosition, |
| 152 Variable::Kind kind = Variable::NORMAL) { | 154 Variable::Kind kind = Variable::NORMAL) { |
| 153 // Note that we must not share the unresolved variables with | 155 // Note that we must not share the unresolved variables with |
| 154 // the same name because they may be removed selectively via | 156 // the same name because they may be removed selectively via |
| 155 // RemoveUnresolved(). | 157 // RemoveUnresolved(). |
| 156 DCHECK(!already_resolved_); | 158 DCHECK(!already_resolved_); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 335 |
| 334 const AstRawString* catch_variable_name() const { | 336 const AstRawString* catch_variable_name() const { |
| 335 DCHECK(is_catch_scope()); | 337 DCHECK(is_catch_scope()); |
| 336 DCHECK_EQ(1, num_var()); | 338 DCHECK_EQ(1, num_var()); |
| 337 return static_cast<AstRawString*>(variables_.Start()->key); | 339 return static_cast<AstRawString*>(variables_.Start()->key); |
| 338 } | 340 } |
| 339 | 341 |
| 340 // --------------------------------------------------------------------------- | 342 // --------------------------------------------------------------------------- |
| 341 // Variable allocation. | 343 // Variable allocation. |
| 342 | 344 |
| 343 // Collect variables in this scope. Note that the function variable - if | |
| 344 // present - is not collected and should be handled separately. | |
| 345 void CollectVariables(ZoneList<Variable*>* stack_locals, | |
| 346 ZoneList<Variable*>* context_locals, | |
| 347 ZoneList<Variable*>* context_globals); | |
| 348 | |
| 349 // Result of variable allocation. | 345 // Result of variable allocation. |
| 350 int num_stack_slots() const { return num_stack_slots_; } | 346 int num_stack_slots() const { return num_stack_slots_; } |
| 351 int num_heap_slots() const { return num_heap_slots_; } | 347 int num_heap_slots() const { return num_heap_slots_; } |
| 352 int num_global_slots() const { return num_global_slots_; } | |
| 353 | 348 |
| 354 int StackLocalCount() const; | 349 int StackLocalCount() const; |
| 355 int ContextLocalCount() const; | 350 int ContextLocalCount() const; |
| 356 int ContextGlobalCount() const; | |
| 357 | 351 |
| 358 // Determine if we can parse a function literal in this scope lazily. | 352 // Determine if we can parse a function literal in this scope lazily. |
| 359 bool AllowsLazyParsing() const; | 353 bool AllowsLazyParsing() const; |
| 360 | 354 |
| 361 // The number of contexts between this and scope; zero if this == scope. | 355 // The number of contexts between this and scope; zero if this == scope. |
| 362 int ContextChainLength(Scope* scope) const; | 356 int ContextChainLength(Scope* scope) const; |
| 363 | 357 |
| 364 // The number of contexts between this and the outermost context that has a | 358 // The number of contexts between this and the outermost context that has a |
| 365 // sloppy eval call. One if this->calls_sloppy_eval(). | 359 // sloppy eval call. One if this->calls_sloppy_eval(). |
| 366 int ContextChainLengthUntilOutermostSloppyEval() const; | 360 int ContextChainLengthUntilOutermostSloppyEval() const; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 bool already_resolved_ : 1; | 470 bool already_resolved_ : 1; |
| 477 #endif | 471 #endif |
| 478 | 472 |
| 479 // Source positions. | 473 // Source positions. |
| 480 int start_position_; | 474 int start_position_; |
| 481 int end_position_; | 475 int end_position_; |
| 482 | 476 |
| 483 // Computed via AllocateVariables. | 477 // Computed via AllocateVariables. |
| 484 int num_stack_slots_; | 478 int num_stack_slots_; |
| 485 int num_heap_slots_; | 479 int num_heap_slots_; |
| 486 int num_global_slots_; | |
| 487 | 480 |
| 488 // The scope type. | 481 // The scope type. |
| 489 const ScopeType scope_type_; | 482 const ScopeType scope_type_; |
| 490 | 483 |
| 491 // Scope-specific information computed during parsing. | 484 // Scope-specific information computed during parsing. |
| 492 // | 485 // |
| 493 // The language mode of this scope. | 486 // The language mode of this scope. |
| 494 STATIC_ASSERT(LANGUAGE_END == 2); | 487 STATIC_ASSERT(LANGUAGE_END == 2); |
| 495 bool is_strict_ : 1; | 488 bool is_strict_ : 1; |
| 496 // This scope or a nested catch scope or with scope contain an 'eval' call. At | 489 // This scope or a nested catch scope or with scope contain an 'eval' call. At |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 void AllocateModuleVariables(); | 841 void AllocateModuleVariables(); |
| 849 | 842 |
| 850 private: | 843 private: |
| 851 ModuleDescriptor* module_descriptor_; | 844 ModuleDescriptor* module_descriptor_; |
| 852 }; | 845 }; |
| 853 | 846 |
| 854 } // namespace internal | 847 } // namespace internal |
| 855 } // namespace v8 | 848 } // namespace v8 |
| 856 | 849 |
| 857 #endif // V8_AST_SCOPES_H_ | 850 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |