Files
sdk/pkg/kernel/bin/count_breakdown.dart
T
Johnni Winther 7e6692b20c Revert "[kernel] Migrate remaining bin/lib libraries in package:..."
Revert submission 195268

Reason for revert: Implicitly triggers running bin/* in sound null safety, revealing an unsafe use of List.length=

Reverted Changes:
I026ace4fd:[cfe] Migrate front_end libraries from wave 3-4
I9ba1f809b:[kernel] Migrate remaining bin/lib libraries in pa...

Change-Id: I3535c45d6eaf970dc5a17b6d7274cd9d6aa16ae2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195507
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2021-04-15 14:55:37 +00:00

55 lines
1.5 KiB
Dart
Executable File

#!/usr/bin/env dart
// Copyright (c) 2018, 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.
// @dart = 2.9
import 'dart:io';
import 'package:kernel/kernel.dart';
import 'package:kernel/src/tool/command_line_util.dart';
void usage() {
print("Enumerates the different node types in the provided dill file");
print("and counts them.");
print("");
print("Usage: dart <script> dillFile.dill");
print("The given argument should be an existing file");
print("that is valid to load as a dill file.");
exit(1);
}
main(List<String> args) {
CommandLineHelper.requireExactlyOneArgument(args, usage,
requireFileExists: true);
Component component = CommandLineHelper.tryLoadDill(args[0]);
TypeCounter counter = new TypeCounter();
component.accept(counter);
counter.printStats();
}
class TypeCounter extends RecursiveVisitor {
Map<String, int> _typeCounts = <String, int>{};
defaultNode(Node node) {
String key = node.runtimeType.toString();
_typeCounts[key] ??= 0;
_typeCounts[key]++;
super.defaultNode(node);
}
printStats() {
List<List<Object>> data = [];
_typeCounts.forEach((type, count) {
data.add([type, count]);
});
data.sort((a, b) {
int aCount = a[1];
int bCount = b[1];
return bCount - aCount;
});
for (var entry in data) {
print("${entry[0]}: ${entry[1]}");
}
}
}