| OLD | NEW |
| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
| 9 #include "src/messages.h" | 9 #include "src/messages.h" |
| 10 #include "src/parser.h" | 10 #include "src/parser.h" |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 static int Compare(const VarAndOrder* a, const VarAndOrder* b) { | 586 static int Compare(const VarAndOrder* a, const VarAndOrder* b) { |
| 587 return a->order_ - b->order_; | 587 return a->order_ - b->order_; |
| 588 } | 588 } |
| 589 | 589 |
| 590 private: | 590 private: |
| 591 Variable* var_; | 591 Variable* var_; |
| 592 int order_; | 592 int order_; |
| 593 }; | 593 }; |
| 594 | 594 |
| 595 | 595 |
| 596 void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, | 596 void Scope::CollectStackAndContextLocals( |
| 597 ZoneList<Variable*>* context_locals) { | 597 ZoneList<Variable*>* stack_locals, ZoneList<Variable*>* context_locals, |
| 598 ZoneList<Variable*>* strong_mode_free_variables) { |
| 598 DCHECK(stack_locals != NULL); | 599 DCHECK(stack_locals != NULL); |
| 599 DCHECK(context_locals != NULL); | 600 DCHECK(context_locals != NULL); |
| 600 | 601 |
| 601 // Collect internals which are always allocated on the heap. | 602 // Collect internals which are always allocated on the heap. |
| 602 for (int i = 0; i < internals_.length(); i++) { | 603 for (int i = 0; i < internals_.length(); i++) { |
| 603 Variable* var = internals_[i]; | 604 Variable* var = internals_[i]; |
| 604 if (var->is_used()) { | 605 if (var->is_used()) { |
| 605 DCHECK(var->IsContextSlot()); | 606 DCHECK(var->IsContextSlot()); |
| 606 context_locals->Add(var, zone()); | 607 context_locals->Add(var, zone()); |
| 607 } | 608 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 621 } | 622 } |
| 622 } | 623 } |
| 623 } | 624 } |
| 624 | 625 |
| 625 // Collect declared local variables. | 626 // Collect declared local variables. |
| 626 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); | 627 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); |
| 627 for (VariableMap::Entry* p = variables_.Start(); | 628 for (VariableMap::Entry* p = variables_.Start(); |
| 628 p != NULL; | 629 p != NULL; |
| 629 p = variables_.Next(p)) { | 630 p = variables_.Next(p)) { |
| 630 Variable* var = reinterpret_cast<Variable*>(p->value); | 631 Variable* var = reinterpret_cast<Variable*>(p->value); |
| 632 if (strong_mode_free_variables && var->has_strong_mode_reference() && |
| 633 var->mode() == DYNAMIC_GLOBAL) { |
| 634 strong_mode_free_variables->Add(var, zone()); |
| 635 } |
| 636 |
| 631 if (var->is_used()) { | 637 if (var->is_used()) { |
| 632 vars.Add(VarAndOrder(var, p->order), zone()); | 638 vars.Add(VarAndOrder(var, p->order), zone()); |
| 633 } | 639 } |
| 634 } | 640 } |
| 635 vars.Sort(VarAndOrder::Compare); | 641 vars.Sort(VarAndOrder::Compare); |
| 636 int var_count = vars.length(); | 642 int var_count = vars.length(); |
| 637 for (int i = 0; i < var_count; i++) { | 643 for (int i = 0; i < var_count; i++) { |
| 638 Variable* var = vars[i].var(); | 644 Variable* var = vars[i].var(); |
| 639 if (var->IsStackLocal()) { | 645 if (var->IsStackLocal()) { |
| 640 stack_locals->Add(var, zone()); | 646 stack_locals->Add(var, zone()); |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 | 1114 |
| 1109 case DYNAMIC_LOOKUP: | 1115 case DYNAMIC_LOOKUP: |
| 1110 // The variable could not be resolved statically. | 1116 // The variable could not be resolved statically. |
| 1111 var = NonLocal(proxy->raw_name(), DYNAMIC); | 1117 var = NonLocal(proxy->raw_name(), DYNAMIC); |
| 1112 break; | 1118 break; |
| 1113 } | 1119 } |
| 1114 | 1120 |
| 1115 DCHECK(var != NULL); | 1121 DCHECK(var != NULL); |
| 1116 if (proxy->is_assigned()) var->set_maybe_assigned(); | 1122 if (proxy->is_assigned()) var->set_maybe_assigned(); |
| 1117 | 1123 |
| 1124 if (is_strong(language_mode())) { |
| 1125 // Record that the variable is referred to from strong mode. Also, record |
| 1126 // the position. |
| 1127 var->RecordStrongModeReference(proxy->position(), proxy->end_position()); |
| 1128 } |
| 1129 |
| 1118 proxy->BindTo(var); | 1130 proxy->BindTo(var); |
| 1119 | 1131 |
| 1120 return true; | 1132 return true; |
| 1121 } | 1133 } |
| 1122 | 1134 |
| 1123 | 1135 |
| 1124 bool Scope::CheckStrongModeDeclaration(VariableProxy* proxy, Variable* var) { | 1136 bool Scope::CheckStrongModeDeclaration(VariableProxy* proxy, Variable* var) { |
| 1125 // Check for declaration-after use (for variables) in strong mode. Note that | 1137 // Check for declaration-after use (for variables) in strong mode. Note that |
| 1126 // we can only do this in the case where we have seen the declaration. And we | 1138 // we can only do this in the case where we have seen the declaration. And we |
| 1127 // always allow referencing functions (for now). | 1139 // always allow referencing functions (for now). |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1458 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 1470 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); |
| 1459 } | 1471 } |
| 1460 | 1472 |
| 1461 | 1473 |
| 1462 int Scope::ContextLocalCount() const { | 1474 int Scope::ContextLocalCount() const { |
| 1463 if (num_heap_slots() == 0) return 0; | 1475 if (num_heap_slots() == 0) return 0; |
| 1464 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1476 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1465 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1477 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
| 1466 } | 1478 } |
| 1467 } } // namespace v8::internal | 1479 } } // namespace v8::internal |
| OLD | NEW |