| 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.enqueue; | 5 library dart2js.js.enqueue; |
| 6 | 6 |
| 7 import 'dart:collection' show Queue; | 7 import 'dart:collection' show Queue; |
| 8 | 8 |
| 9 import '../common/backend_api.dart' show Backend; | |
| 10 import '../common/codegen.dart' show CodegenWorkItem; | 9 import '../common/codegen.dart' show CodegenWorkItem; |
| 11 import '../common/tasks.dart' show CompilerTask; | 10 import '../common/tasks.dart' show CompilerTask; |
| 12 import '../common/work.dart' show WorkItem; | 11 import '../common/work.dart' show WorkItem; |
| 13 import '../common.dart'; | 12 import '../common.dart'; |
| 14 import '../elements/resolution_types.dart' | 13 import '../elements/resolution_types.dart' |
| 15 show ResolutionDartType, ResolutionInterfaceType; | 14 show ResolutionDartType, ResolutionInterfaceType; |
| 16 import '../elements/elements.dart' show MemberElement, TypedElement; | 15 import '../elements/elements.dart' show MemberElement, TypedElement; |
| 17 import '../elements/entities.dart'; | 16 import '../elements/entities.dart'; |
| 18 import '../enqueue.dart'; | 17 import '../enqueue.dart'; |
| 18 import '../js_backend/backend.dart' show JavaScriptBackend; |
| 19 import '../native/native.dart' as native; | 19 import '../native/native.dart' as native; |
| 20 import '../options.dart'; | 20 import '../options.dart'; |
| 21 import '../types/types.dart' show TypeMaskStrategy; | 21 import '../types/types.dart' show TypeMaskStrategy; |
| 22 import '../universe/world_builder.dart'; | 22 import '../universe/world_builder.dart'; |
| 23 import '../universe/use.dart' | 23 import '../universe/use.dart' |
| 24 show DynamicUse, StaticUse, StaticUseKind, TypeUse, TypeUseKind; | 24 show DynamicUse, StaticUse, StaticUseKind, TypeUse, TypeUseKind; |
| 25 import '../universe/world_impact.dart' | 25 import '../universe/world_impact.dart' |
| 26 show ImpactUseCase, WorldImpact, WorldImpactVisitor; | 26 show ImpactUseCase, WorldImpact, WorldImpactVisitor; |
| 27 import '../util/enumset.dart'; | 27 import '../util/enumset.dart'; |
| 28 import '../util/util.dart' show Setlet; | 28 import '../util/util.dart' show Setlet; |
| 29 | 29 |
| 30 /// [Enqueuer] which is specific to code generation. | 30 /// [Enqueuer] which is specific to code generation. |
| 31 class CodegenEnqueuer extends EnqueuerImpl { | 31 class CodegenEnqueuer extends EnqueuerImpl { |
| 32 final String name; | 32 final String name; |
| 33 final EnqueuerStrategy strategy; | 33 final EnqueuerStrategy strategy; |
| 34 | 34 |
| 35 Set<ClassEntity> _recentClasses = new Setlet<ClassEntity>(); | 35 Set<ClassEntity> _recentClasses = new Setlet<ClassEntity>(); |
| 36 final CodegenWorldBuilderImpl _universe; | 36 final CodegenWorldBuilderImpl _universe; |
| 37 final WorkItemBuilder _workItemBuilder; | 37 final WorkItemBuilder _workItemBuilder; |
| 38 | 38 |
| 39 bool queueIsClosed = false; | 39 bool queueIsClosed = false; |
| 40 final CompilerTask task; | 40 final CompilerTask task; |
| 41 final native.NativeEnqueuer nativeEnqueuer; | 41 final native.NativeEnqueuer nativeEnqueuer; |
| 42 final Backend _backend; | 42 final JavaScriptBackend _backend; |
| 43 final CompilerOptions _options; | 43 final CompilerOptions _options; |
| 44 | 44 |
| 45 WorldImpactVisitor _impactVisitor; | 45 WorldImpactVisitor _impactVisitor; |
| 46 | 46 |
| 47 final Queue<WorkItem> _queue = new Queue<WorkItem>(); | 47 final Queue<WorkItem> _queue = new Queue<WorkItem>(); |
| 48 | 48 |
| 49 /// All declaration elements that have been processed by codegen. | 49 /// All declaration elements that have been processed by codegen. |
| 50 final Set<Entity> _processedEntities = new Set<Entity>(); | 50 final Set<Entity> _processedEntities = new Set<Entity>(); |
| 51 | 51 |
| 52 static const ImpactUseCase IMPACT_USE = | 52 static const ImpactUseCase IMPACT_USE = |
| 53 const ImpactUseCase('CodegenEnqueuer'); | 53 const ImpactUseCase('CodegenEnqueuer'); |
| 54 | 54 |
| 55 CodegenEnqueuer( | 55 CodegenEnqueuer(this.task, JavaScriptBackend backend, CompilerOptions options, |
| 56 this.task, Backend backend, CompilerOptions options, this.strategy) | 56 this.strategy) |
| 57 : _universe = | 57 : _universe = |
| 58 new CodegenWorldBuilderImpl(backend, const TypeMaskStrategy()), | 58 new CodegenWorldBuilderImpl(backend, const TypeMaskStrategy()), |
| 59 _workItemBuilder = new CodegenWorkItemBuilder(backend, options), | 59 _workItemBuilder = new CodegenWorkItemBuilder(backend, options), |
| 60 nativeEnqueuer = backend.nativeCodegenEnqueuer(), | 60 nativeEnqueuer = backend.nativeCodegenEnqueuer(), |
| 61 this._backend = backend, | 61 this._backend = backend, |
| 62 this._options = options, | 62 this._options = options, |
| 63 this.name = 'codegen enqueuer' { | 63 this.name = 'codegen enqueuer' { |
| 64 _impactVisitor = new EnqueuerImplImpactVisitor(this); | 64 _impactVisitor = new EnqueuerImplImpactVisitor(this); |
| 65 } | 65 } |
| 66 | 66 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 @override | 251 @override |
| 252 Iterable<Entity> get processedEntities => _processedEntities; | 252 Iterable<Entity> get processedEntities => _processedEntities; |
| 253 | 253 |
| 254 @override | 254 @override |
| 255 Iterable<ClassEntity> get processedClasses => _universe.processedClasses; | 255 Iterable<ClassEntity> get processedClasses => _universe.processedClasses; |
| 256 } | 256 } |
| 257 | 257 |
| 258 /// Builder that creates the work item necessary for the code generation of a | 258 /// Builder that creates the work item necessary for the code generation of a |
| 259 /// [MemberElement]. | 259 /// [MemberElement]. |
| 260 class CodegenWorkItemBuilder extends WorkItemBuilder { | 260 class CodegenWorkItemBuilder extends WorkItemBuilder { |
| 261 Backend _backend; | 261 JavaScriptBackend _backend; |
| 262 CompilerOptions _options; | 262 CompilerOptions _options; |
| 263 | 263 |
| 264 CodegenWorkItemBuilder(this._backend, this._options); | 264 CodegenWorkItemBuilder(this._backend, this._options); |
| 265 | 265 |
| 266 @override | 266 @override |
| 267 WorkItem createWorkItem(MemberElement element) { | 267 WorkItem createWorkItem(MemberElement element) { |
| 268 assert(invariant(element, element.isDeclaration)); | 268 assert(invariant(element, element.isDeclaration)); |
| 269 // Don't generate code for foreign elements. | 269 // Don't generate code for foreign elements. |
| 270 if (_backend.isForeign(element)) return null; | 270 if (_backend.isForeign(element)) return null; |
| 271 if (element.isAbstract) return null; | 271 if (element.isAbstract) return null; |
| 272 | 272 |
| 273 // Codegen inlines field initializers. It only needs to generate | 273 // Codegen inlines field initializers. It only needs to generate |
| 274 // code for checked setters. | 274 // code for checked setters. |
| 275 if (element.isField && element.isInstanceMember) { | 275 if (element.isField && element.isInstanceMember) { |
| 276 if (!_options.enableTypeAssertions || | 276 if (!_options.enableTypeAssertions || |
| 277 element.enclosingElement.isClosure) { | 277 element.enclosingElement.isClosure) { |
| 278 return null; | 278 return null; |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 return new CodegenWorkItem(_backend, element); | 281 return new CodegenWorkItem(_backend, element); |
| 282 } | 282 } |
| 283 } | 283 } |
| OLD | NEW |