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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart

Issue 766723002: Add an optional decorator to SExprStringifier to augment the output of nodes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 6 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 dart2js.ir_nodes_sexpr; 5 library dart2js.ir_nodes_sexpr;
6 6
7 import '../util/util.dart'; 7 import '../util/util.dart';
8 import 'cps_ir_nodes.dart'; 8 import 'cps_ir_nodes.dart';
9 9
10 /// A [Decorator] is a function used by [SExpressionStringifier] to augment the
11 /// output produced for a node. It can be provided to the constructor.
12 typedef String Decorator(Node node, String s);
13
10 /// Generate a Lisp-like S-expression representation of an IR node as a string. 14 /// Generate a Lisp-like S-expression representation of an IR node as a string.
11 class SExpressionStringifier extends Visitor<String> with Indentation { 15 class SExpressionStringifier extends Visitor<String> with Indentation {
12 final _Namer namer = new _Namer(); 16 final _Namer namer = new _Namer();
13 17
14 String newValueName(Node node) => namer.defineValueName(node); 18 String newValueName(Node node) => namer.defineValueName(node);
15 String newContinuationName(Node node) => namer.defineContinuationName(node); 19 String newContinuationName(Node node) => namer.defineContinuationName(node);
20 final Decorator decorator;
21
22 SExpressionStringifier([this.decorator]);
16 23
17 String access(Reference<Definition> r) => namer.getName(r.definition); 24 String access(Reference<Definition> r) => namer.getName(r.definition);
18 25
19 String visitParameter(Parameter node) { 26 String visitParameter(Parameter node) {
20 return namer.useElementName(node); 27 return namer.useElementName(node);
21 } 28 }
22 29
30 /// Main entry point for creating a [String] from a [Node]. All recursive
31 /// calls must go through this method.
32 String visit(Node node) {
33 String s = super.visit(node);
34 return (decorator == null) ? s : decorator(node, s);
35 }
36
23 String visitFunctionDefinition(FunctionDefinition node) { 37 String visitFunctionDefinition(FunctionDefinition node) {
24 String name = node.element.name; 38 String name = node.element.name;
25 namer.useReturnName(node.returnContinuation); 39 namer.useReturnName(node.returnContinuation);
26 String parameters = node.parameters.map(visit).join(' '); 40 String parameters = node.parameters.map(visit).join(' ');
27 String body = indentBlock(() => visit(node.body)); 41 String body = indentBlock(() => visit(node.body));
28 return '$indentation(FunctionDefinition $name ($parameters return)\n' 42 return '$indentation(FunctionDefinition $name ($parameters return)\n'
29 '$body)'; 43 '$body)';
30 } 44 }
31 45
32 String visitLetPrim(LetPrim node) { 46 String visitLetPrim(LetPrim node) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 String useReturnName(Continuation node) { 228 String useReturnName(Continuation node) {
215 assert(!_names.containsKey(node) || _names[node] == 'return'); 229 assert(!_names.containsKey(node) || _names[node] == 'return');
216 return _names[node] = 'return'; 230 return _names[node] = 'return';
217 } 231 }
218 232
219 String getName(Node node) { 233 String getName(Node node) {
220 assert(_names.containsKey(node)); 234 assert(_names.containsKey(node));
221 return _names[node]; 235 return _names[node];
222 } 236 }
223 } 237 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698