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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/kernel/front_end_adapter.dart
diff --git a/pkg/compiler/lib/src/kernel/front_end_adapter.dart b/pkg/compiler/lib/src/kernel/front_end_adapter.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b2bc3ee390243e11ac71946cb9812ec583e25ceb
--- /dev/null
+++ b/pkg/compiler/lib/src/kernel/front_end_adapter.dart
@@ -0,0 +1,100 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// Helper classes and methods to adapt between `package:compiler` and
+/// `package:front_end` APIs.
+library compiler.kernel.front_end_adapter;
+
+import 'dart:async';
+
+import 'package:front_end/front_end.dart' as fe;
+
+import '../../compiler_new.dart' as api;
+
+import '../common.dart';
+import '../io/source_file.dart';
+
+/// A front-ends's [FileSystem] that uses dart2js's [api.CompilerInput].
+class CompilerFileSystem implements fe.FileSystem {
+ final api.CompilerInput inputProvider;
+
+ CompilerFileSystem(this.inputProvider);
+
+ @override
+ fe.FileSystemEntity entityForUri(Uri uri) =>
+ new _CompilerFileSystemEntity(uri, this);
+}
+
+class _CompilerFileSystemEntity implements fe.FileSystemEntity {
+ final Uri uri;
+ final CompilerFileSystem fs;
+
+ _CompilerFileSystemEntity(this.uri, this.fs);
+
+ @override
+ Future<String> readAsString() async {
+ api.Input input;
+ try {
+ input = await fs.inputProvider
+ .readFromUri(uri, inputKind: api.InputKind.utf8);
+ } catch (e) {
+ throw new fe.FileSystemException(uri, '$e');
+ }
+ if (input == null) throw new fe.FileSystemException(uri, "File not found");
+ // TODO(sigmund): technically someone could provide dart2js with an input
+ // that is not a SourceFile. Note that this assumption is also done in the
+ // (non-kernel) ScriptLoader.
+ SourceFile file = input as SourceFile;
+ return file.slowText();
+ }
+
+ @override
+ Future<List<int>> readAsBytes() async {
+ api.Input input;
+ try {
+ input = await fs.inputProvider
+ .readFromUri(uri, inputKind: api.InputKind.binary);
+ } catch (e) {
+ throw new fe.FileSystemException(uri, '$e');
+ }
+ if (input == null) throw new fe.FileSystemException(uri, "File not found");
+ return input.data;
+ }
+
+ @override
+ Future<bool> exists() async {
+ try {
+ api.Input input = await fs.inputProvider
+ .readFromUri(uri, inputKind: api.InputKind.binary);
+ return input != null;
+ } catch (e) {
+ return false;
+ }
+ }
+}
+
+/// Report a [message] received from the front-end, using dart2js's
+/// [DiagnosticReporter].
+void reportFrontEndMessage(
+ DiagnosticReporter reporter, fe.CompilationMessage message) {
+ // TODO(sigmund): translate message kinds using message.dart2jsCode
+ MessageKind kind = MessageKind.GENERIC;
+ switch (message.severity) {
+ case fe.Severity.error:
+ 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
+ reporter.reportErrorMessage(
+ NO_LOCATION_SPANNABLE, kind, {'text': message.message});
+ break;
+ case fe.Severity.warning:
+ reporter.reportWarningMessage(
+ NO_LOCATION_SPANNABLE, kind, {'text': message.message});
+ break;
+ case fe.Severity.nit:
+ reporter.reportHintMessage(
+ NO_LOCATION_SPANNABLE, kind, {'text': message.message});
+ break;
+ default:
+ throw new UnimplementedError('unhandled severity ${message.severity}');
+ }
+}
« 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