OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
ahe
2017/03/24 12:00:41
\o/
| |
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 /// This file declares a "shadow hierarchy" of concrete classes which extend | |
6 /// the kernel class hierarchy using mixins from `builder/shadow_ast.dart`. | |
7 /// | |
8 /// Instances of these classes may be created using the factory methods in | |
9 /// `ast_factory.dart`. | |
10 /// | |
11 /// Note that these classes represent the Dart language prior to desugaring. | |
12 /// When a single Dart construct desugars to a tree containing multiple kernel | |
13 /// AST nodes, the shadow class extends the kernel object at the top of the | |
14 /// desugared tree. | |
15 /// | |
16 /// This means that in some cases multiple shadow classes may extend the same | |
17 /// kernel class, because multiple constructs in Dart may desugar to a tree | |
18 /// with the same kind of root node. | |
19 import 'package:kernel/ast.dart' as kernel; | |
20 import 'package:kernel/ast.dart' show DartType; | |
21 | |
22 import '../builder/shadow_ast.dart' as builder; | |
23 | |
24 /// Concrete shadow object representing a statement block in kernel form. | |
25 class Block extends kernel.Block with builder.Block implements Statement { | |
ahe
2017/03/24 12:00:41
KernelBlock?
Paul Berry
2017/03/24 14:55:24
Done.
| |
26 Block(List<Statement> statements) : super(statements); | |
27 | |
28 @override | |
29 List<Statement> get shadowStatements => statements; | |
30 } | |
31 | |
32 /// Common base class for shadow objects representing expressions in kernel | |
33 /// form. | |
34 abstract class Expression implements kernel.Expression, builder.Expression {} | |
35 | |
36 /// Concrete shadow object representing a function expression in kernel form. | |
37 class FunctionExpression extends kernel.FunctionExpression | |
38 with builder.FunctionExpression | |
39 implements Expression { | |
40 FunctionExpression(kernel.FunctionNode function) : super(function); | |
41 | |
42 @override | |
43 Statement get shadowBody => function.body; | |
44 | |
45 @override | |
46 bool get shadowIsAsync { | |
47 // TODO(paulberry): is there a helper function in kernel that does this? | |
48 var asyncMarker = function.asyncMarker; | |
49 return asyncMarker == kernel.AsyncMarker.Async || | |
50 asyncMarker == kernel.AsyncMarker.AsyncStar; | |
51 } | |
52 | |
53 @override | |
54 bool get shadowIsExpressionFunction => | |
55 function.body is kernel.ReturnStatement; | |
56 | |
57 @override | |
58 bool get shadowIsGenerator { | |
59 // TODO(paulberry): is there a helper function in kernel that does this? | |
60 var asyncMarker = function.asyncMarker; | |
61 return asyncMarker == kernel.AsyncMarker.SyncStar || | |
62 asyncMarker == kernel.AsyncMarker.AsyncStar; | |
63 } | |
64 | |
65 @override | |
66 set shadowReturnType(DartType type) { | |
67 function.returnType = type; | |
68 } | |
69 | |
70 @override | |
71 DartType shadowMakeFunctionType() { | |
72 return function.functionType; | |
73 } | |
74 } | |
75 | |
76 /// Concrete shadow object representing an integer literal in kernel form. | |
77 class IntLiteral extends kernel.IntLiteral | |
78 with builder.IntLiteral | |
79 implements Expression { | |
80 IntLiteral(int value) : super(value); | |
81 } | |
82 | |
83 /// Concrete shadow object representing a list literal in kernel form. | |
84 class ListLiteral extends _KernelListLiteral | |
85 with builder.ListLiteral | |
86 implements Expression { | |
87 /// TODO(paulberry): see if we can eliminate the need for this by allowing | |
88 /// `null` to be stored in [kernel.ListLiteral] prior to type inference. | |
89 DartType _declaredTypeArgument; | |
90 | |
91 ListLiteral(List<Expression> expressions, | |
92 {DartType typeArgument, bool isConst: false}) | |
93 : _declaredTypeArgument = typeArgument, | |
94 super(expressions, typeArgument ?? const kernel.DynamicType(), isConst); | |
95 | |
96 @override | |
97 Iterable<Expression> get shadowExpressions { | |
98 List<Expression> shadowExpressions = expressions; | |
99 return shadowExpressions; | |
100 } | |
101 | |
102 @override | |
103 kernel.DartType get shadowTypeArgument => _declaredTypeArgument; | |
104 | |
105 @override | |
106 set shadowTypeArgument(kernel.DartType type) { | |
107 typeArgument = type; | |
108 } | |
109 } | |
110 | |
111 /// Concrete shadow object representing a null literal in kernel form. | |
112 class NullLiteral extends kernel.NullLiteral | |
113 with builder.NullLiteral | |
114 implements Expression {} | |
115 | |
116 /// Concrete shadow object representing a return statement in kernel form. | |
117 class ReturnStatement extends _KernelReturnStatement | |
118 with builder.ReturnStatement | |
119 implements Statement { | |
120 ReturnStatement([Expression expression]) : super(expression); | |
121 | |
122 @override | |
123 Expression get shadowExpression => expression; | |
124 } | |
125 | |
126 /// Common base class for shadow objects representing statements in kernel | |
127 /// form. | |
128 abstract class Statement extends kernel.Statement implements builder.Statement { | |
129 } | |
130 | |
131 /// Concrete shadow object representing a variable declaration in kernel form. | |
132 class VariableDeclaration extends _KernelVariableDeclaration | |
133 with builder.VariableDeclaration | |
134 implements Statement { | |
135 /// TODO(paulberry): see if we can eliminate the need for this by allowing | |
136 /// `null` to be stored in [kernel.VariableDeclaration] prior to type inferenc e. | |
ahe
2017/03/24 12:00:40
Alternative: create a subclass of DynamicType call
ahe
2017/03/24 12:00:41
Long line.
Paul Berry
2017/03/24 14:55:24
Done.
Paul Berry
2017/03/24 14:55:24
Interesting idea. I've noted it in the TODO.
| |
137 DartType _declaredType; | |
138 | |
139 VariableDeclaration(String name, | |
140 {Expression initializer, | |
141 DartType type, | |
142 bool isFinal: false, | |
143 bool isConst: false}) | |
144 : _declaredType = type, | |
145 super(name, initializer, type ?? const kernel.DynamicType(), null, | |
146 isFinal, isConst); | |
147 | |
148 @override | |
149 Expression get shadowInitializer => initializer; | |
150 | |
151 @override | |
152 DartType get shadowType => _declaredType; | |
153 | |
154 @override | |
155 set shadowType(kernel.DartType type) { | |
156 this.type = type; | |
157 } | |
158 | |
159 @override | |
160 set type(kernel.DartType type) { | |
161 super.type = _declaredType = type; | |
162 } | |
163 } | |
164 | |
165 /// Concrete shadow object representing a read from a variable in kernel form. | |
166 class VariableGet extends _KernelVariableGet | |
167 with builder.VariableGet | |
168 implements Expression { | |
169 VariableGet(kernel.VariableDeclaration variable, [DartType promotedType]) | |
170 : super(variable, promotedType); | |
171 | |
172 @override | |
173 VariableDeclaration get shadowDeclaration => variable; | |
174 } | |
175 | |
176 /// Adaptor class allowing [kernel.ListLiteral] to be extended with a mixin. | |
177 /// | |
178 /// TODO(paulberry): see if we can eliminate the need for this class by adding | |
179 /// a named constructor to [kernel.ListLiteral] in which all arguments are | |
180 /// required. | |
181 class _KernelListLiteral extends kernel.ListLiteral { | |
182 _KernelListLiteral( | |
183 List<kernel.Expression> expressions, DartType typeArgument, bool isConst) | |
184 : super(expressions, typeArgument: typeArgument, isConst: isConst); | |
185 } | |
186 | |
187 /// Adaptor class allowing [kernel.ReturnStatement] to be extended with a mixin. | |
188 /// | |
189 /// TODO(paulberry): see if we can eliminate the need for this class by adding | |
190 /// a named constructor to [kernel.ReturnStatement] in which all arguments are | |
191 /// required. | |
192 class _KernelReturnStatement extends kernel.ReturnStatement { | |
193 _KernelReturnStatement(Expression expression) : super(expression); | |
194 } | |
195 | |
196 /// Adaptor class allowing [kernel.VariableDeclaration] to be extended with a | |
197 /// mixin. | |
198 /// | |
199 /// TODO(paulberry): see if we can eliminate the need for this class by adding | |
200 /// a named constructor to [kernel.VariableDeclaration] in which all arguments | |
201 /// are required. | |
202 class _KernelVariableDeclaration extends kernel.VariableDeclaration { | |
203 _KernelVariableDeclaration( | |
204 String name, | |
205 kernel.Expression initializer, | |
206 DartType type, | |
207 kernel.InferredValue inferredValue, | |
208 bool isFinal, | |
209 bool isConst) | |
210 : super(name, | |
211 initializer: initializer, | |
212 type: type, | |
213 inferredValue: inferredValue, | |
214 isFinal: isFinal, | |
215 isConst: isConst); | |
216 } | |
217 | |
218 /// Adaptor class allowing [kernel.VariableGet] to be extended with a mixin. | |
219 /// | |
220 /// TODO(paulberry): see if we can eliminate the need for this class by adding | |
221 /// a named constructor to [kernel.VariableGet] in which all arguments are | |
222 /// required. | |
223 class _KernelVariableGet extends kernel.VariableGet { | |
224 _KernelVariableGet(kernel.VariableDeclaration variable, DartType promotedType) | |
225 : super(variable, promotedType); | |
226 } | |
OLD | NEW |