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

Unified Diff: pkg/fasta/lib/src/outline.dart

Issue 2634453004: Fasta infrastructure. (Closed)
Patch Set: Created 3 years, 11 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
Index: pkg/fasta/lib/src/outline.dart
diff --git a/pkg/fasta/lib/src/outline.dart b/pkg/fasta/lib/src/outline.dart
new file mode 100644
index 0000000000000000000000000000000000000000..79ffa2f31b2379803534184f3dfc5b33220c07f5
--- /dev/null
+++ b/pkg/fasta/lib/src/outline.dart
@@ -0,0 +1,128 @@
+// Copyright (c) 2016, 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.
+
+library fasta.outline;
+
+import 'dart:async' show
+ Future;
+
+import 'dart:io' show
+ exitCode;
+
+import 'package:kernel/verifier.dart' show
+ verifyProgram;
+
+import 'compiler_command_line.dart' show
+ CompilerCommandLine;
+
+import 'errors.dart' show
+ InputError,
+ inputError;
+
+import 'kernel/kernel_target.dart' show
+ KernelSourceTarget;
+
+import 'dill/dill_target.dart' show
+ DillTarget;
+
+import 'ticker.dart' show
+ Ticker;
+
+import 'translate_uri.dart' show
+ TranslateUri;
+
+import 'ast_kind.dart' show
+ AstKind;
+
+CompilerCommandLine parseArguments(String programName, List<String> arguments) {
+ return new CompilerCommandLine(programName, arguments);
+}
+
+Future<KernelSourceTarget> outline(List<String> arguments) async {
+ try {
+ CompilerCommandLine cl = parseArguments("outline", arguments);
+ if (cl.verbose) print("Building outlines for ${arguments.join(' ')}");
+ return await doOutline(cl, new Ticker(isVerbose:cl.verbose), cl.output);
Johnni Winther 2017/01/16 09:47:46 `isVerbose:cl.verbose` -> `isVerbose: cl.verbose`
ahe 2017/01/16 12:07:04 Done.
+ } on InputError catch (e) {
+ exitCode = 1;
+ print(e.format());
+ return null;
+ }
+}
+
+Future<Uri> compile(List<String> arguments) async {
+ try {
+ CompilerCommandLine cl = parseArguments("compile", arguments);
+ if (cl.verbose) {
+ print("Compiling directly to Kernel: ${arguments.join(' ')}");
+ }
+ return
+ await doCompile(cl, new Ticker(isVerbose:cl.verbose), AstKind.Kernel);
+ } on InputError catch (e) {
+ exitCode = 1;
+ print(e.format());
+ return null;
+ }
+}
+
+Future<Uri> kompile(List<String> arguments) async {
+ try {
+ CompilerCommandLine cl = parseArguments("kompile", arguments);
+ if (cl.verbose) print("Compiling via analyzer: ${arguments.join(' ')}");
+ return
+ await doCompile(cl, new Ticker(isVerbose:cl.verbose), AstKind.Analyzer);
+ } on InputError catch (e) {
+ exitCode = 1;
+ print(e.format());
+ return null;
+ }
+}
+
+Future<KernelSourceTarget> doOutline(CompilerCommandLine cl, Ticker ticker,
+ [Uri output]) async {
+ TranslateUri uriTranslator = await TranslateUri.parse();
+ ticker.logMs("Read packages file");
+ DillTarget dillTarget = new DillTarget(ticker, uriTranslator);
+ KernelSourceTarget sourceTarget =
+ new KernelSourceTarget(dillTarget, uriTranslator);
+ dillTarget.read(cl.platform);
+ String argument = cl.arguments.first;
+ Uri uri = Uri.base.resolve(argument);
+ String path = uriTranslator.translate(uri)?.path ?? argument;
+ if (path.endsWith(".dart")) {
+ sourceTarget.read(uri);
+ } else {
+ inputError(uri, -1, "Unexpected input: $uri");
+ }
+ await dillTarget.writeOutline(null);
+ await sourceTarget.writeOutline(output);
+ if (cl.dumpIr && output != null) {
+ sourceTarget.dumpIr();
+ }
+ return sourceTarget;
+}
+
+Future<Uri> doCompile(CompilerCommandLine cl, Ticker ticker,
+ AstKind kind) async {
+ KernelSourceTarget sourceTarget = await doOutline(cl, ticker);
+ if (exitCode != 0) return null;
+ Uri uri = cl.output;
+ await sourceTarget.writeProgram(uri, kind);
+ if (cl.dumpIr) {
+ sourceTarget.dumpIr();
+ }
+ if (cl.verify) {
+ try {
+ verifyProgram(sourceTarget.program);
+ ticker.logMs("Verified program");
+ } catch (e, s) {
+ exitCode = 1;
+ print("Verification of program failed: $e");
+ if (s != null && cl.verbose) {
+ print(s);
+ }
+ }
+ }
+ return uri;
+}

Powered by Google App Engine
This is Rietveld 408576698