| 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 'closure.dart' as closureMapping show ClosureTask; | 10 import 'closure.dart' as closureMapping show ClosureTask; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 import 'elements/resolution_types.dart' | 36 import 'elements/resolution_types.dart' |
| 37 show | 37 show |
| 38 ResolutionDartType, | 38 ResolutionDartType, |
| 39 ResolutionDynamicType, | 39 ResolutionDynamicType, |
| 40 ResolutionInterfaceType, | 40 ResolutionInterfaceType, |
| 41 Types; | 41 Types; |
| 42 import 'enqueue.dart' show Enqueuer, EnqueueTask, ResolutionEnqueuer; | 42 import 'enqueue.dart' show Enqueuer, EnqueueTask, ResolutionEnqueuer; |
| 43 import 'environment.dart'; | 43 import 'environment.dart'; |
| 44 import 'id_generator.dart'; | 44 import 'id_generator.dart'; |
| 45 import 'io/source_information.dart' show SourceInformation; | 45 import 'io/source_information.dart' show SourceInformation; |
| 46 import 'js_backend/backend_helpers.dart' as js_backend show BackendHelpers; | |
| 47 import 'js_backend/js_backend.dart' as js_backend show JavaScriptBackend; | 46 import 'js_backend/js_backend.dart' as js_backend show JavaScriptBackend; |
| 48 import 'library_loader.dart' | 47 import 'library_loader.dart' |
| 49 show | 48 show |
| 50 ElementScanner, | 49 ElementScanner, |
| 51 LibraryLoader, | 50 LibraryLoader, |
| 52 LibraryLoaderTask, | 51 LibraryLoaderTask, |
| 53 LoadedLibraries, | 52 LoadedLibraries, |
| 54 LibraryLoaderListener, | 53 LibraryLoaderListener, |
| 55 LibraryProvider, | 54 LibraryProvider, |
| 56 ScriptLoader; | 55 ScriptLoader; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 70 import 'tokens/token_map.dart' show TokenMap; | 69 import 'tokens/token_map.dart' show TokenMap; |
| 71 import 'tree/tree.dart' show Node, TypeAnnotation; | 70 import 'tree/tree.dart' show Node, TypeAnnotation; |
| 72 import 'typechecker.dart' show TypeCheckerTask; | 71 import 'typechecker.dart' show TypeCheckerTask; |
| 73 import 'types/types.dart' show GlobalTypeInferenceTask; | 72 import 'types/types.dart' show GlobalTypeInferenceTask; |
| 74 import 'universe/selector.dart' show Selector; | 73 import 'universe/selector.dart' show Selector; |
| 75 import 'universe/world_builder.dart' | 74 import 'universe/world_builder.dart' |
| 76 show ResolutionWorldBuilder, CodegenWorldBuilder; | 75 show ResolutionWorldBuilder, CodegenWorldBuilder; |
| 77 import 'universe/use.dart' show StaticUse, TypeUse; | 76 import 'universe/use.dart' show StaticUse, TypeUse; |
| 78 import 'universe/world_impact.dart' | 77 import 'universe/world_impact.dart' |
| 79 show ImpactStrategy, WorldImpact, WorldImpactBuilderImpl; | 78 show ImpactStrategy, WorldImpact, WorldImpactBuilderImpl; |
| 80 import 'util/util.dart' show Link, Setlet; | 79 import 'util/util.dart' show Link; |
| 81 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, ClosedWorldImpl; | 80 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, ClosedWorldImpl; |
| 82 | 81 |
| 83 typedef CompilerDiagnosticReporter MakeReporterFunction( | 82 typedef CompilerDiagnosticReporter MakeReporterFunction( |
| 84 Compiler compiler, CompilerOptions options); | 83 Compiler compiler, CompilerOptions options); |
| 85 | 84 |
| 86 abstract class Compiler implements LibraryLoaderListener { | 85 abstract class Compiler implements LibraryLoaderListener { |
| 87 Measurer get measurer; | 86 Measurer get measurer; |
| 88 | 87 |
| 89 final IdGenerator idGenerator = new IdGenerator(); | 88 final IdGenerator idGenerator = new IdGenerator(); |
| 90 Types types; | 89 Types types; |
| 91 _CompilerCommonElements _commonElements; | 90 _CompilerCommonElements _commonElements; |
| 92 _CompilerElementEnvironment _elementEnvironment; | 91 _CompilerElementEnvironment _elementEnvironment; |
| 93 CompilerDiagnosticReporter _reporter; | 92 CompilerDiagnosticReporter _reporter; |
| 94 CompilerResolution _resolution; | 93 CompilerResolution _resolution; |
| 95 ParsingContext _parsingContext; | 94 ParsingContext _parsingContext; |
| 96 | 95 |
| 97 ImpactStrategy impactStrategy = const ImpactStrategy(); | 96 ImpactStrategy impactStrategy = const ImpactStrategy(); |
| 98 | 97 |
| 99 /** | 98 /** |
| 100 * Map from token to the first preceding comment token. | 99 * Map from token to the first preceding comment token. |
| 101 */ | 100 */ |
| 102 final TokenMap commentMap = new TokenMap(); | 101 final TokenMap commentMap = new TokenMap(); |
| 103 | 102 |
| 104 /** | |
| 105 * Records global dependencies, that is, dependencies that don't | |
| 106 * correspond to a particular element. | |
| 107 * | |
| 108 * We should get rid of this and ensure that all dependencies are | |
| 109 * associated with a particular element. | |
| 110 */ | |
| 111 GlobalDependencyRegistry globalDependencies; | |
| 112 | |
| 113 /// Options provided from command-line arguments. | 103 /// Options provided from command-line arguments. |
| 114 final CompilerOptions options; | 104 final CompilerOptions options; |
| 115 | 105 |
| 116 /** | 106 /** |
| 117 * If true, stop compilation after type inference is complete. Used for | 107 * If true, stop compilation after type inference is complete. Used for |
| 118 * debugging and testing purposes only. | 108 * debugging and testing purposes only. |
| 119 */ | 109 */ |
| 120 bool stopAfterTypeInference = false; | 110 bool stopAfterTypeInference = false; |
| 121 | 111 |
| 122 /// Output provider from user of Compiler API. | 112 /// Output provider from user of Compiler API. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 _resolution = createResolution(); | 196 _resolution = createResolution(); |
| 207 _elementEnvironment = new _CompilerElementEnvironment(this); | 197 _elementEnvironment = new _CompilerElementEnvironment(this); |
| 208 _commonElements = | 198 _commonElements = |
| 209 new _CompilerCommonElements(_elementEnvironment, _resolution, reporter); | 199 new _CompilerCommonElements(_elementEnvironment, _resolution, reporter); |
| 210 types = new Types(_resolution); | 200 types = new Types(_resolution); |
| 211 | 201 |
| 212 if (options.verbose) { | 202 if (options.verbose) { |
| 213 progress = new Stopwatch()..start(); | 203 progress = new Stopwatch()..start(); |
| 214 } | 204 } |
| 215 | 205 |
| 216 // TODO(johnniwinther): Separate the dependency tracking from the enqueuing | |
| 217 // for global dependencies. | |
| 218 globalDependencies = new GlobalDependencyRegistry(); | |
| 219 | |
| 220 backend = createBackend(); | 206 backend = createBackend(); |
| 221 enqueuer = backend.makeEnqueuer(); | 207 enqueuer = backend.makeEnqueuer(); |
| 222 | 208 |
| 223 tasks = [ | 209 tasks = [ |
| 224 dietParser = new DietParserTask(idGenerator, backend, reporter, measurer), | 210 dietParser = new DietParserTask(idGenerator, backend, reporter, measurer), |
| 225 scanner = createScannerTask(), | 211 scanner = createScannerTask(), |
| 226 serialization = new SerializationTask(this), | 212 serialization = new SerializationTask(this), |
| 227 libraryLoader = new LibraryLoaderTask( | 213 libraryLoader = new LibraryLoaderTask( |
| 228 resolvedUriTranslator, | 214 resolvedUriTranslator, |
| 229 options.compileOnly | 215 options.compileOnly |
| (...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1891 if (field == null) return false; | 1877 if (field == null) return false; |
| 1892 if (!hasBeenResolved(field)) return false; | 1878 if (!hasBeenResolved(field)) return false; |
| 1893 if (_proxyConstant == null) { | 1879 if (_proxyConstant == null) { |
| 1894 _proxyConstant = constants | 1880 _proxyConstant = constants |
| 1895 .getConstantValue(resolver.constantCompiler.compileConstant(field)); | 1881 .getConstantValue(resolver.constantCompiler.compileConstant(field)); |
| 1896 } | 1882 } |
| 1897 return _proxyConstant == value; | 1883 return _proxyConstant == value; |
| 1898 } | 1884 } |
| 1899 } | 1885 } |
| 1900 | 1886 |
| 1901 class GlobalDependencyRegistry { | |
| 1902 Setlet<Element> _otherDependencies; | |
| 1903 | |
| 1904 GlobalDependencyRegistry(); | |
| 1905 | |
| 1906 void registerDependency(Element element) { | |
| 1907 if (element == null) return; | |
| 1908 if (_otherDependencies == null) { | |
| 1909 _otherDependencies = new Setlet<Element>(); | |
| 1910 } | |
| 1911 _otherDependencies.add(element.implementation); | |
| 1912 } | |
| 1913 | |
| 1914 Iterable<Element> get otherDependencies { | |
| 1915 return _otherDependencies != null ? _otherDependencies : const <Element>[]; | |
| 1916 } | |
| 1917 | |
| 1918 String get name => 'GlobalDependencies'; | |
| 1919 } | |
| 1920 | |
| 1921 class _ScriptLoader implements ScriptLoader { | 1887 class _ScriptLoader implements ScriptLoader { |
| 1922 Compiler compiler; | 1888 Compiler compiler; |
| 1923 _ScriptLoader(this.compiler); | 1889 _ScriptLoader(this.compiler); |
| 1924 | 1890 |
| 1925 Future<Script> readScript(Uri uri, [Spannable spannable]) => | 1891 Future<Script> readScript(Uri uri, [Spannable spannable]) => |
| 1926 compiler.readScript(uri, spannable); | 1892 compiler.readScript(uri, spannable); |
| 1927 } | 1893 } |
| 1928 | 1894 |
| 1929 /// [ScriptLoader] used to ensure that scripts are not loaded accidentally | 1895 /// [ScriptLoader] used to ensure that scripts are not loaded accidentally |
| 1930 /// through the [LibraryLoader] when `CompilerOptions.compileOnly` is `true`. | 1896 /// through the [LibraryLoader] when `CompilerOptions.compileOnly` is `true`. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2067 if (library != null && library.isSynthesized) { | 2033 if (library != null && library.isSynthesized) { |
| 2068 return null; | 2034 return null; |
| 2069 } | 2035 } |
| 2070 if (library == null && required) { | 2036 if (library == null && required) { |
| 2071 throw new SpannableAssertionFailure( | 2037 throw new SpannableAssertionFailure( |
| 2072 library, "The library '${uri}' was not found."); | 2038 library, "The library '${uri}' was not found."); |
| 2073 } | 2039 } |
| 2074 return library; | 2040 return library; |
| 2075 } | 2041 } |
| 2076 } | 2042 } |
| OLD | NEW |