blob: e936dd85e98d1fef7e39a1b9c3a41e0f52c2e2b0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/* NSC -- new Scala compiler
* Copyright 2005-2007 LAMP/EPFL
* @author Martin Odersky
*/
// $Id$
package scala.tools.nsc
import compat.Math.log
import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
/** The main class for NSC, a compiler for the programming
* language Scala.
*/
object MainTokenMetric {
private var reporter: ConsoleReporter = _
private def tokenMetric(compiler: Global, fnames: List[String]) {
import compiler.CompilationUnit
import compiler.syntaxAnalyzer.UnitScanner
import ast.parser.Tokens.EOF
var totale = 0
for (val source <- fnames) {
val s = new UnitScanner(new CompilationUnit(compiler.getSourceFile(source)))
var i = 0
while(s.token != EOF) {
i += 1
s.nextToken
}
var j = 0 ; while(j + log(i) / log(10) < 7) {
j += 1
Console.print(' ')
}
Console.print(i.toString())
Console.print(" ")
Console.println(source.toString())
totale = totale + i
}
Console.println(totale.toString()+" total")
}
def process(args: Array[String]): unit = {
val settings = new Settings(error)
reporter = new ConsoleReporter(settings)
val command = new CompilerCommand(List.fromArray(args), settings, error, false)
try {
val compiler = new Global(command.settings, reporter)
tokenMetric(compiler, command.files)
} catch {
case ex @ FatalError(msg) =>
if (command.settings.debug.value)
ex.printStackTrace();
reporter.error(null, "fatal error: " + msg)
}
}
def main(args: Array[String]): unit = {
process(args)
exit(if (reporter.hasErrors) 1 else 0)
}
}
|