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 library dart2js.js_emitter.native_emitter; | 5 library dart2js.js_emitter.native_emitter; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
9 import '../elements/types.dart' show DartType, FunctionType; | 9 import '../elements/types.dart' show DartType, FunctionType; |
10 import '../elements/entities.dart'; | 10 import '../elements/entities.dart'; |
11 import '../js/js.dart' as jsAst; | 11 import '../js/js.dart' as jsAst; |
12 import '../js/js.dart' show js; | 12 import '../js/js.dart' show js; |
13 import '../js_backend/backend_helpers.dart' show BackendHelpers; | |
14 import '../js_backend/js_backend.dart' show JavaScriptBackend, Namer; | 13 import '../js_backend/js_backend.dart' show JavaScriptBackend, Namer; |
15 import '../js_backend/interceptor_data.dart'; | 14 import '../js_backend/interceptor_data.dart'; |
16 import '../js_backend/native_data.dart'; | 15 import '../js_backend/native_data.dart'; |
17 import '../universe/world_builder.dart' show CodegenWorldBuilder; | 16 import '../universe/world_builder.dart' show CodegenWorldBuilder; |
18 | 17 |
19 import 'code_emitter_task.dart' show CodeEmitterTask; | 18 import 'code_emitter_task.dart' show CodeEmitterTask; |
20 import 'model.dart'; | 19 import 'model.dart'; |
21 | 20 |
22 class NativeEmitter { | 21 class NativeEmitter { |
23 final CodeEmitterTask emitterTask; | 22 final CodeEmitterTask emitterTask; |
(...skipping 11 matching lines...) Expand all Loading... |
35 | 34 |
36 // Caches the methods that have a native body. | 35 // Caches the methods that have a native body. |
37 Set<FunctionEntity> nativeMethods = new Set<FunctionEntity>(); | 36 Set<FunctionEntity> nativeMethods = new Set<FunctionEntity>(); |
38 | 37 |
39 NativeEmitter(CodeEmitterTask emitterTask) : this.emitterTask = emitterTask; | 38 NativeEmitter(CodeEmitterTask emitterTask) : this.emitterTask = emitterTask; |
40 | 39 |
41 Compiler get compiler => emitterTask.compiler; | 40 Compiler get compiler => emitterTask.compiler; |
42 | 41 |
43 JavaScriptBackend get backend => compiler.backend; | 42 JavaScriptBackend get backend => compiler.backend; |
44 | 43 |
45 BackendHelpers get helpers => backend.helpers; | |
46 | |
47 CodegenWorldBuilder get worldBuilder => compiler.codegenWorldBuilder; | 44 CodegenWorldBuilder get worldBuilder => compiler.codegenWorldBuilder; |
48 | 45 |
49 NativeData get nativeData => backend.nativeData; | 46 NativeData get nativeData => backend.nativeData; |
50 | 47 |
51 InterceptorData get interceptorData => backend.interceptorData; | 48 InterceptorData get interceptorData => backend.interceptorData; |
52 | 49 |
53 Namer get namer => backend.namer; | 50 Namer get namer => backend.namer; |
54 | 51 |
55 /** | 52 /** |
56 * Prepares native classes for emission. Returns the unneeded classes. | 53 * Prepares native classes for emission. Returns the unneeded classes. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 Set<Class> seen = new Set<Class>(); | 94 Set<Class> seen = new Set<Class>(); |
98 | 95 |
99 Class objectClass = null; | 96 Class objectClass = null; |
100 Class jsInterceptorClass = null; | 97 Class jsInterceptorClass = null; |
101 | 98 |
102 void walk(Class cls) { | 99 void walk(Class cls) { |
103 if (cls.element == compiler.commonElements.objectClass) { | 100 if (cls.element == compiler.commonElements.objectClass) { |
104 objectClass = cls; | 101 objectClass = cls; |
105 return; | 102 return; |
106 } | 103 } |
107 if (cls.element == helpers.jsInterceptorClass) { | 104 if (cls.element == compiler.commonElements.jsInterceptorClass) { |
108 jsInterceptorClass = cls; | 105 jsInterceptorClass = cls; |
109 return; | 106 return; |
110 } | 107 } |
111 if (seen.contains(cls)) return; | 108 if (seen.contains(cls)) return; |
112 seen.add(cls); | 109 seen.add(cls); |
113 walk(cls.superclass); | 110 walk(cls.superclass); |
114 preOrder.add(cls); | 111 preOrder.add(cls); |
115 } | 112 } |
116 | 113 |
117 classes.forEach(walk); | 114 classes.forEach(walk); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 261 |
265 return cls.methods.isEmpty && | 262 return cls.methods.isEmpty && |
266 cls.isChecks.isEmpty && | 263 cls.isChecks.isEmpty && |
267 cls.callStubs.isEmpty && | 264 cls.callStubs.isEmpty && |
268 !cls.superclass.isMixinApplication && | 265 !cls.superclass.isMixinApplication && |
269 !cls.fields.any(needsAccessor); | 266 !cls.fields.any(needsAccessor); |
270 } | 267 } |
271 | 268 |
272 void potentiallyConvertDartClosuresToJs(List<jsAst.Statement> statements, | 269 void potentiallyConvertDartClosuresToJs(List<jsAst.Statement> statements, |
273 FunctionEntity member, List<jsAst.Parameter> stubParameters) { | 270 FunctionEntity member, List<jsAst.Parameter> stubParameters) { |
274 FunctionEntity converter = helpers.closureConverter; | 271 FunctionEntity converter = compiler.commonElements.closureConverter; |
275 jsAst.Expression closureConverter = | 272 jsAst.Expression closureConverter = |
276 emitterTask.staticFunctionAccess(converter); | 273 emitterTask.staticFunctionAccess(converter); |
277 worldBuilder.forEachParameter(member, (DartType type, String name) { | 274 worldBuilder.forEachParameter(member, (DartType type, String name) { |
278 // If [name] is not in [stubParameters], then the parameter is an optional | 275 // If [name] is not in [stubParameters], then the parameter is an optional |
279 // parameter that was not provided for this stub. | 276 // parameter that was not provided for this stub. |
280 for (jsAst.Parameter stubParameter in stubParameters) { | 277 for (jsAst.Parameter stubParameter in stubParameters) { |
281 if (stubParameter.name == name) { | 278 if (stubParameter.name == name) { |
282 type = type.unaliased; | 279 type = type.unaliased; |
283 if (type.isFunctionType) { | 280 if (type.isFunctionType) { |
284 // The parameter type is a function type either directly or through | 281 // The parameter type is a function type either directly or through |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 // satisfy a check against [element], in which case an interceptor must be | 362 // satisfy a check against [element], in which case an interceptor must be |
366 // used. We should also use an interceptor if the check can't be satisfied | 363 // used. We should also use an interceptor if the check can't be satisfied |
367 // by a native class in case we get a native instance that tries to spoof | 364 // by a native class in case we get a native instance that tries to spoof |
368 // the type info. i.e the criteria for whether or not to use an interceptor | 365 // the type info. i.e the criteria for whether or not to use an interceptor |
369 // is whether the receiver can be native, not the type of the test. | 366 // is whether the receiver can be native, not the type of the test. |
370 ClassEntity cls = element; | 367 ClassEntity cls = element; |
371 if (nativeData.isNativeOrExtendsNative(cls)) return true; | 368 if (nativeData.isNativeOrExtendsNative(cls)) return true; |
372 return isSupertypeOfNativeClass(element); | 369 return isSupertypeOfNativeClass(element); |
373 } | 370 } |
374 } | 371 } |
OLD | NEW |