| 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 import 'optimization/optimization.dart'; | 10 import 'optimization/optimization.dart'; |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 374 |
| 375 String visitInvokeMethodDirectly(InvokeMethodDirectly node) { | 375 String visitInvokeMethodDirectly(InvokeMethodDirectly node) { |
| 376 String receiver = visitExpression(node.receiver); | 376 String receiver = visitExpression(node.receiver); |
| 377 String host = node.target.enclosingClass.name; | 377 String host = node.target.enclosingClass.name; |
| 378 String name = node.selector.name; | 378 String name = node.selector.name; |
| 379 String args = formatArguments(node); | 379 String args = formatArguments(node); |
| 380 return "$receiver.$host::$name($args)"; | 380 return "$receiver.$host::$name($args)"; |
| 381 } | 381 } |
| 382 | 382 |
| 383 String visitInvokeConstructor(InvokeConstructor node) { | 383 String visitInvokeConstructor(InvokeConstructor node) { |
| 384 String className = node.target.enclosingClass.name; |
| 384 String callName; | 385 String callName; |
| 385 if (node.target.name.isEmpty) { | 386 if (node.target.name.isEmpty) { |
| 386 callName = '${node.type}'; | 387 callName = '${className}'; |
| 387 } else { | 388 } else { |
| 388 callName = '${node.type}.${node.target.name}'; | 389 callName = '${className}.${node.target.name}'; |
| 389 } | 390 } |
| 390 String args = formatArguments(node); | 391 String args = formatArguments(node); |
| 392 String typeArguments = node.typeArguments.map(visitExpression).join(', '); |
| 391 String keyword = node.constant != null ? 'const' : 'new'; | 393 String keyword = node.constant != null ? 'const' : 'new'; |
| 392 return "$keyword $callName($args)"; | 394 return "$keyword $callName<$typeArguments>($args)"; |
| 393 } | 395 } |
| 394 | 396 |
| 395 String visitConcatenateStrings(ConcatenateStrings node) { | 397 String visitConcatenateStrings(ConcatenateStrings node) { |
| 396 String args = node.arguments.map(visitExpression).join(', '); | 398 String args = node.arguments.map(visitExpression).join(', '); |
| 397 return "concat [$args]"; | 399 return "concat [$args]"; |
| 398 } | 400 } |
| 399 | 401 |
| 400 String visitLiteralList(LiteralList node) { | 402 String visitLiteralList(LiteralList node) { |
| 401 String values = node.values.map(visitExpression).join(', '); | 403 String values = node.values.map(visitExpression).join(', '); |
| 402 return "list [$values]"; | 404 return "list [$values]"; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 | 490 |
| 489 String visitCreateInstance(CreateInstance node) { | 491 String visitCreateInstance(CreateInstance node) { |
| 490 String className = node.classElement.name; | 492 String className = node.classElement.name; |
| 491 String arguments = node.arguments.map(visitExpression).join(', '); | 493 String arguments = node.arguments.map(visitExpression).join(', '); |
| 492 return 'CreateInstance $className($arguments)'; | 494 return 'CreateInstance $className($arguments)'; |
| 493 } | 495 } |
| 494 | 496 |
| 495 | 497 |
| 496 @override | 498 @override |
| 497 String visitReadTypeVariable(ReadTypeVariable node) { | 499 String visitReadTypeVariable(ReadTypeVariable node) { |
| 498 return 'read ${node.variable.element} ${visitExpression(node.target)}'; | 500 return 'Read ${node.variable.element} ${visitExpression(node.target)}'; |
| 499 } | 501 } |
| 500 | 502 |
| 501 @override | 503 @override |
| 502 String visitReifyRuntimeType(ReifyRuntimeType node) { | 504 String visitReifyRuntimeType(ReifyRuntimeType node) { |
| 503 return 'reify ${node.value}'; | 505 return 'Reify ${node.value}'; |
| 506 } |
| 507 |
| 508 @override |
| 509 String visitTypeExpression(TypeExpression node) { |
| 510 return node.dartType.toString(); |
| 504 } | 511 } |
| 505 } | 512 } |
| 506 | 513 |
| 507 /** | 514 /** |
| 508 * Invents (and remembers) names for Variables that do not have an associated | 515 * Invents (and remembers) names for Variables that do not have an associated |
| 509 * identifier. | 516 * identifier. |
| 510 * | 517 * |
| 511 * In case a variable is named v0, v1, etc, it may be assigned a different | 518 * In case a variable is named v0, v1, etc, it may be assigned a different |
| 512 * name to avoid clashing with a previously synthesized variable name. | 519 * name to avoid clashing with a previously synthesized variable name. |
| 513 */ | 520 */ |
| 514 class Names { | 521 class Names { |
| 515 final Map<Variable, String> _names = {}; | 522 final Map<Variable, String> _names = {}; |
| 516 final Set<String> _usedNames = new Set(); | 523 final Set<String> _usedNames = new Set(); |
| 517 int _counter = 0; | 524 int _counter = 0; |
| 518 | 525 |
| 519 String varName(Variable v) { | 526 String varName(Variable v) { |
| 520 String name = _names[v]; | 527 String name = _names[v]; |
| 521 if (name == null) { | 528 if (name == null) { |
| 522 String prefix = v.element == null ? 'v' : '${v.element.name}_'; | 529 String prefix = v.element == null ? 'v' : '${v.element.name}_'; |
| 523 while (name == null || _usedNames.contains(name)) { | 530 while (name == null || _usedNames.contains(name)) { |
| 524 name = "$prefix${_counter++}"; | 531 name = "$prefix${_counter++}"; |
| 525 } | 532 } |
| 526 _names[v] = name; | 533 _names[v] = name; |
| 527 _usedNames.add(name); | 534 _usedNames.add(name); |
| 528 } | 535 } |
| 529 return name; | 536 return name; |
| 530 } | 537 } |
| 531 } | 538 } |
| OLD | NEW |