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

Side by Side Diff: pkg/kernel/lib/kernel.dart

Issue 2872903005: Rework DillLoader to allow adding multiple dills. (Closed)
Patch Set: Fixes for review changes. 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /// Conventions for paths: 5 /// Conventions for paths:
6 /// 6 ///
7 /// - Use the [Uri] class for paths that may have the `file`, `dart` or 7 /// - Use the [Uri] class for paths that may have the `file`, `dart` or
8 /// `package` scheme. Never use [Uri] for relative paths. 8 /// `package` scheme. Never use [Uri] for relative paths.
9 /// - Use [String]s for all filenames and paths that have no scheme prefix. 9 /// - Use [String]s for all filenames and paths that have no scheme prefix.
10 /// - Never translate a `dart:` or `package:` URI into a `file:` URI, instead 10 /// - Never translate a `dart:` or `package:` URI into a `file:` URI, instead
11 /// translate it to a [String] if the file system path is needed. 11 /// translate it to a [String] if the file system path is needed.
12 /// - Only use [File] from dart:io at the last moment when it is needed. 12 /// - Only use [File] from dart:io at the last moment when it is needed.
13 /// 13 ///
14 library kernel; 14 library kernel;
15 15
16 import 'ast.dart'; 16 import 'ast.dart';
17 import 'binary/ast_to_binary.dart'; 17 import 'binary/ast_to_binary.dart';
18 import 'binary/ast_from_binary.dart'; 18 import 'binary/ast_from_binary.dart';
19 import 'dart:async'; 19 import 'dart:async';
20 import 'dart:io'; 20 import 'dart:io';
21 import 'text/ast_to_text.dart'; 21 import 'text/ast_to_text.dart';
22 22
23 export 'ast.dart'; 23 export 'ast.dart';
24 24
25 Program loadProgramFromBinary(String path, [Program program]) { 25 Program loadProgramFromBinary(String path, [Program program]) {
26 List<int> bytes = new File(path).readAsBytesSync();
27 return loadProgramFromBytes(bytes, program);
28 }
29
30 Program loadProgramFromBytes(List<int> bytes, [Program program]) {
26 program ??= new Program(); 31 program ??= new Program();
27 new BinaryBuilder(new File(path).readAsBytesSync()).readProgram(program); 32 new BinaryBuilder(bytes).readProgram(program);
28 return program; 33 return program;
29 } 34 }
30 35
31 Future writeProgramToBinary(Program program, String path) { 36 Future writeProgramToBinary(Program program, String path) {
32 var sink; 37 var sink;
33 if (path == 'null' || path == 'stdout') { 38 if (path == 'null' || path == 'stdout') {
34 sink = stdout.nonBlocking; 39 sink = stdout.nonBlocking;
35 } else { 40 } else {
36 sink = new File(path).openWrite(); 41 sink = new File(path).openWrite();
37 } 42 }
(...skipping 26 matching lines...) Expand all
64 {String path, bool showExternal: false, bool showOffsets: false}) { 69 {String path, bool showExternal: false, bool showOffsets: false}) {
65 StringBuffer buffer = new StringBuffer(); 70 StringBuffer buffer = new StringBuffer();
66 new Printer(buffer, showExternal: showExternal, showOffsets: showOffsets) 71 new Printer(buffer, showExternal: showExternal, showOffsets: showOffsets)
67 .writeProgramFile(program); 72 .writeProgramFile(program);
68 if (path == null) { 73 if (path == null) {
69 print(buffer); 74 print(buffer);
70 } else { 75 } else {
71 new File(path).writeAsStringSync('$buffer'); 76 new File(path).writeAsStringSync('$buffer');
72 } 77 }
73 } 78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698