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

Side by Side Diff: pkg/compiler/lib/src/deferred_load.dart

Issue 1383483006: Extract DiagnosticReporter implementation from Compiler. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fixes after rebase. Created 5 years, 2 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 deferred_load; 5 library deferred_load;
6 6
7 import 'common/backend_api.dart' show 7 import 'common/backend_api.dart' show
8 Backend; 8 Backend;
9 import 'common/resolution.dart' show 9 import 'common/resolution.dart' show
10 Resolution; 10 Resolution;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 bool isDeferred(Element element) { 197 bool isDeferred(Element element) {
198 return outputUnitForElement(element) != mainOutputUnit; 198 return outputUnitForElement(element) != mainOutputUnit;
199 } 199 }
200 200
201 /// Returns the unique name for the deferred import of [prefix]. 201 /// Returns the unique name for the deferred import of [prefix].
202 String getImportDeferName(Spannable node, PrefixElement prefix) { 202 String getImportDeferName(Spannable node, PrefixElement prefix) {
203 String name = 203 String name =
204 _importDeferName[new _DeclaredDeferredImport(prefix.deferredImport)]; 204 _importDeferName[new _DeclaredDeferredImport(prefix.deferredImport)];
205 if (name == null) { 205 if (name == null) {
206 compiler.internalError(node, "No deferred name for $prefix."); 206 reporter.internalError(node, "No deferred name for $prefix.");
207 } 207 }
208 return name; 208 return name;
209 } 209 }
210 210
211 /// Returns `true` if element [to] is reachable from element [from] without 211 /// Returns `true` if element [to] is reachable from element [from] without
212 /// crossing a deferred import. 212 /// crossing a deferred import.
213 /// 213 ///
214 /// For example, if we have two deferred libraries `A` and `B` that both 214 /// For example, if we have two deferred libraries `A` and `B` that both
215 /// import a library `C`, then even though elements from `A` and `C` end up in 215 /// import a library `C`, then even though elements from `A` and `C` end up in
216 /// different output units, there is a non-deferred path between `A` and `C`. 216 /// different output units, there is a non-deferred path between `A` and `C`.
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 // import "lib.dart" as a; 709 // import "lib.dart" as a;
710 // import "lib2.dart" as a; 710 // import "lib2.dart" as a;
711 // We must be able to signal error for case 1, 2, 3, but accept case 4. 711 // We must be able to signal error for case 1, 2, 3, but accept case 4.
712 712
713 // The prefixes that have been used by any imports in this library. 713 // The prefixes that have been used by any imports in this library.
714 Setlet<String> usedPrefixes = new Setlet<String>(); 714 Setlet<String> usedPrefixes = new Setlet<String>();
715 // The last deferred import we saw with a given prefix (if any). 715 // The last deferred import we saw with a given prefix (if any).
716 Map<String, ImportElement> prefixDeferredImport = 716 Map<String, ImportElement> prefixDeferredImport =
717 new Map<String, ImportElement>(); 717 new Map<String, ImportElement>();
718 for (LibraryElement library in compiler.libraryLoader.libraries) { 718 for (LibraryElement library in compiler.libraryLoader.libraries) {
719 compiler.withCurrentElement(library, () { 719 reporter.withCurrentElement(library, () {
720 prefixDeferredImport.clear(); 720 prefixDeferredImport.clear();
721 usedPrefixes.clear(); 721 usedPrefixes.clear();
722 // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List 722 // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List
723 // instead of a Link. 723 // instead of a Link.
724 for (ImportElement import in library.imports) { 724 for (ImportElement import in library.imports) {
725 /// Give an error if the old annotation-based syntax has been used. 725 /// Give an error if the old annotation-based syntax has been used.
726 List<MetadataAnnotation> metadataList = import.metadata; 726 List<MetadataAnnotation> metadataList = import.metadata;
727 if (metadataList != null) { 727 if (metadataList != null) {
728 for (MetadataAnnotation metadata in metadataList) { 728 for (MetadataAnnotation metadata in metadataList) {
729 metadata.ensureResolved(compiler.resolution); 729 metadata.ensureResolved(compiler.resolution);
730 ConstantValue value = 730 ConstantValue value =
731 compiler.constants.getConstantValue(metadata.constant); 731 compiler.constants.getConstantValue(metadata.constant);
732 Element element = value.getType(compiler.coreTypes).element; 732 Element element = value.getType(compiler.coreTypes).element;
733 if (element == deferredLibraryClass) { 733 if (element == deferredLibraryClass) {
734 compiler.reportErrorMessage( 734 reporter.reportErrorMessage(
735 import, MessageKind.DEFERRED_OLD_SYNTAX); 735 import, MessageKind.DEFERRED_OLD_SYNTAX);
736 } 736 }
737 } 737 }
738 } 738 }
739 739
740 String prefix = (import.prefix != null) 740 String prefix = (import.prefix != null)
741 ? import.prefix.name 741 ? import.prefix.name
742 : null; 742 : null;
743 // The last import we saw with the same prefix. 743 // The last import we saw with the same prefix.
744 ImportElement previousDeferredImport = prefixDeferredImport[prefix]; 744 ImportElement previousDeferredImport = prefixDeferredImport[prefix];
745 if (import.isDeferred) { 745 if (import.isDeferred) {
746 _DeferredImport key = new _DeclaredDeferredImport(import); 746 _DeferredImport key = new _DeclaredDeferredImport(import);
747 LibraryElement importedLibrary = import.importedLibrary; 747 LibraryElement importedLibrary = import.importedLibrary;
748 _allDeferredImports[key] = importedLibrary; 748 _allDeferredImports[key] = importedLibrary;
749 749
750 if (prefix == null) { 750 if (prefix == null) {
751 compiler.reportErrorMessage( 751 reporter.reportErrorMessage(
752 import, 752 import,
753 MessageKind.DEFERRED_LIBRARY_WITHOUT_PREFIX); 753 MessageKind.DEFERRED_LIBRARY_WITHOUT_PREFIX);
754 } else { 754 } else {
755 prefixDeferredImport[prefix] = import; 755 prefixDeferredImport[prefix] = import;
756 _deferredImportDescriptions[key] = 756 _deferredImportDescriptions[key] =
757 new ImportDescription(import, library, compiler); 757 new ImportDescription(import, library, compiler);
758 } 758 }
759 isProgramSplit = true; 759 isProgramSplit = true;
760 lastDeferred = import; 760 lastDeferred = import;
761 } 761 }
762 if (prefix != null) { 762 if (prefix != null) {
763 if (previousDeferredImport != null || 763 if (previousDeferredImport != null ||
764 (import.isDeferred && usedPrefixes.contains(prefix))) { 764 (import.isDeferred && usedPrefixes.contains(prefix))) {
765 ImportElement failingImport = (previousDeferredImport != null) 765 ImportElement failingImport = (previousDeferredImport != null)
766 ? previousDeferredImport 766 ? previousDeferredImport
767 : import; 767 : import;
768 compiler.reportErrorMessage( 768 reporter.reportErrorMessage(
769 failingImport.prefix, 769 failingImport.prefix,
770 MessageKind.DEFERRED_LIBRARY_DUPLICATE_PREFIX); 770 MessageKind.DEFERRED_LIBRARY_DUPLICATE_PREFIX);
771 } 771 }
772 usedPrefixes.add(prefix); 772 usedPrefixes.add(prefix);
773 } 773 }
774 } 774 }
775 }); 775 });
776 } 776 }
777 if (isProgramSplit) { 777 if (isProgramSplit) {
778 isProgramSplit = compiler.backend.enableDeferredLoadingIfSupported( 778 isProgramSplit = compiler.backend.enableDeferredLoadingIfSupported(
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 return result; 940 return result;
941 } 941 }
942 942
943 bool operator ==(other) { 943 bool operator ==(other) {
944 if (other is! _DeclaredDeferredImport) return false; 944 if (other is! _DeclaredDeferredImport) return false;
945 return declaration == other.declaration; 945 return declaration == other.declaration;
946 } 946 }
947 947
948 int get hashCode => declaration.hashCode * 17; 948 int get hashCode => declaration.hashCode * 17;
949 } 949 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/dart_types.dart ('k') | pkg/compiler/lib/src/diagnostics/diagnostic_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698