| 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 library dart2js.world; | 5 library dart2js.world; |
| 6 | 6 |
| 7 import 'closure.dart' show ClosureClassElement; | |
| 8 import 'common.dart'; | 7 import 'common.dart'; |
| 9 import 'constants/constant_system.dart'; | 8 import 'constants/constant_system.dart'; |
| 10 import 'common_elements.dart' show CommonElements, ElementEnvironment; | 9 import 'common_elements.dart' show CommonElements, ElementEnvironment; |
| 11 import 'elements/entities.dart'; | 10 import 'elements/entities.dart'; |
| 12 import 'elements/elements.dart' | 11 import 'elements/elements.dart' |
| 13 show | 12 show |
| 14 ClassElement, | 13 ClassElement, |
| 15 Element, | 14 Element, |
| 16 MemberElement, | 15 MemberElement, |
| 17 MethodElement, | 16 MethodElement, |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 bool getCurrentlyKnownMightBePassedToApply(FunctionEntity element); | 368 bool getCurrentlyKnownMightBePassedToApply(FunctionEntity element); |
| 370 | 369 |
| 371 /// Registers that [element] is called in a loop. | 370 /// Registers that [element] is called in a loop. |
| 372 // TODO(johnniwinther): Is this 'potentially called' or 'known to be called'? | 371 // TODO(johnniwinther): Is this 'potentially called' or 'known to be called'? |
| 373 void addFunctionCalledInLoop(MemberEntity element); | 372 void addFunctionCalledInLoop(MemberEntity element); |
| 374 | 373 |
| 375 /// Registers that [element] is guaranteed not to throw an exception. | 374 /// Registers that [element] is guaranteed not to throw an exception. |
| 376 void registerCannotThrow(FunctionEntity element); | 375 void registerCannotThrow(FunctionEntity element); |
| 377 | 376 |
| 378 /// Adds the closure class [cls] to the inference world. The class is | 377 /// Adds the closure class [cls] to the inference world. The class is |
| 379 /// considered directly instantiated. | 378 /// considered directly instantiated. If [fromInstanceMember] is true, this |
| 380 void registerClosureClass(covariant ClassElement cls); | 379 /// closure class represents a closure that is inside an instance member, thus |
| 380 /// has access to `this`. |
| 381 void registerClosureClass(covariant ClassEntity cls, bool fromInstanceMember); |
| 381 } | 382 } |
| 382 | 383 |
| 383 abstract class OpenWorld implements World { | 384 abstract class OpenWorld implements World { |
| 384 /// Called to add [cls] to the set of known classes. | 385 /// Called to add [cls] to the set of known classes. |
| 385 /// | 386 /// |
| 386 /// This ensures that class hierarchy queries can be performed on [cls] and | 387 /// This ensures that class hierarchy queries can be performed on [cls] and |
| 387 /// classes that extend or implement it. | 388 /// classes that extend or implement it. |
| 388 void registerClass(covariant ClassEntity cls); | 389 void registerClass(covariant ClassEntity cls); |
| 389 | 390 |
| 390 void registerUsedElement(MemberEntity element); | 391 void registerUsedElement(MemberEntity element); |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 StringBuffer sb = new StringBuffer(); | 1172 StringBuffer sb = new StringBuffer(); |
| 1172 if (cls != null) { | 1173 if (cls != null) { |
| 1173 sb.write("Classes in the closed world related to $cls:\n"); | 1174 sb.write("Classes in the closed world related to $cls:\n"); |
| 1174 } else { | 1175 } else { |
| 1175 sb.write("Instantiated classes in the closed world:\n"); | 1176 sb.write("Instantiated classes in the closed world:\n"); |
| 1176 } | 1177 } |
| 1177 getClassHierarchyNode(commonElements.objectClass) | 1178 getClassHierarchyNode(commonElements.objectClass) |
| 1178 .printOn(sb, ' ', instantiatedOnly: cls == null, withRespectTo: cls); | 1179 .printOn(sb, ' ', instantiatedOnly: cls == null, withRespectTo: cls); |
| 1179 return sb.toString(); | 1180 return sb.toString(); |
| 1180 } | 1181 } |
| 1182 |
| 1183 /// Should only be called by subclasses. |
| 1184 void addClassHierarchyNode(ClassEntity cls, ClassHierarchyNode node) { |
| 1185 _classHierarchyNodes[cls] = node; |
| 1186 } |
| 1187 |
| 1188 /// Should only be called by subclasses. |
| 1189 void addClassSet(ClassEntity cls, ClassSet classSet) { |
| 1190 _classSets[cls] = classSet; |
| 1191 } |
| 1181 } | 1192 } |
| 1182 | 1193 |
| 1183 class ClosedWorldImpl extends ClosedWorldBase with ClosedWorldRtiNeedMixin { | 1194 class ClosedWorldImpl extends ClosedWorldBase with ClosedWorldRtiNeedMixin { |
| 1184 ClosedWorldImpl( | 1195 ClosedWorldImpl( |
| 1185 {CompilerOptions options, | 1196 {CompilerOptions options, |
| 1186 ElementEnvironment elementEnvironment, | 1197 ElementEnvironment elementEnvironment, |
| 1187 DartTypes dartTypes, | 1198 DartTypes dartTypes, |
| 1188 CommonElements commonElements, | 1199 CommonElements commonElements, |
| 1189 ConstantSystem constantSystem, | 1200 ConstantSystem constantSystem, |
| 1190 NativeData nativeData, | 1201 NativeData nativeData, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 MemberElement element = findMatchIn(cls, selector); | 1301 MemberElement element = findMatchIn(cls, selector); |
| 1291 if (element == null) return false; | 1302 if (element == null) return false; |
| 1292 | 1303 |
| 1293 if (element.isAbstract) { | 1304 if (element.isAbstract) { |
| 1294 ClassElement enclosingClass = element.enclosingClass; | 1305 ClassElement enclosingClass = element.enclosingClass; |
| 1295 return hasConcreteMatch(enclosingClass.superclass, selector); | 1306 return hasConcreteMatch(enclosingClass.superclass, selector); |
| 1296 } | 1307 } |
| 1297 return selector.appliesUntyped(element); | 1308 return selector.appliesUntyped(element); |
| 1298 } | 1309 } |
| 1299 | 1310 |
| 1300 void registerClosureClass(ClosureClassElement cls) { | 1311 void registerClosureClass(ClassElement cls, bool _) { |
| 1301 ClassHierarchyNode parentNode = getClassHierarchyNode(cls.superclass); | 1312 ClassHierarchyNode parentNode = getClassHierarchyNode(cls.superclass); |
| 1302 ClassHierarchyNode node = _classHierarchyNodes[cls] = | 1313 ClassHierarchyNode node = _classHierarchyNodes[cls] = |
| 1303 new ClassHierarchyNode(parentNode, cls, cls.hierarchyDepth); | 1314 new ClassHierarchyNode(parentNode, cls, cls.hierarchyDepth); |
| 1304 for (ResolutionInterfaceType type in cls.allSupertypes) { | 1315 for (ResolutionInterfaceType type in cls.allSupertypes) { |
| 1305 ClassSet subtypeSet = getClassSet(type.element); | 1316 ClassSet subtypeSet = getClassSet(type.element); |
| 1306 subtypeSet.addSubtype(node); | 1317 subtypeSet.addSubtype(node); |
| 1307 } | 1318 } |
| 1308 _classSets[cls] = new ClassSet(node); | 1319 _classSets[cls] = new ClassSet(node); |
| 1309 _updateSuperClassHierarchyNodeForClass(node); | 1320 _updateSuperClassHierarchyNodeForClass(node); |
| 1310 node.isDirectlyInstantiated = true; | 1321 node.isDirectlyInstantiated = true; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1343 void computeRtiNeed(ResolutionWorldBuilder resolutionWorldBuilder, | 1354 void computeRtiNeed(ResolutionWorldBuilder resolutionWorldBuilder, |
| 1344 RuntimeTypesNeedBuilder rtiNeedBuilder, | 1355 RuntimeTypesNeedBuilder rtiNeedBuilder, |
| 1345 {bool enableTypeAssertions}) { | 1356 {bool enableTypeAssertions}) { |
| 1346 _rtiNeed = rtiNeedBuilder.computeRuntimeTypesNeed( | 1357 _rtiNeed = rtiNeedBuilder.computeRuntimeTypesNeed( |
| 1347 resolutionWorldBuilder, this, | 1358 resolutionWorldBuilder, this, |
| 1348 enableTypeAssertions: enableTypeAssertions); | 1359 enableTypeAssertions: enableTypeAssertions); |
| 1349 } | 1360 } |
| 1350 | 1361 |
| 1351 RuntimeTypesNeed get rtiNeed => _rtiNeed; | 1362 RuntimeTypesNeed get rtiNeed => _rtiNeed; |
| 1352 } | 1363 } |
| OLD | NEW |