| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library tree_ir_tracer; | 5 library tree_ir_tracer; |
| 6 | 6 |
| 7 import 'dart:async' show EventSink; | 7 import 'dart:async' show EventSink; |
| 8 import '../tracer.dart'; | 8 import '../tracer.dart'; |
| 9 import 'tree_ir_nodes.dart'; | 9 import 'tree_ir_nodes.dart'; |
| 10 | 10 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 return names.varName(node.variable); | 353 return names.varName(node.variable); |
| 354 } | 354 } |
| 355 | 355 |
| 356 String visitAssign(Assign node) { | 356 String visitAssign(Assign node) { |
| 357 String variable = names.varName(node.variable); | 357 String variable = names.varName(node.variable); |
| 358 String value = visitExpression(node.value); | 358 String value = visitExpression(node.value); |
| 359 return '$variable = $value'; | 359 return '$variable = $value'; |
| 360 } | 360 } |
| 361 | 361 |
| 362 String formatArguments(Invoke node) { | 362 String formatArguments(Invoke node) { |
| 363 List<String> args = new List<String>(); | 363 return node.arguments.map(visitExpression).join(', '); |
| 364 int positionalArgumentCount = node.selector.positionalArgumentCount; | |
| 365 for (int i = 0; i < positionalArgumentCount; ++i) { | |
| 366 args.add(node.arguments[i].accept(this)); | |
| 367 } | |
| 368 for (int i = 0; i < node.selector.namedArgumentCount; ++i) { | |
| 369 String name = node.selector.namedArguments[i]; | |
| 370 String arg = node.arguments[positionalArgumentCount + i].accept(this); | |
| 371 args.add("$name: $arg"); | |
| 372 } | |
| 373 return args.join(', '); | |
| 374 } | 364 } |
| 375 | 365 |
| 376 String visitInvokeStatic(InvokeStatic node) { | 366 String visitInvokeStatic(InvokeStatic node) { |
| 377 String head = node.target.name; | 367 String head = node.target.name; |
| 378 String args = formatArguments(node); | 368 String args = formatArguments(node); |
| 379 return "$head($args)"; | 369 return "$head($args)"; |
| 380 } | 370 } |
| 381 | 371 |
| 382 String visitInvokeMethod(InvokeMethod node) { | 372 String visitInvokeMethod(InvokeMethod node) { |
| 383 String receiver = node.receiver.accept(this); | 373 String receiver = node.receiver.accept(this); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 | 518 |
| 529 @override | 519 @override |
| 530 String visitReifyRuntimeType(ReifyRuntimeType node) { | 520 String visitReifyRuntimeType(ReifyRuntimeType node) { |
| 531 return 'Reify ${node.value}'; | 521 return 'Reify ${node.value}'; |
| 532 } | 522 } |
| 533 | 523 |
| 534 @override | 524 @override |
| 535 String visitTypeExpression(TypeExpression node) { | 525 String visitTypeExpression(TypeExpression node) { |
| 536 return node.dartType.toString(); | 526 return node.dartType.toString(); |
| 537 } | 527 } |
| 528 |
| 529 @override |
| 530 String visitCreateInvocationMirror(CreateInvocationMirror node) { |
| 531 String args = node.arguments.map(visitExpression).join(', '); |
| 532 return 'CreateInvocationMirror(${node.selector.name}, $args)'; |
| 533 } |
| 538 } | 534 } |
| 539 | 535 |
| 540 /** | 536 /** |
| 541 * Invents (and remembers) names for Variables that do not have an associated | 537 * Invents (and remembers) names for Variables that do not have an associated |
| 542 * identifier. | 538 * identifier. |
| 543 * | 539 * |
| 544 * In case a variable is named v0, v1, etc, it may be assigned a different | 540 * In case a variable is named v0, v1, etc, it may be assigned a different |
| 545 * name to avoid clashing with a previously synthesized variable name. | 541 * name to avoid clashing with a previously synthesized variable name. |
| 546 */ | 542 */ |
| 547 class Names { | 543 class Names { |
| 548 final Map<Variable, String> _names = {}; | 544 final Map<Variable, String> _names = {}; |
| 549 final Set<String> _usedNames = new Set(); | 545 final Set<String> _usedNames = new Set(); |
| 550 int _counter = 0; | 546 int _counter = 0; |
| 551 | 547 |
| 552 String varName(Variable v) { | 548 String varName(Variable v) { |
| 553 String name = _names[v]; | 549 String name = _names[v]; |
| 554 if (name == null) { | 550 if (name == null) { |
| 555 String prefix = v.element == null ? 'v' : '${v.element.name}_'; | 551 String prefix = v.element == null ? 'v' : '${v.element.name}_'; |
| 556 while (name == null || _usedNames.contains(name)) { | 552 while (name == null || _usedNames.contains(name)) { |
| 557 name = "$prefix${_counter++}"; | 553 name = "$prefix${_counter++}"; |
| 558 } | 554 } |
| 559 _names[v] = name; | 555 _names[v] = name; |
| 560 _usedNames.add(name); | 556 _usedNames.add(name); |
| 561 } | 557 } |
| 562 return name; | 558 return name; |
| 563 } | 559 } |
| 564 } | 560 } |
| OLD | NEW |