| 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' | 8 import '../common/backend_api.dart' |
| 9 show Backend, ForeignResolver, NativeRegistry; | 9 show Backend, ForeignResolver, NativeRegistry; |
| 10 import '../common/registry.dart' show Registry; | 10 import '../common/registry.dart' show Registry; |
| 11 import '../common/resolution.dart' show ResolutionImpact, Target; | 11 import '../common/resolution.dart' show ResolutionImpact, Target; |
| 12 import '../constants/expressions.dart'; | 12 import '../constants/expressions.dart'; |
| 13 import '../dart_types.dart'; | 13 import '../dart_types.dart'; |
| 14 import '../diagnostics/source_span.dart'; | 14 import '../diagnostics/source_span.dart'; |
| 15 import '../elements/elements.dart'; | 15 import '../elements/elements.dart'; |
| 16 import '../tree/tree.dart'; | 16 import '../tree/tree.dart'; |
| 17 import '../universe/call_structure.dart' show CallStructure; | 17 import '../universe/call_structure.dart' show CallStructure; |
| 18 import '../universe/feature.dart'; | 18 import '../universe/feature.dart'; |
| 19 import '../universe/selector.dart' show Selector; | 19 import '../universe/selector.dart' show Selector; |
| 20 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; | 20 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; |
| 21 import '../universe/world_impact.dart' show WorldImpact, WorldImpactBuilder; | 21 import '../universe/world_impact.dart' show WorldImpact, WorldImpactBuilder; |
| 22 import '../util/enumset.dart' show EnumSet; | 22 import '../util/enumset.dart' show EnumSet; |
| 23 import '../util/util.dart' show Setlet; | 23 import '../util/util.dart' show Setlet; |
| 24 import 'members.dart' show ResolverVisitor; | 24 import 'members.dart' show ResolverVisitor; |
| 25 import 'send_structure.dart'; | 25 import 'send_structure.dart'; |
| 26 import 'tree_elements.dart' show TreeElementMapping; | 26 import 'tree_elements.dart' show TreeElementMapping; |
| 27 | 27 |
| 28 class _ResolutionWorldImpact extends ResolutionImpact | 28 class ResolutionWorldImpactBuilder extends ResolutionImpact |
| 29 with WorldImpactBuilder | 29 with WorldImpactBuilder |
| 30 implements NativeRegistry { | 30 implements NativeRegistry { |
| 31 final String name; | 31 final String name; |
| 32 EnumSet<Feature> _features; | 32 EnumSet<Feature> _features; |
| 33 Setlet<MapLiteralUse> _mapLiterals; | 33 Setlet<MapLiteralUse> _mapLiterals; |
| 34 Setlet<ListLiteralUse> _listLiterals; | 34 Setlet<ListLiteralUse> _listLiterals; |
| 35 Setlet<String> _constSymbolNames; | 35 Setlet<String> _constSymbolNames; |
| 36 Setlet<ConstantExpression> _constantLiterals; | 36 Setlet<ConstantExpression> _constantLiterals; |
| 37 Setlet<dynamic> _nativeData; | 37 Setlet<dynamic> _nativeData; |
| 38 | 38 |
| 39 _ResolutionWorldImpact(this.name); | 39 ResolutionWorldImpactBuilder(this.name); |
| 40 | 40 |
| 41 void registerMapLiteral(MapLiteralUse mapLiteralUse) { | 41 void registerMapLiteral(MapLiteralUse mapLiteralUse) { |
| 42 assert(mapLiteralUse != null); | 42 assert(mapLiteralUse != null); |
| 43 if (_mapLiterals == null) { | 43 if (_mapLiterals == null) { |
| 44 _mapLiterals = new Setlet<MapLiteralUse>(); | 44 _mapLiterals = new Setlet<MapLiteralUse>(); |
| 45 } | 45 } |
| 46 _mapLiterals.add(mapLiteralUse); | 46 _mapLiterals.add(mapLiteralUse); |
| 47 } | 47 } |
| 48 | 48 |
| 49 @override | 49 @override |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 /// [ResolutionRegistry] collects all resolution information. It stores node | 154 /// [ResolutionRegistry] collects all resolution information. It stores node |
| 155 /// related information in a [TreeElements] mapping and registers calls with | 155 /// related information in a [TreeElements] mapping and registers calls with |
| 156 /// [Backend], [World] and [Enqueuer]. | 156 /// [Backend], [World] and [Enqueuer]. |
| 157 // TODO(johnniwinther): Split this into an interface and implementation class. | 157 // TODO(johnniwinther): Split this into an interface and implementation class. |
| 158 class ResolutionRegistry extends Registry { | 158 class ResolutionRegistry extends Registry { |
| 159 final Target target; | 159 final Target target; |
| 160 final TreeElementMapping mapping; | 160 final TreeElementMapping mapping; |
| 161 final _ResolutionWorldImpact worldImpact; | 161 final ResolutionWorldImpactBuilder impactBuilder; |
| 162 | 162 |
| 163 ResolutionRegistry(this.target, TreeElementMapping mapping) | 163 ResolutionRegistry(this.target, TreeElementMapping mapping) |
| 164 : this.mapping = mapping, | 164 : this.mapping = mapping, |
| 165 this.worldImpact = | 165 this.impactBuilder = new ResolutionWorldImpactBuilder( |
| 166 new _ResolutionWorldImpact(mapping.analyzedElement.toString()); | 166 mapping.analyzedElement.toString()); |
| 167 | 167 |
| 168 bool get isForResolution => true; | 168 bool get isForResolution => true; |
| 169 | 169 |
| 170 String toString() => 'ResolutionRegistry for ${mapping.analyzedElement}'; | 170 String toString() => 'ResolutionRegistry for ${mapping.analyzedElement}'; |
| 171 | 171 |
| 172 ////////////////////////////////////////////////////////////////////////////// | 172 ////////////////////////////////////////////////////////////////////////////// |
| 173 // Node-to-Element mapping functionality. | 173 // Node-to-Element mapping functionality. |
| 174 ////////////////////////////////////////////////////////////////////////////// | 174 ////////////////////////////////////////////////////////////////////////////// |
| 175 | 175 |
| 176 /// Register [node] as the declaration of [element]. | 176 /// Register [node] as the declaration of [element]. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 void registerPotentialMutationIn( | 317 void registerPotentialMutationIn( |
| 318 Node contextNode, VariableElement element, Node mutationNode) { | 318 Node contextNode, VariableElement element, Node mutationNode) { |
| 319 mapping.registerPotentialMutationIn(contextNode, element, mutationNode); | 319 mapping.registerPotentialMutationIn(contextNode, element, mutationNode); |
| 320 } | 320 } |
| 321 | 321 |
| 322 ////////////////////////////////////////////////////////////////////////////// | 322 ////////////////////////////////////////////////////////////////////////////// |
| 323 // Various Backend/Enqueuer/World registration. | 323 // Various Backend/Enqueuer/World registration. |
| 324 ////////////////////////////////////////////////////////////////////////////// | 324 ////////////////////////////////////////////////////////////////////////////// |
| 325 | 325 |
| 326 void registerStaticUse(StaticUse staticUse) { | 326 void registerStaticUse(StaticUse staticUse) { |
| 327 worldImpact.registerStaticUse(staticUse); | 327 impactBuilder.registerStaticUse(staticUse); |
| 328 } | 328 } |
| 329 | 329 |
| 330 /// Register the use of a type. | 330 /// Register the use of a type. |
| 331 void registerTypeUse(TypeUse typeUse) { | 331 void registerTypeUse(TypeUse typeUse) { |
| 332 worldImpact.registerTypeUse(typeUse); | 332 impactBuilder.registerTypeUse(typeUse); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void registerSuperUse(SourceSpan span) { | 335 void registerSuperUse(SourceSpan span) { |
| 336 mapping.addSuperUse(span); | 336 mapping.addSuperUse(span); |
| 337 } | 337 } |
| 338 | 338 |
| 339 void registerTypeLiteral(Send node, DartType type) { | 339 void registerTypeLiteral(Send node, DartType type) { |
| 340 mapping.setType(node, type); | 340 mapping.setType(node, type); |
| 341 worldImpact.registerTypeUse(new TypeUse.typeLiteral(type)); | 341 impactBuilder.registerTypeUse(new TypeUse.typeLiteral(type)); |
| 342 } | 342 } |
| 343 | 343 |
| 344 void registerLiteralList(Node node, InterfaceType type, | 344 void registerLiteralList(Node node, InterfaceType type, |
| 345 {bool isConstant, bool isEmpty}) { | 345 {bool isConstant, bool isEmpty}) { |
| 346 setType(node, type); | 346 setType(node, type); |
| 347 worldImpact.registerListLiteral( | 347 impactBuilder.registerListLiteral( |
| 348 new ListLiteralUse(type, isConstant: isConstant, isEmpty: isEmpty)); | 348 new ListLiteralUse(type, isConstant: isConstant, isEmpty: isEmpty)); |
| 349 } | 349 } |
| 350 | 350 |
| 351 void registerMapLiteral(Node node, InterfaceType type, | 351 void registerMapLiteral(Node node, InterfaceType type, |
| 352 {bool isConstant, bool isEmpty}) { | 352 {bool isConstant, bool isEmpty}) { |
| 353 setType(node, type); | 353 setType(node, type); |
| 354 worldImpact.registerMapLiteral( | 354 impactBuilder.registerMapLiteral( |
| 355 new MapLiteralUse(type, isConstant: isConstant, isEmpty: isEmpty)); | 355 new MapLiteralUse(type, isConstant: isConstant, isEmpty: isEmpty)); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void registerForeignCall(Node node, Element element, | 358 void registerForeignCall(Node node, Element element, |
| 359 CallStructure callStructure, ResolverVisitor visitor) { | 359 CallStructure callStructure, ResolverVisitor visitor) { |
| 360 var nativeData = target.resolveForeignCall(node, element, callStructure, | 360 var nativeData = target.resolveForeignCall(node, element, callStructure, |
| 361 new ForeignResolutionResolver(visitor, this)); | 361 new ForeignResolutionResolver(visitor, this)); |
| 362 if (nativeData != null) { | 362 if (nativeData != null) { |
| 363 // Split impact from resolution result. | 363 // Split impact from resolution result. |
| 364 mapping.registerNativeData(node, nativeData); | 364 mapping.registerNativeData(node, nativeData); |
| 365 worldImpact.registerNativeData(nativeData); | 365 impactBuilder.registerNativeData(nativeData); |
| 366 } | 366 } |
| 367 } | 367 } |
| 368 | 368 |
| 369 void registerDynamicUse(DynamicUse dynamicUse) { | 369 void registerDynamicUse(DynamicUse dynamicUse) { |
| 370 worldImpact.registerDynamicUse(dynamicUse); | 370 impactBuilder.registerDynamicUse(dynamicUse); |
| 371 } | 371 } |
| 372 | 372 |
| 373 void registerFeature(Feature feature) { | 373 void registerFeature(Feature feature) { |
| 374 worldImpact.registerFeature(feature); | 374 impactBuilder.registerFeature(feature); |
| 375 } | 375 } |
| 376 | 376 |
| 377 void registerConstSymbol(String name) { | 377 void registerConstSymbol(String name) { |
| 378 worldImpact.registerConstSymbolName(name); | 378 impactBuilder.registerConstSymbolName(name); |
| 379 } | 379 } |
| 380 | 380 |
| 381 void registerConstantLiteral(ConstantExpression constant) { | 381 void registerConstantLiteral(ConstantExpression constant) { |
| 382 worldImpact.registerConstantLiteral(constant); | 382 impactBuilder.registerConstantLiteral(constant); |
| 383 } | 383 } |
| 384 | 384 |
| 385 ClassElement defaultSuperclass(ClassElement element) { | 385 ClassElement defaultSuperclass(ClassElement element) { |
| 386 return target.defaultSuperclass(element); | 386 return target.defaultSuperclass(element); |
| 387 } | 387 } |
| 388 | 388 |
| 389 void registerInstantiation(InterfaceType type) { | 389 void registerInstantiation(InterfaceType type) { |
| 390 worldImpact.registerTypeUse(new TypeUse.instantiation(type)); | 390 impactBuilder.registerTypeUse(new TypeUse.instantiation(type)); |
| 391 } | 391 } |
| 392 | 392 |
| 393 void registerSendStructure(Send node, SendStructure sendStructure) { | 393 void registerSendStructure(Send node, SendStructure sendStructure) { |
| 394 mapping.setSendStructure(node, sendStructure); | 394 mapping.setSendStructure(node, sendStructure); |
| 395 } | 395 } |
| 396 | 396 |
| 397 void registerNewStructure(NewExpression node, NewStructure newStructure) { | 397 void registerNewStructure(NewExpression node, NewStructure newStructure) { |
| 398 mapping.setNewStructure(node, newStructure); | 398 mapping.setNewStructure(node, newStructure); |
| 399 } | 399 } |
| 400 | 400 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 423 @override | 423 @override |
| 424 void registerInstantiatedType(InterfaceType type) { | 424 void registerInstantiatedType(InterfaceType type) { |
| 425 registry.registerInstantiation(type); | 425 registry.registerInstantiation(type); |
| 426 } | 426 } |
| 427 | 427 |
| 428 @override | 428 @override |
| 429 DartType resolveTypeFromString(Node node, String typeName) { | 429 DartType resolveTypeFromString(Node node, String typeName) { |
| 430 return visitor.resolveTypeFromString(node, typeName); | 430 return visitor.resolveTypeFromString(node, typeName); |
| 431 } | 431 } |
| 432 } | 432 } |
| OLD | NEW |