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

Side by Side Diff: utils/template/tree.dart

Issue 137013002: Removed obsolete code (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Removed libraries not used Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/template/tool.dart ('k') | utils/template/uitest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4 /**
5 * The base type for all nodes in a dart abstract syntax tree.
6 */
7 class ASTNode {
8 /** The source code this [ASTNode] represents. */
9 SourceSpan span;
10
11 ASTNode(this.span) {}
12
13 /** Classic double-dispatch visitor for implementing passes. */
14 abstract visit(TreeVisitor visitor);
15
16 /** A multiline string showing the node and its children. */
17 String toDebugString() {
18 var to = new TreeOutput();
19 var tp = new TreePrinter(to);
20 this.visit(tp);
21 return to.buf.toString();
22 }
23 }
24
25 // TODO(jimhug): Clean-up and factor out of core.
26 /** Simple class to provide a textual dump of trees for debugging. */
27 class TreeOutput {
28 int depth;
29 StringBuffer buf;
30
31 var printer;
32
33 static void dump(ASTNode node) {
34 var o = new TreeOutput();
35 node.visit(new TreePrinter(o));
36 print(o.buf);
37 }
38
39 TreeOutput(): this.depth = 0, this.buf = new StringBuffer() {
40 }
41
42 void write(String s) {
43 for (int i=0; i < depth; i++) {
44 buf.write(' ');
45 }
46 buf.write(s);
47 }
48
49 void writeln(String s) {
50 buf.writeln(s);
51 }
52
53 void heading(String name, span) {
54 write(name);
55 buf.writeln(' (${span.locationText})');
56 }
57
58 String toValue(value) {
59 if (value == null) return 'null';
60 else if (value is Identifier) return value.name;
61 else return value.toString();
62 }
63
64 void writeNode(String label, ASTNode node) {
65 write(label + ': ');
66 depth += 1;
67 if (node != null) node.visit(printer);
68 else writeln('null');
69 depth -= 1;
70 }
71
72 void writeValue(String label, value) {
73 var v = toValue(value);
74 writeln('${label}: ${v}');
75 }
76
77 void writeList(String label, List list) {
78 write(label + ': ');
79 if (list == null) {
80 buf.writeln('null');
81 } else {
82 for (var item in list) {
83 buf.write(item.toString());
84 buf.write(', ');
85 }
86 buf.write('\n');
87 }
88 }
89
90 void writeNodeList(String label, List list) {
91 writeln('${label} [');
92 if (list != null) {
93 depth += 1;
94 for (var node in list) {
95 if (node != null) {
96 node.visit(printer);
97 } else {
98 writeln('null');
99 }
100 }
101 depth -= 1;
102 writeln(']');
103 }
104 }
105 }
OLDNEW
« no previous file with comments | « utils/template/tool.dart ('k') | utils/template/uitest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698