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

Side by Side Diff: pkg/front_end/lib/src/kernel_generator_impl.dart

Issue 2979623002: Use messages for (some) public API errors (Closed)
Patch Set: Created 3 years, 5 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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_impl; 6 library front_end.kernel_generator_impl;
7 7
8 import 'dart:async' show Future; 8 import 'dart:async' show Future;
9 import 'dart:async'; 9 import 'dart:async';
10 10
11 import 'package:kernel/kernel.dart' show Program, CanonicalName; 11 import 'package:kernel/kernel.dart' show Program, CanonicalName;
12 12
13 import 'base/processed_options.dart'; 13 import 'base/processed_options.dart';
14 import 'fasta/compiler_command_line.dart';
14 import 'fasta/dill/dill_target.dart' show DillTarget; 15 import 'fasta/dill/dill_target.dart' show DillTarget;
15 import 'fasta/deprecated_problems.dart' show deprecated_InputError, reportCrash; 16 import 'fasta/deprecated_problems.dart' show deprecated_InputError, reportCrash;
16 import 'fasta/kernel/kernel_outline_shaker.dart'; 17 import 'fasta/kernel/kernel_outline_shaker.dart';
17 import 'fasta/kernel/kernel_target.dart' show KernelTarget; 18 import 'fasta/kernel/kernel_target.dart' show KernelTarget;
19 import 'fasta/kernel/utils.dart';
18 import 'fasta/kernel/verifier.dart'; 20 import 'fasta/kernel/verifier.dart';
19 import 'fasta/kernel/utils.dart';
20 import 'fasta/compiler_command_line.dart';
21 import 'fasta/translate_uri.dart' show TranslateUri; 21 import 'fasta/translate_uri.dart' show TranslateUri;
22 22
23 /// Implementation for the `package:front_end/kernel_generator.dart` and 23 /// Implementation for the `package:front_end/kernel_generator.dart` and
24 /// `package:front_end/summary_generator.dart` APIs. 24 /// `package:front_end/summary_generator.dart` APIs.
25 Future<CompilerResult> generateKernel(ProcessedOptions options, 25 Future<CompilerResult> generateKernel(ProcessedOptions options,
26 {bool buildSummary: false, 26 {bool buildSummary: false,
27 bool buildProgram: true, 27 bool buildProgram: true,
28 bool trimDependencies: false}) async { 28 bool trimDependencies: false}) async {
29 // TODO(sigmund): Replace CompilerCommandLine and instead simply use a 29 // TODO(sigmund): Replace CompilerCommandLine and instead simply use a
30 // CompilerContext that directly uses the ProcessedOptions throught the 30 // CompilerContext that directly uses the ProcessedOptions throught the
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // program is destructive, so if we are emitting summaries and the 103 // program is destructive, so if we are emitting summaries and the
104 // program in a single API call, we would need to clone the program here 104 // program in a single API call, we would need to clone the program here
105 // to avoid deleting pieces that are needed by kernelTarget.buildProgram 105 // to avoid deleting pieces that are needed by kernelTarget.buildProgram
106 // below. 106 // below.
107 assert(!buildProgram); 107 assert(!buildProgram);
108 var excluded = 108 var excluded =
109 dillTarget.loader.libraries.map((lib) => lib.importUri).toSet(); 109 dillTarget.loader.libraries.map((lib) => lib.importUri).toSet();
110 trimProgram(summaryProgram, (uri) => !excluded.contains(uri)); 110 trimProgram(summaryProgram, (uri) => !excluded.contains(uri));
111 } 111 }
112 if (options.verify) { 112 if (options.verify) {
113 verifyProgram(summaryProgram).forEach((e) => options.reportError('$e')); 113 verifyProgram(summaryProgram).forEach(options.reportMessage);
114 } 114 }
115 if (options.debugDump) { 115 if (options.debugDump) {
116 printProgramText(summaryProgram, 116 printProgramText(summaryProgram,
117 libraryFilter: kernelTarget.isSourceLibrary); 117 libraryFilter: kernelTarget.isSourceLibrary);
118 } 118 }
119 if (kernelTarget.errors.isEmpty) { 119 if (kernelTarget.errors.isEmpty) {
120 summary = serializeProgram(summaryProgram, excludeUriToSource: true); 120 summary = serializeProgram(summaryProgram, excludeUriToSource: true);
121 } 121 }
122 options.ticker.logMs("Generated outline"); 122 options.ticker.logMs("Generated outline");
123 } 123 }
124 124
125 Program program; 125 Program program;
126 if (buildProgram && kernelTarget.errors.isEmpty) { 126 if (buildProgram && kernelTarget.errors.isEmpty) {
127 program = await kernelTarget.buildProgram(verify: options.verify); 127 program = await kernelTarget.buildProgram(verify: options.verify);
128 if (trimDependencies) { 128 if (trimDependencies) {
129 var excluded = 129 var excluded =
130 dillTarget.loader.libraries.map((lib) => lib.importUri).toSet(); 130 dillTarget.loader.libraries.map((lib) => lib.importUri).toSet();
131 trimProgram(program, (uri) => !excluded.contains(uri)); 131 trimProgram(program, (uri) => !excluded.contains(uri));
132 } 132 }
133 if (options.debugDump) { 133 if (options.debugDump) {
134 printProgramText(program, libraryFilter: kernelTarget.isSourceLibrary); 134 printProgramText(program, libraryFilter: kernelTarget.isSourceLibrary);
135 } 135 }
136 options.ticker.logMs("Generated program"); 136 options.ticker.logMs("Generated program");
137 } 137 }
138 138
139 if (kernelTarget.errors.isNotEmpty) { 139 if (kernelTarget.errors.isNotEmpty) {
140 kernelTarget.errors.forEach(options.reportError); 140 kernelTarget.errors.forEach(options.deprecated_reportError);
141 return null; 141 return null;
142 } 142 }
143 143
144 return new CompilerResult( 144 return new CompilerResult(
145 summary: summary, 145 summary: summary,
146 program: program, 146 program: program,
147 deps: kernelTarget.loader.getDependencies()); 147 deps: kernelTarget.loader.getDependencies());
148 } on deprecated_InputError catch (e) { 148 } on deprecated_InputError catch (e) {
149 options.reportError(e.deprecated_format()); 149 options.deprecated_reportError(e.deprecated_format());
150 return null; 150 return null;
151 } catch (e, t) { 151 } catch (e, t) {
152 return reportCrash(e, t); 152 return reportCrash(e, t);
153 } 153 }
154 } 154 }
155 155
156 /// Result object of [generateKernel]. 156 /// Result object of [generateKernel].
157 class CompilerResult { 157 class CompilerResult {
158 /// The generated summary bytes, if it was requested. 158 /// The generated summary bytes, if it was requested.
159 final List<int> summary; 159 final List<int> summary;
160 160
161 /// The generated program, if it was requested. 161 /// The generated program, if it was requested.
162 final Program program; 162 final Program program;
163 163
164 /// Dependencies traversed by the compiler. Used only for generating 164 /// Dependencies traversed by the compiler. Used only for generating
165 /// dependency .GN files in the dart-sdk build system. 165 /// dependency .GN files in the dart-sdk build system.
166 /// Note this might be removed when we switch to compute depencencies without 166 /// Note this might be removed when we switch to compute depencencies without
167 /// using the compiler itself. 167 /// using the compiler itself.
168 final List<Uri> deps; 168 final List<Uri> deps;
169 169
170 CompilerResult({this.summary, this.program, this.deps}); 170 CompilerResult({this.summary, this.program, this.deps});
171 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698