| 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/js_backend.dart' show JavaScriptBackend, Namer; | 13 import '../js_backend/js_backend.dart' show JavaScriptBackend, Namer; |
| 14 import '../js_backend/interceptor_data.dart'; | 14 import '../js_backend/interceptor_data.dart'; |
| 15 import '../js_backend/native_data.dart'; | 15 import '../js_backend/native_data.dart'; |
| 16 import '../universe/world_builder.dart' show CodegenWorldBuilder; | 16 import '../universe/world_builder.dart' show CodegenWorldBuilder; |
| 17 | 17 |
| 18 import 'code_emitter_task.dart' show CodeEmitterTask; | 18 import 'code_emitter_task.dart' show CodeEmitterTask; |
| 19 import 'model.dart'; | 19 import 'model.dart'; |
| 20 | 20 |
| 21 class NativeEmitter { | 21 class NativeEmitter { |
| 22 final CodeEmitterTask emitterTask; | 22 final CodeEmitterTask emitterTask; |
| 23 final NativeData nativeData; |
| 23 | 24 |
| 24 // Whether the application contains native classes. | 25 // Whether the application contains native classes. |
| 25 bool hasNativeClasses = false; | 26 bool hasNativeClasses = false; |
| 26 | 27 |
| 27 // Caches the native subtypes of a native class. | 28 // Caches the native subtypes of a native class. |
| 28 Map<ClassEntity, List<ClassEntity>> subtypes = | 29 Map<ClassEntity, List<ClassEntity>> subtypes = |
| 29 <ClassEntity, List<ClassEntity>>{}; | 30 <ClassEntity, List<ClassEntity>>{}; |
| 30 | 31 |
| 31 // Caches the direct native subtypes of a native class. | 32 // Caches the direct native subtypes of a native class. |
| 32 Map<ClassEntity, List<ClassEntity>> directSubtypes = | 33 Map<ClassEntity, List<ClassEntity>> directSubtypes = |
| 33 <ClassEntity, List<ClassEntity>>{}; | 34 <ClassEntity, List<ClassEntity>>{}; |
| 34 | 35 |
| 35 // Caches the methods that have a native body. | 36 // Caches the methods that have a native body. |
| 36 Set<FunctionEntity> nativeMethods = new Set<FunctionEntity>(); | 37 Set<FunctionEntity> nativeMethods = new Set<FunctionEntity>(); |
| 37 | 38 |
| 38 NativeEmitter(CodeEmitterTask emitterTask) : this.emitterTask = emitterTask; | 39 NativeEmitter(this.emitterTask, this.nativeData); |
| 39 | 40 |
| 40 Compiler get compiler => emitterTask.compiler; | 41 Compiler get compiler => emitterTask.compiler; |
| 41 | 42 |
| 42 JavaScriptBackend get backend => compiler.backend; | 43 JavaScriptBackend get backend => compiler.backend; |
| 43 | 44 |
| 44 CodegenWorldBuilder get worldBuilder => compiler.codegenWorldBuilder; | 45 CodegenWorldBuilder get worldBuilder => compiler.codegenWorldBuilder; |
| 45 | 46 |
| 46 NativeData get nativeData => backend.nativeData; | |
| 47 | |
| 48 InterceptorData get interceptorData => backend.interceptorData; | 47 InterceptorData get interceptorData => backend.interceptorData; |
| 49 | 48 |
| 50 Namer get namer => backend.namer; | 49 Namer get namer => backend.namer; |
| 51 | 50 |
| 52 /** | 51 /** |
| 53 * Prepares native classes for emission. Returns the unneeded classes. | 52 * Prepares native classes for emission. Returns the unneeded classes. |
| 54 * | 53 * |
| 55 * Removes trivial classes (that can be represented by a super type) and | 54 * Removes trivial classes (that can be represented by a super type) and |
| 56 * generates properties that have to be added to classes (native or not). | 55 * generates properties that have to be added to classes (native or not). |
| 57 * | 56 * |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // satisfy a check against [element], in which case an interceptor must be | 361 // satisfy a check against [element], in which case an interceptor must be |
| 363 // used. We should also use an interceptor if the check can't be satisfied | 362 // used. We should also use an interceptor if the check can't be satisfied |
| 364 // by a native class in case we get a native instance that tries to spoof | 363 // by a native class in case we get a native instance that tries to spoof |
| 365 // the type info. i.e the criteria for whether or not to use an interceptor | 364 // the type info. i.e the criteria for whether or not to use an interceptor |
| 366 // is whether the receiver can be native, not the type of the test. | 365 // is whether the receiver can be native, not the type of the test. |
| 367 ClassEntity cls = element; | 366 ClassEntity cls = element; |
| 368 if (nativeData.isNativeOrExtendsNative(cls)) return true; | 367 if (nativeData.isNativeOrExtendsNative(cls)) return true; |
| 369 return isSupertypeOfNativeClass(element); | 368 return isSupertypeOfNativeClass(element); |
| 370 } | 369 } |
| 371 } | 370 } |
| OLD | NEW |