| 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/resolution.dart' | 10 import '../common/resolution.dart' |
| 11 show Feature, ListLiteralUse, MapLiteralUse, ResolutionImpact; | 11 show Feature, ListLiteralUse, MapLiteralUse, ResolutionImpact, Target; |
| 12 import '../common/registry.dart' show Registry; | 12 import '../common/registry.dart' show Registry; |
| 13 import '../compiler.dart' show Compiler; | 13 import '../compiler.dart' show Compiler; |
| 14 import '../constants/expressions.dart'; | 14 import '../constants/expressions.dart'; |
| 15 import '../dart_types.dart'; | 15 import '../dart_types.dart'; |
| 16 import '../diagnostics/source_span.dart'; | 16 import '../diagnostics/source_span.dart'; |
| 17 import '../enqueue.dart' show ResolutionEnqueuer; | 17 import '../enqueue.dart' show ResolutionEnqueuer; |
| 18 import '../elements/elements.dart'; | 18 import '../elements/elements.dart'; |
| 19 import '../tree/tree.dart'; | 19 import '../tree/tree.dart'; |
| 20 import '../util/util.dart' show Setlet; | 20 import '../util/util.dart' show Setlet; |
| 21 import '../universe/call_structure.dart' show CallStructure; | 21 import '../universe/call_structure.dart' show CallStructure; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 153 } |
| 154 return sb.toString(); | 154 return sb.toString(); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 /// [ResolutionRegistry] collects all resolution information. It stores node | 158 /// [ResolutionRegistry] collects all resolution information. It stores node |
| 159 /// related information in a [TreeElements] mapping and registers calls with | 159 /// related information in a [TreeElements] mapping and registers calls with |
| 160 /// [Backend], [World] and [Enqueuer]. | 160 /// [Backend], [World] and [Enqueuer]. |
| 161 // TODO(johnniwinther): Split this into an interface and implementation class. | 161 // TODO(johnniwinther): Split this into an interface and implementation class. |
| 162 class ResolutionRegistry extends Registry { | 162 class ResolutionRegistry extends Registry { |
| 163 final Compiler compiler; | 163 final Target target; |
| 164 final TreeElementMapping mapping; | 164 final TreeElementMapping mapping; |
| 165 final _ResolutionWorldImpact worldImpact; | 165 final _ResolutionWorldImpact worldImpact; |
| 166 | 166 |
| 167 ResolutionRegistry(Compiler compiler, TreeElementMapping mapping) | 167 ResolutionRegistry(this.target, TreeElementMapping mapping) |
| 168 : this.compiler = compiler, | 168 : this.mapping = mapping, |
| 169 this.mapping = mapping, | |
| 170 this.worldImpact = | 169 this.worldImpact = |
| 171 new _ResolutionWorldImpact(mapping.analyzedElement.toString()); | 170 new _ResolutionWorldImpact(mapping.analyzedElement.toString()); |
| 172 | 171 |
| 173 bool get isForResolution => true; | 172 bool get isForResolution => true; |
| 174 | 173 |
| 175 Backend get backend => compiler.backend; | |
| 176 | |
| 177 String toString() => 'ResolutionRegistry for ${mapping.analyzedElement}'; | 174 String toString() => 'ResolutionRegistry for ${mapping.analyzedElement}'; |
| 178 | 175 |
| 179 ////////////////////////////////////////////////////////////////////////////// | 176 ////////////////////////////////////////////////////////////////////////////// |
| 180 // Node-to-Element mapping functionality. | 177 // Node-to-Element mapping functionality. |
| 181 ////////////////////////////////////////////////////////////////////////////// | 178 ////////////////////////////////////////////////////////////////////////////// |
| 182 | 179 |
| 183 /// Register [node] as the declaration of [element]. | 180 /// Register [node] as the declaration of [element]. |
| 184 void defineFunction(FunctionExpression node, FunctionElement element) { | 181 void defineFunction(FunctionExpression node, FunctionElement element) { |
| 185 // TODO(sigurdm): Remove when not needed by the dart2dart backend. | 182 // TODO(sigurdm): Remove when not needed by the dart2dart backend. |
| 186 if (node.name != null) { | 183 if (node.name != null) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 | 354 |
| 358 void registerMapLiteral(Node node, InterfaceType type, | 355 void registerMapLiteral(Node node, InterfaceType type, |
| 359 {bool isConstant, bool isEmpty}) { | 356 {bool isConstant, bool isEmpty}) { |
| 360 setType(node, type); | 357 setType(node, type); |
| 361 worldImpact.registerMapLiteral( | 358 worldImpact.registerMapLiteral( |
| 362 new MapLiteralUse(type, isConstant: isConstant, isEmpty: isEmpty)); | 359 new MapLiteralUse(type, isConstant: isConstant, isEmpty: isEmpty)); |
| 363 } | 360 } |
| 364 | 361 |
| 365 void registerForeignCall(Node node, Element element, | 362 void registerForeignCall(Node node, Element element, |
| 366 CallStructure callStructure, ResolverVisitor visitor) { | 363 CallStructure callStructure, ResolverVisitor visitor) { |
| 367 var nativeData = backend.resolveForeignCall(node, element, callStructure, | 364 var nativeData = target.resolveForeignCall(node, element, callStructure, |
| 368 new ForeignResolutionResolver(visitor, this)); | 365 new ForeignResolutionResolver(visitor, this)); |
| 369 if (nativeData != null) { | 366 if (nativeData != null) { |
| 370 // Split impact from resolution result. | 367 // Split impact from resolution result. |
| 371 mapping.registerNativeData(node, nativeData); | 368 mapping.registerNativeData(node, nativeData); |
| 372 worldImpact.registerNativeData(nativeData); | 369 worldImpact.registerNativeData(nativeData); |
| 373 } | 370 } |
| 374 } | 371 } |
| 375 | 372 |
| 376 void registerDynamicUse(DynamicUse dynamicUse) { | 373 void registerDynamicUse(DynamicUse dynamicUse) { |
| 377 worldImpact.registerDynamicUse(dynamicUse); | 374 worldImpact.registerDynamicUse(dynamicUse); |
| 378 } | 375 } |
| 379 | 376 |
| 380 void registerFeature(Feature feature) { | 377 void registerFeature(Feature feature) { |
| 381 worldImpact.registerFeature(feature); | 378 worldImpact.registerFeature(feature); |
| 382 } | 379 } |
| 383 | 380 |
| 384 void registerConstSymbol(String name) { | 381 void registerConstSymbol(String name) { |
| 385 worldImpact.registerConstSymbolName(name); | 382 worldImpact.registerConstSymbolName(name); |
| 386 } | 383 } |
| 387 | 384 |
| 388 void registerConstantLiteral(ConstantExpression constant) { | 385 void registerConstantLiteral(ConstantExpression constant) { |
| 389 worldImpact.registerConstantLiteral(constant); | 386 worldImpact.registerConstantLiteral(constant); |
| 390 } | 387 } |
| 391 | 388 |
| 392 ClassElement defaultSuperclass(ClassElement element) { | 389 ClassElement defaultSuperclass(ClassElement element) { |
| 393 return backend.defaultSuperclass(element); | 390 return target.defaultSuperclass(element); |
| 394 } | 391 } |
| 395 | 392 |
| 396 void registerInstantiation(InterfaceType type) { | 393 void registerInstantiation(InterfaceType type) { |
| 397 worldImpact.registerTypeUse(new TypeUse.instantiation(type)); | 394 worldImpact.registerTypeUse(new TypeUse.instantiation(type)); |
| 398 } | 395 } |
| 399 | 396 |
| 400 void registerSendStructure(Send node, SendStructure sendStructure) { | 397 void registerSendStructure(Send node, SendStructure sendStructure) { |
| 401 mapping.setSendStructure(node, sendStructure); | 398 mapping.setSendStructure(node, sendStructure); |
| 402 } | 399 } |
| 403 | 400 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 430 @override | 427 @override |
| 431 void registerInstantiatedType(InterfaceType type) { | 428 void registerInstantiatedType(InterfaceType type) { |
| 432 registry.registerInstantiation(type); | 429 registry.registerInstantiation(type); |
| 433 } | 430 } |
| 434 | 431 |
| 435 @override | 432 @override |
| 436 DartType resolveTypeFromString(Node node, String typeName) { | 433 DartType resolveTypeFromString(Node node, String typeName) { |
| 437 return visitor.resolveTypeFromString(node, typeName); | 434 return visitor.resolveTypeFromString(node, typeName); |
| 438 } | 435 } |
| 439 } | 436 } |
| OLD | NEW |