| 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/object.h" | 8 #include "vm/object.h" |
| 9 #include "vm/os.h" | 9 #include "vm/os.h" |
| 10 #include "vm/parser.h" | 10 #include "vm/parser.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 OS::Print(")"); | 23 OS::Print(")"); |
| 24 } | 24 } |
| 25 | 25 |
| 26 | 26 |
| 27 void AstPrinter::VisitSequenceNode(SequenceNode* node_sequence) { | 27 void AstPrinter::VisitSequenceNode(SequenceNode* node_sequence) { |
| 28 // TODO(regis): Make the output more readable by indenting the nested | 28 // TODO(regis): Make the output more readable by indenting the nested |
| 29 // sequences. This could be achieved using a AstPrinterContext similar to the | 29 // sequences. This could be achieved using a AstPrinterContext similar to the |
| 30 // CodeGeneratorContext. | 30 // CodeGeneratorContext. |
| 31 ASSERT(node_sequence != NULL); | 31 ASSERT(node_sequence != NULL); |
| 32 for (int i = 0; i < node_sequence->length(); i++) { | 32 for (int i = 0; i < node_sequence->length(); i++) { |
| 33 OS::Print("scope 0x%x: ", | 33 OS::Print("scope %p: ", |
| 34 node_sequence->scope()); | 34 node_sequence->scope()); |
| 35 node_sequence->NodeAt(i)->Visit(this); | 35 node_sequence->NodeAt(i)->Visit(this); |
| 36 OS::Print("\n"); | 36 OS::Print("\n"); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 | 40 |
| 41 void AstPrinter::VisitCloneContextNode(CloneContextNode* node) { | 41 void AstPrinter::VisitCloneContextNode(CloneContextNode* node) { |
| 42 VisitGenericAstNode(node); | 42 VisitGenericAstNode(node); |
| 43 } | 43 } |
| 44 | 44 |
| 45 | 45 |
| 46 void AstPrinter::VisitArgumentListNode(ArgumentListNode* arguments) { | 46 void AstPrinter::VisitArgumentListNode(ArgumentListNode* arguments) { |
| 47 VisitGenericAstNode(arguments); | 47 VisitGenericAstNode(arguments); |
| 48 } | 48 } |
| 49 | 49 |
| 50 | 50 |
| 51 void AstPrinter::VisitArgumentDefinitionTestNode( | 51 void AstPrinter::VisitArgumentDefinitionTestNode( |
| 52 ArgumentDefinitionTestNode* node) { | 52 ArgumentDefinitionTestNode* node) { |
| 53 OS::Print("(%s ?%s @%d)", | 53 OS::Print("(%s ?%s @%"Pd")", |
| 54 node->Name(), | 54 node->Name(), |
| 55 node->formal_parameter_name().ToCString(), | 55 node->formal_parameter_name().ToCString(), |
| 56 node->formal_parameter_index()); | 56 node->formal_parameter_index()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 void AstPrinter::VisitReturnNode(ReturnNode* node) { | 60 void AstPrinter::VisitReturnNode(ReturnNode* node) { |
| 61 VisitGenericAstNode(node); | 61 VisitGenericAstNode(node); |
| 62 } | 62 } |
| 63 | 63 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 void AstPrinter::VisitDoWhileNode(DoWhileNode* node) { | 237 void AstPrinter::VisitDoWhileNode(DoWhileNode* node) { |
| 238 OS::Print("(do "); | 238 OS::Print("(do "); |
| 239 node->body()->Visit(this); | 239 node->body()->Visit(this); |
| 240 OS::Print(" while "); | 240 OS::Print(" while "); |
| 241 node->condition()->Visit(this); | 241 node->condition()->Visit(this); |
| 242 OS::Print(")"); | 242 OS::Print(")"); |
| 243 } | 243 } |
| 244 | 244 |
| 245 | 245 |
| 246 void AstPrinter::VisitJumpNode(JumpNode* node) { | 246 void AstPrinter::VisitJumpNode(JumpNode* node) { |
| 247 OS::Print("(%s %s in scope 0x%x)", | 247 OS::Print("(%s %s in scope %p)", |
| 248 node->Name(), | 248 node->Name(), |
| 249 node->label()->name().ToCString(), | 249 node->label()->name().ToCString(), |
| 250 node->label()->owner()); | 250 node->label()->owner()); |
| 251 } | 251 } |
| 252 | 252 |
| 253 | 253 |
| 254 void AstPrinter::VisitInstanceCallNode(InstanceCallNode* node) { | 254 void AstPrinter::VisitInstanceCallNode(InstanceCallNode* node) { |
| 255 OS::Print("(%s '%s'(", node->Name(), node->function_name().ToCString()); | 255 OS::Print("(%s '%s'(", node->Name(), node->function_name().ToCString()); |
| 256 node->VisitChildren(this); | 256 node->VisitChildren(this); |
| 257 OS::Print("))"); | 257 OS::Print("))"); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 OS::Print(" alias"); | 398 OS::Print(" alias"); |
| 399 } | 399 } |
| 400 if (var->HasIndex()) { | 400 if (var->HasIndex()) { |
| 401 OS::Print(" @%d", var->index()); | 401 OS::Print(" @%d", var->index()); |
| 402 if (var->is_captured()) { | 402 if (var->is_captured()) { |
| 403 OS::Print(" ctx %d", var->owner()->context_level()); | 403 OS::Print(" ctx %d", var->owner()->context_level()); |
| 404 } | 404 } |
| 405 } else if (var->owner()->function_level() != 0) { | 405 } else if (var->owner()->function_level() != 0) { |
| 406 OS::Print(" lev %d", var->owner()->function_level()); | 406 OS::Print(" lev %d", var->owner()->function_level()); |
| 407 } | 407 } |
| 408 OS::Print(" valid %d-%d)", var->token_pos(), scope->end_token_pos()); | 408 OS::Print(" valid %"Pd"-%"Pd")", |
| 409 var->token_pos(), |
| 410 scope->end_token_pos()); |
| 409 } | 411 } |
| 410 const LocalScope* child = scope->child(); | 412 const LocalScope* child = scope->child(); |
| 411 while (child != NULL) { | 413 while (child != NULL) { |
| 412 OS::Print("{scope 0x%x ", child); | 414 OS::Print("{scope %p ", child); |
| 413 if (child->HasContextLevel()) { | 415 if (child->HasContextLevel()) { |
| 414 OS::Print("ctx %d numctxvar %d ", | 416 OS::Print("ctx %d numctxvar %d ", |
| 415 child->context_level(), | 417 child->context_level(), |
| 416 child->num_context_variables()); | 418 child->num_context_variables()); |
| 417 } | 419 } |
| 418 OS::Print("llev %d ", child->loop_level()); | 420 OS::Print("llev %d ", child->loop_level()); |
| 419 PrintLocalScope(child, 0); | 421 PrintLocalScope(child, 0); |
| 420 OS::Print("}"); | 422 OS::Print("}"); |
| 421 child = child->sibling(); | 423 child = child->sibling(); |
| 422 } | 424 } |
| 423 } | 425 } |
| 424 | 426 |
| 425 | 427 |
| 426 void AstPrinter::PrintFunctionScope(const ParsedFunction& parsed_function) { | 428 void AstPrinter::PrintFunctionScope(const ParsedFunction& parsed_function) { |
| 427 HANDLESCOPE(Isolate::Current()); | 429 HANDLESCOPE(Isolate::Current()); |
| 428 const Function& function = parsed_function.function(); | 430 const Function& function = parsed_function.function(); |
| 429 const Array& default_parameter_values = | 431 const Array& default_parameter_values = |
| 430 parsed_function.default_parameter_values(); | 432 parsed_function.default_parameter_values(); |
| 431 SequenceNode* node_sequence = parsed_function.node_sequence(); | 433 SequenceNode* node_sequence = parsed_function.node_sequence(); |
| 432 ASSERT(node_sequence != NULL); | 434 ASSERT(node_sequence != NULL); |
| 433 const LocalScope* scope = node_sequence->scope(); | 435 const LocalScope* scope = node_sequence->scope(); |
| 434 ASSERT(scope != NULL); | 436 ASSERT(scope != NULL); |
| 435 const char* function_name = function.ToFullyQualifiedCString(); | 437 const char* function_name = function.ToFullyQualifiedCString(); |
| 436 OS::Print("Scope for function '%s' {scope 0x%x ", function_name, scope); | 438 OS::Print("Scope for function '%s' {scope %p ", function_name, scope); |
| 437 if (scope->HasContextLevel()) { | 439 if (scope->HasContextLevel()) { |
| 438 OS::Print("ctx %d numctxvar %d ", | 440 OS::Print("ctx %d numctxvar %d ", |
| 439 scope->context_level(), | 441 scope->context_level(), |
| 440 scope->num_context_variables()); | 442 scope->num_context_variables()); |
| 441 } | 443 } |
| 442 OS::Print("llev %d ", scope->loop_level()); | 444 OS::Print("llev %d ", scope->loop_level()); |
| 443 const int num_fixed_params = function.num_fixed_parameters(); | 445 const int num_fixed_params = function.num_fixed_parameters(); |
| 444 const int num_opt_params = function.num_optional_parameters(); | 446 const int num_opt_params = function.num_optional_parameters(); |
| 445 const int num_params = num_fixed_params + num_opt_params; | 447 const int num_params = num_fixed_params + num_opt_params; |
| 446 // Parameters must be listed first and must all appear in the top scope. | 448 // Parameters must be listed first and must all appear in the top scope. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 458 const Object& default_parameter_value = Object::Handle( | 460 const Object& default_parameter_value = Object::Handle( |
| 459 default_parameter_values.At(pos - num_fixed_params)); | 461 default_parameter_values.At(pos - num_fixed_params)); |
| 460 OS::Print(" =%s", default_parameter_value.ToCString()); | 462 OS::Print(" =%s", default_parameter_value.ToCString()); |
| 461 } | 463 } |
| 462 if (param->HasIndex()) { | 464 if (param->HasIndex()) { |
| 463 OS::Print(" @%d", param->index()); | 465 OS::Print(" @%d", param->index()); |
| 464 if (param->is_captured()) { | 466 if (param->is_captured()) { |
| 465 OS::Print(" ctx %d", param->owner()->context_level()); | 467 OS::Print(" ctx %d", param->owner()->context_level()); |
| 466 } | 468 } |
| 467 } | 469 } |
| 468 OS::Print(" valid %d-%d)", param->token_pos(), scope->end_token_pos()); | 470 OS::Print(" valid %"Pd"-%"Pd")", |
| 471 param->token_pos(), |
| 472 scope->end_token_pos()); |
| 469 pos++; | 473 pos++; |
| 470 } | 474 } |
| 471 // Visit remaining non-parameter variables and children scopes. | 475 // Visit remaining non-parameter variables and children scopes. |
| 472 PrintLocalScope(scope, pos); | 476 PrintLocalScope(scope, pos); |
| 473 OS::Print("}\n"); | 477 OS::Print("}\n"); |
| 474 } | 478 } |
| 475 | 479 |
| 476 | 480 |
| 477 void AstPrinter::PrintFunctionNodes(const ParsedFunction& parsed_function) { | 481 void AstPrinter::PrintFunctionNodes(const ParsedFunction& parsed_function) { |
| 478 HANDLESCOPE(Isolate::Current()); | 482 HANDLESCOPE(Isolate::Current()); |
| 479 SequenceNode* node_sequence = parsed_function.node_sequence(); | 483 SequenceNode* node_sequence = parsed_function.node_sequence(); |
| 480 ASSERT(node_sequence != NULL); | 484 ASSERT(node_sequence != NULL); |
| 481 AstPrinter ast_printer; | 485 AstPrinter ast_printer; |
| 482 const char* function_name = | 486 const char* function_name = |
| 483 parsed_function.function().ToFullyQualifiedCString(); | 487 parsed_function.function().ToFullyQualifiedCString(); |
| 484 OS::Print("Ast for function '%s' {\n", function_name); | 488 OS::Print("Ast for function '%s' {\n", function_name); |
| 485 node_sequence->Visit(&ast_printer); | 489 node_sequence->Visit(&ast_printer); |
| 486 OS::Print("}\n"); | 490 OS::Print("}\n"); |
| 487 } | 491 } |
| 488 | 492 |
| 489 } // namespace dart | 493 } // namespace dart |
| OLD | NEW |