| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 _storeTypeArguments( | 211 _storeTypeArguments( |
| 212 type.typeArguments, result, compilationUnit, typeParameterContext); | 212 type.typeArguments, result, compilationUnit, typeParameterContext); |
| 213 return result; | 213 return result; |
| 214 } | 214 } |
| 215 if (element is FunctionTypeAliasElementForLink) { | 215 if (element is FunctionTypeAliasElementForLink) { |
| 216 result.reference = compilationUnit.addReference(element); | 216 result.reference = compilationUnit.addReference(element); |
| 217 _storeTypeArguments( | 217 _storeTypeArguments( |
| 218 type.typeArguments, result, compilationUnit, typeParameterContext); | 218 type.typeArguments, result, compilationUnit, typeParameterContext); |
| 219 return result; | 219 return result; |
| 220 } | 220 } |
| 221 if (element is FunctionElement) { |
| 222 // Element is a FunctionElement but not a TopLevelFunctionElementForLink |
| 223 // or a MethodElementForLink. This means that it's a synthetic function |
| 224 // element that was generated on the fly to represent a type that has no |
| 225 // associated source code location. |
| 226 assert(element.enclosingElement == null); |
| 227 result.syntheticReturnType = _createLinkedType( |
| 228 element.returnType, compilationUnit, typeParameterContext); |
| 229 result.syntheticParams = element.parameters |
| 230 .map((ParameterElement param) => _serializeSyntheticParam( |
| 231 param, compilationUnit, typeParameterContext)) |
| 232 .toList(); |
| 233 return result; |
| 234 } |
| 221 // TODO(paulberry): implement other cases. | 235 // TODO(paulberry): implement other cases. |
| 222 throw new UnimplementedError('${element.runtimeType}'); | 236 throw new UnimplementedError('${element.runtimeType}'); |
| 223 } | 237 } |
| 224 // TODO(paulberry): implement other cases. | 238 // TODO(paulberry): implement other cases. |
| 225 throw new UnimplementedError('${type.runtimeType}'); | 239 throw new UnimplementedError('${type.runtimeType}'); |
| 226 } | 240 } |
| 227 | 241 |
| 228 /** | 242 /** |
| 243 * Create an [UnlinkedParam] representing the given [parameter], which should be |
| 244 * a parameter of a synthetic function type (e.g. one produced during type |
| 245 * inference as a result of computing the least upper bound of two function |
| 246 * types). |
| 247 */ |
| 248 UnlinkedParamBuilder _serializeSyntheticParam( |
| 249 ParameterElement parameter, |
| 250 CompilationUnitElementInBuildUnit compilationUnit, |
| 251 TypeParameterizedElementForLink typeParameterContext) { |
| 252 UnlinkedParamBuilder b = new UnlinkedParamBuilder(); |
| 253 b.name = parameter.name; |
| 254 switch (parameter.parameterKind) { |
| 255 case ParameterKind.REQUIRED: |
| 256 b.kind = UnlinkedParamKind.required; |
| 257 break; |
| 258 case ParameterKind.POSITIONAL: |
| 259 b.kind = UnlinkedParamKind.positional; |
| 260 break; |
| 261 case ParameterKind.NAMED: |
| 262 b.kind = UnlinkedParamKind.named; |
| 263 break; |
| 264 } |
| 265 DartType type = parameter.type; |
| 266 if (!parameter.hasImplicitType) { |
| 267 if (type is FunctionType && type.element.isSynthetic) { |
| 268 b.isFunctionTyped = true; |
| 269 b.type = _createLinkedType( |
| 270 type.returnType, compilationUnit, typeParameterContext); |
| 271 b.parameters = type.parameters |
| 272 .map((parameter) => _serializeSyntheticParam( |
| 273 parameter, compilationUnit, typeParameterContext)) |
| 274 .toList(); |
| 275 } else { |
| 276 b.type = _createLinkedType(type, compilationUnit, typeParameterContext); |
| 277 } |
| 278 } |
| 279 return b; |
| 280 } |
| 281 |
| 282 /** |
| 229 * Store the given [typeArguments] in [encodedType], using [compilationUnit] and | 283 * Store the given [typeArguments] in [encodedType], using [compilationUnit] and |
| 230 * [typeParameterContext] to serialize them. | 284 * [typeParameterContext] to serialize them. |
| 231 */ | 285 */ |
| 232 void _storeTypeArguments( | 286 void _storeTypeArguments( |
| 233 List<DartType> typeArguments, | 287 List<DartType> typeArguments, |
| 234 EntityRefBuilder encodedType, | 288 EntityRefBuilder encodedType, |
| 235 CompilationUnitElementInBuildUnit compilationUnit, | 289 CompilationUnitElementInBuildUnit compilationUnit, |
| 236 TypeParameterizedElementForLink typeParameterContext) { | 290 TypeParameterizedElementForLink typeParameterContext) { |
| 237 int count = typeArguments.length; | 291 int count = typeArguments.length; |
| 238 List<EntityRefBuilder> encodedTypeArguments = | 292 List<EntityRefBuilder> encodedTypeArguments = |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 357 |
| 304 /** | 358 /** |
| 305 * Indicates whether this is the core class `Object`. | 359 * Indicates whether this is the core class `Object`. |
| 306 */ | 360 */ |
| 307 bool get isObject; | 361 bool get isObject; |
| 308 | 362 |
| 309 @override | 363 @override |
| 310 LibraryElementForLink get library => enclosingElement.library; | 364 LibraryElementForLink get library => enclosingElement.library; |
| 311 | 365 |
| 312 @override | 366 @override |
| 367 List<MethodElementForLink> get methods; |
| 368 |
| 369 @override |
| 313 String get name; | 370 String get name; |
| 314 | 371 |
| 315 @override | 372 @override |
| 316 ConstructorElementForLink get unnamedConstructor; | 373 ConstructorElementForLink get unnamedConstructor; |
| 317 | 374 |
| 318 @override | 375 @override |
| 319 ReferenceableElementForLink getContainedName(String name) { | 376 ReferenceableElementForLink getContainedName(String name) { |
| 320 if (_containedNames == null) { | 377 if (_containedNames == null) { |
| 321 _containedNames = <String, ReferenceableElementForLink>{}; | 378 _containedNames = <String, ReferenceableElementForLink>{}; |
| 322 // TODO(paulberry): what's the correct way to handle name conflicts? | 379 // TODO(paulberry): what's the correct way to handle name conflicts? |
| 323 for (ConstructorElementForLink constructor in constructors) { | 380 for (ConstructorElementForLink constructor in constructors) { |
| 324 _containedNames[constructor.name] = constructor; | 381 _containedNames[constructor.name] = constructor; |
| 325 } | 382 } |
| 326 for (PropertyAccessorElementForLink accessor in accessors) { | 383 for (PropertyAccessorElementForLink accessor in accessors) { |
| 327 if (accessor.isStatic) { | 384 if (accessor.isStatic) { |
| 328 _containedNames[accessor.name] = accessor; | 385 _containedNames[accessor.name] = accessor; |
| 329 } | 386 } |
| 330 } | 387 } |
| 331 // TODO(paulberry): add methods. | 388 for (MethodElementForLink method in methods) { |
| 389 if (method.isStatic) { |
| 390 _containedNames[method.name] = method; |
| 391 } |
| 392 } |
| 332 } | 393 } |
| 333 return _containedNames.putIfAbsent( | 394 return _containedNames.putIfAbsent( |
| 334 name, () => UndefinedElementForLink.instance); | 395 name, () => UndefinedElementForLink.instance); |
| 335 } | 396 } |
| 336 | 397 |
| 337 /** | 398 /** |
| 338 * Perform type inference and cycle detection on this class and | 399 * Perform type inference and cycle detection on this class and |
| 339 * store the resulting information in [compilationUnit]. | 400 * store the resulting information in [compilationUnit]. |
| 340 */ | 401 */ |
| 341 void link(CompilationUnitElementInBuildUnit compilationUnit); | 402 void link(CompilationUnitElementInBuildUnit compilationUnit); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 return _fields; | 693 return _fields; |
| 633 } | 694 } |
| 634 | 695 |
| 635 @override | 696 @override |
| 636 List<InterfaceType> get interfaces => const []; | 697 List<InterfaceType> get interfaces => const []; |
| 637 | 698 |
| 638 @override | 699 @override |
| 639 bool get isObject => false; | 700 bool get isObject => false; |
| 640 | 701 |
| 641 @override | 702 @override |
| 642 List<MethodElement> get methods => const []; | 703 List<MethodElementForLink> get methods => const []; |
| 643 | 704 |
| 644 @override | 705 @override |
| 645 List<InterfaceType> get mixins => const []; | 706 List<InterfaceType> get mixins => const []; |
| 646 | 707 |
| 647 @override | 708 @override |
| 648 String get name => _unlinkedEnum.name; | 709 String get name => _unlinkedEnum.name; |
| 649 | 710 |
| 650 @override | 711 @override |
| 651 InterfaceType get supertype => library._linker.typeProvider.objectType; | 712 InterfaceType get supertype => library._linker.typeProvider.objectType; |
| 652 | 713 |
| (...skipping 2610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3263 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { | 3324 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { |
| 3264 library.unlink(); | 3325 library.unlink(); |
| 3265 } | 3326 } |
| 3266 } | 3327 } |
| 3267 } | 3328 } |
| 3268 | 3329 |
| 3269 /** | 3330 /** |
| 3270 * Element representing a method resynthesized from a summary during linking. | 3331 * Element representing a method resynthesized from a summary during linking. |
| 3271 */ | 3332 */ |
| 3272 class MethodElementForLink extends ExecutableElementForLink | 3333 class MethodElementForLink extends ExecutableElementForLink |
| 3273 implements MethodElementImpl { | 3334 implements MethodElementImpl, ReferenceableElementForLink { |
| 3274 MethodElementForLink(ClassElementForLink_Class enclosingClass, | 3335 MethodElementForLink(ClassElementForLink_Class enclosingClass, |
| 3275 UnlinkedExecutable unlinkedExecutable) | 3336 UnlinkedExecutable unlinkedExecutable) |
| 3276 : super(enclosingClass.enclosingElement, enclosingClass, | 3337 : super(enclosingClass.enclosingElement, enclosingClass, |
| 3277 unlinkedExecutable); | 3338 unlinkedExecutable); |
| 3278 | 3339 |
| 3279 @override | 3340 @override |
| 3341 ConstructorElementForLink get asConstructor => null; |
| 3342 |
| 3343 @override |
| 3344 ConstVariableNode get asConstVariable => null; |
| 3345 |
| 3346 @override |
| 3347 DartType get asStaticType => type; |
| 3348 |
| 3349 @override |
| 3350 TypeInferenceNode get asTypeInferenceNode => null; |
| 3351 |
| 3352 @override |
| 3280 String get identifier => name; | 3353 String get identifier => name; |
| 3281 | 3354 |
| 3282 @override | 3355 @override |
| 3283 ElementKind get kind => ElementKind.METHOD; | 3356 ElementKind get kind => ElementKind.METHOD; |
| 3284 | 3357 |
| 3285 @override | 3358 @override |
| 3359 DartType buildType(DartType getTypeArgument(int i), |
| 3360 List<int> implicitFunctionTypeIndices) => |
| 3361 DynamicTypeImpl.instance; |
| 3362 |
| 3363 @override |
| 3364 ReferenceableElementForLink getContainedName(String name) { |
| 3365 // TODO(paulberry): handle references to `call`. |
| 3366 return UndefinedElementForLink.instance; |
| 3367 } |
| 3368 |
| 3369 @override |
| 3286 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 3370 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 3287 | 3371 |
| 3288 @override | 3372 @override |
| 3289 String toString() => '$enclosingElement.$name'; | 3373 String toString() => '$enclosingElement.$name'; |
| 3290 } | 3374 } |
| 3291 | 3375 |
| 3292 /** | 3376 /** |
| 3293 * Instances of [Node] represent nodes in a dependency graph. The | 3377 * Instances of [Node] represent nodes in a dependency graph. The |
| 3294 * type parameter, [NodeType], is the derived type (this affords some | 3378 * type parameter, [NodeType], is the derived type (this affords some |
| 3295 * extra type safety by making it difficult to accidentally construct | 3379 * extra type safety by making it difficult to accidentally construct |
| (...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4536 * there are no type parameters in scope. | 4620 * there are no type parameters in scope. |
| 4537 */ | 4621 */ |
| 4538 TypeParameterizedElementForLink get _typeParameterContext; | 4622 TypeParameterizedElementForLink get _typeParameterContext; |
| 4539 | 4623 |
| 4540 @override | 4624 @override |
| 4541 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 4625 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 4542 | 4626 |
| 4543 @override | 4627 @override |
| 4544 String toString() => '$enclosingElement.$name'; | 4628 String toString() => '$enclosingElement.$name'; |
| 4545 } | 4629 } |
| OLD | NEW |