| 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 deferred_load; | 5 library deferred_load; |
| 6 | 6 |
| 7 import 'constants/values.dart' show | 7 import 'constants/values.dart' show |
| 8 ConstantValue, | 8 ConstantValue, |
| 9 ConstructedConstantValue, | 9 ConstructedConstantValue, |
| 10 DeferredConstantValue, | 10 DeferredConstantValue, |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 /// Finds all elements and constants that [element] depends directly on. | 245 /// Finds all elements and constants that [element] depends directly on. |
| 246 /// (not the transitive closure.) | 246 /// (not the transitive closure.) |
| 247 /// | 247 /// |
| 248 /// Adds the results to [elements] and [constants]. | 248 /// Adds the results to [elements] and [constants]. |
| 249 void _collectAllElementsAndConstantsResolvedFrom( | 249 void _collectAllElementsAndConstantsResolvedFrom( |
| 250 Element element, | 250 Element element, |
| 251 Set<Element> elements, | 251 Set<Element> elements, |
| 252 Set<ConstantValue> constants, | 252 Set<ConstantValue> constants, |
| 253 isMirrorUsage) { | 253 isMirrorUsage) { |
| 254 | 254 |
| 255 /// Recursively collects all the dependencies of [type]. |
| 256 void collectTypeDependencies(DartType type) { |
| 257 if (type is GenericType) { |
| 258 type.typeArguments.forEach(collectTypeDependencies); |
| 259 } |
| 260 if (type is FunctionType) { |
| 261 for (DartType argumentType in type.parameterTypes) { |
| 262 collectTypeDependencies(argumentType); |
| 263 } |
| 264 for (DartType argumentType in type.optionalParameterTypes) { |
| 265 collectTypeDependencies(argumentType); |
| 266 } |
| 267 for (DartType argumentType in type.namedParameterTypes) { |
| 268 collectTypeDependencies(argumentType); |
| 269 } |
| 270 collectTypeDependencies(type.returnType); |
| 271 } else if (type is TypedefType) { |
| 272 elements.add(type.element); |
| 273 collectTypeDependencies(type.unalias(compiler)); |
| 274 } else if (type is InterfaceType) { |
| 275 elements.add(type.element); |
| 276 } |
| 277 } |
| 278 |
| 255 /// Collects all direct dependencies of [element]. | 279 /// Collects all direct dependencies of [element]. |
| 256 /// | 280 /// |
| 257 /// The collected dependent elements and constants are are added to | 281 /// The collected dependent elements and constants are are added to |
| 258 /// [elements] and [constants] respectively. | 282 /// [elements] and [constants] respectively. |
| 259 void collectDependencies(Element element) { | 283 void collectDependencies(Element element) { |
| 260 // TODO(johnniwinther): Remove this when [AbstractFieldElement] has been | 284 // TODO(johnniwinther): Remove this when [AbstractFieldElement] has been |
| 261 // removed. | 285 // removed. |
| 262 if (element is! AstElement) return; | 286 if (element is! AstElement) return; |
| 263 AstElement astElement = element; | 287 AstElement astElement = element; |
| 264 | 288 |
| 265 // TODO(sigurdm): We want to be more specific about this - need a better | 289 // TODO(sigurdm): We want to be more specific about this - need a better |
| 266 // way to query "liveness". | 290 // way to query "liveness". |
| 267 if (astElement is! TypedefElement && | 291 if (astElement is! TypedefElement && |
| 268 !compiler.enqueuer.resolution.hasBeenResolved(astElement)) { | 292 !compiler.enqueuer.resolution.hasBeenResolved(astElement)) { |
| 269 return; | 293 return; |
| 270 } | 294 } |
| 271 | 295 |
| 272 TreeElements treeElements = astElement.resolvedAst.elements; | 296 TreeElements treeElements = astElement.resolvedAst.elements; |
| 273 | 297 |
| 274 assert(treeElements != null); | 298 assert(treeElements != null); |
| 275 | 299 |
| 276 for (Element dependency in treeElements.allElements) { | 300 for (Element dependency in treeElements.allElements) { |
| 277 if (dependency.isLocal && !dependency.isFunction) continue; | 301 if (dependency.isLocal && !dependency.isFunction) continue; |
| 278 if (dependency.isErroneous) continue; | 302 if (dependency.isErroneous) continue; |
| 279 if (dependency.isTypeVariable) continue; | 303 if (dependency.isTypeVariable) continue; |
| 280 | 304 |
| 281 elements.add(dependency); | 305 elements.add(dependency); |
| 282 } | 306 } |
| 283 | 307 |
| 284 void registerTypeArgumentsAsDependencies(DartType type) { | 308 for (DartType type in treeElements.requiredTypes) { |
| 285 Element dependency = type.element; | 309 collectTypeDependencies(type); |
| 286 if (dependency == null || dependency.isErroneous || | |
| 287 dependency.isTypeVariable) { | |
| 288 return; | |
| 289 } | |
| 290 elements.add(dependency); | |
| 291 if (type is GenericType) { | |
| 292 type.typeArguments.forEach(registerTypeArgumentsAsDependencies); | |
| 293 } | |
| 294 } | 310 } |
| 295 | 311 |
| 296 treeElements.forEachType((Node node, DartType type) { | |
| 297 if (node is NewExpression) registerTypeArgumentsAsDependencies(type); | |
| 298 }); | |
| 299 | |
| 300 treeElements.forEachConstantNode((Node node, _) { | 312 treeElements.forEachConstantNode((Node node, _) { |
| 301 // Explicitly depend on the backend constants. | 313 // Explicitly depend on the backend constants. |
| 302 ConstantValue value = | 314 ConstantValue value = |
| 303 backend.constants.getConstantValueForNode(node, treeElements); | 315 backend.constants.getConstantValueForNode(node, treeElements); |
| 304 if (value != null) { | 316 if (value != null) { |
| 305 // TODO(johnniwinther): Assert that all constants have values when | 317 // TODO(johnniwinther): Assert that all constants have values when |
| 306 // these are directly evaluated. | 318 // these are directly evaluated. |
| 307 constants.add(value); | 319 constants.add(value); |
| 308 } | 320 } |
| 309 }); | 321 }); |
| 310 elements.addAll(treeElements.otherDependencies); | 322 elements.addAll(treeElements.otherDependencies); |
| 311 } | 323 } |
| 312 | 324 |
| 313 // TODO(sigurdm): How is metadata on a patch-class handled? | 325 // TODO(sigurdm): How is metadata on a patch-class handled? |
| 314 for (MetadataAnnotation metadata in element.metadata) { | 326 for (MetadataAnnotation metadata in element.metadata) { |
| 315 ConstantValue constant = | 327 ConstantValue constant = |
| 316 backend.constants.getConstantValueForMetadata(metadata); | 328 backend.constants.getConstantValueForMetadata(metadata); |
| 317 if (constant != null) { | 329 if (constant != null) { |
| 318 constants.add(constant); | 330 constants.add(constant); |
| 319 } | 331 } |
| 320 } | 332 } |
| 321 | 333 |
| 322 collectTypeDependencies(DartType type) { | |
| 323 if (type is FunctionType) { | |
| 324 for (DartType argumentType in type.parameterTypes) { | |
| 325 collectTypeDependencies(argumentType); | |
| 326 } | |
| 327 for (DartType argumentType in type.optionalParameterTypes) { | |
| 328 collectTypeDependencies(argumentType); | |
| 329 } | |
| 330 for (DartType argumentType in type.namedParameterTypes) { | |
| 331 collectTypeDependencies(argumentType); | |
| 332 } | |
| 333 collectTypeDependencies(type.returnType); | |
| 334 } else if (type is TypedefType) { | |
| 335 elements.add(type.element); | |
| 336 collectTypeDependencies(type.unalias(compiler)); | |
| 337 } else if (type is InterfaceType) { | |
| 338 elements.add(type.element); | |
| 339 } | |
| 340 } | |
| 341 | |
| 342 if (element is FunctionElement && | 334 if (element is FunctionElement && |
| 343 compiler.resolverWorld.closurizedMembers.contains(element)) { | 335 compiler.resolverWorld.closurizedMembers.contains(element)) { |
| 344 collectTypeDependencies(element.type); | 336 collectTypeDependencies(element.type); |
| 345 } | 337 } |
| 346 | 338 |
| 347 // TODO(sigurdm): Also collect types that are used in is checks and for | |
| 348 // checked mode. | |
| 349 | |
| 350 if (element.isClass) { | 339 if (element.isClass) { |
| 351 // If we see a class, add everything its live instance members refer | 340 // If we see a class, add everything its live instance members refer |
| 352 // to. Static members are not relevant, unless we are processing | 341 // to. Static members are not relevant, unless we are processing |
| 353 // extra dependencies due to mirrors. | 342 // extra dependencies due to mirrors. |
| 354 void addLiveInstanceMember(Element element) { | 343 void addLiveInstanceMember(Element element) { |
| 355 if (!compiler.enqueuer.resolution.hasBeenResolved(element)) return; | 344 if (!compiler.enqueuer.resolution.hasBeenResolved(element)) return; |
| 356 if (!isMirrorUsage && !element.isInstanceMember) return; | 345 if (!isMirrorUsage && !element.isInstanceMember) return; |
| 357 collectDependencies(element.implementation); | 346 collectDependencies(element.implementation); |
| 358 } | 347 } |
| 359 ClassElement cls = element.declaration; | 348 ClassElement cls = element.declaration; |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 _importingLibrary = importingLibrary; | 890 _importingLibrary = importingLibrary; |
| 902 | 891 |
| 903 String get importingLibraryName { | 892 String get importingLibraryName { |
| 904 String libraryName = _importingLibrary.getLibraryName(); | 893 String libraryName = _importingLibrary.getLibraryName(); |
| 905 return libraryName == "" | 894 return libraryName == "" |
| 906 ? "<unnamed>" | 895 ? "<unnamed>" |
| 907 : libraryName; | 896 : libraryName; |
| 908 } | 897 } |
| 909 | 898 |
| 910 } | 899 } |
| OLD | NEW |