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

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

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

Powered by Google App Engine
This is Rietveld 408576698