OLD | NEW |
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 final Span span; | 12 final SourceSpan 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 void 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(SourceSpan 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 VisitorBase 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); |
50 buf.write('\n'); | 50 buf.write('\n'); |
51 } | 51 } |
52 | 52 |
53 void heading(String name, [span]) { | 53 void heading(String name, [span]) { |
54 write(name); | 54 write(name); |
55 if (span != null) { | 55 if (span != null) { |
56 buf.write(' (${span.getLocationMessage('')})'); | 56 buf.write(' (${span.message('')})'); |
57 } | 57 } |
58 buf.write('\n'); | 58 buf.write('\n'); |
59 } | 59 } |
60 | 60 |
61 String toValue(value) { | 61 String toValue(value) { |
62 if (value == null) return 'null'; | 62 if (value == null) return 'null'; |
63 else if (value is Identifier) return value.name; | 63 else if (value is Identifier) return value.name; |
64 else return value.toString(); | 64 else return value.toString(); |
65 } | 65 } |
66 | 66 |
(...skipping 21 matching lines...) Expand all Loading... |
88 writeln('null'); | 88 writeln('null'); |
89 } | 89 } |
90 } | 90 } |
91 depth -= 1; | 91 depth -= 1; |
92 writeln(']'); | 92 writeln(']'); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 String toString() => buf.toString(); | 96 String toString() => buf.toString(); |
97 } | 97 } |
OLD | NEW |