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 '../elements/resolution_types.dart' | |
9 show ResolutionDartType, ResolutionInterfaceType; | |
10 import '../elements/elements.dart' | 8 import '../elements/elements.dart' |
11 show | 9 show |
| 10 AsyncMarker, |
12 ClassElement, | 11 ClassElement, |
13 Element, | |
14 FunctionElement, | |
15 LocalFunctionElement, | 12 LocalFunctionElement, |
16 MemberElement, | 13 MemberElement, |
17 ResolvedAst; | 14 ResolvedAst; |
18 import '../elements/entities.dart'; | 15 import '../elements/entities.dart'; |
| 16 import '../elements/types.dart' show DartType, InterfaceType; |
19 import '../js_backend/backend.dart' show JavaScriptBackend; | 17 import '../js_backend/backend.dart' show JavaScriptBackend; |
20 import '../universe/use.dart' show ConstantUse, DynamicUse, StaticUse, TypeUse; | 18 import '../universe/use.dart' show ConstantUse, DynamicUse, StaticUse, TypeUse; |
21 import '../universe/world_impact.dart' | 19 import '../universe/world_impact.dart' |
22 show WorldImpact, WorldImpactBuilderImpl, WorldImpactVisitor; | 20 show WorldImpact, WorldImpactBuilderImpl, WorldImpactVisitor; |
| 21 import '../util/enumset.dart'; |
23 import '../util/util.dart' show Pair, Setlet; | 22 import '../util/util.dart' show Pair, Setlet; |
24 import 'work.dart' show WorkItem; | 23 import 'work.dart' show WorkItem; |
25 | 24 |
26 class CodegenImpact extends WorldImpact { | 25 class CodegenImpact extends WorldImpact { |
27 const CodegenImpact(); | 26 const CodegenImpact(); |
28 | 27 |
29 Iterable<Pair<ResolutionDartType, ResolutionDartType>> | 28 Iterable<Pair<DartType, DartType>> get typeVariableBoundsSubtypeChecks { |
30 get typeVariableBoundsSubtypeChecks { | 29 return const <Pair<DartType, DartType>>[]; |
31 return const <Pair<ResolutionDartType, ResolutionDartType>>[]; | |
32 } | 30 } |
33 | 31 |
34 Iterable<String> get constSymbols => const <String>[]; | 32 Iterable<String> get constSymbols => const <String>[]; |
35 | 33 |
36 Iterable<Set<ClassEntity>> get specializedGetInterceptors { | 34 Iterable<Set<ClassEntity>> get specializedGetInterceptors { |
37 return const <Set<ClassEntity>>[]; | 35 return const <Set<ClassEntity>>[]; |
38 } | 36 } |
39 | 37 |
40 bool get usesInterceptor => false; | 38 bool get usesInterceptor => false; |
41 | 39 |
42 Iterable<Element> get asyncMarkers => const <FunctionElement>[]; | 40 Iterable<AsyncMarker> get asyncMarkers => <AsyncMarker>[]; |
43 } | 41 } |
44 | 42 |
45 class _CodegenImpact extends WorldImpactBuilderImpl implements CodegenImpact { | 43 class _CodegenImpact extends WorldImpactBuilderImpl implements CodegenImpact { |
46 Setlet<Pair<ResolutionDartType, ResolutionDartType>> | 44 Setlet<Pair<DartType, DartType>> _typeVariableBoundsSubtypeChecks; |
47 _typeVariableBoundsSubtypeChecks; | |
48 Setlet<String> _constSymbols; | 45 Setlet<String> _constSymbols; |
49 List<Set<ClassEntity>> _specializedGetInterceptors; | 46 List<Set<ClassEntity>> _specializedGetInterceptors; |
50 bool _usesInterceptor = false; | 47 bool _usesInterceptor = false; |
51 Setlet<FunctionElement> _asyncMarkers; | 48 EnumSet<AsyncMarker> _asyncMarkers; |
52 | 49 |
53 _CodegenImpact(); | 50 _CodegenImpact(); |
54 | 51 |
55 void apply(WorldImpactVisitor visitor) { | 52 void apply(WorldImpactVisitor visitor) { |
56 staticUses.forEach(visitor.visitStaticUse); | 53 staticUses.forEach(visitor.visitStaticUse); |
57 dynamicUses.forEach(visitor.visitDynamicUse); | 54 dynamicUses.forEach(visitor.visitDynamicUse); |
58 typeUses.forEach(visitor.visitTypeUse); | 55 typeUses.forEach(visitor.visitTypeUse); |
59 } | 56 } |
60 | 57 |
61 void registerTypeVariableBoundsSubtypeCheck( | 58 void registerTypeVariableBoundsSubtypeCheck( |
62 ResolutionDartType subtype, ResolutionDartType supertype) { | 59 DartType subtype, DartType supertype) { |
63 if (_typeVariableBoundsSubtypeChecks == null) { | 60 if (_typeVariableBoundsSubtypeChecks == null) { |
64 _typeVariableBoundsSubtypeChecks = | 61 _typeVariableBoundsSubtypeChecks = new Setlet<Pair<DartType, DartType>>(); |
65 new Setlet<Pair<ResolutionDartType, ResolutionDartType>>(); | |
66 } | 62 } |
67 _typeVariableBoundsSubtypeChecks.add( | 63 _typeVariableBoundsSubtypeChecks |
68 new Pair<ResolutionDartType, ResolutionDartType>(subtype, supertype)); | 64 .add(new Pair<DartType, DartType>(subtype, supertype)); |
69 } | 65 } |
70 | 66 |
71 Iterable<Pair<ResolutionDartType, ResolutionDartType>> | 67 Iterable<Pair<DartType, DartType>> get typeVariableBoundsSubtypeChecks { |
72 get typeVariableBoundsSubtypeChecks { | |
73 return _typeVariableBoundsSubtypeChecks != null | 68 return _typeVariableBoundsSubtypeChecks != null |
74 ? _typeVariableBoundsSubtypeChecks | 69 ? _typeVariableBoundsSubtypeChecks |
75 : const <Pair<ResolutionDartType, ResolutionDartType>>[]; | 70 : const <Pair<DartType, DartType>>[]; |
76 } | 71 } |
77 | 72 |
78 void registerConstSymbol(String name) { | 73 void registerConstSymbol(String name) { |
79 if (_constSymbols == null) { | 74 if (_constSymbols == null) { |
80 _constSymbols = new Setlet<String>(); | 75 _constSymbols = new Setlet<String>(); |
81 } | 76 } |
82 _constSymbols.add(name); | 77 _constSymbols.add(name); |
83 } | 78 } |
84 | 79 |
85 Iterable<String> get constSymbols { | 80 Iterable<String> get constSymbols { |
(...skipping 12 matching lines...) Expand all Loading... |
98 ? _specializedGetInterceptors | 93 ? _specializedGetInterceptors |
99 : const <Set<ClassEntity>>[]; | 94 : const <Set<ClassEntity>>[]; |
100 } | 95 } |
101 | 96 |
102 void registerUseInterceptor() { | 97 void registerUseInterceptor() { |
103 _usesInterceptor = true; | 98 _usesInterceptor = true; |
104 } | 99 } |
105 | 100 |
106 bool get usesInterceptor => _usesInterceptor; | 101 bool get usesInterceptor => _usesInterceptor; |
107 | 102 |
108 void registerAsyncMarker(FunctionElement element) { | 103 void registerAsyncMarker(AsyncMarker asyncMarker) { |
109 if (_asyncMarkers == null) { | 104 if (_asyncMarkers == null) { |
110 _asyncMarkers = new Setlet<FunctionElement>(); | 105 _asyncMarkers = new EnumSet<AsyncMarker>(); |
111 } | 106 } |
112 _asyncMarkers.add(element); | 107 _asyncMarkers.add(asyncMarker); |
113 } | 108 } |
114 | 109 |
115 Iterable<Element> get asyncMarkers { | 110 Iterable<AsyncMarker> get asyncMarkers { |
116 return _asyncMarkers != null ? _asyncMarkers : const <FunctionElement>[]; | 111 return _asyncMarkers != null |
| 112 ? _asyncMarkers.iterable(AsyncMarker.values) |
| 113 : const <AsyncMarker>[]; |
117 } | 114 } |
118 } | 115 } |
119 | 116 |
120 // TODO(johnniwinther): Split this class into interface and implementation. | 117 // TODO(johnniwinther): Split this class into interface and implementation. |
121 // TODO(johnniwinther): Move this implementation to the JS backend. | 118 // TODO(johnniwinther): Move this implementation to the JS backend. |
122 class CodegenRegistry { | 119 class CodegenRegistry { |
123 final MemberElement currentElement; | 120 final MemberElement currentElement; |
124 final _CodegenImpact worldImpact; | 121 final _CodegenImpact worldImpact; |
125 | 122 |
126 CodegenRegistry(MemberElement currentElement) | 123 CodegenRegistry(MemberElement currentElement) |
(...skipping 19 matching lines...) Expand all Loading... |
146 | 143 |
147 void registerTypeUse(TypeUse typeUse) { | 144 void registerTypeUse(TypeUse typeUse) { |
148 worldImpact.registerTypeUse(typeUse); | 145 worldImpact.registerTypeUse(typeUse); |
149 } | 146 } |
150 | 147 |
151 void registerConstantUse(ConstantUse constantUse) { | 148 void registerConstantUse(ConstantUse constantUse) { |
152 worldImpact.registerConstantUse(constantUse); | 149 worldImpact.registerConstantUse(constantUse); |
153 } | 150 } |
154 | 151 |
155 void registerTypeVariableBoundsSubtypeCheck( | 152 void registerTypeVariableBoundsSubtypeCheck( |
156 ResolutionDartType subtype, ResolutionDartType supertype) { | 153 DartType subtype, DartType supertype) { |
157 worldImpact.registerTypeVariableBoundsSubtypeCheck(subtype, supertype); | 154 worldImpact.registerTypeVariableBoundsSubtypeCheck(subtype, supertype); |
158 } | 155 } |
159 | 156 |
160 void registerInstantiatedClosure(LocalFunctionElement element) { | 157 void registerInstantiatedClosure(LocalFunctionElement element) { |
161 worldImpact.registerStaticUse(new StaticUse.closure(element)); | 158 worldImpact.registerStaticUse(new StaticUse.closure(element)); |
162 } | 159 } |
163 | 160 |
164 void registerConstSymbol(String name) { | 161 void registerConstSymbol(String name) { |
165 worldImpact.registerConstSymbol(name); | 162 worldImpact.registerConstSymbol(name); |
166 } | 163 } |
167 | 164 |
168 void registerSpecializedGetInterceptor(Set<ClassEntity> classes) { | 165 void registerSpecializedGetInterceptor(Set<ClassEntity> classes) { |
169 worldImpact.registerSpecializedGetInterceptor(classes); | 166 worldImpact.registerSpecializedGetInterceptor(classes); |
170 } | 167 } |
171 | 168 |
172 void registerUseInterceptor() { | 169 void registerUseInterceptor() { |
173 worldImpact.registerUseInterceptor(); | 170 worldImpact.registerUseInterceptor(); |
174 } | 171 } |
175 | 172 |
176 void registerInstantiation(ResolutionInterfaceType type) { | 173 void registerInstantiation(InterfaceType type) { |
177 registerTypeUse(new TypeUse.instantiation(type)); | 174 registerTypeUse(new TypeUse.instantiation(type)); |
178 } | 175 } |
179 | 176 |
180 void registerAsyncMarker(FunctionElement element) { | 177 void registerAsyncMarker(AsyncMarker asyncMarker) { |
181 worldImpact.registerAsyncMarker(element); | 178 worldImpact.registerAsyncMarker(asyncMarker); |
182 } | 179 } |
183 } | 180 } |
184 | 181 |
185 /// [WorkItem] used exclusively by the [CodegenEnqueuer]. | 182 /// [WorkItem] used exclusively by the [CodegenEnqueuer]. |
186 class CodegenWorkItem extends WorkItem { | 183 class CodegenWorkItem extends WorkItem { |
187 CodegenRegistry registry; | 184 CodegenRegistry registry; |
188 final ResolvedAst resolvedAst; | 185 final ResolvedAst resolvedAst; |
189 final JavaScriptBackend backend; | 186 final JavaScriptBackend backend; |
190 | 187 |
191 factory CodegenWorkItem(JavaScriptBackend backend, MemberElement element) { | 188 factory CodegenWorkItem(JavaScriptBackend backend, MemberElement element) { |
(...skipping 12 matching lines...) Expand all Loading... |
204 | 201 |
205 MemberElement get element => resolvedAst.element; | 202 MemberElement get element => resolvedAst.element; |
206 | 203 |
207 WorldImpact run() { | 204 WorldImpact run() { |
208 registry = new CodegenRegistry(element); | 205 registry = new CodegenRegistry(element); |
209 return backend.codegen(this); | 206 return backend.codegen(this); |
210 } | 207 } |
211 | 208 |
212 String toString() => 'CodegenWorkItem(${resolvedAst.element})'; | 209 String toString() => 'CodegenWorkItem(${resolvedAst.element})'; |
213 } | 210 } |
OLD | NEW |