summaryrefslogtreecommitdiff
path: root/sources/scala/tools/nsc/Settings.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2005-02-04 13:04:57 +0000
committerMartin Odersky <odersky@gmail.com>2005-02-04 13:04:57 +0000
commit4ab12055ef6a548afdf1b9d583c291b74d3630bc (patch)
treef678ed874115f2654a7ec0398ddf027c0803a707 /sources/scala/tools/nsc/Settings.scala
parent204dbd6dacd0bd3c16c3266b98673e4a630932ce (diff)
downloadscala-4ab12055ef6a548afdf1b9d583c291b74d3630bc.tar.gz
scala-4ab12055ef6a548afdf1b9d583c291b74d3630bc.tar.bz2
scala-4ab12055ef6a548afdf1b9d583c291b74d3630bc.zip
*** empty log message ***
Diffstat (limited to 'sources/scala/tools/nsc/Settings.scala')
-rw-r--r--sources/scala/tools/nsc/Settings.scala155
1 files changed, 155 insertions, 0 deletions
diff --git a/sources/scala/tools/nsc/Settings.scala b/sources/scala/tools/nsc/Settings.scala
new file mode 100644
index 0000000000..7820f0adcb
--- /dev/null
+++ b/sources/scala/tools/nsc/Settings.scala
@@ -0,0 +1,155 @@
+package scala.tools.nsc;
+
+class Settings(error: String => unit) {
+
+ private var allsettings: List[Setting] = List();
+
+ val debuginfo = BooleanSetting("-g", "Generate debugging info");
+ val nowarnings = BooleanSetting("-nowarn", "Generate no warnings");
+ val verbose = BooleanSetting("-verbose", "Output messages about what the compiler is doing");
+ val classpath = StringSetting ("-classpath", "path", "Specify where to find user class files",
+ System.getProperty("scala.class.path",
+ System.getProperty("java.class.path", ".")));
+ val sourcepath = StringSetting ("-sourcepath", "path", "Specify where to find input source files",
+ System.getProperty("scala.source.path",
+ System.getProperty("java.source.path", ".")));
+ val bootclasspath = StringSetting ("-bootclasspath", "path", "Override location of bootstrap class files",
+ System.getProperty("sun.boot.class.path", ""));
+ val extdirs = StringSetting ("-extdirs", "dirs", "Override location of installed extensions",
+ System.getProperty("java.ext.dirs", ""));
+ val outdir = StringSetting ("-d", "directory", "Specify where to place generated class files", ".");
+ val encoding = StringSetting ("-encoding", "encoding", "Specify character encoding used by source files", "ISO-8859-1");
+ val separate = ChoiceSetting ("-separate", "Read symbol files for separate compilation", List("yes","no"), "default");
+ val target = ChoiceSetting ("-target", "Specify which backend to use", List("jvm", "msil"), "jvm");
+ val debug = BooleanSetting("-debug", "Output debugging messages");
+ val explaintypes = BooleanSetting("-explaintypes", "Explain type errors in more detail");
+ 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)");
+ val noimports = BooleanSetting("-noimports", "Compile without any implicit imports");
+ val nopredefs = BooleanSetting("-nopredefs", "Compile without any implicit predefined values");
+ val skip = PhasesSetting ("-skip", "Skip");
+ val check = PhasesSetting ("-check", "Check the tree after");
+ val print = PhasesSetting ("-print", "Print out program after");
+ val printer = ChoiceSetting ("-printer", "Printer to use", List("text", "html"), "text");
+ val printfile = StringSetting ("-printfile", "file", "Specify file in which to print trees", "-");
+ val graph = PhasesSetting ("-graph", "Graph the program after");
+ val stop = PhasesSetting ("-stop", "Stop after first phase in");
+ val log = PhasesSetting ("-log", "Log operations in");
+ val version = BooleanSetting("-version", "Print product version and exit");
+ val help = BooleanSetting("-help", "Print a synopsis of standard options");
+
+ val Xshowcls = StringSetting ("-Xshowcls", "class", "Show class info", "");
+ val Xshowobj = StringSetting ("-Xshowobj", "object", "Show object info", "");
+
+ /** A list of all settings */
+ def allSettings: List[Setting] = allsettings.reverse;
+
+ /** A base class for settings of all types.
+ * Subclasses each define a `value' field of the appropriate type.
+ */
+ abstract class Setting(name: String, descr: String) {
+
+ /** If first arg defines this setting, consume it as well as all following
+ * args needed to define the setting. If this can be done without
+ * error, set value field and return suffix of args else
+ * issue error message and return empty.
+ * If first arg does not define this setting return args unchanged.
+ */
+ def tryToSet(args: List[String]): List[String];
+
+ /** The syntax defining this setting in a help string */
+ def helpSyntax: String = name;
+
+ /** A description of the purpose of this setting in a help string */
+ def helpDescription = descr;
+
+ // initialization
+ allsettings = this :: allsettings;
+ }
+
+ /** A setting represented by a boolean flag (false, unless set */
+ case class BooleanSetting(name: String, descr: String)
+ extends Setting(name, descr) {
+ var value: boolean = false;
+
+ def tryToSet(args: List[String]): List[String] = args match {
+ case n :: rest if (n == name) => value = true; rest
+ case _ => args
+ }
+ }
+
+ /** A setting represented by a string, (`default' unless set) */
+ case class StringSetting(name: String, arg: String, descr: String, default: String)
+ extends Setting(name, descr) {
+ var value: String = default;
+
+ def tryToSet(args: List[String]): List[String] = args match {
+ case n :: rest if (n == name) =>
+ if (rest.isEmpty) {
+ error("missing argument");
+ List()
+ } else {
+ value = rest.head;
+ rest.tail
+ }
+ case _ => args
+ }
+
+ override def helpSyntax = name + " <" + arg + ">";
+ }
+
+ /** A setting represented by a string in a given set of `choices',
+ * (`default' unless set)
+ */
+ case class ChoiceSetting(name: String, descr: String, choices: List[String], default: String)
+ extends Setting(name, descr + choices.mkString(" (", ",", ")")) {
+ var value: String = default;
+
+ private def argument: String = name.substring(1);
+
+ def tryToSet(args: List[String]): List[String] = args match {
+ case n :: rest if (n startsWith (name + ":")) =>
+ val choice = n.substring(name.length() + 1);
+ if (!(choices contains choice)) {
+ error(
+ if (choice == "") "missing " + argument
+ else "unknown " + argument + " '" + choice + "'");
+ List()
+ } else {
+ value = choice;
+ rest
+ }
+ case _ => args
+ }
+
+ override def helpSyntax = name + ":<" + argument + ">";
+ }
+
+ /** A setting represented by a list of strings which should be prefixes of
+ * phase names. This is not checked here, however.
+ * (the empty list, unless set)
+ */
+ case class PhasesSetting(name: String, descr: String)
+ extends Setting(name, descr + " <phases> (see below)") {
+ var value: List[String] = List();
+
+ def tryToSet(args: List[String]): List[String] = args match {
+ case n :: rest if (n startsWith (name + ":")) =>
+ val phase = n.substring(name.length() + 1);
+ if (phase == "") {
+ error("missing phase");
+ List()
+ } else {
+ value = value ::: List(phase);
+ rest
+ }
+ case _ => args
+ }
+
+ override def helpSyntax = name + ":<phases>";
+
+ def contains(phasename: String): boolean =
+ value exists (str => phasename startsWith str)
+ }
+}