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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 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 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:io'; 6 import 'dart:io';
7 7
8 import 'package:front_end/src/scanner/token.dart' show Token; 8 import 'package:front_end/src/scanner/token.dart' show Token;
9 import 'package:kernel/ast.dart'; 9 import 'package:kernel/ast.dart';
10 import 'package:kernel/binary/ast_to_binary.dart'; 10 import 'package:kernel/binary/ast_to_binary.dart';
11 import 'package:kernel/binary/limited_ast_to_binary.dart';
11 import 'package:kernel/text/ast_to_text.dart'; 12 import 'package:kernel/text/ast_to_text.dart';
12 13
13 /// A null-aware alternative to `token.offset`. If [token] is `null`, returns 14 /// A null-aware alternative to `token.offset`. If [token] is `null`, returns
14 /// `TreeNode.noOffset`. 15 /// `TreeNode.noOffset`.
15 int offsetForToken(Token token) => 16 int offsetForToken(Token token) =>
16 token == null ? TreeNode.noOffset : token.offset; 17 token == null ? TreeNode.noOffset : token.offset;
17 18
18 /// Print the given [program]. Do nothing if it is `null`. If the 19 /// Print the given [program]. Do nothing if it is `null`. If the
19 /// [libraryFilter] is provided, then only libraries that satisfy it are 20 /// [libraryFilter] is provided, then only libraries that satisfy it are
20 /// printed. 21 /// printed.
(...skipping 11 matching lines...) Expand all
32 Future<Null> writeProgramToFile(Program program, Uri uri) async { 33 Future<Null> writeProgramToFile(Program program, Uri uri) async {
33 File output = new File.fromUri(uri); 34 File output = new File.fromUri(uri);
34 IOSink sink = output.openWrite(); 35 IOSink sink = output.openWrite();
35 try { 36 try {
36 new BinaryPrinter(sink).writeProgramFile(program); 37 new BinaryPrinter(sink).writeProgramFile(program);
37 program.unbindCanonicalNames(); 38 program.unbindCanonicalNames();
38 } finally { 39 } finally {
39 await sink.close(); 40 await sink.close();
40 } 41 }
41 } 42 }
43
44 /// Serialize the libraries in [program] that match [filter].
45 List<int> serializeProgram(Program program,
46 {bool filter(Library library), bool excludeUriToSource: false}) {
47 ByteSink byteSink = new ByteSink();
48 BinaryPrinter printer = filter == null && !excludeUriToSource
49 ? new BinaryPrinter(byteSink)
50 : new LimitedBinaryPrinter(
51 byteSink, filter ?? (_) => true, excludeUriToSource);
52 printer.writeProgramFile(program);
53 return byteSink.builder.takeBytes();
54 }
55
56 /// A [Sink] that directly writes data into a byte builder.
57 class ByteSink implements Sink<List<int>> {
58 final BytesBuilder builder = new BytesBuilder();
59
60 void add(List<int> data) {
61 builder.add(data);
62 }
63
64 void close() {}
65 }
OLDNEW
« 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