| 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 defines individual world impacts. | 5 /// This library defines individual world impacts. |
| 6 /// | 6 /// |
| 7 /// We call these building blocks `uses`. Each `use` is a single impact of the | 7 /// We call these building blocks `uses`. Each `use` is a single impact of the |
| 8 /// world. Some example uses are: | 8 /// world. Some example uses are: |
| 9 /// | 9 /// |
| 10 /// * an invocation of a top level function | 10 /// * an invocation of a top level function |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 DIRECT_USE, | 82 DIRECT_USE, |
| 83 } | 83 } |
| 84 | 84 |
| 85 /// Statically known use of an [Element]. | 85 /// Statically known use of an [Element]. |
| 86 // TODO(johnniwinther): Create backend-specific implementations with better | 86 // TODO(johnniwinther): Create backend-specific implementations with better |
| 87 // invariants. | 87 // invariants. |
| 88 class StaticUse { | 88 class StaticUse { |
| 89 final Element element; | 89 final Element element; |
| 90 final StaticUseKind kind; | 90 final StaticUseKind kind; |
| 91 final int hashCode; | 91 final int hashCode; |
| 92 final DartType type; | 92 final ResolutionDartType type; |
| 93 | 93 |
| 94 StaticUse.internal(Element element, StaticUseKind kind, | 94 StaticUse.internal(Element element, StaticUseKind kind, |
| 95 [DartType type = null]) | 95 [ResolutionDartType type = null]) |
| 96 : this.element = element, | 96 : this.element = element, |
| 97 this.kind = kind, | 97 this.kind = kind, |
| 98 this.type = type, | 98 this.type = type, |
| 99 this.hashCode = Hashing.objectsHash(element, kind, type) { | 99 this.hashCode = Hashing.objectsHash(element, kind, type) { |
| 100 assert(invariant(element, element.isDeclaration, | 100 assert(invariant(element, element.isDeclaration, |
| 101 message: "Static use element $element must be " | 101 message: "Static use element $element must be " |
| 102 "the declaration element.")); | 102 "the declaration element.")); |
| 103 } | 103 } |
| 104 | 104 |
| 105 /// Invocation of a static or top-level [element] with the given | 105 /// Invocation of a static or top-level [element] with the given |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 245 |
| 246 /// Constructor invocation of [element] with the given [callStructure]. | 246 /// Constructor invocation of [element] with the given [callStructure]. |
| 247 factory StaticUse.constructorInvoke( | 247 factory StaticUse.constructorInvoke( |
| 248 ConstructorElement element, CallStructure callStructure) { | 248 ConstructorElement element, CallStructure callStructure) { |
| 249 // TODO(johnniwinther): Use the [callStructure]. | 249 // TODO(johnniwinther): Use the [callStructure]. |
| 250 return new StaticUse.internal(element, StaticUseKind.GENERAL); | 250 return new StaticUse.internal(element, StaticUseKind.GENERAL); |
| 251 } | 251 } |
| 252 | 252 |
| 253 /// Constructor invocation of [element] with the given [callStructure] on | 253 /// Constructor invocation of [element] with the given [callStructure] on |
| 254 /// [type]. | 254 /// [type]. |
| 255 factory StaticUse.typedConstructorInvoke( | 255 factory StaticUse.typedConstructorInvoke(ConstructorElement element, |
| 256 ConstructorElement element, CallStructure callStructure, DartType type) { | 256 CallStructure callStructure, ResolutionDartType type) { |
| 257 assert(invariant(element, type != null, | 257 assert(invariant(element, type != null, |
| 258 message: "No type provided for constructor invocation.")); | 258 message: "No type provided for constructor invocation.")); |
| 259 // TODO(johnniwinther): Use the [callStructure]. | 259 // TODO(johnniwinther): Use the [callStructure]. |
| 260 return new StaticUse.internal( | 260 return new StaticUse.internal( |
| 261 element, StaticUseKind.CONSTRUCTOR_INVOKE, type); | 261 element, StaticUseKind.CONSTRUCTOR_INVOKE, type); |
| 262 } | 262 } |
| 263 | 263 |
| 264 /// Constant constructor invocation of [element] with the given | 264 /// Constant constructor invocation of [element] with the given |
| 265 /// [callStructure] on [type]. | 265 /// [callStructure] on [type]. |
| 266 factory StaticUse.constConstructorInvoke( | 266 factory StaticUse.constConstructorInvoke(ConstructorElement element, |
| 267 ConstructorElement element, CallStructure callStructure, DartType type) { | 267 CallStructure callStructure, ResolutionDartType type) { |
| 268 assert(invariant(element, type != null, | 268 assert(invariant(element, type != null, |
| 269 message: "No type provided for constructor invocation.")); | 269 message: "No type provided for constructor invocation.")); |
| 270 // TODO(johnniwinther): Use the [callStructure]. | 270 // TODO(johnniwinther): Use the [callStructure]. |
| 271 return new StaticUse.internal( | 271 return new StaticUse.internal( |
| 272 element, StaticUseKind.CONST_CONSTRUCTOR_INVOKE, type); | 272 element, StaticUseKind.CONST_CONSTRUCTOR_INVOKE, type); |
| 273 } | 273 } |
| 274 | 274 |
| 275 /// Constructor redirection to [element] on [type]. | 275 /// Constructor redirection to [element] on [type]. |
| 276 factory StaticUse.constructorRedirect( | 276 factory StaticUse.constructorRedirect( |
| 277 ConstructorElement element, InterfaceType type) { | 277 ConstructorElement element, ResolutionInterfaceType type) { |
| 278 assert(invariant(element, type != null, | 278 assert(invariant(element, type != null, |
| 279 message: "No type provided for constructor invocation.")); | 279 message: "No type provided for constructor invocation.")); |
| 280 return new StaticUse.internal(element, StaticUseKind.REDIRECTION, type); | 280 return new StaticUse.internal(element, StaticUseKind.REDIRECTION, type); |
| 281 } | 281 } |
| 282 | 282 |
| 283 /// Initialization of an instance field [element]. | 283 /// Initialization of an instance field [element]. |
| 284 factory StaticUse.fieldInit(FieldElement element) { | 284 factory StaticUse.fieldInit(FieldElement element) { |
| 285 assert(invariant(element, element.isInstanceMember, | 285 assert(invariant(element, element.isInstanceMember, |
| 286 message: "Field init element $element must be an instance field.")); | 286 message: "Field init element $element must be an instance field.")); |
| 287 return new StaticUse.internal(element, StaticUseKind.GENERAL); | 287 return new StaticUse.internal(element, StaticUseKind.GENERAL); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 IS_CHECK, | 334 IS_CHECK, |
| 335 AS_CAST, | 335 AS_CAST, |
| 336 CHECKED_MODE_CHECK, | 336 CHECKED_MODE_CHECK, |
| 337 CATCH_TYPE, | 337 CATCH_TYPE, |
| 338 TYPE_LITERAL, | 338 TYPE_LITERAL, |
| 339 INSTANTIATION, | 339 INSTANTIATION, |
| 340 MIRROR_INSTANTIATION, | 340 MIRROR_INSTANTIATION, |
| 341 NATIVE_INSTANTIATION, | 341 NATIVE_INSTANTIATION, |
| 342 } | 342 } |
| 343 | 343 |
| 344 /// Use of a [DartType]. | 344 /// Use of a [ResolutionDartType]. |
| 345 class TypeUse { | 345 class TypeUse { |
| 346 final DartType type; | 346 final ResolutionDartType type; |
| 347 final TypeUseKind kind; | 347 final TypeUseKind kind; |
| 348 final int hashCode; | 348 final int hashCode; |
| 349 | 349 |
| 350 TypeUse.internal(DartType type, TypeUseKind kind) | 350 TypeUse.internal(ResolutionDartType type, TypeUseKind kind) |
| 351 : this.type = type, | 351 : this.type = type, |
| 352 this.kind = kind, | 352 this.kind = kind, |
| 353 this.hashCode = Hashing.objectHash(type, Hashing.objectHash(kind)); | 353 this.hashCode = Hashing.objectHash(type, Hashing.objectHash(kind)); |
| 354 | 354 |
| 355 /// [type] used in an is check, like `e is T` or `e is! T`. | 355 /// [type] used in an is check, like `e is T` or `e is! T`. |
| 356 factory TypeUse.isCheck(DartType type) { | 356 factory TypeUse.isCheck(ResolutionDartType type) { |
| 357 return new TypeUse.internal(type, TypeUseKind.IS_CHECK); | 357 return new TypeUse.internal(type, TypeUseKind.IS_CHECK); |
| 358 } | 358 } |
| 359 | 359 |
| 360 /// [type] used in an as cast, like `e as T`. | 360 /// [type] used in an as cast, like `e as T`. |
| 361 factory TypeUse.asCast(DartType type) { | 361 factory TypeUse.asCast(ResolutionDartType type) { |
| 362 return new TypeUse.internal(type, TypeUseKind.AS_CAST); | 362 return new TypeUse.internal(type, TypeUseKind.AS_CAST); |
| 363 } | 363 } |
| 364 | 364 |
| 365 /// [type] used as a type annotation, like `T foo;`. | 365 /// [type] used as a type annotation, like `T foo;`. |
| 366 factory TypeUse.checkedModeCheck(DartType type) { | 366 factory TypeUse.checkedModeCheck(ResolutionDartType type) { |
| 367 return new TypeUse.internal(type, TypeUseKind.CHECKED_MODE_CHECK); | 367 return new TypeUse.internal(type, TypeUseKind.CHECKED_MODE_CHECK); |
| 368 } | 368 } |
| 369 | 369 |
| 370 /// [type] used in a on type catch clause, like `try {} on T catch (e) {}`. | 370 /// [type] used in a on type catch clause, like `try {} on T catch (e) {}`. |
| 371 factory TypeUse.catchType(DartType type) { | 371 factory TypeUse.catchType(ResolutionDartType type) { |
| 372 return new TypeUse.internal(type, TypeUseKind.CATCH_TYPE); | 372 return new TypeUse.internal(type, TypeUseKind.CATCH_TYPE); |
| 373 } | 373 } |
| 374 | 374 |
| 375 /// [type] used as a type literal, like `foo() => T;`. | 375 /// [type] used as a type literal, like `foo() => T;`. |
| 376 factory TypeUse.typeLiteral(DartType type) { | 376 factory TypeUse.typeLiteral(ResolutionDartType type) { |
| 377 return new TypeUse.internal(type, TypeUseKind.TYPE_LITERAL); | 377 return new TypeUse.internal(type, TypeUseKind.TYPE_LITERAL); |
| 378 } | 378 } |
| 379 | 379 |
| 380 /// [type] used in an instantiation, like `new T();`. | 380 /// [type] used in an instantiation, like `new T();`. |
| 381 factory TypeUse.instantiation(InterfaceType type) { | 381 factory TypeUse.instantiation(ResolutionInterfaceType type) { |
| 382 return new TypeUse.internal(type, TypeUseKind.INSTANTIATION); | 382 return new TypeUse.internal(type, TypeUseKind.INSTANTIATION); |
| 383 } | 383 } |
| 384 | 384 |
| 385 /// [type] used in an instantiation through mirrors. | 385 /// [type] used in an instantiation through mirrors. |
| 386 factory TypeUse.mirrorInstantiation(InterfaceType type) { | 386 factory TypeUse.mirrorInstantiation(ResolutionInterfaceType type) { |
| 387 return new TypeUse.internal(type, TypeUseKind.MIRROR_INSTANTIATION); | 387 return new TypeUse.internal(type, TypeUseKind.MIRROR_INSTANTIATION); |
| 388 } | 388 } |
| 389 | 389 |
| 390 /// [type] used in a native instantiation. | 390 /// [type] used in a native instantiation. |
| 391 factory TypeUse.nativeInstantiation(InterfaceType type) { | 391 factory TypeUse.nativeInstantiation(ResolutionInterfaceType type) { |
| 392 return new TypeUse.internal(type, TypeUseKind.NATIVE_INSTANTIATION); | 392 return new TypeUse.internal(type, TypeUseKind.NATIVE_INSTANTIATION); |
| 393 } | 393 } |
| 394 | 394 |
| 395 bool operator ==(other) { | 395 bool operator ==(other) { |
| 396 if (identical(this, other)) return true; | 396 if (identical(this, other)) return true; |
| 397 if (other is! TypeUse) return false; | 397 if (other is! TypeUse) return false; |
| 398 return type == other.type && kind == other.kind; | 398 return type == other.type && kind == other.kind; |
| 399 } | 399 } |
| 400 | 400 |
| 401 String toString() => 'TypeUse($type,$kind)'; | 401 String toString() => 'TypeUse($type,$kind)'; |
| 402 } | 402 } |
| OLD | NEW |