OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library defined `uses`. A `use` is a single impact of the world, for | 5 /// This library defined `uses`. A `use` is a single impact of the world, for |
6 /// instance an invocation of a top level function or a call to the `foo()` | 6 /// instance an invocation of a top level function or a call to the `foo()` |
7 /// method on an unknown class. | 7 /// method on an unknown class. |
8 library dart2js.universe.use; | 8 library dart2js.universe.use; |
9 | 9 |
10 import '../closure.dart' show | 10 import '../closure.dart' show |
11 BoxFieldElement; | 11 BoxFieldElement; |
12 import '../common.dart'; | 12 import '../common.dart'; |
| 13 import '../dart_types.dart'; |
13 import '../elements/elements.dart'; | 14 import '../elements/elements.dart'; |
14 import '../world.dart' show | 15 import '../world.dart' show |
15 ClassWorld; | 16 ClassWorld; |
16 import '../util/util.dart' show | 17 import '../util/util.dart' show |
17 Hashing; | 18 Hashing; |
18 | 19 |
19 import 'call_structure.dart' show | 20 import 'call_structure.dart' show |
20 CallStructure; | 21 CallStructure; |
21 import 'selector.dart' show | 22 import 'selector.dart' show |
22 Selector; | 23 Selector; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 bool operator ==(other) { | 241 bool operator ==(other) { |
241 if (identical(this, other)) return true; | 242 if (identical(this, other)) return true; |
242 if (other is! StaticUse) return false; | 243 if (other is! StaticUse) return false; |
243 return element == other.element && | 244 return element == other.element && |
244 kind == other.kind; | 245 kind == other.kind; |
245 } | 246 } |
246 | 247 |
247 String toString() => 'StaticUse($element,$kind)'; | 248 String toString() => 'StaticUse($element,$kind)'; |
248 } | 249 } |
249 | 250 |
| 251 enum TypeUseKind { |
| 252 IS_CHECK, |
| 253 AS_CAST, |
| 254 CHECKED_MODE_CHECK, |
| 255 CATCH_TYPE, |
| 256 TYPE_LITERAL, |
| 257 INSTANTIATION, |
| 258 } |
| 259 |
| 260 /// Use of a [DartType]. |
| 261 class TypeUse { |
| 262 final DartType type; |
| 263 final TypeUseKind kind; |
| 264 final int hashCode; |
| 265 |
| 266 TypeUse._(DartType type, TypeUseKind kind) |
| 267 : this.type = type, |
| 268 this.kind = kind, |
| 269 this.hashCode = Hashing.objectHash(type, Hashing.objectHash(kind)); |
| 270 |
| 271 /// [type] used in an is check, like `e is T` or `e is! T`. |
| 272 factory TypeUse.isCheck(DartType type) { |
| 273 return new TypeUse._(type, TypeUseKind.IS_CHECK); |
| 274 } |
| 275 |
| 276 /// [type] used in an as cast, like `e as T`. |
| 277 factory TypeUse.asCast(DartType type) { |
| 278 return new TypeUse._(type, TypeUseKind.AS_CAST); |
| 279 } |
| 280 |
| 281 /// [type] used as a type annotation, like `T foo;`. |
| 282 factory TypeUse.checkedModeCheck(DartType type) { |
| 283 return new TypeUse._(type, TypeUseKind.CHECKED_MODE_CHECK); |
| 284 } |
| 285 |
| 286 /// [type] used in a on type catch clause, like `try {} on T catch (e) {}`. |
| 287 factory TypeUse.catchType(DartType type) { |
| 288 return new TypeUse._(type, TypeUseKind.CATCH_TYPE); |
| 289 } |
| 290 |
| 291 /// [type] used as a type literal, like `foo() => T;`. |
| 292 factory TypeUse.typeLiteral(DartType type) { |
| 293 return new TypeUse._(type, TypeUseKind.TYPE_LITERAL); |
| 294 } |
| 295 |
| 296 /// [type] used in an instantiation, like `new T();`. |
| 297 factory TypeUse.instantiation(InterfaceType type) { |
| 298 return new TypeUse._(type, TypeUseKind.INSTANTIATION); |
| 299 } |
| 300 |
| 301 bool operator ==(other) { |
| 302 if (identical(this, other)) return true; |
| 303 if (other is! TypeUse) return false; |
| 304 return type == other.type && |
| 305 kind == other.kind; |
| 306 } |
| 307 |
| 308 String toString() => 'TypeUse($type,$kind)'; |
| 309 } |
OLD | NEW |