Mercurial > projects > dil
annotate trunk/src/cmd/ASTStats.d @ 757:e4b60543c5e8
Revised methods in class Visitor.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Wed, 13 Feb 2008 22:08:58 +0100 |
parents | d422e5f2f3ea |
children | 8380fb2c765f |
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 |
757
e4b60543c5e8
Revised methods in class Visitor.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
672
diff
changeset
|
25 // Override dispatch function. |
e4b60543c5e8
Revised methods in class Visitor.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
672
diff
changeset
|
26 override Node dispatch(Node n) |
672
d422e5f2f3ea
Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
643
diff
changeset
|
27 { |
d422e5f2f3ea
Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
643
diff
changeset
|
28 table[n.kind]++; |
757
e4b60543c5e8
Revised methods in class Visitor.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
672
diff
changeset
|
29 return super.dispatch(n); |
672
d422e5f2f3ea
Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
643
diff
changeset
|
30 } |
643
3bd947eb72c2
Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
31 } |