| 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 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 _currentElement = old; | 942 _currentElement = old; |
| 945 } | 943 } |
| 946 } | 944 } |
| 947 | 945 |
| 948 List<CompilerTask> tasks; | 946 List<CompilerTask> tasks; |
| 949 ScannerTask scanner; | 947 ScannerTask scanner; |
| 950 DietParserTask dietParser; | 948 DietParserTask dietParser; |
| 951 ParserTask parser; | 949 ParserTask parser; |
| 952 PatchParserTask patchParser; | 950 PatchParserTask patchParser; |
| 953 LibraryLoaderTask libraryLoader; | 951 LibraryLoaderTask libraryLoader; |
| 952 SerializationTask serialization; |
| 954 ResolverTask resolver; | 953 ResolverTask resolver; |
| 955 closureMapping.ClosureTask closureToClassMapper; | 954 closureMapping.ClosureTask closureToClassMapper; |
| 956 TypeCheckerTask checker; | 955 TypeCheckerTask checker; |
| 957 IrBuilderTask irBuilder; | 956 IrBuilderTask irBuilder; |
| 958 ti.TypesTask typesTask; | 957 ti.TypesTask typesTask; |
| 959 Backend backend; | 958 Backend backend; |
| 960 | 959 |
| 961 GenericTask reuseLibraryTask; | 960 GenericTask reuseLibraryTask; |
| 962 | 961 |
| 963 /// The constant environment for the frontend interpretation of compile-time | 962 /// The constant environment for the frontend interpretation of compile-time |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 } else { | 1108 } else { |
| 1110 backend = new dart_backend.DartBackend(this, strips, | 1109 backend = new dart_backend.DartBackend(this, strips, |
| 1111 multiFile: dart2dartMultiFile); | 1110 multiFile: dart2dartMultiFile); |
| 1112 if (dumpInfo) { | 1111 if (dumpInfo) { |
| 1113 throw new ArgumentError('--dump-info is not supported for dart2dart.'); | 1112 throw new ArgumentError('--dump-info is not supported for dart2dart.'); |
| 1114 } | 1113 } |
| 1115 } | 1114 } |
| 1116 | 1115 |
| 1117 tasks = [ | 1116 tasks = [ |
| 1118 libraryLoader = new LibraryLoaderTask(this), | 1117 libraryLoader = new LibraryLoaderTask(this), |
| 1118 serialization = new SerializationTask(this), |
| 1119 scanner = new ScannerTask(this), | 1119 scanner = new ScannerTask(this), |
| 1120 dietParser = new DietParserTask(this), | 1120 dietParser = new DietParserTask(this), |
| 1121 parser = new ParserTask(this), | 1121 parser = new ParserTask(this), |
| 1122 patchParser = new PatchParserTask(this), | 1122 patchParser = new PatchParserTask(this), |
| 1123 resolver = new ResolverTask(this, backend.constantCompilerTask), | 1123 resolver = new ResolverTask(this, backend.constantCompilerTask), |
| 1124 closureToClassMapper = new closureMapping.ClosureTask(this), | 1124 closureToClassMapper = new closureMapping.ClosureTask(this), |
| 1125 checker = new TypeCheckerTask(this), | 1125 checker = new TypeCheckerTask(this), |
| 1126 irBuilder = new IrBuilderTask(this, backend.sourceInformationStrategy), | 1126 irBuilder = new IrBuilderTask(this, backend.sourceInformationStrategy), |
| 1127 typesTask = new ti.TypesTask(this), | 1127 typesTask = new ti.TypesTask(this), |
| 1128 constants = backend.constantCompilerTask, | 1128 constants = backend.constantCompilerTask, |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1809 if (tree != null && !analyzeSignaturesOnly && !suppressWarnings) { | 1809 if (tree != null && !analyzeSignaturesOnly && !suppressWarnings) { |
| 1810 // Only analyze nodes with a corresponding [TreeElements]. | 1810 // Only analyze nodes with a corresponding [TreeElements]. |
| 1811 checker.check(element); | 1811 checker.check(element); |
| 1812 } | 1812 } |
| 1813 world.registerResolvedElement(element); | 1813 world.registerResolvedElement(element); |
| 1814 return worldImpact; | 1814 return worldImpact; |
| 1815 } | 1815 } |
| 1816 | 1816 |
| 1817 WorldImpact analyze(ResolutionWorkItem work, ResolutionEnqueuer world) { | 1817 WorldImpact analyze(ResolutionWorkItem work, ResolutionEnqueuer world) { |
| 1818 assert(invariant(work.element, identical(world, enqueuer.resolution))); | 1818 assert(invariant(work.element, identical(world, enqueuer.resolution))); |
| 1819 assert(invariant(work.element, !work.isAnalyzed(), | 1819 assert(invariant(work.element, !work.isAnalyzed, |
| 1820 message: 'Element ${work.element} has already been analyzed')); | 1820 message: 'Element ${work.element} has already been analyzed')); |
| 1821 if (shouldPrintProgress) { | 1821 if (shouldPrintProgress) { |
| 1822 // TODO(ahe): Add structured diagnostics to the compiler API and | 1822 // TODO(ahe): Add structured diagnostics to the compiler API and |
| 1823 // use it to separate this from the --verbose option. | 1823 // use it to separate this from the --verbose option. |
| 1824 if (phase == PHASE_RESOLVING) { | 1824 if (phase == PHASE_RESOLVING) { |
| 1825 log('Resolved ${enqueuer.resolution.resolvedElements.length} ' | 1825 log('Resolved ${enqueuer.resolution.resolvedElements.length} ' |
| 1826 'elements.'); | 1826 'elements.'); |
| 1827 progress.reset(); | 1827 progress.reset(); |
| 1828 } | 1828 } |
| 1829 } | 1829 } |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2233 f(int beginOffset, int endOffset)) { | 2233 f(int beginOffset, int endOffset)) { |
| 2234 final beginOffset = begin.charOffset; | 2234 final beginOffset = begin.charOffset; |
| 2235 final endOffset = end.charOffset + end.charCount; | 2235 final endOffset = end.charOffset + end.charCount; |
| 2236 | 2236 |
| 2237 // [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 |
| 2238 // happens for instance when scanning '$$'. | 2238 // happens for instance when scanning '$$'. |
| 2239 assert(endOffset >= beginOffset); | 2239 assert(endOffset >= beginOffset); |
| 2240 return f(beginOffset, endOffset); | 2240 return f(beginOffset, endOffset); |
| 2241 } | 2241 } |
| 2242 | 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 |
| 2243 String toString() => 'SourceSpan($uri, $begin, $end)'; | 2257 String toString() => 'SourceSpan($uri, $begin, $end)'; |
| 2244 } | 2258 } |
| 2245 | 2259 |
| 2246 /// 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 |
| 2247 /// executed as part of development. | 2261 /// executed as part of development. |
| 2248 /// | 2262 /// |
| 2249 /// 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], |
| 2250 /// [debugWrapPrint], [trace], and [reportHere] are called. | 2264 /// [debugWrapPrint], [trace], and [reportHere] are called. |
| 2251 bool DEBUG_MODE = false; | 2265 bool DEBUG_MODE = false; |
| 2252 | 2266 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2407 const AnyLocation(); | 2421 const AnyLocation(); |
| 2408 | 2422 |
| 2409 bool inSameLocation(Uri uri) => true; | 2423 bool inSameLocation(Uri uri) => true; |
| 2410 | 2424 |
| 2411 String relativize(Uri baseUri) => '$baseUri'; | 2425 String relativize(Uri baseUri) => '$baseUri'; |
| 2412 } | 2426 } |
| 2413 | 2427 |
| 2414 class _CompilerCoreTypes implements CoreTypes { | 2428 class _CompilerCoreTypes implements CoreTypes { |
| 2415 final Compiler compiler; | 2429 final Compiler compiler; |
| 2416 | 2430 |
| 2417 ClassElementX objectClass; | 2431 ClassElement objectClass; |
| 2418 ClassElementX boolClass; | 2432 ClassElement boolClass; |
| 2419 ClassElementX numClass; | 2433 ClassElement numClass; |
| 2420 ClassElementX intClass; | 2434 ClassElement intClass; |
| 2421 ClassElementX doubleClass; | 2435 ClassElement doubleClass; |
| 2422 ClassElementX stringClass; | 2436 ClassElement stringClass; |
| 2423 ClassElementX functionClass; | 2437 ClassElement functionClass; |
| 2424 ClassElementX nullClass; | 2438 ClassElement nullClass; |
| 2425 ClassElementX listClass; | 2439 ClassElement listClass; |
| 2426 ClassElementX typeClass; | 2440 ClassElement typeClass; |
| 2427 ClassElementX mapClass; | 2441 ClassElement mapClass; |
| 2428 ClassElementX symbolClass; | 2442 ClassElement symbolClass; |
| 2429 ClassElementX stackTraceClass; | 2443 ClassElement stackTraceClass; |
| 2430 ClassElementX futureClass; | 2444 ClassElement futureClass; |
| 2431 ClassElementX iterableClass; | 2445 ClassElement iterableClass; |
| 2432 ClassElementX streamClass; | 2446 ClassElement streamClass; |
| 2433 | 2447 |
| 2434 _CompilerCoreTypes(this.compiler); | 2448 _CompilerCoreTypes(this.compiler); |
| 2435 | 2449 |
| 2436 @override | 2450 @override |
| 2437 InterfaceType get objectType => objectClass.computeType(compiler); | 2451 InterfaceType get objectType => objectClass.computeType(compiler); |
| 2438 | 2452 |
| 2439 @override | 2453 @override |
| 2440 InterfaceType get boolType => boolClass.computeType(compiler); | 2454 InterfaceType get boolType => boolClass.computeType(compiler); |
| 2441 | 2455 |
| 2442 @override | 2456 @override |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2508 InterfaceType streamType([DartType elementType]) { | 2522 InterfaceType streamType([DartType elementType]) { |
| 2509 InterfaceType type = streamClass.computeType(compiler); | 2523 InterfaceType type = streamClass.computeType(compiler); |
| 2510 if (elementType == null) { | 2524 if (elementType == null) { |
| 2511 return streamClass.rawType; | 2525 return streamClass.rawType; |
| 2512 } | 2526 } |
| 2513 return type.createInstantiation([elementType]); | 2527 return type.createInstantiation([elementType]); |
| 2514 } | 2528 } |
| 2515 } | 2529 } |
| 2516 | 2530 |
| 2517 typedef void InternalErrorFunction(Spannable location, String message); | 2531 typedef void InternalErrorFunction(Spannable location, String message); |
| OLD | NEW |