Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: pkg/analyzer/lib/src/summary/link.dart

Issue 2196363003: Make analyzer strong-mode clean (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 * during linking. 340 * during linking.
341 */ 341 */
342 abstract class ClassElementForLink extends Object 342 abstract class ClassElementForLink extends Object
343 with ReferenceableElementForLink 343 with ReferenceableElementForLink
344 implements AbstractClassElementImpl { 344 implements AbstractClassElementImpl {
345 Map<String, ReferenceableElementForLink> _containedNames; 345 Map<String, ReferenceableElementForLink> _containedNames;
346 346
347 @override 347 @override
348 final CompilationUnitElementForLink enclosingElement; 348 final CompilationUnitElementForLink enclosingElement;
349 349
350 @override 350 /// TODO(brianwilkerson) This appears to be unused and might be removable.
351 bool hasBeenInferred; 351 bool hasBeenInferred;
352 352
353 ClassElementForLink(CompilationUnitElementForLink enclosingElement) 353 ClassElementForLink(CompilationUnitElementForLink enclosingElement)
354 : enclosingElement = enclosingElement, 354 : enclosingElement = enclosingElement,
355 hasBeenInferred = !enclosingElement.isInBuildUnit; 355 hasBeenInferred = !enclosingElement.isInBuildUnit;
356 356
357 @override 357 @override
358 List<PropertyAccessorElementForLink> get accessors; 358 List<PropertyAccessorElementForLink> get accessors;
359 359
360 @override 360 @override
361 ConstructorElementForLink get asConstructor => unnamedConstructor; 361 ConstructorElementForLink get asConstructor => unnamedConstructor;
362 362
363 @override 363 @override
364 DartType get asStaticType => 364 DartType get asStaticType =>
365 enclosingElement.enclosingElement._linker.typeProvider.typeType; 365 enclosingElement.enclosingElement._linker.typeProvider.typeType;
366 366
367 @override 367 @override
368 List<ConstructorElementForLink> get constructors; 368 List<ConstructorElementForLink> get constructors;
369 369
370 @override 370 @override
371 CompilationUnitElementForLink get enclosingUnit => enclosingElement; 371 CompilationUnitElementImpl get enclosingUnit => enclosingElement;
372 372
373 @override 373 @override
374 List<FieldElementForLink> get fields; 374 List<FieldElementForLink> get fields;
375 375
376 /** 376 /**
377 * Indicates whether this is the core class `Object`. 377 * Indicates whether this is the core class `Object`.
378 */ 378 */
379 bool get isObject; 379 bool get isObject;
380 380
381 @override 381 @override
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 564
565 @override 565 @override
566 InterfaceType get supertype { 566 InterfaceType get supertype {
567 if (isObject) { 567 if (isObject) {
568 return null; 568 return null;
569 } 569 }
570 return _supertype ??= _computeInterfaceType(_unlinkedClass.supertype); 570 return _supertype ??= _computeInterfaceType(_unlinkedClass.supertype);
571 } 571 }
572 572
573 @override 573 @override
574 DartType get type => 574 InterfaceType get type =>
575 _type ??= buildType((int i) => typeParameterTypes[i], null); 575 _type ??= buildType((int i) => typeParameterTypes[i], null);
576 576
577 @override 577 @override
578 List<UnlinkedTypeParam> get unlinkedTypeParams => 578 List<UnlinkedTypeParam> get unlinkedTypeParams =>
579 _unlinkedClass.typeParameters; 579 _unlinkedClass.typeParameters;
580 580
581 @override 581 @override
582 ConstructorElementForLink get unnamedConstructor { 582 ConstructorElementForLink get unnamedConstructor {
583 if (!_unnamedConstructorComputed) { 583 if (!_unnamedConstructorComputed) {
584 for (ConstructorElementForLink constructor in constructors) { 584 for (ConstructorElementForLink constructor in constructors) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 @override 733 @override
734 List<InterfaceType> get mixins => const []; 734 List<InterfaceType> get mixins => const [];
735 735
736 @override 736 @override
737 String get name => _unlinkedEnum.name; 737 String get name => _unlinkedEnum.name;
738 738
739 @override 739 @override
740 InterfaceType get supertype => library._linker.typeProvider.objectType; 740 InterfaceType get supertype => library._linker.typeProvider.objectType;
741 741
742 @override 742 @override
743 DartType get type => _type ??= new InterfaceTypeImpl(this); 743 InterfaceType get type => _type ??= new InterfaceTypeImpl(this);
744 744
745 @override 745 @override
746 List<TypeParameterElement> get typeParameters => const []; 746 List<TypeParameterElement> get typeParameters => const [];
747 747
748 @override 748 @override
749 ConstructorElementForLink get unnamedConstructor => null; 749 ConstructorElementForLink get unnamedConstructor => null;
750 750
751 /** 751 /**
752 * Get the type of the enum's static member `values`. 752 * Get the type of the enum's static member `values`.
753 */ 753 */
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 default: 1191 default:
1192 // TODO(paulberry): implement other cases as necessary 1192 // TODO(paulberry): implement other cases as necessary
1193 throw new UnimplementedError('${element._unlinkedExecutable.kind}'); 1193 throw new UnimplementedError('${element._unlinkedExecutable.kind}');
1194 } 1194 }
1195 return addRawReference(element.name, 1195 return addRawReference(element.name,
1196 numTypeParameters: element.typeParameters.length, 1196 numTypeParameters: element.typeParameters.length,
1197 containingReference: 1197 containingReference:
1198 enclosingClass != null ? addReference(enclosingClass) : null, 1198 enclosingClass != null ? addReference(enclosingClass) : null,
1199 dependency: enclosingClass != null 1199 dependency: enclosingClass != null
1200 ? null 1200 ? null
1201 : library.addDependency(element.library), 1201 : library.addDependency(element.library as LibraryElementForLink),
1202 kind: kind); 1202 kind: kind);
1203 } else if (element is FunctionElementForLink_Initializer) { 1203 } else if (element is FunctionElementForLink_Initializer) {
1204 return addRawReference('', 1204 return addRawReference('',
1205 containingReference: addReference(element.enclosingElement), 1205 containingReference: addReference(element.enclosingElement),
1206 kind: ReferenceKind.function); 1206 kind: ReferenceKind.function);
1207 } else if (element is TopLevelVariableElementForLink) { 1207 } else if (element is TopLevelVariableElementForLink) {
1208 return addRawReference(element.name, 1208 return addRawReference(element.name,
1209 dependency: library.addDependency(element.library), 1209 dependency: library.addDependency(element.library),
1210 kind: ReferenceKind.topLevelPropertyAccessor); 1210 kind: ReferenceKind.topLevelPropertyAccessor);
1211 } else if (element is FieldElementForLink_ClassField) { 1211 } else if (element is FieldElementForLink_ClassField) {
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1622 _unlinkedExecutable != null && 1622 _unlinkedExecutable != null &&
1623 _unlinkedExecutable.constCycleSlot != 0) { 1623 _unlinkedExecutable.constCycleSlot != 0) {
1624 _constNode = new ConstConstructorNode(this); 1624 _constNode = new ConstConstructorNode(this);
1625 } 1625 }
1626 } 1626 }
1627 1627
1628 @override 1628 @override
1629 ConstructorElementForLink get asConstructor => this; 1629 ConstructorElementForLink get asConstructor => this;
1630 1630
1631 @override 1631 @override
1632 ClassElementImpl get enclosingElement => super.enclosingClass;
1633
1634 @override
1632 bool get isCycleFree { 1635 bool get isCycleFree {
1633 if (!_constNode.isEvaluated) { 1636 if (!_constNode.isEvaluated) {
1634 new ConstDependencyWalker().walk(_constNode); 1637 new ConstDependencyWalker().walk(_constNode);
1635 } 1638 }
1636 return _constNode.isCycleFree; 1639 return _constNode.isCycleFree;
1637 } 1640 }
1638 1641
1639 /** 1642 /**
1640 * Perform const cycle detection on this constructor. 1643 * Perform const cycle detection on this constructor.
1641 */ 1644 */
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 * The unlinked representation of the method in the summary. 1848 * The unlinked representation of the method in the summary.
1846 */ 1849 */
1847 final UnlinkedExecutable _unlinkedExecutable; 1850 final UnlinkedExecutable _unlinkedExecutable;
1848 1851
1849 DartType _declaredReturnType; 1852 DartType _declaredReturnType;
1850 DartType _inferredReturnType; 1853 DartType _inferredReturnType;
1851 FunctionTypeImpl _type; 1854 FunctionTypeImpl _type;
1852 String _name; 1855 String _name;
1853 String _displayName; 1856 String _displayName;
1854 1857
1855 @override
1856 final CompilationUnitElementForLink compilationUnit; 1858 final CompilationUnitElementForLink compilationUnit;
1857 1859
1858 ExecutableElementForLink(this.compilationUnit, this._unlinkedExecutable); 1860 ExecutableElementForLink(this.compilationUnit, this._unlinkedExecutable);
1859 1861
1860 @override 1862 @override
1861 ContextForLink get context => compilationUnit.context; 1863 ContextForLink get context => compilationUnit.context;
1862 1864
1863 /** 1865 /**
1864 * If the executable element had an explicitly declared return type, return 1866 * If the executable element had an explicitly declared return type, return
1865 * it. Otherwise return `null`. 1867 * it. Otherwise return `null`.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 return _inferredReturnType; 1924 return _inferredReturnType;
1923 } 1925 }
1924 1926
1925 @override 1927 @override
1926 bool get isStatic => _unlinkedExecutable.isStatic; 1928 bool get isStatic => _unlinkedExecutable.isStatic;
1927 1929
1928 @override 1930 @override
1929 bool get isSynthetic => false; 1931 bool get isSynthetic => false;
1930 1932
1931 @override 1933 @override
1932 LibraryElementForLink get library => enclosingElement.library; 1934 LibraryElement get library => enclosingElement.library;
1933 1935
1934 @override 1936 @override
1935 String get name { 1937 String get name {
1936 if (_name == null) { 1938 if (_name == null) {
1937 _name = _unlinkedExecutable.name; 1939 _name = _unlinkedExecutable.name;
1938 if (_name == '-' && _unlinkedExecutable.parameters.isEmpty) { 1940 if (_name == '-' && _unlinkedExecutable.parameters.isEmpty) {
1939 _name = 'unary-'; 1941 _name = 'unary-';
1940 } 1942 }
1941 } 1943 }
1942 return _name; 1944 return _name;
(...skipping 25 matching lines...) Expand all
1968 bool isAccessibleIn(LibraryElement library) => 1970 bool isAccessibleIn(LibraryElement library) =>
1969 !Identifier.isPrivateName(name) || identical(this.library, library); 1971 !Identifier.isPrivateName(name) || identical(this.library, library);
1970 1972
1971 /** 1973 /**
1972 * Compute the default return type for this type of executable element (if no 1974 * Compute the default return type for this type of executable element (if no
1973 * return type is declared and strong mode type inference cannot infer a 1975 * return type is declared and strong mode type inference cannot infer a
1974 * better return type). 1976 * better return type).
1975 */ 1977 */
1976 DartType _computeDefaultReturnType() { 1978 DartType _computeDefaultReturnType() {
1977 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter && 1979 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter &&
1978 library._linker.strongMode) { 1980 (library as LibraryElementForLink)._linker.strongMode) {
1979 // In strong mode, setters without an explicit return type are 1981 // In strong mode, setters without an explicit return type are
1980 // considered to return `void`. 1982 // considered to return `void`.
1981 return VoidTypeImpl.instance; 1983 return VoidTypeImpl.instance;
1982 } else { 1984 } else {
1983 return DynamicTypeImpl.instance; 1985 return DynamicTypeImpl.instance;
1984 } 1986 }
1985 } 1987 }
1986 } 1988 }
1987 1989
1988 /** 1990 /**
(...skipping 1732 matching lines...) Expand 10 before | Expand all | Expand 10 after
3721 implements MethodElementImpl { 3723 implements MethodElementImpl {
3722 MethodElementForLink(ClassElementForLink_Class enclosingClass, 3724 MethodElementForLink(ClassElementForLink_Class enclosingClass,
3723 UnlinkedExecutable unlinkedExecutable) 3725 UnlinkedExecutable unlinkedExecutable)
3724 : super(enclosingClass.enclosingElement, enclosingClass, 3726 : super(enclosingClass.enclosingElement, enclosingClass,
3725 unlinkedExecutable); 3727 unlinkedExecutable);
3726 3728
3727 @override 3729 @override
3728 DartType get asStaticType => type; 3730 DartType get asStaticType => type;
3729 3731
3730 @override 3732 @override
3733 ClassElementImpl get enclosingElement => super.enclosingClass;
3734
3735 @override
3731 String get identifier => name; 3736 String get identifier => name;
3732 3737
3733 @override 3738 @override
3734 ElementKind get kind => ElementKind.METHOD; 3739 ElementKind get kind => ElementKind.METHOD;
3735 3740
3736 @override 3741 @override
3737 FunctionElementForLink_Local getLocalFunction(int index) { 3742 FunctionElementForLink_Local getLocalFunction(int index) {
3738 // TODO(paulberry): implement. 3743 // TODO(paulberry): implement.
3739 return null; 3744 return null;
3740 } 3745 }
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
3991 DartType get type => enclosingElement.computeVariableType(); 3996 DartType get type => enclosingElement.computeVariableType();
3992 3997
3993 @override 3998 @override
3994 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 3999 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3995 } 4000 }
3996 4001
3997 /** 4002 /**
3998 * Mixin used by elements that can have parameters. 4003 * Mixin used by elements that can have parameters.
3999 */ 4004 */
4000 abstract class ParameterParentElementForLink implements Element { 4005 abstract class ParameterParentElementForLink implements Element {
4001 List<ParameterElementForLink> _parameters; 4006 List<ParameterElement> _parameters;
4002 4007
4003 /** 4008 /**
4004 * Get the appropriate integer list to store in 4009 * Get the appropriate integer list to store in
4005 * [EntityRef.implicitFunctionTypeIndices] to refer to this element. For an 4010 * [EntityRef.implicitFunctionTypeIndices] to refer to this element. For an
4006 * element representing a function-typed parameter, this should return a 4011 * element representing a function-typed parameter, this should return a
4007 * non-empty list. For an element representing an executable, this should 4012 * non-empty list. For an element representing an executable, this should
4008 * return the empty list. 4013 * return the empty list.
4009 */ 4014 */
4010 List<int> get implicitFunctionTypeIndices; 4015 List<int> get implicitFunctionTypeIndices;
4011 4016
4012 /** 4017 /**
4013 * Get all the parameters of this element. 4018 * Get all the parameters of this element.
4014 */ 4019 */
4015 List<ParameterElementForLink> get parameters { 4020 List<ParameterElement> get parameters {
4016 if (_parameters == null) { 4021 if (_parameters == null) {
4017 List<UnlinkedParam> unlinkedParameters = this.unlinkedParameters; 4022 List<UnlinkedParam> unlinkedParameters = this.unlinkedParameters;
4018 int numParameters = unlinkedParameters.length; 4023 int numParameters = unlinkedParameters.length;
4019 _parameters = new List<ParameterElementForLink>(numParameters); 4024 _parameters = new List<ParameterElement>(numParameters);
4020 for (int i = 0; i < numParameters; i++) { 4025 for (int i = 0; i < numParameters; i++) {
4021 UnlinkedParam unlinkedParam = unlinkedParameters[i]; 4026 UnlinkedParam unlinkedParam = unlinkedParameters[i];
4022 _parameters[i] = new ParameterElementForLink( 4027 _parameters[i] = new ParameterElementForLink(
4023 this, 4028 this,
4024 unlinkedParam, 4029 unlinkedParam,
4025 typeParameterContext, 4030 typeParameterContext,
4026 typeParameterContext.enclosingUnit.resynthesizerContext 4031 typeParameterContext.enclosingUnit.resynthesizerContext
4027 as CompilationUnitElementForLink, 4032 as CompilationUnitElementForLink,
4028 i); 4033 i);
4029 } 4034 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
4135 4140
4136 /** 4141 /**
4137 * Specialization of [PropertyAccessorElementForLink] for non-synthetic 4142 * Specialization of [PropertyAccessorElementForLink] for non-synthetic
4138 * accessors explicitly declared in the source code. 4143 * accessors explicitly declared in the source code.
4139 */ 4144 */
4140 class PropertyAccessorElementForLink_Executable 4145 class PropertyAccessorElementForLink_Executable
4141 extends ExecutableElementForLink_NonLocal 4146 extends ExecutableElementForLink_NonLocal
4142 with ReferenceableElementForLink 4147 with ReferenceableElementForLink
4143 implements PropertyAccessorElementForLink { 4148 implements PropertyAccessorElementForLink {
4144 @override 4149 @override
4145 SyntheticVariableElementForLink variable; 4150 PropertyInducingElement variable;
4146 4151
4147 PropertyAccessorElementForLink_Executable( 4152 PropertyAccessorElementForLink_Executable(
4148 CompilationUnitElementForLink enclosingUnit, 4153 CompilationUnitElementForLink enclosingUnit,
4149 ClassElementForLink_Class enclosingClass, 4154 ClassElementForLink_Class enclosingClass,
4150 UnlinkedExecutable unlinkedExecutable, 4155 UnlinkedExecutable unlinkedExecutable,
4151 this.variable) 4156 this.variable)
4152 : super(enclosingUnit, enclosingClass, unlinkedExecutable); 4157 : super(enclosingUnit, enclosingClass, unlinkedExecutable);
4153 4158
4154 @override 4159 @override
4155 DartType get asStaticType => returnType; 4160 DartType get asStaticType => returnType;
(...skipping 12 matching lines...) Expand all
4168 4173
4169 @override 4174 @override
4170 bool get isStatic => enclosingClass == null || super.isStatic; 4175 bool get isStatic => enclosingClass == null || super.isStatic;
4171 4176
4172 @override 4177 @override
4173 ElementKind get kind => _unlinkedExecutable.kind == 4178 ElementKind get kind => _unlinkedExecutable.kind ==
4174 UnlinkedExecutableKind.getter ? ElementKind.GETTER : ElementKind.SETTER; 4179 UnlinkedExecutableKind.getter ? ElementKind.GETTER : ElementKind.SETTER;
4175 4180
4176 @override 4181 @override
4177 ReferenceableElementForLink getContainedName(String name) { 4182 ReferenceableElementForLink getContainedName(String name) {
4178 return new NonstaticMemberElementForLink(library, this, name); 4183 return new NonstaticMemberElementForLink(
4184 library as LibraryElementForLink, this, name);
4179 } 4185 }
4180 4186
4181 @override 4187 @override
4182 FunctionElementForLink_Local getLocalFunction(int index) { 4188 FunctionElementForLink_Local getLocalFunction(int index) {
4183 // TODO(paulberry): implement 4189 // TODO(paulberry): implement
4184 return null; 4190 return null;
4185 } 4191 }
4186 4192
4187 @override 4193 @override
4188 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 4194 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
4956 * there are no type parameters in scope. 4962 * there are no type parameters in scope.
4957 */ 4963 */
4958 TypeParameterizedElementMixin get _typeParameterContext; 4964 TypeParameterizedElementMixin get _typeParameterContext;
4959 4965
4960 @override 4966 @override
4961 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 4967 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
4962 4968
4963 @override 4969 @override
4964 String toString() => '$enclosingElement.$name'; 4970 String toString() => '$enclosingElement.$name';
4965 } 4971 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/type_system.dart ('k') | pkg/analyzer/lib/src/summary/summarize_ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698