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

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

Issue 2544063004: Clean up --print-scopes output (Closed)
Patch Set: Anonymous namespace 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 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 arguments_ = nullptr; 1335 arguments_ = nullptr;
1336 } 1336 }
1337 } 1337 }
1338 1338
1339 ResetAfterPreparsing(ast_node_factory->ast_value_factory(), false); 1339 ResetAfterPreparsing(ast_node_factory->ast_value_factory(), false);
1340 1340
1341 unresolved_ = unresolved; 1341 unresolved_ = unresolved;
1342 } 1342 }
1343 1343
1344 #ifdef DEBUG 1344 #ifdef DEBUG
1345 static const char* Header(ScopeType scope_type, FunctionKind function_kind, 1345 namespace {
1346 bool is_declaration_scope) { 1346
1347 const char* Header(ScopeType scope_type, FunctionKind function_kind,
1348 bool is_declaration_scope) {
1347 switch (scope_type) { 1349 switch (scope_type) {
1348 case EVAL_SCOPE: return "eval"; 1350 case EVAL_SCOPE: return "eval";
1349 // TODO(adamk): Should we print concise method scopes specially? 1351 // TODO(adamk): Should we print concise method scopes specially?
1350 case FUNCTION_SCOPE: 1352 case FUNCTION_SCOPE:
1351 if (IsGeneratorFunction(function_kind)) return "function*"; 1353 if (IsGeneratorFunction(function_kind)) return "function*";
1352 if (IsAsyncFunction(function_kind)) return "async function"; 1354 if (IsAsyncFunction(function_kind)) return "async function";
1353 if (IsArrowFunction(function_kind)) return "arrow"; 1355 if (IsArrowFunction(function_kind)) return "arrow";
1354 return "function"; 1356 return "function";
1355 case MODULE_SCOPE: return "module"; 1357 case MODULE_SCOPE: return "module";
1356 case SCRIPT_SCOPE: return "global"; 1358 case SCRIPT_SCOPE: return "global";
1357 case CATCH_SCOPE: return "catch"; 1359 case CATCH_SCOPE: return "catch";
1358 case BLOCK_SCOPE: return is_declaration_scope ? "varblock" : "block"; 1360 case BLOCK_SCOPE: return is_declaration_scope ? "varblock" : "block";
1359 case WITH_SCOPE: return "with"; 1361 case WITH_SCOPE: return "with";
1360 } 1362 }
1361 UNREACHABLE(); 1363 UNREACHABLE();
1362 return NULL; 1364 return NULL;
1363 } 1365 }
1364 1366
1367 void Indent(int n, const char* str) { PrintF("%*s%s", n, "", str); }
1365 1368
1366 static void Indent(int n, const char* str) { 1369 void PrintName(const AstRawString* name) {
1367 PrintF("%*s%s", n, "", str);
1368 }
1369
1370
1371 static void PrintName(const AstRawString* name) {
1372 PrintF("%.*s", name->length(), name->raw_data()); 1370 PrintF("%.*s", name->length(), name->raw_data());
1373 } 1371 }
1374 1372
1375 1373 void PrintLocation(Variable* var) {
1376 static void PrintLocation(Variable* var) {
1377 switch (var->location()) { 1374 switch (var->location()) {
1378 case VariableLocation::UNALLOCATED: 1375 case VariableLocation::UNALLOCATED:
1379 break; 1376 break;
1380 case VariableLocation::PARAMETER: 1377 case VariableLocation::PARAMETER:
1381 PrintF("parameter[%d]", var->index()); 1378 PrintF("parameter[%d]", var->index());
1382 break; 1379 break;
1383 case VariableLocation::LOCAL: 1380 case VariableLocation::LOCAL:
1384 PrintF("local[%d]", var->index()); 1381 PrintF("local[%d]", var->index());
1385 break; 1382 break;
1386 case VariableLocation::CONTEXT: 1383 case VariableLocation::CONTEXT:
1387 PrintF("context[%d]", var->index()); 1384 PrintF("context[%d]", var->index());
1388 break; 1385 break;
1389 case VariableLocation::LOOKUP: 1386 case VariableLocation::LOOKUP:
1390 PrintF("lookup"); 1387 PrintF("lookup");
1391 break; 1388 break;
1392 case VariableLocation::MODULE: 1389 case VariableLocation::MODULE:
1393 PrintF("module"); 1390 PrintF("module");
1394 break; 1391 break;
1395 } 1392 }
1396 } 1393 }
1397 1394
1398 1395 void PrintVar(int indent, Variable* var) {
1399 static void PrintVar(int indent, Variable* var) { 1396 Indent(indent, VariableMode2String(var->mode()));
1400 if (var->is_used() || !var->IsUnallocated()) { 1397 PrintF(" ");
1401 Indent(indent, VariableMode2String(var->mode())); 1398 if (var->raw_name()->IsEmpty())
1402 PrintF(" "); 1399 PrintF(".%p", reinterpret_cast<void*>(var));
1403 if (var->raw_name()->IsEmpty()) 1400 else
1404 PrintF(".%p", reinterpret_cast<void*>(var)); 1401 PrintName(var->raw_name());
1405 else 1402 PrintF("; // ");
1406 PrintName(var->raw_name()); 1403 PrintLocation(var);
1407 PrintF("; // "); 1404 bool comma = !var->IsUnallocated();
1408 PrintLocation(var); 1405 if (var->has_forced_context_allocation()) {
1409 bool comma = !var->IsUnallocated(); 1406 if (comma) PrintF(", ");
1410 if (var->has_forced_context_allocation()) { 1407 PrintF("forced context allocation");
1411 if (comma) PrintF(", "); 1408 comma = true;
1412 PrintF("forced context allocation");
1413 comma = true;
1414 }
1415 if (var->maybe_assigned() == kNotAssigned) {
1416 if (comma) PrintF(", ");
1417 PrintF("never assigned");
1418 }
1419 PrintF("\n");
1420 } 1409 }
1410 if (var->maybe_assigned() == kNotAssigned) {
1411 if (comma) PrintF(", ");
1412 PrintF("never assigned");
1413 }
1414 PrintF("\n");
1421 } 1415 }
1422 1416
1423 static void PrintMap(int indent, VariableMap* map, bool locals) { 1417 void PrintMap(int indent, const char* label, VariableMap* map, bool locals,
1418 Variable* function_var) {
1419 bool printed_label = false;
1424 for (VariableMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) { 1420 for (VariableMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) {
1425 Variable* var = reinterpret_cast<Variable*>(p->value); 1421 Variable* var = reinterpret_cast<Variable*>(p->value);
1422 if (var == function_var) continue;
1426 bool local = !IsDynamicVariableMode(var->mode()); 1423 bool local = !IsDynamicVariableMode(var->mode());
1427 if (locals ? local : !local) { 1424 if ((locals ? local : !local) &&
1428 if (var == nullptr) { 1425 (var->is_used() || !var->IsUnallocated())) {
1429 Indent(indent, "<?>\n"); 1426 if (!printed_label) {
1430 } else { 1427 Indent(indent, label);
1431 PrintVar(indent, var); 1428 printed_label = true;
1432 } 1429 }
1430 PrintVar(indent, var);
1433 } 1431 }
1434 } 1432 }
1435 } 1433 }
1436 1434
1435 } // anonymous namespace
1436
1437 void DeclarationScope::PrintParameters() { 1437 void DeclarationScope::PrintParameters() {
1438 PrintF(" ("); 1438 PrintF(" (");
1439 for (int i = 0; i < params_.length(); i++) { 1439 for (int i = 0; i < params_.length(); i++) {
1440 if (i > 0) PrintF(", "); 1440 if (i > 0) PrintF(", ");
1441 const AstRawString* name = params_[i]->raw_name(); 1441 const AstRawString* name = params_[i]->raw_name();
1442 if (name->IsEmpty()) 1442 if (name->IsEmpty())
1443 PrintF(".%p", reinterpret_cast<void*>(params_[i])); 1443 PrintF(".%p", reinterpret_cast<void*>(params_[i]));
1444 else 1444 else
1445 PrintName(name); 1445 PrintName(name);
1446 } 1446 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 Indent(n1, "// "); 1501 Indent(n1, "// ");
1502 PrintF("%d heap slots\n", num_heap_slots_); 1502 PrintF("%d heap slots\n", num_heap_slots_);
1503 } 1503 }
1504 1504
1505 // Print locals. 1505 // Print locals.
1506 if (function != nullptr) { 1506 if (function != nullptr) {
1507 Indent(n1, "// function var:\n"); 1507 Indent(n1, "// function var:\n");
1508 PrintVar(n1, function); 1508 PrintVar(n1, function);
1509 } 1509 }
1510 1510
1511 if (variables_.occupancy() != 0) { 1511 PrintMap(n1, "// local vars:\n", &variables_, true, function);
1512 Indent(n1, "// local vars:\n"); 1512 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 1513
1519 // Print inner scopes (disable by providing negative n). 1514 // Print inner scopes (disable by providing negative n).
1520 if (n >= 0) { 1515 if (n >= 0) {
1521 for (Scope* scope = inner_scope_; scope != nullptr; 1516 for (Scope* scope = inner_scope_; scope != nullptr;
1522 scope = scope->sibling_) { 1517 scope = scope->sibling_) {
1523 PrintF("\n"); 1518 PrintF("\n");
1524 scope->Print(n1); 1519 scope->Print(n1);
1525 } 1520 }
1526 } 1521 }
1527 1522
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
2069 Variable* function = 2064 Variable* function =
2070 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 2065 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
2071 bool is_function_var_in_context = 2066 bool is_function_var_in_context =
2072 function != nullptr && function->IsContextSlot(); 2067 function != nullptr && function->IsContextSlot();
2073 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 2068 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
2074 (is_function_var_in_context ? 1 : 0); 2069 (is_function_var_in_context ? 1 : 0);
2075 } 2070 }
2076 2071
2077 } // namespace internal 2072 } // namespace internal
2078 } // namespace v8 2073 } // 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