| 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/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/ast/scopeinfo.h" | 8 #include "src/ast/scopeinfo.h" |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 Scope* scope = this->ClosureScope(); | 551 Scope* scope = this->ClosureScope(); |
| 552 Variable* var = new(zone()) Variable(scope, | 552 Variable* var = new(zone()) Variable(scope, |
| 553 name, | 553 name, |
| 554 TEMPORARY, | 554 TEMPORARY, |
| 555 Variable::NORMAL, | 555 Variable::NORMAL, |
| 556 kCreatedInitialized); | 556 kCreatedInitialized); |
| 557 scope->AddTemporary(var); | 557 scope->AddTemporary(var); |
| 558 return var; | 558 return var; |
| 559 } | 559 } |
| 560 | 560 |
| 561 | 561 int Scope::RemoveTemporary(Variable* var) { |
| 562 bool Scope::RemoveTemporary(Variable* var) { | 562 DCHECK_NOT_NULL(var); |
| 563 // Most likely (always?) any temporary variable we want to remove | 563 // Most likely (always?) any temporary variable we want to remove |
| 564 // was just added before, so we search backwards. | 564 // was just added before, so we search backwards. |
| 565 for (int i = temps_.length(); i-- > 0;) { | 565 for (int i = temps_.length(); i-- > 0;) { |
| 566 if (temps_[i] == var) { | 566 if (temps_[i] == var) { |
| 567 temps_.Remove(i); | 567 // Don't shrink temps_, as callers of this method expect |
| 568 return true; | 568 // the returned indices to be unique per-scope. |
| 569 temps_[i] = nullptr; |
| 570 return i; |
| 569 } | 571 } |
| 570 } | 572 } |
| 571 return false; | 573 return -1; |
| 572 } | 574 } |
| 573 | 575 |
| 574 | 576 |
| 575 void Scope::AddDeclaration(Declaration* declaration) { | 577 void Scope::AddDeclaration(Declaration* declaration) { |
| 576 decls_.Add(declaration, zone()); | 578 decls_.Add(declaration, zone()); |
| 577 } | 579 } |
| 578 | 580 |
| 579 | 581 |
| 580 Declaration* Scope::CheckConflictingVarDeclarations() { | 582 Declaration* Scope::CheckConflictingVarDeclarations() { |
| 581 int length = decls_.length(); | 583 int length = decls_.length(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 ZoneList<Variable*>* context_locals, | 630 ZoneList<Variable*>* context_locals, |
| 629 ZoneList<Variable*>* context_globals) { | 631 ZoneList<Variable*>* context_globals) { |
| 630 DCHECK(stack_locals != NULL); | 632 DCHECK(stack_locals != NULL); |
| 631 DCHECK(context_locals != NULL); | 633 DCHECK(context_locals != NULL); |
| 632 DCHECK(context_globals != NULL); | 634 DCHECK(context_globals != NULL); |
| 633 | 635 |
| 634 // Collect temporaries which are always allocated on the stack, unless the | 636 // Collect temporaries which are always allocated on the stack, unless the |
| 635 // context as a whole has forced context allocation. | 637 // context as a whole has forced context allocation. |
| 636 for (int i = 0; i < temps_.length(); i++) { | 638 for (int i = 0; i < temps_.length(); i++) { |
| 637 Variable* var = temps_[i]; | 639 Variable* var = temps_[i]; |
| 640 if (var == nullptr) continue; |
| 638 if (var->is_used()) { | 641 if (var->is_used()) { |
| 639 if (var->IsContextSlot()) { | 642 if (var->IsContextSlot()) { |
| 640 DCHECK(has_forced_context_allocation()); | 643 DCHECK(has_forced_context_allocation()); |
| 641 context_locals->Add(var, zone()); | 644 context_locals->Add(var, zone()); |
| 642 } else if (var->IsStackLocal()) { | 645 } else if (var->IsStackLocal()) { |
| 643 stack_locals->Add(var, zone()); | 646 stack_locals->Add(var, zone()); |
| 644 } else { | 647 } else { |
| 645 DCHECK(var->IsParameter()); | 648 DCHECK(var->IsParameter()); |
| 646 } | 649 } |
| 647 } | 650 } |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 num_global_slots_); | 980 num_global_slots_); |
| 978 } | 981 } |
| 979 | 982 |
| 980 // Print locals. | 983 // Print locals. |
| 981 if (function_ != NULL) { | 984 if (function_ != NULL) { |
| 982 Indent(n1, "// function var:\n"); | 985 Indent(n1, "// function var:\n"); |
| 983 PrintVar(n1, function_->proxy()->var()); | 986 PrintVar(n1, function_->proxy()->var()); |
| 984 } | 987 } |
| 985 | 988 |
| 986 if (temps_.length() > 0) { | 989 if (temps_.length() > 0) { |
| 987 Indent(n1, "// temporary vars:\n"); | 990 bool printed_header = false; |
| 988 for (int i = 0; i < temps_.length(); i++) { | 991 for (int i = 0; i < temps_.length(); i++) { |
| 989 PrintVar(n1, temps_[i]); | 992 if (temps_[i] != nullptr) { |
| 993 if (!printed_header) { |
| 994 printed_header = true; |
| 995 Indent(n1, "// temporary vars:\n"); |
| 996 } |
| 997 PrintVar(n1, temps_[i]); |
| 998 } |
| 990 } | 999 } |
| 991 } | 1000 } |
| 992 | 1001 |
| 993 if (variables_.Start() != NULL) { | 1002 if (variables_.Start() != NULL) { |
| 994 Indent(n1, "// local vars:\n"); | 1003 Indent(n1, "// local vars:\n"); |
| 995 PrintMap(n1, &variables_); | 1004 PrintMap(n1, &variables_); |
| 996 } | 1005 } |
| 997 | 1006 |
| 998 if (dynamics_ != NULL) { | 1007 if (dynamics_ != NULL) { |
| 999 Indent(n1, "// dynamic vars:\n"); | 1008 Indent(n1, "// dynamic vars:\n"); |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 // There must be only DYNAMIC_GLOBAL in the script scope. | 1418 // There must be only DYNAMIC_GLOBAL in the script scope. |
| 1410 DCHECK(!is_script_scope() || DYNAMIC_GLOBAL == var->mode()); | 1419 DCHECK(!is_script_scope() || DYNAMIC_GLOBAL == var->mode()); |
| 1411 } | 1420 } |
| 1412 } | 1421 } |
| 1413 } | 1422 } |
| 1414 | 1423 |
| 1415 | 1424 |
| 1416 void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate) { | 1425 void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate) { |
| 1417 // All variables that have no rewrite yet are non-parameter locals. | 1426 // All variables that have no rewrite yet are non-parameter locals. |
| 1418 for (int i = 0; i < temps_.length(); i++) { | 1427 for (int i = 0; i < temps_.length(); i++) { |
| 1428 if (temps_[i] == nullptr) continue; |
| 1419 AllocateNonParameterLocal(isolate, temps_[i]); | 1429 AllocateNonParameterLocal(isolate, temps_[i]); |
| 1420 } | 1430 } |
| 1421 | 1431 |
| 1422 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); | 1432 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); |
| 1423 for (VariableMap::Entry* p = variables_.Start(); | 1433 for (VariableMap::Entry* p = variables_.Start(); |
| 1424 p != NULL; | 1434 p != NULL; |
| 1425 p = variables_.Next(p)) { | 1435 p = variables_.Next(p)) { |
| 1426 Variable* var = reinterpret_cast<Variable*>(p->value); | 1436 Variable* var = reinterpret_cast<Variable*>(p->value); |
| 1427 vars.Add(VarAndOrder(var, p->order), zone()); | 1437 vars.Add(VarAndOrder(var, p->order), zone()); |
| 1428 } | 1438 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1527 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
| 1518 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1528 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1519 (is_function_var_in_context ? 1 : 0); | 1529 (is_function_var_in_context ? 1 : 0); |
| 1520 } | 1530 } |
| 1521 | 1531 |
| 1522 | 1532 |
| 1523 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1533 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1524 | 1534 |
| 1525 } // namespace internal | 1535 } // namespace internal |
| 1526 } // namespace v8 | 1536 } // namespace v8 |
| OLD | NEW |