OLD | NEW |
---|---|
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 Loading... | |
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, Variable::NORMAL, kCreatedInitialized); | |
fschneider
2012/04/11 11:00:42
Boolean parameter should have a comment.
rossberg
2012/04/16 11:25:13
Done.
| |
424 VariableProxy* proxy = factory->NewVariableProxy(var); | |
425 VariableDeclaration* declaration = | |
426 factory->NewVariableDeclaration(proxy, mode, this); | |
427 DeclareFunctionVar(declaration); | |
423 var->AllocateTo(Variable::CONTEXT, index); | 428 var->AllocateTo(Variable::CONTEXT, index); |
424 return var; | 429 return var; |
425 } else { | 430 } else { |
426 return NULL; | 431 return NULL; |
427 } | 432 } |
428 } | 433 } |
429 | 434 |
430 | 435 |
431 Variable* Scope::Lookup(Handle<String> name) { | 436 Variable* Scope::Lookup(Handle<String> name) { |
432 for (Scope* scope = this; | 437 for (Scope* scope = this; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
784 PrintName(params_[i]->name()); | 789 PrintName(params_[i]->name()); |
785 } | 790 } |
786 PrintF(")"); | 791 PrintF(")"); |
787 } | 792 } |
788 | 793 |
789 PrintF(" { // (%d, %d)\n", start_position(), end_position()); | 794 PrintF(" { // (%d, %d)\n", start_position(), end_position()); |
790 | 795 |
791 // Function name, if any (named function literals, only). | 796 // Function name, if any (named function literals, only). |
792 if (function_ != NULL) { | 797 if (function_ != NULL) { |
793 Indent(n1, "// (local) function name: "); | 798 Indent(n1, "// (local) function name: "); |
794 PrintName(function_->name()); | 799 PrintName(function_->proxy()->name()); |
795 PrintF("\n"); | 800 PrintF("\n"); |
796 } | 801 } |
797 | 802 |
798 // Scope info. | 803 // Scope info. |
799 if (HasTrivialOuterContext()) { | 804 if (HasTrivialOuterContext()) { |
800 Indent(n1, "// scope has trivial outer context\n"); | 805 Indent(n1, "// scope has trivial outer context\n"); |
801 } | 806 } |
802 switch (language_mode()) { | 807 switch (language_mode()) { |
803 case CLASSIC_MODE: | 808 case CLASSIC_MODE: |
804 break; | 809 break; |
(...skipping 12 matching lines...) Expand all Loading... | |
817 } | 822 } |
818 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); | 823 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); |
819 if (num_stack_slots_ > 0) { Indent(n1, "// "); | 824 if (num_stack_slots_ > 0) { Indent(n1, "// "); |
820 PrintF("%d stack slots\n", num_stack_slots_); } | 825 PrintF("%d stack slots\n", num_stack_slots_); } |
821 if (num_heap_slots_ > 0) { Indent(n1, "// "); | 826 if (num_heap_slots_ > 0) { Indent(n1, "// "); |
822 PrintF("%d heap slots\n", num_heap_slots_); } | 827 PrintF("%d heap slots\n", num_heap_slots_); } |
823 | 828 |
824 // Print locals. | 829 // Print locals. |
825 Indent(n1, "// function var\n"); | 830 Indent(n1, "// function var\n"); |
826 if (function_ != NULL) { | 831 if (function_ != NULL) { |
827 PrintVar(n1, function_->var()); | 832 PrintVar(n1, function_->proxy()->var()); |
828 } | 833 } |
829 | 834 |
830 Indent(n1, "// temporary vars\n"); | 835 Indent(n1, "// temporary vars\n"); |
831 for (int i = 0; i < temps_.length(); i++) { | 836 for (int i = 0; i < temps_.length(); i++) { |
832 PrintVar(n1, temps_[i]); | 837 PrintVar(n1, temps_[i]); |
833 } | 838 } |
834 | 839 |
835 Indent(n1, "// local vars\n"); | 840 Indent(n1, "// local vars\n"); |
836 PrintMap(n1, &variables_); | 841 PrintMap(n1, &variables_); |
837 | 842 |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1197 p = variables_.Next(p)) { | 1202 p = variables_.Next(p)) { |
1198 Variable* var = reinterpret_cast<Variable*>(p->value); | 1203 Variable* var = reinterpret_cast<Variable*>(p->value); |
1199 AllocateNonParameterLocal(var); | 1204 AllocateNonParameterLocal(var); |
1200 } | 1205 } |
1201 | 1206 |
1202 // For now, function_ must be allocated at the very end. If it gets | 1207 // 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, | 1208 // allocated in the context, it must be the last slot in the context, |
1204 // because of the current ScopeInfo implementation (see | 1209 // because of the current ScopeInfo implementation (see |
1205 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). | 1210 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). |
1206 if (function_ != NULL) { | 1211 if (function_ != NULL) { |
1207 AllocateNonParameterLocal(function_->var()); | 1212 AllocateNonParameterLocal(function_->proxy()->var()); |
1208 } | 1213 } |
1209 } | 1214 } |
1210 | 1215 |
1211 | 1216 |
1212 void Scope::AllocateVariablesRecursively() { | 1217 void Scope::AllocateVariablesRecursively() { |
1213 // Allocate variables for inner scopes. | 1218 // Allocate variables for inner scopes. |
1214 for (int i = 0; i < inner_scopes_.length(); i++) { | 1219 for (int i = 0; i < inner_scopes_.length(); i++) { |
1215 inner_scopes_[i]->AllocateVariablesRecursively(); | 1220 inner_scopes_[i]->AllocateVariablesRecursively(); |
1216 } | 1221 } |
1217 | 1222 |
(...skipping 21 matching lines...) Expand all Loading... | |
1239 num_heap_slots_ = 0; | 1244 num_heap_slots_ = 0; |
1240 } | 1245 } |
1241 | 1246 |
1242 // Allocation done. | 1247 // Allocation done. |
1243 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1248 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
1244 } | 1249 } |
1245 | 1250 |
1246 | 1251 |
1247 int Scope::StackLocalCount() const { | 1252 int Scope::StackLocalCount() const { |
1248 return num_stack_slots() - | 1253 return num_stack_slots() - |
1249 (function_ != NULL && function_->var()->IsStackLocal() ? 1 : 0); | 1254 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); |
1250 } | 1255 } |
1251 | 1256 |
1252 | 1257 |
1253 int Scope::ContextLocalCount() const { | 1258 int Scope::ContextLocalCount() const { |
1254 if (num_heap_slots() == 0) return 0; | 1259 if (num_heap_slots() == 0) return 0; |
1255 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1260 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1256 (function_ != NULL && function_->var()->IsContextSlot() ? 1 : 0); | 1261 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
1257 } | 1262 } |
1258 | 1263 |
1259 } } // namespace v8::internal | 1264 } } // namespace v8::internal |
OLD | NEW |