| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /** | 5 /** |
| 6 * This library is capable of producing linked summaries from unlinked | 6 * This library is capable of producing linked summaries from unlinked |
| 7 * ones (or prelinked ones). It functions by building a miniature | 7 * ones (or prelinked ones). It functions by building a miniature |
| 8 * element model to represent the contents of the summaries, and then | 8 * element model to represent the contents of the summaries, and then |
| 9 * scanning the element model to gather linked information and adding | 9 * scanning the element model to gather linked information and adding |
| 10 * it to the summary data structures. | 10 * it to the summary data structures. |
| (...skipping 3235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3246 * Compute the dependencies of this node. | 3246 * Compute the dependencies of this node. |
| 3247 */ | 3247 */ |
| 3248 List<NodeType> computeDependencies(); | 3248 List<NodeType> computeDependencies(); |
| 3249 } | 3249 } |
| 3250 | 3250 |
| 3251 /** | 3251 /** |
| 3252 * Element used for references that result from trying to access a non-static | 3252 * Element used for references that result from trying to access a non-static |
| 3253 * member of an element that is not a container (e.g. accessing the "length" | 3253 * member of an element that is not a container (e.g. accessing the "length" |
| 3254 * property of a constant). | 3254 * property of a constant). |
| 3255 * | 3255 * |
| 3256 * Also handles accesses to a chain of non-static members separated by '.'. | 3256 * Accesses to a chain of non-static members separated by '.' are andled by |
| 3257 * creating a [NonstaticMemberElementForLink] that points to another |
| 3258 * [NonstaticMemberElementForLink], to whatever nesting level is necessary. |
| 3257 */ | 3259 */ |
| 3258 class NonstaticMemberElementForLink implements ReferenceableElementForLink { | 3260 class NonstaticMemberElementForLink implements ReferenceableElementForLink { |
| 3259 /** | 3261 /** |
| 3260 * The static variable element from which the non-static member access begins. | 3262 * The [ReferenceableElementForLink] which is the target of the non-static |
| 3263 * reference. |
| 3261 */ | 3264 */ |
| 3262 final VariableElementForLink _variable; | 3265 final ReferenceableElementForLink _target; |
| 3263 | 3266 |
| 3264 /** | 3267 /** |
| 3265 * The list of non-static members that are accessed. | 3268 * The name of the non-static members that is being accessed. |
| 3266 */ | 3269 */ |
| 3267 final List<String> _names; | 3270 final String _name; |
| 3268 | 3271 |
| 3269 /** | 3272 /** |
| 3270 * The library in which the access occurs. This determines whether private | 3273 * The library in which the access occurs. This determines whether private |
| 3271 * names are accessible. | 3274 * names are accessible. |
| 3272 */ | 3275 */ |
| 3273 final LibraryElementForLink _library; | 3276 final LibraryElementForLink _library; |
| 3274 | 3277 |
| 3275 NonstaticMemberElementForLink(this._library, this._variable, this._names); | 3278 NonstaticMemberElementForLink(this._library, this._target, this._name); |
| 3276 | 3279 |
| 3277 @override | 3280 @override |
| 3278 ConstructorElementForLink get asConstructor => null; | 3281 ConstructorElementForLink get asConstructor => null; |
| 3279 | 3282 |
| 3280 @override | 3283 @override |
| 3281 ConstVariableNode get asConstVariable => _variable._constNode; | 3284 ConstVariableNode get asConstVariable => _target.asConstVariable; |
| 3282 | 3285 |
| 3283 @override | 3286 @override |
| 3284 DartType get asStaticType { | 3287 DartType get asStaticType { |
| 3285 if (_library._linker.strongMode) { | 3288 if (_library._linker.strongMode) { |
| 3286 DartType type = _variable.asStaticType; | 3289 DartType targetType = _target.asStaticType; |
| 3287 for (String name in _names) { | 3290 if (targetType is InterfaceType) { |
| 3288 type = _typeLookupStep(type, name); | 3291 PropertyAccessorElement getter = |
| 3292 targetType.lookUpGetter(_name, _library); |
| 3293 if (getter != null) { |
| 3294 return getter.returnType; |
| 3295 } |
| 3296 MethodElement method = targetType.lookUpMethod(_name, _library); |
| 3297 if (method != null) { |
| 3298 return method.type; |
| 3299 } |
| 3289 } | 3300 } |
| 3290 return type; | 3301 // TODO(paulberry): handle .call on function types and .toString or |
| 3302 // .hashCode on all types. |
| 3291 } | 3303 } |
| 3292 // TODO(paulberry, scheglov): implement for propagated types | 3304 // TODO(paulberry, scheglov): implement for propagated types |
| 3293 return DynamicTypeImpl.instance; | 3305 return DynamicTypeImpl.instance; |
| 3294 } | 3306 } |
| 3295 | 3307 |
| 3296 @override | 3308 @override |
| 3297 TypeInferenceNode get asTypeInferenceNode => _variable._typeInferenceNode; | 3309 TypeInferenceNode get asTypeInferenceNode => _target.asTypeInferenceNode; |
| 3298 | 3310 |
| 3299 @override | 3311 @override |
| 3300 DartType buildType(DartType getTypeArgument(int i), | 3312 DartType buildType(DartType getTypeArgument(int i), |
| 3301 List<int> implicitFunctionTypeIndices) => | 3313 List<int> implicitFunctionTypeIndices) => |
| 3302 DynamicTypeImpl.instance; | 3314 DynamicTypeImpl.instance; |
| 3303 | 3315 |
| 3304 @override | 3316 @override |
| 3305 ReferenceableElementForLink getContainedName(String name) { | 3317 ReferenceableElementForLink getContainedName(String name) { |
| 3306 return new NonstaticMemberElementForLink( | 3318 return new NonstaticMemberElementForLink(_library, this, name); |
| 3307 _library, _variable, _names.toList()..add(name)); | |
| 3308 } | |
| 3309 | |
| 3310 /** | |
| 3311 * Perform a single step in the resolution of the non-static access, looking | |
| 3312 * up in [type] for the nonstatic entity having the given [name]. Return the | |
| 3313 * type of the entity that was found, or `dynamic` if no entity was found. | |
| 3314 */ | |
| 3315 DartType _typeLookupStep(DartType type, String name) { | |
| 3316 if (type is InterfaceType) { | |
| 3317 PropertyAccessorElement getter = type.lookUpGetter(name, _library); | |
| 3318 if (getter != null) { | |
| 3319 return getter.returnType; | |
| 3320 } | |
| 3321 MethodElement method = type.lookUpMethod(name, _library); | |
| 3322 if (method != null) { | |
| 3323 return method.type; | |
| 3324 } | |
| 3325 } | |
| 3326 // TODO(paulberry): handle .call on function types and .toString or .hashCod
e on all types. | |
| 3327 return DynamicTypeImpl.instance; | |
| 3328 } | 3319 } |
| 3329 } | 3320 } |
| 3330 | 3321 |
| 3331 /** | 3322 /** |
| 3332 * Element representing a function or method parameter resynthesized | 3323 * Element representing a function or method parameter resynthesized |
| 3333 * from a summary during linking. | 3324 * from a summary during linking. |
| 3334 */ | 3325 */ |
| 3335 class ParameterElementForLink implements ParameterElementImpl { | 3326 class ParameterElementForLink implements ParameterElementImpl { |
| 3336 /** | 3327 /** |
| 3337 * The unlinked representation of the parameter in the summary. | 3328 * The unlinked representation of the parameter in the summary. |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3558 @override | 3549 @override |
| 3559 ElementKind get kind => _unlinkedExecutable.kind == | 3550 ElementKind get kind => _unlinkedExecutable.kind == |
| 3560 UnlinkedExecutableKind.getter ? ElementKind.GETTER : ElementKind.SETTER; | 3551 UnlinkedExecutableKind.getter ? ElementKind.GETTER : ElementKind.SETTER; |
| 3561 | 3552 |
| 3562 @override | 3553 @override |
| 3563 DartType buildType(DartType getTypeArgument(int i), | 3554 DartType buildType(DartType getTypeArgument(int i), |
| 3564 List<int> implicitFunctionTypeIndices) => | 3555 List<int> implicitFunctionTypeIndices) => |
| 3565 DynamicTypeImpl.instance; | 3556 DynamicTypeImpl.instance; |
| 3566 | 3557 |
| 3567 @override | 3558 @override |
| 3568 ReferenceableElementForLink getContainedName(String name) => | 3559 ReferenceableElementForLink getContainedName(String name) { |
| 3569 UndefinedElementForLink.instance; | 3560 return new NonstaticMemberElementForLink(library, this, name); |
| 3561 } |
| 3570 | 3562 |
| 3571 @override | 3563 @override |
| 3572 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 3564 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 3573 | 3565 |
| 3574 @override | 3566 @override |
| 3575 String toString() => '$enclosingElement.$name'; | 3567 String toString() => '$enclosingElement.$name'; |
| 3576 } | 3568 } |
| 3577 | 3569 |
| 3578 /** | 3570 /** |
| 3579 * Specialization of [PropertyAccessorElementForLink] for synthetic accessors | 3571 * Specialization of [PropertyAccessorElementForLink] for synthetic accessors |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3671 // (even if we have already computed it), since that would lead to | 3663 // (even if we have already computed it), since that would lead to |
| 3672 // non-deterministic type inference results. | 3664 // non-deterministic type inference results. |
| 3673 return DynamicTypeImpl.instance; | 3665 return DynamicTypeImpl.instance; |
| 3674 } else { | 3666 } else { |
| 3675 return variable.type; | 3667 return variable.type; |
| 3676 } | 3668 } |
| 3677 } | 3669 } |
| 3678 | 3670 |
| 3679 @override | 3671 @override |
| 3680 ReferenceableElementForLink getContainedName(String name) { | 3672 ReferenceableElementForLink getContainedName(String name) { |
| 3681 return new NonstaticMemberElementForLink(library, variable, <String>[name]); | 3673 return new NonstaticMemberElementForLink(library, this, name); |
| 3682 } | 3674 } |
| 3683 | 3675 |
| 3684 @override | 3676 @override |
| 3685 bool isAccessibleIn(LibraryElement library) => | 3677 bool isAccessibleIn(LibraryElement library) => |
| 3686 !Identifier.isPrivateName(name) || identical(this.library, library); | 3678 !Identifier.isPrivateName(name) || identical(this.library, library); |
| 3687 | 3679 |
| 3688 @override | 3680 @override |
| 3689 void link(CompilationUnitElementInBuildUnit compilationUnit) {} | 3681 void link(CompilationUnitElementInBuildUnit compilationUnit) {} |
| 3690 | 3682 |
| 3691 @override | 3683 @override |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4434 * there are no type parameters in scope. | 4426 * there are no type parameters in scope. |
| 4435 */ | 4427 */ |
| 4436 TypeParameterizedElementForLink get _typeParameterContext; | 4428 TypeParameterizedElementForLink get _typeParameterContext; |
| 4437 | 4429 |
| 4438 @override | 4430 @override |
| 4439 DartType buildType(DartType getTypeArgument(int i), | 4431 DartType buildType(DartType getTypeArgument(int i), |
| 4440 List<int> implicitFunctionTypeIndices) => | 4432 List<int> implicitFunctionTypeIndices) => |
| 4441 DynamicTypeImpl.instance; | 4433 DynamicTypeImpl.instance; |
| 4442 | 4434 |
| 4443 ReferenceableElementForLink getContainedName(String name) { | 4435 ReferenceableElementForLink getContainedName(String name) { |
| 4444 return new NonstaticMemberElementForLink(library, this, <String>[name]); | 4436 return new NonstaticMemberElementForLink(library, this, name); |
| 4445 } | 4437 } |
| 4446 | 4438 |
| 4447 @override | 4439 @override |
| 4448 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 4440 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 4449 } | 4441 } |
| OLD | NEW |