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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
976 PrintF("%d heap slots (including %d global slots)\n", num_heap_slots_, | 979 PrintF("%d heap slots (including %d global slots)\n", num_heap_slots_, |
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) { |
nickie
2016/05/10 13:47:08
If you have length() > 0 but only null elements, y
adamk
2016/05/10 17:36:11
This is probably the ugliest part of this approach
| |
987 Indent(n1, "// temporary vars:\n"); | 990 Indent(n1, "// temporary vars:\n"); |
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] != NULL) { |
nickie
2016/05/10 13:47:08
Not nullptr? :-)
adamk
2016/05/10 17:36:11
Was going for consistent, but looks like this func
| |
993 PrintVar(n1, temps_[i]); | |
994 } | |
990 } | 995 } |
991 } | 996 } |
992 | 997 |
993 if (variables_.Start() != NULL) { | 998 if (variables_.Start() != NULL) { |
994 Indent(n1, "// local vars:\n"); | 999 Indent(n1, "// local vars:\n"); |
995 PrintMap(n1, &variables_); | 1000 PrintMap(n1, &variables_); |
996 } | 1001 } |
997 | 1002 |
998 if (dynamics_ != NULL) { | 1003 if (dynamics_ != NULL) { |
999 Indent(n1, "// dynamic vars:\n"); | 1004 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. | 1414 // There must be only DYNAMIC_GLOBAL in the script scope. |
1410 DCHECK(!is_script_scope() || DYNAMIC_GLOBAL == var->mode()); | 1415 DCHECK(!is_script_scope() || DYNAMIC_GLOBAL == var->mode()); |
1411 } | 1416 } |
1412 } | 1417 } |
1413 } | 1418 } |
1414 | 1419 |
1415 | 1420 |
1416 void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate) { | 1421 void Scope::AllocateNonParameterLocalsAndDeclaredGlobals(Isolate* isolate) { |
1417 // All variables that have no rewrite yet are non-parameter locals. | 1422 // All variables that have no rewrite yet are non-parameter locals. |
1418 for (int i = 0; i < temps_.length(); i++) { | 1423 for (int i = 0; i < temps_.length(); i++) { |
1424 if (temps_[i] == nullptr) continue; | |
1419 AllocateNonParameterLocal(isolate, temps_[i]); | 1425 AllocateNonParameterLocal(isolate, temps_[i]); |
1420 } | 1426 } |
1421 | 1427 |
1422 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); | 1428 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); |
1423 for (VariableMap::Entry* p = variables_.Start(); | 1429 for (VariableMap::Entry* p = variables_.Start(); |
1424 p != NULL; | 1430 p != NULL; |
1425 p = variables_.Next(p)) { | 1431 p = variables_.Next(p)) { |
1426 Variable* var = reinterpret_cast<Variable*>(p->value); | 1432 Variable* var = reinterpret_cast<Variable*>(p->value); |
1427 vars.Add(VarAndOrder(var, p->order), zone()); | 1433 vars.Add(VarAndOrder(var, p->order), zone()); |
1428 } | 1434 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1517 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1523 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1518 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1524 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1519 (is_function_var_in_context ? 1 : 0); | 1525 (is_function_var_in_context ? 1 : 0); |
1520 } | 1526 } |
1521 | 1527 |
1522 | 1528 |
1523 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1529 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1524 | 1530 |
1525 } // namespace internal | 1531 } // namespace internal |
1526 } // namespace v8 | 1532 } // namespace v8 |
OLD | NEW |