| 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.dart'; | 7 import '../common.dart'; |
| 8 import '../common/backend_api.dart' show | 8 import '../common/backend_api.dart' show |
| 9 Backend, | 9 Backend, |
| 10 ForeignResolver; | 10 ForeignResolver; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 ResolverVisitor; | 43 ResolverVisitor; |
| 44 import 'tree_elements.dart' show | 44 import 'tree_elements.dart' show |
| 45 TreeElementMapping; | 45 TreeElementMapping; |
| 46 | 46 |
| 47 class _ResolutionWorldImpact extends ResolutionImpact with WorldImpactBuilder { | 47 class _ResolutionWorldImpact extends ResolutionImpact with WorldImpactBuilder { |
| 48 final String name; | 48 final String name; |
| 49 Setlet<Feature> _features; | 49 Setlet<Feature> _features; |
| 50 Setlet<MapLiteralUse> _mapLiterals; | 50 Setlet<MapLiteralUse> _mapLiterals; |
| 51 Setlet<ListLiteralUse> _listLiterals; | 51 Setlet<ListLiteralUse> _listLiterals; |
| 52 Setlet<String> _constSymbolNames; | 52 Setlet<String> _constSymbolNames; |
| 53 Setlet<ConstantExpression> _constantLiterals; |
| 53 | 54 |
| 54 _ResolutionWorldImpact(this.name); | 55 _ResolutionWorldImpact(this.name); |
| 55 | 56 |
| 56 void registerMapLiteral(MapLiteralUse mapLiteralUse) { | 57 void registerMapLiteral(MapLiteralUse mapLiteralUse) { |
| 57 assert(mapLiteralUse != null); | 58 assert(mapLiteralUse != null); |
| 58 if (_mapLiterals == null) { | 59 if (_mapLiterals == null) { |
| 59 _mapLiterals = new Setlet<MapLiteralUse>(); | 60 _mapLiterals = new Setlet<MapLiteralUse>(); |
| 60 } | 61 } |
| 61 _mapLiterals.add(mapLiteralUse); | 62 _mapLiterals.add(mapLiteralUse); |
| 62 } | 63 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 _features = new Setlet<Feature>(); | 100 _features = new Setlet<Feature>(); |
| 100 } | 101 } |
| 101 _features.add(feature); | 102 _features.add(feature); |
| 102 } | 103 } |
| 103 | 104 |
| 104 @override | 105 @override |
| 105 Iterable<Feature> get features { | 106 Iterable<Feature> get features { |
| 106 return _features != null ? _features : const <Feature>[]; | 107 return _features != null ? _features : const <Feature>[]; |
| 107 } | 108 } |
| 108 | 109 |
| 110 void registerConstantLiteral(ConstantExpression constant) { |
| 111 if (_constantLiterals == null) { |
| 112 _constantLiterals = new Setlet<ConstantExpression>(); |
| 113 } |
| 114 _constantLiterals.add(constant); |
| 115 } |
| 116 |
| 117 Iterable<ConstantExpression> get constantLiterals { |
| 118 return _constantLiterals != null |
| 119 ? _constantLiterals : const <ConstantExpression>[]; |
| 120 } |
| 121 |
| 109 String toString() => '_ResolutionWorldImpact($name)'; | 122 String toString() => '_ResolutionWorldImpact($name)'; |
| 110 } | 123 } |
| 111 | 124 |
| 112 /// [ResolutionRegistry] collects all resolution information. It stores node | 125 /// [ResolutionRegistry] collects all resolution information. It stores node |
| 113 /// related information in a [TreeElements] mapping and registers calls with | 126 /// related information in a [TreeElements] mapping and registers calls with |
| 114 /// [Backend], [World] and [Enqueuer]. | 127 /// [Backend], [World] and [Enqueuer]. |
| 115 // TODO(johnniwinther): Split this into an interface and implementation class. | 128 // TODO(johnniwinther): Split this into an interface and implementation class. |
| 116 class ResolutionRegistry extends Registry { | 129 class ResolutionRegistry extends Registry { |
| 117 final Compiler compiler; | 130 final Compiler compiler; |
| 118 final TreeElementMapping mapping; | 131 final TreeElementMapping mapping; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 } | 298 } |
| 286 | 299 |
| 287 ////////////////////////////////////////////////////////////////////////////// | 300 ////////////////////////////////////////////////////////////////////////////// |
| 288 // Various Backend/Enqueuer/World registration. | 301 // Various Backend/Enqueuer/World registration. |
| 289 ////////////////////////////////////////////////////////////////////////////// | 302 ////////////////////////////////////////////////////////////////////////////// |
| 290 | 303 |
| 291 void registerStaticUse(StaticUse staticUse) { | 304 void registerStaticUse(StaticUse staticUse) { |
| 292 worldImpact.registerStaticUse(staticUse); | 305 worldImpact.registerStaticUse(staticUse); |
| 293 } | 306 } |
| 294 | 307 |
| 295 void registerLazyField() { | |
| 296 worldImpact.registerFeature(Feature.LAZY_FIELD); | |
| 297 } | |
| 298 | |
| 299 void registerMetadataConstant(MetadataAnnotation metadata) { | 308 void registerMetadataConstant(MetadataAnnotation metadata) { |
| 300 backend.registerMetadataConstant(metadata, metadata.annotatedElement, this); | 309 backend.registerMetadataConstant(metadata, metadata.annotatedElement, this); |
| 301 } | 310 } |
| 302 | 311 |
| 303 void registerThrowRuntimeError() { | |
| 304 worldImpact.registerFeature(Feature.THROW_RUNTIME_ERROR); | |
| 305 } | |
| 306 | |
| 307 void registerCompileTimeError(ErroneousElement error) { | |
| 308 worldImpact.registerFeature(Feature.COMPILE_TIME_ERROR); | |
| 309 } | |
| 310 | |
| 311 void registerTypeVariableBoundCheck() { | |
| 312 worldImpact.registerFeature(Feature.TYPE_VARIABLE_BOUNDS_CHECK); | |
| 313 } | |
| 314 | |
| 315 void registerThrowNoSuchMethod() { | |
| 316 worldImpact.registerFeature(Feature.THROW_NO_SUCH_METHOD); | |
| 317 } | |
| 318 | |
| 319 /// Register the use of a type. | 312 /// Register the use of a type. |
| 320 void registerTypeUse(TypeUse typeUse) { | 313 void registerTypeUse(TypeUse typeUse) { |
| 321 worldImpact.registerTypeUse(typeUse); | 314 worldImpact.registerTypeUse(typeUse); |
| 322 } | 315 } |
| 323 | 316 |
| 324 void registerClosure(LocalFunctionElement element) { | 317 void registerClosure(LocalFunctionElement element) { |
| 325 worldImpact.registerClosure(element); | 318 worldImpact.registerClosure(element); |
| 326 } | 319 } |
| 327 | 320 |
| 328 void registerSuperUse(Node node) { | 321 void registerSuperUse(Node node) { |
| 329 mapping.addSuperUse(node); | 322 mapping.addSuperUse(node); |
| 330 } | 323 } |
| 331 | 324 |
| 332 void registerSuperNoSuchMethod() { | |
| 333 worldImpact.registerFeature(Feature.SUPER_NO_SUCH_METHOD); | |
| 334 } | |
| 335 | |
| 336 void registerTypeLiteral(Send node, DartType type) { | 325 void registerTypeLiteral(Send node, DartType type) { |
| 337 mapping.setType(node, type); | 326 mapping.setType(node, type); |
| 338 worldImpact.registerTypeUse(new TypeUse.typeLiteral(type)); | 327 worldImpact.registerTypeUse(new TypeUse.typeLiteral(type)); |
| 339 } | 328 } |
| 340 | 329 |
| 341 void registerLiteralList(Node node, | 330 void registerLiteralList(Node node, |
| 342 InterfaceType type, | 331 InterfaceType type, |
| 343 {bool isConstant, | 332 {bool isConstant, |
| 344 bool isEmpty}) { | 333 bool isEmpty}) { |
| 345 setType(node, type); | 334 setType(node, type); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 362 ResolverVisitor visitor) { | 351 ResolverVisitor visitor) { |
| 363 backend.registerForeignCall( | 352 backend.registerForeignCall( |
| 364 node, element, callStructure, | 353 node, element, callStructure, |
| 365 new ForeignResolutionResolver(visitor, this)); | 354 new ForeignResolutionResolver(visitor, this)); |
| 366 } | 355 } |
| 367 | 356 |
| 368 void registerDynamicUse(DynamicUse dynamicUse) { | 357 void registerDynamicUse(DynamicUse dynamicUse) { |
| 369 worldImpact.registerDynamicUse(dynamicUse); | 358 worldImpact.registerDynamicUse(dynamicUse); |
| 370 } | 359 } |
| 371 | 360 |
| 361 void registerFeature(Feature feature) { |
| 362 worldImpact.registerFeature(feature); |
| 363 } |
| 364 |
| 372 void registerConstSymbol(String name) { | 365 void registerConstSymbol(String name) { |
| 373 worldImpact.registerConstSymbolName(name); | 366 worldImpact.registerConstSymbolName(name); |
| 374 } | 367 } |
| 375 | 368 |
| 376 void registerSymbolConstructor() { | 369 void registerConstantLiteral(ConstantExpression constant) { |
| 377 worldImpact.registerFeature(Feature.SYMBOL_CONSTRUCTOR); | 370 worldImpact.registerConstantLiteral(constant); |
| 378 } | |
| 379 | |
| 380 void registerAbstractClassInstantiation() { | |
| 381 worldImpact.registerFeature(Feature.ABSTRACT_CLASS_INSTANTIATION); | |
| 382 } | |
| 383 | |
| 384 void registerStringInterpolation() { | |
| 385 worldImpact.registerFeature(Feature.STRING_INTERPOLATION); | |
| 386 } | |
| 387 | |
| 388 void registerFallThroughError() { | |
| 389 worldImpact.registerFeature(Feature.FALL_THROUGH_ERROR); | |
| 390 } | |
| 391 | |
| 392 void registerCatchStatement() { | |
| 393 worldImpact.registerFeature(Feature.CATCH_STATEMENT); | |
| 394 } | |
| 395 | |
| 396 void registerStackTraceInCatch() { | |
| 397 worldImpact.registerFeature(Feature.STACK_TRACE_IN_CATCH); | |
| 398 } | |
| 399 | |
| 400 void registerSyncForIn(Node node) { | |
| 401 worldImpact.registerFeature(Feature.SYNC_FOR_IN); | |
| 402 } | 371 } |
| 403 | 372 |
| 404 ClassElement defaultSuperclass(ClassElement element) { | 373 ClassElement defaultSuperclass(ClassElement element) { |
| 405 return backend.defaultSuperclass(element); | 374 return backend.defaultSuperclass(element); |
| 406 } | 375 } |
| 407 | 376 |
| 408 void registerMixinUse(MixinApplicationElement mixinApplication, | 377 void registerMixinUse(MixinApplicationElement mixinApplication, |
| 409 ClassElement mixin) { | 378 ClassElement mixin) { |
| 410 universe.registerMixinUse(mixinApplication, mixin); | 379 universe.registerMixinUse(mixinApplication, mixin); |
| 411 } | 380 } |
| 412 | 381 |
| 413 void registerThrowExpression() { | |
| 414 worldImpact.registerFeature(Feature.THROW_EXPRESSION); | |
| 415 } | |
| 416 | |
| 417 void registerInstantiation(InterfaceType type) { | 382 void registerInstantiation(InterfaceType type) { |
| 418 worldImpact.registerTypeUse(new TypeUse.instantiation(type)); | 383 worldImpact.registerTypeUse(new TypeUse.instantiation(type)); |
| 419 } | 384 } |
| 420 | 385 |
| 421 void registerAssert(bool hasMessage) { | |
| 422 worldImpact.registerFeature( | |
| 423 hasMessage ? Feature.ASSERT_WITH_MESSAGE : Feature.ASSERT); | |
| 424 } | |
| 425 | |
| 426 void registerSendStructure(Send node, SendStructure sendStructure) { | 386 void registerSendStructure(Send node, SendStructure sendStructure) { |
| 427 mapping.setSendStructure(node, sendStructure); | 387 mapping.setSendStructure(node, sendStructure); |
| 428 } | 388 } |
| 429 | 389 |
| 430 // TODO(johnniwinther): Remove this when [SendStructure]s are part of the | 390 // TODO(johnniwinther): Remove this when [SendStructure]s are part of the |
| 431 // [ResolutionResult]. | 391 // [ResolutionResult]. |
| 432 SendStructure getSendStructure(Send node) { | 392 SendStructure getSendStructure(Send node) { |
| 433 return mapping.getSendStructure(node); | 393 return mapping.getSendStructure(node); |
| 434 } | 394 } |
| 435 | 395 |
| 436 void registerAsyncMarker(FunctionElement element) { | |
| 437 switch (element.asyncMarker) { | |
| 438 case AsyncMarker.SYNC: | |
| 439 break; | |
| 440 case AsyncMarker.SYNC_STAR: | |
| 441 worldImpact.registerFeature(Feature.SYNC_STAR); | |
| 442 break; | |
| 443 case AsyncMarker.ASYNC: | |
| 444 worldImpact.registerFeature(Feature.ASYNC); | |
| 445 break; | |
| 446 case AsyncMarker.ASYNC_STAR: | |
| 447 worldImpact.registerFeature(Feature.ASYNC_STAR); | |
| 448 break; | |
| 449 } | |
| 450 } | |
| 451 | |
| 452 void registerAsyncForIn(AsyncForIn node) { | |
| 453 worldImpact.registerFeature(Feature.ASYNC_FOR_IN); | |
| 454 } | |
| 455 | |
| 456 void registerIncDecOperation() { | |
| 457 worldImpact.registerFeature(Feature.INC_DEC_OPERATION); | |
| 458 } | |
| 459 | |
| 460 void registerTryStatement() { | 396 void registerTryStatement() { |
| 461 mapping.containsTryStatement = true; | 397 mapping.containsTryStatement = true; |
| 462 } | 398 } |
| 463 } | 399 } |
| 464 | 400 |
| 465 class ForeignResolutionResolver implements ForeignResolver { | 401 class ForeignResolutionResolver implements ForeignResolver { |
| 466 final ResolverVisitor visitor; | 402 final ResolverVisitor visitor; |
| 467 final ResolutionRegistry registry; | 403 final ResolutionRegistry registry; |
| 468 | 404 |
| 469 ForeignResolutionResolver(this.visitor, this.registry); | 405 ForeignResolutionResolver(this.visitor, this.registry); |
| 470 | 406 |
| 471 @override | 407 @override |
| 472 ConstantExpression getConstant(Node node) { | 408 ConstantExpression getConstant(Node node) { |
| 473 return registry.getConstant(node); | 409 return registry.getConstant(node); |
| 474 } | 410 } |
| 475 | 411 |
| 476 @override | 412 @override |
| 477 void registerInstantiatedType(InterfaceType type) { | 413 void registerInstantiatedType(InterfaceType type) { |
| 478 registry.registerInstantiation(type); | 414 registry.registerInstantiation(type); |
| 479 } | 415 } |
| 480 | 416 |
| 481 @override | 417 @override |
| 482 DartType resolveTypeFromString(Node node, String typeName) { | 418 DartType resolveTypeFromString(Node node, String typeName) { |
| 483 return visitor.resolveTypeFromString(node, typeName); | 419 return visitor.resolveTypeFromString(node, typeName); |
| 484 } | 420 } |
| 485 } | 421 } |
| OLD | NEW |