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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Simple script that shows the inferred types of a function.
6 library compiler.tool.show_inferred_types;
7
8 import 'dart:convert';
9 import 'dart:io';
10
11 import 'package:dart2js_info/info.dart';
12 import 'package:dart2js_info/src/util.dart';
13
14 main(args) {
15 if (args.length < 2) {
16 var scriptName = Platform.script.pathSegments.last;
17 print('usage: dart $scriptName <info.json> <function-name-regex> [-l]');
18 print(' -l: print the long qualified name for a function.');
19 exit(1);
20 }
21
22 var showLongName = args.length > 2 && args[2] == '-l';
23
24 var json = JSON.decode(new File(args[0]).readAsStringSync());
25 var info = new AllInfoJsonCodec().decode(json);
26 var nameRegExp = new RegExp(args[1]);
27 matches(e) => nameRegExp.hasMatch(longName(e));
28
29 bool noResults = true;
30 void showMethods() {
31 var sources = info.functions.where(matches).toList();
32 if (sources.isEmpty) return;
33 noResults = false;
34 for (var s in sources) {
35 var params = s.parameters.map((p) => '${p.name}: ${p.type}').join(', ');
36 var name = showLongName ? longName(s) : s.name;
37 print('$name($params): ${s.returnType}');
38 }
39 }
40
41 void showFields() {
42 var sources = info.fields.where(matches).toList();
43 if (sources.isEmpty) return;
44 noResults = false;
45 for (var s in sources) {
46 var name = showLongName ? longName(s) : s.name;
47 print('$name: ${s.inferredType}');
48 }
49 }
50
51 showMethods();
52 showFields();
53 if (noResults) {
54 print('error: no function or field that matches ${args[1]} was found.');
55 exit(1);
56 }
57 }
58
OLDNEW
« 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