| 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), | 18 : indent_(0), logger_(log ? Log::Current() : Log::NoOpLog()) {} |
| 19 logger_(log ? Log::Current() : Log::NoOpLog()) { } | |
| 20 | 19 |
| 21 | 20 |
| 22 AstPrinter::~AstPrinter() { } | 21 AstPrinter::~AstPrinter() {} |
| 23 | 22 |
| 24 | 23 |
| 25 void AstPrinter::VisitGenericAstNode(AstNode* node) { | 24 void AstPrinter::VisitGenericAstNode(AstNode* node) { |
| 26 logger_->Print("(%s ", node->Name()); | 25 logger_->Print("(%s ", node->Name()); |
| 27 node->VisitChildren(this); | 26 node->VisitChildren(this); |
| 28 logger_->Print(")"); | 27 logger_->Print(")"); |
| 29 } | 28 } |
| 30 | 29 |
| 31 | 30 |
| 32 void AstPrinter::VisitSequenceNode(SequenceNode* node) { | 31 void AstPrinter::VisitSequenceNode(SequenceNode* node) { |
| 33 indent_++; | 32 indent_++; |
| 34 LocalScope* scope = node->scope(); | 33 LocalScope* scope = node->scope(); |
| 35 logger_->Print("(%s (scope \"%p\"", node->Name(), scope); | 34 logger_->Print("(%s (scope \"%p\"", node->Name(), scope); |
| 36 if (scope != NULL) { | 35 if (scope != NULL) { |
| 37 logger_->Print(" (%s-%s) loop %d", | 36 logger_->Print(" (%s-%s) loop %d", scope->begin_token_pos().ToCString(), |
| 38 scope->begin_token_pos().ToCString(), | 37 scope->end_token_pos().ToCString(), scope->loop_level()); |
| 39 scope->end_token_pos().ToCString(), | |
| 40 scope->loop_level()); | |
| 41 if (scope->HasContextLevel()) { | 38 if (scope->HasContextLevel()) { |
| 42 logger_->Print(" context %d captures %d", | 39 logger_->Print(" context %d captures %d", scope->context_level(), |
| 43 scope->context_level(), | 40 scope->num_context_variables()); |
| 44 scope->num_context_variables()); | |
| 45 } else { | 41 } else { |
| 46 ASSERT(scope->num_context_variables() == 0); | 42 ASSERT(scope->num_context_variables() == 0); |
| 47 } | 43 } |
| 48 } | 44 } |
| 49 logger_->Print(")"); | 45 logger_->Print(")"); |
| 50 for (int i = 0; i < node->length(); ++i) { | 46 for (int i = 0; i < node->length(); ++i) { |
| 51 logger_->Print("\n"); | 47 logger_->Print("\n"); |
| 52 for (intptr_t p = 0; p < indent_; p++) { | 48 for (intptr_t p = 0; p < indent_; p++) { |
| 53 logger_->Print(" "); | 49 logger_->Print(" "); |
| 54 } | 50 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 UNREACHABLE(); | 82 UNREACHABLE(); |
| 87 } | 83 } |
| 88 logger_->Print("(%s %s", node->Name(), kind); | 84 logger_->Print("(%s %s", node->Name(), kind); |
| 89 node->VisitChildren(this); | 85 node->VisitChildren(this); |
| 90 logger_->Print(")"); | 86 logger_->Print(")"); |
| 91 } | 87 } |
| 92 | 88 |
| 93 | 89 |
| 94 void AstPrinter::VisitGenericLocalNode(AstNode* node, | 90 void AstPrinter::VisitGenericLocalNode(AstNode* node, |
| 95 const LocalVariable& var) { | 91 const LocalVariable& var) { |
| 96 logger_->Print("(%s %s%s \"%s\"", | 92 logger_->Print( |
| 97 node->Name(), | 93 "(%s %s%s \"%s\"", node->Name(), var.is_final() ? "final " : "", |
| 98 var.is_final() ? "final " : "", | 94 String::Handle(var.type().Name()).ToCString(), var.name().ToCString()); |
| 99 String::Handle(var.type().Name()).ToCString(), | |
| 100 var.name().ToCString()); | |
| 101 if (var.HasIndex()) { | 95 if (var.HasIndex()) { |
| 102 if (var.is_captured()) { | 96 if (var.is_captured()) { |
| 103 logger_->Print(" (context %d %d)", | 97 logger_->Print(" (context %d %d)", var.owner()->context_level(), |
| 104 var.owner()->context_level(), | |
| 105 var.index()); | 98 var.index()); |
| 106 } else { | 99 } else { |
| 107 logger_->Print(" (stack %d)", var.index()); | 100 logger_->Print(" (stack %d)", var.index()); |
| 108 } | 101 } |
| 109 } | 102 } |
| 110 logger_->Print(" "); | 103 logger_->Print(" "); |
| 111 node->VisitChildren(this); | 104 node->VisitChildren(this); |
| 112 logger_->Print(")"); | 105 logger_->Print(")"); |
| 113 } | 106 } |
| 114 | 107 |
| 115 | 108 |
| 116 void AstPrinter::VisitLoadLocalNode(LoadLocalNode* node) { | 109 void AstPrinter::VisitLoadLocalNode(LoadLocalNode* node) { |
| 117 VisitGenericLocalNode(node, node->local()); | 110 VisitGenericLocalNode(node, node->local()); |
| 118 } | 111 } |
| 119 | 112 |
| 120 | 113 |
| 121 void AstPrinter::VisitStoreLocalNode(StoreLocalNode* node) { | 114 void AstPrinter::VisitStoreLocalNode(StoreLocalNode* node) { |
| 122 VisitGenericLocalNode(node, node->local()); | 115 VisitGenericLocalNode(node, node->local()); |
| 123 } | 116 } |
| 124 | 117 |
| 125 | 118 |
| 126 void AstPrinter::VisitGenericFieldNode(AstNode* node, const Field& field) { | 119 void AstPrinter::VisitGenericFieldNode(AstNode* node, const Field& field) { |
| 127 logger_->Print("(%s %s%s \"%s\" ", | 120 logger_->Print( |
| 128 node->Name(), | 121 "(%s %s%s \"%s\" ", node->Name(), field.is_final() ? "final " : "", |
| 129 field.is_final() ? "final " : "", | 122 String::Handle(AbstractType::Handle(field.type()).Name()).ToCString(), |
| 130 String::Handle(AbstractType::Handle(field.type()).Name()). | 123 String::Handle(field.name()).ToCString()); |
| 131 ToCString(), | |
| 132 String::Handle(field.name()).ToCString()); | |
| 133 node->VisitChildren(this); | 124 node->VisitChildren(this); |
| 134 logger_->Print(")"); | 125 logger_->Print(")"); |
| 135 } | 126 } |
| 136 | 127 |
| 137 | 128 |
| 138 void AstPrinter::VisitLoadInstanceFieldNode(LoadInstanceFieldNode* node) { | 129 void AstPrinter::VisitLoadInstanceFieldNode(LoadInstanceFieldNode* node) { |
| 139 VisitGenericFieldNode(node, node->field()); | 130 VisitGenericFieldNode(node, node->field()); |
| 140 } | 131 } |
| 141 | 132 |
| 142 | 133 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 171 | 162 |
| 172 | 163 |
| 173 void AstPrinter::VisitLiteralNode(LiteralNode* node) { | 164 void AstPrinter::VisitLiteralNode(LiteralNode* node) { |
| 174 const Instance& literal = node->literal(); | 165 const Instance& literal = node->literal(); |
| 175 logger_->Print("(%s \"%s\")", node->Name(), literal.ToCString()); | 166 logger_->Print("(%s \"%s\")", node->Name(), literal.ToCString()); |
| 176 } | 167 } |
| 177 | 168 |
| 178 | 169 |
| 179 void AstPrinter::VisitTypeNode(TypeNode* node) { | 170 void AstPrinter::VisitTypeNode(TypeNode* node) { |
| 180 const AbstractType& type = node->type(); | 171 const AbstractType& type = node->type(); |
| 181 logger_->Print("(%s \"%s\")", | 172 logger_->Print("(%s \"%s\")", node->Name(), |
| 182 node->Name(), | 173 String::Handle(type.Name()).ToCString()); |
| 183 String::Handle(type.Name()).ToCString()); | |
| 184 } | 174 } |
| 185 | 175 |
| 186 | 176 |
| 187 void AstPrinter::VisitAssignableNode(AssignableNode* node) { | 177 void AstPrinter::VisitAssignableNode(AssignableNode* node) { |
| 188 const AbstractType& type = node->type(); | 178 const AbstractType& type = node->type(); |
| 189 const String& dst_name = node->dst_name(); | 179 const String& dst_name = node->dst_name(); |
| 190 logger_->Print("(%s (type \"%s\") (of \"%s\") ", | 180 logger_->Print("(%s (type \"%s\") (of \"%s\") ", node->Name(), |
| 191 node->Name(), | 181 String::Handle(type.Name()).ToCString(), dst_name.ToCString()); |
| 192 String::Handle(type.Name()).ToCString(), | |
| 193 dst_name.ToCString()); | |
| 194 node->VisitChildren(this); | 182 node->VisitChildren(this); |
| 195 logger_->Print(")"); | 183 logger_->Print(")"); |
| 196 } | 184 } |
| 197 | 185 |
| 198 | 186 |
| 199 void AstPrinter::VisitAwaitNode(AwaitNode* node) { | 187 void AstPrinter::VisitAwaitNode(AwaitNode* node) { |
| 200 logger_->Print("(*****%s***** (scope \"%p\") ", node->Name(), node->scope()); | 188 logger_->Print("(*****%s***** (scope \"%p\") ", node->Name(), node->scope()); |
| 201 node->VisitChildren(this); | 189 node->VisitChildren(this); |
| 202 logger_->Print(")"); | 190 logger_->Print(")"); |
| 203 } | 191 } |
| 204 | 192 |
| 205 | 193 |
| 206 void AstPrinter::VisitAwaitMarkerNode(AwaitMarkerNode* node) { | 194 void AstPrinter::VisitAwaitMarkerNode(AwaitMarkerNode* node) { |
| 207 logger_->Print("(%s (async_scope \"%p\" await_scope \"%p\"))", | 195 logger_->Print("(%s (async_scope \"%p\" await_scope \"%p\"))", node->Name(), |
| 208 node->Name(), | 196 node->async_scope(), node->await_scope()); |
| 209 node->async_scope(), | |
| 210 node->await_scope()); | |
| 211 } | 197 } |
| 212 | 198 |
| 213 | 199 |
| 214 void AstPrinter::VisitPrimaryNode(PrimaryNode* node) { | 200 void AstPrinter::VisitPrimaryNode(PrimaryNode* node) { |
| 215 logger_->Print("(*****%s***** \"%s\")", | 201 logger_->Print("(*****%s***** \"%s\")", node->Name(), |
| 216 node->Name(), | 202 node->primary().ToCString()); |
| 217 node->primary().ToCString()); | |
| 218 } | 203 } |
| 219 | 204 |
| 220 | 205 |
| 221 void AstPrinter::VisitComparisonNode(ComparisonNode* node) { | 206 void AstPrinter::VisitComparisonNode(ComparisonNode* node) { |
| 222 logger_->Print("(%s %s ", node->Name(), node->TokenName()); | 207 logger_->Print("(%s %s ", node->Name(), node->TokenName()); |
| 223 node->VisitChildren(this); | 208 node->VisitChildren(this); |
| 224 logger_->Print(")"); | 209 logger_->Print(")"); |
| 225 } | 210 } |
| 226 | 211 |
| 227 | 212 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 logger_->Print(")"); | 274 logger_->Print(")"); |
| 290 } | 275 } |
| 291 | 276 |
| 292 | 277 |
| 293 void AstPrinter::VisitDoWhileNode(DoWhileNode* node) { | 278 void AstPrinter::VisitDoWhileNode(DoWhileNode* node) { |
| 294 VisitGenericAstNode(node); | 279 VisitGenericAstNode(node); |
| 295 } | 280 } |
| 296 | 281 |
| 297 | 282 |
| 298 void AstPrinter::VisitJumpNode(JumpNode* node) { | 283 void AstPrinter::VisitJumpNode(JumpNode* node) { |
| 299 logger_->Print("(%s %s %s (scope \"%p\"))", | 284 logger_->Print("(%s %s %s (scope \"%p\"))", node->Name(), node->TokenName(), |
| 300 node->Name(), | 285 node->label()->name().ToCString(), node->label()->owner()); |
| 301 node->TokenName(), | |
| 302 node->label()->name().ToCString(), | |
| 303 node->label()->owner()); | |
| 304 } | 286 } |
| 305 | 287 |
| 306 | 288 |
| 307 void AstPrinter::VisitInstanceCallNode(InstanceCallNode* node) { | 289 void AstPrinter::VisitInstanceCallNode(InstanceCallNode* node) { |
| 308 logger_->Print("(%s \"%s\" ", | 290 logger_->Print("(%s \"%s\" ", node->Name(), |
| 309 node->Name(), | 291 node->function_name().ToCString()); |
| 310 node->function_name().ToCString()); | |
| 311 node->VisitChildren(this); | 292 node->VisitChildren(this); |
| 312 logger_->Print(")"); | 293 logger_->Print(")"); |
| 313 } | 294 } |
| 314 | 295 |
| 315 | 296 |
| 316 void AstPrinter::VisitStaticCallNode(StaticCallNode* node) { | 297 void AstPrinter::VisitStaticCallNode(StaticCallNode* node) { |
| 317 const char* function_fullname = node->function().ToFullyQualifiedCString(); | 298 const char* function_fullname = node->function().ToFullyQualifiedCString(); |
| 318 logger_->Print("(%s \"%s\" ", node->Name(), function_fullname); | 299 logger_->Print("(%s \"%s\" ", node->Name(), function_fullname); |
| 319 node->VisitChildren(this); | 300 node->VisitChildren(this); |
| 320 logger_->Print(")"); | 301 logger_->Print(")"); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 349 | 330 |
| 350 | 331 |
| 351 void AstPrinter::VisitInstanceSetterNode(InstanceSetterNode* node) { | 332 void AstPrinter::VisitInstanceSetterNode(InstanceSetterNode* node) { |
| 352 logger_->Print("(%s \"%s\" ", node->Name(), node->field_name().ToCString()); | 333 logger_->Print("(%s \"%s\" ", node->Name(), node->field_name().ToCString()); |
| 353 node->VisitChildren(this); | 334 node->VisitChildren(this); |
| 354 logger_->Print(")"); | 335 logger_->Print(")"); |
| 355 } | 336 } |
| 356 | 337 |
| 357 | 338 |
| 358 void AstPrinter::VisitInitStaticFieldNode(InitStaticFieldNode* node) { | 339 void AstPrinter::VisitInitStaticFieldNode(InitStaticFieldNode* node) { |
| 359 logger_->Print("(%s \"%s\")", | 340 logger_->Print("(%s \"%s\")", node->Name(), |
| 360 node->Name(), | 341 String::Handle(node->field().name()).ToCString()); |
| 361 String::Handle(node->field().name()).ToCString()); | |
| 362 } | 342 } |
| 363 | 343 |
| 364 | 344 |
| 365 void AstPrinter::VisitStaticGetterNode(StaticGetterNode* node) { | 345 void AstPrinter::VisitStaticGetterNode(StaticGetterNode* node) { |
| 366 String& class_name = String::Handle(node->cls().Name()); | 346 String& class_name = String::Handle(node->cls().Name()); |
| 367 logger_->Print("(%s \"%s.%s\")", | 347 logger_->Print("(%s \"%s.%s\")", node->Name(), class_name.ToCString(), |
| 368 node->Name(), | 348 node->field_name().ToCString()); |
| 369 class_name.ToCString(), | |
| 370 node->field_name().ToCString()); | |
| 371 } | 349 } |
| 372 | 350 |
| 373 | 351 |
| 374 void AstPrinter::VisitStaticSetterNode(StaticSetterNode* node) { | 352 void AstPrinter::VisitStaticSetterNode(StaticSetterNode* node) { |
| 375 String& class_name = String::Handle(node->cls().Name()); | 353 String& class_name = String::Handle(node->cls().Name()); |
| 376 logger_->Print("(%s \"%s.%s\" ", | 354 logger_->Print("(%s \"%s.%s\" ", node->Name(), class_name.ToCString(), |
| 377 node->Name(), | 355 node->field_name().ToCString()); |
| 378 class_name.ToCString(), | |
| 379 node->field_name().ToCString()); | |
| 380 node->VisitChildren(this); | 356 node->VisitChildren(this); |
| 381 logger_->Print(")"); | 357 logger_->Print(")"); |
| 382 } | 358 } |
| 383 | 359 |
| 384 | 360 |
| 385 void AstPrinter::VisitLoadIndexedNode(LoadIndexedNode* node) { | 361 void AstPrinter::VisitLoadIndexedNode(LoadIndexedNode* node) { |
| 386 logger_->Print("(%s%s ", node->Name(), node->IsSuperLoad() ? " super" : ""); | 362 logger_->Print("(%s%s ", node->Name(), node->IsSuperLoad() ? " super" : ""); |
| 387 node->VisitChildren(this); | 363 node->VisitChildren(this); |
| 388 logger_->Print(")"); | 364 logger_->Print(")"); |
| 389 } | 365 } |
| 390 | 366 |
| 391 | 367 |
| 392 void AstPrinter::VisitStoreIndexedNode(StoreIndexedNode* node) { | 368 void AstPrinter::VisitStoreIndexedNode(StoreIndexedNode* node) { |
| 393 logger_->Print("(%s%s ", node->Name(), node->IsSuperStore() ? " super" : ""); | 369 logger_->Print("(%s%s ", node->Name(), node->IsSuperStore() ? " super" : ""); |
| 394 node->VisitChildren(this); | 370 node->VisitChildren(this); |
| 395 logger_->Print(")"); | 371 logger_->Print(")"); |
| 396 } | 372 } |
| 397 | 373 |
| 398 | 374 |
| 399 void AstPrinter::VisitNativeBodyNode(NativeBodyNode* node) { | 375 void AstPrinter::VisitNativeBodyNode(NativeBodyNode* node) { |
| 400 logger_->Print("(%s \"%s\" (%" Pd " args))", | 376 logger_->Print( |
| 401 node->Name(), | 377 "(%s \"%s\" (%" Pd " args))", node->Name(), |
| 402 node->native_c_function_name().ToCString(), | 378 node->native_c_function_name().ToCString(), |
| 403 NativeArguments::ParameterCountForResolution(node->function())); | 379 NativeArguments::ParameterCountForResolution(node->function())); |
| 404 } | 380 } |
| 405 | 381 |
| 406 | 382 |
| 407 void AstPrinter::VisitCatchClauseNode(CatchClauseNode* node) { | 383 void AstPrinter::VisitCatchClauseNode(CatchClauseNode* node) { |
| 408 VisitGenericAstNode(node); | 384 VisitGenericAstNode(node); |
| 409 } | 385 } |
| 410 | 386 |
| 411 | 387 |
| 412 void AstPrinter::VisitTryCatchNode(TryCatchNode* node) { | 388 void AstPrinter::VisitTryCatchNode(TryCatchNode* node) { |
| 413 logger_->Print("(%s ", node->Name()); | 389 logger_->Print("(%s ", node->Name()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 } | 427 } |
| 452 } | 428 } |
| 453 | 429 |
| 454 | 430 |
| 455 void AstPrinter::PrintLocalScopeVariable(const LocalScope* scope, | 431 void AstPrinter::PrintLocalScopeVariable(const LocalScope* scope, |
| 456 LocalVariable* var, | 432 LocalVariable* var, |
| 457 int indent) { | 433 int indent) { |
| 458 ASSERT(scope != NULL); | 434 ASSERT(scope != NULL); |
| 459 ASSERT(var != NULL); | 435 ASSERT(var != NULL); |
| 460 IndentN(indent); | 436 IndentN(indent); |
| 461 logger_->Print("(%s%s '%s'", | 437 logger_->Print("(%s%s '%s'", var->is_final() ? "final " : "", |
| 462 var->is_final() ? "final " : "", | 438 String::Handle(var->type().Name()).ToCString(), |
| 463 String::Handle(var->type().Name()).ToCString(), | 439 var->name().ToCString()); |
| 464 var->name().ToCString()); | |
| 465 if (var->owner() != scope) { | 440 if (var->owner() != scope) { |
| 466 logger_->Print(" alias"); | 441 logger_->Print(" alias"); |
| 467 } | 442 } |
| 468 if (var->HasIndex()) { | 443 if (var->HasIndex()) { |
| 469 logger_->Print(" @%d", var->index()); | 444 logger_->Print(" @%d", var->index()); |
| 470 if (var->is_captured()) { | 445 if (var->is_captured()) { |
| 471 logger_->Print(" ctx %d", var->owner()->context_level()); | 446 logger_->Print(" ctx %d", var->owner()->context_level()); |
| 472 } | 447 } |
| 473 } else if (var->owner()->function_level() != 0) { | 448 } else if (var->owner()->function_level() != 0) { |
| 474 logger_->Print(" lev %d", var->owner()->function_level()); | 449 logger_->Print(" lev %d", var->owner()->function_level()); |
| 475 } | 450 } |
| 476 logger_->Print(" valid %s-%s)\n", | 451 logger_->Print(" valid %s-%s)\n", var->token_pos().ToCString(), |
| 477 var->token_pos().ToCString(), | 452 scope->end_token_pos().ToCString()); |
| 478 scope->end_token_pos().ToCString()); | |
| 479 } | 453 } |
| 480 | 454 |
| 481 | 455 |
| 482 void AstPrinter::PrintLocalScope(const LocalScope* scope, | 456 void AstPrinter::PrintLocalScope(const LocalScope* scope, |
| 483 int start_index, | 457 int start_index, |
| 484 int indent) { | 458 int indent) { |
| 485 ASSERT(scope != NULL); | 459 ASSERT(scope != NULL); |
| 486 for (int i = start_index; i < scope->num_variables(); i++) { | 460 for (int i = start_index; i < scope->num_variables(); i++) { |
| 487 LocalVariable* var = scope->VariableAt(i); | 461 LocalVariable* var = scope->VariableAt(i); |
| 488 PrintLocalScopeVariable(scope, var, indent); | 462 PrintLocalScopeVariable(scope, var, indent); |
| 489 } | 463 } |
| 490 const LocalScope* child = scope->child(); | 464 const LocalScope* child = scope->child(); |
| 491 while (child != NULL) { | 465 while (child != NULL) { |
| 492 IndentN(indent); | 466 IndentN(indent); |
| 493 logger_->Print("{scope %p ", child); | 467 logger_->Print("{scope %p ", child); |
| 494 if (child->HasContextLevel()) { | 468 if (child->HasContextLevel()) { |
| 495 logger_->Print("ctx %d numctxvar %d ", | 469 logger_->Print("ctx %d numctxvar %d ", child->context_level(), |
| 496 child->context_level(), | 470 child->num_context_variables()); |
| 497 child->num_context_variables()); | |
| 498 } | 471 } |
| 499 logger_->Print("llev %d\n", child->loop_level()); | 472 logger_->Print("llev %d\n", child->loop_level()); |
| 500 PrintLocalScope(child, 0, indent + kScopeIndent); | 473 PrintLocalScope(child, 0, indent + kScopeIndent); |
| 501 IndentN(indent); | 474 IndentN(indent); |
| 502 logger_->Print("}\n"); | 475 logger_->Print("}\n"); |
| 503 child = child->sibling(); | 476 child = child->sibling(); |
| 504 } | 477 } |
| 505 } | 478 } |
| 506 | 479 |
| 507 | 480 |
| 508 void AstPrinter::PrintFunctionScope(const ParsedFunction& parsed_function) { | 481 void AstPrinter::PrintFunctionScope(const ParsedFunction& parsed_function) { |
| 509 HANDLESCOPE(parsed_function.thread()); | 482 HANDLESCOPE(parsed_function.thread()); |
| 510 const Function& function = parsed_function.function(); | 483 const Function& function = parsed_function.function(); |
| 511 SequenceNode* node_sequence = parsed_function.node_sequence(); | 484 SequenceNode* node_sequence = parsed_function.node_sequence(); |
| 512 ASSERT(node_sequence != NULL); | 485 ASSERT(node_sequence != NULL); |
| 513 const LocalScope* scope = node_sequence->scope(); | 486 const LocalScope* scope = node_sequence->scope(); |
| 514 ASSERT(scope != NULL); | 487 ASSERT(scope != NULL); |
| 515 const char* function_name = function.ToFullyQualifiedCString(); | 488 const char* function_name = function.ToFullyQualifiedCString(); |
| 516 logger_->Print("Scope for function '%s'\n{scope %p ", function_name, scope); | 489 logger_->Print("Scope for function '%s'\n{scope %p ", function_name, scope); |
| 517 if (scope->HasContextLevel()) { | 490 if (scope->HasContextLevel()) { |
| 518 logger_->Print("ctx %d numctxvar %d ", | 491 logger_->Print("ctx %d numctxvar %d ", scope->context_level(), |
| 519 scope->context_level(), | 492 scope->num_context_variables()); |
| 520 scope->num_context_variables()); | |
| 521 } | 493 } |
| 522 logger_->Print("llev %d\n", scope->loop_level()); | 494 logger_->Print("llev %d\n", scope->loop_level()); |
| 523 const int num_fixed_params = function.num_fixed_parameters(); | 495 const int num_fixed_params = function.num_fixed_parameters(); |
| 524 const int num_params = num_fixed_params + function.NumOptionalParameters(); | 496 const int num_params = num_fixed_params + function.NumOptionalParameters(); |
| 525 // Parameters must be listed first and must all appear in the top scope. | 497 // Parameters must be listed first and must all appear in the top scope. |
| 526 ASSERT(num_params <= scope->num_variables()); | 498 ASSERT(num_params <= scope->num_variables()); |
| 527 int pos = 0; // Current position of variable in scope. | 499 int pos = 0; // Current position of variable in scope. |
| 528 int indent = kScopeIndent; | 500 int indent = kScopeIndent; |
| 529 while (pos < num_params) { | 501 while (pos < num_params) { |
| 530 LocalVariable* param = scope->VariableAt(pos); | 502 LocalVariable* param = scope->VariableAt(pos); |
| 531 ASSERT(param->owner() == scope); // No aliases should precede parameters. | 503 ASSERT(param->owner() == scope); // No aliases should precede parameters. |
| 532 IndentN(indent); | 504 IndentN(indent); |
| 533 logger_->Print("(param %s%s '%s'", | 505 logger_->Print("(param %s%s '%s'", param->is_final() ? "final " : "", |
| 534 param->is_final() ? "final " : "", | 506 String::Handle(param->type().Name()).ToCString(), |
| 535 String::Handle(param->type().Name()).ToCString(), | 507 param->name().ToCString()); |
| 536 param->name().ToCString()); | |
| 537 // Print the default value if the parameter is optional. | 508 // Print the default value if the parameter is optional. |
| 538 if (pos >= num_fixed_params && pos < num_params) { | 509 if (pos >= num_fixed_params && pos < num_params) { |
| 539 const Instance& default_parameter_value = | 510 const Instance& default_parameter_value = |
| 540 parsed_function.DefaultParameterValueAt(pos - num_fixed_params); | 511 parsed_function.DefaultParameterValueAt(pos - num_fixed_params); |
| 541 logger_->Print(" =%s", default_parameter_value.ToCString()); | 512 logger_->Print(" =%s", default_parameter_value.ToCString()); |
| 542 } | 513 } |
| 543 if (param->HasIndex()) { | 514 if (param->HasIndex()) { |
| 544 logger_->Print(" @%d", param->index()); | 515 logger_->Print(" @%d", param->index()); |
| 545 if (param->is_captured()) { | 516 if (param->is_captured()) { |
| 546 logger_->Print(" ctx %d", param->owner()->context_level()); | 517 logger_->Print(" ctx %d", param->owner()->context_level()); |
| 547 } | 518 } |
| 548 } | 519 } |
| 549 logger_->Print(" valid %s-%s)\n", | 520 logger_->Print(" valid %s-%s)\n", param->token_pos().ToCString(), |
| 550 param->token_pos().ToCString(), | 521 scope->end_token_pos().ToCString()); |
| 551 scope->end_token_pos().ToCString()); | |
| 552 pos++; | 522 pos++; |
| 553 } | 523 } |
| 554 // Visit remaining non-parameter variables and children scopes. | 524 // Visit remaining non-parameter variables and children scopes. |
| 555 PrintLocalScope(scope, pos, indent); | 525 PrintLocalScope(scope, pos, indent); |
| 556 logger_->Print("}\n"); | 526 logger_->Print("}\n"); |
| 557 } | 527 } |
| 558 | 528 |
| 559 | 529 |
| 560 void AstPrinter::PrintFunctionNodes(const ParsedFunction& parsed_function) { | 530 void AstPrinter::PrintFunctionNodes(const ParsedFunction& parsed_function) { |
| 561 HANDLESCOPE(parsed_function.thread()); | 531 HANDLESCOPE(parsed_function.thread()); |
| 562 SequenceNode* node_sequence = parsed_function.node_sequence(); | 532 SequenceNode* node_sequence = parsed_function.node_sequence(); |
| 563 ASSERT(node_sequence != NULL); | 533 ASSERT(node_sequence != NULL); |
| 564 const char* function_name = | 534 const char* function_name = |
| 565 parsed_function.function().ToFullyQualifiedCString(); | 535 parsed_function.function().ToFullyQualifiedCString(); |
| 566 logger_->Print("Ast for function '%s' {\n", function_name); | 536 logger_->Print("Ast for function '%s' {\n", function_name); |
| 567 node_sequence->Visit(this); | 537 node_sequence->Visit(this); |
| 568 logger_->Print("}\n"); | 538 logger_->Print("}\n"); |
| 569 } | 539 } |
| 570 | 540 |
| 571 } // namespace dart | 541 } // namespace dart |
| 572 | 542 |
| 573 #endif // !defined(PRODUCT) | 543 #endif // !defined(PRODUCT) |
| OLD | NEW |