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

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: rebase 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 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 comma = true; 1069 comma = true;
1071 } 1070 }
1072 if (var->maybe_assigned() == kMaybeAssigned) { 1071 if (var->maybe_assigned() == kMaybeAssigned) {
1073 if (comma) PrintF(", "); 1072 if (comma) PrintF(", ");
1074 PrintF("maybe assigned"); 1073 PrintF("maybe assigned");
1075 } 1074 }
1076 PrintF("\n"); 1075 PrintF("\n");
1077 } 1076 }
1078 } 1077 }
1079 1078
1080 1079 static void PrintMap(int indent, VariableMap* map, bool locals) {
1081 static void PrintMap(int indent, VariableMap* map) { 1080 for (VariableMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) {
1082 for (VariableMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) {
1083 Variable* var = reinterpret_cast<Variable*>(p->value); 1081 Variable* var = reinterpret_cast<Variable*>(p->value);
1084 if (var == NULL) { 1082 bool local = !IsDynamicVariableMode(var->mode());
1085 Indent(indent, "<?>\n"); 1083 if (locals ? local : !local) {
1086 } else { 1084 if (var == nullptr) {
1087 PrintVar(indent, var); 1085 Indent(indent, "<?>\n");
1086 } else {
1087 PrintVar(indent, var);
1088 }
1088 } 1089 }
1089 } 1090 }
1090 } 1091 }
1091 1092
1092 void DeclarationScope::PrintParameters() { 1093 void DeclarationScope::PrintParameters() {
1093 PrintF(" ("); 1094 PrintF(" (");
1094 for (int i = 0; i < params_.length(); i++) { 1095 for (int i = 0; i < params_.length(); i++) {
1095 if (i > 0) PrintF(", "); 1096 if (i > 0) PrintF(", ");
1096 const AstRawString* name = params_[i]->raw_name(); 1097 const AstRawString* name = params_[i]->raw_name();
1097 if (name->IsEmpty()) 1098 if (name->IsEmpty())
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 if (!printed_header) { 1167 if (!printed_header) {
1167 printed_header = true; 1168 printed_header = true;
1168 Indent(n1, "// temporary vars:\n"); 1169 Indent(n1, "// temporary vars:\n");
1169 } 1170 }
1170 PrintVar(n1, (*temps)[i]); 1171 PrintVar(n1, (*temps)[i]);
1171 } 1172 }
1172 } 1173 }
1173 1174
1174 if (variables_.Start() != NULL) { 1175 if (variables_.Start() != NULL) {
1175 Indent(n1, "// local vars:\n"); 1176 Indent(n1, "// local vars:\n");
1176 PrintMap(n1, &variables_); 1177 PrintMap(n1, &variables_, true);
1177 }
1178 1178
1179 if (dynamics_ != NULL) {
1180 Indent(n1, "// dynamic vars:\n"); 1179 Indent(n1, "// dynamic vars:\n");
1181 PrintMap(n1, dynamics_->GetMap(DYNAMIC)); 1180 PrintMap(n1, &variables_, false);
1182 PrintMap(n1, dynamics_->GetMap(DYNAMIC_LOCAL));
1183 PrintMap(n1, dynamics_->GetMap(DYNAMIC_GLOBAL));
1184 } 1181 }
1185 1182
1186 // Print inner scopes (disable by providing negative n). 1183 // Print inner scopes (disable by providing negative n).
1187 if (n >= 0) { 1184 if (n >= 0) {
1188 for (Scope* scope = inner_scope_; scope != nullptr; 1185 for (Scope* scope = inner_scope_; scope != nullptr;
1189 scope = scope->sibling_) { 1186 scope = scope->sibling_) {
1190 PrintF("\n"); 1187 PrintF("\n");
1191 scope->Print(n1); 1188 scope->Print(n1);
1192 } 1189 }
1193 } 1190 }
(...skipping 14 matching lines...) Expand all
1208 } 1205 }
1209 1206
1210 void Scope::CheckZones() { 1207 void Scope::CheckZones() {
1211 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { 1208 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
1212 CHECK_EQ(scope->zone(), zone()); 1209 CHECK_EQ(scope->zone(), zone());
1213 } 1210 }
1214 } 1211 }
1215 #endif // DEBUG 1212 #endif // DEBUG
1216 1213
1217 Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) { 1214 Variable* Scope::NonLocal(const AstRawString* name, VariableMode mode) {
1218 if (dynamics_ == NULL) dynamics_ = new (zone()) DynamicScopePart(zone()); 1215 // Declare a new non-local.
1219 VariableMap* map = dynamics_->GetMap(mode); 1216 DCHECK(IsDynamicVariableMode(mode));
1220 Variable* var = map->Lookup(name); 1217 Variable* var = variables_.Declare(zone(), NULL, name, mode, Variable::NORMAL,
1221 if (var == NULL) { 1218 kCreatedInitialized);
1222 // Declare a new non-local. 1219 // Allocate it by giving it a dynamic lookup.
1223 DCHECK(!IsLexicalVariableMode(mode)); 1220 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; 1221 return var;
1230 } 1222 }
1231 1223
1232 Variable* Scope::LookupRecursive(VariableProxy* proxy, bool declare_free, 1224 Variable* Scope::LookupRecursive(VariableProxy* proxy, bool declare_free,
1233 Scope* outer_scope_end) { 1225 Scope* outer_scope_end) {
1234 DCHECK_NE(outer_scope_end, this); 1226 DCHECK_NE(outer_scope_end, this);
1235 // Short-cut: whenever we find a debug-evaluate scope, just look everything up 1227 // 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 1228 // 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 1229 // lookups it does. It may not have a valid 'this' declaration, and anything
1238 // accessed through debug-evaluate might invalidly resolve to stack-allocated 1230 // 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(); 1673 function != nullptr && function->IsContextSlot();
1682 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1674 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1683 (is_function_var_in_context ? 1 : 0); 1675 (is_function_var_in_context ? 1 : 0);
1684 } 1676 }
1685 1677
1686 1678
1687 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1679 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1688 1680
1689 } // namespace internal 1681 } // namespace internal
1690 } // namespace v8 1682 } // 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