Mercurial > projects > dil
comparison trunk/src/cmd/Statistics.d @ 755:90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Wed, 13 Feb 2008 20:21:25 +0100 |
parents | ff6971637f88 |
children | 4579e8505d5e |
comparison
equal
deleted
inserted
replaced
754:c7a5499faa77 | 755:90668b83ae5e |
---|---|
7 import dil.File; | 7 import dil.File; |
8 import dil.lexer.Lexer; | 8 import dil.lexer.Lexer; |
9 import dil.lexer.Token; | 9 import dil.lexer.Token; |
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 cmd.ASTStats; | 13 import cmd.ASTStats; |
13 import common; | 14 import common; |
14 | 15 |
15 struct Statistics | 16 struct Statistics |
16 { | 17 { |
135 Statistics getStatistics(string filePath, bool printTokensTable, bool printNodesTable) | 136 Statistics getStatistics(string filePath, bool printTokensTable, bool printNodesTable) |
136 { | 137 { |
137 // Create a new record. | 138 // Create a new record. |
138 auto stats = Statistics(printTokensTable); | 139 auto stats = Statistics(printTokensTable); |
139 | 140 |
140 auto sourceText = loadFile(filePath); | 141 auto sourceText = new SourceText(filePath, true); |
141 Parser parser; | 142 Parser parser; |
142 Lexer lx; | 143 Lexer lx; |
143 if (printNodesTable) | 144 if (printNodesTable) |
144 { | 145 { |
145 parser = new Parser(sourceText, filePath); | 146 parser = new Parser(sourceText); |
146 auto rootNode = parser.start(); | 147 auto rootNode = parser.start(); |
147 // Count nodes. | 148 // Count nodes. |
148 stats.nodesTable = (new ASTStats).count(rootNode); | 149 stats.nodesTable = (new ASTStats).count(rootNode); |
149 lx = parser.lexer; | 150 lx = parser.lexer; |
150 } | 151 } |
151 else | 152 else |
152 { | 153 { |
153 lx = new Lexer(sourceText, filePath); | 154 lx = new Lexer(sourceText); |
154 lx.scanAll(); | 155 lx.scanAll(); |
155 } | 156 } |
156 | 157 |
157 auto token = lx.firstToken(); | 158 auto token = lx.firstToken(); |
158 | 159 |