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

Side by Side Diff: src/scopes.cc

Issue 9704054: Refactoring of code generation for declarations, in preparation for modules. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Florian's comments. Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/scopes.h ('k') | src/x64/full-codegen-x64.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 // 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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 true, 405 true,
406 Variable::NORMAL, 406 Variable::NORMAL,
407 init_flag); 407 init_flag);
408 var->AllocateTo(Variable::CONTEXT, index); 408 var->AllocateTo(Variable::CONTEXT, index);
409 return var; 409 return var;
410 } 410 }
411 411
412 412
413 Variable* Scope::LookupFunctionVar(Handle<String> name, 413 Variable* Scope::LookupFunctionVar(Handle<String> name,
414 AstNodeFactory<AstNullVisitor>* factory) { 414 AstNodeFactory<AstNullVisitor>* factory) {
415 if (function_ != NULL && function_->name().is_identical_to(name)) { 415 if (function_ != NULL && function_->proxy()->name().is_identical_to(name)) {
416 return function_->var(); 416 return function_->proxy()->var();
417 } else if (!scope_info_.is_null()) { 417 } else if (!scope_info_.is_null()) {
418 // If we are backed by a scope info, try to lookup the variable there. 418 // If we are backed by a scope info, try to lookup the variable there.
419 VariableMode mode; 419 VariableMode mode;
420 int index = scope_info_->FunctionContextSlotIndex(*name, &mode); 420 int index = scope_info_->FunctionContextSlotIndex(*name, &mode);
421 if (index < 0) return NULL; 421 if (index < 0) return NULL;
422 Variable* var = DeclareFunctionVar(name, mode, factory); 422 Variable* var = new Variable(
423 this, name, mode, true /* is valid LHS */,
424 Variable::NORMAL, kCreatedInitialized);
425 VariableProxy* proxy = factory->NewVariableProxy(var);
426 VariableDeclaration* declaration =
427 factory->NewVariableDeclaration(proxy, mode, this);
428 DeclareFunctionVar(declaration);
423 var->AllocateTo(Variable::CONTEXT, index); 429 var->AllocateTo(Variable::CONTEXT, index);
424 return var; 430 return var;
425 } else { 431 } else {
426 return NULL; 432 return NULL;
427 } 433 }
428 } 434 }
429 435
430 436
431 Variable* Scope::Lookup(Handle<String> name) { 437 Variable* Scope::Lookup(Handle<String> name) {
432 for (Scope* scope = this; 438 for (Scope* scope = this;
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 PrintName(params_[i]->name()); 790 PrintName(params_[i]->name());
785 } 791 }
786 PrintF(")"); 792 PrintF(")");
787 } 793 }
788 794
789 PrintF(" { // (%d, %d)\n", start_position(), end_position()); 795 PrintF(" { // (%d, %d)\n", start_position(), end_position());
790 796
791 // Function name, if any (named function literals, only). 797 // Function name, if any (named function literals, only).
792 if (function_ != NULL) { 798 if (function_ != NULL) {
793 Indent(n1, "// (local) function name: "); 799 Indent(n1, "// (local) function name: ");
794 PrintName(function_->name()); 800 PrintName(function_->proxy()->name());
795 PrintF("\n"); 801 PrintF("\n");
796 } 802 }
797 803
798 // Scope info. 804 // Scope info.
799 if (HasTrivialOuterContext()) { 805 if (HasTrivialOuterContext()) {
800 Indent(n1, "// scope has trivial outer context\n"); 806 Indent(n1, "// scope has trivial outer context\n");
801 } 807 }
802 switch (language_mode()) { 808 switch (language_mode()) {
803 case CLASSIC_MODE: 809 case CLASSIC_MODE:
804 break; 810 break;
(...skipping 12 matching lines...) Expand all
817 } 823 }
818 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); 824 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n");
819 if (num_stack_slots_ > 0) { Indent(n1, "// "); 825 if (num_stack_slots_ > 0) { Indent(n1, "// ");
820 PrintF("%d stack slots\n", num_stack_slots_); } 826 PrintF("%d stack slots\n", num_stack_slots_); }
821 if (num_heap_slots_ > 0) { Indent(n1, "// "); 827 if (num_heap_slots_ > 0) { Indent(n1, "// ");
822 PrintF("%d heap slots\n", num_heap_slots_); } 828 PrintF("%d heap slots\n", num_heap_slots_); }
823 829
824 // Print locals. 830 // Print locals.
825 Indent(n1, "// function var\n"); 831 Indent(n1, "// function var\n");
826 if (function_ != NULL) { 832 if (function_ != NULL) {
827 PrintVar(n1, function_->var()); 833 PrintVar(n1, function_->proxy()->var());
828 } 834 }
829 835
830 Indent(n1, "// temporary vars\n"); 836 Indent(n1, "// temporary vars\n");
831 for (int i = 0; i < temps_.length(); i++) { 837 for (int i = 0; i < temps_.length(); i++) {
832 PrintVar(n1, temps_[i]); 838 PrintVar(n1, temps_[i]);
833 } 839 }
834 840
835 Indent(n1, "// local vars\n"); 841 Indent(n1, "// local vars\n");
836 PrintMap(n1, &variables_); 842 PrintMap(n1, &variables_);
837 843
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 p = variables_.Next(p)) { 1203 p = variables_.Next(p)) {
1198 Variable* var = reinterpret_cast<Variable*>(p->value); 1204 Variable* var = reinterpret_cast<Variable*>(p->value);
1199 AllocateNonParameterLocal(var); 1205 AllocateNonParameterLocal(var);
1200 } 1206 }
1201 1207
1202 // For now, function_ must be allocated at the very end. If it gets 1208 // For now, function_ must be allocated at the very end. If it gets
1203 // allocated in the context, it must be the last slot in the context, 1209 // allocated in the context, it must be the last slot in the context,
1204 // because of the current ScopeInfo implementation (see 1210 // because of the current ScopeInfo implementation (see
1205 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). 1211 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor).
1206 if (function_ != NULL) { 1212 if (function_ != NULL) {
1207 AllocateNonParameterLocal(function_->var()); 1213 AllocateNonParameterLocal(function_->proxy()->var());
1208 } 1214 }
1209 } 1215 }
1210 1216
1211 1217
1212 void Scope::AllocateVariablesRecursively() { 1218 void Scope::AllocateVariablesRecursively() {
1213 // Allocate variables for inner scopes. 1219 // Allocate variables for inner scopes.
1214 for (int i = 0; i < inner_scopes_.length(); i++) { 1220 for (int i = 0; i < inner_scopes_.length(); i++) {
1215 inner_scopes_[i]->AllocateVariablesRecursively(); 1221 inner_scopes_[i]->AllocateVariablesRecursively();
1216 } 1222 }
1217 1223
(...skipping 21 matching lines...) Expand all
1239 num_heap_slots_ = 0; 1245 num_heap_slots_ = 0;
1240 } 1246 }
1241 1247
1242 // Allocation done. 1248 // Allocation done.
1243 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); 1249 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
1244 } 1250 }
1245 1251
1246 1252
1247 int Scope::StackLocalCount() const { 1253 int Scope::StackLocalCount() const {
1248 return num_stack_slots() - 1254 return num_stack_slots() -
1249 (function_ != NULL && function_->var()->IsStackLocal() ? 1 : 0); 1255 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0);
1250 } 1256 }
1251 1257
1252 1258
1253 int Scope::ContextLocalCount() const { 1259 int Scope::ContextLocalCount() const {
1254 if (num_heap_slots() == 0) return 0; 1260 if (num_heap_slots() == 0) return 0;
1255 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1261 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1256 (function_ != NULL && function_->var()->IsContextSlot() ? 1 : 0); 1262 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1257 } 1263 }
1258 1264
1259 } } // namespace v8::internal 1265 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698