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

Unified Diff: pkg/csslib/lib/src/tree_base.dart

Issue 23168002: move csslib into dart svn (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
« no previous file with comments | « pkg/csslib/lib/src/tree.dart ('k') | pkg/csslib/lib/src/tree_printer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « pkg/csslib/lib/src/tree.dart ('k') | pkg/csslib/lib/src/tree_printer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698