| 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.library_loader; | 5 library dart2js.library_loader; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'common/names.dart' show Uris; | 9 import 'common/names.dart' show Uris; |
| 10 import 'common/tasks.dart' show CompilerTask, Measurer; | 10 import 'common/tasks.dart' show CompilerTask, Measurer; |
| (...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 final ImportElementX import; | 965 final ImportElementX import; |
| 966 final LibraryElement importedLibrary; | 966 final LibraryElement importedLibrary; |
| 967 | 967 |
| 968 ImportLink(this.import, this.importedLibrary); | 968 ImportLink(this.import, this.importedLibrary); |
| 969 | 969 |
| 970 /** | 970 /** |
| 971 * Imports the library into the [importingLibrary]. | 971 * Imports the library into the [importingLibrary]. |
| 972 */ | 972 */ |
| 973 void importLibrary( | 973 void importLibrary( |
| 974 DiagnosticReporter reporter, LibraryElementX importingLibrary) { | 974 DiagnosticReporter reporter, LibraryElementX importingLibrary) { |
| 975 assert(invariant(importingLibrary, importedLibrary.exportsHandled, | 975 assert(importedLibrary.exportsHandled, |
| 976 message: 'Exports not handled on $importedLibrary')); | 976 failedAt(importedLibrary, 'Exports not handled on $importedLibrary')); |
| 977 Import tag = import.node; | 977 Import tag = import.node; |
| 978 CombinatorFilter combinatorFilter = new CombinatorFilter.fromTag(tag); | 978 CombinatorFilter combinatorFilter = new CombinatorFilter.fromTag(tag); |
| 979 if (tag != null && tag.prefix != null) { | 979 if (tag != null && tag.prefix != null) { |
| 980 String prefix = tag.prefix.source; | 980 String prefix = tag.prefix.source; |
| 981 Element existingElement = importingLibrary.find(prefix); | 981 Element existingElement = importingLibrary.find(prefix); |
| 982 PrefixElementX prefixElement; | 982 PrefixElementX prefixElement; |
| 983 if (existingElement == null || !existingElement.isPrefix) { | 983 if (existingElement == null || !existingElement.isPrefix) { |
| 984 prefixElement = new PrefixElementX( | 984 prefixElement = new PrefixElementX( |
| 985 prefix, | 985 prefix, |
| 986 importingLibrary.entryCompilationUnit, | 986 importingLibrary.entryCompilationUnit, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 /// export from the library of this node through the [export] declaration | 1124 /// export from the library of this node through the [export] declaration |
| 1125 /// with the given combination [filter]. | 1125 /// with the given combination [filter]. |
| 1126 /// | 1126 /// |
| 1127 /// Additionally, check that all names in the show/hide combinators are in the | 1127 /// Additionally, check that all names in the show/hide combinators are in the |
| 1128 /// export scope of [exportedLibraryElement]. | 1128 /// export scope of [exportedLibraryElement]. |
| 1129 void registerHandledExports( | 1129 void registerHandledExports( |
| 1130 DiagnosticReporter reporter, | 1130 DiagnosticReporter reporter, |
| 1131 LibraryElement exportedLibraryElement, | 1131 LibraryElement exportedLibraryElement, |
| 1132 ExportElementX export, | 1132 ExportElementX export, |
| 1133 CombinatorFilter filter) { | 1133 CombinatorFilter filter) { |
| 1134 assert(invariant(library, exportedLibraryElement.exportsHandled)); | 1134 assert(exportedLibraryElement.exportsHandled, failedAt(library)); |
| 1135 exportedLibraryElement.forEachExport((Element exportedElement) { | 1135 exportedLibraryElement.forEachExport((Element exportedElement) { |
| 1136 if (!filter.exclude(exportedElement)) { | 1136 if (!filter.exclude(exportedElement)) { |
| 1137 Link<ExportElement> exports = pendingExportMap.putIfAbsent( | 1137 Link<ExportElement> exports = pendingExportMap.putIfAbsent( |
| 1138 exportedElement, () => const Link<ExportElement>()); | 1138 exportedElement, () => const Link<ExportElement>()); |
| 1139 pendingExportMap[exportedElement] = exports.prepend(export); | 1139 pendingExportMap[exportedElement] = exports.prepend(export); |
| 1140 } | 1140 } |
| 1141 }); | 1141 }); |
| 1142 if (!reporter.options.suppressHints) { | 1142 if (!reporter.options.suppressHints) { |
| 1143 reporter.withCurrentElement(library, () { | 1143 reporter.withCurrentElement(library, () { |
| 1144 checkLibraryDependency(reporter, export.node, exportedLibraryElement); | 1144 checkLibraryDependency(reporter, export.node, exportedLibraryElement); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 * is a duplicate, an error element is inserted into the export scope. | 1177 * is a duplicate, an error element is inserted into the export scope. |
| 1178 */ | 1178 */ |
| 1179 Element addElementToExportScope(DiagnosticReporter reporter, Element element, | 1179 Element addElementToExportScope(DiagnosticReporter reporter, Element element, |
| 1180 Link<ExportElement> exports) { | 1180 Link<ExportElement> exports) { |
| 1181 String name = element.name; | 1181 String name = element.name; |
| 1182 DiagnosticMessage error; | 1182 DiagnosticMessage error; |
| 1183 List<DiagnosticMessage> infos = <DiagnosticMessage>[]; | 1183 List<DiagnosticMessage> infos = <DiagnosticMessage>[]; |
| 1184 | 1184 |
| 1185 void createDuplicateExportMessage( | 1185 void createDuplicateExportMessage( |
| 1186 Element duplicate, Link<ExportElement> duplicateExports) { | 1186 Element duplicate, Link<ExportElement> duplicateExports) { |
| 1187 assert(invariant(library, !duplicateExports.isEmpty, | 1187 assert( |
| 1188 message: "No export for $duplicate from ${duplicate.library} " | 1188 !duplicateExports.isEmpty, |
| 1189 failedAt( |
| 1190 library, |
| 1191 "No export for $duplicate from ${duplicate.library} " |
| 1189 "in $library.")); | 1192 "in $library.")); |
| 1190 reporter.withCurrentElement(library, () { | 1193 reporter.withCurrentElement(library, () { |
| 1191 for (ExportElement export in duplicateExports) { | 1194 for (ExportElement export in duplicateExports) { |
| 1192 if (error == null) { | 1195 if (error == null) { |
| 1193 error = reporter.createMessage( | 1196 error = reporter.createMessage( |
| 1194 export, MessageKind.DUPLICATE_EXPORT, {'name': name}); | 1197 export, MessageKind.DUPLICATE_EXPORT, {'name': name}); |
| 1195 } else { | 1198 } else { |
| 1196 infos.add(reporter.createMessage( | 1199 infos.add(reporter.createMessage( |
| 1197 export, MessageKind.DUPLICATE_EXPORT_CONT, {'name': name})); | 1200 export, MessageKind.DUPLICATE_EXPORT_CONT, {'name': name})); |
| 1198 } | 1201 } |
| 1199 } | 1202 } |
| 1200 }); | 1203 }); |
| 1201 } | 1204 } |
| 1202 | 1205 |
| 1203 void createDuplicateExportDeclMessage( | 1206 void createDuplicateExportDeclMessage( |
| 1204 Element duplicate, Link<ExportElement> duplicateExports) { | 1207 Element duplicate, Link<ExportElement> duplicateExports) { |
| 1205 assert(invariant(library, !duplicateExports.isEmpty, | 1208 assert( |
| 1206 message: "No export for $duplicate from ${duplicate.library} " | 1209 !duplicateExports.isEmpty, |
| 1210 failedAt( |
| 1211 library, |
| 1212 "No export for $duplicate from ${duplicate.library} " |
| 1207 "in $library.")); | 1213 "in $library.")); |
| 1208 infos.add(reporter.createMessage( | 1214 infos.add(reporter.createMessage( |
| 1209 duplicate, | 1215 duplicate, |
| 1210 MessageKind.DUPLICATE_EXPORT_DECL, | 1216 MessageKind.DUPLICATE_EXPORT_DECL, |
| 1211 {'name': name, 'uriString': duplicateExports.head.uri})); | 1217 {'name': name, 'uriString': duplicateExports.head.uri})); |
| 1212 } | 1218 } |
| 1213 | 1219 |
| 1214 Element existingElement = exportScope[name]; | 1220 Element existingElement = exportScope[name]; |
| 1215 if (existingElement != null && existingElement != element) { | 1221 if (existingElement != null && existingElement != element) { |
| 1216 if (existingElement.isMalformed) { | 1222 if (existingElement.isMalformed) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1415 LibraryDependencyNode exportingNode = nodeMap[library]; | 1421 LibraryDependencyNode exportingNode = nodeMap[library]; |
| 1416 if (loadedLibrary.exportsHandled) { | 1422 if (loadedLibrary.exportsHandled) { |
| 1417 // Export scope already computed on [loadedLibrary]. | 1423 // Export scope already computed on [loadedLibrary]. |
| 1418 CombinatorFilter combinatorFilter = | 1424 CombinatorFilter combinatorFilter = |
| 1419 new CombinatorFilter.fromTag(libraryDependency.node); | 1425 new CombinatorFilter.fromTag(libraryDependency.node); |
| 1420 exportingNode.registerHandledExports( | 1426 exportingNode.registerHandledExports( |
| 1421 reporter, loadedLibrary, libraryDependency, combinatorFilter); | 1427 reporter, loadedLibrary, libraryDependency, combinatorFilter); |
| 1422 return; | 1428 return; |
| 1423 } | 1429 } |
| 1424 LibraryDependencyNode exportedNode = nodeMap[loadedLibrary]; | 1430 LibraryDependencyNode exportedNode = nodeMap[loadedLibrary]; |
| 1425 assert(invariant(loadedLibrary, exportedNode != null, | 1431 assert(exportedNode != null, |
| 1426 message: "$loadedLibrary has not been registered")); | 1432 failedAt(loadedLibrary, "$loadedLibrary has not been registered")); |
| 1427 assert(invariant(library, exportingNode != null, | 1433 assert(exportingNode != null, |
| 1428 message: "$library has not been registered")); | 1434 failedAt(library, "$library has not been registered")); |
| 1429 exportedNode.registerExportDependency(libraryDependency, exportingNode); | 1435 exportedNode.registerExportDependency(libraryDependency, exportingNode); |
| 1430 } else if (libraryDependency == null || libraryDependency.isImport) { | 1436 } else if (libraryDependency == null || libraryDependency.isImport) { |
| 1431 // [loadedLibrary] is imported by [library]. | 1437 // [loadedLibrary] is imported by [library]. |
| 1432 LibraryDependencyNode importingNode = nodeMap[library]; | 1438 LibraryDependencyNode importingNode = nodeMap[library]; |
| 1433 assert(invariant(library, importingNode != null, | 1439 assert(importingNode != null, |
| 1434 message: "$library has not been registered")); | 1440 failedAt(library, "$library has not been registered")); |
| 1435 importingNode.registerImportDependency(libraryDependency, loadedLibrary); | 1441 importingNode.registerImportDependency(libraryDependency, loadedLibrary); |
| 1436 } | 1442 } |
| 1437 } | 1443 } |
| 1438 | 1444 |
| 1439 /** | 1445 /** |
| 1440 * Registers [library] for the processing of its import/export scope. | 1446 * Registers [library] for the processing of its import/export scope. |
| 1441 */ | 1447 */ |
| 1442 void registerNewLibrary(LibraryElement library) { | 1448 void registerNewLibrary(LibraryElement library) { |
| 1443 _newLibraries.add(library); | 1449 _newLibraries.add(library); |
| 1444 if (!library.exportsHandled) { | 1450 if (!library.exportsHandled) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1661 } | 1667 } |
| 1662 | 1668 |
| 1663 /// API used by the library loader to synchronously scan a library or | 1669 /// API used by the library loader to synchronously scan a library or |
| 1664 /// compilation unit and ensure that their library tags are computed. | 1670 /// compilation unit and ensure that their library tags are computed. |
| 1665 abstract class ElementScanner { | 1671 abstract class ElementScanner { |
| 1666 void scanLibrary(LibraryElement library); | 1672 void scanLibrary(LibraryElement library); |
| 1667 void scanUnit(CompilationUnitElement unit); | 1673 void scanUnit(CompilationUnitElement unit); |
| 1668 } | 1674 } |
| 1669 | 1675 |
| 1670 const _reuseLibrarySubtaskName = "Reuse library"; | 1676 const _reuseLibrarySubtaskName = "Reuse library"; |
| OLD | NEW |