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 library dart2js.resolution.registry; | 5 library dart2js.resolution.registry; |
6 | 6 |
7 import '../common/backend_api.dart' show | 7 import '../common/backend_api.dart' show |
8 Backend, | 8 Backend, |
9 ForeignResolver; | 9 ForeignResolver; |
10 import '../common/resolution.dart' show | |
11 Feature, | |
12 ListLiteralUse, | |
13 MapLiteralUse, | |
14 ResolutionWorldImpact; | |
15 import '../common/registry.dart' show | 10 import '../common/registry.dart' show |
16 Registry; | 11 Registry; |
17 import '../compiler.dart' show | 12 import '../compiler.dart' show |
18 Compiler; | 13 Compiler; |
19 import '../constants/expressions.dart'; | 14 import '../constants/expressions.dart'; |
20 import '../dart_types.dart'; | 15 import '../dart_types.dart'; |
21 import '../diagnostics/invariant.dart' show | 16 import '../diagnostics/invariant.dart' show |
22 invariant; | 17 invariant; |
23 import '../enqueue.dart' show | 18 import '../enqueue.dart' show |
24 ResolutionEnqueuer; | 19 ResolutionEnqueuer, |
| 20 WorldImpact; |
25 import '../elements/elements.dart'; | 21 import '../elements/elements.dart'; |
26 import '../helpers/helpers.dart'; | |
27 import '../tree/tree.dart'; | 22 import '../tree/tree.dart'; |
28 import '../util/util.dart' show | 23 import '../util/util.dart' show |
29 Setlet; | 24 Setlet; |
30 import '../universe/call_structure.dart' show | 25 import '../universe/call_structure.dart' show |
31 CallStructure; | 26 CallStructure; |
32 import '../universe/selector.dart' show | 27 import '../universe/selector.dart' show |
33 Selector; | 28 Selector; |
34 import '../universe/universe.dart' show | 29 import '../universe/universe.dart' show |
35 UniverseSelector; | 30 UniverseSelector; |
36 import '../world.dart' show World; | 31 import '../world.dart' show World; |
37 | 32 |
38 import 'send_structure.dart'; | 33 import 'send_structure.dart'; |
39 | 34 |
40 import 'members.dart' show | 35 import 'members.dart' show |
41 ResolverVisitor; | 36 ResolverVisitor; |
42 import 'tree_elements.dart' show | 37 import 'tree_elements.dart' show |
43 TreeElementMapping; | 38 TreeElementMapping; |
44 | 39 |
45 // TODO(johnniwinther): Remove this. | 40 /// [ResolutionRegistry] collects all resolution information. It stores node |
| 41 /// related information in a [TreeElements] mapping and registers calls with |
| 42 /// [Backend], [World] and [Enqueuer]. |
| 43 // TODO(johnniwinther): Split this into an interface and implementation class. |
| 44 |
46 class EagerRegistry implements Registry { | 45 class EagerRegistry implements Registry { |
47 final Compiler compiler; | 46 final Compiler compiler; |
48 final TreeElementMapping mapping; | 47 final TreeElementMapping mapping; |
49 | 48 |
50 EagerRegistry(this.compiler, this.mapping); | 49 EagerRegistry(this.compiler, this.mapping); |
51 | 50 |
52 ResolutionEnqueuer get world => compiler.enqueuer.resolution; | 51 ResolutionEnqueuer get world => compiler.enqueuer.resolution; |
53 | 52 |
54 @override | 53 @override |
55 bool get isForResolution => true; | 54 bool get isForResolution => true; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 93 |
95 @override | 94 @override |
96 void registerStaticInvocation(Element element) { | 95 void registerStaticInvocation(Element element) { |
97 registerDependency(element); | 96 registerDependency(element); |
98 world.registerStaticUse(element); | 97 world.registerStaticUse(element); |
99 } | 98 } |
100 | 99 |
101 String toString() => 'EagerRegistry for ${mapping.analyzedElement}'; | 100 String toString() => 'EagerRegistry for ${mapping.analyzedElement}'; |
102 } | 101 } |
103 | 102 |
104 class _ResolutionWorldImpact implements ResolutionWorldImpact { | 103 class ResolutionWorldImpact implements WorldImpact { |
105 final Registry registry; | 104 final Registry registry; |
106 // TODO(johnniwinther): Do we benefit from lazy initialization of the | |
107 // [Setlet]s? | |
108 Setlet<UniverseSelector> _dynamicInvocations; | 105 Setlet<UniverseSelector> _dynamicInvocations; |
109 Setlet<UniverseSelector> _dynamicGetters; | 106 Setlet<UniverseSelector> _dynamicGetters; |
110 Setlet<UniverseSelector> _dynamicSetters; | 107 Setlet<UniverseSelector> _dynamicSetters; |
111 Setlet<InterfaceType> _instantiatedTypes; | 108 Setlet<InterfaceType> _instantiatedTypes; |
112 Setlet<Element> _staticUses; | 109 Setlet<Element> _staticUses; |
113 Setlet<DartType> _isChecks; | 110 Setlet<DartType> _checkedTypes; |
114 Setlet<DartType> _asCasts; | |
115 Setlet<DartType> _checkedModeChecks; | |
116 Setlet<MethodElement> _closurizedFunctions; | 111 Setlet<MethodElement> _closurizedFunctions; |
117 Setlet<LocalFunctionElement> _closures; | |
118 Setlet<Feature> _features; | |
119 // TODO(johnniwinther): This seems to be a union of other sets. | |
120 Setlet<DartType> _requiredTypes; | |
121 Setlet<MapLiteralUse> _mapLiterals; | |
122 Setlet<ListLiteralUse> _listLiterals; | |
123 Setlet<DartType> _typeLiterals; | |
124 Setlet<String> _constSymbolNames; | |
125 | 112 |
126 _ResolutionWorldImpact(Compiler compiler, TreeElementMapping mapping) | 113 ResolutionWorldImpact(Compiler compiler, TreeElementMapping mapping) |
127 : this.registry = new EagerRegistry(compiler, mapping); | 114 : this.registry = new EagerRegistry(compiler, mapping); |
128 | 115 |
129 void registerDependency(Element element) { | |
130 registry.registerDependency(element); | |
131 } | |
132 | |
133 void registerDynamicGetter(UniverseSelector selector) { | 116 void registerDynamicGetter(UniverseSelector selector) { |
134 if (_dynamicGetters == null) { | 117 if (_dynamicGetters == null) { |
135 _dynamicGetters = new Setlet<UniverseSelector>(); | 118 _dynamicGetters = new Setlet<UniverseSelector>(); |
136 } | 119 } |
137 _dynamicGetters.add(selector); | 120 _dynamicGetters.add(selector); |
138 } | 121 } |
139 | 122 |
140 @override | 123 @override |
141 Iterable<UniverseSelector> get dynamicGetters { | 124 Iterable<UniverseSelector> get dynamicGetters { |
142 return _dynamicGetters != null | 125 return _dynamicGetters != null |
(...skipping 20 matching lines...) Expand all Loading... |
163 _dynamicSetters.add(selector); | 146 _dynamicSetters.add(selector); |
164 } | 147 } |
165 | 148 |
166 @override | 149 @override |
167 Iterable<UniverseSelector> get dynamicSetters { | 150 Iterable<UniverseSelector> get dynamicSetters { |
168 return _dynamicSetters != null | 151 return _dynamicSetters != null |
169 ? _dynamicSetters : const <UniverseSelector>[]; | 152 ? _dynamicSetters : const <UniverseSelector>[]; |
170 } | 153 } |
171 | 154 |
172 void registerInstantiatedType(InterfaceType type) { | 155 void registerInstantiatedType(InterfaceType type) { |
| 156 // TODO(johnniwinther): Enable this when registration doesn't require a |
| 157 // [Registry]. |
| 158 throw new UnsupportedError( |
| 159 'Lazy registration of instantiated not supported.'); |
173 if (_instantiatedTypes == null) { | 160 if (_instantiatedTypes == null) { |
174 _instantiatedTypes = new Setlet<InterfaceType>(); | 161 _instantiatedTypes = new Setlet<InterfaceType>(); |
175 } | 162 } |
176 _instantiatedTypes.add(type); | 163 _instantiatedTypes.add(type); |
177 } | 164 } |
178 | 165 |
179 @override | 166 @override |
180 Iterable<InterfaceType> get instantiatedTypes { | 167 Iterable<InterfaceType> get instantiatedTypes { |
181 return _instantiatedTypes != null | 168 return _instantiatedTypes != null |
182 ? _instantiatedTypes : const <InterfaceType>[]; | 169 ? _instantiatedTypes : const <InterfaceType>[]; |
183 } | 170 } |
184 | 171 |
185 void registerTypeLiteral(DartType type) { | |
186 if (_typeLiterals == null) { | |
187 _typeLiterals = new Setlet<DartType>(); | |
188 } | |
189 _typeLiterals.add(type); | |
190 } | |
191 | |
192 @override | |
193 Iterable<DartType> get typeLiterals { | |
194 return _typeLiterals != null | |
195 ? _typeLiterals : const <DartType>[]; | |
196 } | |
197 | |
198 void registerRequiredType(DartType type) { | |
199 if (_requiredTypes == null) { | |
200 _requiredTypes = new Setlet<DartType>(); | |
201 } | |
202 _requiredTypes.add(type); | |
203 } | |
204 | |
205 @override | |
206 Iterable<DartType> get requiredTypes { | |
207 return _requiredTypes != null | |
208 ? _requiredTypes : const <DartType>[]; | |
209 } | |
210 | |
211 void registerMapLiteral(MapLiteralUse mapLiteralUse) { | |
212 if (_mapLiterals == null) { | |
213 _mapLiterals = new Setlet<MapLiteralUse>(); | |
214 } | |
215 _mapLiterals.add(mapLiteralUse); | |
216 } | |
217 | |
218 @override | |
219 Iterable<MapLiteralUse> get mapLiterals { | |
220 return _mapLiterals != null | |
221 ? _mapLiterals : const <MapLiteralUse>[]; | |
222 } | |
223 | |
224 void registerListLiteral(ListLiteralUse listLiteralUse) { | |
225 if (_listLiterals == null) { | |
226 _listLiterals = new Setlet<ListLiteralUse>(); | |
227 } | |
228 _listLiterals.add(listLiteralUse); | |
229 } | |
230 | |
231 @override | |
232 Iterable<ListLiteralUse> get listLiterals { | |
233 return _listLiterals != null | |
234 ? _listLiterals : const <ListLiteralUse>[]; | |
235 } | |
236 | |
237 void registerStaticUse(Element element) { | 172 void registerStaticUse(Element element) { |
238 if (_staticUses == null) { | 173 if (_staticUses == null) { |
239 _staticUses = new Setlet<Element>(); | 174 _staticUses = new Setlet<Element>(); |
240 } | 175 } |
241 _staticUses.add(element); | 176 _staticUses.add(element); |
242 } | 177 } |
243 | 178 |
244 @override | 179 @override |
245 Iterable<Element> get staticUses { | 180 Iterable<Element> get staticUses { |
246 return _staticUses != null ? _staticUses : const <Element>[]; | 181 return _staticUses != null ? _staticUses : const <Element>[]; |
247 } | 182 } |
248 | 183 |
249 void registerIsCheck(DartType type) { | 184 void registerCheckedType(DartType type) { |
250 if (_isChecks == null) { | 185 if (_checkedTypes == null) { |
251 _isChecks = new Setlet<DartType>(); | 186 _checkedTypes = new Setlet<DartType>(); |
252 } | 187 } |
253 _isChecks.add(type); | 188 _checkedTypes.add(type); |
254 } | 189 } |
255 | 190 |
256 @override | 191 @override |
257 Iterable<DartType> get isChecks { | 192 Iterable<DartType> get checkedTypes { |
258 return _isChecks != null | 193 return _checkedTypes != null |
259 ? _isChecks : const <DartType>[]; | 194 ? _checkedTypes : const <DartType>[]; |
260 } | |
261 | |
262 void registerAsCast(DartType type) { | |
263 if (_asCasts == null) { | |
264 _asCasts = new Setlet<DartType>(); | |
265 } | |
266 _asCasts.add(type); | |
267 } | |
268 | |
269 @override | |
270 Iterable<DartType> get asCasts { | |
271 return _asCasts != null | |
272 ? _asCasts : const <DartType>[]; | |
273 } | |
274 | |
275 void registerCheckedModeCheckedType(DartType type) { | |
276 if (_checkedModeChecks == null) { | |
277 _checkedModeChecks = new Setlet<DartType>(); | |
278 } | |
279 _checkedModeChecks.add(type); | |
280 } | |
281 | |
282 @override | |
283 Iterable<DartType> get checkedModeChecks { | |
284 return _checkedModeChecks != null | |
285 ? _checkedModeChecks : const <DartType>[]; | |
286 } | 195 } |
287 | 196 |
288 void registerClosurizedFunction(MethodElement element) { | 197 void registerClosurizedFunction(MethodElement element) { |
289 if (_closurizedFunctions == null) { | 198 if (_closurizedFunctions == null) { |
290 _closurizedFunctions = new Setlet<MethodElement>(); | 199 _closurizedFunctions = new Setlet<MethodElement>(); |
291 } | 200 } |
292 _closurizedFunctions.add(element); | 201 _closurizedFunctions.add(element); |
293 } | 202 } |
294 | 203 |
295 @override | 204 @override |
296 Iterable<MethodElement> get closurizedFunctions { | 205 Iterable<MethodElement> get closurizedFunctions { |
297 return _closurizedFunctions != null | 206 return _closurizedFunctions != null |
298 ? _closurizedFunctions : const <MethodElement>[]; | 207 ? _closurizedFunctions : const <MethodElement>[]; |
299 } | 208 } |
300 | |
301 void registerClosure(LocalFunctionElement element) { | |
302 if (_closures == null) { | |
303 _closures = new Setlet<LocalFunctionElement>(); | |
304 } | |
305 _closures.add(element); | |
306 } | |
307 | |
308 @override | |
309 Iterable<LocalFunctionElement> get closures { | |
310 return _closures != null | |
311 ? _closures : const <LocalFunctionElement>[]; | |
312 } | |
313 | |
314 void registerConstSymbolName(String name) { | |
315 if (_constSymbolNames == null) { | |
316 _constSymbolNames = new Setlet<String>(); | |
317 } | |
318 _constSymbolNames.add(name); | |
319 } | |
320 | |
321 @override | |
322 Iterable<String> get constSymbolNames { | |
323 return _constSymbolNames != null | |
324 ? _constSymbolNames : const <String>[]; | |
325 } | |
326 | |
327 void registerFeature(Feature feature) { | |
328 if (_features == null) { | |
329 _features = new Setlet<Feature>(); | |
330 } | |
331 _features.add(feature); | |
332 } | |
333 | |
334 @override | |
335 Iterable<Feature> get features { | |
336 return _features != null ? _features : const <Feature>[]; | |
337 } | |
338 | |
339 String toString() => '$registry'; | |
340 } | 209 } |
341 | 210 |
342 /// [ResolutionRegistry] collects all resolution information. It stores node | |
343 /// related information in a [TreeElements] mapping and registers calls with | |
344 /// [Backend], [World] and [Enqueuer]. | |
345 // TODO(johnniwinther): Split this into an interface and implementation class. | |
346 class ResolutionRegistry implements Registry { | 211 class ResolutionRegistry implements Registry { |
347 final Compiler compiler; | 212 final Compiler compiler; |
348 final TreeElementMapping mapping; | 213 final TreeElementMapping mapping; |
349 final _ResolutionWorldImpact worldImpact; | 214 final ResolutionWorldImpact worldImpact; |
350 | 215 |
351 ResolutionRegistry(Compiler compiler, TreeElementMapping mapping) | 216 ResolutionRegistry(Compiler compiler, TreeElementMapping mapping) |
352 : this.compiler = compiler, | 217 : this.compiler = compiler, |
353 this.mapping = mapping, | 218 this.mapping = mapping, |
354 this.worldImpact = new _ResolutionWorldImpact(compiler, mapping); | 219 this.worldImpact = new ResolutionWorldImpact(compiler, mapping); |
355 | 220 |
356 bool get isForResolution => true; | 221 bool get isForResolution => true; |
357 | 222 |
358 ResolutionEnqueuer get world => compiler.enqueuer.resolution; | 223 ResolutionEnqueuer get world => compiler.enqueuer.resolution; |
359 | 224 |
360 World get universe => compiler.world; | 225 World get universe => compiler.world; |
361 | 226 |
362 Backend get backend => compiler.backend; | 227 Backend get backend => compiler.backend; |
363 | 228 |
364 String toString() => 'ResolutionRegistry for ${mapping.analyzedElement}'; | 229 String toString() => 'ResolutionRegistry for ${mapping.analyzedElement}'; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 | 394 |
530 ////////////////////////////////////////////////////////////////////////////// | 395 ////////////////////////////////////////////////////////////////////////////// |
531 // Various Backend/Enqueuer/World registration. | 396 // Various Backend/Enqueuer/World registration. |
532 ////////////////////////////////////////////////////////////////////////////// | 397 ////////////////////////////////////////////////////////////////////////////// |
533 | 398 |
534 void registerStaticUse(Element element) { | 399 void registerStaticUse(Element element) { |
535 worldImpact.registerStaticUse(element); | 400 worldImpact.registerStaticUse(element); |
536 } | 401 } |
537 | 402 |
538 void registerImplicitSuperCall(FunctionElement superConstructor) { | 403 void registerImplicitSuperCall(FunctionElement superConstructor) { |
539 registerDependency(superConstructor); | 404 universe.registerImplicitSuperCall(this, superConstructor); |
540 } | 405 } |
541 | 406 |
542 // TODO(johnniwinther): Remove this. | 407 // TODO(johnniwinther): Remove this. |
543 // Use [registerInstantiatedType] of `rawType` instead. | 408 // Use [registerInstantiatedType] of `rawType` instead. |
544 @deprecated | 409 @deprecated |
545 void registerInstantiatedClass(ClassElement element) { | 410 void registerInstantiatedClass(ClassElement element) { |
546 element.ensureResolved(compiler.resolution); | 411 element.ensureResolved(compiler.resolution); |
547 registerInstantiatedType(element.rawType); | 412 registerInstantiatedType(element.rawType); |
548 } | 413 } |
549 | 414 |
550 void registerLazyField() { | 415 void registerLazyField() { |
551 worldImpact.registerFeature(Feature.LAZY_FIELD); | 416 backend.resolutionCallbacks.onLazyField(this); |
552 } | 417 } |
553 | 418 |
554 void registerMetadataConstant(MetadataAnnotation metadata) { | 419 void registerMetadataConstant(MetadataAnnotation metadata, |
555 backend.registerMetadataConstant(metadata, metadata.annotatedElement, this); | 420 Element annotatedElement) { |
| 421 backend.registerMetadataConstant(metadata, annotatedElement, this); |
556 } | 422 } |
557 | 423 |
558 void registerThrowRuntimeError() { | 424 void registerThrowRuntimeError() { |
559 worldImpact.registerFeature(Feature.THROW_RUNTIME_ERROR); | 425 backend.resolutionCallbacks.onThrowRuntimeError(this); |
560 } | 426 } |
561 | 427 |
562 void registerCompileTimeError(ErroneousElement error) { | 428 void registerCompileTimeError(ErroneousElement error) { |
563 worldImpact.registerFeature(Feature.COMPILE_TIME_ERROR); | 429 backend.resolutionCallbacks.onCompileTimeError(this, error); |
564 } | 430 } |
565 | 431 |
566 void registerTypeVariableBoundCheck() { | 432 void registerTypeVariableBoundCheck() { |
567 worldImpact.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); | 433 backend.resolutionCallbacks.onTypeVariableBoundCheck(this); |
568 } | 434 } |
569 | 435 |
570 void registerThrowNoSuchMethod() { | 436 void registerThrowNoSuchMethod() { |
571 worldImpact.registerFeature(Feature.THROW_NO_SUCH_METHOD); | 437 backend.resolutionCallbacks.onThrowNoSuchMethod(this); |
572 } | 438 } |
573 | 439 |
574 /// Register a checked mode check against [type]. | 440 void registerIsCheck(DartType type) { |
575 void registerCheckedModeCheck(DartType type) { | 441 worldImpact.registerCheckedType(type); |
576 worldImpact.registerCheckedModeCheckedType(type); | 442 backend.resolutionCallbacks.onIsCheck(type, this); |
577 mapping.addRequiredType(type); | 443 mapping.addRequiredType(type); |
578 } | 444 } |
579 | 445 |
580 /// Register an is-test or is-not-test of [type]. | 446 void registerAsCheck(DartType type) { |
581 void registerIsCheck(DartType type) { | 447 registerIsCheck(type); |
582 worldImpact.registerIsCheck(type); | 448 backend.resolutionCallbacks.onAsCheck(type, this); |
583 mapping.addRequiredType(type); | |
584 } | |
585 | |
586 /// Register an as-cast of [type]. | |
587 void registerAsCast(DartType type) { | |
588 worldImpact.registerAsCast(type); | |
589 mapping.addRequiredType(type); | 449 mapping.addRequiredType(type); |
590 } | 450 } |
591 | 451 |
592 void registerClosure(LocalFunctionElement element) { | 452 void registerClosure(LocalFunctionElement element) { |
593 worldImpact.registerClosure(element); | 453 if (element.computeType(compiler.resolution).containsTypeVariables) { |
| 454 backend.registerClosureWithFreeTypeVariables(element, world, this); |
| 455 } |
| 456 world.registerClosure(element); |
594 } | 457 } |
595 | 458 |
596 void registerSuperUse(Node node) { | 459 void registerSuperUse(Node node) { |
597 mapping.addSuperUse(node); | 460 mapping.addSuperUse(node); |
598 } | 461 } |
599 | 462 |
600 void registerDynamicInvocation(UniverseSelector selector) { | 463 void registerDynamicInvocation(UniverseSelector selector) { |
601 worldImpact.registerDynamicInvocation(selector); | 464 worldImpact.registerDynamicInvocation(selector); |
602 } | 465 } |
603 | 466 |
604 void registerSuperNoSuchMethod() { | 467 void registerSuperNoSuchMethod() { |
605 worldImpact.registerFeature(Feature.SUPER_NO_SUCH_METHOD); | 468 backend.resolutionCallbacks.onSuperNoSuchMethod(this); |
| 469 } |
| 470 |
| 471 void registerTypeVariableExpression(TypeVariableElement element) { |
| 472 backend.resolutionCallbacks.onTypeVariableExpression(this, element); |
606 } | 473 } |
607 | 474 |
608 void registerTypeLiteral(Send node, DartType type) { | 475 void registerTypeLiteral(Send node, DartType type) { |
609 mapping.setType(node, type); | 476 mapping.setType(node, type); |
610 worldImpact.registerTypeLiteral(type); | 477 backend.resolutionCallbacks.onTypeLiteral(type, this); |
| 478 backend.registerInstantiatedType(compiler.coreTypes.typeType, world, this); |
611 } | 479 } |
612 | 480 |
613 void registerLiteralList(Node node, | 481 void registerMapLiteral(Node node, DartType type, bool isConstant) { |
614 InterfaceType type, | |
615 {bool isConstant, | |
616 bool isEmpty}) { | |
617 setType(node, type); | 482 setType(node, type); |
618 worldImpact.registerListLiteral( | 483 backend.resolutionCallbacks.onMapLiteral(this, type, isConstant); |
619 new ListLiteralUse(type, isConstant: isConstant, isEmpty: isEmpty)); | |
620 } | |
621 | |
622 void registerMapLiteral(Node node, | |
623 InterfaceType type, | |
624 {bool isConstant, | |
625 bool isEmpty}) { | |
626 setType(node, type); | |
627 worldImpact.registerMapLiteral( | |
628 new MapLiteralUse(type, isConstant: isConstant, isEmpty: isEmpty)); | |
629 } | 484 } |
630 | 485 |
631 void registerForeignCall(Node node, | 486 void registerForeignCall(Node node, |
632 Element element, | 487 Element element, |
633 CallStructure callStructure, | 488 CallStructure callStructure, |
634 ResolverVisitor visitor) { | 489 ResolverVisitor visitor) { |
635 backend.registerForeignCall( | 490 backend.registerForeignCall( |
636 node, element, callStructure, | 491 node, element, callStructure, |
637 new ForeignResolutionResolver(visitor, this)); | 492 new ForeignResolutionResolver(visitor, this)); |
638 } | 493 } |
639 | 494 |
640 void registerGetOfStaticFunction(FunctionElement element) { | 495 void registerGetOfStaticFunction(FunctionElement element) { |
641 worldImpact.registerClosurizedFunction(element); | 496 worldImpact.registerClosurizedFunction(element); |
642 } | 497 } |
643 | 498 |
644 void registerDynamicGetter(UniverseSelector selector) { | 499 void registerDynamicGetter(UniverseSelector selector) { |
645 assert(selector.selector.isGetter); | 500 assert(selector.selector.isGetter); |
646 worldImpact.registerDynamicGetter(selector); | 501 worldImpact.registerDynamicGetter(selector); |
647 } | 502 } |
648 | 503 |
649 void registerDynamicSetter(UniverseSelector selector) { | 504 void registerDynamicSetter(UniverseSelector selector) { |
650 assert(selector.selector.isSetter); | 505 assert(selector.selector.isSetter); |
651 worldImpact.registerDynamicSetter(selector); | 506 worldImpact.registerDynamicSetter(selector); |
652 } | 507 } |
653 | 508 |
654 void registerConstSymbol(String name) { | 509 void registerConstSymbol(String name) { |
655 worldImpact.registerConstSymbolName(name); | 510 backend.registerConstSymbol(name, this); |
656 } | 511 } |
657 | 512 |
658 void registerSymbolConstructor() { | 513 void registerSymbolConstructor() { |
659 worldImpact.registerFeature(Feature.SYMBOL_CONSTRUCTOR); | 514 backend.resolutionCallbacks.onSymbolConstructor(this); |
660 } | 515 } |
661 | 516 |
662 void registerInstantiatedType(InterfaceType type) { | 517 void registerInstantiatedType(InterfaceType type) { |
663 worldImpact.registerInstantiatedType(type); | 518 backend.registerInstantiatedType(type, world, this); |
664 mapping.addRequiredType(type); | 519 mapping.addRequiredType(type); |
665 } | 520 } |
666 | 521 |
667 void registerAbstractClassInstantiation() { | 522 void registerAbstractClassInstantiation() { |
668 worldImpact.registerFeature(Feature.ABSTRACT_CLASS_INSTANTIATION); | 523 backend.resolutionCallbacks.onAbstractClassInstantiation(this); |
669 } | 524 } |
670 | 525 |
671 void registerNewSymbol() { | 526 void registerNewSymbol() { |
672 worldImpact.registerFeature(Feature.NEW_SYMBOL); | 527 backend.registerNewSymbol(this); |
673 } | 528 } |
674 | 529 |
675 void registerRequiredType(DartType type, Element enclosingElement) { | 530 void registerRequiredType(DartType type, Element enclosingElement) { |
676 worldImpact.registerRequiredType(type); | 531 backend.registerRequiredType(type, enclosingElement); |
677 mapping.addRequiredType(type); | 532 mapping.addRequiredType(type); |
678 } | 533 } |
679 | 534 |
680 void registerStringInterpolation() { | 535 void registerStringInterpolation() { |
681 worldImpact.registerFeature(Feature.STRING_INTERPOLATION); | 536 backend.resolutionCallbacks.onStringInterpolation(this); |
682 } | 537 } |
683 | 538 |
684 void registerFallThroughError() { | 539 void registerFallThroughError() { |
685 worldImpact.registerFeature(Feature.FALL_THROUGH_ERROR); | 540 backend.resolutionCallbacks.onFallThroughError(this); |
686 } | 541 } |
687 | 542 |
688 void registerCatchStatement() { | 543 void registerCatchStatement() { |
689 worldImpact.registerFeature(Feature.CATCH_STATEMENT); | 544 backend.resolutionCallbacks.onCatchStatement(this); |
690 } | 545 } |
691 | 546 |
692 void registerStackTraceInCatch() { | 547 void registerStackTraceInCatch() { |
693 worldImpact.registerFeature(Feature.STACK_TRACE_IN_CATCH); | 548 backend.resolutionCallbacks.onStackTraceInCatch(this); |
694 } | 549 } |
695 | 550 |
696 void registerSyncForIn(Node node) { | 551 void registerSyncForIn(Node node) { |
697 worldImpact.registerFeature(Feature.SYNC_FOR_IN); | 552 backend.resolutionCallbacks.onSyncForIn(this); |
698 } | 553 } |
699 | 554 |
700 ClassElement defaultSuperclass(ClassElement element) { | 555 ClassElement defaultSuperclass(ClassElement element) { |
701 return backend.defaultSuperclass(element); | 556 return backend.defaultSuperclass(element); |
702 } | 557 } |
703 | 558 |
704 void registerMixinUse(MixinApplicationElement mixinApplication, | 559 void registerMixinUse(MixinApplicationElement mixinApplication, |
705 ClassElement mixin) { | 560 ClassElement mixin) { |
706 universe.registerMixinUse(mixinApplication, mixin); | 561 universe.registerMixinUse(mixinApplication, mixin); |
707 } | 562 } |
708 | 563 |
709 void registerThrowExpression() { | 564 void registerThrowExpression() { |
710 worldImpact.registerFeature(Feature.THROW_EXPRESSION); | 565 backend.resolutionCallbacks.onThrowExpression(this); |
711 } | 566 } |
712 | 567 |
713 void registerDependency(Element element) { | 568 void registerDependency(Element element) { |
714 mapping.registerDependency(element); | 569 mapping.registerDependency(element); |
715 } | 570 } |
716 | 571 |
717 Setlet<Element> get otherDependencies => mapping.otherDependencies; | 572 Setlet<Element> get otherDependencies => mapping.otherDependencies; |
718 | 573 |
719 void registerStaticInvocation(Element element) { | 574 void registerStaticInvocation(Element element) { |
720 // TODO(johnniwinther): Increase precision of [registerStaticUse] and | 575 // TODO(johnniwinther): Increase precision of [registerStaticUse] and |
721 // [registerDependency]. | 576 // [registerDependency]. |
722 if (element == null) return; | 577 if (element == null) return; |
723 registerStaticUse(element); | 578 registerStaticUse(element); |
724 registerDependency(element); | 579 registerDependency(element); |
725 } | 580 } |
726 | 581 |
727 void registerInstantiation(InterfaceType type) { | 582 void registerInstantiation(InterfaceType type) { |
728 registerInstantiatedType(type); | 583 backend.registerInstantiatedType(type, world, this); |
729 } | 584 } |
730 | 585 |
731 void registerAssert(bool hasMessage) { | 586 void registerAssert(bool hasMessage) { |
732 worldImpact.registerFeature( | 587 backend.resolutionCallbacks.onAssert(hasMessage, this); |
733 hasMessage ? Feature.ASSERT_WITH_MESSAGE : Feature.ASSERT); | |
734 } | 588 } |
735 | 589 |
736 void registerSendStructure(Send node, SendStructure sendStructure) { | 590 void registerSendStructure(Send node, SendStructure sendStructure) { |
737 mapping.setSendStructure(node, sendStructure); | 591 mapping.setSendStructure(node, sendStructure); |
738 } | 592 } |
739 | 593 |
740 // TODO(johnniwinther): Remove this when [SendStructure]s are part of the | 594 // TODO(johnniwinther): Remove this when [SendStructure]s are part of the |
741 // [ResolutionResult]. | 595 // [ResolutionResult]. |
742 SendStructure getSendStructure(Send node) { | 596 SendStructure getSendStructure(Send node) { |
743 return mapping.getSendStructure(node); | 597 return mapping.getSendStructure(node); |
744 } | 598 } |
745 | 599 |
746 void registerAsyncMarker(FunctionElement element) { | 600 void registerAsyncMarker(FunctionElement element) { |
747 switch (element.asyncMarker) { | 601 backend.registerAsyncMarker(element, world, this); |
748 case AsyncMarker.SYNC: | |
749 break; | |
750 case AsyncMarker.SYNC_STAR: | |
751 worldImpact.registerFeature(Feature.SYNC_STAR); | |
752 break; | |
753 case AsyncMarker.ASYNC: | |
754 worldImpact.registerFeature(Feature.ASYNC); | |
755 break; | |
756 case AsyncMarker.ASYNC_STAR: | |
757 worldImpact.registerFeature(Feature.ASYNC_STAR); | |
758 break; | |
759 } | |
760 } | 602 } |
761 | 603 |
762 void registerAsyncForIn(AsyncForIn node) { | 604 void registerAsyncForIn(AsyncForIn node) { |
763 worldImpact.registerFeature(Feature.ASYNC_FOR_IN); | 605 backend.resolutionCallbacks.onAsyncForIn(node, this); |
764 } | 606 } |
765 | 607 |
766 void registerIncDecOperation() { | 608 void registerIncDecOperation() { |
767 worldImpact.registerFeature(Feature.INC_DEC_OPERATION); | 609 backend.resolutionCallbacks.onIncDecOperation(this); |
768 } | 610 } |
769 | 611 |
770 void registerTryStatement() { | 612 void registerTryStatement() { |
771 mapping.containsTryStatement = true; | 613 mapping.containsTryStatement = true; |
772 } | 614 } |
773 } | 615 } |
774 | 616 |
775 class ForeignResolutionResolver implements ForeignResolver { | 617 class ForeignResolutionResolver implements ForeignResolver { |
776 final ResolverVisitor visitor; | 618 final ResolverVisitor visitor; |
777 final ResolutionRegistry registry; | 619 final ResolutionRegistry registry; |
778 | 620 |
779 ForeignResolutionResolver(this.visitor, this.registry); | 621 ForeignResolutionResolver(this.visitor, this.registry); |
780 | 622 |
781 @override | 623 @override |
782 ConstantExpression getConstant(Node node) { | 624 ConstantExpression getConstant(Node node) { |
783 return registry.getConstant(node); | 625 return registry.getConstant(node); |
784 } | 626 } |
785 | 627 |
786 @override | 628 @override |
787 void registerInstantiatedType(InterfaceType type) { | 629 void registerInstantiatedType(InterfaceType type) { |
788 registry.registerInstantiatedType(type); | 630 registry.registerInstantiatedType(type); |
789 } | 631 } |
790 | 632 |
791 @override | 633 @override |
792 DartType resolveTypeFromString(Node node, String typeName) { | 634 DartType resolveTypeFromString(Node node, String typeName) { |
793 return visitor.resolveTypeFromString(node, typeName); | 635 return visitor.resolveTypeFromString(node, typeName); |
794 } | 636 } |
795 } | 637 } |
OLD | NEW |