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

Side by Side Diff: src/ast/scopes.cc

Issue 2544063004: Clean up --print-scopes output (Closed)
Patch Set: Created 4 years 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 | « no previous file | no next file » | 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/ast/scopes.h" 5 #include "src/ast/scopes.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 case VariableLocation::LOOKUP: 1389 case VariableLocation::LOOKUP:
1390 PrintF("lookup"); 1390 PrintF("lookup");
1391 break; 1391 break;
1392 case VariableLocation::MODULE: 1392 case VariableLocation::MODULE:
1393 PrintF("module"); 1393 PrintF("module");
1394 break; 1394 break;
1395 } 1395 }
1396 } 1396 }
1397 1397
1398 1398
1399 static void PrintVar(int indent, Variable* var) { 1399 static void PrintVar(int indent, Variable* var) {
Igor Sheludko 2016/12/02 22:06:10 While you are here please put this function into a
adamk 2016/12/03 00:04:23 Wrapped all these helpers in an anonymous namespac
1400 if (var->is_used() || !var->IsUnallocated()) { 1400 Indent(indent, VariableMode2String(var->mode()));
1401 Indent(indent, VariableMode2String(var->mode())); 1401 PrintF(" ");
1402 PrintF(" "); 1402 if (var->raw_name()->IsEmpty())
1403 if (var->raw_name()->IsEmpty()) 1403 PrintF(".%p", reinterpret_cast<void*>(var));
1404 PrintF(".%p", reinterpret_cast<void*>(var)); 1404 else
1405 else 1405 PrintName(var->raw_name());
1406 PrintName(var->raw_name()); 1406 PrintF("; // ");
1407 PrintF("; // "); 1407 PrintLocation(var);
1408 PrintLocation(var); 1408 bool comma = !var->IsUnallocated();
1409 bool comma = !var->IsUnallocated(); 1409 if (var->has_forced_context_allocation()) {
1410 if (var->has_forced_context_allocation()) { 1410 if (comma) PrintF(", ");
1411 if (comma) PrintF(", "); 1411 PrintF("forced context allocation");
1412 PrintF("forced context allocation"); 1412 comma = true;
1413 comma = true;
1414 }
1415 if (var->maybe_assigned() == kNotAssigned) {
1416 if (comma) PrintF(", ");
1417 PrintF("never assigned");
1418 }
1419 PrintF("\n");
1420 } 1413 }
1414 if (var->maybe_assigned() == kNotAssigned) {
1415 if (comma) PrintF(", ");
1416 PrintF("never assigned");
1417 }
1418 PrintF("\n");
1421 } 1419 }
1422 1420
1423 static void PrintMap(int indent, VariableMap* map, bool locals) { 1421 static void PrintMap(int indent, const char* label, VariableMap* map,
Igor Sheludko 2016/12/02 22:06:10 Same here.
adamk 2016/12/03 00:04:23 Done.
1422 bool locals, Variable* function_var) {
1423 bool printed_label = false;
1424 for (VariableMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) { 1424 for (VariableMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) {
1425 Variable* var = reinterpret_cast<Variable*>(p->value); 1425 Variable* var = reinterpret_cast<Variable*>(p->value);
1426 if (var == function_var) continue;
1426 bool local = !IsDynamicVariableMode(var->mode()); 1427 bool local = !IsDynamicVariableMode(var->mode());
1427 if (locals ? local : !local) { 1428 if ((locals ? local : !local) &&
1428 if (var == nullptr) { 1429 (var->is_used() || !var->IsUnallocated())) {
1429 Indent(indent, "<?>\n"); 1430 if (!printed_label) {
1430 } else { 1431 Indent(indent, label);
1431 PrintVar(indent, var); 1432 printed_label = true;
1432 } 1433 }
1434 PrintVar(indent, var);
1433 } 1435 }
1434 } 1436 }
1435 } 1437 }
1436 1438
1437 void DeclarationScope::PrintParameters() { 1439 void DeclarationScope::PrintParameters() {
1438 PrintF(" ("); 1440 PrintF(" (");
1439 for (int i = 0; i < params_.length(); i++) { 1441 for (int i = 0; i < params_.length(); i++) {
1440 if (i > 0) PrintF(", "); 1442 if (i > 0) PrintF(", ");
1441 const AstRawString* name = params_[i]->raw_name(); 1443 const AstRawString* name = params_[i]->raw_name();
1442 if (name->IsEmpty()) 1444 if (name->IsEmpty())
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 Indent(n1, "// "); 1503 Indent(n1, "// ");
1502 PrintF("%d heap slots\n", num_heap_slots_); 1504 PrintF("%d heap slots\n", num_heap_slots_);
1503 } 1505 }
1504 1506
1505 // Print locals. 1507 // Print locals.
1506 if (function != nullptr) { 1508 if (function != nullptr) {
1507 Indent(n1, "// function var:\n"); 1509 Indent(n1, "// function var:\n");
1508 PrintVar(n1, function); 1510 PrintVar(n1, function);
1509 } 1511 }
1510 1512
1511 if (variables_.occupancy() != 0) { 1513 PrintMap(n1, "// local vars:\n", &variables_, true, function);
1512 Indent(n1, "// local vars:\n"); 1514 PrintMap(n1, "// dynamic vars:\n", &variables_, false, function);
1513 PrintMap(n1, &variables_, true);
1514
1515 Indent(n1, "// dynamic vars:\n");
1516 PrintMap(n1, &variables_, false);
1517 }
1518 1515
1519 // Print inner scopes (disable by providing negative n). 1516 // Print inner scopes (disable by providing negative n).
1520 if (n >= 0) { 1517 if (n >= 0) {
1521 for (Scope* scope = inner_scope_; scope != nullptr; 1518 for (Scope* scope = inner_scope_; scope != nullptr;
1522 scope = scope->sibling_) { 1519 scope = scope->sibling_) {
1523 PrintF("\n"); 1520 PrintF("\n");
1524 scope->Print(n1); 1521 scope->Print(n1);
1525 } 1522 }
1526 } 1523 }
1527 1524
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
2069 Variable* function = 2066 Variable* function =
2070 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 2067 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
2071 bool is_function_var_in_context = 2068 bool is_function_var_in_context =
2072 function != nullptr && function->IsContextSlot(); 2069 function != nullptr && function->IsContextSlot();
2073 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 2070 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
2074 (is_function_var_in_context ? 1 : 0); 2071 (is_function_var_in_context ? 1 : 0);
2075 } 2072 }
2076 2073
2077 } // namespace internal 2074 } // namespace internal
2078 } // namespace v8 2075 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698