| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 enum StaticUseKind { | 66 enum StaticUseKind { |
| 67 GENERAL, | 67 GENERAL, |
| 68 STATIC_TEAR_OFF, | 68 STATIC_TEAR_OFF, |
| 69 SUPER_TEAR_OFF, | 69 SUPER_TEAR_OFF, |
| 70 SUPER_FIELD_SET, | 70 SUPER_FIELD_SET, |
| 71 FIELD_GET, | 71 FIELD_GET, |
| 72 FIELD_SET, | 72 FIELD_SET, |
| 73 CLOSURE, | 73 CLOSURE, |
| 74 CONSTRUCTOR_INVOKE, |
| 75 CONST_CONSTRUCTOR_INVOKE, |
| 74 } | 76 } |
| 75 | 77 |
| 76 /// Statically known use of an [Element]. | 78 /// Statically known use of an [Element]. |
| 77 // TODO(johnniwinther): Create backend-specific implementations with better | 79 // TODO(johnniwinther): Create backend-specific implementations with better |
| 78 // invariants. | 80 // invariants. |
| 79 class StaticUse { | 81 class StaticUse { |
| 80 final Element element; | 82 final Element element; |
| 81 final StaticUseKind kind; | 83 final StaticUseKind kind; |
| 82 final int hashCode; | 84 final int hashCode; |
| 85 final DartType type; |
| 83 | 86 |
| 84 StaticUse.internal(Element element, StaticUseKind kind) | 87 StaticUse.internal(Element element, StaticUseKind kind, |
| 88 [DartType type = null]) |
| 85 : this.element = element, | 89 : this.element = element, |
| 86 this.kind = kind, | 90 this.kind = kind, |
| 87 this.hashCode = Hashing.objectHash(element, Hashing.objectHash(kind)) { | 91 this.type = type, |
| 92 this.hashCode = Hashing.objectsHash(element, kind, type) { |
| 88 assert(invariant(element, element.isDeclaration, | 93 assert(invariant(element, element.isDeclaration, |
| 89 message: "Static use element $element must be " | 94 message: "Static use element $element must be " |
| 90 "the declaration element.")); | 95 "the declaration element.")); |
| 91 } | 96 } |
| 92 | 97 |
| 93 /// Invocation of a static or top-level [element] with the given | 98 /// Invocation of a static or top-level [element] with the given |
| 94 /// [callStructure]. | 99 /// [callStructure]. |
| 95 factory StaticUse.staticInvoke( | 100 factory StaticUse.staticInvoke( |
| 96 MethodElement element, CallStructure callStructure) { | 101 MethodElement element, CallStructure callStructure) { |
| 97 // TODO(johnniwinther): Use the [callStructure]. | 102 // TODO(johnniwinther): Use the [callStructure]. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 return new StaticUse.internal(element, StaticUseKind.GENERAL); | 207 return new StaticUse.internal(element, StaticUseKind.GENERAL); |
| 203 } | 208 } |
| 204 | 209 |
| 205 /// Constructor invocation of [element] with the given [callStructure]. | 210 /// Constructor invocation of [element] with the given [callStructure]. |
| 206 factory StaticUse.constructorInvoke( | 211 factory StaticUse.constructorInvoke( |
| 207 ConstructorElement element, CallStructure callStructure) { | 212 ConstructorElement element, CallStructure callStructure) { |
| 208 // TODO(johnniwinther): Use the [callStructure]. | 213 // TODO(johnniwinther): Use the [callStructure]. |
| 209 return new StaticUse.internal(element, StaticUseKind.GENERAL); | 214 return new StaticUse.internal(element, StaticUseKind.GENERAL); |
| 210 } | 215 } |
| 211 | 216 |
| 217 /// Constructor invocation of [element] with the given [callStructure] on |
| 218 /// [type]. |
| 219 factory StaticUse.typedConstructorInvoke( |
| 220 ConstructorElement element, CallStructure callStructure, DartType type) { |
| 221 assert(invariant(element, type != null, |
| 222 message: "No type provided for constructor invocation.")); |
| 223 // TODO(johnniwinther): Use the [callStructure]. |
| 224 return new StaticUse.internal( |
| 225 element, StaticUseKind.CONSTRUCTOR_INVOKE, type); |
| 226 } |
| 227 |
| 228 /// Constant constructor invocation of [element] with the given |
| 229 /// [callStructure] on [type]. |
| 230 factory StaticUse.constConstructorInvoke( |
| 231 ConstructorElement element, CallStructure callStructure, DartType type) { |
| 232 assert(invariant(element, type != null, |
| 233 message: "No type provided for constructor invocation.")); |
| 234 // TODO(johnniwinther): Use the [callStructure]. |
| 235 return new StaticUse.internal( |
| 236 element, StaticUseKind.CONST_CONSTRUCTOR_INVOKE, type); |
| 237 } |
| 238 |
| 212 /// Constructor redirection to [element]. | 239 /// Constructor redirection to [element]. |
| 213 factory StaticUse.constructorRedirect(ConstructorElement element) { | 240 factory StaticUse.constructorRedirect(ConstructorElement element) { |
| 214 return new StaticUse.internal(element, StaticUseKind.GENERAL); | 241 return new StaticUse.internal(element, StaticUseKind.GENERAL); |
| 215 } | 242 } |
| 216 | 243 |
| 217 /// Initialization of an instance field [element]. | 244 /// Initialization of an instance field [element]. |
| 218 factory StaticUse.fieldInit(FieldElement element) { | 245 factory StaticUse.fieldInit(FieldElement element) { |
| 219 assert(invariant(element, element.isInstanceMember, | 246 assert(invariant(element, element.isInstanceMember, |
| 220 message: "Field init element $element must be an instance field.")); | 247 message: "Field init element $element must be an instance field.")); |
| 221 return new StaticUse.internal(element, StaticUseKind.GENERAL); | 248 return new StaticUse.internal(element, StaticUseKind.GENERAL); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 246 | 273 |
| 247 /// Unknown use of [element]. | 274 /// Unknown use of [element]. |
| 248 @deprecated | 275 @deprecated |
| 249 factory StaticUse.foreignUse(Element element) { | 276 factory StaticUse.foreignUse(Element element) { |
| 250 return new StaticUse.internal(element, StaticUseKind.GENERAL); | 277 return new StaticUse.internal(element, StaticUseKind.GENERAL); |
| 251 } | 278 } |
| 252 | 279 |
| 253 bool operator ==(other) { | 280 bool operator ==(other) { |
| 254 if (identical(this, other)) return true; | 281 if (identical(this, other)) return true; |
| 255 if (other is! StaticUse) return false; | 282 if (other is! StaticUse) return false; |
| 256 return element == other.element && kind == other.kind; | 283 return element == other.element && kind == other.kind && type == other.type; |
| 257 } | 284 } |
| 258 | 285 |
| 259 String toString() => 'StaticUse($element,$kind)'; | 286 String toString() => 'StaticUse($element,$kind,$type)'; |
| 260 } | 287 } |
| 261 | 288 |
| 262 enum TypeUseKind { | 289 enum TypeUseKind { |
| 263 IS_CHECK, | 290 IS_CHECK, |
| 264 AS_CAST, | 291 AS_CAST, |
| 265 CHECKED_MODE_CHECK, | 292 CHECKED_MODE_CHECK, |
| 266 CATCH_TYPE, | 293 CATCH_TYPE, |
| 267 TYPE_LITERAL, | 294 TYPE_LITERAL, |
| 268 INSTANTIATION, | 295 INSTANTIATION, |
| 269 } | 296 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 337 } |
| 311 | 338 |
| 312 bool operator ==(other) { | 339 bool operator ==(other) { |
| 313 if (identical(this, other)) return true; | 340 if (identical(this, other)) return true; |
| 314 if (other is! TypeUse) return false; | 341 if (other is! TypeUse) return false; |
| 315 return type == other.type && kind == other.kind; | 342 return type == other.type && kind == other.kind; |
| 316 } | 343 } |
| 317 | 344 |
| 318 String toString() => 'TypeUse($type,$kind)'; | 345 String toString() => 'TypeUse($type,$kind)'; |
| 319 } | 346 } |
| OLD | NEW |