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

Unified Diff: runtime/vm/ast_printer.cc

Issue 2946903002: Improve --print-ast printing of LetNode. (Closed)
Patch Set: Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/ast_printer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/ast_printer.cc
diff --git a/runtime/vm/ast_printer.cc b/runtime/vm/ast_printer.cc
index e19610911ba9f3713b8cc27cf1ca4fc6a52d4edb..de639406de038637996bbc53d831cb6645369251 100644
--- a/runtime/vm/ast_printer.cc
+++ b/runtime/vm/ast_printer.cc
@@ -44,10 +44,7 @@ void AstPrinter::VisitSequenceNode(SequenceNode* node) {
}
logger_->Print(")");
for (int i = 0; i < node->length(); ++i) {
- logger_->Print("\n");
- for (intptr_t p = 0; p < indent_; p++) {
- logger_->Print(" ");
- }
+ PrintNewlineAndIndent();
node->NodeAt(i)->Visit(this);
}
logger_->Print(")");
@@ -88,18 +85,9 @@ void AstPrinter::VisitReturnNode(ReturnNode* node) {
void AstPrinter::VisitGenericLocalNode(AstNode* node,
- const LocalVariable& var) {
- logger_->Print(
- "(%s %s%s \"%s\"", node->Name(), var.is_final() ? "final " : "",
- String::Handle(var.type().Name()).ToCString(), var.name().ToCString());
- if (var.HasIndex()) {
- if (var.is_captured()) {
- logger_->Print(" (context %d %d)", var.owner()->context_level(),
- var.index());
- } else {
- logger_->Print(" (stack %d)", var.index());
- }
- }
+ const LocalVariable& variable) {
+ logger_->Print("(%s ", node->Name());
+ PrintLocalVariable(&variable);
logger_->Print(" ");
node->VisitChildren(this);
logger_->Print(")");
@@ -146,8 +134,51 @@ void AstPrinter::VisitStoreStaticFieldNode(StoreStaticFieldNode* node) {
}
+void AstPrinter::PrintLocalVariable(const LocalVariable* variable) {
+ logger_->Print("%s%s \"%s\"", variable->is_final() ? "final " : "",
+ String::Handle(variable->type().Name()).ToCString(),
+ variable->name().ToCString());
+ if (variable->HasIndex()) {
+ if (variable->is_captured()) {
+ logger_->Print(" (context %d %d)", variable->owner()->context_level(),
+ variable->index());
+ } else {
+ logger_->Print(" (stack %d)", variable->index());
+ }
+ }
+}
+
+
+void AstPrinter::PrintNewlineAndIndent() {
+ logger_->Print("\n");
+ for (intptr_t p = 0; p < indent_; ++p) {
+ logger_->Print(" ");
+ }
+}
+
+
void AstPrinter::VisitLetNode(LetNode* node) {
- VisitGenericAstNode(node);
+ logger_->Print("(Let (");
+ // Indent the variables and initializers by two.
+ indent_ += 2;
+ for (intptr_t i = 0; i < node->num_temps(); ++i) {
+ if (i != 0) PrintNewlineAndIndent();
+ logger_->Print("(");
+ PrintLocalVariable(node->TempAt(i));
+ logger_->Print(" ");
+ node->InitializerAt(i)->Visit(this);
+ logger_->Print(")");
+ }
+ logger_->Print(")");
+
+ // Indent the body nodes by one.
+ --indent_;
+ for (intptr_t i = 0; i < node->nodes().length(); ++i) {
+ PrintNewlineAndIndent();
+ node->nodes()[i]->Visit(this);
+ }
+ logger_->Print(")");
+ --indent_;
}
« no previous file with comments | « runtime/vm/ast_printer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698