Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Side by Side Diff: pkg/compiler/lib/src/kernel/element_map_impl.dart

Issue 2970673004: Handle static fields in js_model/model_test (Closed)
Patch Set: Updated cf. comment Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/js_model/js_strategy.dart ('k') | pkg/compiler/lib/src/world.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 with 965 with
966 KernelToElementMapForImpactMixin, 966 KernelToElementMapForImpactMixin,
967 KernelToElementMapForImpactImpl, 967 KernelToElementMapForImpactImpl,
968 ElementCreatorMixin, 968 ElementCreatorMixin,
969 KElementCreatorMixin { 969 KElementCreatorMixin {
970 KernelToElementMapForImpactImpl2( 970 KernelToElementMapForImpactImpl2(
971 DiagnosticReporter reporter, Environment environment) 971 DiagnosticReporter reporter, Environment environment)
972 : super(reporter, environment); 972 : super(reporter, environment);
973 } 973 }
974 974
975 /// Element builder used for creating elements and types corresponding to Kernel 975 /// Mixin for implementing [KernelToElementMapForBuilding] shared between
976 /// IR nodes. 976 /// classes that extend [KernelToElementMapBase], i.e. not [KernelAstAdapter].
977 // TODO(johnniwinther): Use this in the JsStrategy 977 abstract class KernelToElementMapForBuildingFromBaseMixin
978 class KernelToElementMapForBuildingImpl extends KernelToElementMapBase 978 implements KernelToElementMapForBuilding, KernelToElementMapBase {
979 with
980 KernelToElementMapForBuildingMixin,
981 ElementCreatorMixin,
982 KElementCreatorMixin
983 implements KernelToWorldBuilder {
984 KernelToElementMapForBuildingImpl(
985 DiagnosticReporter reporter, Environment environment)
986 : super(reporter, environment);
987
988 ConstantEnvironment get constantEnvironment => _constantEnvironment;
989
990 @override 979 @override
991 ConstantValue getFieldConstantValue(ir.Field field) { 980 ConstantValue getFieldConstantValue(ir.Field field) {
992 // TODO(johnniwinther): Cache the result in [FieldData]. 981 // TODO(johnniwinther): Cache the result in [FieldData].
993 return getConstantValue(field.initializer, 982 return getConstantValue(field.initializer,
994 requireConstant: field.isConst, implicitNull: !field.isConst); 983 requireConstant: field.isConst, implicitNull: !field.isConst);
995 } 984 }
996 985
997 ir.Library getKernelLibrary(KLibrary entity) => 986 bool hasConstantFieldInitializer(covariant IndexedField field) {
998 _libraryEnvs[entity.libraryIndex].library;
999
1000 ir.Class getKernelClass(KClass entity) => _classEnvs[entity.classIndex].cls;
1001
1002 bool hasConstantFieldInitializer(covariant KField field) {
1003 FieldData data = _memberData[field.memberIndex]; 987 FieldData data = _memberData[field.memberIndex];
1004 return getFieldConstantValue(data.node) != null; 988 return getFieldConstantValue(data.node) != null;
1005 } 989 }
1006 990
1007 ConstantValue getConstantFieldInitializer(covariant KField field) { 991 ConstantValue getConstantFieldInitializer(covariant IndexedField field) {
1008 FieldData data = _memberData[field.memberIndex]; 992 FieldData data = _memberData[field.memberIndex];
1009 ConstantValue value = getFieldConstantValue(data.node); 993 ConstantValue value = getFieldConstantValue(data.node);
1010 assert(value != null, 994 assert(value != null,
1011 failedAt(field, "Field $field doesn't have a constant initial value.")); 995 failedAt(field, "Field $field doesn't have a constant initial value."));
1012 return value; 996 return value;
1013 } 997 }
1014 998
1015 void forEachParameter(covariant KFunction function, 999 void forEachParameter(covariant IndexedFunction function,
1016 void f(DartType type, String name, ConstantValue defaultValue)) { 1000 void f(DartType type, String name, ConstantValue defaultValue)) {
1017 FunctionData data = _memberData[function.memberIndex]; 1001 FunctionData data = _memberData[function.memberIndex];
1018 data.forEachParameter(this, f); 1002 data.forEachParameter(this, f);
1019 } 1003 }
1004 }
1005
1006 /// Element builder used for creating elements and types corresponding to Kernel
1007 /// IR nodes.
1008 // TODO(johnniwinther): Use this in the JsStrategy
1009 class KernelToElementMapForBuildingImpl extends KernelToElementMapBase
1010 with
1011 KernelToElementMapForBuildingMixin,
1012 KernelToElementMapForBuildingFromBaseMixin,
1013 ElementCreatorMixin,
1014 KElementCreatorMixin
1015 implements KernelToWorldBuilder {
1016 KernelToElementMapForBuildingImpl(
1017 DiagnosticReporter reporter, Environment environment)
1018 : super(reporter, environment);
1019
1020 ConstantEnvironment get constantEnvironment => _constantEnvironment;
1021
1022 ir.Library getKernelLibrary(KLibrary entity) =>
1023 _libraryEnvs[entity.libraryIndex].library;
1024
1025 ir.Class getKernelClass(KClass entity) => _classEnvs[entity.classIndex].cls;
1020 1026
1021 @override 1027 @override
1022 Spannable getSpannable(MemberEntity member, ir.Node node) { 1028 Spannable getSpannable(MemberEntity member, ir.Node node) {
1023 return _getSpannable(member, node); 1029 return _getSpannable(member, node);
1024 } 1030 }
1025 1031
1026 @override 1032 @override
1027 ir.Member getMemberNode(MemberEntity member) { 1033 ir.Member getMemberNode(MemberEntity member) {
1028 return _getMemberNode(member); 1034 return _getMemberNode(member);
1029 } 1035 }
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1460 return elementMap._getAppliedMixin(cls); 1466 return elementMap._getAppliedMixin(cls);
1461 } 1467 }
1462 1468
1463 @override 1469 @override
1464 bool validateClass(ClassEntity cls) => true; 1470 bool validateClass(ClassEntity cls) => true;
1465 1471
1466 @override 1472 @override
1467 bool checkClass(ClassEntity cls) => true; 1473 bool checkClass(ClassEntity cls) => true;
1468 } 1474 }
1469 1475
1470 abstract class KernelClosedWorldMixin implements ClosedWorld { 1476 abstract class KernelClosedWorldMixin implements ClosedWorldBase {
1477 KernelToElementMapBase get elementMap;
1478
1471 @override 1479 @override
1472 bool hasElementIn(ClassEntity cls, Selector selector, Entity element) { 1480 bool hasElementIn(ClassEntity cls, Selector selector, Entity element) {
1473 while (cls != null) { 1481 while (cls != null) {
1474 MemberEntity member = elementEnvironment 1482 MemberEntity member = elementEnvironment
1475 .lookupClassMember(cls, selector.name, setter: selector.isSetter); 1483 .lookupClassMember(cls, selector.name, setter: selector.isSetter);
1476 if (member != null && 1484 if (member != null &&
1477 (!selector.memberName.isPrivate || 1485 (!selector.memberName.isPrivate ||
1478 member.library == selector.library)) { 1486 member.library == selector.library)) {
1479 return member == element; 1487 return member == element;
1480 } 1488 }
1481 cls = elementEnvironment.getSuperClass(cls); 1489 cls = elementEnvironment.getSuperClass(cls);
1482 } 1490 }
1483 return false; 1491 return false;
1484 } 1492 }
1485 }
1486
1487 class KernelClosedWorld extends ClosedWorldBase with KernelClosedWorldMixin {
1488 final KernelToElementMapForImpactImpl _elementMap;
1489
1490 KernelClosedWorld(this._elementMap,
1491 {ElementEnvironment elementEnvironment,
1492 DartTypes dartTypes,
1493 CommonElements commonElements,
1494 ConstantSystem constantSystem,
1495 NativeData nativeData,
1496 InterceptorData interceptorData,
1497 BackendUsage backendUsage,
1498 ResolutionWorldBuilder resolutionWorldBuilder,
1499 Set<ClassEntity> implementedClasses,
1500 Iterable<MemberEntity> liveInstanceMembers,
1501 Set<TypedefElement> allTypedefs,
1502 Map<ClassEntity, Set<ClassEntity>> mixinUses,
1503 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses,
1504 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes,
1505 Map<ClassEntity, ClassSet> classSets})
1506 : super(
1507 elementEnvironment,
1508 dartTypes,
1509 commonElements,
1510 constantSystem,
1511 nativeData,
1512 interceptorData,
1513 backendUsage,
1514 resolutionWorldBuilder,
1515 implementedClasses,
1516 liveInstanceMembers,
1517 allTypedefs,
1518 mixinUses,
1519 typesImplementedBySubclasses,
1520 classHierarchyNodes,
1521 classSets);
1522 1493
1523 @override 1494 @override
1524 bool hasConcreteMatch(ClassEntity cls, Selector selector, 1495 bool hasConcreteMatch(ClassEntity cls, Selector selector,
1525 {ClassEntity stopAtSuperclass}) { 1496 {ClassEntity stopAtSuperclass}) {
1526 throw new UnimplementedError('KernelClosedWorld.hasConcreteMatch'); 1497 throw new UnimplementedError('KernelClosedWorldMixin.hasConcreteMatch');
1527 } 1498 }
1528 1499
1529 @override 1500 @override
1530 bool isNamedMixinApplication(ClassEntity cls) { 1501 bool isNamedMixinApplication(ClassEntity cls) {
1531 throw new UnimplementedError('KernelClosedWorld.isNamedMixinApplication'); 1502 throw new UnimplementedError(
1503 'KernelClosedWorldMixin.isNamedMixinApplication');
1532 } 1504 }
1533 1505
1534 @override 1506 @override
1535 ClassEntity getAppliedMixin(ClassEntity cls) { 1507 ClassEntity getAppliedMixin(ClassEntity cls) {
1536 throw new UnimplementedError('KernelClosedWorld.getAppliedMixin'); 1508 throw new UnimplementedError('KernelClosedWorldMixin.getAppliedMixin');
1537 } 1509 }
1538 1510
1539 @override 1511 @override
1540 Iterable<ClassEntity> getInterfaces(ClassEntity cls) { 1512 Iterable<ClassEntity> getInterfaces(ClassEntity cls) {
1541 throw new UnimplementedError('KernelClosedWorld.getInterfaces'); 1513 throw new UnimplementedError('KernelClosedWorldMixin.getInterfaces');
1542 } 1514 }
1543 1515
1544 @override 1516 @override
1545 ClassEntity getSuperClass(ClassEntity cls) { 1517 ClassEntity getSuperClass(ClassEntity cls) {
1546 throw new UnimplementedError('KernelClosedWorld.getSuperClass'); 1518 throw new UnimplementedError('KernelClosedWorldMixin.getSuperClass');
1547 } 1519 }
1548 1520
1549 @override 1521 @override
1550 int getHierarchyDepth(ClassEntity cls) { 1522 int getHierarchyDepth(ClassEntity cls) {
1551 return _elementMap._getHierarchyDepth(cls); 1523 return elementMap._getHierarchyDepth(cls);
1552 } 1524 }
1553 1525
1554 @override 1526 @override
1555 OrderedTypeSet getOrderedTypeSet(ClassEntity cls) { 1527 OrderedTypeSet getOrderedTypeSet(ClassEntity cls) {
1556 return _elementMap._getOrderedTypeSet(cls); 1528 return elementMap._getOrderedTypeSet(cls);
1557 } 1529 }
1558 1530
1559 @override 1531 @override
1560 bool checkInvariants(ClassEntity cls, {bool mustBeInstantiated: true}) => 1532 bool checkInvariants(ClassEntity cls, {bool mustBeInstantiated: true}) =>
1561 true; 1533 true;
1562 1534
1563 @override 1535 @override
1564 bool checkClass(ClassEntity cls) => true; 1536 bool checkClass(ClassEntity cls) => true;
1565 1537
1566 @override 1538 @override
1567 bool checkEntity(Entity element) => true; 1539 bool checkEntity(Entity element) => true;
1540 }
1541
1542 class KernelClosedWorld extends ClosedWorldBase with KernelClosedWorldMixin {
1543 final KernelToElementMapForImpactImpl elementMap;
1544
1545 KernelClosedWorld(this.elementMap,
1546 {ElementEnvironment elementEnvironment,
1547 DartTypes dartTypes,
1548 CommonElements commonElements,
1549 ConstantSystem constantSystem,
1550 NativeData nativeData,
1551 InterceptorData interceptorData,
1552 BackendUsage backendUsage,
1553 ResolutionWorldBuilder resolutionWorldBuilder,
1554 Set<ClassEntity> implementedClasses,
1555 Iterable<MemberEntity> liveInstanceMembers,
1556 Set<TypedefElement> allTypedefs,
1557 Map<ClassEntity, Set<ClassEntity>> mixinUses,
1558 Map<ClassEntity, Set<ClassEntity>> typesImplementedBySubclasses,
1559 Map<ClassEntity, ClassHierarchyNode> classHierarchyNodes,
1560 Map<ClassEntity, ClassSet> classSets})
1561 : super(
1562 elementEnvironment,
1563 dartTypes,
1564 commonElements,
1565 constantSystem,
1566 nativeData,
1567 interceptorData,
1568 backendUsage,
1569 resolutionWorldBuilder,
1570 implementedClasses,
1571 liveInstanceMembers,
1572 allTypedefs,
1573 mixinUses,
1574 typesImplementedBySubclasses,
1575 classHierarchyNodes,
1576 classSets);
1568 1577
1569 @override 1578 @override
1570 void registerClosureClass(ClassElement cls) { 1579 void registerClosureClass(ClassElement cls) {
1571 throw new UnimplementedError('KernelClosedWorld.registerClosureClass'); 1580 throw new UnimplementedError('KernelClosedWorld.registerClosureClass');
1572 } 1581 }
1573 } 1582 }
1574 1583
1575 // Interface for testing equivalence of Kernel-based entities. 1584 // Interface for testing equivalence of Kernel-based entities.
1576 class WorldDeconstructionForTesting { 1585 class WorldDeconstructionForTesting {
1577 final KernelToElementMapBase elementMap; 1586 final KernelToElementMapBase elementMap;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 } 1688 }
1680 1689
1681 MemberEntity toFrontendMember(covariant IndexedMember member) { 1690 MemberEntity toFrontendMember(covariant IndexedMember member) {
1682 return _frontend._memberList[member.memberIndex]; 1691 return _frontend._memberList[member.memberIndex];
1683 } 1692 }
1684 } 1693 }
1685 1694
1686 class JsKernelToElementMap extends KernelToElementMapBase 1695 class JsKernelToElementMap extends KernelToElementMapBase
1687 with 1696 with
1688 KernelToElementMapForBuildingMixin, 1697 KernelToElementMapForBuildingMixin,
1698 KernelToElementMapForBuildingFromBaseMixin,
1689 JsElementCreatorMixin, 1699 JsElementCreatorMixin,
1690 // TODO(johnniwinther): Avoid mixin in [ElementCreatorMixin]. The 1700 // TODO(johnniwinther): Avoid mixin in [ElementCreatorMixin]. The
1691 // codegen world should be a strict subset of the resolution world and 1701 // codegen world should be a strict subset of the resolution world and
1692 // creating elements for IR nodes should therefore not be needed. 1702 // creating elements for IR nodes should therefore not be needed.
1693 // Currently some are created purely for testing (like 1703 // Currently some are created purely for testing (like
1694 // `element == commonElements.foo`, where 'foo' might not be live). 1704 // `element == commonElements.foo`, where 'foo' might not be live).
1695 // Others are created because we do a 1705 // Others are created because we do a
1696 // `elementEnvironment.forEachLibraryMember(...)` call on each emitted 1706 // `elementEnvironment.forEachLibraryMember(...)` call on each emitted
1697 // library. 1707 // library.
1698 ElementCreatorMixin 1708 ElementCreatorMixin
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 throw new UnsupportedError("JsKernelToElementMap.getLocalFunction"); 1785 throw new UnsupportedError("JsKernelToElementMap.getLocalFunction");
1776 } 1786 }
1777 1787
1778 @override 1788 @override
1779 ClassEntity _getClass(ir.Class node, [ClassEnv env]) { 1789 ClassEntity _getClass(ir.Class node, [ClassEnv env]) {
1780 ClassEntity cls = _classMap[node]; 1790 ClassEntity cls = _classMap[node];
1781 assert(cls != null, "No class entity for $node"); 1791 assert(cls != null, "No class entity for $node");
1782 return cls; 1792 return cls;
1783 } 1793 }
1784 1794
1785 /*@override
1786 TypeVariableEntity _getTypeVariable(ir.TypeParameter node) {
1787 throw new UnsupportedError("JsKernelToElementMap._getTypeVariable");
1788 }*/
1789
1790 // TODO(johnniwinther): Reinsert these when [ElementCreatorMixin] is no longer 1795 // TODO(johnniwinther): Reinsert these when [ElementCreatorMixin] is no longer
1791 // mixed in. 1796 // mixed in.
1792 /*@override 1797 /*@override
1793 FieldEntity _getField(ir.Field node) { 1798 FieldEntity _getField(ir.Field node) {
1794 FieldEntity field = _fieldMap[node]; 1799 FieldEntity field = _fieldMap[node];
1795 assert(field != null, "No field entity for $node"); 1800 assert(field != null, "No field entity for $node");
1796 return field; 1801 return field;
1797 }*/ 1802 }*/
1798 1803
1799 /*@override 1804 /*@override
(...skipping 12 matching lines...) Expand all
1812 1817
1813 @override 1818 @override
1814 ir.Member getMemberNode(MemberEntity member) { 1819 ir.Member getMemberNode(MemberEntity member) {
1815 return _getMemberNode(member); 1820 return _getMemberNode(member);
1816 } 1821 }
1817 1822
1818 @override 1823 @override
1819 ir.Class getClassNode(ClassEntity cls) { 1824 ir.Class getClassNode(ClassEntity cls) {
1820 return _getClassNode(cls); 1825 return _getClassNode(cls);
1821 } 1826 }
1822
1823 @override
1824 ConstantValue getFieldConstantValue(ir.Field field) {
1825 throw new UnsupportedError("JsKernelToElementMap.getFieldConstantValue");
1826 }
1827
1828 @override
1829 void forEachParameter(FunctionEntity function,
1830 void f(DartType type, String name, ConstantValue defaultValue)) {
1831 throw new UnsupportedError("JsKernelToElementMap.forEachParameter");
1832 }
1833
1834 @override
1835 ConstantValue getConstantFieldInitializer(FieldEntity field) {
1836 throw new UnsupportedError(
1837 "JsKernelToElementMap.getConstantFieldInitializer");
1838 }
1839
1840 @override
1841 bool hasConstantFieldInitializer(FieldEntity field) {
1842 throw new UnsupportedError(
1843 "JsKernelToElementMap.hasConstantFieldInitializer");
1844 }
1845 } 1827 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_model/js_strategy.dart ('k') | pkg/compiler/lib/src/world.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698