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.compiler_base; | 5 library dart2js.compiler_base; |
6 | 6 |
7 import 'dart:async' show EventSink, Future; | 7 import 'dart:async' show EventSink, Future; |
8 | 8 |
9 import '../compiler_new.dart' as api; | 9 import '../compiler_new.dart' as api; |
10 import 'cache_strategy.dart' show CacheStrategy; | 10 import 'cache_strategy.dart' show CacheStrategy; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 import 'io/source_information.dart' show SourceInformation; | 44 import 'io/source_information.dart' show SourceInformation; |
45 import 'js_backend/backend_helpers.dart' as js_backend show BackendHelpers; | 45 import 'js_backend/backend_helpers.dart' as js_backend show BackendHelpers; |
46 import 'js_backend/js_backend.dart' as js_backend show JavaScriptBackend; | 46 import 'js_backend/js_backend.dart' as js_backend show JavaScriptBackend; |
47 import 'library_loader.dart' | 47 import 'library_loader.dart' |
48 show | 48 show |
49 ElementScanner, | 49 ElementScanner, |
50 LibraryLoader, | 50 LibraryLoader, |
51 LibraryLoaderTask, | 51 LibraryLoaderTask, |
52 LoadedLibraries, | 52 LoadedLibraries, |
53 LibraryLoaderListener, | 53 LibraryLoaderListener, |
54 ResolvedUriTranslator, | |
55 ScriptLoader; | 54 ScriptLoader; |
56 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; | 55 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; |
57 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; | 56 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; |
58 import 'options.dart' show CompilerOptions, DiagnosticOptions, ParserOptions; | 57 import 'options.dart' show CompilerOptions, DiagnosticOptions, ParserOptions; |
59 import 'parser/diet_parser_task.dart' show DietParserTask; | 58 import 'parser/diet_parser_task.dart' show DietParserTask; |
60 import 'parser/element_listener.dart' show ScannerOptions; | 59 import 'parser/element_listener.dart' show ScannerOptions; |
61 import 'parser/parser_task.dart' show ParserTask; | 60 import 'parser/parser_task.dart' show ParserTask; |
62 import 'patch_parser.dart' show PatchParserTask; | 61 import 'patch_parser.dart' show PatchParserTask; |
63 import 'resolution/registry.dart' show ResolutionRegistry; | 62 import 'resolution/registry.dart' show ResolutionRegistry; |
64 import 'resolution/resolution.dart' show ResolverTask; | 63 import 'resolution/resolution.dart' show ResolverTask; |
65 import 'resolution/tree_elements.dart' show TreeElementMapping; | 64 import 'resolution/tree_elements.dart' show TreeElementMapping; |
65 import 'resolved_uri_translator.dart'; | |
66 import 'scanner/scanner_task.dart' show ScannerTask; | 66 import 'scanner/scanner_task.dart' show ScannerTask; |
67 import 'script.dart' show Script; | 67 import 'script.dart' show Script; |
68 import 'serialization/task.dart' show SerializationTask; | 68 import 'serialization/task.dart' show SerializationTask; |
69 import 'ssa/nodes.dart' show HInstruction; | 69 import 'ssa/nodes.dart' show HInstruction; |
70 import 'tokens/token.dart' show StringToken, Token, TokenPair; | 70 import 'tokens/token.dart' show StringToken, Token, TokenPair; |
71 import 'tokens/token_map.dart' show TokenMap; | 71 import 'tokens/token_map.dart' show TokenMap; |
72 import 'tracer.dart' show Tracer; | 72 import 'tracer.dart' show Tracer; |
73 import 'tree/tree.dart' show Node, TypeAnnotation; | 73 import 'tree/tree.dart' show Node, TypeAnnotation; |
74 import 'typechecker.dart' show TypeCheckerTask; | 74 import 'typechecker.dart' show TypeCheckerTask; |
75 import 'types/types.dart' as ti; | 75 import 'types/types.dart' as ti; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 * If true, stop compilation after type inference is complete. Used for | 126 * If true, stop compilation after type inference is complete. Used for |
127 * debugging and testing purposes only. | 127 * debugging and testing purposes only. |
128 */ | 128 */ |
129 bool stopAfterTypeInference = false; | 129 bool stopAfterTypeInference = false; |
130 | 130 |
131 /// Output provider from user of Compiler API. | 131 /// Output provider from user of Compiler API. |
132 api.CompilerOutput userOutputProvider; | 132 api.CompilerOutput userOutputProvider; |
133 | 133 |
134 List<Uri> librariesToAnalyzeWhenRun; | 134 List<Uri> librariesToAnalyzeWhenRun; |
135 | 135 |
136 /// The set of platform libraries reported as unsupported. | 136 ResolvedUriTranslator get resolvedUriTranslator; |
137 /// | |
138 /// For instance when importing 'dart:io' without '--categories=Server'. | |
139 Set<Uri> disallowedLibraryUris = new Setlet<Uri>(); | |
140 | 137 |
141 Tracer tracer; | 138 Tracer tracer; |
142 | 139 |
143 CompilerTask measuredTask; | 140 CompilerTask measuredTask; |
144 LibraryElement coreLibrary; | 141 LibraryElement coreLibrary; |
145 LibraryElement asyncLibrary; | 142 LibraryElement asyncLibrary; |
146 | 143 |
147 LibraryElement mainApp; | 144 LibraryElement mainApp; |
148 FunctionElement mainFunction; | 145 FunctionElement mainFunction; |
149 | 146 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 throw new ArgumentError('--dump-info is not supported for dart2dart.'); | 322 throw new ArgumentError('--dump-info is not supported for dart2dart.'); |
326 } | 323 } |
327 } | 324 } |
328 | 325 |
329 if (options.dumpInfo && options.useStartupEmitter) { | 326 if (options.dumpInfo && options.useStartupEmitter) { |
330 throw new ArgumentError( | 327 throw new ArgumentError( |
331 '--dump-info is not supported with the fast startup emitter'); | 328 '--dump-info is not supported with the fast startup emitter'); |
332 } | 329 } |
333 | 330 |
334 tasks = [ | 331 tasks = [ |
335 dietParser = new DietParserTask(this, parsing.parserOptions, idGenerator), | 332 dietParser = new DietParserTask( |
333 this, parsing.parserOptions, idGenerator, backend, reporter), | |
336 scanner = createScannerTask(), | 334 scanner = createScannerTask(), |
337 serialization = new SerializationTask(this), | 335 serialization = new SerializationTask(this), |
338 libraryLoader = new LibraryLoaderTask( | 336 libraryLoader = new LibraryLoaderTask( |
339 this, | 337 this, |
340 new _ResolvedUriTranslator(this), | 338 this.resolvedUriTranslator, |
Siggi Cherem (dart-lang)
2016/04/13 20:54:20
nit: eventually we might want to remove `this.` he
| |
341 new _ScriptLoader(this), | 339 new _ScriptLoader(this), |
342 new _ElementScanner(scanner), | 340 new _ElementScanner(scanner), |
343 this.serialization, | 341 this.serialization, |
344 this, | 342 this, |
345 environment), | 343 environment), |
346 parser = new ParserTask(this, parsing.parserOptions), | 344 parser = new ParserTask(this, parsing.parserOptions), |
347 patchParser = new PatchParserTask(this, parsing.parserOptions), | 345 patchParser = new PatchParserTask(this, parsing.parserOptions), |
348 resolver = createResolverTask(), | 346 resolver = createResolverTask(), |
349 closureToClassMapper = new closureMapping.ClosureTask(this), | 347 closureToClassMapper = new closureMapping.ClosureTask(this), |
350 checker = new TypeCheckerTask(this), | 348 checker = new TypeCheckerTask(this), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 bool get disableTypeInference => | 381 bool get disableTypeInference => |
384 options.disableTypeInference || compilationFailed; | 382 options.disableTypeInference || compilationFailed; |
385 | 383 |
386 void unimplemented(Spannable spannable, String methodName) { | 384 void unimplemented(Spannable spannable, String methodName) { |
387 reporter.internalError(spannable, "$methodName not implemented."); | 385 reporter.internalError(spannable, "$methodName not implemented."); |
388 } | 386 } |
389 | 387 |
390 // Compiles the dart script at [uri]. | 388 // Compiles the dart script at [uri]. |
391 // | 389 // |
392 // The resulting future will complete with true if the compilation | 390 // The resulting future will complete with true if the compilation |
393 // succeded. | 391 // succeeded. |
394 Future<bool> run(Uri uri) { | 392 Future<bool> run(Uri uri) { |
395 totalCompileTime.start(); | 393 totalCompileTime.start(); |
396 | 394 |
397 return new Future.sync(() => runInternal(uri)) | 395 return new Future.sync(() => runInternal(uri)) |
398 .catchError((error) => _reporter.onError(uri, error)) | 396 .catchError((error) => _reporter.onError(uri, error)) |
399 .whenComplete(() { | 397 .whenComplete(() { |
400 tracer.close(); | 398 tracer.close(); |
401 totalCompileTime.stop(); | 399 totalCompileTime.stop(); |
402 }).then((_) { | 400 }).then((_) { |
403 return !compilationFailed; | 401 return !compilationFailed; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 if (chainCount > chainLimit) { | 503 if (chainCount > chainLimit) { |
506 // Assume there are more import chains. | 504 // Assume there are more import chains. |
507 importChains.add('...'); | 505 importChains.add('...'); |
508 return false; | 506 return false; |
509 } | 507 } |
510 return true; | 508 return true; |
511 }); | 509 }); |
512 return importChains; | 510 return importChains; |
513 } | 511 } |
514 | 512 |
515 /// Register that [uri] was recognized but disallowed as a dependency. | |
516 /// | |
517 /// For instance import of 'dart:io' without '--categories=Server'. | |
518 void registerDisallowedLibraryUse(Uri uri) { | |
519 disallowedLibraryUris.add(uri); | |
520 } | |
521 | |
522 /// This method is called when all new libraries loaded through | 513 /// This method is called when all new libraries loaded through |
523 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports | 514 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports |
524 /// have been computed. | 515 /// have been computed. |
525 /// | 516 /// |
526 /// [loadedLibraries] contains the newly loaded libraries. | 517 /// [loadedLibraries] contains the newly loaded libraries. |
527 /// | 518 /// |
528 /// The method returns a [Future] allowing for the loading of additional | 519 /// The method returns a [Future] allowing for the loading of additional |
529 /// libraries. | 520 /// libraries. |
530 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { | 521 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { |
531 return new Future.sync(() { | 522 return new Future.sync(() { |
532 for (Uri uri in disallowedLibraryUris) { | 523 for (Uri uri in resolvedUriTranslator.disallowedLibraryUris) { |
533 if (loadedLibraries.containsLibrary(uri)) { | 524 if (loadedLibraries.containsLibrary(uri)) { |
534 Set<String> importChains = | 525 Set<String> importChains = |
535 computeImportChainsFor(loadedLibraries, uri); | 526 computeImportChainsFor(loadedLibraries, uri); |
536 reporter.reportInfo( | 527 reporter.reportInfo( |
537 NO_LOCATION_SPANNABLE, MessageKind.DISALLOWED_LIBRARY_IMPORT, { | 528 NO_LOCATION_SPANNABLE, MessageKind.DISALLOWED_LIBRARY_IMPORT, { |
538 'uri': uri, | 529 'uri': uri, |
539 'importChain': importChains | 530 'importChain': importChains |
540 .join(MessageTemplate.DISALLOWED_LIBRARY_IMPORT_PADDING) | 531 .join(MessageTemplate.DISALLOWED_LIBRARY_IMPORT_PADDING) |
541 }); | 532 }); |
542 } | 533 } |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1093 return !BENIGN_ERRORS.contains(message.message.kind); | 1084 return !BENIGN_ERRORS.contains(message.message.kind); |
1094 } | 1085 } |
1095 | 1086 |
1096 void fatalDiagnosticReported(DiagnosticMessage message, | 1087 void fatalDiagnosticReported(DiagnosticMessage message, |
1097 List<DiagnosticMessage> infos, api.Diagnostic kind) { | 1088 List<DiagnosticMessage> infos, api.Diagnostic kind) { |
1098 if (markCompilationAsFailed(message, kind)) { | 1089 if (markCompilationAsFailed(message, kind)) { |
1099 compilationFailed = true; | 1090 compilationFailed = true; |
1100 } | 1091 } |
1101 } | 1092 } |
1102 | 1093 |
1103 // TODO(sigmund): move this dart doc somewhere else too. | |
1104 /** | |
1105 * Translates the [resolvedUri] into a readable URI. | |
1106 * | |
1107 * The [importingLibrary] holds the library importing [resolvedUri] or | |
1108 * [:null:] if [resolvedUri] is loaded as the main library. The | |
1109 * [importingLibrary] is used to grant access to internal libraries from | |
1110 * platform libraries and patch libraries. | |
1111 * | |
1112 * If the [resolvedUri] is not accessible from [importingLibrary], this method | |
1113 * is responsible for reporting errors. | |
1114 * | |
1115 * See [LibraryLoader] for terminology on URIs. | |
1116 */ | |
1117 Uri translateResolvedUri( | |
1118 LibraryElement importingLibrary, Uri resolvedUri, Spannable spannable) { | |
1119 unimplemented(importingLibrary, 'Compiler.translateResolvedUri'); | |
1120 return null; | |
1121 } | |
1122 | |
1123 /** | 1094 /** |
1124 * Reads the script specified by the [readableUri]. | 1095 * Reads the script specified by the [readableUri]. |
1125 * | 1096 * |
1126 * See [LibraryLoader] for terminology on URIs. | 1097 * See [LibraryLoader] for terminology on URIs. |
1127 */ | 1098 */ |
1128 Future<Script> readScript(Uri readableUri, [Spannable node]) { | 1099 Future<Script> readScript(Uri readableUri, [Spannable node]) { |
1129 unimplemented(node, 'Compiler.readScript'); | 1100 unimplemented(node, 'Compiler.readScript'); |
1130 return null; | 1101 return null; |
1131 } | 1102 } |
1132 | 1103 |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2013 | 1984 |
2014 @override | 1985 @override |
2015 void parsePatchClass(ClassElement cls) { | 1986 void parsePatchClass(ClassElement cls) { |
2016 compiler.patchParser.measure(() { | 1987 compiler.patchParser.measure(() { |
2017 if (cls.isPatch) { | 1988 if (cls.isPatch) { |
2018 compiler.patchParser.parsePatchClassNode(cls); | 1989 compiler.patchParser.parsePatchClassNode(cls); |
2019 } | 1990 } |
2020 }); | 1991 }); |
2021 } | 1992 } |
2022 | 1993 |
2023 ScannerOptions getScannerOptionsFor(Element element) => | 1994 ScannerOptions getScannerOptionsFor(Element element) => new ScannerOptions( |
2024 new ScannerOptions.from(compiler, element.library); | 1995 canUseNative: compiler.backend.canLibraryUseNative(element.library)); |
2025 | 1996 |
2026 ParserOptions get parserOptions => compiler.options; | 1997 ParserOptions get parserOptions => compiler.options; |
2027 } | 1998 } |
2028 | 1999 |
2029 class GlobalDependencyRegistry extends EagerRegistry { | 2000 class GlobalDependencyRegistry extends EagerRegistry { |
2030 final Compiler compiler; | 2001 final Compiler compiler; |
2031 Setlet<Element> _otherDependencies; | 2002 Setlet<Element> _otherDependencies; |
2032 | 2003 |
2033 GlobalDependencyRegistry(this.compiler) : super('GlobalDependencies', null); | 2004 GlobalDependencyRegistry(this.compiler) : super('GlobalDependencies', null); |
2034 | 2005 |
2035 // TODO(johnniwinther): Rename world/universe/enqueuer through out the | 2006 // TODO(johnniwinther): Rename world/universe/enqueuer through out the |
2036 // compiler. | 2007 // compiler. |
2037 @override | 2008 @override |
2038 Enqueuer get world => compiler.enqueuer.codegen; | 2009 Enqueuer get world => compiler.enqueuer.codegen; |
2039 | 2010 |
2040 void registerDependency(Element element) { | 2011 void registerDependency(Element element) { |
2041 if (element == null) return; | 2012 if (element == null) return; |
2042 if (_otherDependencies == null) { | 2013 if (_otherDependencies == null) { |
2043 _otherDependencies = new Setlet<Element>(); | 2014 _otherDependencies = new Setlet<Element>(); |
2044 } | 2015 } |
2045 _otherDependencies.add(element.implementation); | 2016 _otherDependencies.add(element.implementation); |
2046 } | 2017 } |
2047 | 2018 |
2048 Iterable<Element> get otherDependencies { | 2019 Iterable<Element> get otherDependencies { |
2049 return _otherDependencies != null ? _otherDependencies : const <Element>[]; | 2020 return _otherDependencies != null ? _otherDependencies : const <Element>[]; |
2050 } | 2021 } |
2051 } | 2022 } |
2052 | 2023 |
2053 // TODO(sigmund): in the future, each of these classes should be self contained | |
2054 // and not use references to `compiler`. | |
2055 class _ResolvedUriTranslator implements ResolvedUriTranslator { | |
2056 Compiler compiler; | |
2057 _ResolvedUriTranslator(this.compiler); | |
2058 | |
2059 Uri translate(LibraryElement importingLibrary, Uri resolvedUri, | |
2060 [Spannable spannable]) => | |
2061 compiler.translateResolvedUri(importingLibrary, resolvedUri, spannable); | |
2062 } | |
2063 | |
2064 class _ScriptLoader implements ScriptLoader { | 2024 class _ScriptLoader implements ScriptLoader { |
2065 Compiler compiler; | 2025 Compiler compiler; |
2066 _ScriptLoader(this.compiler); | 2026 _ScriptLoader(this.compiler); |
2067 | 2027 |
2068 Future<Script> readScript(Uri uri, [Spannable spannable]) => | 2028 Future<Script> readScript(Uri uri, [Spannable spannable]) => |
2069 compiler.readScript(uri, spannable); | 2029 compiler.readScript(uri, spannable); |
2070 } | 2030 } |
2071 | 2031 |
2072 class _ElementScanner implements ElementScanner { | 2032 class _ElementScanner implements ElementScanner { |
2073 ScannerTask scanner; | 2033 ScannerTask scanner; |
2074 _ElementScanner(this.scanner); | 2034 _ElementScanner(this.scanner); |
2075 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2035 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
2076 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2036 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
2077 } | 2037 } |
2078 | 2038 |
2079 class _EmptyEnvironment implements Environment { | 2039 class _EmptyEnvironment implements Environment { |
2080 const _EmptyEnvironment(); | 2040 const _EmptyEnvironment(); |
2081 | 2041 |
2082 String valueOf(String key) => null; | 2042 String valueOf(String key) => null; |
2083 } | 2043 } |
OLD | NEW |