1 /// Author: Aziz Köksal
2 /// License: GPL3
3 /// $(Maturity average)
4 module cmd.ASTStats;
5
6 import dil.ast.DefaultVisitor,
7 dil.ast.Node,
8 dil.ast.Declaration,
9 dil.ast.Statement,
10 dil.ast.Expression,
11 dil.ast.Types;
12
13 /// Counts the nodes in a syntax tree.
14 class ASTStats : DefaultVisitor2
15 {
16 uint[] table; /// Table for counting nodes.
17
18 /// Starts counting.
19 uint[] count(Node root)
20 {
21 table = new uint[NodeClassNames.length];
22 super.visitN(root);
23 return table;
24 }
25
26 // Override dispatch function.
27 override void dispatch(Node n)
28 {
29 table[n.kind]++;
30 super.dispatch(n);
31 }
32 }