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

Side by Side Diff: pkg/compiler/lib/src/kernel/front_end_adapter.dart

Issue 2989453002: Add support for compiling Dart via the FE in dart2js. (Closed)
Patch Set: update status 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Helper classes and methods to adapt between `package:compiler` and
6 /// `package:front_end` APIs.
7 library compiler.kernel.front_end_adapter;
8
9 import 'dart:async';
10
11 import 'package:front_end/front_end.dart' as fe;
12
13 import '../../compiler_new.dart' as api;
14
15 import '../common.dart';
16 import '../io/source_file.dart';
17
18 /// A front-ends's [FileSystem] that uses dart2js's [api.CompilerInput].
19 class CompilerFileSystem implements fe.FileSystem {
20 final api.CompilerInput inputProvider;
21
22 CompilerFileSystem(this.inputProvider);
23
24 @override
25 fe.FileSystemEntity entityForUri(Uri uri) =>
26 new _CompilerFileSystemEntity(uri, this);
27 }
28
29 class _CompilerFileSystemEntity implements fe.FileSystemEntity {
30 final Uri uri;
31 final CompilerFileSystem fs;
32
33 _CompilerFileSystemEntity(this.uri, this.fs);
34
35 @override
36 Future<String> readAsString() async {
37 api.Input input;
38 try {
39 input = await fs.inputProvider
40 .readFromUri(uri, inputKind: api.InputKind.utf8);
41 } catch (e) {
42 throw new fe.FileSystemException(uri, '$e');
43 }
44 if (input == null) throw new fe.FileSystemException(uri, "File not found");
45 // TODO(sigmund): technically someone could provide dart2js with an input
46 // that is not a SourceFile. Note that this assumption is also done in the
47 // (non-kernel) ScriptLoader.
48 SourceFile file = input as SourceFile;
49 return file.slowText();
50 }
51
52 @override
53 Future<List<int>> readAsBytes() async {
54 api.Input input;
55 try {
56 input = await fs.inputProvider
57 .readFromUri(uri, inputKind: api.InputKind.binary);
58 } catch (e) {
59 throw new fe.FileSystemException(uri, '$e');
60 }
61 if (input == null) throw new fe.FileSystemException(uri, "File not found");
62 return input.data;
63 }
64
65 @override
66 Future<bool> exists() async {
67 try {
68 api.Input input = await fs.inputProvider
69 .readFromUri(uri, inputKind: api.InputKind.binary);
70 return input != null;
71 } catch (e) {
72 return false;
73 }
74 }
75 }
76
77 /// Report a [message] received from the front-end, using dart2js's
78 /// [DiagnosticReporter].
79 void reportFrontEndMessage(
80 DiagnosticReporter reporter, fe.CompilationMessage message) {
81 // TODO(sigmund): translate message kinds using message.dart2jsCode
82 MessageKind kind = MessageKind.GENERIC;
83 switch (message.severity) {
84 case fe.Severity.error:
85 case fe.Severity.internalProblem:
Johnni Winther 2017/07/28 12:26:42 I think `internalProblem` should map to a crash (w
Siggi Cherem (dart-lang) 2017/07/28 19:15:51 good point, I guess I can make it throw here, I'll
86 reporter.reportErrorMessage(
87 NO_LOCATION_SPANNABLE, kind, {'text': message.message});
88 break;
89 case fe.Severity.warning:
90 reporter.reportWarningMessage(
91 NO_LOCATION_SPANNABLE, kind, {'text': message.message});
92 break;
93 case fe.Severity.nit:
94 reporter.reportHintMessage(
95 NO_LOCATION_SPANNABLE, kind, {'text': message.message});
96 break;
97 default:
98 throw new UnimplementedError('unhandled severity ${message.severity}');
99 }
100 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/dart2js_target.dart ('k') | pkg/compiler/lib/src/kernel/kernel_strategy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698