| 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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 String visitForeignExpression(ForeignExpression node) { | 523 String visitForeignExpression(ForeignExpression node) { |
| 524 String arguments = node.arguments.map(visitExpression).join(', '); | 524 String arguments = node.arguments.map(visitExpression).join(', '); |
| 525 return 'Foreign "${node.codeTemplate.source}"($arguments)'; | 525 return 'Foreign "${node.codeTemplate.source}"($arguments)'; |
| 526 } | 526 } |
| 527 | 527 |
| 528 @override | 528 @override |
| 529 String visitApplyBuiltinOperator(ApplyBuiltinOperator node) { | 529 String visitApplyBuiltinOperator(ApplyBuiltinOperator node) { |
| 530 String args = node.arguments.map(visitExpression).join(', '); | 530 String args = node.arguments.map(visitExpression).join(', '); |
| 531 return 'ApplyBuiltinOperator ${node.operator} ($args)'; | 531 return 'ApplyBuiltinOperator ${node.operator} ($args)'; |
| 532 } | 532 } |
| 533 |
| 534 @override |
| 535 String visitGetLength(GetLength node) { |
| 536 String object = visitExpression(node.object); |
| 537 return 'GetLength($object)'; |
| 538 } |
| 539 |
| 540 @override |
| 541 String visitGetIndex(GetIndex node) { |
| 542 String object = visitExpression(node.object); |
| 543 String index = visitExpression(node.index); |
| 544 return 'GetIndex($object, $index)'; |
| 545 } |
| 546 |
| 547 @override |
| 548 String visitSetIndex(SetIndex node) { |
| 549 String object = visitExpression(node.object); |
| 550 String index = visitExpression(node.index); |
| 551 String value = visitExpression(node.value); |
| 552 return 'SetIndex($object, $index, $value)'; |
| 553 } |
| 533 } | 554 } |
| 534 | 555 |
| 535 /** | 556 /** |
| 536 * Invents (and remembers) names for Variables that do not have an associated | 557 * Invents (and remembers) names for Variables that do not have an associated |
| 537 * identifier. | 558 * identifier. |
| 538 * | 559 * |
| 539 * In case a variable is named v0, v1, etc, it may be assigned a different | 560 * In case a variable is named v0, v1, etc, it may be assigned a different |
| 540 * name to avoid clashing with a previously synthesized variable name. | 561 * name to avoid clashing with a previously synthesized variable name. |
| 541 */ | 562 */ |
| 542 class Names { | 563 class Names { |
| 543 final Map<Variable, String> _names = {}; | 564 final Map<Variable, String> _names = {}; |
| 544 final Set<String> _usedNames = new Set(); | 565 final Set<String> _usedNames = new Set(); |
| 545 int _counter = 0; | 566 int _counter = 0; |
| 546 | 567 |
| 547 String varName(Variable v) { | 568 String varName(Variable v) { |
| 548 String name = _names[v]; | 569 String name = _names[v]; |
| 549 if (name == null) { | 570 if (name == null) { |
| 550 String prefix = v.element == null ? 'v' : '${v.element.name}_'; | 571 String prefix = v.element == null ? 'v' : '${v.element.name}_'; |
| 551 while (name == null || _usedNames.contains(name)) { | 572 while (name == null || _usedNames.contains(name)) { |
| 552 name = "$prefix${_counter++}"; | 573 name = "$prefix${_counter++}"; |
| 553 } | 574 } |
| 554 _names[v] = name; | 575 _names[v] = name; |
| 555 _usedNames.add(name); | 576 _usedNames.add(name); |
| 556 } | 577 } |
| 557 return name; | 578 return name; |
| 558 } | 579 } |
| 559 } | 580 } |
| OLD | NEW |