summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/CompileClient.scala2
-rw-r--r--src/compiler/scala/tools/nsc/CompileServer.scala20
-rw-r--r--src/compiler/scala/tools/nsc/CompileSocket.scala15
-rw-r--r--src/compiler/scala/tools/nsc/CompilerCommand.scala44
-rw-r--r--src/compiler/scala/tools/nsc/InterpreterLoop.scala32
-rw-r--r--src/compiler/scala/tools/nsc/Main.scala10
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala8
7 files changed, 81 insertions, 50 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileClient.scala b/src/compiler/scala/tools/nsc/CompileClient.scala
index 32023cccc9..8454f522df 100644
--- a/src/compiler/scala/tools/nsc/CompileClient.scala
+++ b/src/compiler/scala/tools/nsc/CompileClient.scala
@@ -91,7 +91,7 @@ object CompileClient {
}
val socket = if (serverAdr == "") CompileSocket.getOrCreateSocket(vmArgs, !shutdown)
else CompileSocket.getSocket(serverAdr)
- if(shutdown && (socket==null)) {
+ if (shutdown && (socket==null)) {
Console.println("[No compilation server running.]")
return 0
}
diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala
index 89620b5687..0d237e2fd9 100644
--- a/src/compiler/scala/tools/nsc/CompileServer.scala
+++ b/src/compiler/scala/tools/nsc/CompileServer.scala
@@ -67,7 +67,7 @@ object CompileServer extends SocketServer {
var reporter: ConsoleReporter = _
- def session(): unit = {
+ def session() {
System.out.println("New session" +
", total memory = "+ runtime.totalMemory() +
", max memory = " + runtime.maxMemory() +
@@ -90,9 +90,10 @@ object CompileServer extends SocketServer {
compiler = null
return
}
- def error(msg: String): unit =
+ def error(msg: String) {
reporter.error(/*new Position*/ FakePos("fsc"),
msg + "\n fsc -help gives more information")
+ }
val command = new CompilerCommand(args, new Settings(error), error, false) {
override val cmdName = "fsc"
settings.disable(settings.prompt)
@@ -106,13 +107,15 @@ object CompileServer extends SocketServer {
reporter = new ConsoleReporter(command.settings, in, out) {
// disable prompts, so that compile server cannot block
- override def displayPrompt = {}
+ override def displayPrompt = ()
}
if (command.settings.version.value)
reporter.info(null, versionMsg, true)
- else if (command.settings.help.value)
- reporter.info(null, command.usageMsg, true)
+ else if (command.settings.help.value || command.settings.Xhelp.value) {
+ if (command.settings.help.value) reporter.info(null, command.usageMsg, true)
+ if (command.settings.Xhelp.value) reporter.info(null, command.xusageMsg, true)
+ }
else if (command.files.isEmpty)
reporter.info(null, command.usageMsg, true)
else {
@@ -153,17 +156,18 @@ object CompileServer extends SocketServer {
}
/** A directory holding redirected output */
- val redirectDir = new File(CompileSocket.tmpDir, "output-redirects")
+ private val redirectDir = new File(CompileSocket.tmpDir, "output-redirects")
redirectDir.mkdirs
- def redirect(setter: PrintStream => unit, filename: String): unit =
+ private def redirect(setter: PrintStream => unit, filename: String) {
setter(
new PrintStream(
new BufferedOutputStream(
new FileOutputStream(
new File(redirectDir, filename)))))
+ }
- def main(args: Array[String]): unit = {
+ def main(args: Array[String]) {
redirect(System.setOut, "scala-compile-server-out.log")
redirect(System.setErr, "scala-compile-server-err.log")
System.err.println("...starting server on socket "+port+"...")
diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala
index a5a5f178e3..82beda4188 100644
--- a/src/compiler/scala/tools/nsc/CompileSocket.scala
+++ b/src/compiler/scala/tools/nsc/CompileSocket.scala
@@ -115,7 +115,7 @@ object CompileSocket {
vmCommand + vmArgs + " " + serverClass
/** Start a new server; returns true iff it succeeds */
- private def startNewServer(vmArgs: String): unit = {
+ private def startNewServer(vmArgs: String) {
val cmd = serverCommand(vmArgs)
info("[Executed command: " + cmd + "]")
try {
@@ -130,10 +130,10 @@ object CompileSocket {
}
/** The port identification file */
- def portFile(port: int) = new File(portsDir, port.toString())
+ def portFile(port: Int) = new File(portsDir, port.toString())
/** Poll for a server port number; return -1 if none exists yet */
- private def pollPort(): int = {
+ private def pollPort(): Int = {
val hits = portsDir.listFiles()
if (hits.length == 0) -1
else
@@ -152,7 +152,7 @@ object CompileSocket {
/** Get the port number to which a scala compile server is connected;
* If no server is running yet, then create one.
*/
- def getPort(vmArgs: String): int = {
+ def getPort(vmArgs: String): Int = {
var attempts = 0
var port = pollPort()
@@ -170,7 +170,7 @@ object CompileSocket {
}
/** Set the port number to which a scala compile server is connected */
- def setPort(port: int): unit =
+ def setPort(port: Int) {
try {
val f = new PrintWriter(new FileOutputStream(portFile(port)))
f.println(new java.util.Random().nextInt.toString)
@@ -180,15 +180,16 @@ object CompileSocket {
fatal("Cannot create file: " +
portFile(port).getAbsolutePath())
}
+ }
/** Delete the port number to which a scala compile server was connected */
- def deletePort(port: int): unit = portFile(port).delete()
+ def deletePort(port: Int) { portFile(port).delete() }
/** Get a socket connected to a daemon. If create is true, then
* create a new daemon if necessary. Returns null if the connection
* cannot be established.
*/
- def getOrCreateSocket(vmArgs: String, create: boolean): Socket = {
+ def getOrCreateSocket(vmArgs: String, create: Boolean): Socket = {
val nAttempts = 49 // try for about 5 seconds
def getsock(attempts: int): Socket =
if (attempts == 0) {
diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala
index a84dbeb172..0f534c6338 100644
--- a/src/compiler/scala/tools/nsc/CompilerCommand.scala
+++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala
@@ -9,7 +9,7 @@ package scala.tools.nsc
/** A class representing command line info for scalac */
class CompilerCommand(arguments: List[String], val settings: Settings,
- error: String => unit, interactive: boolean) {
+ error: String => Unit, interactive: Boolean) {
private var fs: List[String] = List()
@@ -22,24 +22,40 @@ class CompilerCommand(arguments: List[String], val settings: Settings,
/** The file extension of files that the compiler can process */
val fileEnding = ".scala"
+ private val helpSyntaxColumnWidth: Int =
+ Iterable.max(settings.allSettings map (_.helpSyntax.length))
+
+ private def format(s: String): String = {
+ val buf = new StringBuilder(s)
+ var i = s.length
+ while (i < helpSyntaxColumnWidth) { buf.append(' '); i += 1 }
+ buf.toString()
+ }
+
/** A message explaining usage and options */
def usageMsg: String = {
- // todo: print -X and -javadoc options only on demand
- val helpSyntaxColumnWidth: int =
- Iterable.max(settings.allSettings map (_.helpSyntax.length))
- def format(s: String): String = {
- val buf = new StringBuilder(s)
- var i = s.length
- while (i < helpSyntaxColumnWidth) { buf.append(' '); i += 1 }
- buf.toString()
- }
settings.allSettings
+ .filter(setting =>
+ setting.isStandard &&
+ (settings.doc.value == setting.isDocOption))
+ .map(setting =>
+ format(setting.helpSyntax) + " " + setting.helpDescription)
+ .mkString("Usage: " + cmdName + " <options | source files>\n" +
+ "where possible standard options include:\n",
+ "\n",
+ "\n")
+ }
+
+ /** A message explaining usage and options */
+ def xusageMsg: String = {
+ settings.allSettings
+ .filter(setting =>
+ !setting.isStandard &&
+ (settings.doc.value == setting.isDocOption))
.map(setting =>
format(setting.helpSyntax) + " " + setting.helpDescription)
- .mkString(
- "Usage: " + cmdName + " <options | source files>\n" +
- "where possible options include: \n ",
- "\n ",
+ .mkString("Possible non-standard options include:\n",
+ "\n",
"\n")
}
diff --git a/src/compiler/scala/tools/nsc/InterpreterLoop.scala b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
index 61f3327a4e..f37044be8e 100644
--- a/src/compiler/scala/tools/nsc/InterpreterLoop.scala
+++ b/src/compiler/scala/tools/nsc/InterpreterLoop.scala
@@ -51,12 +51,13 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
replayCommandsRev = cmd :: replayCommandsRev
/** Close the interpreter, if there is one, and set
- * interpreter to null. */
- def closeInterpreter =
+ * interpreter to <code>null</code>. */
+ def closeInterpreter() {
if (interpreter ne null) {
interpreter.close
interpreter = null
}
+ }
/* As soon as the Eclipse plugin no longer needs it, delete uglinessxxx,
* parentClassLoader0, and the parentClassLoader method in Interpreter
@@ -66,11 +67,11 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
/** Create a new interpreter. Close the old one, if there
* is one. */
- def createInterpreter = {
- closeInterpreter
+ def createInterpreter() {
+ //closeInterpreter()
interpreter = new Interpreter(settings, out) {
- override protected def parentClassLoader = parentClassLoader0;
+ override protected def parentClassLoader = parentClassLoader0
}
}
@@ -89,9 +90,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
/** print a friendly help message */
def printHelp {
- out.println("This is a Scala shell.")
- out.println("Type in expressions to have them evaluated.")
- out.println("Type :help to repeat this message.")
+ printWelcome
out.println("Type :load followed by a filename to load a Scala file.")
out.println("Type :replay to reset execution and replay all previous commands.")
out.println("Type :quit to exit the interpreter.")
@@ -168,8 +167,8 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
/** create a new interpreter and replay all commands so far */
def replay() {
- closeInterpreter
- createInterpreter
+ closeInterpreter()
+ createInterpreter()
for (cmd <- replayCommands) {
out.println("Replaying: " + cmd)
command(cmd)
@@ -252,7 +251,7 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
}
- def main(settings: Settings) = {
+ def main(settings: Settings) {
this.settings = settings
uglinessxxx =
@@ -261,25 +260,26 @@ class InterpreterLoop(in0: BufferedReader, out: PrintWriter) {
map(s => new File(s).toURL),
classOf[InterpreterLoop].getClassLoader)
- createInterpreter
+ createInterpreter()
try {
printWelcome
repl
} finally {
- closeInterpreter
+ closeInterpreter()
}
}
/** process command-line arguments and do as they request */
def main(args: Array[String]) {
- def error1(msg: String): Unit = out.println("scala: " + msg)
+ def error1(msg: String) { out.println("scala: " + msg) }
val command = new InterpreterCommand(List.fromArray(args), error1)
- if (!command.ok || command.settings.help.value) {
+ if (!command.ok || command.settings.help.value || command.settings.Xhelp.value) {
// either the command line is wrong, or the user
// explicitly requested a help listing
- out.println(command.usageMsg)
+ if (command.settings.help.value) out.println(command.usageMsg)
+ if (command.settings.Xhelp.value) out.println(command.xusageMsg)
out.flush
}
else
diff --git a/src/compiler/scala/tools/nsc/Main.scala b/src/compiler/scala/tools/nsc/Main.scala
index b257545a36..66d4eb3c1a 100644
--- a/src/compiler/scala/tools/nsc/Main.scala
+++ b/src/compiler/scala/tools/nsc/Main.scala
@@ -30,12 +30,13 @@ object Main extends AnyRef with EvalLoop {
/* needed ?? */
//def errors() = reporter.errors
- def resident(compiler: Global): unit =
+ def resident(compiler: Global) {
loop { line =>
val args = List.fromString(line, ' ')
val command = new CompilerCommand(args, new Settings(error), error, true)
(new compiler.Run) compile command.files
}
+ }
def process(args: Array[String]) {
val settings = new Settings(error)
@@ -43,9 +44,10 @@ object Main extends AnyRef with EvalLoop {
val command = new CompilerCommand(List.fromArray(args), settings, error, false)
if (command.settings.version.value)
reporter.info(null, versionMsg, true)
- else if (command.settings.help.value)
- reporter.info(null, command.usageMsg, true)
- else {
+ else if (command.settings.help.value || command.settings.Xhelp.value) {
+ if (command.settings.help.value) reporter.info(null, command.usageMsg, true)
+ if (command.settings.Xhelp.value) reporter.info(null, command.xusageMsg, true)
+ } else {
try {
object compiler extends Global(command.settings, reporter)
if (reporter.hasErrors) {
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index 79b6a6c140..88752e80ca 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -117,6 +117,9 @@ class Settings(error: String => Unit) {
// val showPhases = BooleanSetting("-showphases", "Print a synopsis of compiler phases")
val inline = BooleanSetting("-Xinline", "Perform inlining when possible")
+
+ /** non-standard options */
+ val Xhelp = new BooleanSetting("-X", "Print a synopsis of non-standard options") { override def hiddenToIDE = true }
val XO = BooleanSetting("-XO", "Optimize. implies -Xinline, -Xcloselim and -Xdce")
val Xcloselim = BooleanSetting("-Xcloselim", "Perform closure elimination")
val Xcodebase = StringSetting ("-Xcodebase", "codebase", "Specify the URL containing the Scala libraries", "")
@@ -233,6 +236,11 @@ class Settings(error: String => Unit) {
def dependsOn(s: Setting, value: String): this.type = { dependency = Some((s, value)); this }
def dependsOn(s: Setting): this.type = dependsOn(s, "")
+ def isStandard: Boolean =
+ !(name startsWith "-X") || (name eq "-X")
+ def isDocOption: Boolean =
+ !dependency.isEmpty && dependency.get._1 == doc
+
// initialization
allsettings = this :: allsettings
}