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 12 matching lines...) Expand all Loading... |
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 bool* added = nullptr); |
28 | 28 |
29 Variable* Lookup(const AstRawString* name); | 29 Variable* Lookup(const AstRawString* name); |
30 }; | 30 }; |
31 | 31 |
32 | 32 |
33 // The dynamic scope part holds hash maps for the variables that will | |
34 // be looked up dynamically from within eval and with scopes. The objects | |
35 // are allocated on-demand from Scope::NonLocal to avoid wasting memory | |
36 // and setup time for scopes that don't need them. | |
37 class DynamicScopePart : public ZoneObject { | |
38 public: | |
39 explicit DynamicScopePart(Zone* zone) { | |
40 for (int i = 0; i < 3; i++) | |
41 maps_[i] = new(zone->New(sizeof(VariableMap))) VariableMap(zone); | |
42 } | |
43 | |
44 VariableMap* GetMap(VariableMode mode) { | |
45 int index = mode - DYNAMIC; | |
46 DCHECK(index >= 0 && index < 3); | |
47 return maps_[index]; | |
48 } | |
49 | |
50 private: | |
51 VariableMap *maps_[3]; | |
52 }; | |
53 | |
54 | |
55 // Sloppy block-scoped function declarations to var-bind | 33 // Sloppy block-scoped function declarations to var-bind |
56 class SloppyBlockFunctionMap : public ZoneHashMap { | 34 class SloppyBlockFunctionMap : public ZoneHashMap { |
57 public: | 35 public: |
58 explicit SloppyBlockFunctionMap(Zone* zone); | 36 explicit SloppyBlockFunctionMap(Zone* zone); |
59 void Declare(Zone* zone, const AstRawString* name, | 37 void Declare(Zone* zone, const AstRawString* name, |
60 SloppyBlockFunctionStatement* statement); | 38 SloppyBlockFunctionStatement* statement); |
61 }; | 39 }; |
62 | 40 |
63 | 41 |
64 // Global invariants after AST construction: Each reference (i.e. identifier) | 42 // Global invariants after AST construction: Each reference (i.e. identifier) |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 // The variables declared in this scope: | 445 // The variables declared in this scope: |
468 // | 446 // |
469 // All user-declared variables (incl. parameters). For script scopes | 447 // All user-declared variables (incl. parameters). For script scopes |
470 // variables may be implicitly 'declared' by being used (possibly in | 448 // variables may be implicitly 'declared' by being used (possibly in |
471 // an inner scope) with no intervening with statements or eval calls. | 449 // an inner scope) with no intervening with statements or eval calls. |
472 VariableMap variables_; | 450 VariableMap variables_; |
473 // In case of non-scopeinfo-backed scopes, this contains the variables of the | 451 // In case of non-scopeinfo-backed scopes, this contains the variables of the |
474 // map above in order of addition. | 452 // map above in order of addition. |
475 // TODO(verwaest): Thread through Variable. | 453 // TODO(verwaest): Thread through Variable. |
476 ZoneList<Variable*> ordered_variables_; | 454 ZoneList<Variable*> ordered_variables_; |
477 // Variables that must be looked up dynamically. | |
478 DynamicScopePart* dynamics_; | |
479 // Unresolved variables referred to from this scope. The proxies themselves | 455 // Unresolved variables referred to from this scope. The proxies themselves |
480 // form a linked list of all unresolved proxies. | 456 // form a linked list of all unresolved proxies. |
481 VariableProxy* unresolved_; | 457 VariableProxy* unresolved_; |
482 // Declarations. | 458 // Declarations. |
483 ZoneList<Declaration*> decls_; | 459 ZoneList<Declaration*> decls_; |
484 | 460 |
485 // Serialized scope info support. | 461 // Serialized scope info support. |
486 Handle<ScopeInfo> scope_info_; | 462 Handle<ScopeInfo> scope_info_; |
487 // Debugging support. | 463 // Debugging support. |
488 #ifdef DEBUG | 464 #ifdef DEBUG |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 void AllocateModuleVariables(); | 860 void AllocateModuleVariables(); |
885 | 861 |
886 private: | 862 private: |
887 ModuleDescriptor* module_descriptor_; | 863 ModuleDescriptor* module_descriptor_; |
888 }; | 864 }; |
889 | 865 |
890 } // namespace internal | 866 } // namespace internal |
891 } // namespace v8 | 867 } // namespace v8 |
892 | 868 |
893 #endif // V8_AST_SCOPES_H_ | 869 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |