OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import '../common.dart'; | 5 import '../common.dart'; |
6 import '../common_elements.dart'; | 6 import '../common_elements.dart'; |
7 import '../elements/elements.dart' show ErroneousElement; | 7 import '../elements/elements.dart' show ErroneousElement; |
8 import '../elements/entities.dart'; | 8 import '../elements/entities.dart'; |
9 import '../elements/resolution_types.dart' show MalformedType; | 9 import '../elements/resolution_types.dart' show MalformedType; |
10 import '../elements/types.dart'; | 10 import '../elements/types.dart'; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 110 } |
111 | 111 |
112 class CheckedModeHelpers { | 112 class CheckedModeHelpers { |
113 final CommonElements _commonElements; | 113 final CommonElements _commonElements; |
114 | 114 |
115 CheckedModeHelpers(this._commonElements); | 115 CheckedModeHelpers(this._commonElements); |
116 | 116 |
117 /// All the checked mode helpers. | 117 /// All the checked mode helpers. |
118 static const List<CheckedModeHelper> helpers = const <CheckedModeHelper>[ | 118 static const List<CheckedModeHelper> helpers = const <CheckedModeHelper>[ |
119 const MalformedCheckedModeHelper('checkMalformedType'), | 119 const MalformedCheckedModeHelper('checkMalformedType'), |
| 120 const CheckedModeHelper('voidTypeCheck'), |
120 const CheckedModeHelper('stringTypeCast'), | 121 const CheckedModeHelper('stringTypeCast'), |
121 const CheckedModeHelper('stringTypeCheck'), | 122 const CheckedModeHelper('stringTypeCheck'), |
122 const CheckedModeHelper('doubleTypeCast'), | 123 const CheckedModeHelper('doubleTypeCast'), |
123 const CheckedModeHelper('doubleTypeCheck'), | 124 const CheckedModeHelper('doubleTypeCheck'), |
124 const CheckedModeHelper('numTypeCast'), | 125 const CheckedModeHelper('numTypeCast'), |
125 const CheckedModeHelper('numTypeCheck'), | 126 const CheckedModeHelper('numTypeCheck'), |
126 const CheckedModeHelper('boolTypeCast'), | 127 const CheckedModeHelper('boolTypeCast'), |
127 const CheckedModeHelper('boolTypeCheck'), | 128 const CheckedModeHelper('boolTypeCheck'), |
128 const CheckedModeHelper('intTypeCast'), | 129 const CheckedModeHelper('intTypeCast'), |
129 const CheckedModeHelper('intTypeCheck'), | 130 const CheckedModeHelper('intTypeCheck'), |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 196 |
196 String getCheckedModeHelperNameInternal(DartType type, | 197 String getCheckedModeHelperNameInternal(DartType type, |
197 {bool typeCast, bool nativeCheckOnly}) { | 198 {bool typeCast, bool nativeCheckOnly}) { |
198 assert(!type.isTypedef); | 199 assert(!type.isTypedef); |
199 if (type.isMalformed) { | 200 if (type.isMalformed) { |
200 // The same error is thrown for type test and type cast of a malformed | 201 // The same error is thrown for type test and type cast of a malformed |
201 // type so we only need one check method. | 202 // type so we only need one check method. |
202 return 'checkMalformedType'; | 203 return 'checkMalformedType'; |
203 } | 204 } |
204 | 205 |
| 206 if (type.isVoid) { |
| 207 assert(!typeCast); // Cannot cast to void. |
| 208 if (nativeCheckOnly) return null; |
| 209 return 'voidTypeCheck'; |
| 210 } |
| 211 |
205 if (type.isTypeVariable) { | 212 if (type.isTypeVariable) { |
206 return typeCast | 213 return typeCast |
207 ? 'subtypeOfRuntimeTypeCast' | 214 ? 'subtypeOfRuntimeTypeCast' |
208 : 'assertSubtypeOfRuntimeType'; | 215 : 'assertSubtypeOfRuntimeType'; |
209 } | 216 } |
210 | 217 |
211 if (type.isFunctionType) { | 218 if (type.isFunctionType) { |
212 return typeCast ? 'functionTypeCast' : 'functionTypeCheck'; | 219 return typeCast ? 'functionTypeCast' : 'functionTypeCheck'; |
213 } | 220 } |
214 | 221 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 290 |
284 if (nativeCheck) { | 291 if (nativeCheck) { |
285 // TODO(karlklose): can we get rid of this branch when we use | 292 // TODO(karlklose): can we get rid of this branch when we use |
286 // interceptors? | 293 // interceptors? |
287 return 'intercepted$suffix'; | 294 return 'intercepted$suffix'; |
288 } else { | 295 } else { |
289 return 'property$suffix'; | 296 return 'property$suffix'; |
290 } | 297 } |
291 } | 298 } |
292 } | 299 } |
OLD | NEW |