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

Unified Diff: bin/show_inferred_types.dart

Issue 2758843003: Add simple binary that prints the inferred type information of a single function (Closed)
Patch Set: rebase Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/show_inferred_types.dart
diff --git a/bin/show_inferred_types.dart b/bin/show_inferred_types.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f8d509adea3116bafb7bc198189cb6423eee496c
--- /dev/null
+++ b/bin/show_inferred_types.dart
@@ -0,0 +1,58 @@
+// 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.
+
+/// Simple script that shows the inferred types of a function.
+library compiler.tool.show_inferred_types;
+
+import 'dart:convert';
+import 'dart:io';
+
+import 'package:dart2js_info/info.dart';
+import 'package:dart2js_info/src/util.dart';
+
+main(args) {
+ if (args.length < 2) {
+ var scriptName = Platform.script.pathSegments.last;
+ print('usage: dart $scriptName <info.json> <function-name-regex> [-l]');
+ print(' -l: print the long qualified name for a function.');
+ exit(1);
+ }
+
+ var showLongName = args.length > 2 && args[2] == '-l';
+
+ var json = JSON.decode(new File(args[0]).readAsStringSync());
+ var info = new AllInfoJsonCodec().decode(json);
+ var nameRegExp = new RegExp(args[1]);
+ matches(e) => nameRegExp.hasMatch(longName(e));
+
+ bool noResults = true;
+ void showMethods() {
+ var sources = info.functions.where(matches).toList();
+ if (sources.isEmpty) return;
+ noResults = false;
+ for (var s in sources) {
+ var params = s.parameters.map((p) => '${p.name}: ${p.type}').join(', ');
+ var name = showLongName ? longName(s) : s.name;
+ print('$name($params): ${s.returnType}');
+ }
+ }
+
+ void showFields() {
+ var sources = info.fields.where(matches).toList();
+ if (sources.isEmpty) return;
+ noResults = false;
+ for (var s in sources) {
+ var name = showLongName ? longName(s) : s.name;
+ print('$name: ${s.inferredType}');
+ }
+ }
+
+ showMethods();
+ showFields();
+ if (noResults) {
+ print('error: no function or field that matches ${args[1]} was found.');
+ exit(1);
+ }
+}
+
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698