Chromium Code Reviews| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
| 9 * compiled. | 9 * compiled. |
| 10 */ | 10 */ |
| 11 const bool REPORT_EXCESS_RESOLUTION = false; | 11 const bool REPORT_EXCESS_RESOLUTION = false; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Contains backend-specific data that is used throughout the compilation of | 14 * Contains backend-specific data that is used throughout the compilation of |
| 15 * one work item. | 15 * one work item. |
| 16 */ | 16 */ |
| 17 class ItemCompilationContext { | 17 class ItemCompilationContext { |
| 18 } | 18 } |
| 19 | 19 |
| 20 abstract class WorkItem { | 20 abstract class WorkItem { |
| 21 final ItemCompilationContext compilationContext; | 21 final ItemCompilationContext compilationContext; |
| 22 /** | 22 /** |
| 23 * Documentation wanted -- johnniwinther | 23 * Documentation wanted -- johnniwinther |
| 24 * | 24 * |
| 25 * Invariant: [element] must be a declaration element. | 25 * Invariant: [element] must be a declaration element. |
| 26 */ | 26 */ |
| 27 final AstElement element; | 27 final AstElement element; |
| 28 | 28 |
| 29 TreeElements get resolutionTree; | |
| 30 | |
| 31 WorkItem(this.element, this.compilationContext) { | 29 WorkItem(this.element, this.compilationContext) { |
| 32 assert(invariant(element, element.isDeclaration)); | 30 assert(invariant(element, element.isDeclaration)); |
| 33 } | 31 } |
| 34 | 32 |
| 35 WorldImpact run(Compiler compiler, Enqueuer world); | 33 WorldImpact run(Compiler compiler, Enqueuer world); |
| 36 } | 34 } |
| 37 | 35 |
| 38 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. | 36 /// [WorkItem] used exclusively by the [ResolutionEnqueuer]. |
| 39 class ResolutionWorkItem extends WorkItem { | 37 class ResolutionWorkItem extends WorkItem { |
| 40 TreeElements resolutionTree; | 38 bool _isAnalyzed = false; |
| 41 | 39 |
| 42 ResolutionWorkItem(AstElement element, | 40 ResolutionWorkItem(AstElement element, |
| 43 ItemCompilationContext compilationContext) | 41 ItemCompilationContext compilationContext) |
| 44 : super(element, compilationContext); | 42 : super(element, compilationContext); |
| 45 | 43 |
| 46 WorldImpact run(Compiler compiler, ResolutionEnqueuer world) { | 44 WorldImpact run(Compiler compiler, ResolutionEnqueuer world) { |
| 47 WorldImpact impact = compiler.analyze(this, world); | 45 WorldImpact impact = compiler.analyze(this, world); |
| 48 resolutionTree = element.resolvedAst.elements; | 46 _isAnalyzed = true; |
| 49 return impact; | 47 return impact; |
| 50 } | 48 } |
| 51 | 49 |
| 52 bool isAnalyzed() => resolutionTree != null; | 50 bool get isAnalyzed => _isAnalyzed; |
| 53 } | 51 } |
| 54 | 52 |
| 55 // TODO(johnniwinther): Split this class into interface and implementation. | 53 // TODO(johnniwinther): Split this class into interface and implementation. |
| 56 // TODO(johnniwinther): Move this implementation to the JS backend. | 54 // TODO(johnniwinther): Move this implementation to the JS backend. |
| 57 class CodegenRegistry extends Registry { | 55 class CodegenRegistry extends Registry { |
| 58 final Compiler compiler; | 56 final Compiler compiler; |
| 59 final TreeElements treeElements; | 57 final TreeElements treeElements; |
| 60 | 58 |
| 61 CodegenRegistry(this.compiler, this.treeElements); | 59 CodegenRegistry(this.compiler, this.treeElements); |
| 62 | 60 |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 937 _currentElement = old; | 935 _currentElement = old; |
| 938 } | 936 } |
| 939 } | 937 } |
| 940 | 938 |
| 941 List<CompilerTask> tasks; | 939 List<CompilerTask> tasks; |
| 942 ScannerTask scanner; | 940 ScannerTask scanner; |
| 943 DietParserTask dietParser; | 941 DietParserTask dietParser; |
| 944 ParserTask parser; | 942 ParserTask parser; |
| 945 PatchParserTask patchParser; | 943 PatchParserTask patchParser; |
| 946 LibraryLoaderTask libraryLoader; | 944 LibraryLoaderTask libraryLoader; |
| 945 SerializationTask serialization; | |
| 947 ResolverTask resolver; | 946 ResolverTask resolver; |
| 948 closureMapping.ClosureTask closureToClassMapper; | 947 closureMapping.ClosureTask closureToClassMapper; |
| 949 TypeCheckerTask checker; | 948 TypeCheckerTask checker; |
| 950 IrBuilderTask irBuilder; | 949 IrBuilderTask irBuilder; |
| 951 ti.TypesTask typesTask; | 950 ti.TypesTask typesTask; |
| 952 Backend backend; | 951 Backend backend; |
| 953 | 952 |
| 954 GenericTask reuseLibraryTask; | 953 GenericTask reuseLibraryTask; |
| 955 | 954 |
| 956 /// The constant environment for the frontend interpretation of compile-time | 955 /// The constant environment for the frontend interpretation of compile-time |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1108 } else { | 1107 } else { |
| 1109 backend = new dart_backend.DartBackend(this, strips, | 1108 backend = new dart_backend.DartBackend(this, strips, |
| 1110 multiFile: dart2dartMultiFile); | 1109 multiFile: dart2dartMultiFile); |
| 1111 if (dumpInfo) { | 1110 if (dumpInfo) { |
| 1112 throw new ArgumentError('--dump-info is not supported for dart2dart.'); | 1111 throw new ArgumentError('--dump-info is not supported for dart2dart.'); |
| 1113 } | 1112 } |
| 1114 } | 1113 } |
| 1115 | 1114 |
| 1116 tasks = [ | 1115 tasks = [ |
| 1117 libraryLoader = new LibraryLoaderTask(this), | 1116 libraryLoader = new LibraryLoaderTask(this), |
| 1117 serialization = new SerializationTask(this), | |
| 1118 scanner = new ScannerTask(this), | 1118 scanner = new ScannerTask(this), |
| 1119 dietParser = new DietParserTask(this), | 1119 dietParser = new DietParserTask(this), |
| 1120 parser = new ParserTask(this), | 1120 parser = new ParserTask(this), |
| 1121 patchParser = new PatchParserTask(this), | 1121 patchParser = new PatchParserTask(this), |
| 1122 resolver = new ResolverTask(this, backend.constantCompilerTask), | 1122 resolver = new ResolverTask(this, backend.constantCompilerTask), |
| 1123 closureToClassMapper = new closureMapping.ClosureTask(this), | 1123 closureToClassMapper = new closureMapping.ClosureTask(this), |
| 1124 checker = new TypeCheckerTask(this), | 1124 checker = new TypeCheckerTask(this), |
| 1125 irBuilder = new IrBuilderTask(this, sourceInformationFactory), | 1125 irBuilder = new IrBuilderTask(this, sourceInformationFactory), |
| 1126 typesTask = new ti.TypesTask(this), | 1126 typesTask = new ti.TypesTask(this), |
| 1127 constants = backend.constantCompilerTask, | 1127 constants = backend.constantCompilerTask, |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1735 } | 1735 } |
| 1736 if (verbose) { | 1736 if (verbose) { |
| 1737 progress.reset(); | 1737 progress.reset(); |
| 1738 } | 1738 } |
| 1739 world.forEach((WorkItem work) { | 1739 world.forEach((WorkItem work) { |
| 1740 withCurrentElement(work.element, () { | 1740 withCurrentElement(work.element, () { |
| 1741 world.applyImpact(work.element, work.run(this, world)); | 1741 world.applyImpact(work.element, work.run(this, world)); |
| 1742 }); | 1742 }); |
| 1743 }); | 1743 }); |
| 1744 world.queueIsClosed = true; | 1744 world.queueIsClosed = true; |
| 1745 //print('------------ $world is closed --------------'); | |
|
floitsch
2015/06/26 20:54:03
remove.
Johnni Winther
2015/07/03 12:13:44
Done.
| |
| 1745 assert(compilationFailed || world.checkNoEnqueuedInvokedInstanceMethods()); | 1746 assert(compilationFailed || world.checkNoEnqueuedInvokedInstanceMethods()); |
| 1746 } | 1747 } |
| 1747 | 1748 |
| 1748 /** | 1749 /** |
| 1749 * Perform various checks of the queues. This includes checking that | 1750 * Perform various checks of the queues. This includes checking that |
| 1750 * the queues are empty (nothing was added after we stopped | 1751 * the queues are empty (nothing was added after we stopped |
| 1751 * processing the queues). Also compute the number of methods that | 1752 * processing the queues). Also compute the number of methods that |
| 1752 * were resolved, but not compiled (aka excess resolution). | 1753 * were resolved, but not compiled (aka excess resolution). |
| 1753 */ | 1754 */ |
| 1754 checkQueues() { | 1755 checkQueues() { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1808 if (tree != null && !analyzeSignaturesOnly && !suppressWarnings) { | 1809 if (tree != null && !analyzeSignaturesOnly && !suppressWarnings) { |
| 1809 // Only analyze nodes with a corresponding [TreeElements]. | 1810 // Only analyze nodes with a corresponding [TreeElements]. |
| 1810 checker.check(element); | 1811 checker.check(element); |
| 1811 } | 1812 } |
| 1812 world.registerResolvedElement(element); | 1813 world.registerResolvedElement(element); |
| 1813 return worldImpact; | 1814 return worldImpact; |
| 1814 } | 1815 } |
| 1815 | 1816 |
| 1816 WorldImpact analyze(ResolutionWorkItem work, ResolutionEnqueuer world) { | 1817 WorldImpact analyze(ResolutionWorkItem work, ResolutionEnqueuer world) { |
| 1817 assert(invariant(work.element, identical(world, enqueuer.resolution))); | 1818 assert(invariant(work.element, identical(world, enqueuer.resolution))); |
| 1818 assert(invariant(work.element, !work.isAnalyzed(), | 1819 assert(invariant(work.element, !work.isAnalyzed, |
| 1819 message: 'Element ${work.element} has already been analyzed')); | 1820 message: 'Element ${work.element} has already been analyzed')); |
| 1820 if (shouldPrintProgress) { | 1821 if (shouldPrintProgress) { |
| 1821 // TODO(ahe): Add structured diagnostics to the compiler API and | 1822 // TODO(ahe): Add structured diagnostics to the compiler API and |
| 1822 // use it to separate this from the --verbose option. | 1823 // use it to separate this from the --verbose option. |
| 1823 if (phase == PHASE_RESOLVING) { | 1824 if (phase == PHASE_RESOLVING) { |
| 1824 log('Resolved ${enqueuer.resolution.resolvedElements.length} ' | 1825 log('Resolved ${enqueuer.resolution.resolvedElements.length} ' |
| 1825 'elements.'); | 1826 'elements.'); |
| 1826 progress.reset(); | 1827 progress.reset(); |
| 1827 } | 1828 } |
| 1828 } | 1829 } |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2232 f(int beginOffset, int endOffset)) { | 2233 f(int beginOffset, int endOffset)) { |
| 2233 final beginOffset = begin.charOffset; | 2234 final beginOffset = begin.charOffset; |
| 2234 final endOffset = end.charOffset + end.charCount; | 2235 final endOffset = end.charOffset + end.charCount; |
| 2235 | 2236 |
| 2236 // [begin] and [end] might be the same for the same empty token. This | 2237 // [begin] and [end] might be the same for the same empty token. This |
| 2237 // happens for instance when scanning '$$'. | 2238 // happens for instance when scanning '$$'. |
| 2238 assert(endOffset >= beginOffset); | 2239 assert(endOffset >= beginOffset); |
| 2239 return f(beginOffset, endOffset); | 2240 return f(beginOffset, endOffset); |
| 2240 } | 2241 } |
| 2241 | 2242 |
| 2243 int get hashCode { | |
| 2244 return 13 * uri.hashCode + | |
| 2245 17 * begin.hashCode + | |
| 2246 19 * end.hashCode; | |
| 2247 } | |
| 2248 | |
| 2249 bool operator ==(other) { | |
| 2250 if (identical(this, other)) return true; | |
| 2251 if (other is! SourceSpan) return false; | |
| 2252 return uri == other.uri && | |
| 2253 begin == other.begin && | |
| 2254 end == other.end; | |
| 2255 } | |
| 2256 | |
| 2242 String toString() => 'SourceSpan($uri, $begin, $end)'; | 2257 String toString() => 'SourceSpan($uri, $begin, $end)'; |
| 2243 } | 2258 } |
| 2244 | 2259 |
| 2245 /// Flag that can be used in assertions to assert that a code path is only | 2260 /// Flag that can be used in assertions to assert that a code path is only |
| 2246 /// executed as part of development. | 2261 /// executed as part of development. |
| 2247 /// | 2262 /// |
| 2248 /// This flag is automatically set to true if helper methods like, [debugPrint], | 2263 /// This flag is automatically set to true if helper methods like, [debugPrint], |
| 2249 /// [debugWrapPrint], [trace], and [reportHere] are called. | 2264 /// [debugWrapPrint], [trace], and [reportHere] are called. |
| 2250 bool DEBUG_MODE = false; | 2265 bool DEBUG_MODE = false; |
| 2251 | 2266 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2406 const AnyLocation(); | 2421 const AnyLocation(); |
| 2407 | 2422 |
| 2408 bool inSameLocation(Uri uri) => true; | 2423 bool inSameLocation(Uri uri) => true; |
| 2409 | 2424 |
| 2410 String relativize(Uri baseUri) => '$baseUri'; | 2425 String relativize(Uri baseUri) => '$baseUri'; |
| 2411 } | 2426 } |
| 2412 | 2427 |
| 2413 class _CompilerCoreTypes implements CoreTypes { | 2428 class _CompilerCoreTypes implements CoreTypes { |
| 2414 final Compiler compiler; | 2429 final Compiler compiler; |
| 2415 | 2430 |
| 2416 ClassElementX objectClass; | 2431 ClassElement objectClass; |
| 2417 ClassElementX boolClass; | 2432 ClassElement boolClass; |
| 2418 ClassElementX numClass; | 2433 ClassElement numClass; |
| 2419 ClassElementX intClass; | 2434 ClassElement intClass; |
| 2420 ClassElementX doubleClass; | 2435 ClassElement doubleClass; |
| 2421 ClassElementX stringClass; | 2436 ClassElement stringClass; |
| 2422 ClassElementX functionClass; | 2437 ClassElement functionClass; |
| 2423 ClassElementX nullClass; | 2438 ClassElement nullClass; |
| 2424 ClassElementX listClass; | 2439 ClassElement listClass; |
| 2425 ClassElementX typeClass; | 2440 ClassElement typeClass; |
| 2426 ClassElementX mapClass; | 2441 ClassElement mapClass; |
| 2427 ClassElementX symbolClass; | 2442 ClassElement symbolClass; |
| 2428 ClassElementX stackTraceClass; | 2443 ClassElement stackTraceClass; |
| 2429 ClassElementX futureClass; | 2444 ClassElement futureClass; |
| 2430 ClassElementX iterableClass; | 2445 ClassElement iterableClass; |
| 2431 ClassElementX streamClass; | 2446 ClassElement streamClass; |
| 2432 | 2447 |
| 2433 _CompilerCoreTypes(this.compiler); | 2448 _CompilerCoreTypes(this.compiler); |
| 2434 | 2449 |
| 2435 @override | 2450 @override |
| 2436 InterfaceType get objectType => objectClass.computeType(compiler); | 2451 InterfaceType get objectType => objectClass.computeType(compiler); |
| 2437 | 2452 |
| 2438 @override | 2453 @override |
| 2439 InterfaceType get boolType => boolClass.computeType(compiler); | 2454 InterfaceType get boolType => boolClass.computeType(compiler); |
| 2440 | 2455 |
| 2441 @override | 2456 @override |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2507 InterfaceType streamType([DartType elementType]) { | 2522 InterfaceType streamType([DartType elementType]) { |
| 2508 InterfaceType type = streamClass.computeType(compiler); | 2523 InterfaceType type = streamClass.computeType(compiler); |
| 2509 if (elementType == null) { | 2524 if (elementType == null) { |
| 2510 return streamClass.rawType; | 2525 return streamClass.rawType; |
| 2511 } | 2526 } |
| 2512 return type.createInstantiation([elementType]); | 2527 return type.createInstantiation([elementType]); |
| 2513 } | 2528 } |
| 2514 } | 2529 } |
| 2515 | 2530 |
| 2516 typedef void InternalErrorFunction(Spannable location, String message); | 2531 typedef void InternalErrorFunction(Spannable location, String message); |
| OLD | NEW |