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