| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 import 'tracer.dart' show Tracer; | 70 import 'tracer.dart' show Tracer; |
| 71 import 'tree/tree.dart' show Node, TypeAnnotation; | 71 import 'tree/tree.dart' show Node, TypeAnnotation; |
| 72 import 'typechecker.dart' show TypeCheckerTask; | 72 import 'typechecker.dart' show TypeCheckerTask; |
| 73 import 'types/types.dart' show GlobalTypeInferenceTask; | 73 import 'types/types.dart' show GlobalTypeInferenceTask; |
| 74 import 'types/masks.dart' show CommonMasks; | 74 import 'types/masks.dart' show CommonMasks; |
| 75 import 'universe/selector.dart' show Selector; | 75 import 'universe/selector.dart' show Selector; |
| 76 import 'universe/universe.dart' show Universe; | 76 import 'universe/universe.dart' show Universe; |
| 77 import 'universe/use.dart' show StaticUse; | 77 import 'universe/use.dart' show StaticUse; |
| 78 import 'universe/world_impact.dart' show ImpactStrategy, WorldImpact; | 78 import 'universe/world_impact.dart' show ImpactStrategy, WorldImpact; |
| 79 import 'util/util.dart' show Link, Setlet; | 79 import 'util/util.dart' show Link, Setlet; |
| 80 import 'world.dart' show World; | 80 import 'world.dart' show ClosedWorld, ClosedWorldRefiner, World; |
| 81 | 81 |
| 82 typedef Backend MakeBackendFuncion(Compiler compiler); | 82 typedef Backend MakeBackendFuncion(Compiler compiler); |
| 83 | 83 |
| 84 typedef CompilerDiagnosticReporter MakeReporterFunction( | 84 typedef CompilerDiagnosticReporter MakeReporterFunction( |
| 85 Compiler compiler, CompilerOptions options); | 85 Compiler compiler, CompilerOptions options); |
| 86 | 86 |
| 87 abstract class Compiler implements LibraryLoaderListener { | 87 abstract class Compiler implements LibraryLoaderListener { |
| 88 Measurer get measurer; | 88 Measurer get measurer; |
| 89 | 89 |
| 90 final IdGenerator idGenerator = new IdGenerator(); | 90 final IdGenerator idGenerator = new IdGenerator(); |
| 91 World world; | 91 World _world; |
| 92 Types types; | 92 Types types; |
| 93 _CompilerCoreTypes _coreTypes; | 93 _CompilerCoreTypes _coreTypes; |
| 94 CompilerDiagnosticReporter _reporter; | 94 CompilerDiagnosticReporter _reporter; |
| 95 _CompilerResolution _resolution; | 95 _CompilerResolution _resolution; |
| 96 ParsingContext _parsingContext; | 96 ParsingContext _parsingContext; |
| 97 | 97 |
| 98 final CacheStrategy cacheStrategy; | 98 final CacheStrategy cacheStrategy; |
| 99 | 99 |
| 100 ImpactStrategy impactStrategy = const ImpactStrategy(); | 100 ImpactStrategy impactStrategy = const ImpactStrategy(); |
| 101 | 101 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 {CompilerOptions options, | 218 {CompilerOptions options, |
| 219 api.CompilerOutput outputProvider, | 219 api.CompilerOutput outputProvider, |
| 220 this.environment: const _EmptyEnvironment(), | 220 this.environment: const _EmptyEnvironment(), |
| 221 MakeBackendFuncion makeBackend, | 221 MakeBackendFuncion makeBackend, |
| 222 MakeReporterFunction makeReporter}) | 222 MakeReporterFunction makeReporter}) |
| 223 : this.options = options, | 223 : this.options = options, |
| 224 this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport), | 224 this.cacheStrategy = new CacheStrategy(options.hasIncrementalSupport), |
| 225 this.userOutputProvider = outputProvider == null | 225 this.userOutputProvider = outputProvider == null |
| 226 ? const NullCompilerOutput() | 226 ? const NullCompilerOutput() |
| 227 : outputProvider { | 227 : outputProvider { |
| 228 world = new World(this); | 228 _world = new World(this); |
| 229 if (makeReporter != null) { | 229 if (makeReporter != null) { |
| 230 _reporter = makeReporter(this, options); | 230 _reporter = makeReporter(this, options); |
| 231 } else { | 231 } else { |
| 232 _reporter = new CompilerDiagnosticReporter(this, options); | 232 _reporter = new CompilerDiagnosticReporter(this, options); |
| 233 } | 233 } |
| 234 _resolution = new _CompilerResolution(this); | 234 _resolution = new _CompilerResolution(this); |
| 235 // TODO(johnniwinther): Initialize core types in [initializeCoreClasses] and | 235 // TODO(johnniwinther): Initialize core types in [initializeCoreClasses] and |
| 236 // make its field final. | 236 // make its field final. |
| 237 _coreTypes = new _CompilerCoreTypes(_resolution, reporter); | 237 _coreTypes = new _CompilerCoreTypes(_resolution, reporter); |
| 238 types = new Types(_resolution); | 238 types = new Types(_resolution); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 if (options.resolveOnly) { | 295 if (options.resolveOnly) { |
| 296 serialization.supportSerialization = true; | 296 serialization.supportSerialization = true; |
| 297 } | 297 } |
| 298 | 298 |
| 299 _parsingContext = | 299 _parsingContext = |
| 300 new ParsingContext(reporter, options, parser, patchParser, backend); | 300 new ParsingContext(reporter, options, parser, patchParser, backend); |
| 301 | 301 |
| 302 tasks.addAll(backend.tasks); | 302 tasks.addAll(backend.tasks); |
| 303 } | 303 } |
| 304 | 304 |
| 305 /// The world currently being computed by resolution. This forms a basis for |
| 306 /// the [inferenceWorld] and later the [closedWorld]. |
| 307 World get openWorld => _world; |
| 308 |
| 309 /// The closed world after resolution but currently refined by inference. |
| 310 ClosedWorldRefiner get inferenceWorld => _world; |
| 311 |
| 312 /// The closed world after resolution and inference. |
| 313 ClosedWorld get closedWorld => _world; |
| 314 |
| 305 /// Creates the scanner task. | 315 /// Creates the scanner task. |
| 306 /// | 316 /// |
| 307 /// Override this to mock the scanner for testing. | 317 /// Override this to mock the scanner for testing. |
| 308 ScannerTask createScannerTask() => | 318 ScannerTask createScannerTask() => |
| 309 new ScannerTask(dietParser, reporter, measurer, | 319 new ScannerTask(dietParser, reporter, measurer, |
| 310 preserveComments: options.preserveComments, commentMap: commentMap); | 320 preserveComments: options.preserveComments, commentMap: commentMap); |
| 311 | 321 |
| 312 /// Creates the resolver task. | 322 /// Creates the resolver task. |
| 313 /// | 323 /// |
| 314 /// Override this to mock the resolver for testing. | 324 /// Override this to mock the resolver for testing. |
| 315 ResolverTask createResolverTask() { | 325 ResolverTask createResolverTask() { |
| 316 return new ResolverTask( | 326 return new ResolverTask( |
| 317 resolution, backend.constantCompilerTask, world, measurer); | 327 resolution, backend.constantCompilerTask, openWorld, measurer); |
| 318 } | 328 } |
| 319 | 329 |
| 320 Universe get resolverWorld => enqueuer.resolution.universe; | 330 Universe get resolverWorld => enqueuer.resolution.universe; |
| 321 Universe get codegenWorld => enqueuer.codegen.universe; | 331 Universe get codegenWorld => enqueuer.codegen.universe; |
| 322 | 332 |
| 323 bool get analyzeAll => options.analyzeAll || compileAll; | 333 bool get analyzeAll => options.analyzeAll || compileAll; |
| 324 | 334 |
| 325 bool get compileAll => false; | 335 bool get compileAll => false; |
| 326 | 336 |
| 327 bool get disableTypeInference => | 337 bool get disableTypeInference => |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 // compiler from analyzing all the code. | 712 // compiler from analyzing all the code. |
| 703 // TODO(johnniwinther): Reenable this when the reporting is more | 713 // TODO(johnniwinther): Reenable this when the reporting is more |
| 704 // precise. | 714 // precise. |
| 705 //reportUnusedCode(); | 715 //reportUnusedCode(); |
| 706 } | 716 } |
| 707 return; | 717 return; |
| 708 } | 718 } |
| 709 assert(mainFunction != null); | 719 assert(mainFunction != null); |
| 710 phase = PHASE_DONE_RESOLVING; | 720 phase = PHASE_DONE_RESOLVING; |
| 711 | 721 |
| 712 world.populate(); | 722 openWorld.populate(); |
| 713 // Compute whole-program-knowledge that the backend needs. (This might | 723 // Compute whole-program-knowledge that the backend needs. (This might |
| 714 // require the information computed in [world.populate].) | 724 // require the information computed in [world.populate].) |
| 715 backend.onResolutionComplete(); | 725 backend.onResolutionComplete(); |
| 716 | 726 |
| 717 deferredLoadTask.onResolutionComplete(mainFunction); | 727 deferredLoadTask.onResolutionComplete(mainFunction); |
| 718 | 728 |
| 719 reporter.log('Inferring types...'); | 729 reporter.log('Inferring types...'); |
| 720 globalInference.runGlobalTypeInference(mainFunction); | 730 globalInference.runGlobalTypeInference(mainFunction); |
| 721 | 731 |
| 722 if (stopAfterTypeInference) return; | 732 if (stopAfterTypeInference) return; |
| (...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1975 compiler.mirrorUsageAnalyzerTask; | 1985 compiler.mirrorUsageAnalyzerTask; |
| 1976 | 1986 |
| 1977 @override | 1987 @override |
| 1978 LibraryElement get coreLibrary => compiler._coreTypes.coreLibrary; | 1988 LibraryElement get coreLibrary => compiler._coreTypes.coreLibrary; |
| 1979 | 1989 |
| 1980 @override | 1990 @override |
| 1981 bool get wasProxyConstantComputedTestingOnly => _proxyConstant != null; | 1991 bool get wasProxyConstantComputedTestingOnly => _proxyConstant != null; |
| 1982 | 1992 |
| 1983 @override | 1993 @override |
| 1984 void registerClass(ClassElement cls) { | 1994 void registerClass(ClassElement cls) { |
| 1985 compiler.world.registerClass(cls); | 1995 compiler.openWorld.registerClass(cls); |
| 1986 } | 1996 } |
| 1987 | 1997 |
| 1988 @override | 1998 @override |
| 1989 void resolveClass(ClassElement cls) { | 1999 void resolveClass(ClassElement cls) { |
| 1990 compiler.resolver.resolveClass(cls); | 2000 compiler.resolver.resolveClass(cls); |
| 1991 } | 2001 } |
| 1992 | 2002 |
| 1993 @override | 2003 @override |
| 1994 void resolveTypedef(TypedefElement typdef) { | 2004 void resolveTypedef(TypedefElement typdef) { |
| 1995 compiler.resolver.resolve(typdef); | 2005 compiler.resolver.resolve(typdef); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2229 _ElementScanner(this.scanner); | 2239 _ElementScanner(this.scanner); |
| 2230 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2240 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 2231 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2241 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 2232 } | 2242 } |
| 2233 | 2243 |
| 2234 class _EmptyEnvironment implements Environment { | 2244 class _EmptyEnvironment implements Environment { |
| 2235 const _EmptyEnvironment(); | 2245 const _EmptyEnvironment(); |
| 2236 | 2246 |
| 2237 String valueOf(String key) => null; | 2247 String valueOf(String key) => null; |
| 2238 } | 2248 } |
| OLD | NEW |