| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// Defines the front-end API for converting source code to Dart Kernel objects. | 5 /// Defines the front-end API for converting source code to Dart Kernel objects. |
| 6 library front_end.kernel_generator; | 6 library front_end.kernel_generator; |
| 7 | 7 |
| 8 import 'compilation_error.dart'; | 8 import 'compilation_error.dart'; |
| 9 import 'compiler_options.dart'; | 9 import 'compiler_options.dart'; |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 | 11 |
| 12 import 'package:analyzer/src/generated/source.dart' show SourceKind; | 12 import 'package:analyzer/src/generated/source.dart' show SourceKind; |
| 13 import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl; |
| 13 import 'package:analyzer/src/summary/package_bundle_reader.dart' | 14 import 'package:analyzer/src/summary/package_bundle_reader.dart' |
| 14 show InSummarySource; | 15 show InSummarySource; |
| 15 // TODO(sigmund): move loader logic under front_end/lib/src/kernel/ | 16 // TODO(sigmund): move loader logic under front_end/lib/src/kernel/ |
| 16 import 'package:kernel/analyzer/loader.dart'; | 17 import 'package:kernel/analyzer/loader.dart'; |
| 17 import 'package:kernel/kernel.dart'; | 18 import 'package:kernel/kernel.dart'; |
| 18 import 'package:source_span/source_span.dart' show SourceSpan; | 19 import 'package:source_span/source_span.dart' show SourceSpan; |
| 19 | 20 |
| 20 /// Generates a kernel representation of the program whose main library is in | 21 /// Generates a kernel representation of the program whose main library is in |
| 21 /// the given [source]. | 22 /// the given [source]. |
| 22 /// | 23 /// |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 /// If [options] contain no configuration to resolve `.packages`, the [entry] | 138 /// If [options] contain no configuration to resolve `.packages`, the [entry] |
| 138 /// file will be used to search for a `.packages` file. | 139 /// file will be used to search for a `.packages` file. |
| 139 Future<DartLoader> _createLoader(CompilerOptions options, | 140 Future<DartLoader> _createLoader(CompilerOptions options, |
| 140 {Repository repository, Uri entry}) async { | 141 {Repository repository, Uri entry}) async { |
| 141 var kernelOptions = _convertOptions(options); | 142 var kernelOptions = _convertOptions(options); |
| 142 var packages = await createPackages( | 143 var packages = await createPackages( |
| 143 _uriToPath(options.packagesFileUri, options), | 144 _uriToPath(options.packagesFileUri, options), |
| 144 discoveryPath: entry?.path); | 145 discoveryPath: entry?.path); |
| 145 var loader = new DartLoader( | 146 var loader = new DartLoader( |
| 146 repository ?? new Repository(), kernelOptions, packages); | 147 repository ?? new Repository(), kernelOptions, packages); |
| 147 var patchPaths = {}; | 148 var patchPaths = <String, List<String>>{}; |
| 148 | 149 |
| 149 // TODO(sigmund,paulberry): use ProcessedOptions so that we can resolve the | 150 // TODO(sigmund,paulberry): use ProcessedOptions so that we can resolve the |
| 150 // URIs correctly even if sdkRoot is inferred and not specified explicitly. | 151 // URIs correctly even if sdkRoot is inferred and not specified explicitly. |
| 151 String resolve(Uri patch) => | 152 String resolve(Uri patch) => |
| 152 options.fileSystem.context.fromUri(options.sdkRoot.resolveUri(patch)); | 153 options.fileSystem.context.fromUri(options.sdkRoot.resolveUri(patch)); |
| 153 | 154 |
| 154 options.targetPatches.forEach((uri, patches) { | 155 options.targetPatches.forEach((uri, patches) { |
| 155 patchPaths['$uri'] = patches.map(resolve).toList(); | 156 patchPaths['$uri'] = patches.map(resolve).toList(); |
| 156 }); | 157 }); |
| 157 loader.context.analysisOptions.patchPaths = patchPaths; | 158 AnalysisOptionsImpl analysisOptions = loader.context.analysisOptions; |
| 159 analysisOptions.patchPaths = patchPaths; |
| 158 return loader; | 160 return loader; |
| 159 } | 161 } |
| 160 | 162 |
| 161 DartOptions _convertOptions(CompilerOptions options) { | 163 DartOptions _convertOptions(CompilerOptions options) { |
| 162 return new DartOptions( | 164 return new DartOptions( |
| 163 strongMode: options.strongMode, | 165 strongMode: options.strongMode, |
| 164 sdk: _uriToPath(options.sdkRoot, options), | 166 sdk: _uriToPath(options.sdkRoot, options), |
| 165 // TODO(sigmund): make it possible to use summaries and still compile the | 167 // TODO(sigmund): make it possible to use summaries and still compile the |
| 166 // sdk sources. | 168 // sdk sources. |
| 167 sdkSummary: | 169 sdkSummary: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 187 } | 189 } |
| 188 | 190 |
| 189 // TODO(sigmund): delete this class. Dartk should not format errors itself, we | 191 // TODO(sigmund): delete this class. Dartk should not format errors itself, we |
| 190 // should just pass them along. | 192 // should just pass them along. |
| 191 class _DartkError implements CompilationError { | 193 class _DartkError implements CompilationError { |
| 192 String get correction => null; | 194 String get correction => null; |
| 193 SourceSpan get span => null; | 195 SourceSpan get span => null; |
| 194 final String message; | 196 final String message; |
| 195 _DartkError(this.message); | 197 _DartkError(this.message); |
| 196 } | 198 } |
| OLD | NEW |