Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 /// This file declares a "shadow hierarchy" of concrete classes which extend | 5 /// This file declares a "shadow hierarchy" of concrete classes which extend |
| 6 /// the kernel class hierarchy, adding methods and fields needed by the | 6 /// the kernel class hierarchy, adding methods and fields needed by the |
| 7 /// BodyBuilder. | 7 /// BodyBuilder. |
| 8 /// | 8 /// |
| 9 /// Instances of these classes may be created using the factory methods in | 9 /// Instances of these classes may be created using the factory methods in |
| 10 /// `ast_factory.dart`. | 10 /// `ast_factory.dart`. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 import 'package:kernel/frontend/accessors.dart'; | 30 import 'package:kernel/frontend/accessors.dart'; |
| 31 import 'package:kernel/type_algebra.dart'; | 31 import 'package:kernel/type_algebra.dart'; |
| 32 | 32 |
| 33 import '../errors.dart' show internalError; | 33 import '../errors.dart' show internalError; |
| 34 | 34 |
| 35 /// Computes the return type of a (possibly factory) constructor. | 35 /// Computes the return type of a (possibly factory) constructor. |
| 36 InterfaceType computeConstructorReturnType(Member constructor) { | 36 InterfaceType computeConstructorReturnType(Member constructor) { |
| 37 if (constructor is Constructor) { | 37 if (constructor is Constructor) { |
| 38 return constructor.enclosingClass.thisType; | 38 return constructor.enclosingClass.thisType; |
| 39 } else { | 39 } else { |
| 40 return computeFactoryConstructorReturnType(constructor); | 40 return constructor.function.returnType; |
|
ahe
2017/06/01 09:10:09
I also have to "steal" all these changes :-)
| |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 /// Computes the return type of a factory constructor. | |
| 45 /// | |
| 46 /// Note that we can't just use `constructor.function.functionType.returnType`, | |
| 47 /// because that's `dynamic` for factory constructors. TODO(paulberry): | |
| 48 /// investigate whether this can be changed. | |
| 49 InterfaceType computeFactoryConstructorReturnType(Procedure constructor) { | |
| 50 var returnType = constructor.enclosingClass.thisType; | |
| 51 if (constructor.enclosingClass.typeParameters.isNotEmpty) { | |
| 52 // target.enclosingClass.typeParameters is not the same as | |
| 53 // target.function.functionType.typeParameters, so we have to substitute. | |
| 54 returnType = Substitution | |
| 55 .fromPairs( | |
| 56 constructor.enclosingClass.typeParameters, | |
| 57 constructor.function.functionType.typeParameters | |
| 58 .map((p) => new TypeParameterType(p)) | |
| 59 .toList()) | |
| 60 .substituteType(returnType); | |
| 61 } | |
| 62 return returnType; | |
| 63 } | |
| 64 | |
| 65 List<DartType> getExplicitTypeArguments(Arguments arguments) { | 44 List<DartType> getExplicitTypeArguments(Arguments arguments) { |
| 66 if (arguments is KernelArguments) { | 45 if (arguments is KernelArguments) { |
| 67 return arguments._hasExplicitTypeArguments ? arguments.types : null; | 46 return arguments._hasExplicitTypeArguments ? arguments.types : null; |
| 68 } else { | 47 } else { |
| 69 // This code path should only be taken in situations where there are no | 48 // This code path should only be taken in situations where there are no |
| 70 // type arguments at all, e.g. calling a user-definable operator. | 49 // type arguments at all, e.g. calling a user-definable operator. |
| 71 assert(arguments.types.isEmpty); | 50 assert(arguments.types.isEmpty); |
| 72 return null; | 51 return null; |
| 73 } | 52 } |
| 74 } | 53 } |
| (...skipping 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1899 } | 1878 } |
| 1900 | 1879 |
| 1901 visitChildren(v) { | 1880 visitChildren(v) { |
| 1902 return internalError("Internal error: Unsupported operation."); | 1881 return internalError("Internal error: Unsupported operation."); |
| 1903 } | 1882 } |
| 1904 | 1883 |
| 1905 transformChildren(v) { | 1884 transformChildren(v) { |
| 1906 return internalError("Internal error: Unsupported operation."); | 1885 return internalError("Internal error: Unsupported operation."); |
| 1907 } | 1886 } |
| 1908 } | 1887 } |
| OLD | NEW |