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

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

Issue 2276483003: Store NonLocals in variables_ (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 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/scopes.h ('k') | no next file » | 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 #include "src/ast/scopes.h" 5 #include "src/ast/scopes.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 } 210 }
211 211
212 void Scope::SetDefaults() { 212 void Scope::SetDefaults() {
213 #ifdef DEBUG 213 #ifdef DEBUG
214 scope_name_ = nullptr; 214 scope_name_ = nullptr;
215 already_resolved_ = false; 215 already_resolved_ = false;
216 #endif 216 #endif
217 inner_scope_ = nullptr; 217 inner_scope_ = nullptr;
218 sibling_ = nullptr; 218 sibling_ = nullptr;
219 unresolved_ = nullptr; 219 unresolved_ = nullptr;
220 dynamics_ = nullptr;
221 220
222 start_position_ = kNoSourcePosition; 221 start_position_ = kNoSourcePosition;
223 end_position_ = kNoSourcePosition; 222 end_position_ = kNoSourcePosition;
224 223
225 num_stack_slots_ = 0; 224 num_stack_slots_ = 0;
226 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; 225 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS;
227 num_global_slots_ = 0; 226 num_global_slots_ = 0;
228 227
229 set_language_mode(SLOPPY); 228 set_language_mode(SLOPPY);
230 229
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 } 1168 }
1170 PrintVar(n1, (*temps)[i]); 1169 PrintVar(n1, (*temps)[i]);
1171 } 1170 }
1172 } 1171 }
1173 1172
1174 if (variables_.Start() != NULL) { 1173 if (variables_.Start() != NULL) {
1175 Indent(n1, "// local vars:\n"); 1174 Indent(n1, "// local vars:\n");
1176 PrintMap(n1, &variables_); 1175 PrintMap(n1, &variables_);
1177 } 1176 }
1178 1177
1179 if (dynamics_ != NULL) {
1180 Indent(n1, "// dynamic vars:\n");
adamk 2016/08/23 22:12:19 So this means non-locals will now be printed as pa
1181 PrintMap(n1, dynamics_->GetMap(DYNAMIC));
1182 PrintMap(n1, dynamics_->GetMap(DYNAMIC_LOCAL));
1183 PrintMap(n1, dynamics_->GetMap(DYNAMIC_GLOBAL));
1184 }
1185
1186 // Print inner scopes (disable by providing negative n). 1178 // Print inner scopes (disable by providing negative n).
1187 if (n >= 0) { 1179 if (n >= 0) {
1188 for (Scope* scope = inner_scope_; scope != nullptr; 1180 for (Scope* scope = inner_scope_; scope != nullptr;
1189 scope = scope->sibling_) { 1181 scope = scope->sibling_) {
1190 PrintF("\n"); 1182 PrintF("\n");
1191 scope->Print(n1); 1183 scope->Print(n1);
1192 } 1184 }
1193 } 1185 }
1194 1186
1195 Indent(n0, "}\n"); 1187 Indent(n0, "}\n");
(...skipping 12 matching lines...) Expand all
1208 } 1200 }
1209 1201
1210 void Scope::CheckZones() { 1202 void Scope::CheckZones() {
1211 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { 1203 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
1212 CHECK_EQ(scope->zone(), zone()); 1204 CHECK_EQ(scope->zone(), zone());
1213 } 1205 }
1214 } 1206 }
1215 #endif // DEBUG 1207 #endif // DEBUG
1216 1208
1217 Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) { 1209 Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) {
1218 if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone()); 1210 // Declare a new non-local.
1219 VariableMap* map = dynamics_->GetMap(mode); 1211 DCHECK(IsDynamicVariableMode(mode));
1220 Variable* var = map->Lookup(name); 1212 Variable* var = variables_.Declare(zone(), NULL, name, mode, Variable::NORMAL,
1221 if (var == NULL) { 1213 kCreatedInitialized);
1222 // Declare a new non-local. 1214 // Allocate it by giving it a dynamic lookup.
1223 DCHECK(!IsLexicalVariableMode(mode)); 1215 var->AllocateTo(VariableLocation::LOOKUP, -1);
1224 var = map->Declare(zone(), NULL, name, mode, Variable::NORMAL,
1225 kCreatedInitialized);
1226 // Allocate it by giving it a dynamic lookup.
1227 var->AllocateTo(VariableLocation::LOOKUP, -1);
1228 }
1229 return var; 1216 return var;
1230 } 1217 }
1231 1218
1232 Variable* Scope::LookupRecursive(VariableProxy* proxy, bool declare_free, 1219 Variable* Scope::LookupRecursive(VariableProxy* proxy, bool declare_free,
1233 Scope* outer_scope_end) { 1220 Scope* outer_scope_end) {
1234 DCHECK_NE(outer_scope_end, this); 1221 DCHECK_NE(outer_scope_end, this);
1235 // Short-cut: whenever we find a debug-evaluate scope, just look everything up 1222 // Short-cut: whenever we find a debug-evaluate scope, just look everything up
1236 // dynamically. Debug-evaluate doesn't properly create scope info for the 1223 // dynamically. Debug-evaluate doesn't properly create scope info for the
1237 // lookups it does. It may not have a valid 'this' declaration, and anything 1224 // lookups it does. It may not have a valid 'this' declaration, and anything
1238 // accessed through debug-evaluate might invalidly resolve to stack-allocated 1225 // accessed through debug-evaluate might invalidly resolve to stack-allocated
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 function != nullptr && function->IsContextSlot(); 1668 function != nullptr && function->IsContextSlot();
1682 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1669 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1683 (is_function_var_in_context ? 1 : 0); 1670 (is_function_var_in_context ? 1 : 0);
1684 } 1671 }
1685 1672
1686 1673
1687 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1674 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1688 1675
1689 } // namespace internal 1676 } // namespace internal
1690 } // namespace v8 1677 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698