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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/ast_printer.h ('k') | 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 (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/ast_printer.h" 5 #include "vm/ast_printer.h"
6 6
7 #include "vm/handles.h" 7 #include "vm/handles.h"
8 #include "vm/log.h" 8 #include "vm/log.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/os.h" 10 #include "vm/os.h"
(...skipping 26 matching lines...) Expand all
37 scope->end_token_pos().ToCString(), scope->loop_level()); 37 scope->end_token_pos().ToCString(), scope->loop_level());
38 if (scope->HasContextLevel()) { 38 if (scope->HasContextLevel()) {
39 logger_->Print(" context %d captures %d", scope->context_level(), 39 logger_->Print(" context %d captures %d", scope->context_level(),
40 scope->num_context_variables()); 40 scope->num_context_variables());
41 } else { 41 } else {
42 ASSERT(scope->num_context_variables() == 0); 42 ASSERT(scope->num_context_variables() == 0);
43 } 43 }
44 } 44 }
45 logger_->Print(")"); 45 logger_->Print(")");
46 for (int i = 0; i < node->length(); ++i) { 46 for (int i = 0; i < node->length(); ++i) {
47 logger_->Print("\n"); 47 PrintNewlineAndIndent();
48 for (intptr_t p = 0; p < indent_; p++) {
49 logger_->Print(" ");
50 }
51 node->NodeAt(i)->Visit(this); 48 node->NodeAt(i)->Visit(this);
52 } 49 }
53 logger_->Print(")"); 50 logger_->Print(")");
54 indent_--; 51 indent_--;
55 } 52 }
56 53
57 54
58 void AstPrinter::VisitCloneContextNode(CloneContextNode* node) { 55 void AstPrinter::VisitCloneContextNode(CloneContextNode* node) {
59 VisitGenericAstNode(node); 56 VisitGenericAstNode(node);
60 } 57 }
(...skipping 20 matching lines...) Expand all
81 kind = ""; 78 kind = "";
82 UNREACHABLE(); 79 UNREACHABLE();
83 } 80 }
84 logger_->Print("(%s %s", node->Name(), kind); 81 logger_->Print("(%s %s", node->Name(), kind);
85 node->VisitChildren(this); 82 node->VisitChildren(this);
86 logger_->Print(")"); 83 logger_->Print(")");
87 } 84 }
88 85
89 86
90 void AstPrinter::VisitGenericLocalNode(AstNode* node, 87 void AstPrinter::VisitGenericLocalNode(AstNode* node,
91 const LocalVariable& var) { 88 const LocalVariable& variable) {
92 logger_->Print( 89 logger_->Print("(%s ", node->Name());
93 "(%s %s%s \"%s\"", node->Name(), var.is_final() ? "final " : "", 90 PrintLocalVariable(&variable);
94 String::Handle(var.type().Name()).ToCString(), var.name().ToCString());
95 if (var.HasIndex()) {
96 if (var.is_captured()) {
97 logger_->Print(" (context %d %d)", var.owner()->context_level(),
98 var.index());
99 } else {
100 logger_->Print(" (stack %d)", var.index());
101 }
102 }
103 logger_->Print(" "); 91 logger_->Print(" ");
104 node->VisitChildren(this); 92 node->VisitChildren(this);
105 logger_->Print(")"); 93 logger_->Print(")");
106 } 94 }
107 95
108 96
109 void AstPrinter::VisitLoadLocalNode(LoadLocalNode* node) { 97 void AstPrinter::VisitLoadLocalNode(LoadLocalNode* node) {
110 VisitGenericLocalNode(node, node->local()); 98 VisitGenericLocalNode(node, node->local());
111 } 99 }
112 100
(...skipping 26 matching lines...) Expand all
139 void AstPrinter::VisitLoadStaticFieldNode(LoadStaticFieldNode* node) { 127 void AstPrinter::VisitLoadStaticFieldNode(LoadStaticFieldNode* node) {
140 VisitGenericFieldNode(node, node->field()); 128 VisitGenericFieldNode(node, node->field());
141 } 129 }
142 130
143 131
144 void AstPrinter::VisitStoreStaticFieldNode(StoreStaticFieldNode* node) { 132 void AstPrinter::VisitStoreStaticFieldNode(StoreStaticFieldNode* node) {
145 VisitGenericFieldNode(node, node->field()); 133 VisitGenericFieldNode(node, node->field());
146 } 134 }
147 135
148 136
137 void AstPrinter::PrintLocalVariable(const LocalVariable* variable) {
138 logger_->Print("%s%s \"%s\"", variable->is_final() ? "final " : "",
139 String::Handle(variable->type().Name()).ToCString(),
140 variable->name().ToCString());
141 if (variable->HasIndex()) {
142 if (variable->is_captured()) {
143 logger_->Print(" (context %d %d)", variable->owner()->context_level(),
144 variable->index());
145 } else {
146 logger_->Print(" (stack %d)", variable->index());
147 }
148 }
149 }
150
151
152 void AstPrinter::PrintNewlineAndIndent() {
153 logger_->Print("\n");
154 for (intptr_t p = 0; p < indent_; ++p) {
155 logger_->Print(" ");
156 }
157 }
158
159
149 void AstPrinter::VisitLetNode(LetNode* node) { 160 void AstPrinter::VisitLetNode(LetNode* node) {
150 VisitGenericAstNode(node); 161 logger_->Print("(Let (");
162 // Indent the variables and initializers by two.
163 indent_ += 2;
164 for (intptr_t i = 0; i < node->num_temps(); ++i) {
165 if (i != 0) PrintNewlineAndIndent();
166 logger_->Print("(");
167 PrintLocalVariable(node->TempAt(i));
168 logger_->Print(" ");
169 node->InitializerAt(i)->Visit(this);
170 logger_->Print(")");
171 }
172 logger_->Print(")");
173
174 // Indent the body nodes by one.
175 --indent_;
176 for (intptr_t i = 0; i < node->nodes().length(); ++i) {
177 PrintNewlineAndIndent();
178 node->nodes()[i]->Visit(this);
179 }
180 logger_->Print(")");
181 --indent_;
151 } 182 }
152 183
153 184
154 void AstPrinter::VisitArrayNode(ArrayNode* node) { 185 void AstPrinter::VisitArrayNode(ArrayNode* node) {
155 VisitGenericAstNode(node); 186 VisitGenericAstNode(node);
156 } 187 }
157 188
158 189
159 void AstPrinter::VisitStringInterpolateNode(StringInterpolateNode* node) { 190 void AstPrinter::VisitStringInterpolateNode(StringInterpolateNode* node) {
160 VisitGenericAstNode(node); 191 VisitGenericAstNode(node);
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 const char* function_name = 565 const char* function_name =
535 parsed_function.function().ToFullyQualifiedCString(); 566 parsed_function.function().ToFullyQualifiedCString();
536 logger_->Print("Ast for function '%s' {\n", function_name); 567 logger_->Print("Ast for function '%s' {\n", function_name);
537 node_sequence->Visit(this); 568 node_sequence->Visit(this);
538 logger_->Print("}\n"); 569 logger_->Print("}\n");
539 } 570 }
540 571
541 } // namespace dart 572 } // namespace dart
542 573
543 #endif // !defined(PRODUCT) 574 #endif // !defined(PRODUCT)
OLDNEW
« 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