| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 visitStatement(node.catchBody); | 165 visitStatement(node.catchBody); |
| 166 | 166 |
| 167 substatements[node.tryBody] = tryBlock; | 167 substatements[node.tryBody] = tryBlock; |
| 168 substatements[node.catchBody] = catchBlock; | 168 substatements[node.catchBody] = catchBlock; |
| 169 } | 169 } |
| 170 | 170 |
| 171 visitExpressionStatement(ExpressionStatement node) { | 171 visitExpressionStatement(ExpressionStatement node) { |
| 172 _addStatement(node); | 172 _addStatement(node); |
| 173 visitStatement(node.next); | 173 visitStatement(node.next); |
| 174 } | 174 } |
| 175 |
| 176 visitForeignStatement(ForeignStatement node) { |
| 177 _addStatement(node); |
| 178 } |
| 175 } | 179 } |
| 176 | 180 |
| 177 class TreeTracer extends TracerUtil with StatementVisitor { | 181 class TreeTracer extends TracerUtil with StatementVisitor { |
| 178 String get passName => null; | 182 String get passName => null; |
| 179 | 183 |
| 180 final EventSink<String> output; | 184 final EventSink<String> output; |
| 181 | 185 |
| 182 TreeTracer(this.output); | 186 TreeTracer(this.output); |
| 183 | 187 |
| 184 List<Variable> parameters; | 188 List<Variable> parameters; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 String value = expr(node.value); | 318 String value = expr(node.value); |
| 315 if (SubexpressionVisitor.usesInfixNotation(node.object)) { | 319 if (SubexpressionVisitor.usesInfixNotation(node.object)) { |
| 316 object = '($object)'; | 320 object = '($object)'; |
| 317 } | 321 } |
| 318 printStatement(null, '$object.$field = $value'); | 322 printStatement(null, '$object.$field = $value'); |
| 319 } | 323 } |
| 320 | 324 |
| 321 String expr(Expression e) { | 325 String expr(Expression e) { |
| 322 return e.accept(new SubexpressionVisitor(names)); | 326 return e.accept(new SubexpressionVisitor(names)); |
| 323 } | 327 } |
| 328 |
| 329 @override |
| 330 visitForeignStatement(ForeignStatement node) { |
| 331 printStatement(null, 'foreign'); |
| 332 } |
| 324 } | 333 } |
| 325 | 334 |
| 326 class SubexpressionVisitor extends ExpressionVisitor<String> { | 335 class SubexpressionVisitor extends ExpressionVisitor<String> { |
| 327 Names names; | 336 Names names; |
| 328 | 337 |
| 329 SubexpressionVisitor(this.names); | 338 SubexpressionVisitor(this.names); |
| 330 | 339 |
| 331 String visitVariableUse(VariableUse node) { | 340 String visitVariableUse(VariableUse node) { |
| 332 return names.varName(node.variable); | 341 return names.varName(node.variable); |
| 333 } | 342 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 return node.dartType.toString(); | 513 return node.dartType.toString(); |
| 505 } | 514 } |
| 506 | 515 |
| 507 @override | 516 @override |
| 508 String visitCreateInvocationMirror(CreateInvocationMirror node) { | 517 String visitCreateInvocationMirror(CreateInvocationMirror node) { |
| 509 String args = node.arguments.map(visitExpression).join(', '); | 518 String args = node.arguments.map(visitExpression).join(', '); |
| 510 return 'CreateInvocationMirror(${node.selector.name}, $args)'; | 519 return 'CreateInvocationMirror(${node.selector.name}, $args)'; |
| 511 } | 520 } |
| 512 | 521 |
| 513 @override | 522 @override |
| 523 String visitForeignExpression(ForeignExpression node) { |
| 524 String arguments = node.arguments.map(visitExpression).join(', '); |
| 525 return 'Foreign "${node.codeTemplate}"($arguments)'; |
| 526 } |
| 527 |
| 528 @override |
| 514 String visitApplyBuiltinOperator(ApplyBuiltinOperator node) { | 529 String visitApplyBuiltinOperator(ApplyBuiltinOperator node) { |
| 515 String args = node.arguments.map(visitExpression).join(', '); | 530 String args = node.arguments.map(visitExpression).join(', '); |
| 516 return 'ApplyBuiltinOperator ${node.operator} ($args)'; | 531 return 'ApplyBuiltinOperator ${node.operator} ($args)'; |
| 517 } | 532 } |
| 518 } | 533 } |
| 519 | 534 |
| 520 /** | 535 /** |
| 521 * Invents (and remembers) names for Variables that do not have an associated | 536 * Invents (and remembers) names for Variables that do not have an associated |
| 522 * identifier. | 537 * identifier. |
| 523 * | 538 * |
| (...skipping 11 matching lines...) Expand all Loading... |
| 535 String prefix = v.element == null ? 'v' : '${v.element.name}_'; | 550 String prefix = v.element == null ? 'v' : '${v.element.name}_'; |
| 536 while (name == null || _usedNames.contains(name)) { | 551 while (name == null || _usedNames.contains(name)) { |
| 537 name = "$prefix${_counter++}"; | 552 name = "$prefix${_counter++}"; |
| 538 } | 553 } |
| 539 _names[v] = name; | 554 _names[v] = name; |
| 540 _usedNames.add(name); | 555 _usedNames.add(name); |
| 541 } | 556 } |
| 542 return name; | 557 return name; |
| 543 } | 558 } |
| 544 } | 559 } |
| OLD | NEW |