annotate trunk/src/cmd/ASTStats.d @ 672:d422e5f2f3ea

Added '--asttable' option to command 'statistics'.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 18 Jan 2008 00:30:14 +0100
parents 3bd947eb72c2
children e4b60543c5e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
643
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
1 /++
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
2 Author: Aziz Köksal
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
3 License: GPL3
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
4 +/
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
5 module cmd.ASTStats;
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
6
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
7 import dil.ast.DefaultVisitor;
672
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
8 import dil.ast.Node,
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
9 dil.ast.Declaration,
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
10 dil.ast.Statement,
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
11 dil.ast.Expression,
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
12 dil.ast.Types;
643
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
13
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
14 class ASTStats : DefaultVisitor
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
15 {
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
16 uint[] table; /// Table for counting nodes.
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
17
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
18 uint[] count(Node root)
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
19 {
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
20 table = new uint[classNames.length];
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
21 super.visitN(root);
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
22 return table;
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
23 }
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
24
672
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
25 // Override dispatch functions.
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
26 override:
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
27 Declaration visitD(Declaration n)
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
28 {
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
29 table[n.kind]++;
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
30 return super.visitD(n);
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
31 }
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
32
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
33 Statement visitS(Statement n)
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
34 {
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
35 table[n.kind]++;
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
36 return super.visitS(n);
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
37 }
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
38
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
39 Expression visitE(Expression n)
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
40 {
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
41 table[n.kind]++;
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
42 return super.visitE(n);
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
43 }
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
44
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
45 TypeNode visitT(TypeNode n)
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
46 {
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
47 table[n.kind]++;
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
48 return super.visitT(n);
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
49 }
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
50
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
51 Node visitN(Node n)
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
52 {
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
53 table[n.kind]++;
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
54 return super.visitN(n);
d422e5f2f3ea Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents: 643
diff changeset
55 }
643
3bd947eb72c2 Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff changeset
56 }