Index: pkg/csslib/lib/src/tree_base.dart |
diff --git a/utils/template/tree.dart b/pkg/csslib/lib/src/tree_base.dart |
similarity index 63% |
copy from utils/template/tree.dart |
copy to pkg/csslib/lib/src/tree_base.dart |
index 6fd1cf0972cd4f971c217c01040a8dbb81f02349..31411d6d06013e62211f9cfe49e0130dafeb6340 100644 |
--- a/utils/template/tree.dart |
+++ b/pkg/csslib/lib/src/tree_base.dart |
@@ -1,44 +1,41 @@ |
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
+ |
+part of csslib.visitor; |
+ |
/** |
- * The base type for all nodes in a dart abstract syntax tree. |
+ * The base type for all nodes in a CSS abstract syntax tree. |
*/ |
-class ASTNode { |
- /** The source code this [ASTNode] represents. */ |
- SourceSpan span; |
+abstract class TreeNode { |
+ /** The source code this [TreeNode] represents. */ |
+ Span span; |
- ASTNode(this.span) {} |
+ TreeNode(this.span) {} |
/** Classic double-dispatch visitor for implementing passes. */ |
- abstract visit(TreeVisitor visitor); |
+ visit(VisitorBase visitor); |
/** A multiline string showing the node and its children. */ |
String toDebugString() { |
var to = new TreeOutput(); |
- var tp = new TreePrinter(to); |
+ var tp = new _TreePrinter(to, true); |
this.visit(tp); |
return to.buf.toString(); |
} |
} |
-// TODO(jimhug): Clean-up and factor out of core. |
+/** The base type for expressions. */ |
+abstract class Expression extends TreeNode { |
+ Expression(Span span): super(span); |
+} |
+ |
/** Simple class to provide a textual dump of trees for debugging. */ |
class TreeOutput { |
- int depth; |
- StringBuffer buf; |
- |
+ int depth = 0; |
+ final StringBuffer buf = new StringBuffer(); |
var printer; |
- static void dump(ASTNode node) { |
- var o = new TreeOutput(); |
- node.visit(new TreePrinter(o)); |
- print(o.buf); |
- } |
- |
- TreeOutput(): this.depth = 0, this.buf = new StringBuffer() { |
- } |
- |
void write(String s) { |
for (int i=0; i < depth; i++) { |
buf.write(' '); |
@@ -47,12 +44,16 @@ class TreeOutput { |
} |
void writeln(String s) { |
- buf.writeln(s); |
+ write(s); |
+ buf.write('\n'); |
} |
- void heading(String name, span) { |
+ void heading(String name, [span]) { |
write(name); |
- buf.writeln(' (${span.locationText})'); |
+ if (span != null) { |
+ buf.write(' (${span.getLocationMessage('')})'); |
+ } |
+ buf.write('\n'); |
} |
String toValue(value) { |
@@ -61,8 +62,8 @@ class TreeOutput { |
else return value.toString(); |
} |
- void writeNode(String label, ASTNode node) { |
- write(label + ': '); |
+ void writeNode(String label, TreeNode node) { |
+ write('${label}: '); |
depth += 1; |
if (node != null) node.visit(printer); |
else writeln('null'); |
@@ -75,9 +76,10 @@ class TreeOutput { |
} |
void writeList(String label, List list) { |
- write(label + ': '); |
+ write('${label}: '); |
if (list == null) { |
- buf.writeln('null'); |
+ buf.write('null'); |
+ buf.write('\n'); |
} else { |
for (var item in list) { |
buf.write(item.toString()); |
@@ -102,4 +104,6 @@ class TreeOutput { |
writeln(']'); |
} |
} |
+ |
+ String toString() => buf.toString(); |
} |