comparison trunk/src/cmd/Statistics.d @ 786:3b34f6a95a27

Added and revised documenation comments.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 24 Feb 2008 02:41:11 +0100
parents 4579e8505d5e
children cf2ad5df025c
comparison
equal deleted inserted replaced
785:57ef69eced96 786:3b34f6a95a27
10 import dil.parser.Parser; 10 import dil.parser.Parser;
11 import dil.ast.NodesEnum; 11 import dil.ast.NodesEnum;
12 import dil.SourceText; 12 import dil.SourceText;
13 import common; 13 import common;
14 14
15 /// A group of statistics variables.
15 struct Statistics 16 struct Statistics
16 { 17 {
17 uint whitespaceCount; /// Counter for whitespace characters. 18 uint whitespaceCount; /// Counter for whitespace characters.
18 uint wsTokenCount; /// Counter for all whitespace tokens. 19 uint wsTokenCount; /// Counter for all whitespace tokens.
19 uint keywordCount; /// Counter for keywords. 20 uint keywordCount; /// Counter for keywords.
20 uint identCount; /// Counter for identifier. 21 uint identCount; /// Counter for identifiers.
21 uint numberCount; /// Counter for number literals. 22 uint numberCount; /// Counter for number literals.
22 uint commentCount; /// Counter for comments. 23 uint commentCount; /// Counter for comments.
23 uint tokenCount; /// Counter for all tokens produced by the Lexer. 24 uint tokenCount; /// Counter for all tokens produced by the Lexer.
24 uint linesOfCode; /// Number of lines. 25 uint linesOfCode; /// Number of lines.
25 uint[] tokensTable; /// Table of counters for all token kinds. 26 uint[] tokensTable; /// Table of counters for all token kinds.
50 foreach (i, count; s.nodesTable) 51 foreach (i, count; s.nodesTable)
51 this.nodesTable[i] += count; 52 this.nodesTable[i] += count;
52 } 53 }
53 } 54 }
54 55
56 /// Executes the statistics command.
55 void execute(string[] filePaths, bool printTokensTable, bool printNodesTable) 57 void execute(string[] filePaths, bool printTokensTable, bool printNodesTable)
56 { 58 {
57 Statistics[] stats; 59 Statistics[] stats;
58 foreach (filePath; filePaths) 60 foreach (filePath; filePaths)
59 stats ~= getStatistics(filePath, printTokensTable, printNodesTable); 61 stats ~= getStatistics(filePath, printTokensTable, printNodesTable);
130 Stdout.formatln(" {,10} | {}", count, classNames[i]); 132 Stdout.formatln(" {,10} | {}", count, classNames[i]);
131 Stdout("// End of nodes table.").newline; 133 Stdout("// End of nodes table.").newline;
132 } 134 }
133 } 135 }
134 136
137 /// Returns the statistics for a D source file.
135 Statistics getStatistics(string filePath, bool printTokensTable, bool printNodesTable) 138 Statistics getStatistics(string filePath, bool printTokensTable, bool printNodesTable)
136 { 139 {
137 // Create a new record. 140 // Create a new record.
138 auto stats = Statistics(printTokensTable); 141 auto stats = Statistics(printTokensTable);
139 142