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

Side by Side Diff: runtime/vm/ast_printer.cc

Issue 293013005: Fix issue 18435 (2nd attempt). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/ast_printer.h ('k') | runtime/vm/code_generator_test.cc » ('j') | 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/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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 384
385 385
386 void AstPrinter::PrintNode(AstNode* node) { 386 void AstPrinter::PrintNode(AstNode* node) {
387 ASSERT(node != NULL); 387 ASSERT(node != NULL);
388 AstPrinter ast_printer; 388 AstPrinter ast_printer;
389 node->Visit(&ast_printer); 389 node->Visit(&ast_printer);
390 OS::Print("\n"); 390 OS::Print("\n");
391 } 391 }
392 392
393 393
394 void AstPrinter::PrintLocalScopeVariable(const LocalScope* scope,
395 LocalVariable* var) {
396 ASSERT(scope != NULL);
397 ASSERT(var != NULL);
398 OS::Print("(%s%s '%s'",
399 var->is_final() ? "final " : "",
400 String::Handle(var->type().Name()).ToCString(),
401 var->name().ToCString());
402 if (var->owner() != scope) {
403 OS::Print(" alias");
404 }
405 if (var->HasIndex()) {
406 OS::Print(" @%d", var->index());
407 if (var->is_captured()) {
408 OS::Print(" ctx %d", var->owner()->context_level());
409 }
410 } else if (var->owner()->function_level() != 0) {
411 OS::Print(" lev %d", var->owner()->function_level());
412 }
413 OS::Print(" valid %" Pd "-%" Pd ")",
414 var->token_pos(),
415 scope->end_token_pos());
416 }
417
418
394 void AstPrinter::PrintLocalScope(const LocalScope* scope, 419 void AstPrinter::PrintLocalScope(const LocalScope* scope,
395 int start_index) { 420 int start_index) {
396 ASSERT(scope != NULL); 421 ASSERT(scope != NULL);
397 for (int i = start_index; i < scope->num_variables(); i++) { 422 for (int i = start_index; i < scope->num_variables(); i++) {
398 LocalVariable* var = scope->VariableAt(i); 423 LocalVariable* var = scope->VariableAt(i);
399 OS::Print("(%s%s '%s'", 424 PrintLocalScopeVariable(scope, var);
400 var->is_final() ? "final " : "",
401 String::Handle(var->type().Name()).ToCString(),
402 var->name().ToCString());
403 if (var->owner() != scope) {
404 OS::Print(" alias");
405 }
406 if (var->HasIndex()) {
407 OS::Print(" @%d", var->index());
408 if (var->is_captured()) {
409 OS::Print(" ctx %d", var->owner()->context_level());
410 }
411 } else if (var->owner()->function_level() != 0) {
412 OS::Print(" lev %d", var->owner()->function_level());
413 }
414 OS::Print(" valid %" Pd "-%" Pd ")",
415 var->token_pos(),
416 scope->end_token_pos());
417 } 425 }
418 const LocalScope* child = scope->child(); 426 const LocalScope* child = scope->child();
419 while (child != NULL) { 427 while (child != NULL) {
420 OS::Print("{scope %p ", child); 428 OS::Print("{scope %p ", child);
421 if (child->HasContextLevel()) { 429 if (child->HasContextLevel()) {
422 OS::Print("ctx %d numctxvar %d ", 430 OS::Print("ctx %d numctxvar %d ",
423 child->context_level(), 431 child->context_level(),
424 child->num_context_variables()); 432 child->num_context_variables());
425 } 433 }
426 OS::Print("llev %d ", child->loop_level()); 434 OS::Print("llev %d ", child->loop_level());
(...skipping 21 matching lines...) Expand all
448 scope->num_context_variables()); 456 scope->num_context_variables());
449 } 457 }
450 OS::Print("llev %d ", scope->loop_level()); 458 OS::Print("llev %d ", scope->loop_level());
451 const int num_fixed_params = function.num_fixed_parameters(); 459 const int num_fixed_params = function.num_fixed_parameters();
452 const int num_params = num_fixed_params + function.NumOptionalParameters(); 460 const int num_params = num_fixed_params + function.NumOptionalParameters();
453 // Parameters must be listed first and must all appear in the top scope. 461 // Parameters must be listed first and must all appear in the top scope.
454 ASSERT(num_params <= scope->num_variables()); 462 ASSERT(num_params <= scope->num_variables());
455 int pos = 0; // Current position of variable in scope. 463 int pos = 0; // Current position of variable in scope.
456 while (pos < num_params) { 464 while (pos < num_params) {
457 LocalVariable* param = scope->VariableAt(pos); 465 LocalVariable* param = scope->VariableAt(pos);
458 ASSERT(param->owner() == scope); 466 ASSERT(param->owner() == scope); // No aliases should precede parameters.
459 OS::Print("(param %s%s '%s'", 467 OS::Print("(param %s%s '%s'",
460 param->is_final() ? "final " : "", 468 param->is_final() ? "final " : "",
461 String::Handle(param->type().Name()).ToCString(), 469 String::Handle(param->type().Name()).ToCString(),
462 param->name().ToCString()); 470 param->name().ToCString());
463 // Print the default value if the parameter is optional. 471 // Print the default value if the parameter is optional.
464 if (pos >= num_fixed_params && pos < num_params) { 472 if (pos >= num_fixed_params && pos < num_params) {
465 const Object& default_parameter_value = Object::Handle( 473 const Object& default_parameter_value = Object::Handle(
466 default_parameter_values.At(pos - num_fixed_params)); 474 default_parameter_values.At(pos - num_fixed_params));
467 OS::Print(" =%s", default_parameter_value.ToCString()); 475 OS::Print(" =%s", default_parameter_value.ToCString());
468 } 476 }
(...skipping 20 matching lines...) Expand all
489 ASSERT(node_sequence != NULL); 497 ASSERT(node_sequence != NULL);
490 AstPrinter ast_printer; 498 AstPrinter ast_printer;
491 const char* function_name = 499 const char* function_name =
492 parsed_function.function().ToFullyQualifiedCString(); 500 parsed_function.function().ToFullyQualifiedCString();
493 OS::Print("Ast for function '%s' {\n", function_name); 501 OS::Print("Ast for function '%s' {\n", function_name);
494 node_sequence->Visit(&ast_printer); 502 node_sequence->Visit(&ast_printer);
495 OS::Print("}\n"); 503 OS::Print("}\n");
496 } 504 }
497 505
498 } // namespace dart 506 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/ast_printer.h ('k') | runtime/vm/code_generator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698