| 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 Registry; |
| 17 import 'common/resolution.dart' | 17 import 'common/resolution.dart' |
| 18 show | 18 show |
| 19 ParsingContext, | 19 ParsingContext, |
| 20 Resolution, | 20 Resolution, |
| 21 ResolutionWorkItem, | 21 ResolutionWorkItem, |
| 22 ResolutionImpact, | 22 ResolutionImpact, |
| 23 Target; | 23 Target; |
| 24 import 'common/tasks.dart' show CompilerTask, GenericTask, Measurer; | 24 import 'common/tasks.dart' show CompilerTask, GenericTask, Measurer; |
| 25 import 'common/work.dart' show WorkItem; | 25 import 'common/work.dart' show WorkItem; |
| 26 import 'common.dart'; | 26 import 'common.dart'; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 _coreTypes = new _CompilerCoreTypes(_resolution, reporter); | 237 _coreTypes = new _CompilerCoreTypes(_resolution, reporter); |
| 238 types = new Types(_resolution); | 238 types = new Types(_resolution); |
| 239 tracer = new Tracer(this, this.outputProvider); | 239 tracer = new Tracer(this, this.outputProvider); |
| 240 | 240 |
| 241 if (options.verbose) { | 241 if (options.verbose) { |
| 242 progress = new Stopwatch()..start(); | 242 progress = new Stopwatch()..start(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 // TODO(johnniwinther): Separate the dependency tracking from the enqueuing | 245 // TODO(johnniwinther): Separate the dependency tracking from the enqueuing |
| 246 // for global dependencies. | 246 // for global dependencies. |
| 247 globalDependencies = new GlobalDependencyRegistry(this); | 247 globalDependencies = new GlobalDependencyRegistry(); |
| 248 | 248 |
| 249 if (makeBackend != null) { | 249 if (makeBackend != null) { |
| 250 backend = makeBackend(this); | 250 backend = makeBackend(this); |
| 251 } else { | 251 } else { |
| 252 js_backend.JavaScriptBackend jsBackend = new js_backend.JavaScriptBackend( | 252 js_backend.JavaScriptBackend jsBackend = new js_backend.JavaScriptBackend( |
| 253 this, | 253 this, |
| 254 generateSourceMap: options.generateSourceMap, | 254 generateSourceMap: options.generateSourceMap, |
| 255 useStartupEmitter: options.useStartupEmitter, | 255 useStartupEmitter: options.useStartupEmitter, |
| 256 useNewSourceInfo: options.useNewSourceInfo, | 256 useNewSourceInfo: options.useNewSourceInfo, |
| 257 useKernel: options.useKernel); | 257 useKernel: options.useKernel); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 303 } |
| 304 | 304 |
| 305 /// The world currently being computed by resolution. This forms a basis for | 305 /// The world currently being computed by resolution. This forms a basis for |
| 306 /// the [inferenceWorld] and later the [closedWorld]. | 306 /// the [inferenceWorld] and later the [closedWorld]. |
| 307 OpenWorld get openWorld => _world; | 307 OpenWorld get openWorld => _world; |
| 308 | 308 |
| 309 /// The closed world after resolution but currently refined by inference. | 309 /// The closed world after resolution but currently refined by inference. |
| 310 ClosedWorldRefiner get inferenceWorld => _world; | 310 ClosedWorldRefiner get inferenceWorld => _world; |
| 311 | 311 |
| 312 /// The closed world after resolution and inference. | 312 /// The closed world after resolution and inference. |
| 313 ClosedWorld get closedWorld => _world; | 313 ClosedWorld get closedWorld { |
| 314 assert(invariant(CURRENT_ELEMENT_SPANNABLE, _world.isClosed, |
| 315 message: "Closed world not computed yet.")); |
| 316 return _world; |
| 317 } |
| 314 | 318 |
| 315 /// Creates the scanner task. | 319 /// Creates the scanner task. |
| 316 /// | 320 /// |
| 317 /// Override this to mock the scanner for testing. | 321 /// Override this to mock the scanner for testing. |
| 318 ScannerTask createScannerTask() => | 322 ScannerTask createScannerTask() => |
| 319 new ScannerTask(dietParser, reporter, measurer, | 323 new ScannerTask(dietParser, reporter, measurer, |
| 320 preserveComments: options.preserveComments, commentMap: commentMap); | 324 preserveComments: options.preserveComments, commentMap: commentMap); |
| 321 | 325 |
| 322 /// Creates the resolver task. | 326 /// Creates the resolver task. |
| 323 /// | 327 /// |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 // compiler from analyzing all the code. | 718 // compiler from analyzing all the code. |
| 715 // TODO(johnniwinther): Reenable this when the reporting is more | 719 // TODO(johnniwinther): Reenable this when the reporting is more |
| 716 // precise. | 720 // precise. |
| 717 //reportUnusedCode(); | 721 //reportUnusedCode(); |
| 718 } | 722 } |
| 719 return; | 723 return; |
| 720 } | 724 } |
| 721 assert(mainFunction != null); | 725 assert(mainFunction != null); |
| 722 phase = PHASE_DONE_RESOLVING; | 726 phase = PHASE_DONE_RESOLVING; |
| 723 | 727 |
| 724 openWorld.populate(); | 728 openWorld.closeWorld(); |
| 725 // Compute whole-program-knowledge that the backend needs. (This might | 729 // Compute whole-program-knowledge that the backend needs. (This might |
| 726 // require the information computed in [world.populate].) | 730 // require the information computed in [world.populate].) |
| 727 backend.onResolutionComplete(); | 731 backend.onResolutionComplete(); |
| 728 | 732 |
| 729 deferredLoadTask.onResolutionComplete(mainFunction); | 733 deferredLoadTask.onResolutionComplete(mainFunction); |
| 730 | 734 |
| 731 reporter.log('Inferring types...'); | 735 reporter.log('Inferring types...'); |
| 732 globalInference.runGlobalTypeInference(mainFunction); | 736 globalInference.runGlobalTypeInference(mainFunction); |
| 733 | 737 |
| 734 if (stopAfterTypeInference) return; | 738 if (stopAfterTypeInference) return; |
| (...skipping 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2185 if (field == null) return false; | 2189 if (field == null) return false; |
| 2186 if (!hasBeenResolved(field)) return false; | 2190 if (!hasBeenResolved(field)) return false; |
| 2187 if (_proxyConstant == null) { | 2191 if (_proxyConstant == null) { |
| 2188 _proxyConstant = constants | 2192 _proxyConstant = constants |
| 2189 .getConstantValue(resolver.constantCompiler.compileConstant(field)); | 2193 .getConstantValue(resolver.constantCompiler.compileConstant(field)); |
| 2190 } | 2194 } |
| 2191 return _proxyConstant == value; | 2195 return _proxyConstant == value; |
| 2192 } | 2196 } |
| 2193 } | 2197 } |
| 2194 | 2198 |
| 2195 class GlobalDependencyRegistry extends EagerRegistry { | 2199 class GlobalDependencyRegistry extends Registry { |
| 2196 final Compiler compiler; | |
| 2197 Setlet<Element> _otherDependencies; | 2200 Setlet<Element> _otherDependencies; |
| 2198 | 2201 |
| 2199 GlobalDependencyRegistry(this.compiler) : super('GlobalDependencies', null); | 2202 GlobalDependencyRegistry(); |
| 2200 | |
| 2201 // TODO(johnniwinther): Rename world/universe/enqueuer through out the | |
| 2202 // compiler. | |
| 2203 @override | |
| 2204 Enqueuer get world => compiler.enqueuer.codegen; | |
| 2205 | 2203 |
| 2206 void registerDependency(Element element) { | 2204 void registerDependency(Element element) { |
| 2207 if (element == null) return; | 2205 if (element == null) return; |
| 2208 if (_otherDependencies == null) { | 2206 if (_otherDependencies == null) { |
| 2209 _otherDependencies = new Setlet<Element>(); | 2207 _otherDependencies = new Setlet<Element>(); |
| 2210 } | 2208 } |
| 2211 _otherDependencies.add(element.implementation); | 2209 _otherDependencies.add(element.implementation); |
| 2212 } | 2210 } |
| 2213 | 2211 |
| 2214 Iterable<Element> get otherDependencies { | 2212 Iterable<Element> get otherDependencies { |
| 2215 return _otherDependencies != null ? _otherDependencies : const <Element>[]; | 2213 return _otherDependencies != null ? _otherDependencies : const <Element>[]; |
| 2216 } | 2214 } |
| 2215 |
| 2216 String get name => 'GlobalDependencies'; |
| 2217 } | 2217 } |
| 2218 | 2218 |
| 2219 class _ScriptLoader implements ScriptLoader { | 2219 class _ScriptLoader implements ScriptLoader { |
| 2220 Compiler compiler; | 2220 Compiler compiler; |
| 2221 _ScriptLoader(this.compiler); | 2221 _ScriptLoader(this.compiler); |
| 2222 | 2222 |
| 2223 Future<Script> readScript(Uri uri, [Spannable spannable]) => | 2223 Future<Script> readScript(Uri uri, [Spannable spannable]) => |
| 2224 compiler.readScript(uri, spannable); | 2224 compiler.readScript(uri, spannable); |
| 2225 } | 2225 } |
| 2226 | 2226 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2241 _ElementScanner(this.scanner); | 2241 _ElementScanner(this.scanner); |
| 2242 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2242 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 2243 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2243 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 2244 } | 2244 } |
| 2245 | 2245 |
| 2246 class _EmptyEnvironment implements Environment { | 2246 class _EmptyEnvironment implements Environment { |
| 2247 const _EmptyEnvironment(); | 2247 const _EmptyEnvironment(); |
| 2248 | 2248 |
| 2249 String valueOf(String key) => null; | 2249 String valueOf(String key) => null; |
| 2250 } | 2250 } |
| OLD | NEW |