Commit 00b9c9e6 authored by adamk's avatar adamk Committed by Commit bot

Clean up --print-scopes output

Several cleanups to the output of the debug-only --print-scopes flag:
  - Function name variable only printed once
  - Only print headers for sections of variables that are non-empty
  - Assume Variables stored in Scope::variables_ are never null

R=verwaest@chromium.org

Review-Url: https://codereview.chromium.org/2544063004
Cr-Commit-Position: refs/heads/master@{#41463}
parent 50e50db7
...@@ -1342,8 +1342,10 @@ void DeclarationScope::AnalyzePartially(AstNodeFactory* ast_node_factory) { ...@@ -1342,8 +1342,10 @@ void DeclarationScope::AnalyzePartially(AstNodeFactory* ast_node_factory) {
} }
#ifdef DEBUG #ifdef DEBUG
static const char* Header(ScopeType scope_type, FunctionKind function_kind, namespace {
bool is_declaration_scope) {
const char* Header(ScopeType scope_type, FunctionKind function_kind,
bool is_declaration_scope) {
switch (scope_type) { switch (scope_type) {
case EVAL_SCOPE: return "eval"; case EVAL_SCOPE: return "eval";
// TODO(adamk): Should we print concise method scopes specially? // TODO(adamk): Should we print concise method scopes specially?
...@@ -1362,18 +1364,13 @@ static const char* Header(ScopeType scope_type, FunctionKind function_kind, ...@@ -1362,18 +1364,13 @@ static const char* Header(ScopeType scope_type, FunctionKind function_kind,
return NULL; return NULL;
} }
void Indent(int n, const char* str) { PrintF("%*s%s", n, "", str); }
static void Indent(int n, const char* str) { void PrintName(const AstRawString* name) {
PrintF("%*s%s", n, "", str);
}
static void PrintName(const AstRawString* name) {
PrintF("%.*s", name->length(), name->raw_data()); PrintF("%.*s", name->length(), name->raw_data());
} }
void PrintLocation(Variable* var) {
static void PrintLocation(Variable* var) {
switch (var->location()) { switch (var->location()) {
case VariableLocation::UNALLOCATED: case VariableLocation::UNALLOCATED:
break; break;
...@@ -1395,45 +1392,48 @@ static void PrintLocation(Variable* var) { ...@@ -1395,45 +1392,48 @@ static void PrintLocation(Variable* var) {
} }
} }
void PrintVar(int indent, Variable* var) {
static void PrintVar(int indent, Variable* var) { Indent(indent, VariableMode2String(var->mode()));
if (var->is_used() || !var->IsUnallocated()) { PrintF(" ");
Indent(indent, VariableMode2String(var->mode())); if (var->raw_name()->IsEmpty())
PrintF(" "); PrintF(".%p", reinterpret_cast<void*>(var));
if (var->raw_name()->IsEmpty()) else
PrintF(".%p", reinterpret_cast<void*>(var)); PrintName(var->raw_name());
else PrintF("; // ");
PrintName(var->raw_name()); PrintLocation(var);
PrintF("; // "); bool comma = !var->IsUnallocated();
PrintLocation(var); if (var->has_forced_context_allocation()) {
bool comma = !var->IsUnallocated(); if (comma) PrintF(", ");
if (var->has_forced_context_allocation()) { PrintF("forced context allocation");
if (comma) PrintF(", "); comma = true;
PrintF("forced context allocation");
comma = true;
}
if (var->maybe_assigned() == kNotAssigned) {
if (comma) PrintF(", ");
PrintF("never assigned");
}
PrintF("\n");
} }
if (var->maybe_assigned() == kNotAssigned) {
if (comma) PrintF(", ");
PrintF("never assigned");
}
PrintF("\n");
} }
static void PrintMap(int indent, VariableMap* map, bool locals) { void PrintMap(int indent, const char* label, VariableMap* map, bool locals,
Variable* function_var) {
bool printed_label = false;
for (VariableMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) { for (VariableMap::Entry* p = map->Start(); p != nullptr; p = map->Next(p)) {
Variable* var = reinterpret_cast<Variable*>(p->value); Variable* var = reinterpret_cast<Variable*>(p->value);
if (var == function_var) continue;
bool local = !IsDynamicVariableMode(var->mode()); bool local = !IsDynamicVariableMode(var->mode());
if (locals ? local : !local) { if ((locals ? local : !local) &&
if (var == nullptr) { (var->is_used() || !var->IsUnallocated())) {
Indent(indent, "<?>\n"); if (!printed_label) {
} else { Indent(indent, label);
PrintVar(indent, var); printed_label = true;
} }
PrintVar(indent, var);
} }
} }
} }
} // anonymous namespace
void DeclarationScope::PrintParameters() { void DeclarationScope::PrintParameters() {
PrintF(" ("); PrintF(" (");
for (int i = 0; i < params_.length(); i++) { for (int i = 0; i < params_.length(); i++) {
...@@ -1508,13 +1508,8 @@ void Scope::Print(int n) { ...@@ -1508,13 +1508,8 @@ void Scope::Print(int n) {
PrintVar(n1, function); PrintVar(n1, function);
} }
if (variables_.occupancy() != 0) { PrintMap(n1, "// local vars:\n", &variables_, true, function);
Indent(n1, "// local vars:\n"); PrintMap(n1, "// dynamic vars:\n", &variables_, false, function);
PrintMap(n1, &variables_, true);
Indent(n1, "// dynamic vars:\n");
PrintMap(n1, &variables_, false);
}
// Print inner scopes (disable by providing negative n). // Print inner scopes (disable by providing negative n).
if (n >= 0) { if (n >= 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment