Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(735)

Side by Side Diff: pkg/front_end/lib/kernel_generator.dart

Issue 2665723002: Implement canonical name scheme in kernel. (Closed)
Patch Set: Remove unintended change in fasta Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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';
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 /// 79 ///
80 /// The return value is a [Program] object with no main method set. 80 /// The return value is a [Program] object with no main method set.
81 /// TODO(paulberry): would it be better to define a data type in kernel to 81 /// TODO(paulberry): would it be better to define a data type in kernel to
82 /// represent a bundle of all the libraries in a given build unit? 82 /// represent a bundle of all the libraries in a given build unit?
83 /// 83 ///
84 /// TODO(paulberry): does additional information need to be output to allow the 84 /// TODO(paulberry): does additional information need to be output to allow the
85 /// caller to match up referenced elements to the summary files they were 85 /// caller to match up referenced elements to the summary files they were
86 /// obtained from? 86 /// obtained from?
87 Future<Program> kernelForBuildUnit( 87 Future<Program> kernelForBuildUnit(
88 List<Uri> sources, CompilerOptions options) async { 88 List<Uri> sources, CompilerOptions options) async {
89 var repository = new Repository(); 89 var program = new Program();
90 var loader = await _createLoader(options, repository: repository); 90 var loader = await _createLoader(options, program: program);
91 var context = loader.context; 91 var context = loader.context;
92 92
93 // Process every library in the build unit. 93 // Process every library in the build unit.
94 for (var uri in sources) { 94 for (var uri in sources) {
95 var source = context.sourceFactory.forUri2(uri); 95 var source = context.sourceFactory.forUri2(uri);
96 // We ignore part files, those are handled by their enclosing library. 96 // We ignore part files, those are handled by their enclosing library.
97 if (context.computeKindOf(source) == SourceKind.PART) { 97 if (context.computeKindOf(source) == SourceKind.PART) {
98 // TODO(sigmund): record it and ensure that this part is within a provided 98 // TODO(sigmund): record it and ensure that this part is within a provided
99 // library. 99 // library.
100 continue; 100 continue;
101 } 101 }
102 loader.loadLibrary(uri); 102 loader.loadLibrary(uri);
103 } 103 }
104 104
105 // Check whether all dependencies were included in [sources]. 105 // Check whether all dependencies were included in [sources].
106 // TODO(sigmund): we should look for dependencies using import, export, and 106 // TODO(sigmund): we should look for dependencies using import, export, and
107 // part directives intead of relying on the dartk-loader. In particular, if a 107 // part directives intead of relying on the dartk-loader. In particular, if a
108 // library is imported but not used, the logic below will not detect it. 108 // library is imported but not used, the logic below will not detect it.
109 for (int i = 0; i < repository.libraries.length; ++i) { 109 for (int i = 0; i < program.libraries.length; ++i) {
110 // Note: we don't use a for-in loop because repository.libraries grows as 110 // Note: we don't use a for-in loop because program.libraries grows as
111 // the loader processes libraries. 111 // the loader processes libraries.
112 var lib = repository.libraries[i]; 112 var lib = program.libraries[i];
113 var source = context.sourceFactory.forUri2(lib.importUri); 113 var source = context.sourceFactory.forUri2(lib.importUri);
114 if (source is InSummarySource) continue; 114 if (source is InSummarySource) continue;
115 if (options.chaseDependencies) { 115 if (options.chaseDependencies) {
116 loader.ensureLibraryIsLoaded(lib); 116 loader.ensureLibraryIsLoaded(lib);
117 } else if (lib.isExternal) { 117 } else if (lib.isExternal) {
118 // Default behavior: the build should be hermetic and all dependencies 118 // Default behavior: the build should be hermetic and all dependencies
119 // should be listed. 119 // should be listed.
120 options.onError(new _DartkError('hermetic build error: ' 120 options.onError(new _DartkError('hermetic build error: '
121 'no source or summary was given for ${lib.importUri}')); 121 'no source or summary was given for ${lib.importUri}'));
122 } 122 }
123 } 123 }
124 124
125 Program program = new Program(repository.libraries);
126 _reportErrors(loader.errors, options.onError); 125 _reportErrors(loader.errors, options.onError);
127 return program; 126 return program;
128 } 127 }
129 128
130 /// Create a [DartLoader] using the provided [options]. 129 /// Create a [DartLoader] using the provided [options].
131 /// 130 ///
132 /// If [options] contain no configuration to resolve `.packages`, the [entry] 131 /// If [options] contain no configuration to resolve `.packages`, the [entry]
133 /// file will be used to search for a `.packages` file. 132 /// file will be used to search for a `.packages` file.
134 Future<DartLoader> _createLoader(CompilerOptions options, 133 Future<DartLoader> _createLoader(CompilerOptions options,
135 {Repository repository, Uri entry}) async { 134 {Program program, Uri entry}) async {
136 var kernelOptions = _convertOptions(options); 135 var kernelOptions = _convertOptions(options);
137 var packages = await createPackages( 136 var packages = await createPackages(
138 _uriToPath(options.packagesFileUri, options), 137 _uriToPath(options.packagesFileUri, options),
139 discoveryPath: entry?.path); 138 discoveryPath: entry?.path);
140 var loader = new DartLoader( 139 var loader =
141 repository ?? new Repository(), kernelOptions, packages); 140 new DartLoader(program ?? new Program(), kernelOptions, packages);
142 var patchPaths = <String, List<String>>{}; 141 var patchPaths = <String, List<String>>{};
143 142
144 // TODO(sigmund,paulberry): use ProcessedOptions so that we can resolve the 143 // TODO(sigmund,paulberry): use ProcessedOptions so that we can resolve the
145 // URIs correctly even if sdkRoot is inferred and not specified explicitly. 144 // URIs correctly even if sdkRoot is inferred and not specified explicitly.
146 String resolve(Uri patch) => 145 String resolve(Uri patch) =>
147 options.fileSystem.context.fromUri(options.sdkRoot.resolveUri(patch)); 146 options.fileSystem.context.fromUri(options.sdkRoot.resolveUri(patch));
148 147
149 options.targetPatches.forEach((uri, patches) { 148 options.targetPatches.forEach((uri, patches) {
150 patchPaths['$uri'] = patches.map(resolve).toList(); 149 patchPaths['$uri'] = patches.map(resolve).toList();
151 }); 150 });
152 AnalysisOptionsImpl analysisOptions = loader.context.analysisOptions; 151 AnalysisOptionsImpl analysisOptions = loader.context.analysisOptions;
153 analysisOptions.patchPaths = patchPaths; 152 analysisOptions.patchPaths = patchPaths;
154 return loader; 153 return loader;
155 } 154 }
156 155
157 DartOptions _convertOptions(CompilerOptions options) { 156 DartOptions _convertOptions(CompilerOptions options) {
(...skipping 25 matching lines...) Expand all
183 } 182 }
184 183
185 // TODO(sigmund): delete this class. Dartk should not format errors itself, we 184 // TODO(sigmund): delete this class. Dartk should not format errors itself, we
186 // should just pass them along. 185 // should just pass them along.
187 class _DartkError implements CompilationError { 186 class _DartkError implements CompilationError {
188 String get correction => null; 187 String get correction => null;
189 SourceSpan get span => null; 188 SourceSpan get span => null;
190 final String message; 189 final String message;
191 _DartkError(this.message); 190 _DartkError(this.message);
192 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698