Index: pkg/dev_compiler/lib/src/compiler/compiler.dart |
diff --git a/pkg/dev_compiler/lib/src/compiler/compiler.dart b/pkg/dev_compiler/lib/src/compiler/compiler.dart |
index e2808bf56caede3b97945a3965ac8de531bb90f8..f9e45c2950e358dbe18e099683e01febcadb16e0 100644 |
--- a/pkg/dev_compiler/lib/src/compiler/compiler.dart |
+++ b/pkg/dev_compiler/lib/src/compiler/compiler.dart |
@@ -2,28 +2,32 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
+import 'dart:async'; |
import 'dart:collection' show HashSet, Queue; |
-import 'dart:convert' show BASE64, JSON, UTF8; |
+import 'dart:convert' show JSON; |
import 'dart:io' show File; |
import 'package:analyzer/analyzer.dart' |
show AnalysisError, CompilationUnit, ErrorSeverity; |
+import 'package:analyzer/context/declared_variables.dart'; |
import 'package:analyzer/dart/element/element.dart' show LibraryElement; |
import 'package:analyzer/file_system/file_system.dart' show ResourceProvider; |
import 'package:analyzer/file_system/physical_file_system.dart' |
show PhysicalResourceProvider; |
import 'package:analyzer/src/context/builder.dart' show ContextBuilder; |
-import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl; |
+import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
+import 'package:analyzer/src/dart/analysis/driver.dart'; |
+import 'package:analyzer/src/dart/analysis/file_state.dart'; |
import 'package:analyzer/src/error/codes.dart' show StaticTypeWarningCode; |
import 'package:analyzer/src/generated/engine.dart' |
show AnalysisContext, AnalysisEngine; |
import 'package:analyzer/src/generated/sdk.dart' show DartSdkManager; |
import 'package:analyzer/src/generated/source.dart' |
- show ContentCache, DartUriResolver; |
+ show ContentCache, DartUriResolver, LineInfo; |
import 'package:analyzer/src/generated/source_io.dart' |
show Source, SourceKind, UriResolver; |
import 'package:analyzer/src/summary/package_bundle_reader.dart' |
- show InSummarySource, InputPackagesResultProvider, SummaryDataStore; |
+ show InSummarySource, SummaryDataStore; |
import 'package:args/args.dart' show ArgParser, ArgResults; |
import 'package:args/src/usage_exception.dart' show UsageException; |
import 'package:func/func.dart' show Func1; |
@@ -57,13 +61,11 @@ import 'source_map_printer.dart' show SourceMapPrintingContext; |
/// sources are immutable for the life of the context, and cache information |
/// about them. |
class ModuleCompiler { |
- final AnalysisContext context; |
+ final AnalysisDriver driver; |
final SummaryDataStore summaryData; |
- final ExtensionTypeSet _extensionTypes; |
+ ExtensionTypeSet _extensionTypes; |
- ModuleCompiler._(AnalysisContext context, this.summaryData) |
- : context = context, |
- _extensionTypes = new ExtensionTypeSet(context); |
+ ModuleCompiler._(this.driver, this.summaryData); |
factory ModuleCompiler(AnalyzerOptions options, |
{ResourceProvider resourceProvider, |
@@ -99,33 +101,44 @@ class ModuleCompiler { |
summaryData: summaryData, |
resourceProvider: resourceProvider); |
- var context = |
- AnalysisEngine.instance.createAnalysisContext() as AnalysisContextImpl; |
- context.analysisOptions = analysisOptions; |
- context.sourceFactory = srcFactory; |
- if (sdkSummaryBundle != null) { |
- context.resultProvider = |
- new InputPackagesResultProvider(context, summaryData); |
- } |
- options.declaredVariables.forEach(context.declaredVariables.define); |
- context.declaredVariables.define('dart.isVM', 'false'); |
- |
+ var declaredVariables = new DeclaredVariables(); |
+ options.declaredVariables.forEach(declaredVariables.define); |
+ declaredVariables.define('dart.isVM', 'false'); |
// TODO(vsm): Should this be hardcoded? |
- context.declaredVariables.define('dart.library.html', 'true'); |
- context.declaredVariables.define('dart.library.io', 'false'); |
+ declaredVariables.define('dart.library.html', 'true'); |
+ declaredVariables.define('dart.library.io', 'false'); |
- if (!context.analysisOptions.strongMode) { |
- throw new ArgumentError('AnalysisContext must be strong mode'); |
+ if (!analysisOptions.strongMode) { |
+ throw new ArgumentError('AnalysisOptions must be strong mode'); |
} |
- if (!context.sourceFactory.dartSdk.context.analysisOptions.strongMode) { |
- throw new ArgumentError('AnalysisContext must have strong mode SDK'); |
+ if (!srcFactory.dartSdk.context.analysisOptions.strongMode) { |
+ throw new ArgumentError('AnalysisOptions must have strong mode SDK'); |
} |
- return new ModuleCompiler._(context, summaryData); |
+ AnalysisDriver driver; |
+ { |
Jennifer Messerly
2017/03/17 18:33:37
i'm not sure this block is necessary
scheglov
2017/04/25 17:07:35
We defined a couple of variables that are not usef
|
+ var logger = new PerformanceLog(new StringBuffer()); |
+// var logger = new PerformanceLog(stdout); |
Jennifer Messerly
2017/03/17 18:33:38
remove?
scheglov
2017/04/25 17:07:35
Done.
|
+ var scheduler = new AnalysisDriverScheduler(logger); |
+ driver = new AnalysisDriver( |
+ scheduler, |
+ logger, |
+ resourceProvider, |
+ new MemoryByteStore(), |
+ new FileContentOverlay(), |
+ 'DDC', |
+ srcFactory, |
+ analysisOptions, |
+ externalSummaries: summaryData); |
+ scheduler.start(); |
+ } |
+ |
+ return new ModuleCompiler._(driver, summaryData); |
} |
bool _isFatalError(AnalysisError e, CompilerOptions options) { |
- if (errorSeverity(context, e) != ErrorSeverity.ERROR) return false; |
+ if (errorSeverity(driver.analysisOptions, e) != ErrorSeverity.ERROR) |
+ return false; |
// These errors are not fatal in the REPL compile mode as we |
// allow access to private members across library boundaries |
@@ -144,40 +157,45 @@ class ModuleCompiler { |
/// *Warning* - this may require resolving the entire world. |
/// If that is not desired, the analysis context must be pre-configured using |
/// summaries before calling this method. |
- JSModuleFile compile(BuildUnit unit, CompilerOptions options) { |
+ Future<JSModuleFile> compile(BuildUnit unit, CompilerOptions options) async { |
var trees = <CompilationUnit>[]; |
var errors = <AnalysisError>[]; |
+ var lineInfoMap = <String, LineInfo>{}; |
var librariesToCompile = new Queue<LibraryElement>(); |
var compilingSdk = false; |
- for (var sourcePath in unit.sources) { |
- var sourceUri = Uri.parse(sourcePath); |
+ for (var sourceUriStr in unit.sources) { |
+ var sourceUri = Uri.parse(sourceUriStr); |
if (sourceUri.scheme == '') { |
- sourceUri = path.toUri(path.absolute(sourcePath)); |
+ sourceUri = path.toUri(path.absolute(sourceUriStr)); |
} else if (sourceUri.scheme == 'dart') { |
compilingSdk = true; |
} |
- Source source = context.sourceFactory.forUri2(sourceUri); |
+ Source source = driver.sourceFactory.forUri2(sourceUri); |
+ String sourcePath = source.fullName; |
var fileUsage = 'You need to pass at least one existing .dart file as an' |
' argument.'; |
if (source == null) { |
throw new UsageException( |
- 'Could not create a source for "$sourcePath". The file name is in' |
+ 'Could not create a source for "$sourceUriStr". The file name is in' |
' the wrong format or was not found.', |
fileUsage); |
} else if (!source.exists()) { |
throw new UsageException( |
- 'Given file "$sourcePath" does not exist.', fileUsage); |
+ 'Given file "$sourceUriStr" does not exist.', fileUsage); |
} |
// Ignore parts. They need to be handled in the context of their library. |
- if (context.computeKindOf(source) == SourceKind.PART) { |
+ SourceKind sourceKind = await driver.getSourceKind(sourcePath); |
+ if (sourceKind == SourceKind.PART) { |
continue; |
} |
- librariesToCompile.add(context.computeLibraryElement(source)); |
+ UnitElementResult unitResult = await driver.getUnitElement(sourcePath); |
+ LibraryElement library = unitResult.element.library; |
+ librariesToCompile.add(library); |
} |
var libraries = new HashSet<LibraryElement>(); |
@@ -190,21 +208,27 @@ class ModuleCompiler { |
librariesToCompile.addAll(library.importedLibraries); |
librariesToCompile.addAll(library.exportedLibraries); |
- var tree = context.resolveCompilationUnit(library.source, library); |
- trees.add(tree); |
- errors.addAll(context.computeErrors(library.source)); |
+ var definingResult = await driver.getResult(library.source.fullName); |
+ trees.add(definingResult.unit); |
+ errors.addAll(definingResult.errors); |
+ lineInfoMap[definingResult.path] = definingResult.lineInfo; |
for (var part in library.parts) { |
- trees.add(context.resolveCompilationUnit(part.source, library)); |
- errors.addAll(context.computeErrors(part.source)); |
+ var partResult = await driver.getResult(part.source.fullName); |
+ trees.add(partResult.unit); |
+ errors.addAll(partResult.errors); |
+ lineInfoMap[partResult.path] = partResult.lineInfo; |
} |
} |
- sortErrors(context, errors); |
+ sortErrors(driver.analysisOptions, errors); |
+ |
+ _extensionTypes ??= await ExtensionTypeSet.create(driver); |
var messages = <String>[]; |
- for (var e in errors) { |
- var m = formatError(context, e); |
+ for (AnalysisError e in errors) { |
+ var lineInfo = lineInfoMap[e.source.fullName]; |
+ var m = formatError(driver.analysisOptions, lineInfo, e); |
if (m != null) messages.add(m); |
} |
@@ -212,8 +236,8 @@ class ModuleCompiler { |
errors.any((e) => _isFatalError(e, options))) { |
return new JSModuleFile.invalid(unit.name, messages, options); |
} |
- var codeGenerator = |
- new CodeGenerator(context, summaryData, options, _extensionTypes); |
+ var codeGenerator = await CodeGenerator.create( |
Jennifer Messerly
2017/03/17 18:33:38
I would rather keep async out of CodeGenerator, an
scheglov
2017/04/25 17:07:35
Done.
|
+ driver, summaryData, options, _extensionTypes); |
return codeGenerator.compile(unit, trees, messages); |
} |
} |