| 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; | 13 import 'common/codegen.dart' show CodegenWorkItem; |
| 14 import 'common/names.dart' show Selectors; | 14 import 'common/names.dart' show Selectors; |
| 15 import 'common/names.dart' show Identifiers, Uris; | 15 import 'common/names.dart' show Identifiers, Uris; |
| 16 import 'common/registry.dart' show EagerRegistry, Registry; | 16 import 'common/registry.dart' show EagerRegistry, Registry; |
| 17 import 'common/resolution.dart' | 17 import 'common/resolution.dart' |
| 18 show Parsing, Resolution, ResolutionWorkItem, ResolutionImpact; | 18 show ParsingContext, Resolution, ResolutionWorkItem, ResolutionImpact; |
| 19 import 'common/tasks.dart' show CompilerTask, GenericTask; | 19 import 'common/tasks.dart' show CompilerTask, GenericTask; |
| 20 import 'common/work.dart' show ItemCompilationContext, WorkItem; | 20 import 'common/work.dart' show ItemCompilationContext, WorkItem; |
| 21 import 'common.dart'; | 21 import 'common.dart'; |
| 22 import 'compile_time_constants.dart'; | 22 import 'compile_time_constants.dart'; |
| 23 import 'constants/values.dart'; | 23 import 'constants/values.dart'; |
| 24 import 'core_types.dart' show CoreClasses, CoreTypes; | 24 import 'core_types.dart' show CoreClasses, CoreTypes; |
| 25 import 'dart_backend/dart_backend.dart' as dart_backend; | 25 import 'dart_backend/dart_backend.dart' as dart_backend; |
| 26 import 'dart_types.dart' show DartType, DynamicType, InterfaceType, Types; | 26 import 'dart_types.dart' show DartType, DynamicType, InterfaceType, Types; |
| 27 import 'deferred_load.dart' show DeferredLoadTask; | 27 import 'deferred_load.dart' show DeferredLoadTask; |
| 28 import 'diagnostics/code_location.dart'; | 28 import 'diagnostics/code_location.dart'; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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 ScriptLoader; | 54 ScriptLoader; |
| 55 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; | 55 import 'mirrors_used.dart' show MirrorUsageAnalyzerTask; |
| 56 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; | 56 import 'null_compiler_output.dart' show NullCompilerOutput, NullSink; |
| 57 import 'options.dart' show CompilerOptions, DiagnosticOptions, ParserOptions; | 57 import 'options.dart' show CompilerOptions, DiagnosticOptions; |
| 58 import 'parser/diet_parser_task.dart' show DietParserTask; | 58 import 'parser/diet_parser_task.dart' show DietParserTask; |
| 59 import 'parser/element_listener.dart' show ScannerOptions; | |
| 60 import 'parser/parser_task.dart' show ParserTask; | 59 import 'parser/parser_task.dart' show ParserTask; |
| 61 import 'patch_parser.dart' show PatchParserTask; | 60 import 'patch_parser.dart' show PatchParserTask; |
| 62 import 'resolution/registry.dart' show ResolutionRegistry; | 61 import 'resolution/registry.dart' show ResolutionRegistry; |
| 63 import 'resolution/resolution.dart' show ResolverTask; | 62 import 'resolution/resolution.dart' show ResolverTask; |
| 64 import 'resolution/tree_elements.dart' show TreeElementMapping; | 63 import 'resolution/tree_elements.dart' show TreeElementMapping; |
| 65 import 'resolved_uri_translator.dart'; | 64 import 'resolved_uri_translator.dart'; |
| 66 import 'scanner/scanner_task.dart' show ScannerTask; | 65 import 'scanner/scanner_task.dart' show ScannerTask; |
| 67 import 'script.dart' show Script; | 66 import 'script.dart' show Script; |
| 68 import 'serialization/task.dart' show SerializationTask; | 67 import 'serialization/task.dart' show SerializationTask; |
| 69 import 'ssa/nodes.dart' show HInstruction; | 68 import 'ssa/nodes.dart' show HInstruction; |
| 70 import 'tokens/token.dart' show StringToken, Token, TokenPair; | 69 import 'tokens/token.dart' show StringToken, Token, TokenPair; |
| 71 import 'tokens/token_map.dart' show TokenMap; | 70 import 'tokens/token_map.dart' show TokenMap; |
| 72 import 'tracer.dart' show Tracer; | 71 import 'tracer.dart' show Tracer; |
| 73 import 'tree/tree.dart' show Node, TypeAnnotation; | 72 import 'tree/tree.dart' show Node, TypeAnnotation; |
| 74 import 'typechecker.dart' show TypeCheckerTask; | 73 import 'typechecker.dart' show TypeCheckerTask; |
| 75 import 'types/types.dart' as ti; | 74 import 'types/types.dart' as ti; |
| 76 import 'universe/call_structure.dart' show CallStructure; | |
| 77 import 'universe/selector.dart' show Selector; | 75 import 'universe/selector.dart' show Selector; |
| 78 import 'universe/universe.dart' show Universe; | 76 import 'universe/universe.dart' show Universe; |
| 79 import 'universe/use.dart' show StaticUse; | 77 import 'universe/use.dart' show StaticUse; |
| 80 import 'universe/world_impact.dart' show ImpactStrategy, WorldImpact; | 78 import 'universe/world_impact.dart' show ImpactStrategy, WorldImpact; |
| 81 import 'util/util.dart' show Link, Setlet; | 79 import 'util/util.dart' show Link, Setlet; |
| 82 import 'world.dart' show World; | 80 import 'world.dart' show World; |
| 83 | 81 |
| 84 abstract class Compiler implements LibraryLoaderListener { | 82 abstract class Compiler implements LibraryLoaderListener { |
| 85 final Stopwatch totalCompileTime = new Stopwatch(); | 83 final Stopwatch totalCompileTime = new Stopwatch(); |
| 86 final IdGenerator idGenerator = new IdGenerator(); | 84 final IdGenerator idGenerator = new IdGenerator(); |
| 87 World world; | 85 World world; |
| 88 Types types; | 86 Types types; |
| 89 _CompilerCoreTypes _coreTypes; | 87 _CompilerCoreTypes _coreTypes; |
| 90 _CompilerDiagnosticReporter _reporter; | 88 _CompilerDiagnosticReporter _reporter; |
| 91 _CompilerResolution _resolution; | 89 _CompilerResolution _resolution; |
| 92 _CompilerParsing _parsing; | 90 ParsingContext _parsingContext; |
| 93 | 91 |
| 94 final CacheStrategy cacheStrategy; | 92 final CacheStrategy cacheStrategy; |
| 95 | 93 |
| 96 ImpactStrategy impactStrategy = const ImpactStrategy(); | 94 ImpactStrategy impactStrategy = const ImpactStrategy(); |
| 97 | 95 |
| 98 /** | 96 /** |
| 99 * Map from token to the first preceding comment token. | 97 * Map from token to the first preceding comment token. |
| 100 */ | 98 */ |
| 101 final TokenMap commentMap = new TokenMap(); | 99 final TokenMap commentMap = new TokenMap(); |
| 102 | 100 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 /// Initialized when dart:mirrors is loaded. | 145 /// Initialized when dart:mirrors is loaded. |
| 148 LibraryElement mirrorsLibrary; | 146 LibraryElement mirrorsLibrary; |
| 149 | 147 |
| 150 /// Initialized when dart:typed_data is loaded. | 148 /// Initialized when dart:typed_data is loaded. |
| 151 LibraryElement typedDataLibrary; | 149 LibraryElement typedDataLibrary; |
| 152 | 150 |
| 153 DiagnosticReporter get reporter => _reporter; | 151 DiagnosticReporter get reporter => _reporter; |
| 154 CoreClasses get coreClasses => _coreTypes; | 152 CoreClasses get coreClasses => _coreTypes; |
| 155 CoreTypes get coreTypes => _coreTypes; | 153 CoreTypes get coreTypes => _coreTypes; |
| 156 Resolution get resolution => _resolution; | 154 Resolution get resolution => _resolution; |
| 157 Parsing get parsing => _parsing; | 155 ParsingContext get parsingContext => _parsingContext; |
| 158 | 156 |
| 159 ClassElement typedDataClass; | 157 ClassElement typedDataClass; |
| 160 | 158 |
| 161 /// The constant for the [proxy] variable defined in dart:core. | 159 /// The constant for the [proxy] variable defined in dart:core. |
| 162 ConstantValue proxyConstant; | 160 ConstantValue proxyConstant; |
| 163 | 161 |
| 164 // TODO(johnniwinther): Move this to the JavaScriptBackend. | 162 // TODO(johnniwinther): Move this to the JavaScriptBackend. |
| 165 /// The class for patch annotation defined in dart:_js_helper. | 163 /// The class for patch annotation defined in dart:_js_helper. |
| 166 ClassElement patchAnnotationClass; | 164 ClassElement patchAnnotationClass; |
| 167 | 165 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 this.environment: const _EmptyEnvironment()}) | 284 this.environment: const _EmptyEnvironment()}) |
| 287 : this.options = options, | 285 : this.options = options, |
| 288 this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport), | 286 this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport), |
| 289 this.userOutputProvider = outputProvider == null | 287 this.userOutputProvider = outputProvider == null |
| 290 ? const NullCompilerOutput() | 288 ? const NullCompilerOutput() |
| 291 : outputProvider { | 289 : outputProvider { |
| 292 world = new World(this); | 290 world = new World(this); |
| 293 // TODO(johnniwinther): Initialize core types in [initializeCoreClasses] and | 291 // TODO(johnniwinther): Initialize core types in [initializeCoreClasses] and |
| 294 // make its field final. | 292 // make its field final. |
| 295 _reporter = new _CompilerDiagnosticReporter(this, options); | 293 _reporter = new _CompilerDiagnosticReporter(this, options); |
| 296 _parsing = new _CompilerParsing(this); | |
| 297 _resolution = new _CompilerResolution(this); | 294 _resolution = new _CompilerResolution(this); |
| 298 _coreTypes = new _CompilerCoreTypes(_resolution); | 295 _coreTypes = new _CompilerCoreTypes(_resolution); |
| 299 types = new Types(_resolution); | 296 types = new Types(_resolution); |
| 300 tracer = new Tracer(this, this.outputProvider); | 297 tracer = new Tracer(this, this.outputProvider); |
| 301 | 298 |
| 302 if (options.verbose) { | 299 if (options.verbose) { |
| 303 progress = new Stopwatch()..start(); | 300 progress = new Stopwatch()..start(); |
| 304 } | 301 } |
| 305 | 302 |
| 306 // TODO(johnniwinther): Separate the dependency tracking from the enqueuing | 303 // TODO(johnniwinther): Separate the dependency tracking from the enqueuing |
| (...skipping 14 matching lines...) Expand all Loading... |
| 321 throw new ArgumentError('--dump-info is not supported for dart2dart.'); | 318 throw new ArgumentError('--dump-info is not supported for dart2dart.'); |
| 322 } | 319 } |
| 323 } | 320 } |
| 324 | 321 |
| 325 if (options.dumpInfo && options.useStartupEmitter) { | 322 if (options.dumpInfo && options.useStartupEmitter) { |
| 326 throw new ArgumentError( | 323 throw new ArgumentError( |
| 327 '--dump-info is not supported with the fast startup emitter'); | 324 '--dump-info is not supported with the fast startup emitter'); |
| 328 } | 325 } |
| 329 | 326 |
| 330 tasks = [ | 327 tasks = [ |
| 331 dietParser = new DietParserTask( | 328 dietParser = |
| 332 this, parsing.parserOptions, idGenerator, backend, reporter), | 329 new DietParserTask(this, options, idGenerator, backend, reporter), |
| 333 scanner = createScannerTask(), | 330 scanner = createScannerTask(), |
| 334 serialization = new SerializationTask(this), | 331 serialization = new SerializationTask(this), |
| 335 libraryLoader = new LibraryLoaderTask( | 332 libraryLoader = new LibraryLoaderTask( |
| 336 this, | 333 this, |
| 337 this.resolvedUriTranslator, | 334 this.resolvedUriTranslator, |
| 338 new _ScriptLoader(this), | 335 new _ScriptLoader(this), |
| 339 new _ElementScanner(scanner), | 336 new _ElementScanner(scanner), |
| 340 this.serialization, | 337 this.serialization, |
| 341 this, | 338 this, |
| 342 environment), | 339 environment), |
| 343 parser = new ParserTask(this, parsing.parserOptions), | 340 parser = new ParserTask(this, options), |
| 344 patchParser = new PatchParserTask(this, parsing.parserOptions), | 341 patchParser = new PatchParserTask(this, options), |
| 345 resolver = createResolverTask(), | 342 resolver = createResolverTask(), |
| 346 closureToClassMapper = new closureMapping.ClosureTask(this), | 343 closureToClassMapper = new closureMapping.ClosureTask(this), |
| 347 checker = new TypeCheckerTask(this), | 344 checker = new TypeCheckerTask(this), |
| 348 typesTask = new ti.TypesTask(this), | 345 typesTask = new ti.TypesTask(this), |
| 349 constants = backend.constantCompilerTask, | 346 constants = backend.constantCompilerTask, |
| 350 deferredLoadTask = new DeferredLoadTask(this), | 347 deferredLoadTask = new DeferredLoadTask(this), |
| 351 mirrorUsageAnalyzerTask = new MirrorUsageAnalyzerTask(this), | 348 mirrorUsageAnalyzerTask = new MirrorUsageAnalyzerTask(this), |
| 352 enqueuer = new EnqueueTask(this), | 349 enqueuer = new EnqueueTask(this), |
| 353 dumpInfoTask = new DumpInfoTask(this), | 350 dumpInfoTask = new DumpInfoTask(this), |
| 354 reuseLibraryTask = new GenericTask('Reuse library', this), | 351 reuseLibraryTask = new GenericTask('Reuse library', this), |
| 355 ]; | 352 ]; |
| 356 | 353 |
| 354 _parsingContext = |
| 355 new ParsingContext(reporter, options, parser, patchParser, backend); |
| 356 |
| 357 tasks.addAll(backend.tasks); | 357 tasks.addAll(backend.tasks); |
| 358 } | 358 } |
| 359 | 359 |
| 360 /// Creates the scanner task. | 360 /// Creates the scanner task. |
| 361 /// | 361 /// |
| 362 /// Override this to mock the scanner for testing. | 362 /// Override this to mock the scanner for testing. |
| 363 ScannerTask createScannerTask() => new ScannerTask(this, dietParser, | 363 ScannerTask createScannerTask() => new ScannerTask(this, dietParser, |
| 364 preserveComments: options.preserveComments, commentMap: commentMap); | 364 preserveComments: options.preserveComments, commentMap: commentMap); |
| 365 | 365 |
| 366 /// Creates the resolver task. | 366 /// Creates the resolver task. |
| (...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1804 <Element, ResolutionImpact>{}; | 1804 <Element, ResolutionImpact>{}; |
| 1805 final Map<Element, WorldImpact> _worldImpactCache = <Element, WorldImpact>{}; | 1805 final Map<Element, WorldImpact> _worldImpactCache = <Element, WorldImpact>{}; |
| 1806 bool retainCachesForTesting = false; | 1806 bool retainCachesForTesting = false; |
| 1807 | 1807 |
| 1808 _CompilerResolution(this.compiler); | 1808 _CompilerResolution(this.compiler); |
| 1809 | 1809 |
| 1810 @override | 1810 @override |
| 1811 DiagnosticReporter get reporter => compiler.reporter; | 1811 DiagnosticReporter get reporter => compiler.reporter; |
| 1812 | 1812 |
| 1813 @override | 1813 @override |
| 1814 Parsing get parsing => compiler.parsing; | 1814 ParsingContext get parsingContext => compiler.parsingContext; |
| 1815 | 1815 |
| 1816 @override | 1816 @override |
| 1817 CoreTypes get coreTypes => compiler.coreTypes; | 1817 CoreTypes get coreTypes => compiler.coreTypes; |
| 1818 | 1818 |
| 1819 @override | 1819 @override |
| 1820 void registerClass(ClassElement cls) { | 1820 void registerClass(ClassElement cls) { |
| 1821 compiler.world.registerClass(cls); | 1821 compiler.world.registerClass(cls); |
| 1822 } | 1822 } |
| 1823 | 1823 |
| 1824 @override | 1824 @override |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1956 Element element, ItemCompilationContext compilationContext) { | 1956 Element element, ItemCompilationContext compilationContext) { |
| 1957 if (compiler.serialization.isDeserialized(element)) { | 1957 if (compiler.serialization.isDeserialized(element)) { |
| 1958 return compiler.serialization | 1958 return compiler.serialization |
| 1959 .createResolutionWorkItem(element, compilationContext); | 1959 .createResolutionWorkItem(element, compilationContext); |
| 1960 } else { | 1960 } else { |
| 1961 return new ResolutionWorkItem(element, compilationContext); | 1961 return new ResolutionWorkItem(element, compilationContext); |
| 1962 } | 1962 } |
| 1963 } | 1963 } |
| 1964 } | 1964 } |
| 1965 | 1965 |
| 1966 // TODO(johnniwinther): Move [ParserTask], [PatchParserTask], [DietParserTask] | |
| 1967 // and [ScannerTask] here. | |
| 1968 class _CompilerParsing implements Parsing { | |
| 1969 final Compiler compiler; | |
| 1970 | |
| 1971 _CompilerParsing(this.compiler); | |
| 1972 | |
| 1973 @override | |
| 1974 DiagnosticReporter get reporter => compiler.reporter; | |
| 1975 | |
| 1976 @override | |
| 1977 measure(f()) => compiler.parser.measure(f); | |
| 1978 | |
| 1979 @override | |
| 1980 void parsePatchClass(ClassElement cls) { | |
| 1981 compiler.patchParser.measure(() { | |
| 1982 if (cls.isPatch) { | |
| 1983 compiler.patchParser.parsePatchClassNode(cls); | |
| 1984 } | |
| 1985 }); | |
| 1986 } | |
| 1987 | |
| 1988 ScannerOptions getScannerOptionsFor(Element element) => new ScannerOptions( | |
| 1989 canUseNative: compiler.backend.canLibraryUseNative(element.library)); | |
| 1990 | |
| 1991 ParserOptions get parserOptions => compiler.options; | |
| 1992 } | |
| 1993 | |
| 1994 class GlobalDependencyRegistry extends EagerRegistry { | 1966 class GlobalDependencyRegistry extends EagerRegistry { |
| 1995 final Compiler compiler; | 1967 final Compiler compiler; |
| 1996 Setlet<Element> _otherDependencies; | 1968 Setlet<Element> _otherDependencies; |
| 1997 | 1969 |
| 1998 GlobalDependencyRegistry(this.compiler) : super('GlobalDependencies', null); | 1970 GlobalDependencyRegistry(this.compiler) : super('GlobalDependencies', null); |
| 1999 | 1971 |
| 2000 // TODO(johnniwinther): Rename world/universe/enqueuer through out the | 1972 // TODO(johnniwinther): Rename world/universe/enqueuer through out the |
| 2001 // compiler. | 1973 // compiler. |
| 2002 @override | 1974 @override |
| 2003 Enqueuer get world => compiler.enqueuer.codegen; | 1975 Enqueuer get world => compiler.enqueuer.codegen; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2028 _ElementScanner(this.scanner); | 2000 _ElementScanner(this.scanner); |
| 2029 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2001 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 2030 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2002 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 2031 } | 2003 } |
| 2032 | 2004 |
| 2033 class _EmptyEnvironment implements Environment { | 2005 class _EmptyEnvironment implements Environment { |
| 2034 const _EmptyEnvironment(); | 2006 const _EmptyEnvironment(); |
| 2035 | 2007 |
| 2036 String valueOf(String key) => null; | 2008 String valueOf(String key) => null; |
| 2037 } | 2009 } |
| OLD | NEW |