summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-03-31 05:58:01 +0000
committerPaul Phillips <paulp@improving.org>2011-03-31 05:58:01 +0000
commitc81e94b5dd39cf86abd0145fc93e0999f57a548c (patch)
treeb9f2f6203b97a1ca2fd55991b2aa7a5c37ef65c3
parent56b7e67051af95bdc7b21b3a7d9333af40ee2e7f (diff)
downloadscala-c81e94b5dd39cf86abd0145fc93e0999f57a548c.tar.gz
scala-c81e94b5dd39cf86abd0145fc93e0999f57a548c.tar.bz2
scala-c81e94b5dd39cf86abd0145fc93e0999f57a548c.zip
Some minor sensibility improvements to previous...
Some minor sensibility improvements to previous patch, and tearing out some obsolete pieces of scalap. No review.
-rw-r--r--src/compiler/scala/tools/nsc/MainGenericRunner.scala14
-rw-r--r--src/compiler/scala/tools/nsc/ScalaDoc.scala31
-rw-r--r--src/scalap/scala/tools/scalap/Main.scala203
3 files changed, 89 insertions, 159 deletions
diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
index 7ead4cce4a..f2d4bacb35 100644
--- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala
+++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala
@@ -19,7 +19,7 @@ import GenericRunnerCommand._
* sources for the code to run: pre-compiled code, a script file,
* or interactive entry.
*/
-object MainGenericRunner {
+class MainGenericRunner {
def errorFn(ex: Throwable): Boolean = {
ex.printStackTrace()
false
@@ -29,11 +29,6 @@ object MainGenericRunner {
false
}
- def main(args: Array[String]) {
- if (!process(args))
- sys.exit(1)
- }
-
def process(args: Array[String]): Boolean = {
val command = new GenericRunnerCommand(args.toList, (x: String) => errorFn(x))
import command.{ settings, howToRun, thingToRun }
@@ -88,3 +83,10 @@ object MainGenericRunner {
}
}
}
+
+object MainGenericRunner extends MainGenericRunner {
+ def main(args: Array[String]) {
+ if (!process(args))
+ sys.exit(1)
+ }
+}
diff --git a/src/compiler/scala/tools/nsc/ScalaDoc.scala b/src/compiler/scala/tools/nsc/ScalaDoc.scala
index dddb027e23..da31ca833d 100644
--- a/src/compiler/scala/tools/nsc/ScalaDoc.scala
+++ b/src/compiler/scala/tools/nsc/ScalaDoc.scala
@@ -8,19 +8,10 @@ package scala.tools.nsc
import java.io.File.pathSeparator
import scala.tools.nsc.doc.DocFactory
-import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
-import scala.tools.nsc.util.FakePos //{Position}
+import scala.tools.nsc.reporters.ConsoleReporter
+import scala.tools.nsc.util.FakePos
import Properties.msilLibPath
-class ScaladocCommand(arguments: List[String], settings: doc.Settings) extends CompilerCommand(arguments, settings) {
- override def cmdName = "scaladoc"
- override def usageMsg = (
- createUsageMsg("where possible scaladoc", false, x => x.isStandard && settings.isScaladocSpecific(x.name)) +
- "\n\nStandard scalac options also available:" +
- createUsageMsg(x => x.isStandard && !settings.isScaladocSpecific(x.name))
- )
-}
-
/** The main class for scaladoc, a front-end for the Scala compiler
* that generates documentation from source files.
*/
@@ -35,12 +26,10 @@ class ScalaDoc {
// symbols just because there was an error
override def hasErrors = false
}
- val command = new ScaladocCommand(args.toList, docSettings)
+ val command = new ScalaDoc.Command(args.toList, docSettings)
if (docSettings.version.value)
reporter.info(null, versionMsg, true)
- else if (docSettings.help.value)
- reporter.info(null, command.usageMsg, true)
else if (docSettings.Xhelp.value)
reporter.info(null, command.xusageMsg, true)
else if (docSettings.Yhelp.value)
@@ -49,12 +38,13 @@ class ScalaDoc {
reporter.warning(null, "Plugins are not available when using Scaladoc")
else if (docSettings.showPhases.value)
reporter.warning(null, "Phases are restricted when using Scaladoc")
+ else if (docSettings.help.value || command.files.isEmpty)
+ reporter.info(null, command.usageMsg, true)
else try {
if (docSettings.target.value == "msil")
msilLibPath foreach (x => docSettings.assemrefs.value += (pathSeparator + x))
- if (command.files.isEmpty) reporter.info(null, command.usageMsg, true)
- else new DocFactory(reporter, docSettings) document command.files
+ new DocFactory(reporter, docSettings) document command.files
}
catch {
case ex @ FatalError(msg) =>
@@ -70,6 +60,15 @@ class ScalaDoc {
}
object ScalaDoc extends ScalaDoc {
+ class Command(arguments: List[String], settings: doc.Settings) extends CompilerCommand(arguments, settings) {
+ override def cmdName = "scaladoc"
+ override def usageMsg = (
+ createUsageMsg("where possible scaladoc", false, x => x.isStandard && settings.isScaladocSpecific(x.name)) +
+ "\n\nStandard scalac options also available:" +
+ createUsageMsg(x => x.isStandard && !settings.isScaladocSpecific(x.name))
+ )
+ }
+
def main(args: Array[String]): Unit = sys exit {
if (process(args)) 0 else 1
}
diff --git a/src/scalap/scala/tools/scalap/Main.scala b/src/scalap/scala/tools/scalap/Main.scala
index 2a2716ba20..7546fd99ae 100644
--- a/src/scalap/scala/tools/scalap/Main.scala
+++ b/src/scalap/scala/tools/scalap/Main.scala
@@ -5,50 +5,33 @@
**
*/
-
package scala.tools.scalap
-import java.io.{PrintStream, OutputStreamWriter, ByteArrayOutputStream}
+import java.io.{ PrintStream, OutputStreamWriter, ByteArrayOutputStream }
import scalax.rules.scalasig._
import tools.nsc.util.{ ClassPath, JavaClassPath }
import tools.util.PathResolver
import ClassPath.DefaultJavaContext
-import tools.nsc.io.{PlainFile, AbstractFile}
+import tools.nsc.io.{ PlainFile, AbstractFile }
/**The main object used to execute scalap on the command-line.
*
* @author Matthias Zenger, Stephane Micheloud, Burak Emir, Ilya Sergey
*/
-object Main {
- val SCALA_SIG = "ScalaSig"
+class Main {
+ val SCALA_SIG = "ScalaSig"
val SCALA_SIG_ANNOTATION = "Lscala/reflect/ScalaSignature;"
- val BYTES_VALUE = "bytes"
+ val BYTES_VALUE = "bytes"
- val versionMsg = "Scala classfile decoder " +
- Properties.versionString + " -- " +
- Properties.copyrightString + "\n"
+ val versionMsg = "Scala classfile decoder %s -- %s\n".format(Properties.versionString, Properties.copyrightString)
/**Verbose program run?
*/
var verbose = false
var printPrivates = false
- /**Prints usage information for scalap.
- */
- def usage {
- Console.println("usage: scalap {<option>} <name>")
- Console.println("where <name> is fully-qualified class name or <package_name>.package for package objects")
- Console.println("and <option> is")
- Console.println(" -private print private definitions")
- Console.println(" -verbose print out additional information")
- Console.println(" -version print out the version number of scalap")
- Console.println(" -help display this usage message")
- Console.println(" -classpath <path> specify where to find user class files")
- Console.println(" -cp <path> specify where to find user class files")
- }
-
def isScalaFile(bytes: Array[Byte]): Boolean = {
- val byteCode = ByteCode(bytes)
+ val byteCode = ByteCode(bytes)
val classFile = ClassFileParser.parse(byteCode)
classFile.attribute("ScalaSig").isDefined
}
@@ -69,11 +52,12 @@ object Main {
def isPackageObjectFile(s: String) = s != null && (s.endsWith(".package") || s == "package")
def parseScalaSignature(scalaSig: ScalaSig, isPackageObject: Boolean) = {
- val baos = new ByteArrayOutputStream
+ val baos = new ByteArrayOutputStream
val stream = new PrintStream(baos)
- val syms = scalaSig.topLevelClasses ::: scalaSig.topLevelObjects
+ val syms = scalaSig.topLevelClasses ++ scalaSig.topLevelObjects
+
syms.head.parent match {
- //Partial match
+ // Partial match
case Some(p) if (p.name != "<empty>") => {
val path = p.path
if (!isPackageObject) {
@@ -93,9 +77,7 @@ object Main {
}
// Print classes
val printer = new ScalaSigPrinter(stream, printPrivates)
- for (c <- syms) {
- printer.printSymbol(c)
- }
+ syms foreach (printer printSymbol _)
baos.toString
}
@@ -109,12 +91,8 @@ object Main {
}
}
- /**Executes scalap with the given arguments and classpath for the
- * class denoted by <code>classname</code>.
- *
- * @param args...
- * @param path...
- * @param classname...
+ /** Executes scalap with the given arguments and classpath for the
+ * class denoted by `classname`.
*/
def process(args: Arguments, path: ClassPath[AbstractFile])(classname: String): Unit = {
// find the classfile
@@ -159,67 +137,6 @@ object Main {
Console.println(" def toString(): java.lang.String")
Console.println("}")
// if the class corresponds to the artificial class scala.AnyVal.
- } else if (classname == "scala.AnyVal") {
- Console.println("package scala")
- Console.println("sealed class AnyVal extends Any")
- // if the class corresponds to the artificial class scala.Boolean.
- } else if (classname == "scala.Boolean") {
- Console.println("package scala")
- Console.println("sealed abstract class Boolean extends AnyVal {")
- Console.println(" def &&(p: => scala.Boolean): scala.Boolean // boolean and")
- Console.println(" def ||(p: => scala.Boolean): scala.Boolean // boolean or")
- Console.println(" def & (x: scala.Boolean): scala.Boolean // boolean strict and")
- Console.println(" def | (x: scala.Boolean): scala.Boolean // boolean stric or")
- Console.println(" def ==(x: scala.Boolean): scala.Boolean // boolean equality")
- Console.println(" def !=(x: scala.Boolean): scala.Boolean // boolean inequality")
- Console.println(" def !: scala.Boolean // boolean negation")
- Console.println("}")
- // if the class corresponds to the artificial class scala.Int.
- } else if (classname == "scala.Int") {
- Console.println("package scala")
- Console.println("sealed abstract class Int extends AnyVal {")
- Console.println(" def ==(that: scala.Double): scala.Boolean")
- Console.println(" def ==(that: scala.Float): scala.Boolean")
- Console.println(" def ==(that: scala.Long): scala.Boolean")
- Console.println(" def ==(that: scala.Int): scala.Boolean")
- Console.println(" def ==(that: scala.Short): scala.Boolean")
- Console.println(" def ==(that: scala.Byte): scala.Boolean")
- Console.println(" def ==(that: scala.Char): scala.Boolean")
- Console.println(" /* analogous for !=, <, >, <=, >= */")
- Console.println
- Console.println(" def + (that: scala.Double): scala.Double // double addition")
- Console.println(" def + (that: scala.Float): scala.Float // float addition")
- Console.println(" def + (that: scala.Long): scala.Long // long addition")
- Console.println(" def + (that: scala.Int): scala.Int // int addition")
- Console.println(" def + (that: scala.Short): scala.Int // int addition")
- Console.println(" def + (that: scala.Byte): scala.Int // int addition")
- Console.println(" def + (that: scala.Char): scala.Int // int addition")
- Console.println(" /* analogous for -, *, /, % */")
- Console.println
- Console.println(" def & (that: scala.Long): scala.Long // long bitwise and")
- Console.println(" def & (that: scala.Int): scala.Int // int bitwise and")
- Console.println(" def & (that: scala.Short): scala.Int // int bitwise and")
- Console.println(" def & (that: scala.Byte): scala.Int // int bitwise and")
- Console.println(" def & (that: scala.Char): scala.Int // int bitwise and")
- Console.println(" /* analogous for |, ^ */")
- Console.println
- Console.println(" def <<(cnt: scala.Int): scala.Int // int left shift")
- Console.println(" def <<(cnt: scala.Long): scala.Int // long left shift")
- Console.println(" /* analogous for >>, >>> */")
- Console.println
- Console.println(" def + : scala.Int // int identity")
- Console.println(" def - : scala.Int // int negation")
- Console.println(" def ~ : scala.Int // int bitwise negation")
- Console.println
- Console.println(" def toByte: scala.Byte // convert to Byte")
- Console.println(" def toShort: scala.Short // convert to Short")
- Console.println(" def toChar: scala.Char // convert to Char")
- Console.println(" def toInt: scala.Int // convert to Int")
- Console.println(" def toLong: scala.Long // convert to Long")
- Console.println(" def toFloat: scala.Float // convert to Float")
- Console.println(" def toDouble: scala.Double // convert to Double")
- Console.println("}")
- // if the class corresponds to the artificial class scala.Nothing.
} else if (classname == "scala.Nothing") {
Console.println("package scala")
Console.println("sealed abstract class Nothing")
@@ -231,46 +148,6 @@ object Main {
Console.println("class/object " + classname + " not found.")
}
- /**The main method of this object.
- */
- def main(args: Array[String]) {
- // print usage information if there is no command-line argument
- if (args.length == 0)
- usage
- // otherwise parse the arguments...
- else {
- val arguments = Arguments.Parser('-')
- .withOption("-private")
- .withOption("-verbose")
- .withOption("-version")
- .withOption("-help")
- .withOptionalArg("-classpath")
- .withOptionalArg("-cp")
- .parse(args);
- if (arguments contains "-version")
- Console.println(versionMsg)
- if (arguments contains "-help")
- usage
- verbose = arguments contains "-verbose"
- printPrivates = arguments contains "-private"
- // construct a custom class path
- def cparg = List("-classpath", "-cp") map (arguments getArgument _) reduceLeft (_ orElse _)
- val path = cparg match {
- case Some(cpstring) =>
- new JavaClassPath(DefaultJavaContext.classesInExpandedPath(cpstring), DefaultJavaContext)
-
- case None =>
- PathResolver.fromPathString("")
- }
- // print the classpath if output is verbose
- if (verbose)
- Console.println(Console.BOLD + "CLASSPATH" + Console.RESET + " = " + path)
-
- // process all given classes
- arguments.getOthers.foreach(process(arguments, path))
- }
- }
-
object EmptyClasspath extends ClassPath[AbstractFile] {
/**
* The short name of the package (without prefix)
@@ -284,3 +161,55 @@ object Main {
val sourcepaths: List[AbstractFile] = Nil
}
}
+
+object Main extends Main {
+ /** Prints usage information for scalap. */
+ def usage() {
+ Console println """
+ |Usage: scalap {<option>} <name>
+ |where <name> is fully-qualified class name or <package_name>.package for package objects
+ |and <option> is
+ | -private print private definitions
+ | -verbose print out additional information
+ | -version print out the version number of scalap
+ | -help display this usage message
+ | -classpath <path> specify where to find user class files
+ | -cp <path> specify where to find user class files
+ """.stripMargin.trim
+ }
+
+ def main(args: Array[String]) {
+ // print usage information if there is no command-line argument
+ if (args.isEmpty)
+ return usage()
+
+ val arguments = Arguments.Parser('-')
+ .withOption("-private")
+ .withOption("-verbose")
+ .withOption("-version")
+ .withOption("-help")
+ .withOptionalArg("-classpath")
+ .withOptionalArg("-cp")
+ .parse(args);
+
+ if (arguments contains "-version")
+ Console.println(versionMsg)
+ if (arguments contains "-help")
+ usage()
+
+ verbose = arguments contains "-verbose"
+ printPrivates = arguments contains "-private"
+ // construct a custom class path
+ val cparg = List("-classpath", "-cp") map (arguments getArgument _) reduceLeft (_ orElse _)
+ val path = cparg match {
+ case Some(cp) => new JavaClassPath(DefaultJavaContext.classesInExpandedPath(cp), DefaultJavaContext)
+ case _ => PathResolver.fromPathString("")
+ }
+ // print the classpath if output is verbose
+ if (verbose)
+ Console.println(Console.BOLD + "CLASSPATH" + Console.RESET + " = " + path)
+
+ // process all given classes
+ arguments.getOthers foreach process(arguments, path)
+ }
+}