OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.dart'; | 5 import '../common.dart'; |
6 import '../common/registry.dart' show Registry; | 6 import '../common/registry.dart' show Registry; |
7 import '../compiler.dart' show Compiler; | 7 import '../compiler.dart' show Compiler; |
8 import '../constants/expressions.dart'; | 8 import '../constants/expressions.dart'; |
9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
11 import '../elements/elements.dart'; | 11 import '../elements/elements.dart'; |
12 import '../enqueue.dart' show Enqueuer; | 12 import '../enqueue.dart' show Enqueuer; |
13 import '../js/js.dart' as jsAst; | 13 import '../js/js.dart' as jsAst; |
14 import '../js_emitter/js_emitter.dart' | 14 import '../js_emitter/js_emitter.dart' |
15 show CodeEmitterTask, MetadataCollector, Placeholder; | 15 show CodeEmitterTask, MetadataCollector, Placeholder; |
16 import '../universe/call_structure.dart' show CallStructure; | 16 import '../universe/call_structure.dart' show CallStructure; |
17 import '../universe/use.dart' show StaticUse; | 17 import '../universe/use.dart' show StaticUse; |
18 import '../universe/world_impact.dart'; | |
19 import '../util/util.dart'; | 18 import '../util/util.dart'; |
20 import 'backend.dart'; | 19 import 'backend.dart'; |
21 | 20 |
22 /** | 21 /** |
23 * Handles construction of TypeVariable constants needed at runtime. | 22 * Handles construction of TypeVariable constants needed at runtime. |
24 */ | 23 */ |
25 class TypeVariableHandler { | 24 class TypeVariableHandler { |
26 final Compiler _compiler; | 25 final Compiler _compiler; |
27 ConstructorElement _typeVariableConstructor; | 26 ConstructorElement _typeVariableConstructor; |
28 | 27 |
29 /** | 28 /** |
30 * Set to 'true' on first encounter of a class with type variables. | 29 * Set to 'true' on first encounter of a class with type variables. |
31 */ | 30 */ |
32 bool _seenClassesWithTypeVariables = false; | 31 bool _seenClassesWithTypeVariables = false; |
33 | 32 |
34 /** | 33 /** |
35 * Maps a class element to a list with indices that point to type variables | 34 * Maps a class element to a list with indices that point to type variables |
36 * constants for each of the class' type variables. | 35 * constants for each of the class' type variables. |
37 */ | 36 */ |
38 Map<ClassElement, List<jsAst.Expression>> _typeVariables = | 37 Map<ClassElement, List<jsAst.Expression>> _typeVariables = |
39 new Map<ClassElement, List<jsAst.Expression>>(); | 38 new Map<ClassElement, List<jsAst.Expression>>(); |
40 | 39 |
41 /** | 40 /** |
42 * Maps a TypeVariableType to the index pointing to the constant representing | 41 * Maps a TypeVariableType to the index pointing to the constant representing |
43 * the corresponding type variable at runtime. | 42 * the corresponding type variable at runtime. |
44 */ | 43 */ |
45 Map<TypeVariableElement, jsAst.Expression> _typeVariableConstants = | 44 Map<TypeVariableElement, jsAst.Expression> _typeVariableConstants = |
46 new Map<TypeVariableElement, jsAst.Expression>(); | 45 new Map<TypeVariableElement, jsAst.Expression>(); |
47 | 46 |
48 /// Impact builder used for the codegen world computation. | |
49 // TODO(johnniwinther): Add impact builder for resolution. | |
50 final StagedWorldImpactBuilder impactBuilder = new StagedWorldImpactBuilder(); | |
51 | |
52 TypeVariableHandler(this._compiler); | 47 TypeVariableHandler(this._compiler); |
53 | 48 |
54 ClassElement get _typeVariableClass => _backend.helpers.typeVariableClass; | 49 ClassElement get _typeVariableClass => _backend.helpers.typeVariableClass; |
55 CodeEmitterTask get _task => _backend.emitter; | 50 CodeEmitterTask get _task => _backend.emitter; |
56 MetadataCollector get _metadataCollector => _task.metadataCollector; | 51 MetadataCollector get _metadataCollector => _task.metadataCollector; |
57 JavaScriptBackend get _backend => _compiler.backend; | 52 JavaScriptBackend get _backend => _compiler.backend; |
58 DiagnosticReporter get reporter => _compiler.reporter; | 53 DiagnosticReporter get reporter => _compiler.reporter; |
59 | 54 |
60 void onQueueEmpty(Enqueuer enqueuer) { | |
61 if (enqueuer.isResolutionQueue) return; | |
62 | |
63 enqueuer.applyImpact(null, impactBuilder.flush()); | |
64 } | |
65 | |
66 void registerClassWithTypeVariables( | 55 void registerClassWithTypeVariables( |
67 ClassElement cls, Enqueuer enqueuer, Registry registry) { | 56 ClassElement cls, Enqueuer enqueuer, Registry registry) { |
68 if (enqueuer.isResolutionQueue) { | 57 if (enqueuer.isResolutionQueue) { |
69 // On first encounter, we have to ensure that the support classes get | 58 // On first encounter, we have to ensure that the support classes get |
70 // resolved. | 59 // resolved. |
71 if (!_seenClassesWithTypeVariables) { | 60 if (!_seenClassesWithTypeVariables) { |
72 _backend.enqueueClass(enqueuer, _typeVariableClass, registry); | 61 _backend.enqueueClass(enqueuer, _typeVariableClass, registry); |
73 _typeVariableClass.ensureResolved(_compiler.resolution); | 62 _typeVariableClass.ensureResolved(_compiler.resolution); |
74 Link constructors = _typeVariableClass.constructors; | 63 Link constructors = _typeVariableClass.constructors; |
75 if (constructors.isEmpty && constructors.tail.isEmpty) { | 64 if (constructors.isEmpty && constructors.tail.isEmpty) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 _typeVariableConstructor.enclosingClass.thisType, | 101 _typeVariableConstructor.enclosingClass.thisType, |
113 _typeVariableConstructor, | 102 _typeVariableConstructor, |
114 const CallStructure.unnamed(3), [ | 103 const CallStructure.unnamed(3), [ |
115 new TypeConstantExpression(cls.rawType), | 104 new TypeConstantExpression(cls.rawType), |
116 new StringConstantExpression(currentTypeVariable.name), | 105 new StringConstantExpression(currentTypeVariable.name), |
117 new SyntheticConstantExpression(boundValue) | 106 new SyntheticConstantExpression(boundValue) |
118 ]); | 107 ]); |
119 | 108 |
120 _backend.constants.evaluate(constant); | 109 _backend.constants.evaluate(constant); |
121 ConstantValue value = _backend.constants.getConstantValue(constant); | 110 ConstantValue value = _backend.constants.getConstantValue(constant); |
122 _backend.computeImpactForCompileTimeConstant(value, impactBuilder, false); | 111 _backend.registerCompileTimeConstant(value, _compiler.globalDependencies); |
123 _backend.addCompileTimeConstantForEmission(value); | 112 _backend.addCompileTimeConstantForEmission(value); |
| 113 _backend.constants.addCompileTimeConstantForEmission(value); |
124 constants | 114 constants |
125 .add(_reifyTypeVariableConstant(value, currentTypeVariable.element)); | 115 .add(_reifyTypeVariableConstant(value, currentTypeVariable.element)); |
126 } | 116 } |
127 _typeVariables[cls] = constants; | 117 _typeVariables[cls] = constants; |
128 } | 118 } |
129 | 119 |
130 /** | 120 /** |
131 * Adds [c] to [emitter.metadataCollector] and returns the index pointing to | 121 * Adds [c] to [emitter.metadataCollector] and returns the index pointing to |
132 * the entry. | 122 * the entry. |
133 * | 123 * |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 158 } |
169 | 159 |
170 List<jsAst.Expression> typeVariablesOf(ClassElement classElement) { | 160 List<jsAst.Expression> typeVariablesOf(ClassElement classElement) { |
171 List<jsAst.Expression> result = _typeVariables[classElement]; | 161 List<jsAst.Expression> result = _typeVariables[classElement]; |
172 if (result == null) { | 162 if (result == null) { |
173 result = const <jsAst.Expression>[]; | 163 result = const <jsAst.Expression>[]; |
174 } | 164 } |
175 return result; | 165 return result; |
176 } | 166 } |
177 } | 167 } |
OLD | NEW |