| 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; |
| 11 import 'closure.dart' as closureMapping show ClosureTask; | 11 import 'closure.dart' as closureMapping show ClosureTask; |
| 12 import 'common/backend_api.dart' show Backend; | 12 import 'common/backend_api.dart' show Backend; |
| 13 import 'common/codegen.dart' show CodegenWorkItem; | |
| 14 import 'common/names.dart' show Selectors; | 13 import 'common/names.dart' show Selectors; |
| 15 import 'common/names.dart' show Identifiers, Uris; | 14 import 'common/names.dart' show Identifiers, Uris; |
| 16 import 'common/resolution.dart' | 15 import 'common/resolution.dart' |
| 17 show | 16 show |
| 18 ParsingContext, | 17 ParsingContext, |
| 19 Resolution, | 18 Resolution, |
| 20 ResolutionWorkItem, | 19 ResolutionWorkItem, |
| 21 ResolutionImpact, | 20 ResolutionImpact, |
| 22 Target; | 21 Target; |
| 23 import 'common/tasks.dart' show CompilerTask, GenericTask, Measurer; | 22 import 'common/tasks.dart' show CompilerTask, GenericTask, Measurer; |
| 24 import 'common/work.dart' show WorkItem; | 23 import 'common/work.dart' show WorkItem; |
| 25 import 'common.dart'; | 24 import 'common.dart'; |
| 26 import 'compile_time_constants.dart'; | 25 import 'compile_time_constants.dart'; |
| 27 import 'constants/values.dart'; | 26 import 'constants/values.dart'; |
| 28 import 'core_types.dart' show CoreClasses, CommonElements, CoreTypes; | 27 import 'core_types.dart' show CommonElements; |
| 29 import 'dart_types.dart' show DartType, DynamicType, InterfaceType, Types; | 28 import 'dart_types.dart' show DartType, DynamicType, InterfaceType, Types; |
| 30 import 'deferred_load.dart' show DeferredLoadTask; | 29 import 'deferred_load.dart' show DeferredLoadTask; |
| 31 import 'diagnostics/code_location.dart'; | 30 import 'diagnostics/code_location.dart'; |
| 32 import 'diagnostics/diagnostic_listener.dart' show DiagnosticReporter; | 31 import 'diagnostics/diagnostic_listener.dart' show DiagnosticReporter; |
| 33 import 'diagnostics/invariant.dart' show REPORT_EXCESS_RESOLUTION; | 32 import 'diagnostics/invariant.dart' show REPORT_EXCESS_RESOLUTION; |
| 34 import 'diagnostics/messages.dart' show Message, MessageTemplate; | 33 import 'diagnostics/messages.dart' show Message, MessageTemplate; |
| 35 import 'dump_info.dart' show DumpInfoTask; | 34 import 'dump_info.dart' show DumpInfoTask; |
| 36 import 'elements/elements.dart'; | 35 import 'elements/elements.dart'; |
| 37 import 'elements/modelx.dart' show ErroneousElementX; | 36 import 'elements/modelx.dart' show ErroneousElementX; |
| 38 import 'enqueue.dart' show Enqueuer, EnqueueTask, ResolutionEnqueuer; | 37 import 'enqueue.dart' show Enqueuer, EnqueueTask, ResolutionEnqueuer; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 typedef Backend MakeBackendFunction(Compiler compiler); | 82 typedef Backend MakeBackendFunction(Compiler compiler); |
| 84 | 83 |
| 85 typedef CompilerDiagnosticReporter MakeReporterFunction( | 84 typedef CompilerDiagnosticReporter MakeReporterFunction( |
| 86 Compiler compiler, CompilerOptions options); | 85 Compiler compiler, CompilerOptions options); |
| 87 | 86 |
| 88 abstract class Compiler implements LibraryLoaderListener { | 87 abstract class Compiler implements LibraryLoaderListener { |
| 89 Measurer get measurer; | 88 Measurer get measurer; |
| 90 | 89 |
| 91 final IdGenerator idGenerator = new IdGenerator(); | 90 final IdGenerator idGenerator = new IdGenerator(); |
| 92 Types types; | 91 Types types; |
| 93 _CompilerCoreTypes _coreTypes; | 92 _CompilerCommonElements _commonElements; |
| 94 CompilerDiagnosticReporter _reporter; | 93 CompilerDiagnosticReporter _reporter; |
| 95 CompilerResolution _resolution; | 94 CompilerResolution _resolution; |
| 96 ParsingContext _parsingContext; | 95 ParsingContext _parsingContext; |
| 97 | 96 |
| 98 final CacheStrategy cacheStrategy; | 97 final CacheStrategy cacheStrategy; |
| 99 | 98 |
| 100 ImpactStrategy impactStrategy = const ImpactStrategy(); | 99 ImpactStrategy impactStrategy = const ImpactStrategy(); |
| 101 | 100 |
| 102 /** | 101 /** |
| 103 * Map from token to the first preceding comment token. | 102 * Map from token to the first preceding comment token. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 126 api.CompilerOutput userOutputProvider; | 125 api.CompilerOutput userOutputProvider; |
| 127 | 126 |
| 128 List<Uri> librariesToAnalyzeWhenRun; | 127 List<Uri> librariesToAnalyzeWhenRun; |
| 129 | 128 |
| 130 ResolvedUriTranslator get resolvedUriTranslator; | 129 ResolvedUriTranslator get resolvedUriTranslator; |
| 131 | 130 |
| 132 LibraryElement mainApp; | 131 LibraryElement mainApp; |
| 133 FunctionElement mainFunction; | 132 FunctionElement mainFunction; |
| 134 | 133 |
| 135 DiagnosticReporter get reporter => _reporter; | 134 DiagnosticReporter get reporter => _reporter; |
| 136 CommonElements get commonElements => _coreTypes; | 135 CommonElements get commonElements => _commonElements; |
| 137 CoreClasses get coreClasses => _coreTypes; | |
| 138 CoreTypes get coreTypes => _coreTypes; | |
| 139 Resolution get resolution => _resolution; | 136 Resolution get resolution => _resolution; |
| 140 ParsingContext get parsingContext => _parsingContext; | 137 ParsingContext get parsingContext => _parsingContext; |
| 141 | 138 |
| 142 // TODO(zarah): Remove this map and incorporate compile-time errors | 139 // TODO(zarah): Remove this map and incorporate compile-time errors |
| 143 // in the model. | 140 // in the model. |
| 144 /// Tracks elements with compile-time errors. | 141 /// Tracks elements with compile-time errors. |
| 145 final Map<Element, List<DiagnosticMessage>> elementsWithCompileTimeErrors = | 142 final Map<Element, List<DiagnosticMessage>> elementsWithCompileTimeErrors = |
| 146 new Map<Element, List<DiagnosticMessage>>(); | 143 new Map<Element, List<DiagnosticMessage>>(); |
| 147 | 144 |
| 148 final Environment environment; | 145 final Environment environment; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport), | 200 this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport), |
| 204 this.userOutputProvider = outputProvider == null | 201 this.userOutputProvider = outputProvider == null |
| 205 ? const NullCompilerOutput() | 202 ? const NullCompilerOutput() |
| 206 : outputProvider { | 203 : outputProvider { |
| 207 if (makeReporter != null) { | 204 if (makeReporter != null) { |
| 208 _reporter = makeReporter(this, options); | 205 _reporter = makeReporter(this, options); |
| 209 } else { | 206 } else { |
| 210 _reporter = new CompilerDiagnosticReporter(this, options); | 207 _reporter = new CompilerDiagnosticReporter(this, options); |
| 211 } | 208 } |
| 212 _resolution = createResolution(); | 209 _resolution = createResolution(); |
| 213 // TODO(johnniwinther): Initialize core types in [initializeCoreClasses] and | 210 _commonElements = new _CompilerCommonElements(_resolution, reporter); |
| 214 // make its field final. | |
| 215 _coreTypes = new _CompilerCoreTypes(_resolution, reporter); | |
| 216 types = new Types(_resolution); | 211 types = new Types(_resolution); |
| 217 | 212 |
| 218 if (options.verbose) { | 213 if (options.verbose) { |
| 219 progress = new Stopwatch()..start(); | 214 progress = new Stopwatch()..start(); |
| 220 } | 215 } |
| 221 | 216 |
| 222 // TODO(johnniwinther): Separate the dependency tracking from the enqueuing | 217 // TODO(johnniwinther): Separate the dependency tracking from the enqueuing |
| 223 // for global dependencies. | 218 // for global dependencies. |
| 224 globalDependencies = new GlobalDependencyRegistry(); | 219 globalDependencies = new GlobalDependencyRegistry(); |
| 225 | 220 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 }); | 334 }); |
| 340 }); | 335 }); |
| 341 | 336 |
| 342 /// This method is called immediately after the [LibraryElement] [library] has | 337 /// This method is called immediately after the [LibraryElement] [library] has |
| 343 /// been created. | 338 /// been created. |
| 344 /// | 339 /// |
| 345 /// Use this callback method to store references to specific libraries. | 340 /// Use this callback method to store references to specific libraries. |
| 346 /// Note that [library] has not been scanned yet, nor has its imports/exports | 341 /// Note that [library] has not been scanned yet, nor has its imports/exports |
| 347 /// been resolved. | 342 /// been resolved. |
| 348 void onLibraryCreated(LibraryElement library) { | 343 void onLibraryCreated(LibraryElement library) { |
| 349 _coreTypes.onLibraryCreated(library); | 344 _commonElements.onLibraryCreated(library); |
| 350 backend.onLibraryCreated(library); | 345 backend.onLibraryCreated(library); |
| 351 } | 346 } |
| 352 | 347 |
| 353 /// This method is called immediately after the [library] and its parts have | 348 /// This method is called immediately after the [library] and its parts have |
| 354 /// been scanned. | 349 /// been scanned. |
| 355 /// | 350 /// |
| 356 /// Use this callback method to store references to specific member declared | 351 /// Use this callback method to store references to specific member declared |
| 357 /// in certain libraries. Note that [library] has not been patched yet, nor | 352 /// in certain libraries. Note that [library] has not been patched yet, nor |
| 358 /// has its imports/exports been resolved. | 353 /// has its imports/exports been resolved. |
| 359 /// | 354 /// |
| (...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 return userOutputProvider.createEventSink(name, extension); | 1115 return userOutputProvider.createEventSink(name, extension); |
| 1121 } | 1116 } |
| 1122 } | 1117 } |
| 1123 | 1118 |
| 1124 /// Information about suppressed warnings and hints for a given library. | 1119 /// Information about suppressed warnings and hints for a given library. |
| 1125 class SuppressionInfo { | 1120 class SuppressionInfo { |
| 1126 int warnings = 0; | 1121 int warnings = 0; |
| 1127 int hints = 0; | 1122 int hints = 0; |
| 1128 } | 1123 } |
| 1129 | 1124 |
| 1130 class _CompilerCoreTypes implements CoreTypes, CoreClasses, CommonElements { | 1125 class _CompilerCommonElements implements CommonElements { |
| 1131 final Resolution resolution; | 1126 final Resolution resolution; |
| 1132 final DiagnosticReporter reporter; | 1127 final DiagnosticReporter reporter; |
| 1133 | 1128 |
| 1134 LibraryElement coreLibrary; | 1129 LibraryElement coreLibrary; |
| 1135 LibraryElement asyncLibrary; | 1130 LibraryElement asyncLibrary; |
| 1136 LibraryElement mirrorsLibrary; | 1131 LibraryElement mirrorsLibrary; |
| 1137 LibraryElement typedDataLibrary; | 1132 LibraryElement typedDataLibrary; |
| 1138 | 1133 |
| 1139 // TODO(sigmund): possibly move this to target-specific collection of | 1134 // TODO(sigmund): possibly move this to target-specific collection of |
| 1140 // elements, or refactor the library so that the helpers we need are in a | 1135 // elements, or refactor the library so that the helpers we need are in a |
| 1141 // target-agnostic place. Currently we are using @patch and @Native from | 1136 // target-agnostic place. Currently we are using @patch and @Native from |
| 1142 // here. We hope we can make those independent of the backend and generic | 1137 // here. We hope we can make those independent of the backend and generic |
| 1143 // enough so the patching algorithm can work without being configured for a | 1138 // enough so the patching algorithm can work without being configured for a |
| 1144 // specific backend. | 1139 // specific backend. |
| 1145 LibraryElement jsHelperLibrary; | 1140 LibraryElement jsHelperLibrary; |
| 1146 | 1141 |
| 1147 _CompilerCoreTypes(this.resolution, this.reporter); | 1142 _CompilerCommonElements(this.resolution, this.reporter); |
| 1148 | 1143 |
| 1149 // From dart:core | 1144 // From dart:core |
| 1150 | 1145 |
| 1151 ClassElement _objectClass; | 1146 ClassElement _objectClass; |
| 1152 ClassElement get objectClass => | 1147 ClassElement get objectClass => |
| 1153 _objectClass ??= _findRequired(coreLibrary, 'Object'); | 1148 _objectClass ??= _findRequired(coreLibrary, 'Object'); |
| 1154 | 1149 |
| 1155 ClassElement _boolClass; | 1150 ClassElement _boolClass; |
| 1156 ClassElement get boolClass => | 1151 ClassElement get boolClass => |
| 1157 _boolClass ??= _findRequired(coreLibrary, 'bool'); | 1152 _boolClass ??= _findRequired(coreLibrary, 'bool'); |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 | 1902 |
| 1908 CompilerResolution(this._compiler); | 1903 CompilerResolution(this._compiler); |
| 1909 | 1904 |
| 1910 @override | 1905 @override |
| 1911 DiagnosticReporter get reporter => _compiler.reporter; | 1906 DiagnosticReporter get reporter => _compiler.reporter; |
| 1912 | 1907 |
| 1913 @override | 1908 @override |
| 1914 ParsingContext get parsingContext => _compiler.parsingContext; | 1909 ParsingContext get parsingContext => _compiler.parsingContext; |
| 1915 | 1910 |
| 1916 @override | 1911 @override |
| 1917 CoreClasses get coreClasses => _compiler.coreClasses; | |
| 1918 | |
| 1919 @override | |
| 1920 CoreTypes get coreTypes => _compiler.coreTypes; | |
| 1921 | |
| 1922 @override | |
| 1923 CommonElements get commonElements => _compiler.commonElements; | 1912 CommonElements get commonElements => _compiler.commonElements; |
| 1924 | 1913 |
| 1925 @override | 1914 @override |
| 1926 Types get types => _compiler.types; | 1915 Types get types => _compiler.types; |
| 1927 | 1916 |
| 1928 @override | 1917 @override |
| 1929 Target get target => _compiler.backend; | 1918 Target get target => _compiler.backend; |
| 1930 | 1919 |
| 1931 @override | 1920 @override |
| 1932 ResolverTask get resolver => _compiler.resolver; | 1921 ResolverTask get resolver => _compiler.resolver; |
| 1933 | 1922 |
| 1934 @override | 1923 @override |
| 1935 ResolutionEnqueuer get enqueuer => _compiler.enqueuer.resolution; | 1924 ResolutionEnqueuer get enqueuer => _compiler.enqueuer.resolution; |
| 1936 | 1925 |
| 1937 @override | 1926 @override |
| 1938 CompilerOptions get options => _compiler.options; | 1927 CompilerOptions get options => _compiler.options; |
| 1939 | 1928 |
| 1940 @override | 1929 @override |
| 1941 IdGenerator get idGenerator => _compiler.idGenerator; | 1930 IdGenerator get idGenerator => _compiler.idGenerator; |
| 1942 | 1931 |
| 1943 @override | 1932 @override |
| 1944 ConstantEnvironment get constants => _compiler.constants; | 1933 ConstantEnvironment get constants => _compiler.constants; |
| 1945 | 1934 |
| 1946 @override | 1935 @override |
| 1947 MirrorUsageAnalyzerTask get mirrorUsageAnalyzerTask => | 1936 MirrorUsageAnalyzerTask get mirrorUsageAnalyzerTask => |
| 1948 _compiler.mirrorUsageAnalyzerTask; | 1937 _compiler.mirrorUsageAnalyzerTask; |
| 1949 | 1938 |
| 1950 @override | 1939 @override |
| 1951 LibraryElement get coreLibrary => _compiler._coreTypes.coreLibrary; | 1940 LibraryElement get coreLibrary => _compiler._commonElements.coreLibrary; |
| 1952 | 1941 |
| 1953 @override | 1942 @override |
| 1954 bool get wasProxyConstantComputedTestingOnly => _proxyConstant != null; | 1943 bool get wasProxyConstantComputedTestingOnly => _proxyConstant != null; |
| 1955 | 1944 |
| 1956 @override | 1945 @override |
| 1957 void registerClass(ClassElement cls) { | 1946 void registerClass(ClassElement cls) { |
| 1958 enqueuer.universe.registerClass(cls); | 1947 enqueuer.universe.registerClass(cls); |
| 1959 } | 1948 } |
| 1960 | 1949 |
| 1961 @override | 1950 @override |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2220 _ElementScanner(this.scanner); | 2209 _ElementScanner(this.scanner); |
| 2221 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2210 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 2222 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2211 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 2223 } | 2212 } |
| 2224 | 2213 |
| 2225 class _EmptyEnvironment implements Environment { | 2214 class _EmptyEnvironment implements Environment { |
| 2226 const _EmptyEnvironment(); | 2215 const _EmptyEnvironment(); |
| 2227 | 2216 |
| 2228 String valueOf(String key) => null; | 2217 String valueOf(String key) => null; |
| 2229 } | 2218 } |
| OLD | NEW |