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.common.codegen; | 5 library dart2js.common.codegen; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
9 import '../constants/values.dart' show ConstantValue; | 9 import '../constants/values.dart' show ConstantValue; |
10 import '../dart_types.dart' show DartType, InterfaceType; | 10 import '../dart_types.dart' show DartType, InterfaceType; |
11 import '../elements/elements.dart' | 11 import '../elements/elements.dart' |
12 show | 12 show |
13 AstElement, | 13 AstElement, |
14 ClassElement, | 14 ClassElement, |
15 Element, | 15 Element, |
16 FunctionElement, | 16 FunctionElement, |
17 LocalFunctionElement, | 17 LocalFunctionElement, |
18 ResolvedAst; | 18 ResolvedAst; |
19 import '../enqueue.dart' show Enqueuer; | 19 import '../enqueue.dart' show Enqueuer; |
20 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; | 20 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; |
21 import '../universe/world_impact.dart' | 21 import '../universe/world_impact.dart' |
22 show WorldImpact, WorldImpactBuilderImpl, WorldImpactVisitor; | 22 show WorldImpact, WorldImpactBuilder, WorldImpactVisitor; |
23 import '../util/util.dart' show Pair, Setlet; | 23 import '../util/util.dart' show Pair, Setlet; |
24 import 'registry.dart' show Registry; | 24 import 'registry.dart' show Registry, EagerRegistry; |
25 import 'work.dart' show WorkItem; | 25 import 'work.dart' show WorkItem; |
26 | 26 |
27 class CodegenImpact extends WorldImpact { | 27 class CodegenImpact extends WorldImpact { |
28 const CodegenImpact(); | 28 const CodegenImpact(); |
29 | 29 |
| 30 // TODO(johnniwinther): Remove this. |
| 31 Registry get registry => null; |
| 32 |
30 Iterable<ConstantValue> get compileTimeConstants => const <ConstantValue>[]; | 33 Iterable<ConstantValue> get compileTimeConstants => const <ConstantValue>[]; |
31 | 34 |
32 Iterable<Pair<DartType, DartType>> get typeVariableBoundsSubtypeChecks { | 35 Iterable<Pair<DartType, DartType>> get typeVariableBoundsSubtypeChecks { |
33 return const <Pair<DartType, DartType>>[]; | 36 return const <Pair<DartType, DartType>>[]; |
34 } | 37 } |
35 | 38 |
36 Iterable<String> get constSymbols => const <String>[]; | 39 Iterable<String> get constSymbols => const <String>[]; |
37 | 40 |
38 Iterable<Set<ClassElement>> get specializedGetInterceptors { | 41 Iterable<Set<ClassElement>> get specializedGetInterceptors { |
39 return const <Set<ClassElement>>[]; | 42 return const <Set<ClassElement>>[]; |
40 } | 43 } |
41 | 44 |
42 bool get usesInterceptor => false; | 45 bool get usesInterceptor => false; |
43 | 46 |
44 Iterable<ClassElement> get typeConstants => const <ClassElement>[]; | 47 Iterable<ClassElement> get typeConstants => const <ClassElement>[]; |
45 | 48 |
46 Iterable<Element> get asyncMarkers => const <FunctionElement>[]; | 49 Iterable<Element> get asyncMarkers => const <FunctionElement>[]; |
47 } | 50 } |
48 | 51 |
49 class _CodegenImpact extends WorldImpactBuilderImpl implements CodegenImpact { | 52 class _CodegenImpact extends WorldImpactBuilder implements CodegenImpact { |
| 53 // TODO(johnniwinther): Remove this. |
| 54 final Registry registry; |
| 55 |
50 Setlet<ConstantValue> _compileTimeConstants; | 56 Setlet<ConstantValue> _compileTimeConstants; |
51 Setlet<Pair<DartType, DartType>> _typeVariableBoundsSubtypeChecks; | 57 Setlet<Pair<DartType, DartType>> _typeVariableBoundsSubtypeChecks; |
52 Setlet<String> _constSymbols; | 58 Setlet<String> _constSymbols; |
53 List<Set<ClassElement>> _specializedGetInterceptors; | 59 List<Set<ClassElement>> _specializedGetInterceptors; |
54 bool _usesInterceptor = false; | 60 bool _usesInterceptor = false; |
55 Setlet<ClassElement> _typeConstants; | 61 Setlet<ClassElement> _typeConstants; |
56 Setlet<FunctionElement> _asyncMarkers; | 62 Setlet<FunctionElement> _asyncMarkers; |
57 | 63 |
58 _CodegenImpact(); | 64 _CodegenImpact(this.registry); |
59 | 65 |
60 void apply(WorldImpactVisitor visitor) { | 66 void apply(WorldImpactVisitor visitor) { |
61 staticUses.forEach(visitor.visitStaticUse); | 67 staticUses.forEach(visitor.visitStaticUse); |
62 dynamicUses.forEach(visitor.visitDynamicUse); | 68 dynamicUses.forEach(visitor.visitDynamicUse); |
63 typeUses.forEach(visitor.visitTypeUse); | 69 typeUses.forEach(visitor.visitTypeUse); |
64 } | 70 } |
65 | 71 |
66 void registerCompileTimeConstant(ConstantValue constant) { | 72 void registerCompileTimeConstant(ConstantValue constant) { |
67 if (_compileTimeConstants == null) { | 73 if (_compileTimeConstants == null) { |
68 _compileTimeConstants = new Setlet<ConstantValue>(); | 74 _compileTimeConstants = new Setlet<ConstantValue>(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // TODO(johnniwinther): Split this class into interface and implementation. | 153 // TODO(johnniwinther): Split this class into interface and implementation. |
148 // TODO(johnniwinther): Move this implementation to the JS backend. | 154 // TODO(johnniwinther): Move this implementation to the JS backend. |
149 class CodegenRegistry extends Registry { | 155 class CodegenRegistry extends Registry { |
150 final Compiler compiler; | 156 final Compiler compiler; |
151 final Element currentElement; | 157 final Element currentElement; |
152 final _CodegenImpact worldImpact; | 158 final _CodegenImpact worldImpact; |
153 | 159 |
154 CodegenRegistry(Compiler compiler, AstElement currentElement) | 160 CodegenRegistry(Compiler compiler, AstElement currentElement) |
155 : this.compiler = compiler, | 161 : this.compiler = compiler, |
156 this.currentElement = currentElement, | 162 this.currentElement = currentElement, |
157 this.worldImpact = new _CodegenImpact(); | 163 this.worldImpact = new _CodegenImpact(new EagerRegistry( |
| 164 'EagerRegistry for $currentElement', compiler.enqueuer.codegen)); |
158 | 165 |
159 bool get isForResolution => false; | 166 bool get isForResolution => false; |
160 | 167 |
161 String toString() => 'CodegenRegistry for $currentElement'; | 168 String toString() => 'CodegenRegistry for $currentElement'; |
162 | 169 |
163 @deprecated | 170 @deprecated |
164 void registerInstantiatedClass(ClassElement element) { | 171 void registerInstantiatedClass(ClassElement element) { |
165 registerInstantiation(element.rawType); | 172 registerInstantiation(element.rawType); |
166 } | 173 } |
167 | 174 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 244 |
238 WorldImpact run(Compiler compiler, Enqueuer world) { | 245 WorldImpact run(Compiler compiler, Enqueuer world) { |
239 if (world.isProcessed(element)) return const WorldImpact(); | 246 if (world.isProcessed(element)) return const WorldImpact(); |
240 | 247 |
241 registry = new CodegenRegistry(compiler, element); | 248 registry = new CodegenRegistry(compiler, element); |
242 return compiler.codegen(this, world); | 249 return compiler.codegen(this, world); |
243 } | 250 } |
244 | 251 |
245 String toString() => 'CodegenWorkItem(${resolvedAst.element})'; | 252 String toString() => 'CodegenWorkItem(${resolvedAst.element})'; |
246 } | 253 } |
OLD | NEW |