| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 List<LibraryEntity> _libraryList = <LibraryEntity>[]; | 78 List<LibraryEntity> _libraryList = <LibraryEntity>[]; |
| 79 List<ClassEntity> _classList = <ClassEntity>[]; | 79 List<ClassEntity> _classList = <ClassEntity>[]; |
| 80 List<MemberEntity> _memberList = <MemberEntity>[]; | 80 List<MemberEntity> _memberList = <MemberEntity>[]; |
| 81 List<TypeVariableEntity> _typeVariableList = <TypeVariableEntity>[]; | 81 List<TypeVariableEntity> _typeVariableList = <TypeVariableEntity>[]; |
| 82 | 82 |
| 83 /// List of library environments by `IndexedLibrary.libraryIndex`. This is | 83 /// List of library environments by `IndexedLibrary.libraryIndex`. This is |
| 84 /// used for fast lookup into library classes and members. | 84 /// used for fast lookup into library classes and members. |
| 85 List<LibraryEnv> _libraryEnvs = <LibraryEnv>[]; | 85 List<LibraryEnv> _libraryEnvs = <LibraryEnv>[]; |
| 86 | 86 |
| 87 /// List of library data by `IndexedLibrary.libraryIndex`. This is used for |
| 88 /// fast lookup into library properties. |
| 89 List<LibraryData> _libraryData = <LibraryData>[]; |
| 90 |
| 87 /// List of class environments by `IndexedClass.classIndex`. This is used for | 91 /// List of class environments by `IndexedClass.classIndex`. This is used for |
| 88 /// fast lookup into class members. | 92 /// fast lookup into class members. |
| 89 List<ClassEnv> _classEnvs = <ClassEnv>[]; | 93 List<ClassEnv> _classEnvs = <ClassEnv>[]; |
| 90 | 94 |
| 91 /// List of class data by `IndexedClass.classIndex`. This is used for | 95 /// List of class data by `IndexedClass.classIndex`. This is used for |
| 92 /// fast lookup into class properties. | 96 /// fast lookup into class properties. |
| 93 List<ClassData> _classData = <ClassData>[]; | 97 List<ClassData> _classData = <ClassData>[]; |
| 94 | 98 |
| 95 /// List of member data by `IndexedMember.memberIndex`. This is used for | 99 /// List of member data by `IndexedMember.memberIndex`. This is used for |
| 96 /// fast lookup into member properties. | 100 /// fast lookup into member properties. |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 assert(checkFamily(cls)); | 605 assert(checkFamily(cls)); |
| 602 return _classEnvs[cls.classIndex].cls; | 606 return _classEnvs[cls.classIndex].cls; |
| 603 } | 607 } |
| 604 } | 608 } |
| 605 | 609 |
| 606 /// Mixin that implements the abstract methods in [KernelToElementMapBase]. | 610 /// Mixin that implements the abstract methods in [KernelToElementMapBase]. |
| 607 abstract class ElementCreatorMixin { | 611 abstract class ElementCreatorMixin { |
| 608 ProgramEnv get _env; | 612 ProgramEnv get _env; |
| 609 List<LibraryEntity> get _libraryList; | 613 List<LibraryEntity> get _libraryList; |
| 610 List<LibraryEnv> get _libraryEnvs; | 614 List<LibraryEnv> get _libraryEnvs; |
| 615 List<LibraryData> get _libraryData; |
| 611 List<ClassEntity> get _classList; | 616 List<ClassEntity> get _classList; |
| 612 List<ClassEnv> get _classEnvs; | 617 List<ClassEnv> get _classEnvs; |
| 613 List<ClassData> get _classData; | 618 List<ClassData> get _classData; |
| 614 List<MemberEntity> get _memberList; | 619 List<MemberEntity> get _memberList; |
| 615 List<MemberData> get _memberData; | 620 List<MemberData> get _memberData; |
| 616 List<TypeVariableEntity> get _typeVariableList; | 621 List<TypeVariableEntity> get _typeVariableList; |
| 617 | 622 |
| 618 Map<ir.Library, IndexedLibrary> _libraryMap = <ir.Library, IndexedLibrary>{}; | 623 Map<ir.Library, IndexedLibrary> _libraryMap = <ir.Library, IndexedLibrary>{}; |
| 619 Map<ir.Class, IndexedClass> _classMap = <ir.Class, IndexedClass>{}; | 624 Map<ir.Class, IndexedClass> _classMap = <ir.Class, IndexedClass>{}; |
| 620 Map<ir.TypeParameter, IndexedTypeVariable> _typeVariableMap = | 625 Map<ir.TypeParameter, IndexedTypeVariable> _typeVariableMap = |
| (...skipping 25 matching lines...) Expand all Loading... |
| 646 _libraryEnvs.add(libraryEnv ?? _env.lookupLibrary(canonicalUri)); | 651 _libraryEnvs.add(libraryEnv ?? _env.lookupLibrary(canonicalUri)); |
| 647 String name = node.name; | 652 String name = node.name; |
| 648 if (name == null) { | 653 if (name == null) { |
| 649 // Use the file name as script name. | 654 // Use the file name as script name. |
| 650 String path = canonicalUri.path; | 655 String path = canonicalUri.path; |
| 651 name = path.substring(path.lastIndexOf('/') + 1); | 656 name = path.substring(path.lastIndexOf('/') + 1); |
| 652 } | 657 } |
| 653 LibraryEntity library = | 658 LibraryEntity library = |
| 654 createLibrary(_libraryMap.length, name, canonicalUri); | 659 createLibrary(_libraryMap.length, name, canonicalUri); |
| 655 _libraryList.add(library); | 660 _libraryList.add(library); |
| 661 _libraryData.add(new LibraryData(node)); |
| 656 return library; | 662 return library; |
| 657 }); | 663 }); |
| 658 } | 664 } |
| 659 | 665 |
| 660 void addClosureClass(KernelClosureClass cls, InterfaceType supertype) { | 666 void addClosureClass(KernelClosureClass cls, InterfaceType supertype) { |
| 661 cls.classIndex = _classEnvs.length; | 667 cls.classIndex = _classEnvs.length; |
| 662 _classEnvs.add(new ClassEnv.closureClass()); | 668 _classEnvs.add(new ClassEnv.closureClass()); |
| 663 _classList.add(cls); | 669 _classList.add(cls); |
| 664 | 670 |
| 665 // Create a classData and set up the interfaces and subclass | 671 // Create a classData and set up the interfaces and subclass |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 return library; | 1283 return library; |
| 1278 } | 1284 } |
| 1279 | 1285 |
| 1280 @override | 1286 @override |
| 1281 bool isDeferredLoadLibraryGetter(MemberEntity member) { | 1287 bool isDeferredLoadLibraryGetter(MemberEntity member) { |
| 1282 // TODO(redemption): Support these. | 1288 // TODO(redemption): Support these. |
| 1283 return false; | 1289 return false; |
| 1284 } | 1290 } |
| 1285 | 1291 |
| 1286 @override | 1292 @override |
| 1287 Iterable<ConstantValue> getMemberMetadata(covariant IndexedMember member) { | 1293 Iterable<ConstantValue> getLibraryMetadata(covariant IndexedLibrary library) { |
| 1294 LibraryData libraryData = elementMap._libraryData[library.libraryIndex]; |
| 1295 return libraryData.getMetadata(elementMap); |
| 1296 } |
| 1297 |
| 1298 @override |
| 1299 Iterable<ConstantValue> getClassMetadata(covariant IndexedClass cls) { |
| 1300 ClassData classData = elementMap._classData[cls.classIndex]; |
| 1301 return classData.getMetadata(elementMap); |
| 1302 } |
| 1303 |
| 1304 @override |
| 1305 Iterable<ConstantValue> getTypedefMetadata(TypedefEntity typedef) { |
| 1306 // TODO(redemption): Support this. |
| 1307 throw new UnsupportedError('ElementEnvironment.getTypedefMetadata'); |
| 1308 } |
| 1309 |
| 1310 @override |
| 1311 Iterable<ConstantValue> getMemberMetadata(covariant IndexedMember member, |
| 1312 {bool includeParameterMetadata: false}) { |
| 1313 // TODO(redemption): Support includeParameterMetadata. |
| 1288 MemberData memberData = elementMap._memberData[member.memberIndex]; | 1314 MemberData memberData = elementMap._memberData[member.memberIndex]; |
| 1289 return memberData.getMetadata(elementMap); | 1315 return memberData.getMetadata(elementMap); |
| 1290 } | 1316 } |
| 1291 | 1317 |
| 1292 @override | 1318 @override |
| 1293 FunctionType getFunctionTypeOfTypedef(TypedefEntity typedef) { | 1319 FunctionType getFunctionTypeOfTypedef(TypedefEntity typedef) { |
| 1294 // TODO(redemption): Support this. | 1320 // TODO(redemption): Support this. |
| 1295 throw new UnsupportedError('ElementEnvironment.getTypedefAlias'); | 1321 throw new UnsupportedError('ElementEnvironment.getTypedefAlias'); |
| 1296 } | 1322 } |
| 1297 } | 1323 } |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1783 implements | 1809 implements |
| 1784 KernelToWorldBuilder { | 1810 KernelToWorldBuilder { |
| 1785 JsKernelToElementMap(DiagnosticReporter reporter, Environment environment, | 1811 JsKernelToElementMap(DiagnosticReporter reporter, Environment environment, |
| 1786 KernelToElementMapForImpactImpl _elementMap) | 1812 KernelToElementMapForImpactImpl _elementMap) |
| 1787 : super(reporter, environment) { | 1813 : super(reporter, environment) { |
| 1788 _env = _elementMap._env; | 1814 _env = _elementMap._env; |
| 1789 for (int libraryIndex = 0; | 1815 for (int libraryIndex = 0; |
| 1790 libraryIndex < _elementMap._libraryEnvs.length; | 1816 libraryIndex < _elementMap._libraryEnvs.length; |
| 1791 libraryIndex++) { | 1817 libraryIndex++) { |
| 1792 LibraryEnv env = _elementMap._libraryEnvs[libraryIndex]; | 1818 LibraryEnv env = _elementMap._libraryEnvs[libraryIndex]; |
| 1819 LibraryData data = _elementMap._libraryData[libraryIndex]; |
| 1793 LibraryEntity oldLibrary = _elementMap._libraryList[libraryIndex]; | 1820 LibraryEntity oldLibrary = _elementMap._libraryList[libraryIndex]; |
| 1794 LibraryEntity newLibrary = convertLibrary(oldLibrary); | 1821 LibraryEntity newLibrary = convertLibrary(oldLibrary); |
| 1795 _libraryMap[env.library] = newLibrary; | 1822 _libraryMap[env.library] = newLibrary; |
| 1796 _libraryList.add(newLibrary); | 1823 _libraryList.add(newLibrary); |
| 1824 _libraryData.add(data.copy()); |
| 1797 _libraryEnvs.add(env); | 1825 _libraryEnvs.add(env); |
| 1798 } | 1826 } |
| 1799 for (int classIndex = 0; | 1827 for (int classIndex = 0; |
| 1800 classIndex < _elementMap._classEnvs.length; | 1828 classIndex < _elementMap._classEnvs.length; |
| 1801 classIndex++) { | 1829 classIndex++) { |
| 1802 ClassEnv env = _elementMap._classEnvs[classIndex]; | 1830 ClassEnv env = _elementMap._classEnvs[classIndex]; |
| 1803 ClassData data = _elementMap._classData[classIndex]; | 1831 ClassData data = _elementMap._classData[classIndex]; |
| 1804 ClassEntity oldClass = _elementMap._classList[classIndex]; | 1832 ClassEntity oldClass = _elementMap._classList[classIndex]; |
| 1805 IndexedLibrary oldLibrary = oldClass.library; | 1833 IndexedLibrary oldLibrary = oldClass.library; |
| 1806 LibraryEntity newLibrary = _libraryList[oldLibrary.libraryIndex]; | 1834 LibraryEntity newLibrary = _libraryList[oldLibrary.libraryIndex]; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1974 if (data.constructorBody != null) { | 2002 if (data.constructorBody != null) { |
| 1975 f(data.constructorBody); | 2003 f(data.constructorBody); |
| 1976 } | 2004 } |
| 1977 }); | 2005 }); |
| 1978 } | 2006 } |
| 1979 | 2007 |
| 1980 String getDeferredUri(ir.LibraryDependency node) { | 2008 String getDeferredUri(ir.LibraryDependency node) { |
| 1981 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); | 2009 throw new UnimplementedError('JsKernelToElementMap.getDeferredUri'); |
| 1982 } | 2010 } |
| 1983 } | 2011 } |
| OLD | NEW |