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

Side by Side Diff: pkg/csslib/lib/src/tree_base.dart

Issue 64373003: pkg/csslib: types, fixes, cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: more Created 7 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of csslib.visitor; 5 part of csslib.visitor;
6 6
7 /** 7 /**
8 * The base type for all nodes in a CSS abstract syntax tree. 8 * The base type for all nodes in a CSS abstract syntax tree.
9 */ 9 */
10 abstract class TreeNode { 10 abstract class TreeNode {
11 /** The source code this [TreeNode] represents. */ 11 /** The source code this [TreeNode] represents. */
12 Span span; 12 final Span span;
13 13
14 TreeNode(this.span) {} 14 TreeNode(this.span);
15 15
16 TreeNode clone(); 16 TreeNode clone();
17 17
18 /** Classic double-dispatch visitor for implementing passes. */ 18 /** Classic double-dispatch visitor for implementing passes. */
19 visit(VisitorBase visitor); 19 void visit(VisitorBase visitor);
20 20
21 /** A multiline string showing the node and its children. */ 21 /** A multiline string showing the node and its children. */
22 String toDebugString() { 22 String toDebugString() {
23 var to = new TreeOutput(); 23 var to = new TreeOutput();
24 var tp = new _TreePrinter(to, true); 24 var tp = new _TreePrinter(to, true);
25 this.visit(tp); 25 this.visit(tp);
26 return to.buf.toString(); 26 return to.buf.toString();
27 } 27 }
28 } 28 }
29 29
30 /** The base type for expressions. */ 30 /** The base type for expressions. */
31 abstract class Expression extends TreeNode { 31 abstract class Expression extends TreeNode {
32 Expression(Span span): super(span); 32 Expression(Span span): super(span);
33 } 33 }
34 34
35 /** Simple class to provide a textual dump of trees for debugging. */ 35 /** Simple class to provide a textual dump of trees for debugging. */
36 class TreeOutput { 36 class TreeOutput {
37 int depth = 0; 37 int depth = 0;
38 final StringBuffer buf = new StringBuffer(); 38 final StringBuffer buf = new StringBuffer();
39 var printer; 39 VisitorBase printer;
40 40
41 void write(String s) { 41 void write(String s) {
42 for (int i=0; i < depth; i++) { 42 for (int i=0; i < depth; i++) {
43 buf.write(' '); 43 buf.write(' ');
44 } 44 }
45 buf.write(s); 45 buf.write(s);
46 } 46 }
47 47
48 void writeln(String s) { 48 void writeln(String s) {
49 write(s); 49 write(s);
(...skipping 20 matching lines...) Expand all
70 if (node != null) node.visit(printer); 70 if (node != null) node.visit(printer);
71 else writeln('null'); 71 else writeln('null');
72 depth -= 1; 72 depth -= 1;
73 } 73 }
74 74
75 void writeValue(String label, value) { 75 void writeValue(String label, value) {
76 var v = toValue(value); 76 var v = toValue(value);
77 writeln('${label}: ${v}'); 77 writeln('${label}: ${v}');
78 } 78 }
79 79
80 void writeList(String label, List list) { 80 void writeList(String label, List<TreeNode> list) {
81 write('${label}: '); 81 write('${label}: ');
82 if (list == null) { 82 if (list == null) {
83 buf.write('null'); 83 buf.write('null');
84 buf.write('\n'); 84 buf.write('\n');
85 } else { 85 } else {
86 for (var item in list) { 86 for (var item in list) {
87 buf.write(item.toString()); 87 buf.write(item.toString());
88 buf.write(', '); 88 buf.write(', ');
89 } 89 }
90 buf.write('\n'); 90 buf.write('\n');
91 } 91 }
92 } 92 }
93 93
94 void writeNodeList(String label, List list) { 94 void writeNodeList(String label, List<TreeNode> list) {
95 writeln('${label} ['); 95 writeln('${label} [');
96 if (list != null) { 96 if (list != null) {
97 depth += 1; 97 depth += 1;
98 for (var node in list) { 98 for (var node in list) {
99 if (node != null) { 99 if (node != null) {
100 node.visit(printer); 100 node.visit(printer);
101 } else { 101 } else {
102 writeln('null'); 102 writeln('null');
103 } 103 }
104 } 104 }
105 depth -= 1; 105 depth -= 1;
106 writeln(']'); 106 writeln(']');
107 } 107 }
108 } 108 }
109 109
110 String toString() => buf.toString(); 110 String toString() => buf.toString();
111 } 111 }
OLDNEW
« 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