Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: src/ast/scopes.h

Issue 2324783002: Include only stuff you need, part 9: variables.h (Closed)
Patch Set: rebased Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/scopeinfo.cc ('k') | src/ast/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/variables.h"
9 #include "src/base/hashmap.h" 8 #include "src/base/hashmap.h"
10 #include "src/globals.h" 9 #include "src/globals.h"
10 #include "src/objects.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 AstNodeFactory; 16 class AstNodeFactory;
17 class AstValueFactory; 17 class AstValueFactory;
18 class AstRawString; 18 class AstRawString;
19 class Declaration; 19 class Declaration;
20 class ParseInfo; 20 class ParseInfo;
21 class SloppyBlockFunctionStatement; 21 class SloppyBlockFunctionStatement;
22 class StringSet;
22 class VariableProxy; 23 class VariableProxy;
23 24
24 // A hash map to support fast variable declaration and lookup. 25 // A hash map to support fast variable declaration and lookup.
25 class VariableMap: public ZoneHashMap { 26 class VariableMap: public ZoneHashMap {
26 public: 27 public:
27 explicit VariableMap(Zone* zone); 28 explicit VariableMap(Zone* zone);
28 29
29 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, 30 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name,
30 VariableMode mode, Variable::Kind kind, 31 VariableMode mode, VariableKind kind,
31 InitializationFlag initialization_flag, 32 InitializationFlag initialization_flag,
32 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, 33 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned,
33 bool* added = nullptr); 34 bool* added = nullptr);
34 35
35 Variable* Lookup(const AstRawString* name); 36 Variable* Lookup(const AstRawString* name);
36 void Remove(Variable* var); 37 void Remove(Variable* var);
37 void Add(Zone* zone, Variable* var); 38 void Add(Zone* zone, Variable* var);
38 }; 39 };
39 40
40 41
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 134
134 Variable* LookupInScopeInfo(const AstRawString* name); 135 Variable* LookupInScopeInfo(const AstRawString* name);
135 136
136 // Lookup a variable in this scope or outer scopes. 137 // Lookup a variable in this scope or outer scopes.
137 // Returns the variable or NULL if not found. 138 // Returns the variable or NULL if not found.
138 Variable* Lookup(const AstRawString* name); 139 Variable* Lookup(const AstRawString* name);
139 140
140 // Declare a local variable in this scope. If the variable has been 141 // Declare a local variable in this scope. If the variable has been
141 // declared before, the previously declared variable is returned. 142 // declared before, the previously declared variable is returned.
142 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, 143 Variable* DeclareLocal(const AstRawString* name, VariableMode mode,
143 InitializationFlag init_flag, Variable::Kind kind, 144 InitializationFlag init_flag, VariableKind kind,
144 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned); 145 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned);
145 146
146 Variable* DeclareVariable(Declaration* declaration, VariableMode mode, 147 Variable* DeclareVariable(Declaration* declaration, VariableMode mode,
147 InitializationFlag init, 148 InitializationFlag init,
148 bool allow_harmony_restrictive_generators, 149 bool allow_harmony_restrictive_generators,
149 bool* sloppy_mode_block_scope_function_redefinition, 150 bool* sloppy_mode_block_scope_function_redefinition,
150 bool* ok); 151 bool* ok);
151 152
152 // Declarations list. 153 // Declarations list.
153 ZoneList<Declaration*>* declarations() { return &decls_; } 154 ZoneList<Declaration*>* declarations() { return &decls_; }
154 155
155 ZoneList<Variable*>* locals() { return &locals_; } 156 ZoneList<Variable*>* locals() { return &locals_; }
156 157
157 // Create a new unresolved variable. 158 // Create a new unresolved variable.
158 VariableProxy* NewUnresolved(AstNodeFactory* factory, 159 VariableProxy* NewUnresolved(AstNodeFactory* factory,
159 const AstRawString* name, 160 const AstRawString* name,
160 int start_position = kNoSourcePosition, 161 int start_position = kNoSourcePosition,
161 int end_position = kNoSourcePosition, 162 int end_position = kNoSourcePosition,
162 Variable::Kind kind = Variable::NORMAL); 163 VariableKind kind = NORMAL_VARIABLE);
163 164
164 void AddUnresolved(VariableProxy* proxy); 165 void AddUnresolved(VariableProxy* proxy);
165 166
166 // Remove a unresolved variable. During parsing, an unresolved variable 167 // Remove a unresolved variable. During parsing, an unresolved variable
167 // may have been added optimistically, but then only the variable name 168 // may have been added optimistically, but then only the variable name
168 // was used (typically for labels). If the variable was not declared, the 169 // was used (typically for labels). If the variable was not declared, the
169 // addition introduced a new unresolved variable which may end up being 170 // addition introduced a new unresolved variable which may end up being
170 // allocated globally as a "ghost" variable. RemoveUnresolved removes 171 // allocated globally as a "ghost" variable. RemoveUnresolved removes
171 // such a variable again if it was added; otherwise this is a no-op. 172 // such a variable again if it was added; otherwise this is a no-op.
172 bool RemoveUnresolved(VariableProxy* var); 173 bool RemoveUnresolved(VariableProxy* var);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 409
409 protected: 410 protected:
410 explicit Scope(Zone* zone); 411 explicit Scope(Zone* zone);
411 412
412 void set_language_mode(LanguageMode language_mode) { 413 void set_language_mode(LanguageMode language_mode) {
413 is_strict_ = is_strict(language_mode); 414 is_strict_ = is_strict(language_mode);
414 } 415 }
415 416
416 private: 417 private:
417 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, 418 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name,
418 VariableMode mode, Variable::Kind kind, 419 VariableMode mode, VariableKind kind,
419 InitializationFlag initialization_flag, 420 InitializationFlag initialization_flag,
420 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) { 421 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) {
421 bool added; 422 bool added;
422 Variable* var = 423 Variable* var =
423 variables_.Declare(zone, scope, name, mode, kind, initialization_flag, 424 variables_.Declare(zone, scope, name, mode, kind, initialization_flag,
424 maybe_assigned_flag, &added); 425 maybe_assigned_flag, &added);
425 if (added) locals_.Add(var, zone); 426 if (added) locals_.Add(var, zone);
426 return var; 427 return var;
427 } 428 }
428 429
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 // expects all parameters to be declared and from left to right. 643 // expects all parameters to be declared and from left to right.
643 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, 644 Variable* DeclareParameter(const AstRawString* name, VariableMode mode,
644 bool is_optional, bool is_rest, bool* is_duplicate, 645 bool is_optional, bool is_rest, bool* is_duplicate,
645 AstValueFactory* ast_value_factory); 646 AstValueFactory* ast_value_factory);
646 647
647 // Declare an implicit global variable in this scope which must be a 648 // Declare an implicit global variable in this scope which must be a
648 // script scope. The variable was introduced (possibly from an inner 649 // script scope. The variable was introduced (possibly from an inner
649 // scope) by a reference to an unresolved variable with no intervening 650 // scope) by a reference to an unresolved variable with no intervening
650 // with statements or eval calls. 651 // with statements or eval calls.
651 Variable* DeclareDynamicGlobal(const AstRawString* name, 652 Variable* DeclareDynamicGlobal(const AstRawString* name,
652 Variable::Kind variable_kind); 653 VariableKind variable_kind);
653 654
654 // The variable corresponding to the 'this' value. 655 // The variable corresponding to the 'this' value.
655 Variable* receiver() { 656 Variable* receiver() {
656 DCHECK(has_this_declaration()); 657 DCHECK(has_this_declaration());
657 DCHECK_NOT_NULL(receiver_); 658 DCHECK_NOT_NULL(receiver_);
658 return receiver_; 659 return receiver_;
659 } 660 }
660 661
661 // TODO(wingo): Add a GLOBAL_SCOPE scope type which will lexically allocate 662 // TODO(wingo): Add a GLOBAL_SCOPE scope type which will lexically allocate
662 // "this" (and no other variable) on the native context. Script scopes then 663 // "this" (and no other variable) on the native context. Script scopes then
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 void AllocateModuleVariables(); 855 void AllocateModuleVariables();
855 856
856 private: 857 private:
857 ModuleDescriptor* module_descriptor_; 858 ModuleDescriptor* module_descriptor_;
858 }; 859 };
859 860
860 } // namespace internal 861 } // namespace internal
861 } // namespace v8 862 } // namespace v8
862 863
863 #endif // V8_AST_SCOPES_H_ 864 #endif // V8_AST_SCOPES_H_
OLDNEW
« no previous file with comments | « src/ast/scopeinfo.cc ('k') | src/ast/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698