summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/scala/tools/cmd')
-rw-r--r--src/compiler/scala/tools/cmd/FromString.scala4
-rw-r--r--src/compiler/scala/tools/cmd/gen/AnyVals.scala64
2 files changed, 41 insertions, 27 deletions
diff --git a/src/compiler/scala/tools/cmd/FromString.scala b/src/compiler/scala/tools/cmd/FromString.scala
index 3792c26c34..9592e7a716 100644
--- a/src/compiler/scala/tools/cmd/FromString.scala
+++ b/src/compiler/scala/tools/cmd/FromString.scala
@@ -7,14 +7,14 @@ package scala.tools
package cmd
import nsc.io.{ Path, File, Directory }
-import scala.reflect.OptManifest
+import scala.reflect.Manifest
/** A general mechanism for defining how a command line argument
* (always a String) is transformed into an arbitrary type. A few
* example instances are in the companion object, but in general
* either IntFromString will suffice or you'll want custom transformers.
*/
-abstract class FromString[+T](implicit m: OptManifest[T]) extends PartialFunction[String, T] {
+abstract class FromString[+T](implicit m: Manifest[T]) extends PartialFunction[String, T] {
def apply(s: String): T
def isDefinedAt(s: String): Boolean = true
def zero: T = apply("")
diff --git a/src/compiler/scala/tools/cmd/gen/AnyVals.scala b/src/compiler/scala/tools/cmd/gen/AnyVals.scala
index 0869350dd3..e8230b8ca4 100644
--- a/src/compiler/scala/tools/cmd/gen/AnyVals.scala
+++ b/src/compiler/scala/tools/cmd/gen/AnyVals.scala
@@ -14,20 +14,34 @@ trait AnyValReps {
sealed abstract class AnyValNum(name: String, repr: Option[String], javaEquiv: String) extends AnyValRep(name,repr,javaEquiv) {
case class Op(val op : String, val doc : String)
+
+ private def companionCoercions(tos: String*) = {
+ tos.toList map (to =>
+ """implicit def %s2%s(x: %s): %s = x.to%s""".format(javaEquiv, to, name, to.capitalize, to.capitalize)
+ )
+ }
+ def implicitCoercions: List[String] = javaEquiv match {
+ case "byte" => companionCoercions("short", "int", "long", "float", "double")
+ case "short" | "char" => companionCoercions("int", "long", "float", "double")
+ case "int" => companionCoercions("long", "float", "double")
+ case "long" => companionCoercions("float", "double")
+ case "float" => companionCoercions("double")
+ case _ => Nil
+ }
def isCardinal: Boolean = isIntegerType(this)
def unaryOps = {
val ops = List(
Op("+", "/**\n" +
- " * @return this value, unmodified\n" +
+ " * Returns this value, unmodified.\n" +
" */"),
Op("-", "/**\n" +
- " * @return the negation of this value\n" +
+ " * Returns the negation of this value.\n" +
" */"))
if(isCardinal)
Op("~", "/**\n" +
- " * @return the bitwise negation of this value\n" +
+ " * Returns the bitwise negation of this value.\n" +
" * @example {{{\n" +
" * ~5 == -6\n" +
" * // in binary: ~00000101 ==\n" +
@@ -41,7 +55,7 @@ trait AnyValReps {
if (isCardinal)
List(
Op("|", "/**\n" +
- " * @return the bitwise OR of this value and x\n" +
+ " * Returns the bitwise OR of this value and `x`.\n" +
" * @example {{{\n" +
" * (0xf0 | 0xaa) == 0xfa\n" +
" * // in binary: 11110000\n" +
@@ -51,7 +65,7 @@ trait AnyValReps {
" * }}}\n" +
" */"),
Op("&", "/**\n" +
- " * @return the bitwise AND of this value and x\n" +
+ " * Returns the bitwise AND of this value and `x`.\n" +
" * @example {{{\n" +
" * (0xf0 & 0xaa) == 0xa0\n" +
" * // in binary: 11110000\n" +
@@ -61,7 +75,7 @@ trait AnyValReps {
" * }}}\n" +
" */"),
Op("^", "/**\n" +
- " * @return the bitwise XOR of this value and x\n" +
+ " * Returns the bitwise XOR of this value and `x`.\n" +
" * @example {{{\n" +
" * (0xf0 ^ 0xaa) == 0x5a\n" +
" * // in binary: 11110000\n" +
@@ -76,13 +90,13 @@ trait AnyValReps {
if (isCardinal)
List(
Op("<<", "/**\n" +
- " * @return this value bit-shifted left by the specified number of bits,\n" +
+ " * Returns this value bit-shifted left by the specified number of bits,\n" +
" * filling in the new right bits with zeroes.\n" +
" * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}}\n" +
" */"),
Op(">>>", "/**\n" +
- " * @return this value bit-shifted right by the specified number of bits,\n" +
+ " * Returns this value bit-shifted right by the specified number of bits,\n" +
" * filling the new left bits with zeroes.\n" +
" * @example {{{ 21 >>> 3 == 2 // in binary: 010101 >>> 3 == 010 }}}\n" +
" * @example {{{\n" +
@@ -93,7 +107,7 @@ trait AnyValReps {
" */"),
Op(">>", "/**\n" +
- " * @return this value bit-shifted left by the specified number of bits,\n" +
+ " * Returns this value bit-shifted left by the specified number of bits,\n" +
" * filling in the right bits with the same value as the left-most bit of this.\n" +
" * The effect of this is to retain the sign of the value.\n" +
" * @example {{{\n" +
@@ -105,19 +119,19 @@ trait AnyValReps {
else Nil
def comparisonOps = List(
- Op("==", "/**\n * @return `true` if this value is equal x, `false` otherwise\n */"),
- Op("!=", "/**\n * @return `true` if this value is not equal to x, `false` otherwise\n */"),
- Op("<", "/**\n * @return `true` if this value is less than x, `false` otherwise\n */"),
- Op("<=", "/**\n * @return `true` if this value is less than or equal to x, `false` otherwise\n */"),
- Op(">", "/**\n * @return `true` if this value is greater than x, `false` otherwise\n */"),
- Op(">=", "/**\n * @return `true` if this value is greater than or equal to x, `false` otherwise\n */"))
+ Op("==", "/**\n * Returns `true` if this value is equal to x, `false` otherwise.\n */"),
+ Op("!=", "/**\n * Returns `true` if this value is not equal to x, `false` otherwise.\n */"),
+ Op("<", "/**\n * Returns `true` if this value is less than x, `false` otherwise.\n */"),
+ Op("<=", "/**\n * Returns `true` if this value is less than or equal to x, `false` otherwise.\n */"),
+ Op(">", "/**\n * Returns `true` if this value is greater than x, `false` otherwise.\n */"),
+ Op(">=", "/**\n * Returns `true` if this value is greater than or equal to x, `false` otherwise.\n */"))
def otherOps = List(
- Op("+", "/**\n * @return the sum of this value and x\n */"),
- Op("-", "/**\n * @return the difference of this value and x\n */"),
- Op("*", "/**\n * @return the product of this value and x\n */"),
- Op("/", "/**\n * @return the quotient of this value and x\n */"),
- Op("%", "/**\n * @return the remainder of the division of this value by x\n */"))
+ Op("+", "/**\n * Returns the sum of this value and `x`.\n */"),
+ Op("-", "/**\n * Returns the difference of this value and `x`.\n */"),
+ Op("*", "/**\n * Returns the product of this value and `x`.\n */"),
+ Op("/", "/**\n * Returns the quotient of this value and `x`.\n */"),
+ Op("%", "/**\n * Returns the remainder of the division of this value by `x`.\n */"))
// Given two numeric value types S and T , the operation type of S and T is defined as follows:
// If both S and T are subrange types then the operation type of S and T is Int.
@@ -160,7 +174,7 @@ trait AnyValReps {
}
def objectLines = {
val comp = if (isCardinal) cardinalCompanion else floatingCompanion
- (comp + allCompanions).trim.lines map interpolate toList
+ ((comp + allCompanions).trim.lines map interpolate).toList ++ implicitCoercions
}
/** Makes a set of binary operations based on the given set of ops, args, and resultFn.
@@ -224,8 +238,8 @@ trait AnyValReps {
def classDoc = interpolate(classDocTemplate)
def objectDoc = ""
def mkImports = ""
- def mkClass = assemble("final class", "AnyVal", classLines) + "\n"
- def mkObject = assemble("object", "AnyValCompanion", objectLines) + "\n"
+ def mkClass = assemble("final class", "private", "AnyVal", classLines) + "\n"
+ def mkObject = assemble("object", "", "AnyValCompanion", objectLines) + "\n"
def make() = List[String](
headerTemplate,
mkImports,
@@ -235,8 +249,8 @@ trait AnyValReps {
mkObject
) mkString ""
- def assemble(what: String, parent: String, lines: List[String]): String = {
- val decl = "%s %s extends %s ".format(what, name, parent)
+ def assemble(what: String, ctor: String, parent: String, lines: List[String]): String = {
+ val decl = "%s %s %s extends %s ".format(what, name, ctor, parent)
val body = if (lines.isEmpty) "{ }\n\n" else lines map indent mkString ("{\n", "\n", "\n}\n")
decl + body