summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2005-11-16 11:18:22 +0000
committerBurak Emir <emir@epfl.ch>2005-11-16 11:18:22 +0000
commitb58c45a42553d263874b83f0cb5cbd941e547124 (patch)
treeef832ece7891c1e7c11b89ef2ce58330b57a568c
parentea98167b27447b0325339ee07bf75638dea61138 (diff)
downloadscala-b58c45a42553d263874b83f0cb5cbd941e547124.tar.gz
scala-b58c45a42553d263874b83f0cb5cbd941e547124.tar.bz2
scala-b58c45a42553d263874b83f0cb5cbd941e547124.zip
added tokenMetric setting to compiler
-rwxr-xr-xsources/scala/tools/nsc/Main.scala29
-rw-r--r--sources/scala/tools/nsc/Settings.scala1
2 files changed, 29 insertions, 1 deletions
diff --git a/sources/scala/tools/nsc/Main.scala b/sources/scala/tools/nsc/Main.scala
index 395b489046..f8649fd9ca 100755
--- a/sources/scala/tools/nsc/Main.scala
+++ b/sources/scala/tools/nsc/Main.scala
@@ -75,6 +75,31 @@ object Main {
)
}
+ def tokenMetric(compiler: Global, fnames: List[String]): unit = {
+ import compiler.CompilationUnit;
+ import compiler.syntaxAnalyzer.Scanner;
+ import ast.parser.Tokens.EOF;
+ var totale = 0;
+ for (val source <- fnames) {
+ val s = new Scanner(new CompilationUnit(compiler.getSourceFile(source)));
+ s.nextToken;
+ var i = 0;
+ while(s.token != EOF) {
+ i = i + 1;
+ s.nextToken()
+ }
+ var j = 0 ; while(j + Math.log(i)/ Math.log(10) < 7) {
+ j = 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 = {
reporter = new ConsoleReporter();
val command = new CompilerCommand(List.fromArray(args), error, false);
@@ -86,7 +111,9 @@ object Main {
else {
try {
val compiler = new Global(command.settings, reporter);
- if (command.settings.resident.value)
+ if (command.settings.tokenMetric.value)
+ tokenMetric(compiler, command.files);
+ else if (command.settings.resident.value)
resident(compiler);
else if (command.settings.interpret.value)
interpret(compiler);
diff --git a/sources/scala/tools/nsc/Settings.scala b/sources/scala/tools/nsc/Settings.scala
index 0e927e2c34..c71f291dbe 100644
--- a/sources/scala/tools/nsc/Settings.scala
+++ b/sources/scala/tools/nsc/Settings.scala
@@ -31,6 +31,7 @@ class Settings(error: String => unit) {
val explaintypes = BooleanSetting("-explaintypes", "Explain type errors in more detail");
val interpret = BooleanSetting("-interpret", "Run interpreter");
val resident = BooleanSetting("-resident", "Compiler stays resident, files to compile are read from standard input");
+ val tokenMetric = BooleanSetting("-tokenMetric", "only count tokens");
val uniqid = BooleanSetting("-uniqid", "Print identifiers with unique names (debugging option)");
val printtypes = BooleanSetting("-printtypes", "Print tree types (debugging option)");
val prompt = BooleanSetting("-prompt", "Display a prompt after each error (debugging option)");