| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 153 |
| 154 /** | 154 /** |
| 155 * Create an [EntityRefBuilder] representing the given [type], in a form | 155 * Create an [EntityRefBuilder] representing the given [type], in a form |
| 156 * suitable for inclusion in [LinkedUnit.types]. [compilationUnit] is the | 156 * suitable for inclusion in [LinkedUnit.types]. [compilationUnit] is the |
| 157 * compilation unit in which the type will be used. If [slot] is provided, it | 157 * compilation unit in which the type will be used. If [slot] is provided, it |
| 158 * is stored in [EntityRefBuilder.slot]. | 158 * is stored in [EntityRefBuilder.slot]. |
| 159 */ | 159 */ |
| 160 EntityRefBuilder _createLinkedType( | 160 EntityRefBuilder _createLinkedType( |
| 161 DartType type, | 161 DartType type, |
| 162 CompilationUnitElementInBuildUnit compilationUnit, | 162 CompilationUnitElementInBuildUnit compilationUnit, |
| 163 TypeParameterizedElementForLink typeParameterContext, | 163 TypeParameterizedElementMixin typeParameterContext, |
| 164 {int slot}) { | 164 {int slot}) { |
| 165 EntityRefBuilder result = new EntityRefBuilder(slot: slot); | 165 EntityRefBuilder result = new EntityRefBuilder(slot: slot); |
| 166 if (type is InterfaceType) { | 166 if (type is InterfaceType) { |
| 167 ClassElementForLink element = type.element; | 167 ClassElementForLink element = type.element; |
| 168 result.reference = compilationUnit.addReference(element); | 168 result.reference = compilationUnit.addReference(element); |
| 169 _storeTypeArguments( | 169 _storeTypeArguments( |
| 170 type.typeArguments, result, compilationUnit, typeParameterContext); | 170 type.typeArguments, result, compilationUnit, typeParameterContext); |
| 171 return result; | 171 return result; |
| 172 } else if (type is DynamicTypeImpl) { | 172 } else if (type is DynamicTypeImpl) { |
| 173 result.reference = compilationUnit.addRawReference('dynamic'); | 173 result.reference = compilationUnit.addRawReference('dynamic'); |
| 174 return result; | 174 return result; |
| 175 } else if (type is VoidTypeImpl) { | 175 } else if (type is VoidTypeImpl) { |
| 176 result.reference = compilationUnit.addRawReference('void'); | 176 result.reference = compilationUnit.addRawReference('void'); |
| 177 return result; | 177 return result; |
| 178 } else if (type is BottomTypeImpl) { | 178 } else if (type is BottomTypeImpl) { |
| 179 result.reference = compilationUnit.addRawReference('*bottom*'); | 179 result.reference = compilationUnit.addRawReference('*bottom*'); |
| 180 return result; | 180 return result; |
| 181 } else if (type is TypeParameterType) { | 181 } else if (type is TypeParameterType) { |
| 182 TypeParameterElementForLink element = type.element; | 182 TypeParameterElementImpl element = type.element; |
| 183 if (typeParameterContext.isTypeParameterInScope(element)) { | 183 if (typeParameterContext.isTypeParameterInScope(element)) { |
| 184 result.paramReference = | 184 result.paramReference = |
| 185 typeParameterContext.typeParameterNestingLevel - element.nestingLevel; | 185 typeParameterContext.typeParameterNestingLevel - element.nestingLevel; |
| 186 } else { | 186 } else { |
| 187 // Out-of-scope type parameters only occur in circumstances where they | 187 // Out-of-scope type parameters only occur in circumstances where they |
| 188 // are irrelevant (i.e. when a type parameter is unused). So we can | 188 // are irrelevant (i.e. when a type parameter is unused). So we can |
| 189 // safely convert them to `dynamic`. | 189 // safely convert them to `dynamic`. |
| 190 result.reference = compilationUnit.addRawReference('dynamic'); | 190 result.reference = compilationUnit.addRawReference('dynamic'); |
| 191 } | 191 } |
| 192 return result; | 192 return result; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 244 |
| 245 /** | 245 /** |
| 246 * Create an [UnlinkedParam] representing the given [parameter], which should be | 246 * Create an [UnlinkedParam] representing the given [parameter], which should be |
| 247 * a parameter of a synthetic function type (e.g. one produced during type | 247 * a parameter of a synthetic function type (e.g. one produced during type |
| 248 * inference as a result of computing the least upper bound of two function | 248 * inference as a result of computing the least upper bound of two function |
| 249 * types). | 249 * types). |
| 250 */ | 250 */ |
| 251 UnlinkedParamBuilder _serializeSyntheticParam( | 251 UnlinkedParamBuilder _serializeSyntheticParam( |
| 252 ParameterElement parameter, | 252 ParameterElement parameter, |
| 253 CompilationUnitElementInBuildUnit compilationUnit, | 253 CompilationUnitElementInBuildUnit compilationUnit, |
| 254 TypeParameterizedElementForLink typeParameterContext) { | 254 TypeParameterizedElementMixin typeParameterContext) { |
| 255 UnlinkedParamBuilder b = new UnlinkedParamBuilder(); | 255 UnlinkedParamBuilder b = new UnlinkedParamBuilder(); |
| 256 b.name = parameter.name; | 256 b.name = parameter.name; |
| 257 switch (parameter.parameterKind) { | 257 switch (parameter.parameterKind) { |
| 258 case ParameterKind.REQUIRED: | 258 case ParameterKind.REQUIRED: |
| 259 b.kind = UnlinkedParamKind.required; | 259 b.kind = UnlinkedParamKind.required; |
| 260 break; | 260 break; |
| 261 case ParameterKind.POSITIONAL: | 261 case ParameterKind.POSITIONAL: |
| 262 b.kind = UnlinkedParamKind.positional; | 262 b.kind = UnlinkedParamKind.positional; |
| 263 break; | 263 break; |
| 264 case ParameterKind.NAMED: | 264 case ParameterKind.NAMED: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 283 } | 283 } |
| 284 | 284 |
| 285 /** | 285 /** |
| 286 * Store the given [typeArguments] in [encodedType], using [compilationUnit] and | 286 * Store the given [typeArguments] in [encodedType], using [compilationUnit] and |
| 287 * [typeParameterContext] to serialize them. | 287 * [typeParameterContext] to serialize them. |
| 288 */ | 288 */ |
| 289 void _storeTypeArguments( | 289 void _storeTypeArguments( |
| 290 List<DartType> typeArguments, | 290 List<DartType> typeArguments, |
| 291 EntityRefBuilder encodedType, | 291 EntityRefBuilder encodedType, |
| 292 CompilationUnitElementInBuildUnit compilationUnit, | 292 CompilationUnitElementInBuildUnit compilationUnit, |
| 293 TypeParameterizedElementForLink typeParameterContext) { | 293 TypeParameterizedElementMixin typeParameterContext) { |
| 294 int count = typeArguments.length; | 294 int count = typeArguments.length; |
| 295 List<EntityRefBuilder> encodedTypeArguments = | 295 List<EntityRefBuilder> encodedTypeArguments = |
| 296 new List<EntityRefBuilder>(count); | 296 new List<EntityRefBuilder>(count); |
| 297 for (int i = 0; i < count; i++) { | 297 for (int i = 0; i < count; i++) { |
| 298 encodedTypeArguments[i] = _createLinkedType( | 298 encodedTypeArguments[i] = _createLinkedType( |
| 299 typeArguments[i], compilationUnit, typeParameterContext); | 299 typeArguments[i], compilationUnit, typeParameterContext); |
| 300 } | 300 } |
| 301 encodedType.typeArguments = encodedTypeArguments; | 301 encodedType.typeArguments = encodedTypeArguments; |
| 302 } | 302 } |
| 303 | 303 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 @override | 356 @override |
| 357 LibraryElementForLink get library => enclosingElement.library; | 357 LibraryElementForLink get library => enclosingElement.library; |
| 358 | 358 |
| 359 @override | 359 @override |
| 360 List<MethodElementForLink> get methods; | 360 List<MethodElementForLink> get methods; |
| 361 | 361 |
| 362 @override | 362 @override |
| 363 String get name; | 363 String get name; |
| 364 | 364 |
| 365 @override | 365 @override |
| 366 ResynthesizerContext get resynthesizerContext => enclosingElement; |
| 367 |
| 368 @override |
| 366 ConstructorElementForLink get unnamedConstructor; | 369 ConstructorElementForLink get unnamedConstructor; |
| 367 | 370 |
| 368 @override | 371 @override |
| 369 ReferenceableElementForLink getContainedName(String name) { | 372 ReferenceableElementForLink getContainedName(String name) { |
| 370 if (_containedNames == null) { | 373 if (_containedNames == null) { |
| 371 _containedNames = <String, ReferenceableElementForLink>{}; | 374 _containedNames = <String, ReferenceableElementForLink>{}; |
| 372 // TODO(paulberry): what's the correct way to handle name conflicts? | 375 // TODO(paulberry): what's the correct way to handle name conflicts? |
| 373 for (ConstructorElementForLink constructor in constructors) { | 376 for (ConstructorElementForLink constructor in constructors) { |
| 374 _containedNames[constructor.name] = constructor; | 377 _containedNames[constructor.name] = constructor; |
| 375 } | 378 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 392 | 395 |
| 393 @override | 396 @override |
| 394 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 397 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 395 } | 398 } |
| 396 | 399 |
| 397 /** | 400 /** |
| 398 * Element representing a class resynthesized from a summary during | 401 * Element representing a class resynthesized from a summary during |
| 399 * linking. | 402 * linking. |
| 400 */ | 403 */ |
| 401 class ClassElementForLink_Class extends ClassElementForLink | 404 class ClassElementForLink_Class extends ClassElementForLink |
| 402 with TypeParameterizedElementForLink { | 405 with TypeParameterizedElementMixin { |
| 403 /** | 406 /** |
| 404 * The unlinked representation of the class in the summary. | 407 * The unlinked representation of the class in the summary. |
| 405 */ | 408 */ |
| 406 final UnlinkedClass _unlinkedClass; | 409 final UnlinkedClass _unlinkedClass; |
| 407 | 410 |
| 408 List<ConstructorElementForLink> _constructors; | 411 List<ConstructorElementForLink> _constructors; |
| 409 ConstructorElementForLink _unnamedConstructor; | 412 ConstructorElementForLink _unnamedConstructor; |
| 410 bool _unnamedConstructorComputed = false; | 413 bool _unnamedConstructorComputed = false; |
| 411 List<FieldElementForLink_ClassField> _fields; | 414 List<FieldElementForLink_ClassField> _fields; |
| 412 InterfaceType _supertype; | 415 InterfaceType _supertype; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 _accessors.add(field.getter); | 455 _accessors.add(field.getter); |
| 453 if (!field.isConst && !field.isFinal) { | 456 if (!field.isConst && !field.isFinal) { |
| 454 _accessors.add(field.setter); | 457 _accessors.add(field.setter); |
| 455 } | 458 } |
| 456 } | 459 } |
| 457 } | 460 } |
| 458 return _accessors; | 461 return _accessors; |
| 459 } | 462 } |
| 460 | 463 |
| 461 @override | 464 @override |
| 462 CompilationUnitElementForLink get compilationUnit => enclosingElement; | |
| 463 | |
| 464 @override | |
| 465 List<ConstructorElementForLink> get constructors { | 465 List<ConstructorElementForLink> get constructors { |
| 466 if (_constructors == null) { | 466 if (_constructors == null) { |
| 467 _constructors = <ConstructorElementForLink>[]; | 467 _constructors = <ConstructorElementForLink>[]; |
| 468 for (UnlinkedExecutable unlinkedExecutable | 468 for (UnlinkedExecutable unlinkedExecutable |
| 469 in _unlinkedClass.executables) { | 469 in _unlinkedClass.executables) { |
| 470 if (unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) { | 470 if (unlinkedExecutable.kind == UnlinkedExecutableKind.constructor) { |
| 471 _constructors | 471 _constructors |
| 472 .add(new ConstructorElementForLink(this, unlinkedExecutable)); | 472 .add(new ConstructorElementForLink(this, unlinkedExecutable)); |
| 473 } | 473 } |
| 474 } | 474 } |
| 475 if (_constructors.isEmpty) { | 475 if (_constructors.isEmpty) { |
| 476 _unnamedConstructorComputed = true; | 476 _unnamedConstructorComputed = true; |
| 477 _unnamedConstructor = new ConstructorElementForLink_Synthetic(this); | 477 _unnamedConstructor = new ConstructorElementForLink_Synthetic(this); |
| 478 _constructors.add(_unnamedConstructor); | 478 _constructors.add(_unnamedConstructor); |
| 479 } | 479 } |
| 480 } | 480 } |
| 481 return _constructors; | 481 return _constructors; |
| 482 } | 482 } |
| 483 | 483 |
| 484 @override | 484 @override |
| 485 String get displayName => _unlinkedClass.name; | 485 String get displayName => _unlinkedClass.name; |
| 486 | 486 |
| 487 @override | 487 @override |
| 488 TypeParameterizedElementForLink get enclosingTypeParameterContext => null; | 488 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; |
| 489 | 489 |
| 490 @override | 490 @override |
| 491 List<FieldElementForLink_ClassField> get fields { | 491 List<FieldElementForLink_ClassField> get fields { |
| 492 if (_fields == null) { | 492 if (_fields == null) { |
| 493 _fields = <FieldElementForLink_ClassField>[]; | 493 _fields = <FieldElementForLink_ClassField>[]; |
| 494 for (UnlinkedVariable field in _unlinkedClass.fields) { | 494 for (UnlinkedVariable field in _unlinkedClass.fields) { |
| 495 _fields.add(new FieldElementForLink_ClassField(this, field)); | 495 _fields.add(new FieldElementForLink_ClassField(this, field)); |
| 496 } | 496 } |
| 497 } | 497 } |
| 498 return _fields; | 498 return _fields; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 return null; | 542 return null; |
| 543 } | 543 } |
| 544 return _supertype ??= _computeInterfaceType(_unlinkedClass.supertype); | 544 return _supertype ??= _computeInterfaceType(_unlinkedClass.supertype); |
| 545 } | 545 } |
| 546 | 546 |
| 547 @override | 547 @override |
| 548 DartType get type => | 548 DartType get type => |
| 549 _type ??= buildType((int i) => typeParameterTypes[i], null); | 549 _type ??= buildType((int i) => typeParameterTypes[i], null); |
| 550 | 550 |
| 551 @override | 551 @override |
| 552 List<UnlinkedTypeParam> get unlinkedTypeParams => |
| 553 _unlinkedClass.typeParameters; |
| 554 |
| 555 @override |
| 552 ConstructorElementForLink get unnamedConstructor { | 556 ConstructorElementForLink get unnamedConstructor { |
| 553 if (!_unnamedConstructorComputed) { | 557 if (!_unnamedConstructorComputed) { |
| 554 for (ConstructorElementForLink constructor in constructors) { | 558 for (ConstructorElementForLink constructor in constructors) { |
| 555 if (constructor.name.isEmpty) { | 559 if (constructor.name.isEmpty) { |
| 556 _unnamedConstructor = constructor; | 560 _unnamedConstructor = constructor; |
| 557 break; | 561 break; |
| 558 } | 562 } |
| 559 } | 563 } |
| 560 _unnamedConstructorComputed = true; | 564 _unnamedConstructorComputed = true; |
| 561 } | 565 } |
| 562 return _unnamedConstructor; | 566 return _unnamedConstructor; |
| 563 } | 567 } |
| 564 | 568 |
| 565 @override | 569 @override |
| 566 List<UnlinkedTypeParam> get _unlinkedTypeParams => | |
| 567 _unlinkedClass.typeParameters; | |
| 568 | |
| 569 @override | |
| 570 DartType buildType( | 570 DartType buildType( |
| 571 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { | 571 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { |
| 572 int numTypeParameters = _unlinkedClass.typeParameters.length; | 572 int numTypeParameters = _unlinkedClass.typeParameters.length; |
| 573 if (numTypeParameters != 0) { | 573 if (numTypeParameters != 0) { |
| 574 return new InterfaceTypeImpl.elementWithNameAndArgs(this, name, () { | 574 return new InterfaceTypeImpl.elementWithNameAndArgs(this, name, () { |
| 575 List<DartType> typeArguments = new List<DartType>(numTypeParameters); | 575 List<DartType> typeArguments = new List<DartType>(numTypeParameters); |
| 576 for (int i = 0; i < numTypeParameters; i++) { | 576 for (int i = 0; i < numTypeParameters; i++) { |
| 577 typeArguments[i] = getTypeArgument(i); | 577 typeArguments[i] = getTypeArgument(i); |
| 578 } | 578 } |
| 579 return typeArguments; | 579 return typeArguments; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 } | 623 } |
| 624 | 624 |
| 625 @override | 625 @override |
| 626 String toString() => '$enclosingElement.$name'; | 626 String toString() => '$enclosingElement.$name'; |
| 627 | 627 |
| 628 /** | 628 /** |
| 629 * Convert [typeRef] into an [InterfaceType]. | 629 * Convert [typeRef] into an [InterfaceType]. |
| 630 */ | 630 */ |
| 631 InterfaceType _computeInterfaceType(EntityRef typeRef) { | 631 InterfaceType _computeInterfaceType(EntityRef typeRef) { |
| 632 if (typeRef != null) { | 632 if (typeRef != null) { |
| 633 DartType type = enclosingElement._resolveTypeRef(typeRef, this); | 633 DartType type = enclosingElement.resolveTypeRef(typeRef, this); |
| 634 if (type is InterfaceType) { | 634 if (type is InterfaceType) { |
| 635 return type; | 635 return type; |
| 636 } | 636 } |
| 637 // In the event that the `typeRef` isn't an interface type (which may | 637 // In the event that the `typeRef` isn't an interface type (which may |
| 638 // happen in the event of erroneous code) just fall through and pretend | 638 // happen in the event of erroneous code) just fall through and pretend |
| 639 // the supertype is `Object`. | 639 // the supertype is `Object`. |
| 640 } | 640 } |
| 641 return enclosingElement.enclosingElement._linker.typeProvider.objectType; | 641 return enclosingElement.enclosingElement._linker.typeProvider.objectType; |
| 642 } | 642 } |
| 643 } | 643 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 | 733 |
| 734 @override | 734 @override |
| 735 String toString() => '$enclosingElement.$name'; | 735 String toString() => '$enclosingElement.$name'; |
| 736 } | 736 } |
| 737 | 737 |
| 738 /** | 738 /** |
| 739 * Element representing a compilation unit resynthesized from a | 739 * Element representing a compilation unit resynthesized from a |
| 740 * summary during linking. | 740 * summary during linking. |
| 741 */ | 741 */ |
| 742 abstract class CompilationUnitElementForLink | 742 abstract class CompilationUnitElementForLink |
| 743 implements CompilationUnitElementImpl { | 743 implements CompilationUnitElementImpl, ResynthesizerContext { |
| 744 /** | 744 /** |
| 745 * The unlinked representation of the compilation unit in the | 745 * The unlinked representation of the compilation unit in the |
| 746 * summary. | 746 * summary. |
| 747 */ | 747 */ |
| 748 final UnlinkedUnit _unlinkedUnit; | 748 final UnlinkedUnit _unlinkedUnit; |
| 749 | 749 |
| 750 /** | 750 /** |
| 751 * For each entry in [UnlinkedUnit.references], the element referred | 751 * For each entry in [UnlinkedUnit.references], the element referred |
| 752 * to by the reference, or `null` if it hasn't been located yet. | 752 * to by the reference, or `null` if it hasn't been located yet. |
| 753 */ | 753 */ |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 return _containedNames.putIfAbsent( | 930 return _containedNames.putIfAbsent( |
| 931 name, () => UndefinedElementForLink.instance); | 931 name, () => UndefinedElementForLink.instance); |
| 932 } | 932 } |
| 933 | 933 |
| 934 /** | 934 /** |
| 935 * Compute the type referred to by the given linked type [slot] (interpreted | 935 * Compute the type referred to by the given linked type [slot] (interpreted |
| 936 * relative to [typeParameterContext]). If there is no inferred type in the | 936 * relative to [typeParameterContext]). If there is no inferred type in the |
| 937 * given slot, `dynamic` is returned. | 937 * given slot, `dynamic` is returned. |
| 938 */ | 938 */ |
| 939 DartType getLinkedType( | 939 DartType getLinkedType( |
| 940 int slot, TypeParameterizedElementForLink typeParameterContext); | 940 int slot, TypeParameterizedElementMixin typeParameterContext); |
| 941 | 941 |
| 942 @override | 942 @override |
| 943 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 943 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 944 | 944 |
| 945 @override | 945 @override |
| 946 DartType resolveTypeRef( |
| 947 EntityRef type, TypeParameterizedElementMixin typeParameterContext, |
| 948 {bool defaultVoid: false, bool instantiateToBoundsAllowed: true}) { |
| 949 if (type == null) { |
| 950 if (defaultVoid) { |
| 951 return VoidTypeImpl.instance; |
| 952 } else { |
| 953 return DynamicTypeImpl.instance; |
| 954 } |
| 955 } |
| 956 if (type.paramReference != 0) { |
| 957 return typeParameterContext.getTypeParameterType(type.paramReference); |
| 958 } else if (type.syntheticReturnType != null) { |
| 959 // TODO(paulberry): implement. |
| 960 throw new UnimplementedError(); |
| 961 } else if (type.implicitFunctionTypeIndices.isNotEmpty) { |
| 962 // TODO(paulberry): implement. |
| 963 throw new UnimplementedError(); |
| 964 } else { |
| 965 DartType getTypeArgument(int i) { |
| 966 if (i < type.typeArguments.length) { |
| 967 return resolveTypeRef(type.typeArguments[i], typeParameterContext); |
| 968 } else { |
| 969 return DynamicTypeImpl.instance; |
| 970 } |
| 971 } |
| 972 ReferenceableElementForLink element = _resolveRef(type.reference); |
| 973 return element.buildType( |
| 974 getTypeArgument, type.implicitFunctionTypeIndices); |
| 975 } |
| 976 } |
| 977 |
| 978 @override |
| 946 String toString() => enclosingElement.toString(); | 979 String toString() => enclosingElement.toString(); |
| 947 | 980 |
| 948 /** | 981 /** |
| 949 * Return the element referred to by the given [index] in | 982 * Return the element referred to by the given [index] in |
| 950 * [UnlinkedUnit.references]. If the reference is unresolved, | 983 * [UnlinkedUnit.references]. If the reference is unresolved, |
| 951 * return [UndefinedElementForLink.instance]. | 984 * return [UndefinedElementForLink.instance]. |
| 952 */ | 985 */ |
| 953 ReferenceableElementForLink _resolveRef(int index) { | 986 ReferenceableElementForLink _resolveRef(int index) { |
| 954 if (_references[index] == null) { | 987 if (_references[index] == null) { |
| 955 UnlinkedReference unlinkedReference = | 988 UnlinkedReference unlinkedReference = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 985 _references[index] = enclosingElement.getContainedName(name); | 1018 _references[index] = enclosingElement.getContainedName(name); |
| 986 } | 1019 } |
| 987 } else { | 1020 } else { |
| 988 LibraryElementForLink dependency = | 1021 LibraryElementForLink dependency = |
| 989 enclosingElement._getDependency(linkedReference.dependency); | 1022 enclosingElement._getDependency(linkedReference.dependency); |
| 990 _references[index] = dependency.getContainedName(name); | 1023 _references[index] = dependency.getContainedName(name); |
| 991 } | 1024 } |
| 992 } | 1025 } |
| 993 return _references[index]; | 1026 return _references[index]; |
| 994 } | 1027 } |
| 995 | |
| 996 /** | |
| 997 * Resolve an [EntityRef] into a type. If the reference is | |
| 998 * unresolved, return [DynamicTypeImpl.instance]. | |
| 999 * | |
| 1000 * TODO(paulberry): or should we have a class representing an | |
| 1001 * unresolved type, for consistency with the full element model? | |
| 1002 */ | |
| 1003 DartType _resolveTypeRef( | |
| 1004 EntityRef type, TypeParameterizedElementForLink typeParameterContext, | |
| 1005 {bool defaultVoid: false}) { | |
| 1006 if (type == null) { | |
| 1007 if (defaultVoid) { | |
| 1008 return VoidTypeImpl.instance; | |
| 1009 } else { | |
| 1010 return DynamicTypeImpl.instance; | |
| 1011 } | |
| 1012 } | |
| 1013 if (type.paramReference != 0) { | |
| 1014 return typeParameterContext.getTypeParameterType(type.paramReference); | |
| 1015 } else if (type.syntheticReturnType != null) { | |
| 1016 // TODO(paulberry): implement. | |
| 1017 throw new UnimplementedError(); | |
| 1018 } else if (type.implicitFunctionTypeIndices.isNotEmpty) { | |
| 1019 // TODO(paulberry): implement. | |
| 1020 throw new UnimplementedError(); | |
| 1021 } else { | |
| 1022 DartType getTypeArgument(int i) { | |
| 1023 if (i < type.typeArguments.length) { | |
| 1024 return _resolveTypeRef(type.typeArguments[i], typeParameterContext); | |
| 1025 } else { | |
| 1026 return DynamicTypeImpl.instance; | |
| 1027 } | |
| 1028 } | |
| 1029 ReferenceableElementForLink element = _resolveRef(type.reference); | |
| 1030 return element.buildType( | |
| 1031 getTypeArgument, type.implicitFunctionTypeIndices); | |
| 1032 } | |
| 1033 } | |
| 1034 } | 1028 } |
| 1035 | 1029 |
| 1036 /** | 1030 /** |
| 1037 * Element representing a compilation unit which is part of the build | 1031 * Element representing a compilation unit which is part of the build |
| 1038 * unit being linked. | 1032 * unit being linked. |
| 1039 */ | 1033 */ |
| 1040 class CompilationUnitElementInBuildUnit extends CompilationUnitElementForLink { | 1034 class CompilationUnitElementInBuildUnit extends CompilationUnitElementForLink { |
| 1041 @override | 1035 @override |
| 1042 final LinkedUnitBuilder _linkedUnit; | 1036 final LinkedUnitBuilder _linkedUnit; |
| 1043 | 1037 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1180 return addRawReference(element.name, | 1174 return addRawReference(element.name, |
| 1181 containingReference: addReference(enclosingClass), | 1175 containingReference: addReference(enclosingClass), |
| 1182 kind: ReferenceKind.propertyAccessor); | 1176 kind: ReferenceKind.propertyAccessor); |
| 1183 } | 1177 } |
| 1184 // TODO(paulberry): implement other cases | 1178 // TODO(paulberry): implement other cases |
| 1185 throw new UnimplementedError('${element.runtimeType}'); | 1179 throw new UnimplementedError('${element.runtimeType}'); |
| 1186 } | 1180 } |
| 1187 | 1181 |
| 1188 @override | 1182 @override |
| 1189 DartType getLinkedType( | 1183 DartType getLinkedType( |
| 1190 int slot, TypeParameterizedElementForLink typeParameterContext) { | 1184 int slot, TypeParameterizedElementMixin typeParameterContext) { |
| 1191 // This method should only be called on compilation units that come from | 1185 // This method should only be called on compilation units that come from |
| 1192 // dependencies, never on compilation units that are part of the current | 1186 // dependencies, never on compilation units that are part of the current |
| 1193 // build unit. | 1187 // build unit. |
| 1194 throw new StateError( | 1188 throw new StateError( |
| 1195 'Linker tried to access linked type from current build unit'); | 1189 'Linker tried to access linked type from current build unit'); |
| 1196 } | 1190 } |
| 1197 | 1191 |
| 1198 /** | 1192 /** |
| 1199 * Perform type inference and const cycle detection on this | 1193 * Perform type inference and const cycle detection on this |
| 1200 * compilation unit. | 1194 * compilation unit. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1229 */ | 1223 */ |
| 1230 void _storeConstCycle(int slot) { | 1224 void _storeConstCycle(int slot) { |
| 1231 _linkedUnit.constCycles.add(slot); | 1225 _linkedUnit.constCycles.add(slot); |
| 1232 } | 1226 } |
| 1233 | 1227 |
| 1234 /** | 1228 /** |
| 1235 * Store the given [linkedType] in the given [slot] of the this compilation | 1229 * Store the given [linkedType] in the given [slot] of the this compilation |
| 1236 * unit's linked type list. | 1230 * unit's linked type list. |
| 1237 */ | 1231 */ |
| 1238 void _storeLinkedType(int slot, DartType linkedType, | 1232 void _storeLinkedType(int slot, DartType linkedType, |
| 1239 TypeParameterizedElementForLink typeParameterContext) { | 1233 TypeParameterizedElementMixin typeParameterContext) { |
| 1240 if (slot != 0) { | 1234 if (slot != 0) { |
| 1241 if (linkedType != null && !linkedType.isDynamic) { | 1235 if (linkedType != null && !linkedType.isDynamic) { |
| 1242 _linkedUnit.types.add(_createLinkedType( | 1236 _linkedUnit.types.add(_createLinkedType( |
| 1243 linkedType, this, typeParameterContext, | 1237 linkedType, this, typeParameterContext, |
| 1244 slot: slot)); | 1238 slot: slot)); |
| 1245 } | 1239 } |
| 1246 } | 1240 } |
| 1247 } | 1241 } |
| 1248 } | 1242 } |
| 1249 | 1243 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1286 for (EntityRef ref in _linkedUnit.types) { | 1280 for (EntityRef ref in _linkedUnit.types) { |
| 1287 _linkedTypeRefs[ref.slot] = ref; | 1281 _linkedTypeRefs[ref.slot] = ref; |
| 1288 } | 1282 } |
| 1289 } | 1283 } |
| 1290 | 1284 |
| 1291 @override | 1285 @override |
| 1292 bool get isInBuildUnit => false; | 1286 bool get isInBuildUnit => false; |
| 1293 | 1287 |
| 1294 @override | 1288 @override |
| 1295 DartType getLinkedType( | 1289 DartType getLinkedType( |
| 1296 int slot, TypeParameterizedElementForLink typeParameterContext) { | 1290 int slot, TypeParameterizedElementMixin typeParameterContext) { |
| 1297 if (slot < _linkedTypeRefs.length) { | 1291 if (slot < _linkedTypeRefs.length) { |
| 1298 return _resolveTypeRef(_linkedTypeRefs[slot], typeParameterContext); | 1292 return resolveTypeRef(_linkedTypeRefs[slot], typeParameterContext); |
| 1299 } else { | 1293 } else { |
| 1300 return DynamicTypeImpl.instance; | 1294 return DynamicTypeImpl.instance; |
| 1301 } | 1295 } |
| 1302 } | 1296 } |
| 1303 } | 1297 } |
| 1304 | 1298 |
| 1305 /** | 1299 /** |
| 1306 * Instance of [ConstNode] representing a constant constructor. | 1300 * Instance of [ConstNode] representing a constant constructor. |
| 1307 */ | 1301 */ |
| 1308 class ConstConstructorNode extends ConstNode { | 1302 class ConstConstructorNode extends ConstNode { |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1748 // Kick off the algorithm starting with the starting point. | 1742 // Kick off the algorithm starting with the starting point. |
| 1749 strongConnect(startingPoint); | 1743 strongConnect(startingPoint); |
| 1750 } | 1744 } |
| 1751 } | 1745 } |
| 1752 | 1746 |
| 1753 /** | 1747 /** |
| 1754 * Base class for executable elements resynthesized from a summary during | 1748 * Base class for executable elements resynthesized from a summary during |
| 1755 * linking. | 1749 * linking. |
| 1756 */ | 1750 */ |
| 1757 abstract class ExecutableElementForLink extends Object | 1751 abstract class ExecutableElementForLink extends Object |
| 1758 with TypeParameterizedElementForLink, ParameterParentElementForLink | 1752 with TypeParameterizedElementMixin, ParameterParentElementForLink |
| 1759 implements ExecutableElementImpl { | 1753 implements ExecutableElementImpl { |
| 1760 /** | 1754 /** |
| 1761 * The unlinked representation of the method in the summary. | 1755 * The unlinked representation of the method in the summary. |
| 1762 */ | 1756 */ |
| 1763 final UnlinkedExecutable _unlinkedExecutable; | 1757 final UnlinkedExecutable _unlinkedExecutable; |
| 1764 | 1758 |
| 1765 DartType _declaredReturnType; | 1759 DartType _declaredReturnType; |
| 1766 DartType _inferredReturnType; | 1760 DartType _inferredReturnType; |
| 1767 FunctionTypeImpl _type; | 1761 FunctionTypeImpl _type; |
| 1768 String _name; | 1762 String _name; |
| 1769 String _displayName; | 1763 String _displayName; |
| 1770 | 1764 |
| 1771 @override | 1765 @override |
| 1772 final CompilationUnitElementForLink compilationUnit; | 1766 final CompilationUnitElementForLink compilationUnit; |
| 1773 | 1767 |
| 1774 ExecutableElementForLink(this.compilationUnit, this._unlinkedExecutable); | 1768 ExecutableElementForLink(this.compilationUnit, this._unlinkedExecutable); |
| 1775 | 1769 |
| 1776 /** | 1770 /** |
| 1777 * If the executable element had an explicitly declared return type, return | 1771 * If the executable element had an explicitly declared return type, return |
| 1778 * it. Otherwise return `null`. | 1772 * it. Otherwise return `null`. |
| 1779 */ | 1773 */ |
| 1780 DartType get declaredReturnType { | 1774 DartType get declaredReturnType { |
| 1781 if (_unlinkedExecutable.returnType == null) { | 1775 if (_unlinkedExecutable.returnType == null) { |
| 1782 return null; | 1776 return null; |
| 1783 } else { | 1777 } else { |
| 1784 return _declaredReturnType ??= | 1778 return _declaredReturnType ??= |
| 1785 compilationUnit._resolveTypeRef(_unlinkedExecutable.returnType, this); | 1779 compilationUnit.resolveTypeRef(_unlinkedExecutable.returnType, this); |
| 1786 } | 1780 } |
| 1787 } | 1781 } |
| 1788 | 1782 |
| 1789 @override | 1783 @override |
| 1790 String get displayName { | 1784 String get displayName { |
| 1791 if (_displayName == null) { | 1785 if (_displayName == null) { |
| 1792 _displayName = _unlinkedExecutable.name; | 1786 _displayName = _unlinkedExecutable.name; |
| 1793 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { | 1787 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { |
| 1794 _displayName = _displayName.substring(0, _displayName.length - 1); | 1788 _displayName = _displayName.substring(0, _displayName.length - 1); |
| 1795 } | 1789 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 if (_name == null) { | 1840 if (_name == null) { |
| 1847 _name = _unlinkedExecutable.name; | 1841 _name = _unlinkedExecutable.name; |
| 1848 if (_name == '-' && _unlinkedExecutable.parameters.isEmpty) { | 1842 if (_name == '-' && _unlinkedExecutable.parameters.isEmpty) { |
| 1849 _name = 'unary-'; | 1843 _name = 'unary-'; |
| 1850 } | 1844 } |
| 1851 } | 1845 } |
| 1852 return _name; | 1846 return _name; |
| 1853 } | 1847 } |
| 1854 | 1848 |
| 1855 @override | 1849 @override |
| 1850 ResynthesizerContext get resynthesizerContext => compilationUnit; |
| 1851 |
| 1852 @override |
| 1856 DartType get returnType => declaredReturnType ?? inferredReturnType; | 1853 DartType get returnType => declaredReturnType ?? inferredReturnType; |
| 1857 | 1854 |
| 1858 @override | 1855 @override |
| 1859 void set returnType(DartType inferredType) { | 1856 void set returnType(DartType inferredType) { |
| 1860 assert(_inferredReturnType == null); | 1857 assert(_inferredReturnType == null); |
| 1861 _inferredReturnType = inferredType; | 1858 _inferredReturnType = inferredType; |
| 1862 } | 1859 } |
| 1863 | 1860 |
| 1864 @override | 1861 @override |
| 1865 FunctionTypeImpl get type => _type ??= new FunctionTypeImpl(this); | 1862 FunctionTypeImpl get type => _type ??= new FunctionTypeImpl(this); |
| 1866 | 1863 |
| 1867 @override | 1864 @override |
| 1868 TypeParameterizedElementForLink get typeParameterContext => this; | 1865 TypeParameterizedElementMixin get typeParameterContext => this; |
| 1869 | 1866 |
| 1870 @override | 1867 @override |
| 1871 List<UnlinkedParam> get unlinkedParameters => _unlinkedExecutable.parameters; | 1868 List<UnlinkedParam> get unlinkedParameters => _unlinkedExecutable.parameters; |
| 1872 | 1869 |
| 1873 @override | 1870 @override |
| 1874 List<UnlinkedTypeParam> get _unlinkedTypeParams => | 1871 List<UnlinkedTypeParam> get unlinkedTypeParams => |
| 1875 _unlinkedExecutable.typeParameters; | 1872 _unlinkedExecutable.typeParameters; |
| 1876 | 1873 |
| 1877 @override | 1874 @override |
| 1878 bool isAccessibleIn(LibraryElement library) => | 1875 bool isAccessibleIn(LibraryElement library) => |
| 1879 !Identifier.isPrivateName(name) || identical(this.library, library); | 1876 !Identifier.isPrivateName(name) || identical(this.library, library); |
| 1880 | 1877 |
| 1881 /** | 1878 /** |
| 1882 * Compute the default return type for this type of executable element (if no | 1879 * Compute the default return type for this type of executable element (if no |
| 1883 * return type is declared and strong mode type inference cannot infer a | 1880 * return type is declared and strong mode type inference cannot infer a |
| 1884 * better return type). | 1881 * better return type). |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1910 ExecutableElementForLink_NonLocal( | 1907 ExecutableElementForLink_NonLocal( |
| 1911 CompilationUnitElementForLink compilationUnit, | 1908 CompilationUnitElementForLink compilationUnit, |
| 1912 this.enclosingClass, | 1909 this.enclosingClass, |
| 1913 UnlinkedExecutable unlinkedExecutable) | 1910 UnlinkedExecutable unlinkedExecutable) |
| 1914 : super(compilationUnit, unlinkedExecutable); | 1911 : super(compilationUnit, unlinkedExecutable); |
| 1915 | 1912 |
| 1916 @override | 1913 @override |
| 1917 Element get enclosingElement => enclosingClass ?? compilationUnit; | 1914 Element get enclosingElement => enclosingClass ?? compilationUnit; |
| 1918 | 1915 |
| 1919 @override | 1916 @override |
| 1920 TypeParameterizedElementForLink get enclosingTypeParameterContext => | 1917 TypeParameterizedElementMixin get enclosingTypeParameterContext => |
| 1921 enclosingClass; | 1918 enclosingClass; |
| 1922 | 1919 |
| 1923 /** | 1920 /** |
| 1924 * Store the results of type inference for this method in [compilationUnit]. | 1921 * Store the results of type inference for this method in [compilationUnit]. |
| 1925 */ | 1922 */ |
| 1926 void link(CompilationUnitElementInBuildUnit compilationUnit) { | 1923 void link(CompilationUnitElementInBuildUnit compilationUnit) { |
| 1927 if (_unlinkedExecutable.returnType == null) { | 1924 if (_unlinkedExecutable.returnType == null) { |
| 1928 compilationUnit._storeLinkedType( | 1925 compilationUnit._storeLinkedType( |
| 1929 _unlinkedExecutable.inferredReturnTypeSlot, inferredReturnType, this); | 1926 _unlinkedExecutable.inferredReturnTypeSlot, inferredReturnType, this); |
| 1930 } | 1927 } |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2267 stack.length -= numNamed + numPositional; | 2264 stack.length -= numNamed + numPositional; |
| 2268 strPtr += numNamed; | 2265 strPtr += numNamed; |
| 2269 EntityRef ref = _getNextRef(); | 2266 EntityRef ref = _getNextRef(); |
| 2270 ConstructorElementForLink element = | 2267 ConstructorElementForLink element = |
| 2271 unit._resolveRef(ref.reference).asConstructor; | 2268 unit._resolveRef(ref.reference).asConstructor; |
| 2272 if (element != null) { | 2269 if (element != null) { |
| 2273 ClassElementForLink_Class enclosingClass = element.enclosingClass; | 2270 ClassElementForLink_Class enclosingClass = element.enclosingClass; |
| 2274 stack.add(enclosingClass.buildType((int i) { | 2271 stack.add(enclosingClass.buildType((int i) { |
| 2275 // Type argument explicitly specified. | 2272 // Type argument explicitly specified. |
| 2276 if (i < ref.typeArguments.length) { | 2273 if (i < ref.typeArguments.length) { |
| 2277 return unit._resolveTypeRef( | 2274 return unit.resolveTypeRef( |
| 2278 ref.typeArguments[i], variable._typeParameterContext); | 2275 ref.typeArguments[i], variable._typeParameterContext); |
| 2279 } | 2276 } |
| 2280 // In strong mode, type argument defaults to bound (if any). | 2277 // In strong mode, type argument defaults to bound (if any). |
| 2281 if (linker.strongMode) { | 2278 if (linker.strongMode) { |
| 2282 TypeParameterElement typeParameter = enclosingClass.typeParameters[i]; | 2279 TypeParameterElement typeParameter = enclosingClass.typeParameters[i]; |
| 2283 if (typeParameter.bound != null) { | 2280 if (typeParameter.bound != null) { |
| 2284 return typeParameter.bound; | 2281 return typeParameter.bound; |
| 2285 } | 2282 } |
| 2286 } | 2283 } |
| 2287 // Otherwise type argument defaults to `dynamic`. | 2284 // Otherwise type argument defaults to `dynamic`. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2407 List<String> _getNextStrings(int n) { | 2404 List<String> _getNextStrings(int n) { |
| 2408 List<String> result = new List<String>(n); | 2405 List<String> result = new List<String>(n); |
| 2409 for (int i = 0; i < n; i++) { | 2406 for (int i = 0; i < n; i++) { |
| 2410 result[i] = _getNextString(); | 2407 result[i] = _getNextString(); |
| 2411 } | 2408 } |
| 2412 return result; | 2409 return result; |
| 2413 } | 2410 } |
| 2414 | 2411 |
| 2415 DartType _getNextTypeRef() { | 2412 DartType _getNextTypeRef() { |
| 2416 EntityRef ref = _getNextRef(); | 2413 EntityRef ref = _getNextRef(); |
| 2417 return unit._resolveTypeRef(ref, variable._typeParameterContext); | 2414 return unit.resolveTypeRef(ref, variable._typeParameterContext); |
| 2418 } | 2415 } |
| 2419 | 2416 |
| 2420 /** | 2417 /** |
| 2421 * Return the type of the property with the given [propertyName] in the | 2418 * Return the type of the property with the given [propertyName] in the |
| 2422 * given [targetType]. May return `dynamic` if the property cannot be | 2419 * given [targetType]. May return `dynamic` if the property cannot be |
| 2423 * resolved. | 2420 * resolved. |
| 2424 */ | 2421 */ |
| 2425 DartType _getPropertyType(DartType targetType, String propertyName) { | 2422 DartType _getPropertyType(DartType targetType, String propertyName) { |
| 2426 return targetType is InterfaceType | 2423 return targetType is InterfaceType |
| 2427 ? targetType.lookUpGetter(propertyName, library)?.returnType | 2424 ? targetType.lookUpGetter(propertyName, library)?.returnType |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2594 bool get isStatic => unlinkedVariable.isStatic; | 2591 bool get isStatic => unlinkedVariable.isStatic; |
| 2595 | 2592 |
| 2596 @override | 2593 @override |
| 2597 void set type(DartType inferredType) { | 2594 void set type(DartType inferredType) { |
| 2598 assert(!isStatic); | 2595 assert(!isStatic); |
| 2599 assert(_inferredInstanceType == null); | 2596 assert(_inferredInstanceType == null); |
| 2600 _inferredInstanceType = inferredType; | 2597 _inferredInstanceType = inferredType; |
| 2601 } | 2598 } |
| 2602 | 2599 |
| 2603 @override | 2600 @override |
| 2604 TypeParameterizedElementForLink get _typeParameterContext => enclosingElement; | 2601 TypeParameterizedElementMixin get _typeParameterContext => enclosingElement; |
| 2605 | 2602 |
| 2606 /** | 2603 /** |
| 2607 * Store the results of type inference for this field in | 2604 * Store the results of type inference for this field in |
| 2608 * [compilationUnit]. | 2605 * [compilationUnit]. |
| 2609 */ | 2606 */ |
| 2610 void link(CompilationUnitElementInBuildUnit compilationUnit) { | 2607 void link(CompilationUnitElementInBuildUnit compilationUnit) { |
| 2611 if (hasImplicitType) { | 2608 if (hasImplicitType) { |
| 2612 compilationUnit._storeLinkedType( | 2609 compilationUnit._storeLinkedType( |
| 2613 unlinkedVariable.inferredTypeSlot, | 2610 unlinkedVariable.inferredTypeSlot, |
| 2614 isStatic ? inferredType : _inferredInstanceType, | 2611 isStatic ? inferredType : _inferredInstanceType, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2668 * Element representing a function-typed parameter resynthesied from a summary | 2665 * Element representing a function-typed parameter resynthesied from a summary |
| 2669 * during linking. | 2666 * during linking. |
| 2670 */ | 2667 */ |
| 2671 class FunctionElementForLink_FunctionTypedParam extends Object | 2668 class FunctionElementForLink_FunctionTypedParam extends Object |
| 2672 with ParameterParentElementForLink | 2669 with ParameterParentElementForLink |
| 2673 implements FunctionElement { | 2670 implements FunctionElement { |
| 2674 @override | 2671 @override |
| 2675 final ParameterElementForLink enclosingElement; | 2672 final ParameterElementForLink enclosingElement; |
| 2676 | 2673 |
| 2677 @override | 2674 @override |
| 2678 final TypeParameterizedElementForLink typeParameterContext; | 2675 final TypeParameterizedElementMixin typeParameterContext; |
| 2679 | 2676 |
| 2680 @override | 2677 @override |
| 2681 final List<UnlinkedParam> unlinkedParameters; | 2678 final List<UnlinkedParam> unlinkedParameters; |
| 2682 | 2679 |
| 2683 DartType _returnType; | 2680 DartType _returnType; |
| 2684 List<int> _implicitFunctionTypeIndices; | 2681 List<int> _implicitFunctionTypeIndices; |
| 2685 | 2682 |
| 2686 FunctionElementForLink_FunctionTypedParam(this.enclosingElement, | 2683 FunctionElementForLink_FunctionTypedParam(this.enclosingElement, |
| 2687 this.typeParameterContext, this.unlinkedParameters); | 2684 this.typeParameterContext, this.unlinkedParameters); |
| 2688 | 2685 |
| 2689 @override | 2686 @override |
| 2690 List<int> get implicitFunctionTypeIndices { | 2687 List<int> get implicitFunctionTypeIndices { |
| 2691 if (_implicitFunctionTypeIndices == null) { | 2688 if (_implicitFunctionTypeIndices == null) { |
| 2692 _implicitFunctionTypeIndices = enclosingElement | 2689 _implicitFunctionTypeIndices = enclosingElement |
| 2693 .enclosingElement.implicitFunctionTypeIndices | 2690 .enclosingElement.implicitFunctionTypeIndices |
| 2694 .toList(); | 2691 .toList(); |
| 2695 _implicitFunctionTypeIndices.add(enclosingElement._parameterIndex); | 2692 _implicitFunctionTypeIndices.add(enclosingElement._parameterIndex); |
| 2696 } | 2693 } |
| 2697 return _implicitFunctionTypeIndices; | 2694 return _implicitFunctionTypeIndices; |
| 2698 } | 2695 } |
| 2699 | 2696 |
| 2700 @override | 2697 @override |
| 2701 DartType get returnType { | 2698 DartType get returnType { |
| 2702 if (_returnType == null) { | 2699 if (_returnType == null) { |
| 2703 if (enclosingElement._unlinkedParam.type == null) { | 2700 if (enclosingElement._unlinkedParam.type == null) { |
| 2704 _returnType = DynamicTypeImpl.instance; | 2701 _returnType = DynamicTypeImpl.instance; |
| 2705 } else { | 2702 } else { |
| 2706 _returnType = enclosingElement.compilationUnit._resolveTypeRef( | 2703 _returnType = enclosingElement.compilationUnit.resolveTypeRef( |
| 2707 enclosingElement._unlinkedParam.type, typeParameterContext); | 2704 enclosingElement._unlinkedParam.type, typeParameterContext); |
| 2708 } | 2705 } |
| 2709 } | 2706 } |
| 2710 return _returnType; | 2707 return _returnType; |
| 2711 } | 2708 } |
| 2712 | 2709 |
| 2713 @override | 2710 @override |
| 2714 List<TypeParameterElement> get typeParameters => const []; | 2711 List<TypeParameterElement> get typeParameters => const []; |
| 2715 | 2712 |
| 2716 @override | 2713 @override |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2728 */ | 2725 */ |
| 2729 final VariableElementForLink _variable; | 2726 final VariableElementForLink _variable; |
| 2730 | 2727 |
| 2731 List<FunctionElementForLink_Local_NonSynthetic> _functions; | 2728 List<FunctionElementForLink_Local_NonSynthetic> _functions; |
| 2732 | 2729 |
| 2733 FunctionElementForLink_Initializer(this._variable); | 2730 FunctionElementForLink_Initializer(this._variable); |
| 2734 | 2731 |
| 2735 @override | 2732 @override |
| 2736 VariableElementForLink get enclosingElement => _variable; | 2733 VariableElementForLink get enclosingElement => _variable; |
| 2737 | 2734 |
| 2738 TypeParameterizedElementForLink get enclosingTypeParameterContext => | 2735 TypeParameterizedElementMixin get enclosingTypeParameterContext => |
| 2739 _variable.enclosingElement is ClassElementForLink | 2736 _variable.enclosingElement is ClassElementForLink |
| 2740 ? _variable.enclosingElement | 2737 ? _variable.enclosingElement |
| 2741 : null; | 2738 : null; |
| 2742 | 2739 |
| 2743 @override | 2740 @override |
| 2744 List<FunctionElementForLink_Local_NonSynthetic> get functions => | 2741 List<FunctionElementForLink_Local_NonSynthetic> get functions => |
| 2745 _functions ??= _variable.unlinkedVariable.initializer.localFunctions | 2742 _functions ??= _variable.unlinkedVariable.initializer.localFunctions |
| 2746 .map((UnlinkedExecutable ex) => | 2743 .map((UnlinkedExecutable ex) => |
| 2747 new FunctionElementForLink_Local_NonSynthetic( | 2744 new FunctionElementForLink_Local_NonSynthetic( |
| 2748 _variable.compilationUnit, this, ex)) | 2745 _variable.compilationUnit, this, ex)) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2804 @override | 2801 @override |
| 2805 final ExecutableElementForLink enclosingElement; | 2802 final ExecutableElementForLink enclosingElement; |
| 2806 | 2803 |
| 2807 FunctionElementForLink_Local_NonSynthetic( | 2804 FunctionElementForLink_Local_NonSynthetic( |
| 2808 CompilationUnitElementForLink compilationUnit, | 2805 CompilationUnitElementForLink compilationUnit, |
| 2809 this.enclosingElement, | 2806 this.enclosingElement, |
| 2810 UnlinkedExecutable unlinkedExecutable) | 2807 UnlinkedExecutable unlinkedExecutable) |
| 2811 : super(compilationUnit, unlinkedExecutable); | 2808 : super(compilationUnit, unlinkedExecutable); |
| 2812 | 2809 |
| 2813 @override | 2810 @override |
| 2814 TypeParameterizedElementForLink get enclosingTypeParameterContext => | 2811 TypeParameterizedElementMixin get enclosingTypeParameterContext => |
| 2815 enclosingElement; | 2812 enclosingElement; |
| 2816 | 2813 |
| 2817 @override | 2814 @override |
| 2818 DartType buildType( | 2815 DartType buildType( |
| 2819 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { | 2816 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { |
| 2820 assert(implicitFunctionTypeIndices.isEmpty); | 2817 assert(implicitFunctionTypeIndices.isEmpty); |
| 2821 return type; | 2818 return type; |
| 2822 } | 2819 } |
| 2823 | 2820 |
| 2824 @override | 2821 @override |
| 2825 FunctionElementForLink_Local getLocalFunction(int index) { | 2822 FunctionElementForLink_Local getLocalFunction(int index) { |
| 2826 // TODO(paulberry): implement. | 2823 // TODO(paulberry): implement. |
| 2827 throw new UnimplementedError(); | 2824 throw new UnimplementedError(); |
| 2828 } | 2825 } |
| 2829 | 2826 |
| 2830 @override | 2827 @override |
| 2831 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 2828 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 2832 } | 2829 } |
| 2833 | 2830 |
| 2834 /** | 2831 /** |
| 2835 * Element representing a typedef resynthesized from a summary during linking. | 2832 * Element representing a typedef resynthesized from a summary during linking. |
| 2836 */ | 2833 */ |
| 2837 class FunctionTypeAliasElementForLink extends Object | 2834 class FunctionTypeAliasElementForLink extends Object |
| 2838 with | 2835 with |
| 2839 TypeParameterizedElementForLink, | 2836 TypeParameterizedElementMixin, |
| 2840 ParameterParentElementForLink, | 2837 ParameterParentElementForLink, |
| 2841 ReferenceableElementForLink | 2838 ReferenceableElementForLink |
| 2842 implements FunctionTypeAliasElement, ElementImpl { | 2839 implements FunctionTypeAliasElement, ElementImpl { |
| 2843 @override | 2840 @override |
| 2844 final CompilationUnitElementForLink enclosingElement; | 2841 final CompilationUnitElementForLink enclosingElement; |
| 2845 | 2842 |
| 2846 /** | 2843 /** |
| 2847 * The unlinked representation of the typedef in the summary. | 2844 * The unlinked representation of the typedef in the summary. |
| 2848 */ | 2845 */ |
| 2849 final UnlinkedTypedef _unlinkedTypedef; | 2846 final UnlinkedTypedef _unlinkedTypedef; |
| 2850 | 2847 |
| 2851 FunctionTypeImpl _type; | 2848 FunctionTypeImpl _type; |
| 2852 DartType _returnType; | 2849 DartType _returnType; |
| 2853 | 2850 |
| 2854 FunctionTypeAliasElementForLink(this.enclosingElement, this._unlinkedTypedef); | 2851 FunctionTypeAliasElementForLink(this.enclosingElement, this._unlinkedTypedef); |
| 2855 | 2852 |
| 2856 @override | 2853 @override |
| 2857 DartType get asStaticType { | 2854 DartType get asStaticType { |
| 2858 return enclosingElement.enclosingElement._linker.typeProvider.typeType; | 2855 return enclosingElement.enclosingElement._linker.typeProvider.typeType; |
| 2859 } | 2856 } |
| 2860 | 2857 |
| 2861 @override | 2858 @override |
| 2862 CompilationUnitElementForLink get compilationUnit => enclosingElement; | 2859 TypeParameterizedElementMixin get enclosingTypeParameterContext => null; |
| 2863 | |
| 2864 @override | |
| 2865 TypeParameterizedElementForLink get enclosingTypeParameterContext => null; | |
| 2866 | 2860 |
| 2867 @override | 2861 @override |
| 2868 String get identifier => _unlinkedTypedef.name; | 2862 String get identifier => _unlinkedTypedef.name; |
| 2869 | 2863 |
| 2870 @override | 2864 @override |
| 2871 List<int> get implicitFunctionTypeIndices => const <int>[]; | 2865 List<int> get implicitFunctionTypeIndices => const <int>[]; |
| 2872 | 2866 |
| 2873 @override | 2867 @override |
| 2874 bool get isSynthetic => false; | 2868 bool get isSynthetic => false; |
| 2875 | 2869 |
| 2876 @override | 2870 @override |
| 2877 LibraryElementForLink get library => enclosingElement.library; | 2871 LibraryElementForLink get library => enclosingElement.library; |
| 2878 | 2872 |
| 2879 @override | 2873 @override |
| 2880 String get name => _unlinkedTypedef.name; | 2874 String get name => _unlinkedTypedef.name; |
| 2881 | 2875 |
| 2882 @override | 2876 @override |
| 2883 DartType get returnType => _returnType ??= | 2877 ResynthesizerContext get resynthesizerContext => enclosingElement; |
| 2884 enclosingElement._resolveTypeRef(_unlinkedTypedef.returnType, this); | |
| 2885 | 2878 |
| 2886 @override | 2879 @override |
| 2887 TypeParameterizedElementForLink get typeParameterContext => this; | 2880 DartType get returnType => _returnType ??= |
| 2881 enclosingElement.resolveTypeRef(_unlinkedTypedef.returnType, this); |
| 2882 |
| 2883 @override |
| 2884 TypeParameterizedElementMixin get typeParameterContext => this; |
| 2888 | 2885 |
| 2889 @override | 2886 @override |
| 2890 List<UnlinkedParam> get unlinkedParameters => _unlinkedTypedef.parameters; | 2887 List<UnlinkedParam> get unlinkedParameters => _unlinkedTypedef.parameters; |
| 2891 | 2888 |
| 2892 @override | 2889 @override |
| 2893 List<UnlinkedTypeParam> get _unlinkedTypeParams => | 2890 List<UnlinkedTypeParam> get unlinkedTypeParams => |
| 2894 _unlinkedTypedef.typeParameters; | 2891 _unlinkedTypedef.typeParameters; |
| 2895 | 2892 |
| 2896 @override | 2893 @override |
| 2897 DartType buildType( | 2894 DartType buildType( |
| 2898 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { | 2895 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { |
| 2899 int numTypeParameters = _unlinkedTypedef.typeParameters.length; | 2896 int numTypeParameters = _unlinkedTypedef.typeParameters.length; |
| 2900 if (numTypeParameters != 0) { | 2897 if (numTypeParameters != 0) { |
| 2901 List<DartType> typeArguments = new List<DartType>(numTypeParameters); | 2898 List<DartType> typeArguments = new List<DartType>(numTypeParameters); |
| 2902 for (int i = 0; i < numTypeParameters; i++) { | 2899 for (int i = 0; i < numTypeParameters; i++) { |
| 2903 typeArguments[i] = getTypeArgument(i); | 2900 typeArguments[i] = getTypeArgument(i); |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3597 */ | 3594 */ |
| 3598 class ParameterElementForLink implements ParameterElementImpl { | 3595 class ParameterElementForLink implements ParameterElementImpl { |
| 3599 /** | 3596 /** |
| 3600 * The unlinked representation of the parameter in the summary. | 3597 * The unlinked representation of the parameter in the summary. |
| 3601 */ | 3598 */ |
| 3602 final UnlinkedParam _unlinkedParam; | 3599 final UnlinkedParam _unlinkedParam; |
| 3603 | 3600 |
| 3604 /** | 3601 /** |
| 3605 * The innermost enclosing element that can declare type parameters. | 3602 * The innermost enclosing element that can declare type parameters. |
| 3606 */ | 3603 */ |
| 3607 final TypeParameterizedElementForLink _typeParameterContext; | 3604 final TypeParameterizedElementMixin _typeParameterContext; |
| 3608 | 3605 |
| 3609 /** | 3606 /** |
| 3610 * If this parameter has a default value and the enclosing library | 3607 * If this parameter has a default value and the enclosing library |
| 3611 * is part of the build unit being linked, the parameter's node in | 3608 * is part of the build unit being linked, the parameter's node in |
| 3612 * the constant evaluation dependency graph. Otherwise `null`. | 3609 * the constant evaluation dependency graph. Otherwise `null`. |
| 3613 */ | 3610 */ |
| 3614 ConstNode _constNode; | 3611 ConstNode _constNode; |
| 3615 | 3612 |
| 3616 /** | 3613 /** |
| 3617 * The compilation unit in which this parameter appears. | 3614 * The compilation unit in which this parameter appears. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3669 this, _typeParameterContext, _unlinkedParam.parameters)); | 3666 this, _typeParameterContext, _unlinkedParam.parameters)); |
| 3670 } else if (_unlinkedParam.type == null) { | 3667 } else if (_unlinkedParam.type == null) { |
| 3671 if (!compilationUnit.isInBuildUnit) { | 3668 if (!compilationUnit.isInBuildUnit) { |
| 3672 _inferredType = compilationUnit.getLinkedType( | 3669 _inferredType = compilationUnit.getLinkedType( |
| 3673 _unlinkedParam.inferredTypeSlot, _typeParameterContext); | 3670 _unlinkedParam.inferredTypeSlot, _typeParameterContext); |
| 3674 return _inferredType; | 3671 return _inferredType; |
| 3675 } else { | 3672 } else { |
| 3676 _declaredType = DynamicTypeImpl.instance; | 3673 _declaredType = DynamicTypeImpl.instance; |
| 3677 } | 3674 } |
| 3678 } else { | 3675 } else { |
| 3679 _declaredType = compilationUnit._resolveTypeRef( | 3676 _declaredType = compilationUnit.resolveTypeRef( |
| 3680 _unlinkedParam.type, _typeParameterContext); | 3677 _unlinkedParam.type, _typeParameterContext); |
| 3681 } | 3678 } |
| 3682 } | 3679 } |
| 3683 return _declaredType; | 3680 return _declaredType; |
| 3684 } | 3681 } |
| 3685 | 3682 |
| 3686 @override | 3683 @override |
| 3687 void set type(DartType inferredType) { | 3684 void set type(DartType inferredType) { |
| 3688 assert(_inferredType == null); | 3685 assert(_inferredType == null); |
| 3689 _inferredType = inferredType; | 3686 _inferredType = inferredType; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3746 /** | 3743 /** |
| 3747 * Get all the parameters of this element. | 3744 * Get all the parameters of this element. |
| 3748 */ | 3745 */ |
| 3749 List<ParameterElementForLink> get parameters { | 3746 List<ParameterElementForLink> get parameters { |
| 3750 if (_parameters == null) { | 3747 if (_parameters == null) { |
| 3751 List<UnlinkedParam> unlinkedParameters = this.unlinkedParameters; | 3748 List<UnlinkedParam> unlinkedParameters = this.unlinkedParameters; |
| 3752 int numParameters = unlinkedParameters.length; | 3749 int numParameters = unlinkedParameters.length; |
| 3753 _parameters = new List<ParameterElementForLink>(numParameters); | 3750 _parameters = new List<ParameterElementForLink>(numParameters); |
| 3754 for (int i = 0; i < numParameters; i++) { | 3751 for (int i = 0; i < numParameters; i++) { |
| 3755 UnlinkedParam unlinkedParam = unlinkedParameters[i]; | 3752 UnlinkedParam unlinkedParam = unlinkedParameters[i]; |
| 3756 _parameters[i] = new ParameterElementForLink(this, unlinkedParam, | 3753 _parameters[i] = new ParameterElementForLink( |
| 3757 typeParameterContext, typeParameterContext.compilationUnit, i); | 3754 this, |
| 3755 unlinkedParam, |
| 3756 typeParameterContext, |
| 3757 typeParameterContext.resynthesizerContext |
| 3758 as CompilationUnitElementForLink, |
| 3759 i); |
| 3758 } | 3760 } |
| 3759 } | 3761 } |
| 3760 return _parameters; | 3762 return _parameters; |
| 3761 } | 3763 } |
| 3762 | 3764 |
| 3763 /** | 3765 /** |
| 3764 * Get the innermost enclosing element that can declare type parameters (which | 3766 * Get the innermost enclosing element that can declare type parameters (which |
| 3765 * may be [this], or may be a parent when there are function-typed | 3767 * may be [this], or may be a parent when there are function-typed |
| 3766 * parameters). | 3768 * parameters). |
| 3767 */ | 3769 */ |
| 3768 TypeParameterizedElementForLink get typeParameterContext; | 3770 TypeParameterizedElementMixin get typeParameterContext; |
| 3769 | 3771 |
| 3770 /** | 3772 /** |
| 3771 * Get the list of unlinked parameters of this element. | 3773 * Get the list of unlinked parameters of this element. |
| 3772 */ | 3774 */ |
| 3773 List<UnlinkedParam> get unlinkedParameters; | 3775 List<UnlinkedParam> get unlinkedParameters; |
| 3774 } | 3776 } |
| 3775 | 3777 |
| 3776 /** | 3778 /** |
| 3777 * Element representing a getter or setter resynthesized from a summary during | 3779 * Element representing a getter or setter resynthesized from a summary during |
| 3778 * linking. | 3780 * linking. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3877 CompilationUnitElementForLink enclosingUnit, | 3879 CompilationUnitElementForLink enclosingUnit, |
| 3878 ClassElementForLink_Class enclosingClass, | 3880 ClassElementForLink_Class enclosingClass, |
| 3879 UnlinkedExecutable unlinkedExecutable, | 3881 UnlinkedExecutable unlinkedExecutable, |
| 3880 this.variable) | 3882 this.variable) |
| 3881 : super(enclosingUnit, enclosingClass, unlinkedExecutable); | 3883 : super(enclosingUnit, enclosingClass, unlinkedExecutable); |
| 3882 | 3884 |
| 3883 @override | 3885 @override |
| 3884 DartType get asStaticType => returnType; | 3886 DartType get asStaticType => returnType; |
| 3885 | 3887 |
| 3886 @override | 3888 @override |
| 3887 bool get isStatic => enclosingClass == null || super.isStatic; | |
| 3888 | |
| 3889 @override | |
| 3890 PropertyAccessorElementForLink_Executable get correspondingGetter => | 3889 PropertyAccessorElementForLink_Executable get correspondingGetter => |
| 3891 variable.getter; | 3890 variable.getter; |
| 3892 | 3891 |
| 3893 @override | 3892 @override |
| 3894 bool get isGetter => | 3893 bool get isGetter => |
| 3895 _unlinkedExecutable.kind == UnlinkedExecutableKind.getter; | 3894 _unlinkedExecutable.kind == UnlinkedExecutableKind.getter; |
| 3896 | 3895 |
| 3897 @override | 3896 @override |
| 3898 bool get isSetter => | 3897 bool get isSetter => |
| 3899 _unlinkedExecutable.kind == UnlinkedExecutableKind.setter; | 3898 _unlinkedExecutable.kind == UnlinkedExecutableKind.setter; |
| 3900 | 3899 |
| 3901 @override | 3900 @override |
| 3901 bool get isStatic => enclosingClass == null || super.isStatic; |
| 3902 |
| 3903 @override |
| 3902 ElementKind get kind => _unlinkedExecutable.kind == | 3904 ElementKind get kind => _unlinkedExecutable.kind == |
| 3903 UnlinkedExecutableKind.getter ? ElementKind.GETTER : ElementKind.SETTER; | 3905 UnlinkedExecutableKind.getter ? ElementKind.GETTER : ElementKind.SETTER; |
| 3904 | 3906 |
| 3905 @override | 3907 @override |
| 3906 ReferenceableElementForLink getContainedName(String name) { | 3908 ReferenceableElementForLink getContainedName(String name) { |
| 3907 return new NonstaticMemberElementForLink(library, this, name); | 3909 return new NonstaticMemberElementForLink(library, this, name); |
| 3908 } | 3910 } |
| 3909 | 3911 |
| 3910 @override | 3912 @override |
| 3911 FunctionElementForLink_Local getLocalFunction(int index) { | 3913 FunctionElementForLink_Local getLocalFunction(int index) { |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4157 DartType _returnType; | 4159 DartType _returnType; |
| 4158 | 4160 |
| 4159 TopLevelFunctionElementForLink( | 4161 TopLevelFunctionElementForLink( |
| 4160 CompilationUnitElementForLink enclosingUnit, UnlinkedExecutable _buf) | 4162 CompilationUnitElementForLink enclosingUnit, UnlinkedExecutable _buf) |
| 4161 : super(enclosingUnit, null, _buf); | 4163 : super(enclosingUnit, null, _buf); |
| 4162 | 4164 |
| 4163 @override | 4165 @override |
| 4164 DartType get asStaticType => type; | 4166 DartType get asStaticType => type; |
| 4165 | 4167 |
| 4166 @override | 4168 @override |
| 4169 String get identifier => _unlinkedExecutable.name; |
| 4170 |
| 4171 @override |
| 4167 bool get isStatic => true; | 4172 bool get isStatic => true; |
| 4168 | 4173 |
| 4169 @override | 4174 @override |
| 4170 ElementKind get kind => ElementKind.FUNCTION; | 4175 ElementKind get kind => ElementKind.FUNCTION; |
| 4171 | 4176 |
| 4172 @override | 4177 @override |
| 4173 FunctionElementForLink_Local getLocalFunction(int index) { | 4178 FunctionElementForLink_Local getLocalFunction(int index) { |
| 4174 // TODO(paulberry): implement. | 4179 // TODO(paulberry): implement. |
| 4175 return null; | 4180 return null; |
| 4176 } | 4181 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4192 @override | 4197 @override |
| 4193 CompilationUnitElementForLink get enclosingElement => compilationUnit; | 4198 CompilationUnitElementForLink get enclosingElement => compilationUnit; |
| 4194 | 4199 |
| 4195 @override | 4200 @override |
| 4196 bool get isStatic => true; | 4201 bool get isStatic => true; |
| 4197 | 4202 |
| 4198 @override | 4203 @override |
| 4199 LibraryElementForLink get library => compilationUnit.library; | 4204 LibraryElementForLink get library => compilationUnit.library; |
| 4200 | 4205 |
| 4201 @override | 4206 @override |
| 4202 TypeParameterizedElementForLink get _typeParameterContext => null; | 4207 TypeParameterizedElementMixin get _typeParameterContext => null; |
| 4203 | 4208 |
| 4204 /** | 4209 /** |
| 4205 * Store the results of type inference for this variable in | 4210 * Store the results of type inference for this variable in |
| 4206 * [compilationUnit]. | 4211 * [compilationUnit]. |
| 4207 */ | 4212 */ |
| 4208 void link(CompilationUnitElementInBuildUnit compilationUnit) { | 4213 void link(CompilationUnitElementInBuildUnit compilationUnit) { |
| 4209 if (hasImplicitType) { | 4214 if (hasImplicitType) { |
| 4210 TypeInferenceNode typeInferenceNode = this._typeInferenceNode; | 4215 TypeInferenceNode typeInferenceNode = this._typeInferenceNode; |
| 4211 if (typeInferenceNode != null) { | 4216 if (typeInferenceNode != null) { |
| 4212 compilationUnit._storeLinkedType( | 4217 compilationUnit._storeLinkedType( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4321 } else { | 4326 } else { |
| 4322 variableElement._inferredType = | 4327 variableElement._inferredType = |
| 4323 new ExprTypeComputer(variableElement).compute(); | 4328 new ExprTypeComputer(variableElement).compute(); |
| 4324 } | 4329 } |
| 4325 } | 4330 } |
| 4326 | 4331 |
| 4327 @override | 4332 @override |
| 4328 String toString() => 'TypeInferenceNode($variableElement)'; | 4333 String toString() => 'TypeInferenceNode($variableElement)'; |
| 4329 } | 4334 } |
| 4330 | 4335 |
| 4331 /** | |
| 4332 * Element representing a type parameter resynthesized from a summary during | |
| 4333 * linking. | |
| 4334 */ | |
| 4335 class TypeParameterElementForLink implements TypeParameterElementImpl { | |
| 4336 /** | |
| 4337 * The unlinked representation of the type parameter in the summary. | |
| 4338 */ | |
| 4339 final UnlinkedTypeParam _unlinkedTypeParam; | |
| 4340 | |
| 4341 /** | |
| 4342 * The number of type parameters whose scope overlaps this one, and which are | |
| 4343 * declared earlier in the file. | |
| 4344 */ | |
| 4345 final int nestingLevel; | |
| 4346 | |
| 4347 @override | |
| 4348 final TypeParameterizedElementForLink enclosingElement; | |
| 4349 | |
| 4350 TypeParameterTypeImpl _type; | |
| 4351 ElementLocation _location; | |
| 4352 | |
| 4353 DartType _bound; | |
| 4354 | |
| 4355 TypeParameterElementForLink( | |
| 4356 this.enclosingElement, this._unlinkedTypeParam, this.nestingLevel); | |
| 4357 | |
| 4358 @override | |
| 4359 DartType get bound { | |
| 4360 if (_unlinkedTypeParam.bound == null) { | |
| 4361 return null; | |
| 4362 } | |
| 4363 return _bound ??= enclosingElement.compilationUnit | |
| 4364 ._resolveTypeRef(_unlinkedTypeParam.bound, enclosingElement); | |
| 4365 } | |
| 4366 | |
| 4367 @override | |
| 4368 String get identifier => name; | |
| 4369 | |
| 4370 @override | |
| 4371 ElementKind get kind => ElementKind.TYPE_PARAMETER; | |
| 4372 | |
| 4373 @override | |
| 4374 ElementLocation get location => | |
| 4375 _location ??= new ElementLocationImpl.con1(this); | |
| 4376 | |
| 4377 @override | |
| 4378 String get name => _unlinkedTypeParam.name; | |
| 4379 | |
| 4380 @override | |
| 4381 TypeParameterTypeImpl get type => _type ??= new TypeParameterTypeImpl(this); | |
| 4382 | |
| 4383 @override | |
| 4384 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | |
| 4385 } | |
| 4386 | |
| 4387 /** | |
| 4388 * Mixin representing an element which can have type parameters. | |
| 4389 */ | |
| 4390 abstract class TypeParameterizedElementForLink | |
| 4391 implements TypeParameterizedElement { | |
| 4392 List<TypeParameterType> _typeParameterTypes; | |
| 4393 List<TypeParameterElementForLink> _typeParameters; | |
| 4394 int _nestingLevel; | |
| 4395 | |
| 4396 /** | |
| 4397 * Get the compilation unit in which this element is declared. | |
| 4398 */ | |
| 4399 CompilationUnitElementForLink get compilationUnit; | |
| 4400 | |
| 4401 /** | |
| 4402 * Get the type parameter context enclosing this one, if any. | |
| 4403 */ | |
| 4404 TypeParameterizedElementForLink get enclosingTypeParameterContext; | |
| 4405 | |
| 4406 /** | |
| 4407 * Find out how many type parameters are in scope in this context. | |
| 4408 */ | |
| 4409 int get typeParameterNestingLevel => | |
| 4410 _nestingLevel ??= _unlinkedTypeParams.length + | |
| 4411 (enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0); | |
| 4412 | |
| 4413 List<TypeParameterElementForLink> get typeParameters { | |
| 4414 if (_typeParameters == null) { | |
| 4415 int enclosingNestingLevel = | |
| 4416 enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0; | |
| 4417 int numTypeParameters = _unlinkedTypeParams.length; | |
| 4418 _typeParameters = | |
| 4419 new List<TypeParameterElementForLink>(numTypeParameters); | |
| 4420 for (int i = 0; i < numTypeParameters; i++) { | |
| 4421 _typeParameters[i] = new TypeParameterElementForLink( | |
| 4422 this, _unlinkedTypeParams[i], enclosingNestingLevel + i); | |
| 4423 } | |
| 4424 } | |
| 4425 return _typeParameters; | |
| 4426 } | |
| 4427 | |
| 4428 /** | |
| 4429 * Get a list of [TypeParameterType] objects corresponding to the | |
| 4430 * element's type parameters. | |
| 4431 */ | |
| 4432 List<TypeParameterType> get typeParameterTypes { | |
| 4433 if (_typeParameterTypes == null) { | |
| 4434 _typeParameterTypes = typeParameters | |
| 4435 .map((TypeParameterElementForLink e) => e.type) | |
| 4436 .toList(); | |
| 4437 } | |
| 4438 return _typeParameterTypes; | |
| 4439 } | |
| 4440 | |
| 4441 /** | |
| 4442 * Get the [UnlinkedTypeParam]s representing the type parameters declared by | |
| 4443 * this element. | |
| 4444 */ | |
| 4445 List<UnlinkedTypeParam> get _unlinkedTypeParams; | |
| 4446 | |
| 4447 /** | |
| 4448 * Convert the given [index] into a type parameter type. | |
| 4449 */ | |
| 4450 TypeParameterType getTypeParameterType(int index) { | |
| 4451 List<TypeParameterType> types = typeParameterTypes; | |
| 4452 if (index <= types.length) { | |
| 4453 return types[types.length - index]; | |
| 4454 } else if (enclosingTypeParameterContext != null) { | |
| 4455 return enclosingTypeParameterContext | |
| 4456 .getTypeParameterType(index - types.length); | |
| 4457 } else { | |
| 4458 // If we get here, it means that a summary contained a type parameter inde
x | |
| 4459 // that was out of range. | |
| 4460 throw new RangeError('Invalid type parameter index'); | |
| 4461 } | |
| 4462 } | |
| 4463 | |
| 4464 /** | |
| 4465 * Find out if the given [typeParameter] is in scope in this context. | |
| 4466 */ | |
| 4467 bool isTypeParameterInScope(TypeParameterElementForLink typeParameter) { | |
| 4468 if (typeParameter.enclosingElement == this) { | |
| 4469 return true; | |
| 4470 } else if (enclosingTypeParameterContext != null) { | |
| 4471 return enclosingTypeParameterContext | |
| 4472 .isTypeParameterInScope(typeParameter); | |
| 4473 } else { | |
| 4474 return false; | |
| 4475 } | |
| 4476 } | |
| 4477 } | |
| 4478 | |
| 4479 class TypeProviderForLink implements TypeProvider { | 4336 class TypeProviderForLink implements TypeProvider { |
| 4480 final Linker _linker; | 4337 final Linker _linker; |
| 4481 | 4338 |
| 4482 InterfaceType _boolType; | 4339 InterfaceType _boolType; |
| 4483 InterfaceType _deprecatedType; | 4340 InterfaceType _deprecatedType; |
| 4484 InterfaceType _doubleType; | 4341 InterfaceType _doubleType; |
| 4485 InterfaceType _functionType; | 4342 InterfaceType _functionType; |
| 4486 InterfaceType _futureDynamicType; | 4343 InterfaceType _futureDynamicType; |
| 4487 InterfaceType _futureNullType; | 4344 InterfaceType _futureNullType; |
| 4488 InterfaceType _futureType; | 4345 InterfaceType _futureType; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4678 } | 4535 } |
| 4679 | 4536 |
| 4680 /** | 4537 /** |
| 4681 * If the variable has an explicitly declared return type, return it. | 4538 * If the variable has an explicitly declared return type, return it. |
| 4682 * Otherwise return `null`. | 4539 * Otherwise return `null`. |
| 4683 */ | 4540 */ |
| 4684 DartType get declaredType { | 4541 DartType get declaredType { |
| 4685 if (unlinkedVariable.type == null) { | 4542 if (unlinkedVariable.type == null) { |
| 4686 return null; | 4543 return null; |
| 4687 } else { | 4544 } else { |
| 4688 return _declaredType ??= compilationUnit._resolveTypeRef( | 4545 return _declaredType ??= compilationUnit.resolveTypeRef( |
| 4689 unlinkedVariable.type, _typeParameterContext); | 4546 unlinkedVariable.type, _typeParameterContext); |
| 4690 } | 4547 } |
| 4691 } | 4548 } |
| 4692 | 4549 |
| 4693 @override | 4550 @override |
| 4694 PropertyAccessorElementForLink_Variable get getter => | 4551 PropertyAccessorElementForLink_Variable get getter => |
| 4695 _getter ??= new PropertyAccessorElementForLink_Variable(this, false); | 4552 _getter ??= new PropertyAccessorElementForLink_Variable(this, false); |
| 4696 | 4553 |
| 4697 @override | 4554 @override |
| 4698 bool get hasImplicitType => unlinkedVariable.type == null; | 4555 bool get hasImplicitType => unlinkedVariable.type == null; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4770 | 4627 |
| 4771 @override | 4628 @override |
| 4772 void set type(DartType newType) { | 4629 void set type(DartType newType) { |
| 4773 // TODO(paulberry): store inferred type. | 4630 // TODO(paulberry): store inferred type. |
| 4774 } | 4631 } |
| 4775 | 4632 |
| 4776 /** | 4633 /** |
| 4777 * The context in which type parameters should be interpreted, or `null` if | 4634 * The context in which type parameters should be interpreted, or `null` if |
| 4778 * there are no type parameters in scope. | 4635 * there are no type parameters in scope. |
| 4779 */ | 4636 */ |
| 4780 TypeParameterizedElementForLink get _typeParameterContext; | 4637 TypeParameterizedElementMixin get _typeParameterContext; |
| 4781 | 4638 |
| 4782 @override | 4639 @override |
| 4783 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 4640 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 4784 | 4641 |
| 4785 @override | 4642 @override |
| 4786 String toString() => '$enclosingElement.$name'; | 4643 String toString() => '$enclosingElement.$name'; |
| 4787 } | 4644 } |
| OLD | NEW |