Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: pkg/compiler/lib/src/tree_ir/tree_ir_tracer.dart

Issue 1185633003: cps-ir: Support foreign code. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Status file updates. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 @override 511 @override
503 String visitTypeExpression(TypeExpression node) { 512 String visitTypeExpression(TypeExpression node) {
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 }
521
522 @override
523 String visitForeignExpression(ForeignExpression node) {
524 String arguments = node.arguments.map(visitExpression).join(', ');
525 return 'Foreign "${node.codeTemplate}"($arguments)';
526 }
512 } 527 }
513 528
514 /** 529 /**
515 * Invents (and remembers) names for Variables that do not have an associated 530 * Invents (and remembers) names for Variables that do not have an associated
516 * identifier. 531 * identifier.
517 * 532 *
518 * In case a variable is named v0, v1, etc, it may be assigned a different 533 * In case a variable is named v0, v1, etc, it may be assigned a different
519 * name to avoid clashing with a previously synthesized variable name. 534 * name to avoid clashing with a previously synthesized variable name.
520 */ 535 */
521 class Names { 536 class Names {
522 final Map<Variable, String> _names = {}; 537 final Map<Variable, String> _names = {};
523 final Set<String> _usedNames = new Set(); 538 final Set<String> _usedNames = new Set();
524 int _counter = 0; 539 int _counter = 0;
525 540
526 String varName(Variable v) { 541 String varName(Variable v) {
527 String name = _names[v]; 542 String name = _names[v];
528 if (name == null) { 543 if (name == null) {
529 String prefix = v.element == null ? 'v' : '${v.element.name}_'; 544 String prefix = v.element == null ? 'v' : '${v.element.name}_';
530 while (name == null || _usedNames.contains(name)) { 545 while (name == null || _usedNames.contains(name)) {
531 name = "$prefix${_counter++}"; 546 name = "$prefix${_counter++}";
532 } 547 }
533 _names[v] = name; 548 _names[v] = name;
534 _usedNames.add(name); 549 _usedNames.add(name);
535 } 550 }
536 return name; 551 return name;
537 } 552 }
538 } 553 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698