Chromium Code Reviews| OLD | NEW |
|---|---|
| 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'; | |
| 6 import 'dart:io'; | |
| 7 | |
| 8 import 'package:front_end/src/fasta/ticker.dart'; | |
| 5 import 'package:front_end/src/scanner/token.dart' show Token; | 9 import 'package:front_end/src/scanner/token.dart' show Token; |
| 6 import 'package:kernel/ast.dart'; | 10 import 'package:kernel/ast.dart'; |
| 11 import 'package:kernel/binary/ast_to_binary.dart'; | |
| 7 import 'package:kernel/text/ast_to_text.dart'; | 12 import 'package:kernel/text/ast_to_text.dart'; |
| 8 | 13 |
| 9 /// 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 |
| 10 /// `TreeNode.noOffset`. | 15 /// `TreeNode.noOffset`. |
| 11 int offsetForToken(Token token) => | 16 int offsetForToken(Token token) => |
| 12 token == null ? TreeNode.noOffset : token.offset; | 17 token == null ? TreeNode.noOffset : token.offset; |
| 13 | 18 |
| 14 /// Print the given [program]. Do nothing if it is `null`. | 19 /// Print the given [program]. Do nothing if it is `null`. |
| 15 void printProgramText(Program program) { | 20 void printProgramText(Program program) { |
| 16 if (program == null) return; | 21 if (program == null) return; |
| 17 StringBuffer sb = new StringBuffer(); | 22 StringBuffer sb = new StringBuffer(); |
| 18 for (Library library in program.libraries) { | 23 for (Library library in program.libraries) { |
| 19 Printer printer = new Printer(sb); | 24 Printer printer = new Printer(sb); |
| 20 printer.writeLibraryFile(library); | 25 printer.writeLibraryFile(library); |
| 21 } | 26 } |
| 22 print(sb); | 27 print(sb); |
| 23 } | 28 } |
| 29 | |
| 30 Future<Program> writeProgramToFileUri(Ticker ticker, Uri uri, Program program, | |
|
Siggi Cherem (dart-lang)
2017/05/17 22:01:35
a couple minor suggestions:
- rename to writeProg
scheglov
2017/05/17 22:16:04
Good suggestions.
Done.
| |
| 31 {bool isFullProgram}) async { | |
| 32 File output = new File.fromUri(uri); | |
| 33 IOSink sink = output.openWrite(); | |
| 34 try { | |
| 35 new BinaryPrinter(sink).writeProgramFile(program); | |
| 36 program.unbindCanonicalNames(); | |
| 37 } finally { | |
| 38 await sink.close(); | |
| 39 } | |
| 40 if (isFullProgram) { | |
| 41 ticker.logMs("Wrote program to ${uri.toFilePath()}"); | |
| 42 } else { | |
| 43 ticker.logMs("Wrote outline to ${uri.toFilePath()}"); | |
| 44 } | |
| 45 return null; | |
| 46 } | |
| OLD | NEW |