| OLD | NEW |
| 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" |
| 11 #include "vm/parser.h" | 11 #include "vm/parser.h" |
| 12 | 12 |
| 13 #if !defined(PRODUCT) | 13 #if !defined(PRODUCT) |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 AstPrinter::AstPrinter(bool log) | 17 AstPrinter::AstPrinter(bool log) |
| 18 : indent_(0), logger_(log ? Log::Current() : Log::NoOpLog()) {} | 18 : indent_(0), logger_(log ? Log::Current() : Log::NoOpLog()) {} |
| 19 | 19 |
| 20 | |
| 21 AstPrinter::~AstPrinter() {} | 20 AstPrinter::~AstPrinter() {} |
| 22 | 21 |
| 23 | |
| 24 void AstPrinter::VisitGenericAstNode(AstNode* node) { | 22 void AstPrinter::VisitGenericAstNode(AstNode* node) { |
| 25 logger_->Print("(%s ", node->Name()); | 23 logger_->Print("(%s ", node->Name()); |
| 26 node->VisitChildren(this); | 24 node->VisitChildren(this); |
| 27 logger_->Print(")"); | 25 logger_->Print(")"); |
| 28 } | 26 } |
| 29 | 27 |
| 30 | |
| 31 void AstPrinter::VisitSequenceNode(SequenceNode* node) { | 28 void AstPrinter::VisitSequenceNode(SequenceNode* node) { |
| 32 indent_++; | 29 indent_++; |
| 33 LocalScope* scope = node->scope(); | 30 LocalScope* scope = node->scope(); |
| 34 logger_->Print("(%s (scope \"%p\"", node->Name(), scope); | 31 logger_->Print("(%s (scope \"%p\"", node->Name(), scope); |
| 35 if (scope != NULL) { | 32 if (scope != NULL) { |
| 36 logger_->Print(" (%s-%s) loop %d", scope->begin_token_pos().ToCString(), | 33 logger_->Print(" (%s-%s) loop %d", scope->begin_token_pos().ToCString(), |
| 37 scope->end_token_pos().ToCString(), scope->loop_level()); | 34 scope->end_token_pos().ToCString(), scope->loop_level()); |
| 38 if (scope->HasContextLevel()) { | 35 if (scope->HasContextLevel()) { |
| 39 logger_->Print(" context %d captures %d", scope->context_level(), | 36 logger_->Print(" context %d captures %d", scope->context_level(), |
| 40 scope->num_context_variables()); | 37 scope->num_context_variables()); |
| 41 } else { | 38 } else { |
| 42 ASSERT(scope->num_context_variables() == 0); | 39 ASSERT(scope->num_context_variables() == 0); |
| 43 } | 40 } |
| 44 } | 41 } |
| 45 logger_->Print(")"); | 42 logger_->Print(")"); |
| 46 for (int i = 0; i < node->length(); ++i) { | 43 for (int i = 0; i < node->length(); ++i) { |
| 47 PrintNewlineAndIndent(); | 44 PrintNewlineAndIndent(); |
| 48 node->NodeAt(i)->Visit(this); | 45 node->NodeAt(i)->Visit(this); |
| 49 } | 46 } |
| 50 logger_->Print(")"); | 47 logger_->Print(")"); |
| 51 indent_--; | 48 indent_--; |
| 52 } | 49 } |
| 53 | 50 |
| 54 | |
| 55 void AstPrinter::VisitCloneContextNode(CloneContextNode* node) { | 51 void AstPrinter::VisitCloneContextNode(CloneContextNode* node) { |
| 56 VisitGenericAstNode(node); | 52 VisitGenericAstNode(node); |
| 57 } | 53 } |
| 58 | 54 |
| 59 | |
| 60 void AstPrinter::VisitArgumentListNode(ArgumentListNode* arguments) { | 55 void AstPrinter::VisitArgumentListNode(ArgumentListNode* arguments) { |
| 61 VisitGenericAstNode(arguments); | 56 VisitGenericAstNode(arguments); |
| 62 } | 57 } |
| 63 | 58 |
| 64 | |
| 65 void AstPrinter::VisitReturnNode(ReturnNode* node) { | 59 void AstPrinter::VisitReturnNode(ReturnNode* node) { |
| 66 const char* kind; | 60 const char* kind; |
| 67 switch (node->return_type()) { | 61 switch (node->return_type()) { |
| 68 case ReturnNode::kContinuation: | 62 case ReturnNode::kContinuation: |
| 69 kind = "continuation "; | 63 kind = "continuation "; |
| 70 break; | 64 break; |
| 71 case ReturnNode::kContinuationTarget: | 65 case ReturnNode::kContinuationTarget: |
| 72 kind = "continuation-target "; | 66 kind = "continuation-target "; |
| 73 break; | 67 break; |
| 74 case ReturnNode::kRegular: | 68 case ReturnNode::kRegular: |
| 75 kind = ""; | 69 kind = ""; |
| 76 break; | 70 break; |
| 77 default: | 71 default: |
| 78 kind = ""; | 72 kind = ""; |
| 79 UNREACHABLE(); | 73 UNREACHABLE(); |
| 80 } | 74 } |
| 81 logger_->Print("(%s %s", node->Name(), kind); | 75 logger_->Print("(%s %s", node->Name(), kind); |
| 82 node->VisitChildren(this); | 76 node->VisitChildren(this); |
| 83 logger_->Print(")"); | 77 logger_->Print(")"); |
| 84 } | 78 } |
| 85 | 79 |
| 86 | |
| 87 void AstPrinter::VisitGenericLocalNode(AstNode* node, | 80 void AstPrinter::VisitGenericLocalNode(AstNode* node, |
| 88 const LocalVariable& variable) { | 81 const LocalVariable& variable) { |
| 89 logger_->Print("(%s ", node->Name()); | 82 logger_->Print("(%s ", node->Name()); |
| 90 PrintLocalVariable(&variable); | 83 PrintLocalVariable(&variable); |
| 91 logger_->Print(" "); | 84 logger_->Print(" "); |
| 92 node->VisitChildren(this); | 85 node->VisitChildren(this); |
| 93 logger_->Print(")"); | 86 logger_->Print(")"); |
| 94 } | 87 } |
| 95 | 88 |
| 96 | |
| 97 void AstPrinter::VisitLoadLocalNode(LoadLocalNode* node) { | 89 void AstPrinter::VisitLoadLocalNode(LoadLocalNode* node) { |
| 98 VisitGenericLocalNode(node, node->local()); | 90 VisitGenericLocalNode(node, node->local()); |
| 99 } | 91 } |
| 100 | 92 |
| 101 | |
| 102 void AstPrinter::VisitStoreLocalNode(StoreLocalNode* node) { | 93 void AstPrinter::VisitStoreLocalNode(StoreLocalNode* node) { |
| 103 VisitGenericLocalNode(node, node->local()); | 94 VisitGenericLocalNode(node, node->local()); |
| 104 } | 95 } |
| 105 | 96 |
| 106 | |
| 107 void AstPrinter::VisitGenericFieldNode(AstNode* node, const Field& field) { | 97 void AstPrinter::VisitGenericFieldNode(AstNode* node, const Field& field) { |
| 108 logger_->Print( | 98 logger_->Print( |
| 109 "(%s %s%s \"%s\" ", node->Name(), field.is_final() ? "final " : "", | 99 "(%s %s%s \"%s\" ", node->Name(), field.is_final() ? "final " : "", |
| 110 String::Handle(AbstractType::Handle(field.type()).Name()).ToCString(), | 100 String::Handle(AbstractType::Handle(field.type()).Name()).ToCString(), |
| 111 String::Handle(field.name()).ToCString()); | 101 String::Handle(field.name()).ToCString()); |
| 112 node->VisitChildren(this); | 102 node->VisitChildren(this); |
| 113 logger_->Print(")"); | 103 logger_->Print(")"); |
| 114 } | 104 } |
| 115 | 105 |
| 116 | |
| 117 void AstPrinter::VisitLoadInstanceFieldNode(LoadInstanceFieldNode* node) { | 106 void AstPrinter::VisitLoadInstanceFieldNode(LoadInstanceFieldNode* node) { |
| 118 VisitGenericFieldNode(node, node->field()); | 107 VisitGenericFieldNode(node, node->field()); |
| 119 } | 108 } |
| 120 | 109 |
| 121 | |
| 122 void AstPrinter::VisitStoreInstanceFieldNode(StoreInstanceFieldNode* node) { | 110 void AstPrinter::VisitStoreInstanceFieldNode(StoreInstanceFieldNode* node) { |
| 123 VisitGenericFieldNode(node, Field::ZoneHandle(node->field().Original())); | 111 VisitGenericFieldNode(node, Field::ZoneHandle(node->field().Original())); |
| 124 } | 112 } |
| 125 | 113 |
| 126 | |
| 127 void AstPrinter::VisitLoadStaticFieldNode(LoadStaticFieldNode* node) { | 114 void AstPrinter::VisitLoadStaticFieldNode(LoadStaticFieldNode* node) { |
| 128 VisitGenericFieldNode(node, node->field()); | 115 VisitGenericFieldNode(node, node->field()); |
| 129 } | 116 } |
| 130 | 117 |
| 131 | |
| 132 void AstPrinter::VisitStoreStaticFieldNode(StoreStaticFieldNode* node) { | 118 void AstPrinter::VisitStoreStaticFieldNode(StoreStaticFieldNode* node) { |
| 133 VisitGenericFieldNode(node, node->field()); | 119 VisitGenericFieldNode(node, node->field()); |
| 134 } | 120 } |
| 135 | 121 |
| 136 | |
| 137 void AstPrinter::PrintLocalVariable(const LocalVariable* variable) { | 122 void AstPrinter::PrintLocalVariable(const LocalVariable* variable) { |
| 138 logger_->Print("%s%s \"%s\"", variable->is_final() ? "final " : "", | 123 logger_->Print("%s%s \"%s\"", variable->is_final() ? "final " : "", |
| 139 String::Handle(variable->type().Name()).ToCString(), | 124 String::Handle(variable->type().Name()).ToCString(), |
| 140 variable->name().ToCString()); | 125 variable->name().ToCString()); |
| 141 if (variable->HasIndex()) { | 126 if (variable->HasIndex()) { |
| 142 if (variable->is_captured()) { | 127 if (variable->is_captured()) { |
| 143 logger_->Print(" (context %d %d)", variable->owner()->context_level(), | 128 logger_->Print(" (context %d %d)", variable->owner()->context_level(), |
| 144 variable->index()); | 129 variable->index()); |
| 145 } else { | 130 } else { |
| 146 logger_->Print(" (stack %d)", variable->index()); | 131 logger_->Print(" (stack %d)", variable->index()); |
| 147 } | 132 } |
| 148 } | 133 } |
| 149 } | 134 } |
| 150 | 135 |
| 151 | |
| 152 void AstPrinter::PrintNewlineAndIndent() { | 136 void AstPrinter::PrintNewlineAndIndent() { |
| 153 logger_->Print("\n"); | 137 logger_->Print("\n"); |
| 154 for (intptr_t p = 0; p < indent_; ++p) { | 138 for (intptr_t p = 0; p < indent_; ++p) { |
| 155 logger_->Print(" "); | 139 logger_->Print(" "); |
| 156 } | 140 } |
| 157 } | 141 } |
| 158 | 142 |
| 159 | |
| 160 void AstPrinter::VisitLetNode(LetNode* node) { | 143 void AstPrinter::VisitLetNode(LetNode* node) { |
| 161 logger_->Print("(Let ("); | 144 logger_->Print("(Let ("); |
| 162 // Indent the variables and initializers by two. | 145 // Indent the variables and initializers by two. |
| 163 indent_ += 2; | 146 indent_ += 2; |
| 164 for (intptr_t i = 0; i < node->num_temps(); ++i) { | 147 for (intptr_t i = 0; i < node->num_temps(); ++i) { |
| 165 if (i != 0) PrintNewlineAndIndent(); | 148 if (i != 0) PrintNewlineAndIndent(); |
| 166 logger_->Print("("); | 149 logger_->Print("("); |
| 167 PrintLocalVariable(node->TempAt(i)); | 150 PrintLocalVariable(node->TempAt(i)); |
| 168 logger_->Print(" "); | 151 logger_->Print(" "); |
| 169 node->InitializerAt(i)->Visit(this); | 152 node->InitializerAt(i)->Visit(this); |
| 170 logger_->Print(")"); | 153 logger_->Print(")"); |
| 171 } | 154 } |
| 172 logger_->Print(")"); | 155 logger_->Print(")"); |
| 173 | 156 |
| 174 // Indent the body nodes by one. | 157 // Indent the body nodes by one. |
| 175 --indent_; | 158 --indent_; |
| 176 for (intptr_t i = 0; i < node->nodes().length(); ++i) { | 159 for (intptr_t i = 0; i < node->nodes().length(); ++i) { |
| 177 PrintNewlineAndIndent(); | 160 PrintNewlineAndIndent(); |
| 178 node->nodes()[i]->Visit(this); | 161 node->nodes()[i]->Visit(this); |
| 179 } | 162 } |
| 180 logger_->Print(")"); | 163 logger_->Print(")"); |
| 181 --indent_; | 164 --indent_; |
| 182 } | 165 } |
| 183 | 166 |
| 184 | |
| 185 void AstPrinter::VisitArrayNode(ArrayNode* node) { | 167 void AstPrinter::VisitArrayNode(ArrayNode* node) { |
| 186 VisitGenericAstNode(node); | 168 VisitGenericAstNode(node); |
| 187 } | 169 } |
| 188 | 170 |
| 189 | |
| 190 void AstPrinter::VisitStringInterpolateNode(StringInterpolateNode* node) { | 171 void AstPrinter::VisitStringInterpolateNode(StringInterpolateNode* node) { |
| 191 VisitGenericAstNode(node); | 172 VisitGenericAstNode(node); |
| 192 } | 173 } |
| 193 | 174 |
| 194 | |
| 195 void AstPrinter::VisitLiteralNode(LiteralNode* node) { | 175 void AstPrinter::VisitLiteralNode(LiteralNode* node) { |
| 196 const Instance& literal = node->literal(); | 176 const Instance& literal = node->literal(); |
| 197 logger_->Print("(%s \"%s\")", node->Name(), literal.ToCString()); | 177 logger_->Print("(%s \"%s\")", node->Name(), literal.ToCString()); |
| 198 } | 178 } |
| 199 | 179 |
| 200 | |
| 201 void AstPrinter::VisitTypeNode(TypeNode* node) { | 180 void AstPrinter::VisitTypeNode(TypeNode* node) { |
| 202 const AbstractType& type = node->type(); | 181 const AbstractType& type = node->type(); |
| 203 logger_->Print("(%s \"%s\")", node->Name(), | 182 logger_->Print("(%s \"%s\")", node->Name(), |
| 204 String::Handle(type.Name()).ToCString()); | 183 String::Handle(type.Name()).ToCString()); |
| 205 } | 184 } |
| 206 | 185 |
| 207 | |
| 208 void AstPrinter::VisitAssignableNode(AssignableNode* node) { | 186 void AstPrinter::VisitAssignableNode(AssignableNode* node) { |
| 209 const AbstractType& type = node->type(); | 187 const AbstractType& type = node->type(); |
| 210 const String& dst_name = node->dst_name(); | 188 const String& dst_name = node->dst_name(); |
| 211 logger_->Print("(%s (type \"%s\") (of \"%s\") ", node->Name(), | 189 logger_->Print("(%s (type \"%s\") (of \"%s\") ", node->Name(), |
| 212 String::Handle(type.Name()).ToCString(), dst_name.ToCString()); | 190 String::Handle(type.Name()).ToCString(), dst_name.ToCString()); |
| 213 node->VisitChildren(this); | 191 node->VisitChildren(this); |
| 214 logger_->Print(")"); | 192 logger_->Print(")"); |
| 215 } | 193 } |
| 216 | 194 |
| 217 | |
| 218 void AstPrinter::VisitAwaitNode(AwaitNode* node) { | 195 void AstPrinter::VisitAwaitNode(AwaitNode* node) { |
| 219 logger_->Print("(*****%s***** (scope \"%p\") ", node->Name(), node->scope()); | 196 logger_->Print("(*****%s***** (scope \"%p\") ", node->Name(), node->scope()); |
| 220 node->VisitChildren(this); | 197 node->VisitChildren(this); |
| 221 logger_->Print(")"); | 198 logger_->Print(")"); |
| 222 } | 199 } |
| 223 | 200 |
| 224 | |
| 225 void AstPrinter::VisitAwaitMarkerNode(AwaitMarkerNode* node) { | 201 void AstPrinter::VisitAwaitMarkerNode(AwaitMarkerNode* node) { |
| 226 logger_->Print("(%s (async_scope \"%p\" await_scope \"%p\"))", node->Name(), | 202 logger_->Print("(%s (async_scope \"%p\" await_scope \"%p\"))", node->Name(), |
| 227 node->async_scope(), node->await_scope()); | 203 node->async_scope(), node->await_scope()); |
| 228 } | 204 } |
| 229 | 205 |
| 230 | |
| 231 void AstPrinter::VisitPrimaryNode(PrimaryNode* node) { | 206 void AstPrinter::VisitPrimaryNode(PrimaryNode* node) { |
| 232 logger_->Print("(*****%s***** \"%s\")", node->Name(), | 207 logger_->Print("(*****%s***** \"%s\")", node->Name(), |
| 233 node->primary().ToCString()); | 208 node->primary().ToCString()); |
| 234 } | 209 } |
| 235 | 210 |
| 236 | |
| 237 void AstPrinter::VisitComparisonNode(ComparisonNode* node) { | 211 void AstPrinter::VisitComparisonNode(ComparisonNode* node) { |
| 238 logger_->Print("(%s %s ", node->Name(), node->TokenName()); | 212 logger_->Print("(%s %s ", node->Name(), node->TokenName()); |
| 239 node->VisitChildren(this); | 213 node->VisitChildren(this); |
| 240 logger_->Print(")"); | 214 logger_->Print(")"); |
| 241 } | 215 } |
| 242 | 216 |
| 243 | |
| 244 void AstPrinter::VisitBinaryOpNode(BinaryOpNode* node) { | 217 void AstPrinter::VisitBinaryOpNode(BinaryOpNode* node) { |
| 245 logger_->Print("(%s %s ", node->Name(), node->TokenName()); | 218 logger_->Print("(%s %s ", node->Name(), node->TokenName()); |
| 246 node->VisitChildren(this); | 219 node->VisitChildren(this); |
| 247 logger_->Print(")"); | 220 logger_->Print(")"); |
| 248 } | 221 } |
| 249 | 222 |
| 250 | |
| 251 void AstPrinter::VisitUnaryOpNode(UnaryOpNode* node) { | 223 void AstPrinter::VisitUnaryOpNode(UnaryOpNode* node) { |
| 252 logger_->Print("(%s %s ", node->Name(), node->TokenName()); | 224 logger_->Print("(%s %s ", node->Name(), node->TokenName()); |
| 253 node->VisitChildren(this); | 225 node->VisitChildren(this); |
| 254 logger_->Print(")"); | 226 logger_->Print(")"); |
| 255 } | 227 } |
| 256 | 228 |
| 257 | |
| 258 void AstPrinter::VisitConditionalExprNode(ConditionalExprNode* node) { | 229 void AstPrinter::VisitConditionalExprNode(ConditionalExprNode* node) { |
| 259 VisitGenericAstNode(node); | 230 VisitGenericAstNode(node); |
| 260 } | 231 } |
| 261 | 232 |
| 262 | |
| 263 void AstPrinter::VisitIfNode(IfNode* node) { | 233 void AstPrinter::VisitIfNode(IfNode* node) { |
| 264 VisitGenericAstNode(node); | 234 VisitGenericAstNode(node); |
| 265 } | 235 } |
| 266 | 236 |
| 267 | |
| 268 void AstPrinter::VisitCaseNode(CaseNode* node) { | 237 void AstPrinter::VisitCaseNode(CaseNode* node) { |
| 269 logger_->Print("(%s (", node->Name()); | 238 logger_->Print("(%s (", node->Name()); |
| 270 for (int i = 0; i < node->case_expressions()->length(); i++) { | 239 for (int i = 0; i < node->case_expressions()->length(); i++) { |
| 271 node->case_expressions()->NodeAt(i)->Visit(this); | 240 node->case_expressions()->NodeAt(i)->Visit(this); |
| 272 } | 241 } |
| 273 if (node->contains_default()) { | 242 if (node->contains_default()) { |
| 274 logger_->Print(" default"); | 243 logger_->Print(" default"); |
| 275 } | 244 } |
| 276 logger_->Print(")"); | 245 logger_->Print(")"); |
| 277 node->statements()->Visit(this); | 246 node->statements()->Visit(this); |
| 278 logger_->Print(")"); | 247 logger_->Print(")"); |
| 279 } | 248 } |
| 280 | 249 |
| 281 | |
| 282 void AstPrinter::VisitSwitchNode(SwitchNode* node) { | 250 void AstPrinter::VisitSwitchNode(SwitchNode* node) { |
| 283 VisitGenericAstNode(node); | 251 VisitGenericAstNode(node); |
| 284 } | 252 } |
| 285 | 253 |
| 286 | |
| 287 void AstPrinter::VisitWhileNode(WhileNode* node) { | 254 void AstPrinter::VisitWhileNode(WhileNode* node) { |
| 288 VisitGenericAstNode(node); | 255 VisitGenericAstNode(node); |
| 289 } | 256 } |
| 290 | 257 |
| 291 | |
| 292 void AstPrinter::VisitForNode(ForNode* node) { | 258 void AstPrinter::VisitForNode(ForNode* node) { |
| 293 // Complicated because the condition is optional and so we clearly want to | 259 // Complicated because the condition is optional and so we clearly want to |
| 294 // indicate the subparts. | 260 // indicate the subparts. |
| 295 logger_->Print("(%s (init ", node->Name()); | 261 logger_->Print("(%s (init ", node->Name()); |
| 296 node->initializer()->Visit(this); | 262 node->initializer()->Visit(this); |
| 297 if (node->condition() != NULL) { | 263 if (node->condition() != NULL) { |
| 298 logger_->Print(") (cond "); | 264 logger_->Print(") (cond "); |
| 299 node->condition()->Visit(this); | 265 node->condition()->Visit(this); |
| 300 } | 266 } |
| 301 logger_->Print(") (update "); | 267 logger_->Print(") (update "); |
| 302 node->increment()->Visit(this); | 268 node->increment()->Visit(this); |
| 303 logger_->Print(") "); | 269 logger_->Print(") "); |
| 304 node->body()->Visit(this); | 270 node->body()->Visit(this); |
| 305 logger_->Print(")"); | 271 logger_->Print(")"); |
| 306 } | 272 } |
| 307 | 273 |
| 308 | |
| 309 void AstPrinter::VisitDoWhileNode(DoWhileNode* node) { | 274 void AstPrinter::VisitDoWhileNode(DoWhileNode* node) { |
| 310 VisitGenericAstNode(node); | 275 VisitGenericAstNode(node); |
| 311 } | 276 } |
| 312 | 277 |
| 313 | |
| 314 void AstPrinter::VisitJumpNode(JumpNode* node) { | 278 void AstPrinter::VisitJumpNode(JumpNode* node) { |
| 315 logger_->Print("(%s %s %s (scope \"%p\"))", node->Name(), node->TokenName(), | 279 logger_->Print("(%s %s %s (scope \"%p\"))", node->Name(), node->TokenName(), |
| 316 node->label()->name().ToCString(), node->label()->owner()); | 280 node->label()->name().ToCString(), node->label()->owner()); |
| 317 } | 281 } |
| 318 | 282 |
| 319 | |
| 320 void AstPrinter::VisitInstanceCallNode(InstanceCallNode* node) { | 283 void AstPrinter::VisitInstanceCallNode(InstanceCallNode* node) { |
| 321 logger_->Print("(%s \"%s\" ", node->Name(), | 284 logger_->Print("(%s \"%s\" ", node->Name(), |
| 322 node->function_name().ToCString()); | 285 node->function_name().ToCString()); |
| 323 node->VisitChildren(this); | 286 node->VisitChildren(this); |
| 324 logger_->Print(")"); | 287 logger_->Print(")"); |
| 325 } | 288 } |
| 326 | 289 |
| 327 | |
| 328 void AstPrinter::VisitStaticCallNode(StaticCallNode* node) { | 290 void AstPrinter::VisitStaticCallNode(StaticCallNode* node) { |
| 329 const char* function_fullname = node->function().ToFullyQualifiedCString(); | 291 const char* function_fullname = node->function().ToFullyQualifiedCString(); |
| 330 logger_->Print("(%s \"%s\" ", node->Name(), function_fullname); | 292 logger_->Print("(%s \"%s\" ", node->Name(), function_fullname); |
| 331 node->VisitChildren(this); | 293 node->VisitChildren(this); |
| 332 logger_->Print(")"); | 294 logger_->Print(")"); |
| 333 } | 295 } |
| 334 | 296 |
| 335 | |
| 336 void AstPrinter::VisitClosureNode(ClosureNode* node) { | 297 void AstPrinter::VisitClosureNode(ClosureNode* node) { |
| 337 const char* function_fullname = node->function().ToFullyQualifiedCString(); | 298 const char* function_fullname = node->function().ToFullyQualifiedCString(); |
| 338 logger_->Print("(%s \"%s\")", node->Name(), function_fullname); | 299 logger_->Print("(%s \"%s\")", node->Name(), function_fullname); |
| 339 } | 300 } |
| 340 | 301 |
| 341 | |
| 342 void AstPrinter::VisitClosureCallNode(ClosureCallNode* node) { | 302 void AstPrinter::VisitClosureCallNode(ClosureCallNode* node) { |
| 343 VisitGenericAstNode(node); | 303 VisitGenericAstNode(node); |
| 344 } | 304 } |
| 345 | 305 |
| 346 | |
| 347 void AstPrinter::VisitConstructorCallNode(ConstructorCallNode* node) { | 306 void AstPrinter::VisitConstructorCallNode(ConstructorCallNode* node) { |
| 348 const char* kind = node->constructor().IsFactory() ? "factory " : ""; | 307 const char* kind = node->constructor().IsFactory() ? "factory " : ""; |
| 349 const char* constructor_name = node->constructor().ToFullyQualifiedCString(); | 308 const char* constructor_name = node->constructor().ToFullyQualifiedCString(); |
| 350 logger_->Print("(%s %s \"%s\" ", node->Name(), kind, constructor_name); | 309 logger_->Print("(%s %s \"%s\" ", node->Name(), kind, constructor_name); |
| 351 node->VisitChildren(this); | 310 node->VisitChildren(this); |
| 352 logger_->Print(")"); | 311 logger_->Print(")"); |
| 353 } | 312 } |
| 354 | 313 |
| 355 | |
| 356 void AstPrinter::VisitInstanceGetterNode(InstanceGetterNode* node) { | 314 void AstPrinter::VisitInstanceGetterNode(InstanceGetterNode* node) { |
| 357 logger_->Print("(%s \"%s\" ", node->Name(), node->field_name().ToCString()); | 315 logger_->Print("(%s \"%s\" ", node->Name(), node->field_name().ToCString()); |
| 358 node->VisitChildren(this); | 316 node->VisitChildren(this); |
| 359 logger_->Print(")"); | 317 logger_->Print(")"); |
| 360 } | 318 } |
| 361 | 319 |
| 362 | |
| 363 void AstPrinter::VisitInstanceSetterNode(InstanceSetterNode* node) { | 320 void AstPrinter::VisitInstanceSetterNode(InstanceSetterNode* node) { |
| 364 logger_->Print("(%s \"%s\" ", node->Name(), node->field_name().ToCString()); | 321 logger_->Print("(%s \"%s\" ", node->Name(), node->field_name().ToCString()); |
| 365 node->VisitChildren(this); | 322 node->VisitChildren(this); |
| 366 logger_->Print(")"); | 323 logger_->Print(")"); |
| 367 } | 324 } |
| 368 | 325 |
| 369 | |
| 370 void AstPrinter::VisitInitStaticFieldNode(InitStaticFieldNode* node) { | 326 void AstPrinter::VisitInitStaticFieldNode(InitStaticFieldNode* node) { |
| 371 logger_->Print("(%s \"%s\")", node->Name(), | 327 logger_->Print("(%s \"%s\")", node->Name(), |
| 372 String::Handle(node->field().name()).ToCString()); | 328 String::Handle(node->field().name()).ToCString()); |
| 373 } | 329 } |
| 374 | 330 |
| 375 | |
| 376 void AstPrinter::VisitStaticGetterNode(StaticGetterNode* node) { | 331 void AstPrinter::VisitStaticGetterNode(StaticGetterNode* node) { |
| 377 String& class_name = String::Handle(node->cls().Name()); | 332 String& class_name = String::Handle(node->cls().Name()); |
| 378 logger_->Print("(%s \"%s.%s\")", node->Name(), class_name.ToCString(), | 333 logger_->Print("(%s \"%s.%s\")", node->Name(), class_name.ToCString(), |
| 379 node->field_name().ToCString()); | 334 node->field_name().ToCString()); |
| 380 } | 335 } |
| 381 | 336 |
| 382 | |
| 383 void AstPrinter::VisitStaticSetterNode(StaticSetterNode* node) { | 337 void AstPrinter::VisitStaticSetterNode(StaticSetterNode* node) { |
| 384 String& class_name = String::Handle(node->cls().Name()); | 338 String& class_name = String::Handle(node->cls().Name()); |
| 385 logger_->Print("(%s \"%s.%s\" ", node->Name(), class_name.ToCString(), | 339 logger_->Print("(%s \"%s.%s\" ", node->Name(), class_name.ToCString(), |
| 386 node->field_name().ToCString()); | 340 node->field_name().ToCString()); |
| 387 node->VisitChildren(this); | 341 node->VisitChildren(this); |
| 388 logger_->Print(")"); | 342 logger_->Print(")"); |
| 389 } | 343 } |
| 390 | 344 |
| 391 | |
| 392 void AstPrinter::VisitLoadIndexedNode(LoadIndexedNode* node) { | 345 void AstPrinter::VisitLoadIndexedNode(LoadIndexedNode* node) { |
| 393 logger_->Print("(%s%s ", node->Name(), node->IsSuperLoad() ? " super" : ""); | 346 logger_->Print("(%s%s ", node->Name(), node->IsSuperLoad() ? " super" : ""); |
| 394 node->VisitChildren(this); | 347 node->VisitChildren(this); |
| 395 logger_->Print(")"); | 348 logger_->Print(")"); |
| 396 } | 349 } |
| 397 | 350 |
| 398 | |
| 399 void AstPrinter::VisitStoreIndexedNode(StoreIndexedNode* node) { | 351 void AstPrinter::VisitStoreIndexedNode(StoreIndexedNode* node) { |
| 400 logger_->Print("(%s%s ", node->Name(), node->IsSuperStore() ? " super" : ""); | 352 logger_->Print("(%s%s ", node->Name(), node->IsSuperStore() ? " super" : ""); |
| 401 node->VisitChildren(this); | 353 node->VisitChildren(this); |
| 402 logger_->Print(")"); | 354 logger_->Print(")"); |
| 403 } | 355 } |
| 404 | 356 |
| 405 | |
| 406 void AstPrinter::VisitNativeBodyNode(NativeBodyNode* node) { | 357 void AstPrinter::VisitNativeBodyNode(NativeBodyNode* node) { |
| 407 logger_->Print( | 358 logger_->Print( |
| 408 "(%s \"%s\" (%" Pd " args))", node->Name(), | 359 "(%s \"%s\" (%" Pd " args))", node->Name(), |
| 409 node->native_c_function_name().ToCString(), | 360 node->native_c_function_name().ToCString(), |
| 410 NativeArguments::ParameterCountForResolution(node->function())); | 361 NativeArguments::ParameterCountForResolution(node->function())); |
| 411 } | 362 } |
| 412 | 363 |
| 413 | |
| 414 void AstPrinter::VisitCatchClauseNode(CatchClauseNode* node) { | 364 void AstPrinter::VisitCatchClauseNode(CatchClauseNode* node) { |
| 415 VisitGenericAstNode(node); | 365 VisitGenericAstNode(node); |
| 416 } | 366 } |
| 417 | 367 |
| 418 | |
| 419 void AstPrinter::VisitTryCatchNode(TryCatchNode* node) { | 368 void AstPrinter::VisitTryCatchNode(TryCatchNode* node) { |
| 420 logger_->Print("(%s ", node->Name()); | 369 logger_->Print("(%s ", node->Name()); |
| 421 node->try_block()->Visit(this); | 370 node->try_block()->Visit(this); |
| 422 node->catch_block()->Visit(this); | 371 node->catch_block()->Visit(this); |
| 423 if (node->finally_block() != NULL) { | 372 if (node->finally_block() != NULL) { |
| 424 logger_->Print("(finally "); | 373 logger_->Print("(finally "); |
| 425 node->finally_block()->Visit(this); | 374 node->finally_block()->Visit(this); |
| 426 logger_->Print(")"); | 375 logger_->Print(")"); |
| 427 } | 376 } |
| 428 logger_->Print(")"); | 377 logger_->Print(")"); |
| 429 } | 378 } |
| 430 | 379 |
| 431 | |
| 432 void AstPrinter::VisitThrowNode(ThrowNode* node) { | 380 void AstPrinter::VisitThrowNode(ThrowNode* node) { |
| 433 VisitGenericAstNode(node); | 381 VisitGenericAstNode(node); |
| 434 } | 382 } |
| 435 | 383 |
| 436 | |
| 437 void AstPrinter::VisitStopNode(StopNode* node) { | 384 void AstPrinter::VisitStopNode(StopNode* node) { |
| 438 logger_->Print("(%s %s)", node->Name(), node->message()); | 385 logger_->Print("(%s %s)", node->Name(), node->message()); |
| 439 } | 386 } |
| 440 | 387 |
| 441 | |
| 442 void AstPrinter::VisitInlinedFinallyNode(InlinedFinallyNode* node) { | 388 void AstPrinter::VisitInlinedFinallyNode(InlinedFinallyNode* node) { |
| 443 VisitGenericAstNode(node); | 389 VisitGenericAstNode(node); |
| 444 } | 390 } |
| 445 | 391 |
| 446 | |
| 447 void AstPrinter::PrintNode(AstNode* node) { | 392 void AstPrinter::PrintNode(AstNode* node) { |
| 448 ASSERT(node != NULL); | 393 ASSERT(node != NULL); |
| 449 AstPrinter ast_printer; | 394 AstPrinter ast_printer; |
| 450 node->Visit(&ast_printer); | 395 node->Visit(&ast_printer); |
| 451 logger_->Print("\n"); | 396 logger_->Print("\n"); |
| 452 } | 397 } |
| 453 | 398 |
| 454 | |
| 455 void AstPrinter::IndentN(int count) { | 399 void AstPrinter::IndentN(int count) { |
| 456 for (int i = 0; i < count; i++) { | 400 for (int i = 0; i < count; i++) { |
| 457 logger_->Print(" "); | 401 logger_->Print(" "); |
| 458 } | 402 } |
| 459 } | 403 } |
| 460 | 404 |
| 461 | |
| 462 void AstPrinter::PrintLocalScopeVariable(const LocalScope* scope, | 405 void AstPrinter::PrintLocalScopeVariable(const LocalScope* scope, |
| 463 LocalVariable* var, | 406 LocalVariable* var, |
| 464 int indent) { | 407 int indent) { |
| 465 ASSERT(scope != NULL); | 408 ASSERT(scope != NULL); |
| 466 ASSERT(var != NULL); | 409 ASSERT(var != NULL); |
| 467 IndentN(indent); | 410 IndentN(indent); |
| 468 logger_->Print("(%s%s '%s'", var->is_final() ? "final " : "", | 411 logger_->Print("(%s%s '%s'", var->is_final() ? "final " : "", |
| 469 String::Handle(var->type().Name()).ToCString(), | 412 String::Handle(var->type().Name()).ToCString(), |
| 470 var->name().ToCString()); | 413 var->name().ToCString()); |
| 471 if (var->owner() != scope) { | 414 if (var->owner() != scope) { |
| 472 logger_->Print(" alias"); | 415 logger_->Print(" alias"); |
| 473 } | 416 } |
| 474 if (var->HasIndex()) { | 417 if (var->HasIndex()) { |
| 475 logger_->Print(" @%d", var->index()); | 418 logger_->Print(" @%d", var->index()); |
| 476 if (var->is_captured()) { | 419 if (var->is_captured()) { |
| 477 logger_->Print(" ctx %d", var->owner()->context_level()); | 420 logger_->Print(" ctx %d", var->owner()->context_level()); |
| 478 } | 421 } |
| 479 } else if (var->owner()->function_level() != 0) { | 422 } else if (var->owner()->function_level() != 0) { |
| 480 logger_->Print(" lev %d", var->owner()->function_level()); | 423 logger_->Print(" lev %d", var->owner()->function_level()); |
| 481 } | 424 } |
| 482 logger_->Print(" valid %s-%s)\n", var->token_pos().ToCString(), | 425 logger_->Print(" valid %s-%s)\n", var->token_pos().ToCString(), |
| 483 scope->end_token_pos().ToCString()); | 426 scope->end_token_pos().ToCString()); |
| 484 } | 427 } |
| 485 | 428 |
| 486 | |
| 487 void AstPrinter::PrintLocalScope(const LocalScope* scope, | 429 void AstPrinter::PrintLocalScope(const LocalScope* scope, |
| 488 int start_index, | 430 int start_index, |
| 489 int indent) { | 431 int indent) { |
| 490 ASSERT(scope != NULL); | 432 ASSERT(scope != NULL); |
| 491 for (int i = start_index; i < scope->num_variables(); i++) { | 433 for (int i = start_index; i < scope->num_variables(); i++) { |
| 492 LocalVariable* var = scope->VariableAt(i); | 434 LocalVariable* var = scope->VariableAt(i); |
| 493 PrintLocalScopeVariable(scope, var, indent); | 435 PrintLocalScopeVariable(scope, var, indent); |
| 494 } | 436 } |
| 495 const LocalScope* child = scope->child(); | 437 const LocalScope* child = scope->child(); |
| 496 while (child != NULL) { | 438 while (child != NULL) { |
| 497 IndentN(indent); | 439 IndentN(indent); |
| 498 logger_->Print("{scope %p ", child); | 440 logger_->Print("{scope %p ", child); |
| 499 if (child->HasContextLevel()) { | 441 if (child->HasContextLevel()) { |
| 500 logger_->Print("ctx %d numctxvar %d ", child->context_level(), | 442 logger_->Print("ctx %d numctxvar %d ", child->context_level(), |
| 501 child->num_context_variables()); | 443 child->num_context_variables()); |
| 502 } | 444 } |
| 503 logger_->Print("llev %d\n", child->loop_level()); | 445 logger_->Print("llev %d\n", child->loop_level()); |
| 504 PrintLocalScope(child, 0, indent + kScopeIndent); | 446 PrintLocalScope(child, 0, indent + kScopeIndent); |
| 505 IndentN(indent); | 447 IndentN(indent); |
| 506 logger_->Print("}\n"); | 448 logger_->Print("}\n"); |
| 507 child = child->sibling(); | 449 child = child->sibling(); |
| 508 } | 450 } |
| 509 } | 451 } |
| 510 | 452 |
| 511 | |
| 512 void AstPrinter::PrintFunctionScope(const ParsedFunction& parsed_function) { | 453 void AstPrinter::PrintFunctionScope(const ParsedFunction& parsed_function) { |
| 513 HANDLESCOPE(parsed_function.thread()); | 454 HANDLESCOPE(parsed_function.thread()); |
| 514 const Function& function = parsed_function.function(); | 455 const Function& function = parsed_function.function(); |
| 515 SequenceNode* node_sequence = parsed_function.node_sequence(); | 456 SequenceNode* node_sequence = parsed_function.node_sequence(); |
| 516 ASSERT(node_sequence != NULL); | 457 ASSERT(node_sequence != NULL); |
| 517 const LocalScope* scope = node_sequence->scope(); | 458 const LocalScope* scope = node_sequence->scope(); |
| 518 ASSERT(scope != NULL); | 459 ASSERT(scope != NULL); |
| 519 const char* function_name = function.ToFullyQualifiedCString(); | 460 const char* function_name = function.ToFullyQualifiedCString(); |
| 520 logger_->Print("Scope for function '%s'\n{scope %p ", function_name, scope); | 461 logger_->Print("Scope for function '%s'\n{scope %p ", function_name, scope); |
| 521 if (scope->HasContextLevel()) { | 462 if (scope->HasContextLevel()) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 550 } | 491 } |
| 551 logger_->Print(" valid %s-%s)\n", param->token_pos().ToCString(), | 492 logger_->Print(" valid %s-%s)\n", param->token_pos().ToCString(), |
| 552 scope->end_token_pos().ToCString()); | 493 scope->end_token_pos().ToCString()); |
| 553 pos++; | 494 pos++; |
| 554 } | 495 } |
| 555 // Visit remaining non-parameter variables and children scopes. | 496 // Visit remaining non-parameter variables and children scopes. |
| 556 PrintLocalScope(scope, pos, indent); | 497 PrintLocalScope(scope, pos, indent); |
| 557 logger_->Print("}\n"); | 498 logger_->Print("}\n"); |
| 558 } | 499 } |
| 559 | 500 |
| 560 | |
| 561 void AstPrinter::PrintFunctionNodes(const ParsedFunction& parsed_function) { | 501 void AstPrinter::PrintFunctionNodes(const ParsedFunction& parsed_function) { |
| 562 HANDLESCOPE(parsed_function.thread()); | 502 HANDLESCOPE(parsed_function.thread()); |
| 563 SequenceNode* node_sequence = parsed_function.node_sequence(); | 503 SequenceNode* node_sequence = parsed_function.node_sequence(); |
| 564 ASSERT(node_sequence != NULL); | 504 ASSERT(node_sequence != NULL); |
| 565 const char* function_name = | 505 const char* function_name = |
| 566 parsed_function.function().ToFullyQualifiedCString(); | 506 parsed_function.function().ToFullyQualifiedCString(); |
| 567 logger_->Print("Ast for function '%s' {\n", function_name); | 507 logger_->Print("Ast for function '%s' {\n", function_name); |
| 568 node_sequence->Visit(this); | 508 node_sequence->Visit(this); |
| 569 logger_->Print("}\n"); | 509 logger_->Print("}\n"); |
| 570 } | 510 } |
| 571 | 511 |
| 572 } // namespace dart | 512 } // namespace dart |
| 573 | 513 |
| 574 #endif // !defined(PRODUCT) | 514 #endif // !defined(PRODUCT) |
| OLD | NEW |