OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 * The base type for all nodes in a dart abstract syntax tree. | 5 * The base type for all nodes in a dart abstract syntax tree. |
6 */ | 6 */ |
7 class Node { | 7 class Node { |
8 /** The source code this [Node] represents. */ | 8 /** The source code this [Node] represents. */ |
9 SourceSpan span; | 9 SourceSpan span; |
10 | 10 |
11 Node(this.span) {} | 11 Node(this.span) {} |
12 | 12 |
13 /** Classic double-dispatch visitor for implementing passes. */ | 13 /** Classic double-dispatch visitor for implementing passes. */ |
14 abstract visit(TreeVisitor visitor); | 14 abstract visit(TreeVisitor visitor); |
15 | 15 |
16 /** A multiline string showing the node and its children. */ | 16 /** A multiline string showing the node and its children. */ |
17 String toDebugString() { | 17 String toDebugString() { |
18 var to = new TreeOutput(); | 18 var to = new TreeOutput(); |
19 var tp = new TreePrinter(to); | 19 var tp = new TreePrinter(to); |
20 this.visit(tp); | 20 this.visit(tp); |
21 return to.buf.toString(); | 21 return to.buf.toString(); |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 /** Represents all definitions allowed at the top-level. */ | 25 /** Represents all definitions allowed at the top-level. */ |
26 class Definition extends Statement { | 26 class Definition extends Statement { |
27 Definition(SourceSpan span): super(span) {} | 27 Definition(SourceSpan span): super(span) {} |
28 | 28 |
29 List<TypeParameter> get typeParameters() => null; | 29 List<TypeParameter> get typeParameters() => null; |
30 String get nativeType() => null; | 30 NativeType get nativeType() => null; |
31 } | 31 } |
32 | 32 |
33 /** The base type for statements. */ | 33 /** The base type for statements. */ |
34 class Statement extends Node { | 34 class Statement extends Node { |
35 Statement(SourceSpan span): super(span) {} | 35 Statement(SourceSpan span): super(span) {} |
36 } | 36 } |
37 | 37 |
38 /** The base type for expressions. */ | 38 /** The base type for expressions. */ |
39 class Expression extends Node { | 39 class Expression extends Node { |
40 Expression(SourceSpan span): super(span) {} | 40 Expression(SourceSpan span): super(span) {} |
41 } | 41 } |
42 | 42 |
| 43 /** The base type for a reference to a [Type]. */ |
43 class TypeReference extends Node { | 44 class TypeReference extends Node { |
44 Type type; | 45 TypeReference(SourceSpan span): super(span) {} |
45 TypeReference(SourceSpan span, [this.type=null]): super(span) {} | |
46 | |
47 visit(TreeVisitor visitor) => visitor.visitTypeReference(this); | |
48 | |
49 bool get isFinal() => false; | |
50 } | 46 } |
51 | 47 |
52 // TODO(jimhug): Clean-up and factor out of core. | 48 // TODO(jimhug): Clean-up and factor out of core. |
53 /** Simple class to provide a textual dump of trees for debugging. */ | 49 /** Simple class to provide a textual dump of trees for debugging. */ |
54 class TreeOutput { | 50 class TreeOutput { |
55 int depth; | 51 int depth; |
56 StringBuffer buf; | 52 StringBuffer buf; |
57 | 53 |
58 var printer; | 54 var printer; |
59 | 55 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 node.visit(printer); | 122 node.visit(printer); |
127 } else { | 123 } else { |
128 writeln('null'); | 124 writeln('null'); |
129 } | 125 } |
130 } | 126 } |
131 depth -= 1; | 127 depth -= 1; |
132 writeln(']'); | 128 writeln(']'); |
133 } | 129 } |
134 } | 130 } |
135 } | 131 } |
OLD | NEW |