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

Unified Diff: lib/compiler/implementation/tree/unparser.dart

Issue 10919033: Rework Unparser/unparse StringBuffer management. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: lib/compiler/implementation/tree/unparser.dart
diff --git a/lib/compiler/implementation/tree/unparser.dart b/lib/compiler/implementation/tree/unparser.dart
index fe6a4935ff48e0803ebcb9ca0d85f2a0f394c300..7adb555d246ce6089e8c489fb2b3d0a7e608c091 100644
--- a/lib/compiler/implementation/tree/unparser.dart
+++ b/lib/compiler/implementation/tree/unparser.dart
@@ -5,21 +5,28 @@
// Returns null if no need to rename a node.
typedef String Renamer(Node node);
+String unparse(Node node) {
+ Unparser unparser = new Unparser();
+ unparser.visit(node);
+ return unparser.result;
+}
+
class Unparser implements Visitor {
Renamer rename;
- StringBuffer sb;
+ final StringBuffer sb;
+
+ String get result => sb.toString();
- Unparser() {
+ Unparser() : sb = new StringBuffer() {
// TODO(smok): Move this to initializer once dart2js stops complaining
// about closures in initializers.
rename = (Node node) => null;
}
- Unparser.withRenamer(this.rename);
+ Unparser.withRenamer(this.rename) : sb = new StringBuffer();
- String unparse(Node node) {
- sb = new StringBuffer();
- visit(node);
- return sb.toString();
+ // TODO(antonm): will go away soon.
+ void addString(String s) {
+ sb.add(s);
}
void add(SourceString string) {

Powered by Google App Engine
This is Rietveld 408576698