OLD | NEW |
---|---|
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.kernel.element_map; | 5 library dart2js.kernel.element_map; |
6 | 6 |
7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
8 | 8 |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common/names.dart' show Identifiers; | 10 import '../common/names.dart' show Identifiers; |
(...skipping 10 matching lines...) Expand all Loading... | |
21 import '../elements/names.dart'; | 21 import '../elements/names.dart'; |
22 import '../elements/types.dart'; | 22 import '../elements/types.dart'; |
23 import '../environment.dart'; | 23 import '../environment.dart'; |
24 import '../frontend_strategy.dart'; | 24 import '../frontend_strategy.dart'; |
25 import '../js_backend/backend_usage.dart'; | 25 import '../js_backend/backend_usage.dart'; |
26 import '../js_backend/constant_system_javascript.dart'; | 26 import '../js_backend/constant_system_javascript.dart'; |
27 import '../js_backend/interceptor_data.dart'; | 27 import '../js_backend/interceptor_data.dart'; |
28 import '../js_backend/native_data.dart'; | 28 import '../js_backend/native_data.dart'; |
29 import '../js_backend/no_such_method_registry.dart'; | 29 import '../js_backend/no_such_method_registry.dart'; |
30 import '../js_backend/runtime_types.dart'; | 30 import '../js_backend/runtime_types.dart'; |
31 import '../js_model/closure.dart'; | |
31 import '../js_model/elements.dart'; | 32 import '../js_model/elements.dart'; |
32 import '../native/enqueue.dart'; | 33 import '../native/enqueue.dart'; |
33 import '../native/native.dart' as native; | 34 import '../native/native.dart' as native; |
34 import '../native/resolver.dart'; | 35 import '../native/resolver.dart'; |
35 import '../ordered_typeset.dart'; | 36 import '../ordered_typeset.dart'; |
36 import '../options.dart'; | 37 import '../options.dart'; |
37 import '../universe/class_set.dart'; | 38 import '../universe/class_set.dart'; |
38 import '../universe/selector.dart'; | 39 import '../universe/selector.dart'; |
39 import '../universe/world_builder.dart'; | 40 import '../universe/world_builder.dart'; |
40 import '../world.dart'; | 41 import '../world.dart'; |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 String path = canonicalUri.path; | 650 String path = canonicalUri.path; |
650 name = path.substring(path.lastIndexOf('/') + 1); | 651 name = path.substring(path.lastIndexOf('/') + 1); |
651 } | 652 } |
652 LibraryEntity library = | 653 LibraryEntity library = |
653 createLibrary(_libraryMap.length, name, canonicalUri); | 654 createLibrary(_libraryMap.length, name, canonicalUri); |
654 _libraryList.add(library); | 655 _libraryList.add(library); |
655 return library; | 656 return library; |
656 }); | 657 }); |
657 } | 658 } |
658 | 659 |
660 void addClosureClass(KernelClosureClass cls, InterfaceType supertype) { | |
661 cls.classIndex = _classEnvs.length; | |
662 _classEnvs.add(new ClassEnv.closureClass()); | |
663 _classList.add(cls); | |
664 | |
665 // Create a classData and set up the interfaces and subclass | |
666 // relationships that _ensureSupertypes and _ensureThisAndRawType are doing | |
667 var closureData = new ClassData(null); | |
668 closureData.isMixinApplication = false; | |
Siggi Cherem (dart-lang)
2017/07/12 21:25:03
nit: let's use cascades :)
Emily Fortuna
2017/07/12 22:02:18
That was my plan before, but I must have had a syn
| |
669 closureData.thisType = | |
670 closureData.rawType = new InterfaceType(cls, const/*<DartType>*/ []); | |
671 closureData.supertype = supertype; | |
672 closureData.interfaces = const <InterfaceType>[]; | |
673 var setBuilder = | |
674 new _KernelOrderedTypeSetBuilder((this as KernelToElementMapBase), cls); | |
675 _classData.add(closureData); | |
676 closureData.orderedTypeSet = setBuilder.createOrderedTypeSet( | |
677 closureData.supertype, const Link<InterfaceType>()); | |
678 // TODO(efortuna): Does getMetadata get called in ClassData for this object? | |
679 } | |
680 | |
659 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) { | 681 ClassEntity _getClass(ir.Class node, [ClassEnv classEnv]) { |
660 return _classMap.putIfAbsent(node, () { | 682 return _classMap.putIfAbsent(node, () { |
661 KLibrary library = _getLibrary(node.enclosingLibrary); | 683 KLibrary library = _getLibrary(node.enclosingLibrary); |
662 if (classEnv == null) { | 684 if (classEnv == null) { |
663 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name); | 685 classEnv = _libraryEnvs[library.libraryIndex].lookupClass(node.name); |
664 } | 686 } |
665 _classEnvs.add(classEnv); | 687 _classEnvs.add(classEnv); |
666 _classData.add(new ClassData(node)); | 688 _classData.add(new ClassData(node)); |
667 ClassEntity cls = createClass(library, _classMap.length, node.name, | 689 ClassEntity cls = createClass(library, _classList.length, node.name, |
668 isAbstract: node.isAbstract); | 690 isAbstract: node.isAbstract); |
669 _classList.add(cls); | 691 _classList.add(cls); |
670 return cls; | 692 return cls; |
671 }); | 693 }); |
672 } | 694 } |
673 | 695 |
674 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) { | 696 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) { |
675 return _typeVariableMap.putIfAbsent(node, () { | 697 return _typeVariableMap.putIfAbsent(node, () { |
676 if (node.parent is ir.Class) { | 698 if (node.parent is ir.Class) { |
677 int typeVariableIndex = _typeVariableList.length; | 699 int typeVariableIndex = _typeVariableList.length; |
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1529 throw new UnimplementedError('KernelClosedWorldMixin.getAppliedMixin'); | 1551 throw new UnimplementedError('KernelClosedWorldMixin.getAppliedMixin'); |
1530 } | 1552 } |
1531 | 1553 |
1532 @override | 1554 @override |
1533 Iterable<ClassEntity> getInterfaces(ClassEntity cls) { | 1555 Iterable<ClassEntity> getInterfaces(ClassEntity cls) { |
1534 throw new UnimplementedError('KernelClosedWorldMixin.getInterfaces'); | 1556 throw new UnimplementedError('KernelClosedWorldMixin.getInterfaces'); |
1535 } | 1557 } |
1536 | 1558 |
1537 @override | 1559 @override |
1538 ClassEntity getSuperClass(ClassEntity cls) { | 1560 ClassEntity getSuperClass(ClassEntity cls) { |
1539 throw new UnimplementedError('KernelClosedWorldMixin.getSuperClass'); | 1561 return elementMap._getSuperType(cls)?.element; |
1540 } | 1562 } |
1541 | 1563 |
1542 @override | 1564 @override |
1543 int getHierarchyDepth(ClassEntity cls) { | 1565 int getHierarchyDepth(ClassEntity cls) { |
1544 return elementMap._getHierarchyDepth(cls); | 1566 return elementMap._getHierarchyDepth(cls); |
1545 } | 1567 } |
1546 | 1568 |
1547 @override | 1569 @override |
1548 OrderedTypeSet getOrderedTypeSet(ClassEntity cls) { | 1570 OrderedTypeSet getOrderedTypeSet(ClassEntity cls) { |
1549 return elementMap._getOrderedTypeSet(cls); | 1571 return elementMap._getOrderedTypeSet(cls); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1599 allTypedefs, | 1621 allTypedefs, |
1600 mixinUses, | 1622 mixinUses, |
1601 typesImplementedBySubclasses, | 1623 typesImplementedBySubclasses, |
1602 classHierarchyNodes, | 1624 classHierarchyNodes, |
1603 classSets) { | 1625 classSets) { |
1604 computeRtiNeed(resolutionWorldBuilder, rtiNeedBuilder, | 1626 computeRtiNeed(resolutionWorldBuilder, rtiNeedBuilder, |
1605 enableTypeAssertions: options.enableTypeAssertions); | 1627 enableTypeAssertions: options.enableTypeAssertions); |
1606 } | 1628 } |
1607 | 1629 |
1608 @override | 1630 @override |
1609 void registerClosureClass(ClassElement cls) { | 1631 void registerClosureClass(ClassEntity cls, bool isInstanceMember) { |
1610 throw new UnimplementedError('KernelClosedWorld.registerClosureClass'); | 1632 // Tell the hierarchy that this is the super class. then we can use |
1633 // .getSupertypes(class) | |
1634 IndexedClass superclass = isInstanceMember | |
1635 ? commonElements.boundClosureClass | |
1636 : commonElements.closureClass; | |
1637 ClassHierarchyNode parentNode = getClassHierarchyNode(superclass); | |
1638 ClassHierarchyNode node = new ClassHierarchyNode( | |
1639 parentNode, cls, getHierarchyDepth(superclass) + 1); | |
1640 addClassHierarchyNode(cls, node); | |
1641 for (InterfaceType type in getOrderedTypeSet(superclass).types) { | |
1642 // TODO(efortuna): assert that the FunctionClass is in this ordered set. | |
1643 // If not, we need to explicitly add node as a subtype of FunctionClass. | |
1644 ClassSet subtypeSet = getClassSet(type.element); | |
1645 subtypeSet.addSubtype(node); | |
1646 } | |
1647 addClassSet(cls, new ClassSet(node)); | |
1648 | |
1649 // Ensure that the supertype's hierarchy is completely set up. | |
1650 var supertype = new InterfaceType(superclass, const []); | |
1651 ClassData superdata = elementMap._classData[superclass.classIndex]; | |
1652 elementMap._ensureSupertypes(superclass, superdata); | |
1653 elementMap._ensureThisAndRawType(superclass, superdata); | |
1654 | |
1655 elementMap.addClosureClass(cls, supertype); | |
1656 node.isDirectlyInstantiated = true; | |
1611 } | 1657 } |
1612 } | 1658 } |
1613 | 1659 |
1614 // Interface for testing equivalence of Kernel-based entities. | 1660 // Interface for testing equivalence of Kernel-based entities. |
1615 class WorldDeconstructionForTesting { | 1661 class WorldDeconstructionForTesting { |
1616 final KernelToElementMapBase elementMap; | 1662 final KernelToElementMapBase elementMap; |
1617 | 1663 |
1618 WorldDeconstructionForTesting(this.elementMap); | 1664 WorldDeconstructionForTesting(this.elementMap); |
1619 | 1665 |
1620 IndexedClass getSuperclassForClass(IndexedClass cls) { | 1666 IndexedClass getSuperclassForClass(IndexedClass cls) { |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1921 if (data.constructorBody != null) { | 1967 if (data.constructorBody != null) { |
1922 f(data.constructorBody); | 1968 f(data.constructorBody); |
1923 } | 1969 } |
1924 }); | 1970 }); |
1925 } | 1971 } |
1926 | 1972 |
1927 String getDeferredUri(ir.LibraryDependency node) { | 1973 String getDeferredUri(ir.LibraryDependency node) { |
1928 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); | 1974 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); |
1929 } | 1975 } |
1930 } | 1976 } |
OLD | NEW |