Chromium Code Reviews| 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 for (var parameter in type.typeParameters) { | |
| 56 // Note, normally, we would have to remove these substitutions again to | |
| 57 // avoid memory leaks. Unfortunately, that that's not compatible with | |
| 58 // how function types share their TypeParameter object with a | |
| 59 // FunctionNode. | |
| 60 substitution[parameter] = const DynamicType(); | |
| 61 } | |
| 62 for (var parameter in type.typeParameters) { | |
| 63 if (!isObject(parameter.bound)) { | |
| 64 substitution[parameter] = substitute(parameter.bound, substitution); | |
| 65 } | |
| 66 } | |
| 67 // We need to delete the type parameters of the function type before | |
| 68 // calling [substitute], otherwise it creates a new environment with | |
| 69 // fresh type variables that shadow the ones we want to remove. Since a | |
| 70 // FunctionType is often assumed to immutable, we return a copy. | |
|
Kevin Millikin (Google)
2017/08/14 10:47:35
"to immutable" ==> "to be immutable"
| |
| 71 type = new FunctionType(type.positionalParameters, type.returnType, | |
| 72 namedParameters: type.namedParameters, | |
| 73 requiredParameterCount: type.requiredParameterCount, | |
| 74 positionalParameterNames: type.positionalParameterNames, | |
| 75 typedefReference: type.typedefReference); | |
| 76 } | |
| 54 type = substitute(type, substitution); | 77 type = substitute(type, substitution); |
| 55 if (isInConstantContext) { | 78 if (isInConstantContext) { |
| 56 type = substitute(type, constantSubstitution); | 79 type = substitute(type, constantSubstitution); |
| 57 } | 80 } |
| 58 return type; | 81 return type; |
| 59 } | 82 } |
| 60 | 83 |
| 61 @override | 84 @override |
| 62 visitClass(Class node) { | 85 visitClass(Class node) { |
| 63 for (var parameter in node.typeParameters) { | 86 for (var parameter in node.typeParameters) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 } | 174 } |
| 152 | 175 |
| 153 @override | 176 @override |
| 154 visitMapLiteral(MapLiteral node) { | 177 visitMapLiteral(MapLiteral node) { |
| 155 if (node.isConst) pushConstantContext(); | 178 if (node.isConst) pushConstantContext(); |
| 156 node.transformChildren(this); | 179 node.transformChildren(this); |
| 157 if (node.isConst) popConstantContext(); | 180 if (node.isConst) popConstantContext(); |
| 158 return node; | 181 return node; |
| 159 } | 182 } |
| 160 } | 183 } |
| OLD | NEW |