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

Unified Diff: pkg/front_end/lib/src/fasta/kernel/utils.dart

Issue 2953703002: Tweak public APIs and use them in patch_sdk, dart2js, and kernel-service (Closed)
Patch Set: cl review updates: cleanup in kernel deserialization 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/front_end/lib/src/fasta/kernel/kernel_target.dart ('k') | pkg/front_end/lib/src/fasta/loader.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/kernel/utils.dart
diff --git a/pkg/front_end/lib/src/fasta/kernel/utils.dart b/pkg/front_end/lib/src/fasta/kernel/utils.dart
index df9748ba387553c27d01cb8690ec00f48eefa775..f77b16dd9d11fd3388a66c7f431f6c0c2d40ca24 100644
--- a/pkg/front_end/lib/src/fasta/kernel/utils.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/utils.dart
@@ -8,6 +8,7 @@ import 'dart:io';
import 'package:front_end/src/scanner/token.dart' show Token;
import 'package:kernel/ast.dart';
import 'package:kernel/binary/ast_to_binary.dart';
+import 'package:kernel/binary/limited_ast_to_binary.dart';
import 'package:kernel/text/ast_to_text.dart';
/// A null-aware alternative to `token.offset`. If [token] is `null`, returns
@@ -39,3 +40,26 @@ Future<Null> writeProgramToFile(Program program, Uri uri) async {
await sink.close();
}
}
+
+/// Serialize the libraries in [program] that match [filter].
+List<int> serializeProgram(Program program,
+ {bool filter(Library library), bool excludeUriToSource: false}) {
+ ByteSink byteSink = new ByteSink();
+ BinaryPrinter printer = filter == null && !excludeUriToSource
+ ? new BinaryPrinter(byteSink)
+ : new LimitedBinaryPrinter(
+ byteSink, filter ?? (_) => true, excludeUriToSource);
+ printer.writeProgramFile(program);
+ return byteSink.builder.takeBytes();
+}
+
+/// A [Sink] that directly writes data into a byte builder.
+class ByteSink implements Sink<List<int>> {
+ final BytesBuilder builder = new BytesBuilder();
+
+ void add(List<int> data) {
+ builder.add(data);
+ }
+
+ void close() {}
+}
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/kernel_target.dart ('k') | pkg/front_end/lib/src/fasta/loader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698