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

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

Issue 2740343002: Increase coverage of crash reporting. (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library fasta; 5 library fasta;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'dart:convert' show JSON; 9 import 'dart:convert' show JSON;
10 10
11 import 'dart:io' show BytesBuilder, FileSystemEntity, exitCode; 11 import 'dart:io' show BytesBuilder, Directory, File, exitCode;
12 12
13 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; 13 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
14 14
15 import 'package:kernel/kernel.dart' show Program; 15 import 'package:kernel/kernel.dart' show Program;
16 16
17 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget; 17 import 'package:kernel/target/targets.dart' show Target, TargetFlags, getTarget;
18 18
19 import 'kernel/verifier.dart' show verifyProgram; 19 import 'kernel/verifier.dart' show verifyProgram;
20 20
21 import 'compiler_command_line.dart' show CompilerCommandLine; 21 import 'compiler_command_line.dart' show CompilerCommandLine;
22 22
23 import 'compiler_context.dart' show CompilerContext; 23 import 'compiler_context.dart' show CompilerContext;
24 24
25 import 'errors.dart' show InputError, inputError; 25 import 'errors.dart' show InputError, formatUnexpected, inputError, reportCrash;
26 26
27 import 'kernel/kernel_target.dart' show KernelTarget; 27 import 'kernel/kernel_target.dart' show KernelTarget;
28 28
29 import 'dill/dill_target.dart' show DillTarget; 29 import 'dill/dill_target.dart' show DillTarget;
30 30
31 import 'ticker.dart' show Ticker; 31 import 'ticker.dart' show Ticker;
32 32
33 import 'translate_uri.dart' show TranslateUri; 33 import 'translate_uri.dart' show TranslateUri;
34 34
35 import 'vm.dart' show CompilationResult; 35 import 'vm.dart' show CompilationResult;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 print(s); 159 print(s);
160 } 160 }
161 } 161 }
162 } 162 }
163 return uri; 163 return uri;
164 } 164 }
165 } 165 }
166 166
167 Future<CompilationResult> parseScript( 167 Future<CompilationResult> parseScript(
168 Uri fileName, Uri packages, Uri patchedSdk, bool verbose) async { 168 Uri fileName, Uri packages, Uri patchedSdk, bool verbose) async {
169 if (!FileSystemEntity.isFileSync(fileName.toFilePath())) { 169 try {
170 throw "Input file '${fileName.toFilePath()}' does not exist."; 170 if (!await new File.fromUri(fileName).exists()) {
171 return new CompilationResult.error(
172 formatUnexpected(fileName, -1, "No such file."));
173 }
174 if (!await new Directory.fromUri(patchedSdk).exists()) {
175 return new CompilationResult.error(
176 formatUnexpected(patchedSdk, -1, "Patched sdk directory not found."));
177 }
178
179 Target target = getTarget("vm", new TargetFlags(strongMode: false));
180
181 Program program;
182 final uriTranslator = await TranslateUri.parse(null, packages);
183 final Ticker ticker = new Ticker(isVerbose: verbose);
184 final DillTarget dillTarget = new DillTarget(ticker, uriTranslator);
185 dillTarget.read(patchedSdk.resolve('platform.dill'));
186 final KernelTarget kernelTarget =
187 new KernelTarget(dillTarget, uriTranslator);
188 try {
189 kernelTarget.read(fileName);
190 await dillTarget.writeOutline(null);
191 program = await kernelTarget.writeOutline(null);
192 program = await kernelTarget.writeProgram(null);
193 if (kernelTarget.errors.isNotEmpty) {
194 return new CompilationResult.errors(kernelTarget.errors
195 .map((err) => err.toString())
196 .toList(growable: false));
197 }
198 } on InputError catch (e) {
199 return new CompilationResult.error(e.format());
200 }
201
202 // Perform target-specific transformations.
203 target.performModularTransformations(program);
204 target.performGlobalTransformations(program);
205
206 // Write the program to a list of bytes and return it.
207 var sink = new ByteSink();
208 new BinaryPrinter(sink).writeProgramFile(program);
209 return new CompilationResult.ok(sink.builder.takeBytes());
210 } catch (e, s) {
211 return reportCrash(e, s, fileName);
171 } 212 }
172
173 if (!FileSystemEntity.isDirectorySync(patchedSdk.toFilePath())) {
174 throw "Patched sdk directory not found at ${patchedSdk.toFilePath()}";
175 }
176
177 Target target = getTarget("vm", new TargetFlags(strongMode: false));
178
179 Program program;
180 final uriTranslator = await TranslateUri.parse(null, packages);
181 final Ticker ticker = new Ticker(isVerbose: verbose);
182 final DillTarget dillTarget = new DillTarget(ticker, uriTranslator);
183 dillTarget.read(patchedSdk.resolve('platform.dill'));
184 final KernelTarget kernelTarget = new KernelTarget(dillTarget, uriTranslator);
185 try {
186 kernelTarget.read(fileName);
187 await dillTarget.writeOutline(null);
188 program = await kernelTarget.writeOutline(null);
189 program = await kernelTarget.writeProgram(null);
190 if (kernelTarget.errors.isNotEmpty) {
191 return new CompilationResult.errors(kernelTarget.errors
192 .map((err) => err.toString())
193 .toList(growable: false));
194 }
195 } on InputError catch (e) {
196 return new CompilationResult.error(e.format());
197 }
198
199 // Perform target-specific transformations.
200 target.performModularTransformations(program);
201 target.performGlobalTransformations(program);
202
203 // Write the program to a list of bytes and return it.
204 var sink = new ByteSink();
205 new BinaryPrinter(sink).writeProgramFile(program);
206 return new CompilationResult.ok(sink.builder.takeBytes());
207 } 213 }
208 214
209 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28316 215 // TODO(ahe): https://github.com/dart-lang/sdk/issues/28316
210 class ByteSink implements Sink<List<int>> { 216 class ByteSink implements Sink<List<int>> {
211 final BytesBuilder builder = new BytesBuilder(); 217 final BytesBuilder builder = new BytesBuilder();
212 218
213 void add(List<int> data) { 219 void add(List<int> data) {
214 builder.add(data); 220 builder.add(data);
215 } 221 }
216 222
217 void close() { 223 void close() {
218 // Nothing to do. 224 // Nothing to do.
219 } 225 }
220 } 226 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698