Mercurial > projects > dil
annotate trunk/src/cmd/ASTStats.d @ 797:cf2ad5df025c
Added documentation comments.
Removed Lexer.loadKeywords() and revised Lexer.isReservedIdentifier().
Also removed Lexer.getTokens().
Renamed keywords to g_reservedIds.
Renamed classNames to g_classNames.
Added PRE and DMDBUG macros.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Fri, 29 Feb 2008 22:51:24 +0100 |
parents | 8380fb2c765f |
children |
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 |
783
8380fb2c765f
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
14 /// Counts the nodes in a syntax tree. |
643
3bd947eb72c2
Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
15 class ASTStats : DefaultVisitor |
3bd947eb72c2
Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
16 { |
3bd947eb72c2
Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
17 uint[] table; /// Table for counting nodes. |
3bd947eb72c2
Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
18 |
783
8380fb2c765f
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
19 /// Starts counting. |
643
3bd947eb72c2
Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
20 uint[] count(Node root) |
3bd947eb72c2
Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
21 { |
797
cf2ad5df025c
Added documentation comments.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
783
diff
changeset
|
22 table = new uint[g_classNames.length]; |
643
3bd947eb72c2
Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
23 super.visitN(root); |
3bd947eb72c2
Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
24 return table; |
3bd947eb72c2
Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
25 } |
3bd947eb72c2
Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
26 |
757
e4b60543c5e8
Revised methods in class Visitor.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
672
diff
changeset
|
27 // Override dispatch function. |
e4b60543c5e8
Revised methods in class Visitor.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
672
diff
changeset
|
28 override Node dispatch(Node n) |
672
d422e5f2f3ea
Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
643
diff
changeset
|
29 { |
d422e5f2f3ea
Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
643
diff
changeset
|
30 table[n.kind]++; |
757
e4b60543c5e8
Revised methods in class Visitor.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
672
diff
changeset
|
31 return super.dispatch(n); |
672
d422e5f2f3ea
Added '--asttable' option to command 'statistics'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
643
diff
changeset
|
32 } |
643
3bd947eb72c2
Added module cmd.ASTStats.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
diff
changeset
|
33 } |