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

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

Issue 1353843002: dart2js cps: Support sync* and yield. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart ('k') | pkg/pkg.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 171 }
172 172
173 visitExpressionStatement(ExpressionStatement node) { 173 visitExpressionStatement(ExpressionStatement node) {
174 _addStatement(node); 174 _addStatement(node);
175 visitStatement(node.next); 175 visitStatement(node.next);
176 } 176 }
177 177
178 visitForeignStatement(ForeignStatement node) { 178 visitForeignStatement(ForeignStatement node) {
179 _addStatement(node); 179 _addStatement(node);
180 } 180 }
181
182 @override
183 visitYield(Yield node) {
184 _addStatement(node);
185 }
181 } 186 }
182 187
183 class TreeTracer extends TracerUtil with StatementVisitor { 188 class TreeTracer extends TracerUtil with StatementVisitor {
184 String get passName => null; 189 String get passName => null;
185 190
186 final EventSink<String> output; 191 final EventSink<String> output;
187 192
188 TreeTracer(this.output); 193 TreeTracer(this.output);
189 194
190 List<Variable> parameters; 195 List<Variable> parameters;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 } 334 }
330 335
331 String expr(Expression e) { 336 String expr(Expression e) {
332 return e.accept(new SubexpressionVisitor(names)); 337 return e.accept(new SubexpressionVisitor(names));
333 } 338 }
334 339
335 @override 340 @override
336 visitForeignStatement(ForeignStatement node) { 341 visitForeignStatement(ForeignStatement node) {
337 printStatement(null, 'foreign ${node.codeTemplate.source}'); 342 printStatement(null, 'foreign ${node.codeTemplate.source}');
338 } 343 }
344
345 @override
346 visitYield(Yield node) {
347 printStatement(null, 'yield ${expr(node.input)}');
348 }
339 } 349 }
340 350
341 class SubexpressionVisitor extends ExpressionVisitor<String> { 351 class SubexpressionVisitor extends ExpressionVisitor<String> {
342 Names names; 352 Names names;
343 353
344 SubexpressionVisitor(this.names); 354 SubexpressionVisitor(this.names);
345 355
346 String visitVariableUse(VariableUse node) { 356 String visitVariableUse(VariableUse node) {
347 return names.varName(node.variable); 357 return names.varName(node.variable);
348 } 358 }
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 String index = visitExpression(node.index); 572 String index = visitExpression(node.index);
563 String value = visitExpression(node.value); 573 String value = visitExpression(node.value);
564 return 'SetIndex($object, $index, $value)'; 574 return 'SetIndex($object, $index, $value)';
565 } 575 }
566 576
567 @override 577 @override
568 String visitAwait(Await node) { 578 String visitAwait(Await node) {
569 String value = visitExpression(node.input); 579 String value = visitExpression(node.input);
570 return 'Await($value)'; 580 return 'Await($value)';
571 } 581 }
582
583 @override
584 String visitYield(Yield node) {
585 String value = visitExpression(node.input);
586 return 'Yield($value)';
587 }
572 } 588 }
573 589
574 /** 590 /**
575 * Invents (and remembers) names for Variables that do not have an associated 591 * Invents (and remembers) names for Variables that do not have an associated
576 * identifier. 592 * identifier.
577 * 593 *
578 * In case a variable is named v0, v1, etc, it may be assigned a different 594 * In case a variable is named v0, v1, etc, it may be assigned a different
579 * name to avoid clashing with a previously synthesized variable name. 595 * name to avoid clashing with a previously synthesized variable name.
580 */ 596 */
581 class Names { 597 class Names {
582 final Map<Variable, String> _names = {}; 598 final Map<Variable, String> _names = {};
583 final Set<String> _usedNames = new Set(); 599 final Set<String> _usedNames = new Set();
584 int _counter = 0; 600 int _counter = 0;
585 601
586 String varName(Variable v) { 602 String varName(Variable v) {
587 String name = _names[v]; 603 String name = _names[v];
588 if (name == null) { 604 if (name == null) {
589 String prefix = v.element == null ? 'v' : '${v.element.name}_'; 605 String prefix = v.element == null ? 'v' : '${v.element.name}_';
590 while (name == null || _usedNames.contains(name)) { 606 while (name == null || _usedNames.contains(name)) {
591 name = "$prefix${_counter++}"; 607 name = "$prefix${_counter++}";
592 } 608 }
593 _names[v] = name; 609 _names[v] = name;
594 _usedNames.add(name); 610 _usedNames.add(name);
595 } 611 }
596 return name; 612 return name;
597 } 613 }
598 } 614 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart ('k') | pkg/pkg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698