Index: pkg/compiler/lib/src/apiimpl.dart |
diff --git a/pkg/compiler/lib/src/apiimpl.dart b/pkg/compiler/lib/src/apiimpl.dart |
index bfadc5b9ec3e351c94e15edc4d40f33e27856ba0..3fe63b6a34d04449cf97a2d77f51a41881cf9fe9 100644 |
--- a/pkg/compiler/lib/src/apiimpl.dart |
+++ b/pkg/compiler/lib/src/apiimpl.dart |
@@ -14,8 +14,8 @@ import 'package:package_config/src/packages_impl.dart' |
import 'package:package_config/src/util.dart' show checkValidPackageUri; |
import '../compiler_new.dart' as api; |
-import 'common.dart'; |
import 'common/tasks.dart' show GenericTask; |
+import 'common.dart'; |
import 'compiler.dart'; |
import 'diagnostics/messages.dart' show Message; |
import 'elements/elements.dart' as elements; |
@@ -23,6 +23,7 @@ import 'environment.dart'; |
import 'io/source_file.dart'; |
import 'options.dart' show CompilerOptions; |
import 'platform_configuration.dart' as platform_configuration; |
+import 'resolved_uri_translator.dart'; |
import 'script.dart'; |
/// Implements the [Compiler] using a [api.CompilerInput] for supplying the |
@@ -31,12 +32,12 @@ class CompilerImpl extends Compiler { |
api.CompilerInput provider; |
api.CompilerDiagnostics handler; |
Packages packages; |
- bool mockableLibraryUsed = false; |
- /// A mapping of the dart: library-names to their location. |
- /// |
- /// Initialized in [setupSdk]. |
- Map<String, Uri> sdkLibraries; |
+ bool get mockableLibraryUsed => resolvedUriTranslator.isSet |
+ ? resolvedUriTranslator.mockableLibraryUsed |
+ : false; |
+ |
+ ForwardingResolvedUriTranslator resolvedUriTranslator; |
GenericTask userHandlerTask; |
GenericTask userProviderTask; |
@@ -46,7 +47,8 @@ class CompilerImpl extends Compiler { |
CompilerImpl(this.provider, api.CompilerOutput outputProvider, this.handler, |
CompilerOptions options) |
- : super( |
+ : resolvedUriTranslator = new ForwardingResolvedUriTranslator(), |
+ super( |
options: options, |
outputProvider: outputProvider, |
environment: new _Environment(options.environment)) { |
@@ -64,15 +66,6 @@ class CompilerImpl extends Compiler { |
null, null, null, null, message, api.Diagnostic.VERBOSE_INFO); |
} |
- /// See [Compiler.translateResolvedUri]. |
- Uri translateResolvedUri(elements.LibraryElement importingLibrary, |
- Uri resolvedUri, Spannable spannable) { |
- if (resolvedUri.scheme == 'dart') { |
- return translateDartUri(importingLibrary, resolvedUri, spannable); |
- } |
- return resolvedUri; |
- } |
- |
/** |
* Reads the script designated by [readableUri]. |
*/ |
@@ -149,63 +142,6 @@ class CompilerImpl extends Compiler { |
Uri translateUri(Spannable node, Uri uri) => |
uri.scheme == 'package' ? translatePackageUri(node, uri) : uri; |
- /// Translates "resolvedUri" with scheme "dart" to a [uri] resolved relative |
- /// to `options.platformConfigUri` according to the information in the file at |
- /// `options.platformConfigUri`. |
- /// |
- /// Returns null and emits an error if the library could not be found or |
- /// imported into [importingLibrary]. |
- /// |
- /// Internal libraries (whose name starts with '_') can be only resolved if |
- /// [importingLibrary] is a platform or patch library. |
- Uri translateDartUri(elements.LibraryElement importingLibrary, |
- Uri resolvedUri, Spannable spannable) { |
- Uri location = lookupLibraryUri(resolvedUri.path); |
- |
- if (location == null) { |
- reporter.reportErrorMessage(spannable, MessageKind.LIBRARY_NOT_FOUND, |
- {'resolvedUri': resolvedUri}); |
- return null; |
- } |
- |
- if (resolvedUri.path.startsWith('_')) { |
- bool allowInternalLibraryAccess = importingLibrary != null && |
- (importingLibrary.isPlatformLibrary || |
- importingLibrary.isPatch || |
- importingLibrary.canonicalUri.path |
- .contains('sdk/tests/compiler/dart2js_native')); |
- |
- if (!allowInternalLibraryAccess) { |
- if (importingLibrary != null) { |
- reporter.reportErrorMessage( |
- spannable, MessageKind.INTERNAL_LIBRARY_FROM, { |
- 'resolvedUri': resolvedUri, |
- 'importingUri': importingLibrary.canonicalUri |
- }); |
- } else { |
- reporter.reportErrorMessage(spannable, MessageKind.INTERNAL_LIBRARY, |
- {'resolvedUri': resolvedUri}); |
- registerDisallowedLibraryUse(resolvedUri); |
- } |
- return null; |
- } |
- } |
- |
- if (location.scheme == "unsupported") { |
- reporter.reportErrorMessage(spannable, MessageKind.LIBRARY_NOT_SUPPORTED, |
- {'resolvedUri': resolvedUri}); |
- registerDisallowedLibraryUse(resolvedUri); |
- return null; |
- } |
- |
- if (resolvedUri.path == 'html' || resolvedUri.path == 'io') { |
- // TODO(ahe): Get rid of mockableLibraryUsed when test.dart |
- // supports this use case better. |
- mockableLibraryUsed = true; |
- } |
- return location; |
- } |
- |
Uri translatePackageUri(Spannable node, Uri uri) { |
try { |
checkValidPackageUri(uri); |
@@ -224,7 +160,7 @@ class CompilerImpl extends Compiler { |
Future<elements.LibraryElement> analyzeUri(Uri uri, |
{bool skipLibraryWithPartOfTag: true}) { |
List<Future> setupFutures = new List<Future>(); |
- if (sdkLibraries == null) { |
+ if (resolvedUriTranslator.isNotSet) { |
setupFutures.add(setupSdk()); |
} |
if (packages == null) { |
@@ -273,11 +209,12 @@ class CompilerImpl extends Compiler { |
} |
Future<Null> setupSdk() { |
- if (sdkLibraries == null) { |
+ if (resolvedUriTranslator.isNotSet) { |
return platform_configuration |
.load(options.platformConfigUri, provider) |
.then((Map<String, Uri> mapping) { |
- sdkLibraries = mapping; |
+ resolvedUriTranslator.resolvedUriTranslator = |
+ new ResolvedUriTranslator(mapping, reporter); |
}); |
} else { |
// The incremental compiler sets up the sdk before run. |
@@ -290,7 +227,7 @@ class CompilerImpl extends Compiler { |
log('Using platform configuration at ${options.platformConfigUri}'); |
return Future.wait([setupSdk(), setupPackages(uri)]).then((_) { |
- assert(sdkLibraries != null); |
+ assert(resolvedUriTranslator.isSet); |
assert(packages != null); |
return super.run(uri).then((bool success) { |
@@ -355,12 +292,6 @@ class CompilerImpl extends Compiler { |
.measure(() => options.packagesDiscoveryProvider(uri)); |
} |
- Uri lookupLibraryUri(String libraryName) { |
- assert(invariant(NO_LOCATION_SPANNABLE, sdkLibraries != null, |
- message: "setupSdk() has not been run")); |
- return sdkLibraries[libraryName]; |
- } |
- |
Uri resolvePatchUri(String libraryName) { |
return backend.resolvePatchUri(libraryName, options.platformConfigUri); |
} |
@@ -370,14 +301,15 @@ class _Environment implements Environment { |
final Map<String, String> definitions; |
// TODO(sigmund): break the circularity here: Compiler needs an environment to |
- // intialize the library loader, but the environment here needs to know about |
+ // initialize the library loader, but the environment here needs to know about |
// how the sdk is set up and about whether the backend supports mirrors. |
CompilerImpl compiler; |
_Environment(this.definitions); |
String valueOf(String name) { |
- assert(invariant(NO_LOCATION_SPANNABLE, compiler.sdkLibraries != null, |
+ assert(invariant( |
+ NO_LOCATION_SPANNABLE, compiler.resolvedUriTranslator != null, |
message: "setupSdk() has not been run")); |
var result = definitions[name]; |
@@ -389,7 +321,7 @@ class _Environment implements Environment { |
// Private libraries are not exposed to the users. |
if (libraryName.startsWith("_")) return null; |
- if (compiler.sdkLibraries.containsKey(libraryName)) { |
+ if (compiler.resolvedUriTranslator.sdkLibraries.containsKey(libraryName)) { |
// Dart2js always "supports" importing 'dart:mirrors' but will abort |
// the compilation at a later point if the backend doesn't support |
// mirrors. In this case 'mirrors' should not be in the environment. |