OLD | NEW |
---|---|
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
6 | 6 |
7 import '../closure.dart'; | 7 import '../closure.dart'; |
8 import '../common.dart'; | 8 import '../common.dart'; |
9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
10 import '../common_elements.dart'; | 10 import '../common_elements.dart'; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 | 157 |
158 /// Interface that translates between Kernel IR nodes and entities used for | 158 /// Interface that translates between Kernel IR nodes and entities used for |
159 /// global type inference and building the SSA graph for members. | 159 /// global type inference and building the SSA graph for members. |
160 abstract class KernelToElementMapForBuilding implements KernelToElementMap { | 160 abstract class KernelToElementMapForBuilding implements KernelToElementMap { |
161 /// [ElementEnvironment] for library, class and member lookup. | 161 /// [ElementEnvironment] for library, class and member lookup. |
162 ElementEnvironment get elementEnvironment; | 162 ElementEnvironment get elementEnvironment; |
163 | 163 |
164 /// Returns the list of [DartType]s corresponding to [types]. | 164 /// Returns the list of [DartType]s corresponding to [types]. |
165 List<DartType> getDartTypes(List<ir.DartType> types); | 165 List<DartType> getDartTypes(List<ir.DartType> types); |
166 | 166 |
167 /// Returns the kernel IR node that defines the [member]. | 167 /// Returns the definition information for [member]. |
168 ir.Node getMemberNode(covariant MemberEntity member); | 168 MemberDefinition getMemberDefinition(covariant MemberEntity member); |
169 | 169 |
170 /// Returns the kernel IR node that defines the [cls]. | 170 /// Returns the definition information for [cls]. |
171 ir.Class getClassNode(covariant ClassEntity cls); | 171 ClassDefinition getClassDefinition(covariant ClassEntity cls); |
172 | 172 |
173 /// Returns the [LibraryEntity] corresponding to the library [node]. | 173 /// Returns the [LibraryEntity] corresponding to the library [node]. |
174 LibraryEntity getLibrary(ir.Library node); | 174 LibraryEntity getLibrary(ir.Library node); |
175 | 175 |
176 /// Returns the [js.Template] for the `JsBuiltin` [constant] value. | 176 /// Returns the [js.Template] for the `JsBuiltin` [constant] value. |
177 js.Template getJsBuiltinTemplate( | 177 js.Template getJsBuiltinTemplate( |
178 ConstantValue constant, CodeEmitterTask emitter); | 178 ConstantValue constant, CodeEmitterTask emitter); |
179 | 179 |
180 /// Return the [ConstantValue] the initial value of [field] or `null` if | 180 /// Return the [ConstantValue] the initial value of [field] or `null` if |
181 /// the initializer is not a constant expression. | 181 /// the initializer is not a constant expression. |
182 ConstantValue getFieldConstantValue(ir.Field field); | 182 ConstantValue getFieldConstantValue(ir.Field field); |
183 | 183 |
184 /// Returns the `noSuchMethod` [FunctionEntity] call from a | 184 /// Returns the `noSuchMethod` [FunctionEntity] call from a |
185 /// `super.noSuchMethod` invocation within [cls]. | 185 /// `super.noSuchMethod` invocation within [cls]. |
186 FunctionEntity getSuperNoSuchMethod(ClassEntity cls); | 186 FunctionEntity getSuperNoSuchMethod(ClassEntity cls); |
187 | 187 |
188 /// Returns a [Spannable] for a message pointing to the IR [node] in the | 188 /// Returns a [Spannable] for a message pointing to the IR [node] in the |
189 /// context of [member]. | 189 /// context of [member]. |
190 Spannable getSpannable(MemberEntity member, ir.Node node); | 190 Spannable getSpannable(MemberEntity member, ir.Node node); |
191 | 191 |
192 /// Returns the constructor body entity corresponding to [constructor]. | 192 /// Returns the constructor body entity corresponding to [constructor]. |
193 FunctionEntity getConstructorBody(ir.Constructor node); | 193 FunctionEntity getConstructorBody(ir.Constructor node); |
194 | 194 |
195 /// Returns the uri for the deferred import [node]. | 195 /// Returns the uri for the deferred import [node]. |
196 // TODO(johnniwinther): Avoid this method by deriving the uri directly from | 196 // TODO(johnniwinther): Avoid this method by deriving the uri directly from |
197 // the node. | 197 // the node. |
198 String getDeferredUri(ir.LibraryDependency node); | 198 String getDeferredUri(ir.LibraryDependency node); |
199 } | 199 } |
200 | 200 |
201 // TODO(johnniwinther,efortuna): Add more when needed. | |
202 // TODO(johnniwinther): Should we split regular into method, field, etc.? | |
203 enum MemberKind { | |
204 // A regular member defined by an [ir.Node]. | |
205 regular, | |
206 // A constructor whose initializer is defined by an [ir.Constructor] node. | |
207 constructor, | |
208 // A constructor whose body is defined by an [ir.Constructor] node. | |
209 constructorBody, | |
210 // A closure class `call` method whose body is defined by an | |
211 // [ir.FunctionExpression]. | |
212 closureCall, | |
213 } | |
214 | |
215 /// Definition information for a [MemberEntity]. | |
216 abstract class MemberDefinition { | |
217 /// The defined member. | |
218 MemberEntity get member; | |
219 | |
220 /// The kind of the defined member. This determines the semantics of [node]. | |
221 MemberKind get kind; | |
222 | |
223 /// The defining [ir.Node] for this member, if supported by its [kind]. | |
224 ir.Node get node; | |
225 | |
226 /// The canonical location of [member]. This is used for sorting the members | |
227 /// in the emitted code. | |
228 ir.Location get location; | |
229 } | |
230 | |
231 enum ClassKind { | |
232 regular, | |
233 closure, | |
234 } | |
235 | |
236 /// A member directly defined by its [ir.Member] node. | |
237 class RegularMemberDefinition implements MemberDefinition { | |
238 final MemberEntity member; | |
239 final ir.Member node; | |
240 | |
241 RegularMemberDefinition(this.member, this.node); | |
242 | |
243 ir.Location get location => node.location; | |
244 | |
245 MemberKind get kind => MemberKind.regular; | |
246 | |
247 String toString() => 'RegularMemberDefinition(kind:$kind,member:$member,' | |
248 'node:$node,location:$location)'; | |
249 } | |
250 | |
251 /// The definition of a special kind of member | |
252 class SpecialMemberDefinition implements MemberDefinition { | |
253 final MemberEntity member; | |
254 final ir.TreeNode node; | |
255 final MemberKind kind; | |
256 | |
257 SpecialMemberDefinition(this.member, this.node, this.kind); | |
258 | |
259 ir.Location get location => node.location; | |
260 | |
261 String toString() => 'SpecialMemberDefinition(kind:$kind,member:$member,' | |
262 'node:$node,location:$location)'; | |
263 } | |
264 | |
265 /// Definition information for a [ClassEntity]. | |
266 abstract class ClassDefinition { | |
267 /// The defined class. | |
268 ClassEntity get cls; | |
269 | |
270 /// The kind of the defined class. This determines the semantics of [node]. | |
271 ClassKind get kind; | |
272 | |
273 /// The defining [ir.Node] for this class, if supported by its [kind]. | |
274 ir.Node get node; | |
Emily Fortuna
2017/07/19 21:38:58
why not ir.Class here? Is this so that node can be
Johnni Winther
2017/07/21 07:47:57
Done.
| |
275 | |
276 /// The canonical location of [cls]. This is used for sorting the classes | |
277 /// in the emitted code. | |
278 ir.Location get location; | |
279 } | |
280 | |
281 /// A class directly defined by its [ir.Class] node. | |
282 class RegularClassDefinition implements ClassDefinition { | |
283 final ClassEntity cls; | |
284 final ir.Class node; | |
285 | |
286 RegularClassDefinition(this.cls, this.node); | |
287 | |
288 ir.Location get location => node.location; | |
289 | |
290 ClassKind get kind => ClassKind.regular; | |
291 | |
292 String toString() => 'RegularClassDefinition(kind:$kind,cls:$cls,' | |
293 'node:$node,location:$location)'; | |
294 } | |
295 | |
201 /// Kinds of foreign functions. | 296 /// Kinds of foreign functions. |
202 enum ForeignKind { | 297 enum ForeignKind { |
203 JS, | 298 JS, |
204 JS_BUILTIN, | 299 JS_BUILTIN, |
205 JS_EMBEDDED_GLOBAL, | 300 JS_EMBEDDED_GLOBAL, |
206 JS_INTERCEPTOR_CONSTANT, | 301 JS_INTERCEPTOR_CONSTANT, |
207 NONE, | 302 NONE, |
208 } | 303 } |
209 | 304 |
210 /// Interface for type inference results for kernel IR nodes. | 305 /// Interface for type inference results for kernel IR nodes. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 /// [closureClassMaps]. | 414 /// [closureClassMaps]. |
320 CapturedLoopScope getCapturedLoopScope( | 415 CapturedLoopScope getCapturedLoopScope( |
321 ClosureDataLookup closureLookup, ir.TreeNode node); | 416 ClosureDataLookup closureLookup, ir.TreeNode node); |
322 } | 417 } |
323 | 418 |
324 /// Comparator for the canonical order or named arguments. | 419 /// Comparator for the canonical order or named arguments. |
325 // TODO(johnniwinther): Remove this when named parameters are sorted in dill. | 420 // TODO(johnniwinther): Remove this when named parameters are sorted in dill. |
326 int namedOrdering(ir.VariableDeclaration a, ir.VariableDeclaration b) { | 421 int namedOrdering(ir.VariableDeclaration a, ir.VariableDeclaration b) { |
327 return a.name.compareTo(b.name); | 422 return a.name.compareTo(b.name); |
328 } | 423 } |
OLD | NEW |