| 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 ConstructorElementForLink get unnamedConstructor; | 312 ConstructorElementForLink get unnamedConstructor; |
| 313 | 313 |
| 314 @override | 314 @override |
| 315 ReferenceableElementForLink getContainedName(String name) { | 315 ReferenceableElementForLink getContainedName(String name) { |
| 316 if (_containedNames == null) { | 316 if (_containedNames == null) { |
| 317 _containedNames = <String, ReferenceableElementForLink>{}; | 317 _containedNames = <String, ReferenceableElementForLink>{}; |
| 318 // TODO(paulberry): what's the correct way to handle name conflicts? | 318 // TODO(paulberry): what's the correct way to handle name conflicts? |
| 319 for (ConstructorElementForLink constructor in constructors) { | 319 for (ConstructorElementForLink constructor in constructors) { |
| 320 _containedNames[constructor.name] = constructor; | 320 _containedNames[constructor.name] = constructor; |
| 321 } | 321 } |
| 322 for (FieldElementForLink field in fields) { | |
| 323 // TODO(paulberry): do we need to handle nonstatic fields for | |
| 324 // consistent behavior with erroneous code? | |
| 325 if (field.isStatic) { | |
| 326 _containedNames[field.name] = field; | |
| 327 } | |
| 328 } | |
| 329 for (PropertyAccessorElementForLink accessor in accessors) { | 322 for (PropertyAccessorElementForLink accessor in accessors) { |
| 330 if (accessor.isStatic && !accessor.isSynthetic) { | 323 if (accessor.isStatic) { |
| 331 // TODO(paulberry): add synthetic elements too? | |
| 332 _containedNames[accessor.name] = accessor; | 324 _containedNames[accessor.name] = accessor; |
| 333 } | 325 } |
| 334 } | 326 } |
| 335 // TODO(paulberry): add methods. | 327 // TODO(paulberry): add methods. |
| 336 } | 328 } |
| 337 return _containedNames.putIfAbsent( | 329 return _containedNames.putIfAbsent( |
| 338 name, () => UndefinedElementForLink.instance); | 330 name, () => UndefinedElementForLink.instance); |
| 339 } | 331 } |
| 340 | 332 |
| 341 /** | 333 /** |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 this, unlinkedExecutable, syntheticVariable); | 388 this, unlinkedExecutable, syntheticVariable); |
| 397 _accessors.add(accessor); | 389 _accessors.add(accessor); |
| 398 if (unlinkedExecutable.kind == UnlinkedExecutableKind.getter) { | 390 if (unlinkedExecutable.kind == UnlinkedExecutableKind.getter) { |
| 399 syntheticVariable._getter = accessor; | 391 syntheticVariable._getter = accessor; |
| 400 } else { | 392 } else { |
| 401 syntheticVariable._setter = accessor; | 393 syntheticVariable._setter = accessor; |
| 402 } | 394 } |
| 403 } | 395 } |
| 404 } | 396 } |
| 405 for (FieldElementForLink_ClassField field in fields) { | 397 for (FieldElementForLink_ClassField field in fields) { |
| 406 _accessors | 398 _accessors.add(field.getter); |
| 407 .add(new PropertyAccessorElementForLink_Variable(field, false)); | |
| 408 if (!field.isConst && !field.isFinal) { | 399 if (!field.isConst && !field.isFinal) { |
| 409 _accessors | 400 _accessors.add(field.setter); |
| 410 .add(new PropertyAccessorElementForLink_Variable(field, true)); | |
| 411 } | 401 } |
| 412 } | 402 } |
| 413 } | 403 } |
| 414 return _accessors; | 404 return _accessors; |
| 415 } | 405 } |
| 416 | 406 |
| 417 @override | 407 @override |
| 418 List<ConstructorElementForLink> get constructors { | 408 List<ConstructorElementForLink> get constructors { |
| 419 if (_constructors == null) { | 409 if (_constructors == null) { |
| 420 _constructors = <ConstructorElementForLink>[]; | 410 _constructors = <ConstructorElementForLink>[]; |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 if (superClass != null && !superClass.isObject) { | 1246 if (superClass != null && !superClass.isObject) { |
| 1257 ConstructorElementForLink unnamedConstructor = | 1247 ConstructorElementForLink unnamedConstructor = |
| 1258 superClass.unnamedConstructor; | 1248 superClass.unnamedConstructor; |
| 1259 safeAddDependency(unnamedConstructor?._constNode); | 1249 safeAddDependency(unnamedConstructor?._constNode); |
| 1260 } | 1250 } |
| 1261 } | 1251 } |
| 1262 for (FieldElementForLink field in enclosingClass.fields) { | 1252 for (FieldElementForLink field in enclosingClass.fields) { |
| 1263 // Note: non-static const isn't allowed but we handle it anyway so | 1253 // Note: non-static const isn't allowed but we handle it anyway so |
| 1264 // that we won't be confused by incorrect code. | 1254 // that we won't be confused by incorrect code. |
| 1265 if ((field.isFinal || field.isConst) && !field.isStatic) { | 1255 if ((field.isFinal || field.isConst) && !field.isStatic) { |
| 1266 safeAddDependency(field.asConstVariable); | 1256 safeAddDependency(field.getter.asConstVariable); |
| 1267 } | 1257 } |
| 1268 } | 1258 } |
| 1269 for (ParameterElementForLink parameterElement | 1259 for (ParameterElementForLink parameterElement |
| 1270 in constructorElement.parameters) { | 1260 in constructorElement.parameters) { |
| 1271 safeAddDependency(parameterElement._constNode); | 1261 safeAddDependency(parameterElement._constNode); |
| 1272 } | 1262 } |
| 1273 } | 1263 } |
| 1274 return dependencies; | 1264 return dependencies; |
| 1275 } | 1265 } |
| 1276 | 1266 |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2451 return DynamicTypeImpl.instance; | 2441 return DynamicTypeImpl.instance; |
| 2452 } | 2442 } |
| 2453 return type; | 2443 return type; |
| 2454 } | 2444 } |
| 2455 } | 2445 } |
| 2456 | 2446 |
| 2457 /** | 2447 /** |
| 2458 * Element representing a field resynthesized from a summary during | 2448 * Element representing a field resynthesized from a summary during |
| 2459 * linking. | 2449 * linking. |
| 2460 */ | 2450 */ |
| 2461 abstract class FieldElementForLink | 2451 abstract class FieldElementForLink implements FieldElement { |
| 2462 implements FieldElement, ReferenceableElementForLink {} | 2452 @override |
| 2453 PropertyAccessorElementForLink get getter; |
| 2454 |
| 2455 @override |
| 2456 PropertyAccessorElementForLink get setter; |
| 2457 } |
| 2463 | 2458 |
| 2464 /** | 2459 /** |
| 2465 * Specialization of [FieldElementForLink] for class fields. | 2460 * Specialization of [FieldElementForLink] for class fields. |
| 2466 */ | 2461 */ |
| 2467 class FieldElementForLink_ClassField extends VariableElementForLink | 2462 class FieldElementForLink_ClassField extends VariableElementForLink |
| 2468 implements FieldElementForLink { | 2463 implements FieldElementForLink { |
| 2469 @override | 2464 @override |
| 2470 final ClassElementForLink_Class enclosingElement; | 2465 final ClassElementForLink_Class enclosingElement; |
| 2471 | 2466 |
| 2467 PropertyAccessorElementForLink_Variable _getter; |
| 2468 PropertyAccessorElementForLink_Variable _setter; |
| 2469 |
| 2472 /** | 2470 /** |
| 2473 * If this is an instance field, the type that was computed by | 2471 * If this is an instance field, the type that was computed by |
| 2474 * [InstanceMemberInferrer] (if any). Otherwise `null`. | 2472 * [InstanceMemberInferrer] (if any). Otherwise `null`. |
| 2475 */ | 2473 */ |
| 2476 DartType _inferredInstanceType; | 2474 DartType _inferredInstanceType; |
| 2477 | 2475 |
| 2478 FieldElementForLink_ClassField(ClassElementForLink_Class enclosingElement, | 2476 FieldElementForLink_ClassField(ClassElementForLink_Class enclosingElement, |
| 2479 UnlinkedVariable unlinkedVariable) | 2477 UnlinkedVariable unlinkedVariable) |
| 2480 : enclosingElement = enclosingElement, | 2478 : enclosingElement = enclosingElement, |
| 2481 super(unlinkedVariable, enclosingElement.enclosingElement); | 2479 super(unlinkedVariable, enclosingElement.enclosingElement); |
| 2482 | 2480 |
| 2483 @override | 2481 @override |
| 2482 PropertyAccessorElementForLink_Variable get getter => |
| 2483 _getter ??= new PropertyAccessorElementForLink_Variable(this, false); |
| 2484 |
| 2485 @override |
| 2484 bool get isStatic => unlinkedVariable.isStatic; | 2486 bool get isStatic => unlinkedVariable.isStatic; |
| 2485 | 2487 |
| 2486 @override | 2488 @override |
| 2489 PropertyAccessorElementForLink_Variable get setter { |
| 2490 if (!isConst && !isFinal) { |
| 2491 return _setter ??= |
| 2492 new PropertyAccessorElementForLink_Variable(this, true); |
| 2493 } else { |
| 2494 return null; |
| 2495 } |
| 2496 } |
| 2497 |
| 2498 @override |
| 2487 void set type(DartType inferredType) { | 2499 void set type(DartType inferredType) { |
| 2488 assert(!isStatic); | 2500 assert(!isStatic); |
| 2489 assert(_inferredInstanceType == null); | 2501 assert(_inferredInstanceType == null); |
| 2490 _inferredInstanceType = inferredType; | 2502 _inferredInstanceType = inferredType; |
| 2491 } | 2503 } |
| 2492 | 2504 |
| 2493 @override | 2505 @override |
| 2494 TypeParameterizedElementForLink get _typeParameterContext => enclosingElement; | 2506 TypeParameterizedElementForLink get _typeParameterContext => enclosingElement; |
| 2495 | 2507 |
| 2496 /** | 2508 /** |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2520 * is an enum's `values` field. | 2532 * is an enum's `values` field. |
| 2521 */ | 2533 */ |
| 2522 final UnlinkedEnumValue unlinkedEnumValue; | 2534 final UnlinkedEnumValue unlinkedEnumValue; |
| 2523 | 2535 |
| 2524 @override | 2536 @override |
| 2525 final ClassElementForLink_Enum enclosingElement; | 2537 final ClassElementForLink_Enum enclosingElement; |
| 2526 | 2538 |
| 2527 FieldElementForLink_EnumField(this.unlinkedEnumValue, this.enclosingElement); | 2539 FieldElementForLink_EnumField(this.unlinkedEnumValue, this.enclosingElement); |
| 2528 | 2540 |
| 2529 @override | 2541 @override |
| 2530 ConstructorElementForLink get asConstructor => null; | |
| 2531 | |
| 2532 @override | |
| 2533 ConstVariableNode get asConstVariable { | |
| 2534 // Even though enum fields are constants, there is no need to include them | |
| 2535 // in the const dependency graph because they can't participate in a | |
| 2536 // circularity. | |
| 2537 return null; | |
| 2538 } | |
| 2539 | |
| 2540 @override | |
| 2541 DartType get asStaticType => enclosingElement.type; | |
| 2542 | |
| 2543 @override | |
| 2544 TypeInferenceNode get asTypeInferenceNode => null; | |
| 2545 | |
| 2546 @override | |
| 2547 bool get isStatic => true; | 2542 bool get isStatic => true; |
| 2548 | 2543 |
| 2549 @override | 2544 @override |
| 2550 bool get isSynthetic => false; | 2545 bool get isSynthetic => false; |
| 2551 | 2546 |
| 2552 @override | 2547 @override |
| 2553 String get name => | 2548 String get name => |
| 2554 unlinkedEnumValue == null ? 'values' : unlinkedEnumValue.name; | 2549 unlinkedEnumValue == null ? 'values' : unlinkedEnumValue.name; |
| 2555 | 2550 |
| 2556 @override | 2551 @override |
| 2557 DartType buildType(DartType getTypeArgument(int i), | |
| 2558 List<int> implicitFunctionTypeIndices) => | |
| 2559 DynamicTypeImpl.instance; | |
| 2560 | |
| 2561 @override | |
| 2562 ReferenceableElementForLink getContainedName(String name) => | |
| 2563 UndefinedElementForLink.instance; | |
| 2564 | |
| 2565 @override | |
| 2566 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 2552 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 2567 | 2553 |
| 2568 @override | 2554 @override |
| 2569 String toString() => '$enclosingElement.$name'; | 2555 String toString() => '$enclosingElement.$name'; |
| 2570 } | 2556 } |
| 2571 | 2557 |
| 2572 /** | 2558 /** |
| 2573 * Element representing a function-typed parameter resynthesied from a summary | 2559 * Element representing a function-typed parameter resynthesied from a summary |
| 2574 * during linking. | 2560 * during linking. |
| 2575 */ | 2561 */ |
| (...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3583 @override | 3569 @override |
| 3584 final bool isSetter; | 3570 final bool isSetter; |
| 3585 | 3571 |
| 3586 final VariableElementForLink variable; | 3572 final VariableElementForLink variable; |
| 3587 FunctionTypeImpl _type; | 3573 FunctionTypeImpl _type; |
| 3588 List<ParameterElement> _parameters; | 3574 List<ParameterElement> _parameters; |
| 3589 | 3575 |
| 3590 PropertyAccessorElementForLink_Variable(this.variable, this.isSetter); | 3576 PropertyAccessorElementForLink_Variable(this.variable, this.isSetter); |
| 3591 | 3577 |
| 3592 @override | 3578 @override |
| 3579 ConstructorElementForLink get asConstructor => null; |
| 3580 |
| 3581 @override |
| 3582 ConstVariableNode get asConstVariable => variable._constNode; |
| 3583 |
| 3584 @override |
| 3585 DartType get asStaticType => returnType; |
| 3586 |
| 3587 @override |
| 3588 TypeInferenceNode get asTypeInferenceNode => variable._typeInferenceNode; |
| 3589 |
| 3590 @override |
| 3593 Element get enclosingElement => variable.enclosingElement; | 3591 Element get enclosingElement => variable.enclosingElement; |
| 3594 | 3592 |
| 3595 @override | 3593 @override |
| 3596 bool get isGetter => !isSetter; | 3594 bool get isGetter => !isSetter; |
| 3597 | 3595 |
| 3598 @override | 3596 @override |
| 3599 bool get isStatic => variable.isStatic; | 3597 bool get isStatic => variable.isStatic; |
| 3600 | 3598 |
| 3601 @override | 3599 @override |
| 3602 bool get isSynthetic => true; | 3600 bool get isSynthetic => true; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3633 | 3631 |
| 3634 @override | 3632 @override |
| 3635 FunctionTypeImpl get type => _type ??= new FunctionTypeImpl(this); | 3633 FunctionTypeImpl get type => _type ??= new FunctionTypeImpl(this); |
| 3636 | 3634 |
| 3637 @override | 3635 @override |
| 3638 List<TypeParameterElement> get typeParameters { | 3636 List<TypeParameterElement> get typeParameters { |
| 3639 // TODO(paulberry): is this correct for fields in generic classes? | 3637 // TODO(paulberry): is this correct for fields in generic classes? |
| 3640 return const []; | 3638 return const []; |
| 3641 } | 3639 } |
| 3642 | 3640 |
| 3641 @override |
| 3642 DartType buildType(DartType getTypeArgument(int i), |
| 3643 List<int> implicitFunctionTypeIndices) => |
| 3644 DynamicTypeImpl.instance; |
| 3645 |
| 3643 /** | 3646 /** |
| 3644 * Compute the type of the corresponding variable, which may depend on the | 3647 * Compute the type of the corresponding variable, which may depend on the |
| 3645 * progress of type inference. | 3648 * progress of type inference. |
| 3646 */ | 3649 */ |
| 3647 DartType computeVariableType() { | 3650 DartType computeVariableType() { |
| 3648 if (variable.hasImplicitType && | 3651 if (variable.hasImplicitType && |
| 3649 !isStatic && | 3652 !isStatic && |
| 3650 !variable.compilationUnit.isTypeInferenceComplete) { | 3653 !variable.compilationUnit.isTypeInferenceComplete) { |
| 3651 // This is an instance field and we are currently inferring types in the | 3654 // This is an instance field and we are currently inferring types in the |
| 3652 // library cycle containing it. So we shouldn't use the inferred type | 3655 // library cycle containing it. So we shouldn't use the inferred type |
| 3653 // (even if we have already computed it), since that would lead to | 3656 // (even if we have already computed it), since that would lead to |
| 3654 // non-deterministic type inference results. | 3657 // non-deterministic type inference results. |
| 3655 return DynamicTypeImpl.instance; | 3658 return DynamicTypeImpl.instance; |
| 3656 } else { | 3659 } else { |
| 3657 return variable.type; | 3660 return variable.type; |
| 3658 } | 3661 } |
| 3659 } | 3662 } |
| 3660 | 3663 |
| 3661 @override | 3664 @override |
| 3665 ReferenceableElementForLink getContainedName(String name) => |
| 3666 UndefinedElementForLink.instance; |
| 3667 |
| 3668 @override |
| 3662 bool isAccessibleIn(LibraryElement library) => | 3669 bool isAccessibleIn(LibraryElement library) => |
| 3663 !Identifier.isPrivateName(name) || identical(this.library, library); | 3670 !Identifier.isPrivateName(name) || identical(this.library, library); |
| 3664 | 3671 |
| 3665 @override | 3672 @override |
| 3666 void link(CompilationUnitElementInBuildUnit compilationUnit) {} | 3673 void link(CompilationUnitElementInBuildUnit compilationUnit) {} |
| 3667 | 3674 |
| 3668 @override | 3675 @override |
| 3669 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 3676 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 3670 | 3677 |
| 3671 @override | 3678 @override |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4434 if (type is InterfaceType) { | 4441 if (type is InterfaceType) { |
| 4435 Element result = type.lookUpGetter(name, compilationUnit.library); | 4442 Element result = type.lookUpGetter(name, compilationUnit.library); |
| 4436 result ??= type.lookUpMethod(name, compilationUnit.library); | 4443 result ??= type.lookUpMethod(name, compilationUnit.library); |
| 4437 return result; | 4444 return result; |
| 4438 } | 4445 } |
| 4439 } | 4446 } |
| 4440 // TODO(scheglov): implement for propagated types | 4447 // TODO(scheglov): implement for propagated types |
| 4441 return null; | 4448 return null; |
| 4442 } | 4449 } |
| 4443 } | 4450 } |
| OLD | NEW |