diff options
author | Martin Odersky <odersky@gmail.com> | 2006-07-12 13:05:13 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2006-07-12 13:05:13 +0000 |
commit | 8592375f95a644f0bae55b4ce9215b4533cba2d4 (patch) | |
tree | 4dc29cb2a7c56c3c7c47da9d3b643646b952959f /src/compiler/scala | |
parent | b53dced1215bffa82ae3f4aa38f614e4a0f48a7d (diff) | |
download | scala-8592375f95a644f0bae55b4ce9215b4533cba2d4.tar.gz scala-8592375f95a644f0bae55b4ce9215b4533cba2d4.tar.bz2 scala-8592375f95a644f0bae55b4ce9215b4533cba2d4.zip |
Made fsc safer and scriptable
Fixed position errors for imported prefixes
Fixed symbol literals (bug369)
Diffstat (limited to 'src/compiler/scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/CompileClient.scala | 5 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/CompileServer.scala | 10 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/CompileSocket.scala | 12 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/CompilerCommand.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ScriptRunner.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Settings.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/Trees.scala | 7 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 8 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 2 |
10 files changed, 43 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileClient.scala b/src/compiler/scala/tools/nsc/CompileClient.scala index 7e8d3b642e..de780a9c70 100644 --- a/src/compiler/scala/tools/nsc/CompileClient.scala +++ b/src/compiler/scala/tools/nsc/CompileClient.scala @@ -57,7 +57,7 @@ object CompileClient { def main(args: Array[String]): unit = { val Pair(vmArgs, serverAdr) = normalize(args) - if (args exists ("-verbose" ==)) { + if (args.toList contains "-verbose") { System.out.println("[Server arguments: " + args.mkString("", " ", "]")) System.out.println("[VM arguments: " + vmArgs + "]") } @@ -65,7 +65,8 @@ object CompileClient { else CompileSocket.getSocket(serverAdr) val out = new PrintWriter(socket.getOutputStream(), true) val in = new BufferedReader(new InputStreamReader(socket.getInputStream())) - out.println(args.mkString("", " ", "")) + out.println(CompileSocket.getPassWord(socket.getPort())) + out.println(args.mkString("", "\0", "")) var fromServer = in.readLine() while (fromServer != null) { System.out.println(fromServer) diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala index 53ca8dff56..256bc6bdd5 100644 --- a/src/compiler/scala/tools/nsc/CompileServer.scala +++ b/src/compiler/scala/tools/nsc/CompileServer.scala @@ -5,7 +5,7 @@ // $Id$ package scala.tools.nsc -import scala.tools.util.{SocketServer, StringOps} +import scala.tools.util.SocketServer import scala.tools.nsc.util.Position import scala.tools.nsc.reporters.{Reporter, ConsoleReporter} import scala.tools.nsc.doc.DocGenerator @@ -69,12 +69,14 @@ object CompileServer extends SocketServer { System.out.println("New session, total memory = "+runtime.totalMemory()+ ", max memory = "+runtime.maxMemory()+ ", free memory = "+runtime.freeMemory) + val passWord = CompileSocket.getPassWord(port) + val guestPassWord = in.readLine() val input = in.readLine() - if (input != null) { + if (input != null && passWord == guestPassWord) { try { inSession = true progress = true - val args = StringOps.words(input) + val args = input.split("\0").toList if (args contains "-shutdown") { out.println("[Scala compile server exited]") shutDown = true @@ -110,7 +112,7 @@ object CompileServer extends SocketServer { else if (command.files.isEmpty) reporter.info(null, command.usageMsg, true) else { - try {scala.tools.nsc.CompileServer + try { if (compiler != null && settingsAreCompatible(command.settings, compiler.settings)) { compiler.settings = command.settings compiler.reporter = reporter diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala index d8abd33ae6..15dad1df53 100644 --- a/src/compiler/scala/tools/nsc/CompileSocket.scala +++ b/src/compiler/scala/tools/nsc/CompileSocket.scala @@ -14,7 +14,7 @@ object CompileSocket { private val dirName = "scalac-compile-server-port" /** The vm-part of the command to start a new scala compile server */ - private val vmCommand = "java" + private val vmCommand = "scala" /** The class name of the scala compile server */ private val serverClass = "scala.tools.nsc.CompileServer" @@ -87,7 +87,8 @@ object CompileSocket { /** Set the port number to which a scala compile server is connected */ def setPort(port: int): unit = try { - val f = new FileOutputStream(portFile(port)); + val f = new DataOutputStream(new FileOutputStream(portFile(port))) + f.writeChars(new java.util.Random().nextInt.toString) f.close() } catch { case ex: IOException => @@ -151,4 +152,11 @@ object CompileSocket { "unable to establish connection to server "+hostName+":"+port+"; exiting") exit(1) } + + def getPassWord(port: int): String = { + val f = new DataInputStream(new FileInputStream(portFile(port))) + val result = f.readLine() + f.close() + result + } } diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala index 1678460416..782a6a9338 100644 --- a/src/compiler/scala/tools/nsc/CompilerCommand.scala +++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala @@ -64,7 +64,7 @@ class CompilerCommand(arguments: List[String], error: String => unit, interactiv ok = false } } - } else if (args.head.endsWith(fileEnding)) { + } else if (settings.Xscript.value || args.head.endsWith(fileEnding)) { fs = args.head :: fs args = args.tail } else { diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index a0a99bc348..77aed1d1c9 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -524,7 +524,11 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable def compile(filenames: List[String]): unit = try { - compileSources(filenames map getSourceFile) + if (settings.Xscript.value && filenames.length != 1) + error("can only compile one script at a time") + val sources = filenames map ( + if (settings.Xscript.value) ScriptRunner.wrappedScript else getSourceFile) + compileSources(sources) } catch { case ex: IOException => error(ex.getMessage()) } diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala index 593ee60629..d9c1a6112d 100644 --- a/src/compiler/scala/tools/nsc/ScriptRunner.scala +++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala @@ -122,7 +122,7 @@ object ScriptRunner { /** Wrap a script file into a runnable object named * scala.scripting.Main . */ - private def wrappedScript(filename: String): SourceFile = { + def wrappedScript(filename: String): SourceFile = { val preamble = new SourceFile("<script preamble>", ("package scala.scripting\n" + diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index 1dfc8ab0d5..82af96729a 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -121,6 +121,7 @@ class Settings(error: String => unit) { val Xlinearizer = ChoiceSetting ("-Xlinearizer", "Linearizer to use", List("normal", "dfs", "rpo", "dump"), "rpo") val Xgenerics = BooleanSetting("-Xgenerics", "Use generic Java types"); val Xprintpos = BooleanSetting("-Xprintpos", "Print tree positions (as offsets)"); + val Xscript = BooleanSetting("-Xscript", "compile script file"); /** A list of all settings */ def allSettings: List[Setting] = allsettings.reverse diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index b2bc956359..61ae3b6013 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -1252,6 +1252,13 @@ trait Trees requires Global { } } + object resetPos extends Traverser { + override def traverse(t: Tree): unit = { + if (t != EmptyTree) t.setPos(Position.NOPOS) + super.traverse(t) + } + } + /** A traverser which resets symbol and tpe fields of all nodes in a given tree * except for (1) TypeTree nodes, whose .tpe field is kept and * (2) is a .symbol field refers to a symbol which is defined outside the diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index efe6bde052..5c37359adc 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -328,6 +328,14 @@ trait Scanners requires SyntaxAnalyzer { token = SYMBOLLIT return } + } else if (isSpecial(in.ch)) { + putChar(in.ch) + in.next + if (in.ch != '\'') { + getOperatorRest + token = SYMBOLLIT + return + } } else { getlitch() } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 1a7d0e1644..a2171bf600 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1400,7 +1400,7 @@ trait Typers requires Analyzer { imports1 = imports1.tail } defSym = impSym - qual = imports.head.qual + qual = atPos(tree.pos)(resetPos(imports.head.qual.duplicate)) pre = qual.tpe } else { if (settings.debug.value) { |