Chromium Code Reviews| Index: pkg/compiler/lib/src/compiler.dart |
| diff --git a/pkg/compiler/lib/src/compiler.dart b/pkg/compiler/lib/src/compiler.dart |
| index 1b01849c9558a21ac442383036edcd05909a46f6..c885e337246e66a794873e75e52fd136931734d0 100644 |
| --- a/pkg/compiler/lib/src/compiler.dart |
| +++ b/pkg/compiler/lib/src/compiler.dart |
| @@ -9,36 +9,29 @@ import 'dart:async' show EventSink, Future; |
| import '../compiler_new.dart' as api; |
| import 'cache_strategy.dart' show CacheStrategy; |
| import 'closure.dart' as closureMapping show ClosureTask; |
| -import 'common.dart'; |
| import 'common/backend_api.dart' show Backend; |
| -import 'common/codegen.dart' show CodegenImpact, CodegenWorkItem; |
| +import 'common/codegen.dart' show CodegenWorkItem; |
| +import 'common/names.dart' show Selectors; |
| import 'common/names.dart' show Identifiers, Uris; |
| import 'common/registry.dart' show EagerRegistry, Registry; |
| import 'common/resolution.dart' |
| show Parsing, Resolution, ResolutionWorkItem, ResolutionImpact; |
| import 'common/tasks.dart' show CompilerTask, GenericTask; |
| import 'common/work.dart' show ItemCompilationContext, WorkItem; |
| +import 'common.dart'; |
| import 'compile_time_constants.dart'; |
| import 'constants/values.dart'; |
| import 'core_types.dart' show CoreClasses, CoreTypes; |
| import 'dart_backend/dart_backend.dart' as dart_backend; |
| import 'dart_types.dart' show DartType, DynamicType, InterfaceType, Types; |
| -import 'deferred_load.dart' show DeferredLoadTask, OutputUnit; |
| +import 'deferred_load.dart' show DeferredLoadTask; |
| import 'diagnostics/code_location.dart'; |
| import 'diagnostics/diagnostic_listener.dart' show DiagnosticReporter; |
| import 'diagnostics/invariant.dart' show REPORT_EXCESS_RESOLUTION; |
| import 'diagnostics/messages.dart' show Message, MessageTemplate; |
| import 'dump_info.dart' show DumpInfoTask; |
| import 'elements/elements.dart'; |
| -import 'elements/modelx.dart' |
| - show |
| - ErroneousElementX, |
| - ClassElementX, |
| - CompilationUnitElementX, |
| - DeferredLoaderGetterElementX, |
| - MethodElementX, |
| - LibraryElementX, |
| - PrefixElementX; |
| +import 'elements/modelx.dart' show ErroneousElementX; |
| import 'enqueue.dart' |
| show |
| CodegenEnqueuer, |
| @@ -58,10 +51,8 @@ import 'library_loader.dart' |
| LibraryLoaderTask, |
| LoadedLibraries, |
| LibraryLoaderListener, |
| - ResolvedUriTranslator, |
| ScriptLoader; |
| import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; |
| -import 'common/names.dart' show Selectors; |
| import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; |
| import 'options.dart' show CompilerOptions, DiagnosticOptions, ParserOptions; |
| import 'parser/diet_parser_task.dart' show DietParserTask; |
| @@ -71,13 +62,14 @@ import 'patch_parser.dart' show PatchParserTask; |
| import 'resolution/registry.dart' show ResolutionRegistry; |
| import 'resolution/resolution.dart' show ResolverTask; |
| import 'resolution/tree_elements.dart' show TreeElementMapping; |
| +import 'resolved_uri_translator.dart'; |
| import 'scanner/scanner_task.dart' show ScannerTask; |
| -import 'serialization/task.dart' show SerializationTask; |
| import 'script.dart' show Script; |
| +import 'serialization/task.dart' show SerializationTask; |
| import 'ssa/nodes.dart' show HInstruction; |
| -import 'tracer.dart' show Tracer; |
| import 'tokens/token.dart' show StringToken, Token, TokenPair; |
| import 'tokens/token_map.dart' show TokenMap; |
| +import 'tracer.dart' show Tracer; |
| import 'tree/tree.dart' show Node, TypeAnnotation; |
| import 'typechecker.dart' show TypeCheckerTask; |
| import 'types/types.dart' as ti; |
| @@ -141,10 +133,7 @@ abstract class Compiler implements LibraryLoaderListener, IdGenerator { |
| List<Uri> librariesToAnalyzeWhenRun; |
| - /// The set of platform libraries reported as unsupported. |
| - /// |
| - /// For instance when importing 'dart:io' without '--categories=Server'. |
| - Set<Uri> disallowedLibraryUris = new Setlet<Uri>(); |
| + ResolvedUriTranslator get resolvedUriTranslator; |
| Tracer tracer; |
| @@ -340,7 +329,8 @@ abstract class Compiler implements LibraryLoaderListener, IdGenerator { |
| } |
| tasks = [ |
| - dietParser = new DietParserTask(this, parsing.parserOptions, idGenerator), |
| + dietParser = new DietParserTask( |
| + this, parsing.parserOptions, idGenerator, backend, reporter), |
| scanner = createScannerTask(), |
| serialization = new SerializationTask(this), |
| libraryLoader = new LibraryLoaderTask( |
| @@ -402,7 +392,7 @@ abstract class Compiler implements LibraryLoaderListener, IdGenerator { |
| // Compiles the dart script at [uri]. |
| // |
| // The resulting future will complete with true if the compilation |
| - // succeded. |
| + // succeeded. |
| Future<bool> run(Uri uri) { |
| totalCompileTime.start(); |
| @@ -524,13 +514,6 @@ abstract class Compiler implements LibraryLoaderListener, IdGenerator { |
| return importChains; |
| } |
| - /// Register that [uri] was recognized but disallowed as a dependency. |
| - /// |
| - /// For instance import of 'dart:io' without '--categories=Server'. |
| - void registerDisallowedLibraryUse(Uri uri) { |
| - disallowedLibraryUris.add(uri); |
| - } |
| - |
| /// This method is called when all new libraries loaded through |
| /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports |
| /// have been computed. |
| @@ -541,7 +524,9 @@ abstract class Compiler implements LibraryLoaderListener, IdGenerator { |
| /// libraries. |
| Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { |
| return new Future.sync(() { |
| - for (Uri uri in disallowedLibraryUris) { |
| + var disallowedLibraries = |
| + resolvedUriTranslator?.disallowedLibraryUris ?? const <Uri>[]; |
| + for (Uri uri in disallowedLibraries) { |
| if (loadedLibraries.containsLibrary(uri)) { |
| Set<String> importChains = |
| computeImportChainsFor(loadedLibraries, uri); |
| @@ -1112,26 +1097,6 @@ abstract class Compiler implements LibraryLoaderListener, IdGenerator { |
| } |
| } |
| - // TODO(sigmund): move this dart doc somewhere else too. |
| - /** |
| - * Translates the [resolvedUri] into a readable URI. |
| - * |
| - * The [importingLibrary] holds the library importing [resolvedUri] or |
| - * [:null:] if [resolvedUri] is loaded as the main library. The |
| - * [importingLibrary] is used to grant access to internal libraries from |
| - * platform libraries and patch libraries. |
| - * |
| - * If the [resolvedUri] is not accessible from [importingLibrary], this method |
| - * is responsible for reporting errors. |
| - * |
| - * See [LibraryLoader] for terminology on URIs. |
| - */ |
| - Uri translateResolvedUri( |
| - LibraryElement importingLibrary, Uri resolvedUri, Spannable spannable) { |
| - unimplemented(importingLibrary, 'Compiler.translateResolvedUri'); |
| - return null; |
| - } |
| - |
| /** |
| * Reads the script specified by the [readableUri]. |
| * |
| @@ -1911,7 +1876,6 @@ class _CompilerResolution implements Resolution { |
| return null; |
| } |
| - |
| @override |
| bool hasResolutionImpact(Element element) { |
| return _resolutionImpactCache.containsKey(element); |
| @@ -2019,8 +1983,8 @@ class _CompilerParsing implements Parsing { |
| }); |
| } |
| - ScannerOptions getScannerOptionsFor(Element element) => |
| - new ScannerOptions.from(compiler, element.library); |
| + ScannerOptions getScannerOptionsFor(Element element) => new ScannerOptions( |
| + canUseNative: compiler.backend.canLibraryUseNative(element.library)); |
| ParserOptions get parserOptions => compiler.options; |
| } |
| @@ -2051,13 +2015,30 @@ class GlobalDependencyRegistry extends EagerRegistry { |
| // TODO(sigmund): in the future, each of these classes should be self contained |
| // and not use references to `compiler`. |
| +// TODO(het): This class is an ugly hack because we need a |
| +// [ResolvedUriTranslator] at compiler construction time, but the actual |
| +// translator isn't set until the compiler actually starts running. |
|
Siggi Cherem (dart-lang)
2016/04/13 15:53:35
Some ideas to make it more self explanatory:
- re
Harry Terkelsen
2016/04/13 20:23:40
Done.
|
| class _ResolvedUriTranslator implements ResolvedUriTranslator { |
| Compiler compiler; |
| _ResolvedUriTranslator(this.compiler); |
| + @override |
| Uri translate(LibraryElement importingLibrary, Uri resolvedUri, |
| [Spannable spannable]) => |
| - compiler.translateResolvedUri(importingLibrary, resolvedUri, spannable); |
| + compiler.resolvedUriTranslator |
| + .translate(importingLibrary, resolvedUri, spannable); |
| + |
| + @override |
| + Set<Uri> get disallowedLibraryUris => |
| + compiler.resolvedUriTranslator.disallowedLibraryUris; |
| + |
| + @override |
| + bool get mockableLibraryUsed => |
| + compiler.resolvedUriTranslator.mockableLibraryUsed; |
| + |
| + @override |
| + Map<String, Uri> get sdkLibraries => |
| + compiler.resolvedUriTranslator.sdkLibraries; |
| } |
| class _ScriptLoader implements ScriptLoader { |