| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 serialization = new SerializationTask(this), | 358 serialization = new SerializationTask(this), |
| 359 libraryLoader = new LibraryLoaderTask( | 359 libraryLoader = new LibraryLoaderTask( |
| 360 this, | 360 this, |
| 361 new _ResolvedUriTranslator(this), | 361 new _ResolvedUriTranslator(this), |
| 362 new _ScriptLoader(this), | 362 new _ScriptLoader(this), |
| 363 new _ElementScanner(scanner), | 363 new _ElementScanner(scanner), |
| 364 this.serialization, | 364 this.serialization, |
| 365 this, | 365 this, |
| 366 environment), | 366 environment), |
| 367 parser = new ParserTask(this, parsing.parserOptions), | 367 parser = new ParserTask(this, parsing.parserOptions), |
| 368 patchParser = new PatchParserTask(this, parsing.parserOptions), | 368 patchParser = createPatchParserTask(), |
| 369 resolver = createResolverTask(), | 369 resolver = createResolverTask(), |
| 370 closureToClassMapper = new closureMapping.ClosureTask(this), | 370 closureToClassMapper = new closureMapping.ClosureTask(this), |
| 371 checker = new TypeCheckerTask(this), | 371 checker = new TypeCheckerTask(this), |
| 372 typesTask = new ti.TypesTask(this), | 372 typesTask = new ti.TypesTask(this), |
| 373 constants = backend.constantCompilerTask, | 373 constants = backend.constantCompilerTask, |
| 374 deferredLoadTask = new DeferredLoadTask(this), | 374 deferredLoadTask = new DeferredLoadTask(this), |
| 375 mirrorUsageAnalyzerTask = new MirrorUsageAnalyzerTask(this), | 375 mirrorUsageAnalyzerTask = createMirrorUsageAnalyzerTask(), |
| 376 enqueuer = backend.makeEnqueuer(), | 376 enqueuer = backend.makeEnqueuer(), |
| 377 dumpInfoTask = new DumpInfoTask(this), | 377 dumpInfoTask = new DumpInfoTask(this), |
| 378 reuseLibraryTask = new GenericTask('Reuse library', this), | 378 reuseLibraryTask = new GenericTask('Reuse library', this), |
| 379 selfTask = new GenericTask('self', this), | 379 selfTask = new GenericTask('self', this), |
| 380 ]; | 380 ]; |
| 381 | 381 |
| 382 tasks.addAll(backend.tasks); | 382 tasks.addAll(backend.tasks); |
| 383 } | 383 } |
| 384 | 384 |
| 385 /// Creates the scanner task. | 385 /// Creates the scanner task. |
| 386 /// | 386 /// |
| 387 /// Override this to mock the scanner for testing. | 387 /// Override this to mock the scanner for testing. |
| 388 ScannerTask createScannerTask() => new ScannerTask(this, dietParser, | 388 ScannerTask createScannerTask() => new ScannerTask(this, dietParser, |
| 389 preserveComments: options.preserveComments, commentMap: commentMap); | 389 preserveComments: options.preserveComments, commentMap: commentMap); |
| 390 | 390 |
| 391 /// Creates the resolver task. | 391 /// Creates the resolver task. |
| 392 /// | 392 /// |
| 393 /// Override this to mock the resolver for testing. | 393 /// Override this to mock the resolver for testing. |
| 394 ResolverTask createResolverTask() { | 394 ResolverTask createResolverTask() { |
| 395 return new ResolverTask(this, backend.constantCompilerTask); | 395 return new ResolverTask(this, backend.constantCompilerTask); |
| 396 } | 396 } |
| 397 | 397 |
| 398 PatchParserTask createPatchParserTask() { |
| 399 return new PatchParserTask(this, parsing.parserOptions); |
| 400 } |
| 401 |
| 402 MirrorUsageAnalyzerTask createMirrorUsageAnalyzerTask() { |
| 403 return new MirrorUsageAnalyzerTask(this); |
| 404 } |
| 405 |
| 398 Universe get resolverWorld => enqueuer.resolution.universe; | 406 Universe get resolverWorld => enqueuer.resolution.universe; |
| 399 Universe get codegenWorld => enqueuer.codegen.universe; | 407 Universe get codegenWorld => enqueuer.codegen.universe; |
| 400 | 408 |
| 401 bool get analyzeAll => options.analyzeAll || compileAll; | 409 bool get analyzeAll => options.analyzeAll || compileAll; |
| 402 | 410 |
| 403 bool get compileAll => false; | 411 bool get compileAll => false; |
| 404 | 412 |
| 405 bool get disableTypeInference => | 413 bool get disableTypeInference => |
| 406 options.disableTypeInference || compilationFailed; | 414 options.disableTypeInference || compilationFailed; |
| 407 | 415 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 /// been scanned. | 460 /// been scanned. |
| 453 /// | 461 /// |
| 454 /// Use this callback method to store references to specific member declared | 462 /// Use this callback method to store references to specific member declared |
| 455 /// in certain libraries. Note that [library] has not been patched yet, nor | 463 /// in certain libraries. Note that [library] has not been patched yet, nor |
| 456 /// has its imports/exports been resolved. | 464 /// has its imports/exports been resolved. |
| 457 /// | 465 /// |
| 458 /// Use [loader] to register the creation and scanning of a patch library | 466 /// Use [loader] to register the creation and scanning of a patch library |
| 459 /// for [library]. | 467 /// for [library]. |
| 460 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { | 468 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { |
| 461 Uri uri = library.canonicalUri; | 469 Uri uri = library.canonicalUri; |
| 462 if (uri == Uris.dart_core) { | 470 if (library.compilationUnit.script.isSynthesized) { |
| 471 // Ignore. |
| 472 } else if (uri == Uris.dart_core) { |
| 463 initializeCoreClasses(); | 473 initializeCoreClasses(); |
| 464 identicalFunction = coreLibrary.find('identical'); | 474 identicalFunction = coreLibrary.find('identical'); |
| 465 } else if (uri == Uris.dart__internal) { | 475 } else if (uri == Uris.dart__internal) { |
| 466 symbolImplementationClass = findRequiredElement(library, 'Symbol'); | 476 symbolImplementationClass = findRequiredElement(library, 'Symbol'); |
| 467 } else if (uri == Uris.dart_mirrors) { | 477 } else if (uri == Uris.dart_mirrors) { |
| 468 mirrorSystemClass = findRequiredElement(library, 'MirrorSystem'); | 478 mirrorSystemClass = findRequiredElement(library, 'MirrorSystem'); |
| 469 mirrorsUsedClass = findRequiredElement(library, 'MirrorsUsed'); | 479 mirrorsUsedClass = findRequiredElement(library, 'MirrorsUsed'); |
| 470 } else if (uri == Uris.dart_async) { | 480 } else if (uri == Uris.dart_async) { |
| 471 asyncLibrary = library; | 481 asyncLibrary = library; |
| 472 deferredLibraryClass = findRequiredElement(library, 'DeferredLibrary'); | 482 deferredLibraryClass = findRequiredElement(library, 'DeferredLibrary'); |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 } | 1054 } |
| 1045 } | 1055 } |
| 1046 reporter.log('Excess resolution work: ${resolved.length}.'); | 1056 reporter.log('Excess resolution work: ${resolved.length}.'); |
| 1047 for (Element e in resolved) { | 1057 for (Element e in resolved) { |
| 1048 reporter.reportWarningMessage(e, MessageKind.GENERIC, | 1058 reporter.reportWarningMessage(e, MessageKind.GENERIC, |
| 1049 {'text': 'Warning: $e resolved but not compiled.'}); | 1059 {'text': 'Warning: $e resolved but not compiled.'}); |
| 1050 } | 1060 } |
| 1051 } | 1061 } |
| 1052 | 1062 |
| 1053 WorldImpact analyzeElement(Element element) | 1063 WorldImpact analyzeElement(Element element) |
| 1054 => selfTask.measureSubtask("Compiler.analyzeElement", () { | 1064 => selfTask.measureSubtaskElement("Compiler.analyzeElement", element, () { |
| 1055 assert(invariant( | 1065 assert(invariant( |
| 1056 element, | 1066 element, |
| 1057 element.impliesType || | 1067 element.impliesType || |
| 1058 element.isField || | 1068 element.isField || |
| 1059 element.isFunction || | 1069 element.isFunction || |
| 1060 element.isConstructor || | 1070 element.isConstructor || |
| 1061 element.isGetter || | 1071 element.isGetter || |
| 1062 element.isSetter, | 1072 element.isSetter, |
| 1063 message: 'Unexpected element kind: ${element.kind}')); | 1073 message: 'Unexpected element kind: ${element.kind}')); |
| 1064 assert(invariant(element, element is AnalyzableElement, | 1074 assert(invariant(element, element is AnalyzableElement, |
| 1065 message: 'Element $element is not analyzable.')); | 1075 message: 'Element $element is not analyzable.')); |
| 1066 assert(invariant(element, element.isDeclaration)); | 1076 assert(invariant(element, element.isDeclaration)); |
| 1067 return resolution.computeWorldImpact(element); | 1077 return resolution.computeWorldImpact(element); |
| 1068 }); | 1078 }); |
| 1069 | 1079 |
| 1070 WorldImpact analyze(ResolutionWorkItem work, | 1080 WorldImpact analyze(ResolutionWorkItem work, |
| 1071 ResolutionEnqueuer world) | 1081 ResolutionEnqueuer world) |
| 1072 => selfTask.measureSubtask("Compiler.analyze", () { | 1082 => selfTask.measureSubtaskElement("Compiler.analyze", work.element, () { |
| 1073 assert(invariant(work.element, identical(world, enqueuer.resolution))); | 1083 assert(invariant(work.element, identical(world, enqueuer.resolution))); |
| 1074 assert(invariant(work.element, !work.isAnalyzed, | 1084 assert(invariant(work.element, !work.isAnalyzed, |
| 1075 message: 'Element ${work.element} has already been analyzed')); | 1085 message: 'Element ${work.element} has already been analyzed')); |
| 1076 if (shouldPrintProgress) { | 1086 if (shouldPrintProgress) { |
| 1077 // TODO(ahe): Add structured diagnostics to the compiler API and | 1087 // TODO(ahe): Add structured diagnostics to the compiler API and |
| 1078 // use it to separate this from the --verbose option. | 1088 // use it to separate this from the --verbose option. |
| 1079 if (phase == PHASE_RESOLVING) { | 1089 if (phase == PHASE_RESOLVING) { |
| 1080 reporter.log('Resolved ${enqueuer.resolution.processedElements.length} ' | 1090 reporter.log('Resolved ${enqueuer.resolution.processedElements.length} ' |
| 1081 'elements.'); | 1091 'elements.'); |
| 1082 progress.reset(); | 1092 progress.reset(); |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 currentElement.enclosingClass.isEnumClass) { | 1700 currentElement.enclosingClass.isEnumClass) { |
| 1691 // Enums ASTs are synthesized (and give messed up messages). | 1701 // Enums ASTs are synthesized (and give messed up messages). |
| 1692 return true; | 1702 return true; |
| 1693 } | 1703 } |
| 1694 | 1704 |
| 1695 if (currentElement is AstElement) { | 1705 if (currentElement is AstElement) { |
| 1696 AstElement astElement = currentElement; | 1706 AstElement astElement = currentElement; |
| 1697 if (astElement.hasNode) { | 1707 if (astElement.hasNode) { |
| 1698 Token from = astElement.node.getBeginToken(); | 1708 Token from = astElement.node.getBeginToken(); |
| 1699 Token to = astElement.node.getEndToken(); | 1709 Token to = astElement.node.getEndToken(); |
| 1700 if (astElement.metadata.isNotEmpty) { | 1710 for (MetadataAnnotation annotation in astElement.metadata) { |
| 1701 from = astElement.metadata.first.beginToken; | 1711 // For patched elements, metadata contains annotations from both |
| 1712 // origin and patch. Search for the first annotation from this |
| 1713 // element. For example, if origin class is @Deprecated. |
| 1714 if (annotation.annotatedElement == currentElement) { |
| 1715 from = annotation.beginToken; |
| 1716 break; |
| 1717 } |
| 1702 } | 1718 } |
| 1703 return validateToken(from, to); | 1719 return validateToken(from, to); |
| 1704 } | 1720 } |
| 1705 } | 1721 } |
| 1706 return true; | 1722 return true; |
| 1707 }, message: "Invalid current element: $currentElement [$begin,$end].")); | 1723 }, message: "Invalid current element: $currentElement [$begin,$end].")); |
| 1708 } | 1724 } |
| 1709 return new SourceSpan.fromTokens(uri, begin, end); | 1725 return new SourceSpan.fromTokens(uri, begin, end); |
| 1710 } | 1726 } |
| 1711 | 1727 |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2127 _ElementScanner(this.scanner); | 2143 _ElementScanner(this.scanner); |
| 2128 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 2144 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 2129 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 2145 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 2130 } | 2146 } |
| 2131 | 2147 |
| 2132 class _EmptyEnvironment implements Environment { | 2148 class _EmptyEnvironment implements Environment { |
| 2133 const _EmptyEnvironment(); | 2149 const _EmptyEnvironment(); |
| 2134 | 2150 |
| 2135 String valueOf(String key) => null; | 2151 String valueOf(String key) => null; |
| 2136 } | 2152 } |
| OLD | NEW |