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; |
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 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1945 } | 1924 } |
1946 | 1925 |
1947 transformChildren(v) { | 1926 transformChildren(v) { |
1948 return internalError("Internal error: Unsupported operation."); | 1927 return internalError("Internal error: Unsupported operation."); |
1949 } | 1928 } |
1950 | 1929 |
1951 visitChildren(v) { | 1930 visitChildren(v) { |
1952 return internalError("Internal error: Unsupported operation."); | 1931 return internalError("Internal error: Unsupported operation."); |
1953 } | 1932 } |
1954 } | 1933 } |
OLD | NEW |