| 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 ElementEnvironment _elementEnvironment; | |
| 92 CompilerDiagnosticReporter _reporter; | 91 CompilerDiagnosticReporter _reporter; |
| 93 CompilerResolution _resolution; | 92 CompilerResolution _resolution; |
| 94 ParsingContext _parsingContext; | 93 ParsingContext _parsingContext; |
| 95 | 94 |
| 96 ImpactStrategy impactStrategy = const ImpactStrategy(); | 95 ImpactStrategy impactStrategy = const ImpactStrategy(); |
| 97 | 96 |
| 98 /** | 97 /** |
| 99 * Map from token to the first preceding comment token. | 98 * Map from token to the first preceding comment token. |
| 100 */ | 99 */ |
| 101 final TokenMap commentMap = new TokenMap(); | 100 final TokenMap commentMap = new TokenMap(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 113 api.CompilerOutput userOutputProvider; | 112 api.CompilerOutput userOutputProvider; |
| 114 | 113 |
| 115 List<Uri> librariesToAnalyzeWhenRun; | 114 List<Uri> librariesToAnalyzeWhenRun; |
| 116 | 115 |
| 117 ResolvedUriTranslator get resolvedUriTranslator; | 116 ResolvedUriTranslator get resolvedUriTranslator; |
| 118 | 117 |
| 119 LibraryEntity mainApp; | 118 LibraryEntity mainApp; |
| 120 FunctionEntity mainFunction; | 119 FunctionEntity mainFunction; |
| 121 | 120 |
| 122 DiagnosticReporter get reporter => _reporter; | 121 DiagnosticReporter get reporter => _reporter; |
| 123 ElementEnvironment get elementEnvironment => _elementEnvironment; | |
| 124 Resolution get resolution => _resolution; | 122 Resolution get resolution => _resolution; |
| 125 ParsingContext get parsingContext => _parsingContext; | 123 ParsingContext get parsingContext => _parsingContext; |
| 126 | 124 |
| 127 // TODO(zarah): Remove this map and incorporate compile-time errors | 125 // TODO(zarah): Remove this map and incorporate compile-time errors |
| 128 // in the model. | 126 // in the model. |
| 129 /// Tracks elements with compile-time errors. | 127 /// Tracks elements with compile-time errors. |
| 130 final Map<Entity, List<DiagnosticMessage>> elementsWithCompileTimeErrors = | 128 final Map<Entity, List<DiagnosticMessage>> elementsWithCompileTimeErrors = |
| 131 new Map<Entity, List<DiagnosticMessage>>(); | 129 new Map<Entity, List<DiagnosticMessage>>(); |
| 132 | 130 |
| 133 final Environment environment; | 131 final Environment environment; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } else { | 191 } else { |
| 194 _reporter = new CompilerDiagnosticReporter(this, options); | 192 _reporter = new CompilerDiagnosticReporter(this, options); |
| 195 } | 193 } |
| 196 frontendStrategy = options.loadFromDill | 194 frontendStrategy = options.loadFromDill |
| 197 ? new KernelFrontEndStrategy(reporter, environment) | 195 ? new KernelFrontEndStrategy(reporter, environment) |
| 198 : new ResolutionFrontEndStrategy(this); | 196 : new ResolutionFrontEndStrategy(this); |
| 199 backendStrategy = options.loadFromDill | 197 backendStrategy = options.loadFromDill |
| 200 ? new KernelBackendStrategy(this) | 198 ? new KernelBackendStrategy(this) |
| 201 : new ElementBackendStrategy(this); | 199 : new ElementBackendStrategy(this); |
| 202 _resolution = createResolution(); | 200 _resolution = createResolution(); |
| 203 _elementEnvironment = frontendStrategy.elementEnvironment; | |
| 204 types = new Types(_resolution); | 201 types = new Types(_resolution); |
| 205 | 202 |
| 206 if (options.verbose) { | 203 if (options.verbose) { |
| 207 progress = new Stopwatch()..start(); | 204 progress = new Stopwatch()..start(); |
| 208 } | 205 } |
| 209 | 206 |
| 210 backend = createBackend(); | 207 backend = createBackend(); |
| 211 enqueuer = backend.makeEnqueuer(); | 208 enqueuer = backend.makeEnqueuer(); |
| 212 | 209 |
| 213 tasks = [ | 210 tasks = [ |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 } | 558 } |
| 562 } | 559 } |
| 563 } | 560 } |
| 564 if (frontendStrategy.commonElements.mirrorsLibrary != null && | 561 if (frontendStrategy.commonElements.mirrorsLibrary != null && |
| 565 !options.loadFromDill) { | 562 !options.loadFromDill) { |
| 566 // TODO(johnniwinther): Support mirrors from dill. | 563 // TODO(johnniwinther): Support mirrors from dill. |
| 567 resolveLibraryMetadata(); | 564 resolveLibraryMetadata(); |
| 568 } | 565 } |
| 569 reporter.log('Resolving...'); | 566 reporter.log('Resolving...'); |
| 570 | 567 |
| 571 processQueue(resolutionEnqueuer, mainFunction, libraryLoader.libraries, | 568 processQueue(frontendStrategy.elementEnvironment, resolutionEnqueuer, |
| 569 mainFunction, libraryLoader.libraries, |
| 572 onProgress: showResolutionProgress); | 570 onProgress: showResolutionProgress); |
| 573 backend.onResolutionEnd(); | 571 backend.onResolutionEnd(); |
| 574 resolutionEnqueuer.logSummary(reporter.log); | 572 resolutionEnqueuer.logSummary(reporter.log); |
| 575 | 573 |
| 576 _reporter.reportSuppressedMessagesSummary(); | 574 _reporter.reportSuppressedMessagesSummary(); |
| 577 | 575 |
| 578 if (compilationFailed) { | 576 if (compilationFailed) { |
| 579 if (!options.generateCodeWithCompileTimeErrors || options.useKernel) { | 577 if (!options.generateCodeWithCompileTimeErrors || options.useKernel) { |
| 580 return; | 578 return; |
| 581 } | 579 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 | 612 |
| 615 Enqueuer codegenEnqueuer = enqueuer.createCodegenEnqueuer(closedWorld); | 613 Enqueuer codegenEnqueuer = enqueuer.createCodegenEnqueuer(closedWorld); |
| 616 _codegenWorldBuilder = codegenEnqueuer.worldBuilder; | 614 _codegenWorldBuilder = codegenEnqueuer.worldBuilder; |
| 617 codegenEnqueuer.applyImpact( | 615 codegenEnqueuer.applyImpact( |
| 618 backend.onCodegenStart(closedWorld, _codegenWorldBuilder)); | 616 backend.onCodegenStart(closedWorld, _codegenWorldBuilder)); |
| 619 if (compileAll) { | 617 if (compileAll) { |
| 620 libraryLoader.libraries.forEach((LibraryEntity library) { | 618 libraryLoader.libraries.forEach((LibraryEntity library) { |
| 621 codegenEnqueuer.applyImpact(computeImpactForLibrary(library)); | 619 codegenEnqueuer.applyImpact(computeImpactForLibrary(library)); |
| 622 }); | 620 }); |
| 623 } | 621 } |
| 624 processQueue(codegenEnqueuer, mainFunction, libraryLoader.libraries, | 622 processQueue(closedWorld.elementEnvironment, codegenEnqueuer, |
| 623 mainFunction, libraryLoader.libraries, |
| 625 onProgress: showCodegenProgress); | 624 onProgress: showCodegenProgress); |
| 626 codegenEnqueuer.logSummary(reporter.log); | 625 codegenEnqueuer.logSummary(reporter.log); |
| 627 | 626 |
| 628 int programSize = backend.assembleProgram(closedWorld); | 627 int programSize = backend.assembleProgram(closedWorld); |
| 629 | 628 |
| 630 if (options.dumpInfo) { | 629 if (options.dumpInfo) { |
| 631 dumpInfoTask.reportSize(programSize); | 630 dumpInfoTask.reportSize(programSize); |
| 632 dumpInfoTask.dumpInfo(closedWorld); | 631 dumpInfoTask.dumpInfo(closedWorld); |
| 633 } | 632 } |
| 634 | 633 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 work.element, | 736 work.element, |
| 738 () => selfTask.measureSubtask("world.applyImpact", () { | 737 () => selfTask.measureSubtask("world.applyImpact", () { |
| 739 enqueuer.applyImpact( | 738 enqueuer.applyImpact( |
| 740 selfTask.measureSubtask("work.run", () => work.run()), | 739 selfTask.measureSubtask("work.run", () => work.run()), |
| 741 impactSource: work.element); | 740 impactSource: work.element); |
| 742 })); | 741 })); |
| 743 }); | 742 }); |
| 744 }); | 743 }); |
| 745 } | 744 } |
| 746 | 745 |
| 747 void processQueue(Enqueuer enqueuer, FunctionEntity mainMethod, | 746 void processQueue(ElementEnvironment elementEnvironment, Enqueuer enqueuer, |
| 748 Iterable<LibraryEntity> libraries, | 747 FunctionEntity mainMethod, Iterable<LibraryEntity> libraries, |
| 749 {void onProgress(Enqueuer enqueuer)}) { | 748 {void onProgress(Enqueuer enqueuer)}) { |
| 750 selfTask.measureSubtask("Compiler.processQueue", () { | 749 selfTask.measureSubtask("Compiler.processQueue", () { |
| 751 enqueuer.open(impactStrategy, mainMethod, libraries); | 750 enqueuer.open(impactStrategy, mainMethod, libraries); |
| 752 if (options.verbose) { | 751 if (options.verbose) { |
| 753 progress.reset(); | 752 progress.reset(); |
| 754 } | 753 } |
| 755 emptyQueue(enqueuer, onProgress: onProgress); | 754 emptyQueue(enqueuer, onProgress: onProgress); |
| 756 enqueuer.queueIsClosed = true; | 755 enqueuer.queueIsClosed = true; |
| 757 enqueuer.close(); | 756 enqueuer.close(); |
| 758 // Notify the impact strategy impacts are no longer needed for this | 757 // Notify the impact strategy impacts are no longer needed for this |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 | 1288 |
| 1290 CompilerResolution(this._compiler); | 1289 CompilerResolution(this._compiler); |
| 1291 | 1290 |
| 1292 @override | 1291 @override |
| 1293 DiagnosticReporter get reporter => _compiler.reporter; | 1292 DiagnosticReporter get reporter => _compiler.reporter; |
| 1294 | 1293 |
| 1295 @override | 1294 @override |
| 1296 ParsingContext get parsingContext => _compiler.parsingContext; | 1295 ParsingContext get parsingContext => _compiler.parsingContext; |
| 1297 | 1296 |
| 1298 @override | 1297 @override |
| 1298 ElementEnvironment get elementEnvironment => |
| 1299 _compiler.frontendStrategy.elementEnvironment; |
| 1300 |
| 1301 @override |
| 1299 CommonElements get commonElements => | 1302 CommonElements get commonElements => |
| 1300 _compiler.frontendStrategy.commonElements; | 1303 _compiler.frontendStrategy.commonElements; |
| 1301 | 1304 |
| 1302 @override | 1305 @override |
| 1303 Types get types => _compiler.types; | 1306 Types get types => _compiler.types; |
| 1304 | 1307 |
| 1305 @override | 1308 @override |
| 1306 Target get target => _compiler.backend.target; | 1309 Target get target => _compiler.backend.target; |
| 1307 | 1310 |
| 1308 @override | 1311 @override |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1582 _ElementScanner(this.scanner); | 1585 _ElementScanner(this.scanner); |
| 1583 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); | 1586 void scanLibrary(LibraryElement library) => scanner.scanLibrary(library); |
| 1584 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); | 1587 void scanUnit(CompilationUnitElement unit) => scanner.scan(unit); |
| 1585 } | 1588 } |
| 1586 | 1589 |
| 1587 class _EmptyEnvironment implements Environment { | 1590 class _EmptyEnvironment implements Environment { |
| 1588 const _EmptyEnvironment(); | 1591 const _EmptyEnvironment(); |
| 1589 | 1592 |
| 1590 String valueOf(String key) => null; | 1593 String valueOf(String key) => null; |
| 1591 } | 1594 } |
| OLD | NEW |