| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 '../common/backend_api.dart'; | 5 import '../common/backend_api.dart'; |
| 6 import '../common_elements.dart' show CommonElements, ElementEnvironment; | 6 import '../common_elements.dart' show CommonElements, ElementEnvironment; |
| 7 import '../elements/elements.dart'; | 7 import '../elements/elements.dart'; |
| 8 import '../elements/entities.dart'; | 8 import '../elements/entities.dart'; |
| 9 import '../elements/resolution_types.dart'; | 9 import '../elements/resolution_types.dart'; |
| 10 import '../elements/types.dart'; | 10 import '../elements/types.dart'; |
| 11 import '../js_backend/backend_helpers.dart' show BackendHelpers; | |
| 12 import '../js_backend/backend_usage.dart' show BackendUsageBuilder; | 11 import '../js_backend/backend_usage.dart' show BackendUsageBuilder; |
| 13 import '../js_backend/native_data.dart' show NativeData; | 12 import '../js_backend/native_data.dart' show NativeData; |
| 14 import '../js_emitter/js_emitter.dart' show CodeEmitterTask, NativeEmitter; | 13 import '../js_emitter/js_emitter.dart' show CodeEmitterTask, NativeEmitter; |
| 15 import '../options.dart'; | 14 import '../options.dart'; |
| 16 import '../universe/use.dart' show StaticUse, TypeUse; | 15 import '../universe/use.dart' show StaticUse, TypeUse; |
| 17 import '../universe/world_impact.dart' | 16 import '../universe/world_impact.dart' |
| 18 show WorldImpact, WorldImpactBuilder, WorldImpactBuilderImpl; | 17 show WorldImpact, WorldImpactBuilder, WorldImpactBuilderImpl; |
| 19 import 'behavior.dart'; | 18 import 'behavior.dart'; |
| 20 import 'resolver.dart' show NativeClassResolver; | 19 import 'resolver.dart' show NativeClassResolver; |
| 21 | 20 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 final Set<ClassEntity> _unusedClasses = new Set<ClassEntity>(); | 46 final Set<ClassEntity> _unusedClasses = new Set<ClassEntity>(); |
| 48 | 47 |
| 49 bool get hasInstantiatedNativeClasses => !_registeredClasses.isEmpty; | 48 bool get hasInstantiatedNativeClasses => !_registeredClasses.isEmpty; |
| 50 | 49 |
| 51 /// Log message reported if all native types are used. | 50 /// Log message reported if all native types are used. |
| 52 String _allUsedMessage; | 51 String _allUsedMessage; |
| 53 | 52 |
| 54 final CompilerOptions _options; | 53 final CompilerOptions _options; |
| 55 final ElementEnvironment _elementEnvironment; | 54 final ElementEnvironment _elementEnvironment; |
| 56 final CommonElements _commonElements; | 55 final CommonElements _commonElements; |
| 57 final BackendHelpers _helpers; | |
| 58 final BackendClasses _backendClasses; | 56 final BackendClasses _backendClasses; |
| 59 | 57 |
| 60 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. | 58 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. |
| 61 NativeEnqueuerBase(this._options, this._elementEnvironment, | 59 NativeEnqueuerBase(this._options, this._elementEnvironment, |
| 62 this._commonElements, this._helpers, this._backendClasses); | 60 this._commonElements, this._backendClasses); |
| 63 | 61 |
| 64 bool get enableLiveTypeAnalysis => _options.enableNativeLiveTypeAnalysis; | 62 bool get enableLiveTypeAnalysis => _options.enableNativeLiveTypeAnalysis; |
| 65 | 63 |
| 66 void onInstantiatedType(InterfaceType type) { | 64 void onInstantiatedType(InterfaceType type) { |
| 67 if (_unusedClasses.remove(type.element)) { | 65 if (_unusedClasses.remove(type.element)) { |
| 68 _registeredClasses.add(type.element); | 66 _registeredClasses.add(type.element); |
| 69 } | 67 } |
| 70 } | 68 } |
| 71 | 69 |
| 72 /// Register [classes] as natively instantiated in [impactBuilder]. | 70 /// Register [classes] as natively instantiated in [impactBuilder]. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 154 } |
| 157 | 155 |
| 158 void _registerBackendUse(FunctionEntity element) {} | 156 void _registerBackendUse(FunctionEntity element) {} |
| 159 | 157 |
| 160 Iterable<ClassEntity> _onFirstNativeClass(WorldImpactBuilder impactBuilder) { | 158 Iterable<ClassEntity> _onFirstNativeClass(WorldImpactBuilder impactBuilder) { |
| 161 void staticUse(FunctionEntity element) { | 159 void staticUse(FunctionEntity element) { |
| 162 impactBuilder.registerStaticUse(new StaticUse.implicitInvoke(element)); | 160 impactBuilder.registerStaticUse(new StaticUse.implicitInvoke(element)); |
| 163 _registerBackendUse(element); | 161 _registerBackendUse(element); |
| 164 } | 162 } |
| 165 | 163 |
| 166 staticUse(_helpers.defineProperty); | 164 staticUse(_commonElements.defineProperty); |
| 167 staticUse(_helpers.toStringForNativeObject); | 165 staticUse(_commonElements.toStringForNativeObject); |
| 168 staticUse(_helpers.hashCodeForNativeObject); | 166 staticUse(_commonElements.hashCodeForNativeObject); |
| 169 staticUse(_helpers.closureConverter); | 167 staticUse(_commonElements.closureConverter); |
| 170 return _findNativeExceptions(); | 168 return _findNativeExceptions(); |
| 171 } | 169 } |
| 172 | 170 |
| 173 Iterable<ClassEntity> _findNativeExceptions() { | 171 Iterable<ClassEntity> _findNativeExceptions() { |
| 174 return _findUnusedClassesMatching((ClassEntity classElement) { | 172 return _findUnusedClassesMatching((ClassEntity classElement) { |
| 175 // TODO(sra): Annotate exception classes in dart:html. | 173 // TODO(sra): Annotate exception classes in dart:html. |
| 176 String name = classElement.name; | 174 String name = classElement.name; |
| 177 if (name.contains('Exception')) return true; | 175 if (name.contains('Exception')) return true; |
| 178 if (name.contains('Error')) return true; | 176 if (name.contains('Error')) return true; |
| 179 return false; | 177 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 192 final BackendUsageBuilder _backendUsageBuilder; | 190 final BackendUsageBuilder _backendUsageBuilder; |
| 193 | 191 |
| 194 /// The set of all native classes. Each native class is in [nativeClasses] | 192 /// The set of all native classes. Each native class is in [nativeClasses] |
| 195 /// and exactly one of [unusedClasses] and [registeredClasses]. | 193 /// and exactly one of [unusedClasses] and [registeredClasses]. |
| 196 final Set<ClassEntity> _nativeClasses = new Set<ClassEntity>(); | 194 final Set<ClassEntity> _nativeClasses = new Set<ClassEntity>(); |
| 197 | 195 |
| 198 NativeResolutionEnqueuer( | 196 NativeResolutionEnqueuer( |
| 199 CompilerOptions options, | 197 CompilerOptions options, |
| 200 ElementEnvironment elementEnvironment, | 198 ElementEnvironment elementEnvironment, |
| 201 CommonElements commonElements, | 199 CommonElements commonElements, |
| 202 BackendHelpers helpers, | |
| 203 BackendClasses backendClasses, | 200 BackendClasses backendClasses, |
| 204 this._backendUsageBuilder, | 201 this._backendUsageBuilder, |
| 205 this._nativeClassResolver) | 202 this._nativeClassResolver) |
| 206 : super(options, elementEnvironment, commonElements, helpers, | 203 : super(options, elementEnvironment, commonElements, backendClasses); |
| 207 backendClasses); | |
| 208 | 204 |
| 209 void _registerBackendUse(FunctionEntity element) { | 205 void _registerBackendUse(FunctionEntity element) { |
| 210 _backendUsageBuilder.registerBackendFunctionUse(element); | 206 _backendUsageBuilder.registerBackendFunctionUse(element); |
| 211 _backendUsageBuilder.registerGlobalFunctionDependency(element); | 207 _backendUsageBuilder.registerGlobalFunctionDependency(element); |
| 212 } | 208 } |
| 213 | 209 |
| 214 WorldImpact processNativeClasses(Iterable<LibraryEntity> libraries) { | 210 WorldImpact processNativeClasses(Iterable<LibraryEntity> libraries) { |
| 215 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); | 211 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); |
| 216 Iterable<ClassEntity> nativeClasses = | 212 Iterable<ClassEntity> nativeClasses = |
| 217 _nativeClassResolver.computeNativeClasses(libraries); | 213 _nativeClassResolver.computeNativeClasses(libraries); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 234 final CodeEmitterTask _emitter; | 230 final CodeEmitterTask _emitter; |
| 235 final NativeResolutionEnqueuer _resolutionEnqueuer; | 231 final NativeResolutionEnqueuer _resolutionEnqueuer; |
| 236 final NativeData _nativeData; | 232 final NativeData _nativeData; |
| 237 | 233 |
| 238 final Set<ClassEntity> _doneAddSubtypes = new Set<ClassEntity>(); | 234 final Set<ClassEntity> _doneAddSubtypes = new Set<ClassEntity>(); |
| 239 | 235 |
| 240 NativeCodegenEnqueuer( | 236 NativeCodegenEnqueuer( |
| 241 CompilerOptions options, | 237 CompilerOptions options, |
| 242 ElementEnvironment elementEnvironment, | 238 ElementEnvironment elementEnvironment, |
| 243 CommonElements commonElements, | 239 CommonElements commonElements, |
| 244 BackendHelpers helpers, | |
| 245 BackendClasses backendClasses, | 240 BackendClasses backendClasses, |
| 246 this._emitter, | 241 this._emitter, |
| 247 this._resolutionEnqueuer, | 242 this._resolutionEnqueuer, |
| 248 this._nativeData) | 243 this._nativeData) |
| 249 : super(options, elementEnvironment, commonElements, helpers, | 244 : super(options, elementEnvironment, commonElements, backendClasses); |
| 250 backendClasses); | |
| 251 | 245 |
| 252 WorldImpact processNativeClasses(Iterable<LibraryElement> libraries) { | 246 WorldImpact processNativeClasses(Iterable<LibraryElement> libraries) { |
| 253 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); | 247 WorldImpactBuilderImpl impactBuilder = new WorldImpactBuilderImpl(); |
| 254 _unusedClasses.addAll(_resolutionEnqueuer._nativeClasses); | 248 _unusedClasses.addAll(_resolutionEnqueuer._nativeClasses); |
| 255 | 249 |
| 256 if (!enableLiveTypeAnalysis) { | 250 if (!enableLiveTypeAnalysis) { |
| 257 _registerTypeUses( | 251 _registerTypeUses( |
| 258 impactBuilder, _resolutionEnqueuer._nativeClasses, 'forced'); | 252 impactBuilder, _resolutionEnqueuer._nativeClasses, 'forced'); |
| 259 } | 253 } |
| 260 | 254 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassEntity>[]); | 305 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassEntity>[]); |
| 312 directSubtypes.add(cls); | 306 directSubtypes.add(cls); |
| 313 } | 307 } |
| 314 | 308 |
| 315 void logSummary(void log(String message)) { | 309 void logSummary(void log(String message)) { |
| 316 super.logSummary(log); | 310 super.logSummary(log); |
| 317 log('Compiled ${_registeredClasses.length} native classes, ' | 311 log('Compiled ${_registeredClasses.length} native classes, ' |
| 318 '${_unusedClasses.length} native classes omitted.'); | 312 '${_unusedClasses.length} native classes omitted.'); |
| 319 } | 313 } |
| 320 } | 314 } |
| OLD | NEW |