| 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 library kernel.transformations.erasure; | 4 library kernel.transformations.erasure; |
| 5 | 5 |
| 6 import '../ast.dart'; | 6 import '../ast.dart'; |
| 7 import '../type_algebra.dart'; | 7 import '../type_algebra.dart'; |
| 8 import '../core_types.dart'; | 8 import '../core_types.dart'; |
| 9 | 9 |
| 10 Program transformProgram(CoreTypes coreTypes, Program program) { | 10 Program transformProgram(CoreTypes coreTypes, Program program) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 void popConstantContext() { | 46 void popConstantContext() { |
| 47 --constantContexts; | 47 --constantContexts; |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool get isInConstantContext => constantContexts > 0; | 50 bool get isInConstantContext => constantContexts > 0; |
| 51 | 51 |
| 52 @override | 52 @override |
| 53 visitDartType(DartType type) { | 53 visitDartType(DartType type) { |
| 54 if (type is FunctionType && type.typeParameters.isNotEmpty) { |
| 55 FunctionType function = type; |
| 56 for (var parameter in function.typeParameters) { |
| 57 // Note, normally, we would have to remove these substitutions again to |
| 58 // avoid memory leaks. Unfortunately, that that's not compatible with |
| 59 // how function types share their TypeParameter object with a |
| 60 // FunctionNode. |
| 61 substitution[parameter] = const DynamicType(); |
| 62 } |
| 63 for (var parameter in function.typeParameters) { |
| 64 if (!isObject(parameter.bound)) { |
| 65 substitution[parameter] = substitute(parameter.bound, substitution); |
| 66 } |
| 67 } |
| 68 // We need to delete the type parameters of the function type before |
| 69 // calling [substitute], otherwise it creates a new environment with |
| 70 // fresh type variables that shadow the ones we want to remove. Since a |
| 71 // FunctionType is often assumed to be immutable, we return a copy. |
| 72 type = new FunctionType( |
| 73 function.positionalParameters, function.returnType, |
| 74 namedParameters: function.namedParameters, |
| 75 requiredParameterCount: function.requiredParameterCount, |
| 76 positionalParameterNames: function.positionalParameterNames, |
| 77 typedefReference: function.typedefReference); |
| 78 } |
| 54 type = substitute(type, substitution); | 79 type = substitute(type, substitution); |
| 55 if (isInConstantContext) { | 80 if (isInConstantContext) { |
| 56 type = substitute(type, constantSubstitution); | 81 type = substitute(type, constantSubstitution); |
| 57 } | 82 } |
| 58 return type; | 83 return type; |
| 59 } | 84 } |
| 60 | 85 |
| 61 @override | 86 @override |
| 62 visitClass(Class node) { | 87 visitClass(Class node) { |
| 63 for (var parameter in node.typeParameters) { | 88 for (var parameter in node.typeParameters) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 176 } |
| 152 | 177 |
| 153 @override | 178 @override |
| 154 visitMapLiteral(MapLiteral node) { | 179 visitMapLiteral(MapLiteral node) { |
| 155 if (node.isConst) pushConstantContext(); | 180 if (node.isConst) pushConstantContext(); |
| 156 node.transformChildren(this); | 181 node.transformChildren(this); |
| 157 if (node.isConst) popConstantContext(); | 182 if (node.isConst) popConstantContext(); |
| 158 return node; | 183 return node; |
| 159 } | 184 } |
| 160 } | 185 } |
| OLD | NEW |