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" |
11 #include "src/zone.h" | 11 #include "src/zone.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 class ParseInfo; | 16 class ParseInfo; |
17 | 17 |
18 // A hash map to support fast variable declaration and lookup. | 18 // A hash map to support fast variable declaration and lookup. |
19 class VariableMap: public ZoneHashMap { | 19 class VariableMap: public ZoneHashMap { |
20 public: | 20 public: |
21 explicit VariableMap(Zone* zone); | 21 explicit VariableMap(Zone* zone); |
22 | 22 |
23 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, | 23 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, |
24 VariableMode mode, Variable::Kind kind, | 24 VariableMode mode, Variable::Kind kind, |
25 InitializationFlag initialization_flag, | 25 InitializationFlag initialization_flag, |
26 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); | 26 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, |
| 27 bool* added = nullptr); |
27 | 28 |
28 Variable* Lookup(const AstRawString* name); | 29 Variable* Lookup(const AstRawString* name); |
29 }; | 30 }; |
30 | 31 |
31 | 32 |
32 // The dynamic scope part holds hash maps for the variables that will | 33 // The dynamic scope part holds hash maps for the variables that will |
33 // be looked up dynamically from within eval and with scopes. The objects | 34 // be looked up dynamically from within eval and with scopes. The objects |
34 // are allocated on-demand from Scope::NonLocal to avoid wasting memory | 35 // are allocated on-demand from Scope::NonLocal to avoid wasting memory |
35 // and setup time for scopes that don't need them. | 36 // and setup time for scopes that don't need them. |
36 class DynamicScopePart : public ZoneObject { | 37 class DynamicScopePart : public ZoneObject { |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 // Retrieve `IsSimpleParameterList` of current or outer function. | 441 // Retrieve `IsSimpleParameterList` of current or outer function. |
441 bool HasSimpleParameters(); | 442 bool HasSimpleParameters(); |
442 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } | 443 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } |
443 | 444 |
444 protected: | 445 protected: |
445 void set_language_mode(LanguageMode language_mode) { | 446 void set_language_mode(LanguageMode language_mode) { |
446 is_strict_ = is_strict(language_mode); | 447 is_strict_ = is_strict(language_mode); |
447 } | 448 } |
448 | 449 |
449 private: | 450 private: |
| 451 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, |
| 452 VariableMode mode, Variable::Kind kind, |
| 453 InitializationFlag initialization_flag, |
| 454 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) { |
| 455 bool added; |
| 456 Variable* var = |
| 457 variables_.Declare(zone, scope, name, mode, kind, initialization_flag, |
| 458 maybe_assigned_flag, &added); |
| 459 if (added) ordered_variables_.Add(var, zone); |
| 460 return var; |
| 461 } |
450 Zone* zone_; | 462 Zone* zone_; |
451 | 463 |
452 // Scope tree. | 464 // Scope tree. |
453 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 465 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
454 Scope* inner_scope_; // an inner scope of this scope | 466 Scope* inner_scope_; // an inner scope of this scope |
455 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. | 467 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. |
456 | 468 |
457 // The variables declared in this scope: | 469 // The variables declared in this scope: |
458 // | 470 // |
459 // All user-declared variables (incl. parameters). For script scopes | 471 // All user-declared variables (incl. parameters). For script scopes |
460 // variables may be implicitly 'declared' by being used (possibly in | 472 // variables may be implicitly 'declared' by being used (possibly in |
461 // an inner scope) with no intervening with statements or eval calls. | 473 // an inner scope) with no intervening with statements or eval calls. |
462 VariableMap variables_; | 474 VariableMap variables_; |
| 475 // In case of non-scopeinfo-backed scopes, this contains the variables of the |
| 476 // map above in order of addition. |
| 477 // TODO(verwaest): Thread through Variable. |
| 478 ZoneList<Variable*> ordered_variables_; |
463 // Variables that must be looked up dynamically. | 479 // Variables that must be looked up dynamically. |
464 DynamicScopePart* dynamics_; | 480 DynamicScopePart* dynamics_; |
465 // Unresolved variables referred to from this scope. The proxies themselves | 481 // Unresolved variables referred to from this scope. The proxies themselves |
466 // form a linked list of all unresolved proxies. | 482 // form a linked list of all unresolved proxies. |
467 VariableProxy* unresolved_; | 483 VariableProxy* unresolved_; |
468 // Declarations. | 484 // Declarations. |
469 ZoneList<Declaration*> decls_; | 485 ZoneList<Declaration*> decls_; |
470 | 486 |
471 // Serialized scope info support. | 487 // Serialized scope info support. |
472 Handle<ScopeInfo> scope_info_; | 488 Handle<ScopeInfo> scope_info_; |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 void AllocateModuleVariables(); | 919 void AllocateModuleVariables(); |
904 | 920 |
905 private: | 921 private: |
906 ModuleDescriptor* module_descriptor_; | 922 ModuleDescriptor* module_descriptor_; |
907 }; | 923 }; |
908 | 924 |
909 } // namespace internal | 925 } // namespace internal |
910 } // namespace v8 | 926 } // namespace v8 |
911 | 927 |
912 #endif // V8_AST_SCOPES_H_ | 928 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |