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

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

Issue 2893233003: Let printProgramText() to use filter to print only some libraries. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/kernel_target.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/text/ast_to_text.dart'; 11 import 'package:kernel/text/ast_to_text.dart';
12 12
13 /// A null-aware alternative to `token.offset`. If [token] is `null`, returns 13 /// A null-aware alternative to `token.offset`. If [token] is `null`, returns
14 /// `TreeNode.noOffset`. 14 /// `TreeNode.noOffset`.
15 int offsetForToken(Token token) => 15 int offsetForToken(Token token) =>
16 token == null ? TreeNode.noOffset : token.offset; 16 token == null ? TreeNode.noOffset : token.offset;
17 17
18 /// Print the given [program]. Do nothing if it is `null`. 18 /// Print the given [program]. Do nothing if it is `null`. If the
19 void printProgramText(Program program) { 19 /// [libraryFilter] is provided, then only libraries that satisfy it are
20 /// printed.
21 void printProgramText(Program program, {bool libraryFilter(Library library)}) {
20 if (program == null) return; 22 if (program == null) return;
21 StringBuffer sb = new StringBuffer(); 23 StringBuffer sb = new StringBuffer();
22 for (Library library in program.libraries) { 24 for (Library library in program.libraries) {
25 if (libraryFilter != null && !libraryFilter(library)) continue;
23 Printer printer = new Printer(sb); 26 Printer printer = new Printer(sb);
24 printer.writeLibraryFile(library); 27 printer.writeLibraryFile(library);
25 } 28 }
26 print(sb); 29 print(sb);
27 } 30 }
28 31
29 Future<Null> writeProgramToFile(Program program, Uri uri) async { 32 Future<Null> writeProgramToFile(Program program, Uri uri) async {
30 File output = new File.fromUri(uri); 33 File output = new File.fromUri(uri);
31 IOSink sink = output.openWrite(); 34 IOSink sink = output.openWrite();
32 try { 35 try {
33 new BinaryPrinter(sink).writeProgramFile(program); 36 new BinaryPrinter(sink).writeProgramFile(program);
34 program.unbindCanonicalNames(); 37 program.unbindCanonicalNames();
35 } finally { 38 } finally {
36 await sink.close(); 39 await sink.close();
37 } 40 }
38 } 41 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/kernel_target.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698