| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 /** | 124 /** |
| 125 * Create an [EntityRefBuilder] representing the given [type], in a form | 125 * Create an [EntityRefBuilder] representing the given [type], in a form |
| 126 * suitable for inclusion in [LinkedUnit.types]. [compilationUnit] is the | 126 * suitable for inclusion in [LinkedUnit.types]. [compilationUnit] is the |
| 127 * compilation unit in which the type will be used. If [slot] is provided, it | 127 * compilation unit in which the type will be used. If [slot] is provided, it |
| 128 * is stored in [EntityRefBuilder.slot]. | 128 * is stored in [EntityRefBuilder.slot]. |
| 129 */ | 129 */ |
| 130 EntityRefBuilder _createLinkedType( | 130 EntityRefBuilder _createLinkedType( |
| 131 DartType type, | 131 DartType type, |
| 132 CompilationUnitElementInBuildUnit compilationUnit, | 132 CompilationUnitElementInBuildUnit compilationUnit, |
| 133 TypeParameterContext typeParameterContext, | 133 TypeParameterizedElementForLink typeParameterContext, |
| 134 {int slot}) { | 134 {int slot}) { |
| 135 EntityRefBuilder result = new EntityRefBuilder(slot: slot); | 135 EntityRefBuilder result = new EntityRefBuilder(slot: slot); |
| 136 if (type is InterfaceType) { | 136 if (type is InterfaceType) { |
| 137 ClassElementForLink element = type.element; | 137 ClassElementForLink element = type.element; |
| 138 result.reference = compilationUnit.addReference(element); | 138 result.reference = compilationUnit.addReference(element); |
| 139 if (type.typeArguments.isNotEmpty) { | 139 if (type.typeArguments.isNotEmpty) { |
| 140 result.typeArguments = type.typeArguments | 140 result.typeArguments = type.typeArguments |
| 141 .map((DartType t) => | 141 .map((DartType t) => |
| 142 _createLinkedType(t, compilationUnit, typeParameterContext)) | 142 _createLinkedType(t, compilationUnit, typeParameterContext)) |
| 143 .toList(); | 143 .toList(); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 } | 339 } |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 return _constructors; | 342 return _constructors; |
| 343 } | 343 } |
| 344 | 344 |
| 345 @override | 345 @override |
| 346 String get displayName => _unlinkedClass.name; | 346 String get displayName => _unlinkedClass.name; |
| 347 | 347 |
| 348 @override | 348 @override |
| 349 TypeParameterContext get enclosingTypeParameterContext => null; | 349 TypeParameterizedElementForLink get enclosingTypeParameterContext => null; |
| 350 | 350 |
| 351 @override | 351 @override |
| 352 List<FieldElementForLink_ClassField> get fields { | 352 List<FieldElementForLink_ClassField> get fields { |
| 353 if (_fields == null) { | 353 if (_fields == null) { |
| 354 _fields = <FieldElementForLink_ClassField>[]; | 354 _fields = <FieldElementForLink_ClassField>[]; |
| 355 for (UnlinkedVariable field in _unlinkedClass.fields) { | 355 for (UnlinkedVariable field in _unlinkedClass.fields) { |
| 356 _fields.add(new FieldElementForLink_ClassField(this, field)); | 356 _fields.add(new FieldElementForLink_ClassField(this, field)); |
| 357 } | 357 } |
| 358 } | 358 } |
| 359 return _fields; | 359 return _fields; |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 } | 701 } |
| 702 | 702 |
| 703 /** | 703 /** |
| 704 * Resolve an [EntityRef] into a type. If the reference is | 704 * Resolve an [EntityRef] into a type. If the reference is |
| 705 * unresolved, return [DynamicTypeImpl.instance]. | 705 * unresolved, return [DynamicTypeImpl.instance]. |
| 706 * | 706 * |
| 707 * TODO(paulberry): or should we have a class representing an | 707 * TODO(paulberry): or should we have a class representing an |
| 708 * unresolved type, for consistency with the full element model? | 708 * unresolved type, for consistency with the full element model? |
| 709 */ | 709 */ |
| 710 DartType _resolveTypeRef( | 710 DartType _resolveTypeRef( |
| 711 EntityRef type, TypeParameterContext typeParameterContext, | 711 EntityRef type, TypeParameterizedElementForLink typeParameterContext, |
| 712 {bool defaultVoid: false}) { | 712 {bool defaultVoid: false}) { |
| 713 if (type == null) { | 713 if (type == null) { |
| 714 if (defaultVoid) { | 714 if (defaultVoid) { |
| 715 return VoidTypeImpl.instance; | 715 return VoidTypeImpl.instance; |
| 716 } else { | 716 } else { |
| 717 return DynamicTypeImpl.instance; | 717 return DynamicTypeImpl.instance; |
| 718 } | 718 } |
| 719 } | 719 } |
| 720 if (type.paramReference != 0) { | 720 if (type.paramReference != 0) { |
| 721 return typeParameterContext.getTypeParameterType(type.paramReference); | 721 return typeParameterContext.getTypeParameterType(type.paramReference); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 */ | 869 */ |
| 870 void _storeConstCycle(int slot) { | 870 void _storeConstCycle(int slot) { |
| 871 _linkedUnit.constCycles.add(slot); | 871 _linkedUnit.constCycles.add(slot); |
| 872 } | 872 } |
| 873 | 873 |
| 874 /** | 874 /** |
| 875 * Store the given [linkedType] in the given [slot] of the this compilation | 875 * Store the given [linkedType] in the given [slot] of the this compilation |
| 876 * unit's linked type list. | 876 * unit's linked type list. |
| 877 */ | 877 */ |
| 878 void _storeLinkedType(int slot, DartType linkedType, | 878 void _storeLinkedType(int slot, DartType linkedType, |
| 879 TypeParameterContext typeParameterContext) { | 879 TypeParameterizedElementForLink typeParameterContext) { |
| 880 if (slot != 0) { | 880 if (slot != 0) { |
| 881 if (linkedType != null && !linkedType.isDynamic) { | 881 if (linkedType != null && !linkedType.isDynamic) { |
| 882 _linkedUnit.types.add(_createLinkedType( | 882 _linkedUnit.types.add(_createLinkedType( |
| 883 linkedType, this, typeParameterContext, | 883 linkedType, this, typeParameterContext, |
| 884 slot: slot)); | 884 slot: slot)); |
| 885 } | 885 } |
| 886 } | 886 } |
| 887 } | 887 } |
| 888 } | 888 } |
| 889 | 889 |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 strongConnect(startingPoint); | 1333 strongConnect(startingPoint); |
| 1334 } | 1334 } |
| 1335 } | 1335 } |
| 1336 | 1336 |
| 1337 /** | 1337 /** |
| 1338 * Base class for executable elements resynthesized from a summary during | 1338 * Base class for executable elements resynthesized from a summary during |
| 1339 * linking. | 1339 * linking. |
| 1340 */ | 1340 */ |
| 1341 abstract class ExecutableElementForLink extends Object | 1341 abstract class ExecutableElementForLink extends Object |
| 1342 with TypeParameterizedElementForLink | 1342 with TypeParameterizedElementForLink |
| 1343 implements ExecutableElementImpl, TypeParameterContext { | 1343 implements ExecutableElementImpl { |
| 1344 /** | 1344 /** |
| 1345 * The unlinked representation of the method in the summary. | 1345 * The unlinked representation of the method in the summary. |
| 1346 */ | 1346 */ |
| 1347 final UnlinkedExecutable _unlinkedExecutable; | 1347 final UnlinkedExecutable _unlinkedExecutable; |
| 1348 | 1348 |
| 1349 DartType _declaredReturnType; | 1349 DartType _declaredReturnType; |
| 1350 DartType _inferredReturnType; | 1350 DartType _inferredReturnType; |
| 1351 FunctionTypeImpl _type; | 1351 FunctionTypeImpl _type; |
| 1352 List<TypeParameterElementForLink> _typeParameters; | 1352 List<TypeParameterElementForLink> _typeParameters; |
| 1353 List<ParameterElementForLink> _parameters; | 1353 List<ParameterElementForLink> _parameters; |
| 1354 | 1354 |
| 1355 /** | 1355 /** |
| 1356 * TODO(paulberry): this won't always be a class element. | 1356 * TODO(paulberry): this won't always be a class element. |
| 1357 */ | 1357 */ |
| 1358 @override | 1358 @override |
| 1359 final ClassElementForLink_Class enclosingElement; | 1359 final ClassElementForLink_Class enclosingElement; |
| 1360 | 1360 |
| 1361 ExecutableElementForLink(this.enclosingElement, this._unlinkedExecutable); | 1361 ExecutableElementForLink(this.enclosingElement, this._unlinkedExecutable); |
| 1362 | 1362 |
| 1363 @override | 1363 @override |
| 1364 TypeParameterContext get enclosingTypeParameterContext => enclosingElement; | 1364 TypeParameterizedElementForLink get enclosingTypeParameterContext => |
| 1365 enclosingElement; |
| 1365 | 1366 |
| 1366 @override | 1367 @override |
| 1367 bool get hasImplicitReturnType => _unlinkedExecutable.returnType == null; | 1368 bool get hasImplicitReturnType => _unlinkedExecutable.returnType == null; |
| 1368 | 1369 |
| 1369 @override | 1370 @override |
| 1370 bool get isStatic => _unlinkedExecutable.isStatic; | 1371 bool get isStatic => _unlinkedExecutable.isStatic; |
| 1371 | 1372 |
| 1372 @override | 1373 @override |
| 1373 bool get isSynthetic => false; | 1374 bool get isSynthetic => false; |
| 1374 | 1375 |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1903 */ | 1904 */ |
| 1904 class ParameterElementForLink implements ParameterElementImpl { | 1905 class ParameterElementForLink implements ParameterElementImpl { |
| 1905 /** | 1906 /** |
| 1906 * The unlinked representation of the parameter in the summary. | 1907 * The unlinked representation of the parameter in the summary. |
| 1907 */ | 1908 */ |
| 1908 final UnlinkedParam _unlinkedParam; | 1909 final UnlinkedParam _unlinkedParam; |
| 1909 | 1910 |
| 1910 /** | 1911 /** |
| 1911 * The context in which type parameters should be interpreted. | 1912 * The context in which type parameters should be interpreted. |
| 1912 */ | 1913 */ |
| 1913 final TypeParameterContext _typeParameterContext; | 1914 final TypeParameterizedElementForLink _typeParameterContext; |
| 1914 | 1915 |
| 1915 /** | 1916 /** |
| 1916 * If this parameter has a default value and the enclosing library | 1917 * If this parameter has a default value and the enclosing library |
| 1917 * is part of the build unit being linked, the parameter's node in | 1918 * is part of the build unit being linked, the parameter's node in |
| 1918 * the constant evaluation dependency graph. Otherwise `null`. | 1919 * the constant evaluation dependency graph. Otherwise `null`. |
| 1919 */ | 1920 */ |
| 1920 ConstNode _constNode; | 1921 ConstNode _constNode; |
| 1921 | 1922 |
| 1922 /** | 1923 /** |
| 1923 * The compilation unit in which this parameter appears. | 1924 * The compilation unit in which this parameter appears. |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2105 implements TopLevelVariableElement { | 2106 implements TopLevelVariableElement { |
| 2106 TopLevelVariableElementForLink(CompilationUnitElement enclosingElement, | 2107 TopLevelVariableElementForLink(CompilationUnitElement enclosingElement, |
| 2107 UnlinkedVariable unlinkedVariable) | 2108 UnlinkedVariable unlinkedVariable) |
| 2108 : super(unlinkedVariable, enclosingElement); | 2109 : super(unlinkedVariable, enclosingElement); |
| 2109 | 2110 |
| 2110 @override | 2111 @override |
| 2111 bool get isStatic => true; | 2112 bool get isStatic => true; |
| 2112 } | 2113 } |
| 2113 | 2114 |
| 2114 /** | 2115 /** |
| 2115 * Interface representing elements which can serve as the context within which | |
| 2116 * type parameter indices are interpreted. | |
| 2117 */ | |
| 2118 abstract class TypeParameterContext { | |
| 2119 /** | |
| 2120 * Find out how many type parameters are in scope in this context. | |
| 2121 */ | |
| 2122 int get typeParameterNestingLevel; | |
| 2123 | |
| 2124 /** | |
| 2125 * Convert the given [index] into a type parameter type. | |
| 2126 */ | |
| 2127 TypeParameterType getTypeParameterType(int index); | |
| 2128 } | |
| 2129 | |
| 2130 /** | |
| 2131 * Element representing a type parameter resynthesized from a summary during | 2116 * Element representing a type parameter resynthesized from a summary during |
| 2132 * linking. | 2117 * linking. |
| 2133 */ | 2118 */ |
| 2134 class TypeParameterElementForLink implements TypeParameterElement { | 2119 class TypeParameterElementForLink implements TypeParameterElement { |
| 2135 /** | 2120 /** |
| 2136 * The unlinked representation of the type parameter in the summary. | 2121 * The unlinked representation of the type parameter in the summary. |
| 2137 */ | 2122 */ |
| 2138 final UnlinkedTypeParam _unlinkedTypeParam; | 2123 final UnlinkedTypeParam _unlinkedTypeParam; |
| 2139 | 2124 |
| 2140 /** | 2125 /** |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2154 TypeParameterTypeImpl get type => _type ??= new TypeParameterTypeImpl(this); | 2139 TypeParameterTypeImpl get type => _type ??= new TypeParameterTypeImpl(this); |
| 2155 | 2140 |
| 2156 @override | 2141 @override |
| 2157 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 2142 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 2158 } | 2143 } |
| 2159 | 2144 |
| 2160 /** | 2145 /** |
| 2161 * Mixin representing an element which can have type parameters. | 2146 * Mixin representing an element which can have type parameters. |
| 2162 */ | 2147 */ |
| 2163 abstract class TypeParameterizedElementForLink | 2148 abstract class TypeParameterizedElementForLink |
| 2164 implements TypeParameterizedElement, TypeParameterContext { | 2149 implements TypeParameterizedElement { |
| 2165 List<TypeParameterType> _typeParameterTypes; | 2150 List<TypeParameterType> _typeParameterTypes; |
| 2166 List<TypeParameterElementForLink> _typeParameters; | 2151 List<TypeParameterElementForLink> _typeParameters; |
| 2167 int _nestingLevel; | 2152 int _nestingLevel; |
| 2168 | 2153 |
| 2169 /** | 2154 /** |
| 2170 * Get the type parameter context enclosing this one, if any. | 2155 * Get the type parameter context enclosing this one, if any. |
| 2171 */ | 2156 */ |
| 2172 TypeParameterContext get enclosingTypeParameterContext; | 2157 TypeParameterizedElementForLink get enclosingTypeParameterContext; |
| 2173 | 2158 |
| 2174 @override | 2159 /** |
| 2160 * Find out how many type parameters are in scope in this context. |
| 2161 */ |
| 2175 int get typeParameterNestingLevel => | 2162 int get typeParameterNestingLevel => |
| 2176 _nestingLevel ??= _unlinkedTypeParams.length + | 2163 _nestingLevel ??= _unlinkedTypeParams.length + |
| 2177 (enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0); | 2164 (enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0); |
| 2178 | 2165 |
| 2179 List<TypeParameterElementForLink> get typeParameters { | 2166 List<TypeParameterElementForLink> get typeParameters { |
| 2180 if (_typeParameters == null) { | 2167 if (_typeParameters == null) { |
| 2181 int enclosingNestingLevel = | 2168 int enclosingNestingLevel = |
| 2182 enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0; | 2169 enclosingTypeParameterContext?.typeParameterNestingLevel ?? 0; |
| 2183 int numTypeParameters = _unlinkedTypeParams.length; | 2170 int numTypeParameters = _unlinkedTypeParams.length; |
| 2184 _typeParameters = | 2171 _typeParameters = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2203 } | 2190 } |
| 2204 return _typeParameterTypes; | 2191 return _typeParameterTypes; |
| 2205 } | 2192 } |
| 2206 | 2193 |
| 2207 /** | 2194 /** |
| 2208 * Get the [UnlinkedTypeParam]s representing the type parameters declared by | 2195 * Get the [UnlinkedTypeParam]s representing the type parameters declared by |
| 2209 * this element. | 2196 * this element. |
| 2210 */ | 2197 */ |
| 2211 List<UnlinkedTypeParam> get _unlinkedTypeParams; | 2198 List<UnlinkedTypeParam> get _unlinkedTypeParams; |
| 2212 | 2199 |
| 2213 @override | 2200 /** |
| 2201 * Convert the given [index] into a type parameter type. |
| 2202 */ |
| 2214 TypeParameterType getTypeParameterType(int index) { | 2203 TypeParameterType getTypeParameterType(int index) { |
| 2215 List<TypeParameterType> types = typeParameterTypes; | 2204 List<TypeParameterType> types = typeParameterTypes; |
| 2216 if (index <= types.length) { | 2205 if (index <= types.length) { |
| 2217 return types[types.length - index]; | 2206 return types[types.length - index]; |
| 2218 } else if (enclosingTypeParameterContext != null) { | 2207 } else if (enclosingTypeParameterContext != null) { |
| 2219 return enclosingTypeParameterContext | 2208 return enclosingTypeParameterContext |
| 2220 .getTypeParameterType(index - types.length); | 2209 .getTypeParameterType(index - types.length); |
| 2221 } else { | 2210 } else { |
| 2222 // If we get here, it means that a summary contained a type parameter inde
x | 2211 // If we get here, it means that a summary contained a type parameter inde
x |
| 2223 // that was out of range. | 2212 // that was out of range. |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2563 | 2552 |
| 2564 /** | 2553 /** |
| 2565 * Throw away any information produced by a previous call to [link]. | 2554 * Throw away any information produced by a previous call to [link]. |
| 2566 */ | 2555 */ |
| 2567 void unlink() { | 2556 void unlink() { |
| 2568 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { | 2557 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { |
| 2569 library.unlink(); | 2558 library.unlink(); |
| 2570 } | 2559 } |
| 2571 } | 2560 } |
| 2572 } | 2561 } |
| OLD | NEW |