4d3d70af23
Kernel sdk version was bumped from 3.6 to 3.12 in https://dart-review.googlesource.com/c/sdk/+/487542 (and to `^3.12.0-0` in https://dart-review.googlesource.com/c/sdk/+/487880) but the source was never formatted. This is, if nothing else, bad for reviews, where editing a file changes the file in lots of places because of new formatting. This CL is the result of running ``` out/ReleaseX64/dart-sdk/bin/dart format pkg/kernel/ ``` but also updates the formatter version used by a source generator (`pkg/front_end/tool/visitor_generator.dart`) so things agree. Change-Id: I66e35d4f1e2d08cecc30fb314546cae78b49e99b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490082 Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Jens Johansen <jensj@google.com>
99 lines
2.5 KiB
Dart
99 lines
2.5 KiB
Dart
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
/// Conventions for paths:
|
|
///
|
|
/// - Use the [Uri] class for paths that may have the `file`, `dart` or
|
|
/// `package` scheme. Never use [Uri] for relative paths.
|
|
/// - Use [String]s for all filenames and paths that have no scheme prefix.
|
|
/// - Never translate a `dart:` or `package:` URI into a `file:` URI, instead
|
|
/// translate it to a [String] if the file system path is needed.
|
|
/// - Only use [File] from dart:io at the last moment when it is needed.
|
|
///
|
|
library kernel;
|
|
|
|
import 'dart:typed_data';
|
|
|
|
import 'ast.dart';
|
|
import 'binary/ast_to_binary.dart';
|
|
import 'binary/ast_from_binary.dart';
|
|
import 'dart:io';
|
|
import 'text/ast_to_text.dart';
|
|
|
|
export 'ast.dart';
|
|
|
|
Component loadComponentFromBinary(String path, [Component? component]) {
|
|
Uint8List bytes = new File(path).readAsBytesSync();
|
|
return loadComponentFromBytes(bytes, component);
|
|
}
|
|
|
|
Component loadComponentFromBytes(Uint8List bytes, [Component? component]) {
|
|
component ??= new Component();
|
|
new BinaryBuilder(bytes).readComponent(component);
|
|
return component;
|
|
}
|
|
|
|
Component loadComponentSourceFromBytes(
|
|
Uint8List bytes, [
|
|
Component? component,
|
|
]) {
|
|
component ??= new Component();
|
|
new BinaryBuilder(bytes).readComponentSource(component);
|
|
return component;
|
|
}
|
|
|
|
Future writeComponentToBinary(
|
|
Component component,
|
|
String path, {
|
|
bool includeSource = true,
|
|
}) {
|
|
IOSink sink;
|
|
if (path == 'null' || path == 'stdout') {
|
|
sink = stdout.nonBlocking;
|
|
} else {
|
|
sink = new File(path).openWrite();
|
|
}
|
|
|
|
Future future;
|
|
try {
|
|
new BinaryPrinter(
|
|
sink,
|
|
includeSources: includeSource,
|
|
).writeComponentFile(component);
|
|
} finally {
|
|
if (sink == stdout.nonBlocking) {
|
|
future = sink.flush();
|
|
} else {
|
|
future = sink.close();
|
|
}
|
|
}
|
|
|
|
return future;
|
|
}
|
|
|
|
Uint8List writeComponentToBytes(Component component) {
|
|
BytesSink sink = new BytesSink();
|
|
new BinaryPrinter(sink).writeComponentFile(component);
|
|
return sink.builder.toBytes();
|
|
}
|
|
|
|
void writeComponentToText(
|
|
Component component, {
|
|
String? path,
|
|
bool showOffsets = false,
|
|
bool showMetadata = false,
|
|
}) {
|
|
StringBuffer buffer = new StringBuffer();
|
|
new Printer(
|
|
buffer,
|
|
showOffsets: showOffsets,
|
|
showMetadata: showMetadata,
|
|
).writeComponentFile(component);
|
|
if (path == null) {
|
|
print(buffer);
|
|
} else {
|
|
new File(path).writeAsStringSync('$buffer');
|
|
}
|
|
}
|