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

Side by Side Diff: src/scopes.cc

Issue 8438071: Clean up Scope::CollectUsedVariables. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month 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 | Annotate | Revision Log
« src/scopeinfo.cc ('K') | « src/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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 return decl; 522 return decl;
523 } 523 }
524 previous = current; 524 previous = current;
525 current = current->outer_scope_; 525 current = current->outer_scope_;
526 } while (!previous->is_declaration_scope()); 526 } while (!previous->is_declaration_scope());
527 } 527 }
528 return NULL; 528 return NULL;
529 } 529 }
530 530
531 531
532 void Scope::CollectUsedVariables(ZoneList<Variable*>* locals) { 532 void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals,
533 // Collect variables in this scope. 533 ZoneList<Variable*>* context_locals) {
534 // Note that the function_ variable - if present - is not 534 ASSERT(stack_locals != NULL);
535 // collected here but handled separately in ScopeInfo 535 ASSERT(context_locals != NULL);
536 // which is the current user of this function). 536
537 // Collect temporaries which are always allocated on the stack.
537 for (int i = 0; i < temps_.length(); i++) { 538 for (int i = 0; i < temps_.length(); i++) {
538 Variable* var = temps_[i]; 539 Variable* var = temps_[i];
539 if (var->is_used()) { 540 if (var->is_used()) {
540 locals->Add(var); 541 ASSERT(var->IsStackLocal());
542 stack_locals->Add(var);
541 } 543 }
542 } 544 }
545
546 // Collect declared local variables.
543 for (VariableMap::Entry* p = variables_.Start(); 547 for (VariableMap::Entry* p = variables_.Start();
544 p != NULL; 548 p != NULL;
545 p = variables_.Next(p)) { 549 p = variables_.Next(p)) {
546 Variable* var = reinterpret_cast<Variable*>(p->value); 550 Variable* var = reinterpret_cast<Variable*>(p->value);
547 if (var->is_used()) { 551 if (var->is_used()) {
548 locals->Add(var); 552 if (var->IsStackLocal()) {
553 stack_locals->Add(var);
554 } else if (var->IsContextSlot()) {
555 context_locals->Add(var);
556 }
549 } 557 }
550 } 558 }
551 } 559 }
552 560
553 561
554 void Scope::AllocateVariables(Handle<Context> context) { 562 void Scope::AllocateVariables(Handle<Context> context) {
555 ASSERT(outer_scope_ == NULL); // eval or global scopes only 563 ASSERT(outer_scope_ == NULL); // eval or global scopes only
556 564
557 // 1) Propagate scope information. 565 // 1) Propagate scope information.
558 // If we are in an eval scope, we may have other outer scopes about 566 // If we are in an eval scope, we may have other outer scopes about
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1157 // If we didn't allocate any locals in the local context, then we only 1165 // If we didn't allocate any locals in the local context, then we only
1158 // need the minimal number of slots if we must have a context. 1166 // need the minimal number of slots if we must have a context.
1159 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && !must_have_context) { 1167 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && !must_have_context) {
1160 num_heap_slots_ = 0; 1168 num_heap_slots_ = 0;
1161 } 1169 }
1162 1170
1163 // Allocation done. 1171 // Allocation done.
1164 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); 1172 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
1165 } 1173 }
1166 1174
1175
1176 int Scope::StackLocalCount() const {
1177 return num_stack_slots() -
1178 (function_ != NULL && function_->var()->IsStackLocal() ? 1 : 0);
1179 }
1180
1181
1182 int Scope::ContextLocalCount() const {
1183 if (num_heap_slots() == 0) return 0;
1184 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1185 (function_ != NULL && function_->var()->IsContextSlot() ? 1 : 0);
1186 }
1187
1167 } } // namespace v8::internal 1188 } } // namespace v8::internal
OLDNEW
« src/scopeinfo.cc ('K') | « src/scopes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698