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 Future; | 7 import 'dart:async' show Future; |
8 | 8 |
9 import '../compiler_new.dart' as api; | 9 import '../compiler_new.dart' as api; |
10 import 'backend_strategy.dart'; | 10 import 'backend_strategy.dart'; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 typedef CompilerDiagnosticReporter MakeReporterFunction( | 81 typedef CompilerDiagnosticReporter MakeReporterFunction( |
82 Compiler compiler, CompilerOptions options); | 82 Compiler compiler, CompilerOptions options); |
83 | 83 |
84 abstract class Compiler { | 84 abstract class Compiler { |
85 Measurer get measurer; | 85 Measurer get measurer; |
86 | 86 |
87 final IdGenerator idGenerator = new IdGenerator(); | 87 final IdGenerator idGenerator = new IdGenerator(); |
88 DartTypes types; | 88 DartTypes types; |
89 FrontendStrategy frontendStrategy; | 89 FrontendStrategy frontendStrategy; |
90 BackendStrategy backendStrategy; | 90 BackendStrategy backendStrategy; |
91 CommonElements _commonElements; | |
92 ElementEnvironment _elementEnvironment; | 91 ElementEnvironment _elementEnvironment; |
93 CompilerDiagnosticReporter _reporter; | 92 CompilerDiagnosticReporter _reporter; |
94 CompilerResolution _resolution; | 93 CompilerResolution _resolution; |
95 ParsingContext _parsingContext; | 94 ParsingContext _parsingContext; |
96 | 95 |
97 ImpactStrategy impactStrategy = const ImpactStrategy(); | 96 ImpactStrategy impactStrategy = const ImpactStrategy(); |
98 | 97 |
99 /** | 98 /** |
100 * Map from token to the first preceding comment token. | 99 * Map from token to the first preceding comment token. |
101 */ | 100 */ |
(...skipping 13 matching lines...) Expand all Loading... |
115 | 114 |
116 List<Uri> librariesToAnalyzeWhenRun; | 115 List<Uri> librariesToAnalyzeWhenRun; |
117 | 116 |
118 ResolvedUriTranslator get resolvedUriTranslator; | 117 ResolvedUriTranslator get resolvedUriTranslator; |
119 | 118 |
120 LibraryEntity mainApp; | 119 LibraryEntity mainApp; |
121 FunctionEntity mainFunction; | 120 FunctionEntity mainFunction; |
122 | 121 |
123 DiagnosticReporter get reporter => _reporter; | 122 DiagnosticReporter get reporter => _reporter; |
124 ElementEnvironment get elementEnvironment => _elementEnvironment; | 123 ElementEnvironment get elementEnvironment => _elementEnvironment; |
125 CommonElements get commonElements => _commonElements; | |
126 Resolution get resolution => _resolution; | 124 Resolution get resolution => _resolution; |
127 ParsingContext get parsingContext => _parsingContext; | 125 ParsingContext get parsingContext => _parsingContext; |
128 | 126 |
129 // TODO(zarah): Remove this map and incorporate compile-time errors | 127 // TODO(zarah): Remove this map and incorporate compile-time errors |
130 // in the model. | 128 // in the model. |
131 /// Tracks elements with compile-time errors. | 129 /// Tracks elements with compile-time errors. |
132 final Map<Entity, List<DiagnosticMessage>> elementsWithCompileTimeErrors = | 130 final Map<Entity, List<DiagnosticMessage>> elementsWithCompileTimeErrors = |
133 new Map<Entity, List<DiagnosticMessage>>(); | 131 new Map<Entity, List<DiagnosticMessage>>(); |
134 | 132 |
135 final Environment environment; | 133 final Environment environment; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 _reporter = new CompilerDiagnosticReporter(this, options); | 194 _reporter = new CompilerDiagnosticReporter(this, options); |
197 } | 195 } |
198 frontendStrategy = options.loadFromDill | 196 frontendStrategy = options.loadFromDill |
199 ? new KernelFrontEndStrategy(reporter, environment) | 197 ? new KernelFrontEndStrategy(reporter, environment) |
200 : new ResolutionFrontEndStrategy(this); | 198 : new ResolutionFrontEndStrategy(this); |
201 backendStrategy = options.loadFromDill | 199 backendStrategy = options.loadFromDill |
202 ? new KernelBackendStrategy(this) | 200 ? new KernelBackendStrategy(this) |
203 : new ElementBackendStrategy(this); | 201 : new ElementBackendStrategy(this); |
204 _resolution = createResolution(); | 202 _resolution = createResolution(); |
205 _elementEnvironment = frontendStrategy.elementEnvironment; | 203 _elementEnvironment = frontendStrategy.elementEnvironment; |
206 _commonElements = frontendStrategy.commonElements; | |
207 types = new Types(_resolution); | 204 types = new Types(_resolution); |
208 | 205 |
209 if (options.verbose) { | 206 if (options.verbose) { |
210 progress = new Stopwatch()..start(); | 207 progress = new Stopwatch()..start(); |
211 } | 208 } |
212 | 209 |
213 backend = createBackend(); | 210 backend = createBackend(); |
214 enqueuer = backend.makeEnqueuer(); | 211 enqueuer = backend.makeEnqueuer(); |
215 | 212 |
216 tasks = [ | 213 tasks = [ |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 /// already created. | 500 /// already created. |
504 /// | 501 /// |
505 /// During normal compilation resolution only started once, but through | 502 /// During normal compilation resolution only started once, but through |
506 /// [analyzeUri] resolution is started repeatedly. | 503 /// [analyzeUri] resolution is started repeatedly. |
507 ResolutionEnqueuer startResolution() { | 504 ResolutionEnqueuer startResolution() { |
508 ResolutionEnqueuer resolutionEnqueuer; | 505 ResolutionEnqueuer resolutionEnqueuer; |
509 if (enqueuer.hasResolution) { | 506 if (enqueuer.hasResolution) { |
510 resolutionEnqueuer = enqueuer.resolution; | 507 resolutionEnqueuer = enqueuer.resolution; |
511 } else { | 508 } else { |
512 resolutionEnqueuer = enqueuer.createResolutionEnqueuer(); | 509 resolutionEnqueuer = enqueuer.createResolutionEnqueuer(); |
513 backend.onResolutionStart(resolutionEnqueuer); | 510 backend.onResolutionStart(); |
514 } | 511 } |
515 resolutionEnqueuer.addDeferredActions(libraryLoader.pullDeferredActions()); | 512 resolutionEnqueuer.addDeferredActions(libraryLoader.pullDeferredActions()); |
516 return resolutionEnqueuer; | 513 return resolutionEnqueuer; |
517 } | 514 } |
518 | 515 |
519 /// Performs the compilation when all libraries have been loaded. | 516 /// Performs the compilation when all libraries have been loaded. |
520 void compileLoadedLibraries(LibraryEntity rootLibrary) => | 517 void compileLoadedLibraries(LibraryEntity rootLibrary) => |
521 selfTask.measureSubtask("Compiler.compileLoadedLibraries", () { | 518 selfTask.measureSubtask("Compiler.compileLoadedLibraries", () { |
522 ResolutionEnqueuer resolutionEnqueuer = startResolution(); | 519 ResolutionEnqueuer resolutionEnqueuer = startResolution(); |
523 WorldImpactBuilderImpl mainImpact = new WorldImpactBuilderImpl(); | 520 WorldImpactBuilderImpl mainImpact = new WorldImpactBuilderImpl(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 resolutionEnqueuer | 554 resolutionEnqueuer |
558 .applyImpact(computeImpactForLibrary(rootLibrary)); | 555 .applyImpact(computeImpactForLibrary(rootLibrary)); |
559 } | 556 } |
560 if (librariesToAnalyzeWhenRun != null) { | 557 if (librariesToAnalyzeWhenRun != null) { |
561 for (Uri libraryUri in librariesToAnalyzeWhenRun) { | 558 for (Uri libraryUri in librariesToAnalyzeWhenRun) { |
562 resolutionEnqueuer.applyImpact(computeImpactForLibrary( | 559 resolutionEnqueuer.applyImpact(computeImpactForLibrary( |
563 libraryLoader.lookupLibrary(libraryUri))); | 560 libraryLoader.lookupLibrary(libraryUri))); |
564 } | 561 } |
565 } | 562 } |
566 } | 563 } |
567 if (commonElements.mirrorsLibrary != null && !options.loadFromDill) { | 564 if (frontendStrategy.commonElements.mirrorsLibrary != null && |
| 565 !options.loadFromDill) { |
568 // TODO(johnniwinther): Support mirrors from dill. | 566 // TODO(johnniwinther): Support mirrors from dill. |
569 resolveLibraryMetadata(); | 567 resolveLibraryMetadata(); |
570 } | 568 } |
571 reporter.log('Resolving...'); | 569 reporter.log('Resolving...'); |
572 | 570 |
573 processQueue(resolutionEnqueuer, mainFunction, libraryLoader.libraries, | 571 processQueue(resolutionEnqueuer, mainFunction, libraryLoader.libraries, |
574 onProgress: showResolutionProgress); | 572 onProgress: showResolutionProgress); |
575 backend.onResolutionEnd(); | 573 backend.onResolutionEnd(); |
576 resolutionEnqueuer.logSummary(reporter.log); | 574 resolutionEnqueuer.logSummary(reporter.log); |
577 | 575 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 } | 707 } |
710 }); | 708 }); |
711 } | 709 } |
712 return impactBuilder; | 710 return impactBuilder; |
713 } | 711 } |
714 | 712 |
715 // Resolves metadata on library elements. This is necessary in order to | 713 // Resolves metadata on library elements. This is necessary in order to |
716 // resolve metadata classes referenced only from metadata on library tags. | 714 // resolve metadata classes referenced only from metadata on library tags. |
717 // TODO(ahe): Figure out how to do this lazily. | 715 // TODO(ahe): Figure out how to do this lazily. |
718 void resolveLibraryMetadata() { | 716 void resolveLibraryMetadata() { |
719 assert(commonElements.mirrorsLibrary != null); | 717 assert(frontendStrategy.commonElements.mirrorsLibrary != null); |
720 for (LibraryElement library in libraryLoader.libraries) { | 718 for (LibraryElement library in libraryLoader.libraries) { |
721 if (library.metadata != null) { | 719 if (library.metadata != null) { |
722 for (MetadataAnnotation metadata in library.metadata) { | 720 for (MetadataAnnotation metadata in library.metadata) { |
723 metadata.ensureResolved(resolution); | 721 metadata.ensureResolved(resolution); |
724 } | 722 } |
725 } | 723 } |
726 } | 724 } |
727 } | 725 } |
728 | 726 |
729 /** | 727 /** |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 | 1289 |
1292 CompilerResolution(this._compiler); | 1290 CompilerResolution(this._compiler); |
1293 | 1291 |
1294 @override | 1292 @override |
1295 DiagnosticReporter get reporter => _compiler.reporter; | 1293 DiagnosticReporter get reporter => _compiler.reporter; |
1296 | 1294 |
1297 @override | 1295 @override |
1298 ParsingContext get parsingContext => _compiler.parsingContext; | 1296 ParsingContext get parsingContext => _compiler.parsingContext; |
1299 | 1297 |
1300 @override | 1298 @override |
1301 CommonElements get commonElements => _compiler.commonElements; | 1299 CommonElements get commonElements => |
| 1300 _compiler.frontendStrategy.commonElements; |
1302 | 1301 |
1303 @override | 1302 @override |
1304 Types get types => _compiler.types; | 1303 Types get types => _compiler.types; |
1305 | 1304 |
1306 @override | 1305 @override |
1307 Target get target => _compiler.backend.target; | 1306 Target get target => _compiler.backend.target; |
1308 | 1307 |
1309 @override | 1308 @override |
1310 ResolverTask get resolver => _compiler.resolver; | 1309 ResolverTask get resolver => _compiler.resolver; |
1311 | 1310 |
1312 @override | 1311 @override |
1313 ResolutionEnqueuer get enqueuer => _compiler.enqueuer.resolution; | 1312 ResolutionEnqueuer get enqueuer => _compiler.enqueuer.resolution; |
1314 | 1313 |
1315 @override | 1314 @override |
1316 CompilerOptions get options => _compiler.options; | 1315 CompilerOptions get options => _compiler.options; |
1317 | 1316 |
1318 @override | 1317 @override |
1319 IdGenerator get idGenerator => _compiler.idGenerator; | 1318 IdGenerator get idGenerator => _compiler.idGenerator; |
1320 | 1319 |
1321 @override | 1320 @override |
1322 ConstantEnvironment get constants => _compiler.constants; | 1321 ConstantEnvironment get constants => _compiler.constants; |
1323 | 1322 |
1324 @override | 1323 @override |
1325 MirrorUsageAnalyzerTask get mirrorUsageAnalyzerTask => | 1324 MirrorUsageAnalyzerTask get mirrorUsageAnalyzerTask => |
1326 _compiler.mirrorUsageAnalyzerTask; | 1325 _compiler.mirrorUsageAnalyzerTask; |
1327 | 1326 |
1328 LibraryElement get coreLibrary => _compiler._commonElements.coreLibrary; | 1327 LibraryElement get coreLibrary => |
| 1328 _compiler.frontendStrategy.commonElements.coreLibrary; |
1329 | 1329 |
1330 @override | 1330 @override |
1331 bool get wasProxyConstantComputedTestingOnly => _proxyConstant != null; | 1331 bool get wasProxyConstantComputedTestingOnly => _proxyConstant != null; |
1332 | 1332 |
1333 @override | 1333 @override |
1334 void registerClass(ClassElement cls) { | 1334 void registerClass(ClassElement cls) { |
1335 enqueuer.worldBuilder.registerClass(cls); | 1335 enqueuer.worldBuilder.registerClass(cls); |
1336 } | 1336 } |
1337 | 1337 |
1338 @override | 1338 @override |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 _ElementScanner(this.scanner); | 1582 _ElementScanner(this.scanner); |
1583 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 1583 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
1584 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 1584 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
1585 } | 1585 } |
1586 | 1586 |
1587 class _EmptyEnvironment implements Environment { | 1587 class _EmptyEnvironment implements Environment { |
1588 const _EmptyEnvironment(); | 1588 const _EmptyEnvironment(); |
1589 | 1589 |
1590 String valueOf(String key) => null; | 1590 String valueOf(String key) => null; |
1591 } | 1591 } |
OLD | NEW |