| 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 |
| 11 /// * a call to the `foo()` method on an unknown class. | 11 /// * a call to the `foo()` method on an unknown class. |
| 12 /// * an instantiation of class T | 12 /// * an instantiation of class T |
| 13 /// | 13 /// |
| 14 /// The different compiler stages combine these uses into `WorldImpact` objects, | 14 /// The different compiler stages combine these uses into `WorldImpact` objects, |
| 15 /// which are later used to construct a closed-world understanding of the | 15 /// which are later used to construct a closed-world understanding of the |
| 16 /// program. | 16 /// program. |
| 17 library dart2js.universe.use; | 17 library dart2js.universe.use; |
| 18 | 18 |
| 19 import '../closure.dart' show BoxFieldElement; | 19 import '../closure.dart' show BoxFieldElement; |
| 20 import '../common.dart'; | 20 import '../common.dart'; |
| 21 import '../elements/types.dart'; | 21 import '../elements/types.dart'; |
| 22 import '../elements/elements.dart' | 22 import '../elements/elements.dart' |
| 23 show | 23 show |
| 24 ConstructorElement, | |
| 25 ConstructorBodyElement, | 24 ConstructorBodyElement, |
| 26 Element, | 25 Element, |
| 27 Entity, | 26 Entity, |
| 28 LocalFunctionElement; | 27 LocalFunctionElement; |
| 29 import '../elements/entities.dart'; | 28 import '../elements/entities.dart'; |
| 30 import '../util/util.dart' show Hashing; | 29 import '../util/util.dart' show Hashing; |
| 31 import '../world.dart' show World; | 30 import '../world.dart' show World; |
| 32 import 'call_structure.dart' show CallStructure; | 31 import 'call_structure.dart' show CallStructure; |
| 33 import 'selector.dart' show Selector; | 32 import 'selector.dart' show Selector; |
| 34 import 'world_builder.dart' show ReceiverConstraint; | 33 import 'world_builder.dart' show ReceiverConstraint; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 /// Closurization of a super method [element]. | 196 /// Closurization of a super method [element]. |
| 198 factory StaticUse.superTearOff(FunctionEntity element) { | 197 factory StaticUse.superTearOff(FunctionEntity element) { |
| 199 assert(invariant(element, element.isInstanceMember && element.isFunction, | 198 assert(invariant(element, element.isInstanceMember && element.isFunction, |
| 200 message: "Super invoke element $element must be an instance method.")); | 199 message: "Super invoke element $element must be an instance method.")); |
| 201 return new StaticUse.internal(element, StaticUseKind.SUPER_TEAR_OFF); | 200 return new StaticUse.internal(element, StaticUseKind.SUPER_TEAR_OFF); |
| 202 } | 201 } |
| 203 | 202 |
| 204 /// Invocation of a constructor [element] through a this or super | 203 /// Invocation of a constructor [element] through a this or super |
| 205 /// constructor call with the given [callStructure]. | 204 /// constructor call with the given [callStructure]. |
| 206 factory StaticUse.superConstructorInvoke( | 205 factory StaticUse.superConstructorInvoke( |
| 207 ConstructorElement element, CallStructure callStructure) { | 206 ConstructorEntity element, CallStructure callStructure) { |
| 208 // TODO(johnniwinther): Use the [callStructure]. | 207 // TODO(johnniwinther): Use the [callStructure]. |
| 209 assert(invariant(element, element.isGenerativeConstructor, | 208 assert(invariant(element, element.isGenerativeConstructor, |
| 210 message: "Constructor invoke element $element must be a " | 209 message: "Constructor invoke element $element must be a " |
| 211 "generative constructor.")); | 210 "generative constructor.")); |
| 212 return new StaticUse.internal(element, StaticUseKind.GENERAL); | 211 return new StaticUse.internal(element, StaticUseKind.GENERAL); |
| 213 } | 212 } |
| 214 | 213 |
| 215 /// Invocation of a constructor (body) [element] through a this or super | 214 /// Invocation of a constructor (body) [element] through a this or super |
| 216 /// constructor call with the given [callStructure]. | 215 /// constructor call with the given [callStructure]. |
| 217 factory StaticUse.constructorBodyInvoke( | 216 factory StaticUse.constructorBodyInvoke( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 244 factory StaticUse.directSet(FieldEntity element) { | 243 factory StaticUse.directSet(FieldEntity element) { |
| 245 assert(invariant(element, element.isInstanceMember, | 244 assert(invariant(element, element.isInstanceMember, |
| 246 message: "Direct set element $element must be an instance member.")); | 245 message: "Direct set element $element must be an instance member.")); |
| 247 assert(invariant(element, element.isField, | 246 assert(invariant(element, element.isField, |
| 248 message: "Direct set element $element must be a field.")); | 247 message: "Direct set element $element must be a field.")); |
| 249 return new StaticUse.internal(element, StaticUseKind.GENERAL); | 248 return new StaticUse.internal(element, StaticUseKind.GENERAL); |
| 250 } | 249 } |
| 251 | 250 |
| 252 /// Constructor invocation of [element] with the given [callStructure]. | 251 /// Constructor invocation of [element] with the given [callStructure]. |
| 253 factory StaticUse.constructorInvoke( | 252 factory StaticUse.constructorInvoke( |
| 254 FunctionEntity element, CallStructure callStructure) { | 253 ConstructorEntity element, CallStructure callStructure) { |
| 255 assert(invariant(element, element.isConstructor, | 254 assert(invariant(element, element.isConstructor, |
| 256 message: "Constructor invocation element $element " | 255 message: "Constructor invocation element $element " |
| 257 "must be a constructor.")); | 256 "must be a constructor.")); |
| 258 // TODO(johnniwinther): Use the [callStructure]. | 257 // TODO(johnniwinther): Use the [callStructure]. |
| 259 return new StaticUse.internal(element, StaticUseKind.GENERAL); | 258 return new StaticUse.internal(element, StaticUseKind.GENERAL); |
| 260 } | 259 } |
| 261 | 260 |
| 262 /// Constructor invocation of [element] with the given [callStructure] on | 261 /// Constructor invocation of [element] with the given [callStructure] on |
| 263 /// [type]. | 262 /// [type]. |
| 264 factory StaticUse.typedConstructorInvoke( | 263 factory StaticUse.typedConstructorInvoke( |
| 265 FunctionEntity element, CallStructure callStructure, DartType type) { | 264 ConstructorEntity element, CallStructure callStructure, DartType type) { |
| 266 assert(invariant(element, type != null, | 265 assert(invariant(element, type != null, |
| 267 message: "No type provided for constructor invocation.")); | 266 message: "No type provided for constructor invocation.")); |
| 268 assert(invariant(element, element.isConstructor, | 267 assert(invariant(element, element.isConstructor, |
| 269 message: "Typed constructor invocation element $element " | 268 message: "Typed constructor invocation element $element " |
| 270 "must be a constructor.")); | 269 "must be a constructor.")); |
| 271 // TODO(johnniwinther): Use the [callStructure]. | 270 // TODO(johnniwinther): Use the [callStructure]. |
| 272 return new StaticUse.internal( | 271 return new StaticUse.internal( |
| 273 element, StaticUseKind.CONSTRUCTOR_INVOKE, type); | 272 element, StaticUseKind.CONSTRUCTOR_INVOKE, type); |
| 274 } | 273 } |
| 275 | 274 |
| 276 /// Constant constructor invocation of [element] with the given | 275 /// Constant constructor invocation of [element] with the given |
| 277 /// [callStructure] on [type]. | 276 /// [callStructure] on [type]. |
| 278 factory StaticUse.constConstructorInvoke( | 277 factory StaticUse.constConstructorInvoke( |
| 279 FunctionEntity element, CallStructure callStructure, DartType type) { | 278 ConstructorEntity element, CallStructure callStructure, DartType type) { |
| 280 assert(invariant(element, type != null, | 279 assert(invariant(element, type != null, |
| 281 message: "No type provided for constructor invocation.")); | 280 message: "No type provided for constructor invocation.")); |
| 282 assert(invariant(element, element.isConstructor, | 281 assert(invariant(element, element.isConstructor, |
| 283 message: "Const constructor invocation element $element " | 282 message: "Const constructor invocation element $element " |
| 284 "must be a constructor.")); | 283 "must be a constructor.")); |
| 285 // TODO(johnniwinther): Use the [callStructure]. | 284 // TODO(johnniwinther): Use the [callStructure]. |
| 286 return new StaticUse.internal( | 285 return new StaticUse.internal( |
| 287 element, StaticUseKind.CONST_CONSTRUCTOR_INVOKE, type); | 286 element, StaticUseKind.CONST_CONSTRUCTOR_INVOKE, type); |
| 288 } | 287 } |
| 289 | 288 |
| 290 /// Constructor redirection to [element] on [type]. | 289 /// Constructor redirection to [element] on [type]. |
| 291 factory StaticUse.constructorRedirect( | 290 factory StaticUse.constructorRedirect( |
| 292 FunctionEntity element, InterfaceType type) { | 291 ConstructorEntity element, InterfaceType type) { |
| 293 assert(invariant(element, type != null, | 292 assert(invariant(element, type != null, |
| 294 message: "No type provided for constructor redirection.")); | 293 message: "No type provided for constructor redirection.")); |
| 295 assert(invariant(element, element.isConstructor, | 294 assert(invariant(element, element.isConstructor, |
| 296 message: "Constructor redirection element $element " | 295 message: "Constructor redirection element $element " |
| 297 "must be a constructor.")); | 296 "must be a constructor.")); |
| 298 return new StaticUse.internal(element, StaticUseKind.REDIRECTION, type); | 297 return new StaticUse.internal(element, StaticUseKind.REDIRECTION, type); |
| 299 } | 298 } |
| 300 | 299 |
| 301 /// Initialization of an instance field [element]. | 300 /// Initialization of an instance field [element]. |
| 302 factory StaticUse.fieldInit(FieldEntity element) { | 301 factory StaticUse.fieldInit(FieldEntity element) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 } | 413 } |
| 415 | 414 |
| 416 bool operator ==(other) { | 415 bool operator ==(other) { |
| 417 if (identical(this, other)) return true; | 416 if (identical(this, other)) return true; |
| 418 if (other is! TypeUse) return false; | 417 if (other is! TypeUse) return false; |
| 419 return type == other.type && kind == other.kind; | 418 return type == other.type && kind == other.kind; |
| 420 } | 419 } |
| 421 | 420 |
| 422 String toString() => 'TypeUse($type,$kind)'; | 421 String toString() => 'TypeUse($type,$kind)'; |
| 423 } | 422 } |
| OLD | NEW |