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

Unified 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: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart
diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart
index d25af39fcfef36600f263d3db575224f16940da6..f4e82fd0d917096dbec803810b8d4644462f9811 100644
--- a/pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart
+++ b/pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart
@@ -7,12 +7,19 @@ library dart2js.ir_nodes_sexpr;
import '../util/util.dart';
import 'cps_ir_nodes.dart';
+/// A [Decorator] is a function used by [SExpressionStringifier] to augment the
+/// output produced for a node. It can be provided to the constructor.
+typedef String Decorator(Node node, String s);
+
/// Generate a Lisp-like S-expression representation of an IR node as a string.
class SExpressionStringifier extends Visitor<String> with Indentation {
final _Namer namer = new _Namer();
String newValueName(Node node) => namer.defineValueName(node);
String newContinuationName(Node node) => namer.defineContinuationName(node);
+ final Decorator decorator;
+
+ SExpressionStringifier([this.decorator]);
String access(Reference<Definition> r) => namer.getName(r.definition);
@@ -20,6 +27,13 @@ class SExpressionStringifier extends Visitor<String> with Indentation {
return namer.useElementName(node);
}
+ /// Main entry point for creating a [String] from a [Node]. All recursive
+ /// calls must go through this method.
+ String visit(Node node) {
+ String s = super.visit(node);
+ return (decorator != null) ? decorator(node, s) : s;
sigurdm 2014/11/27 12:53:37 One fewer negations: return decorator == null ? s
karlklose 2014/11/27 13:25:14 Done.
+ }
+
String visitFunctionDefinition(FunctionDefinition node) {
String name = node.element.name;
namer.useReturnName(node.returnContinuation);
« 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