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