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

Side by Side Diff: src/scopes.cc

Issue 1263563002: Correct handling of temporaries as parameters. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « src/parser.h ('k') | src/variables.h » ('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 // 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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 if (var != NULL) return var; 458 if (var != NULL) return var;
459 } 459 }
460 return NULL; 460 return NULL;
461 } 461 }
462 462
463 463
464 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode, 464 Variable* Scope::DeclareParameter(const AstRawString* name, VariableMode mode,
465 bool is_rest, bool* is_duplicate) { 465 bool is_rest, bool* is_duplicate) {
466 DCHECK(!already_resolved()); 466 DCHECK(!already_resolved());
467 DCHECK(is_function_scope()); 467 DCHECK(is_function_scope());
468
469 Variable* var; 468 Variable* var;
470 if (!name->IsEmpty()) { 469 if (mode == TEMPORARY) {
470 var = NewTemporary(name);
471 } else {
471 var = variables_.Declare(this, name, mode, Variable::NORMAL, 472 var = variables_.Declare(this, name, mode, Variable::NORMAL,
472 kCreatedInitialized); 473 kCreatedInitialized);
473 // TODO(wingo): Avoid O(n^2) check. 474 // TODO(wingo): Avoid O(n^2) check.
474 *is_duplicate = IsDeclaredParameter(name); 475 *is_duplicate = IsDeclaredParameter(name);
475 } else {
476 var = new (zone())
477 Variable(this, name, TEMPORARY, Variable::NORMAL, kCreatedInitialized);
478 } 476 }
479 if (is_rest) { 477 if (is_rest) {
480 DCHECK_NULL(rest_parameter_); 478 DCHECK_NULL(rest_parameter_);
481 rest_parameter_ = var; 479 rest_parameter_ = var;
482 rest_index_ = num_parameters(); 480 rest_index_ = num_parameters();
483 } 481 }
484 params_.Add(var, zone()); 482 params_.Add(var, zone());
485 return var; 483 return var;
486 } 484 }
487 485
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 DCHECK(context_globals != NULL); 611 DCHECK(context_globals != NULL);
614 612
615 // Collect temporaries which are always allocated on the stack, unless the 613 // Collect temporaries which are always allocated on the stack, unless the
616 // context as a whole has forced context allocation. 614 // context as a whole has forced context allocation.
617 for (int i = 0; i < temps_.length(); i++) { 615 for (int i = 0; i < temps_.length(); i++) {
618 Variable* var = temps_[i]; 616 Variable* var = temps_[i];
619 if (var->is_used()) { 617 if (var->is_used()) {
620 if (var->IsContextSlot()) { 618 if (var->IsContextSlot()) {
621 DCHECK(has_forced_context_allocation()); 619 DCHECK(has_forced_context_allocation());
622 context_locals->Add(var, zone()); 620 context_locals->Add(var, zone());
621 } else if (var->IsStackLocal()) {
622 stack_locals->Add(var, zone());
623 } else { 623 } else {
624 DCHECK(var->IsStackLocal()); 624 DCHECK(var->IsParameter());
625 stack_locals->Add(var, zone());
626 } 625 }
627 } 626 }
628 } 627 }
629 628
630 // Collect declared local variables. 629 // Collect declared local variables.
631 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone()); 630 ZoneList<VarAndOrder> vars(variables_.occupancy(), zone());
632 for (VariableMap::Entry* p = variables_.Start(); 631 for (VariableMap::Entry* p = variables_.Start();
633 p != NULL; 632 p != NULL;
634 p = variables_.Next(p)) { 633 p = variables_.Next(p)) {
635 Variable* var = reinterpret_cast<Variable*>(p->value); 634 Variable* var = reinterpret_cast<Variable*>(p->value);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 PrintF("lookup"); 854 PrintF("lookup");
856 break; 855 break;
857 } 856 }
858 } 857 }
859 858
860 859
861 static void PrintVar(int indent, Variable* var) { 860 static void PrintVar(int indent, Variable* var) {
862 if (var->is_used() || !var->IsUnallocated()) { 861 if (var->is_used() || !var->IsUnallocated()) {
863 Indent(indent, Variable::Mode2String(var->mode())); 862 Indent(indent, Variable::Mode2String(var->mode()));
864 PrintF(" "); 863 PrintF(" ");
865 PrintName(var->raw_name()); 864 if (var->raw_name()->IsEmpty())
865 PrintF(".%p", var);
866 else
867 PrintName(var->raw_name());
866 PrintF("; // "); 868 PrintF("; // ");
867 PrintLocation(var); 869 PrintLocation(var);
868 bool comma = !var->IsUnallocated(); 870 bool comma = !var->IsUnallocated();
869 if (var->has_forced_context_allocation()) { 871 if (var->has_forced_context_allocation()) {
870 if (comma) PrintF(", "); 872 if (comma) PrintF(", ");
871 PrintF("forced context allocation"); 873 PrintF("forced context allocation");
872 comma = true; 874 comma = true;
873 } 875 }
874 if (var->maybe_assigned() == kMaybeAssigned) { 876 if (var->maybe_assigned() == kMaybeAssigned) {
875 if (comma) PrintF(", "); 877 if (comma) PrintF(", ");
(...skipping 25 matching lines...) Expand all
901 if (!scope_name_->IsEmpty()) { 903 if (!scope_name_->IsEmpty()) {
902 PrintF(" "); 904 PrintF(" ");
903 PrintName(scope_name_); 905 PrintName(scope_name_);
904 } 906 }
905 907
906 // Print parameters, if any. 908 // Print parameters, if any.
907 if (is_function_scope()) { 909 if (is_function_scope()) {
908 PrintF(" ("); 910 PrintF(" (");
909 for (int i = 0; i < params_.length(); i++) { 911 for (int i = 0; i < params_.length(); i++) {
910 if (i > 0) PrintF(", "); 912 if (i > 0) PrintF(", ");
911 PrintName(params_[i]->raw_name()); 913 const AstRawString* name = params_[i]->raw_name();
914 if (name->IsEmpty())
915 PrintF(".%p", params_[i]);
916 else
917 PrintName(name);
912 } 918 }
913 PrintF(")"); 919 PrintF(")");
914 } 920 }
915 921
916 PrintF(" { // (%d, %d)\n", start_position(), end_position()); 922 PrintF(" { // (%d, %d)\n", start_position(), end_position());
917 923
918 // Function name, if any (named function literals, only). 924 // Function name, if any (named function literals, only).
919 if (function_ != NULL) { 925 if (function_ != NULL) {
920 Indent(n1, "// (local) function name: "); 926 Indent(n1, "// (local) function name: ");
921 PrintName(function_->proxy()->raw_name()); 927 PrintName(function_->proxy()->raw_name());
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 function_ != NULL && function_->proxy()->var()->IsContextSlot(); 1605 function_ != NULL && function_->proxy()->var()->IsContextSlot();
1600 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1606 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1601 (is_function_var_in_context ? 1 : 0); 1607 (is_function_var_in_context ? 1 : 0);
1602 } 1608 }
1603 1609
1604 1610
1605 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1611 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1606 1612
1607 } // namespace internal 1613 } // namespace internal
1608 } // namespace v8 1614 } // namespace v8
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/variables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698