diff options
author | Paul Phillips <paulp@improving.org> | 2012-06-04 12:05:57 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-06-06 14:23:45 -0700 |
commit | 241c7606d0bf5f3209b9d549fb751dbbc5b8e514 (patch) | |
tree | 1a9ce60b92f37cf6ca58f69a7fdcaecd90e532bb /src/library/scala/Short.scala | |
parent | a43e070e232ce35ef14fce34458ee3ea6e823078 (diff) | |
download | scala-241c7606d0bf5f3209b9d549fb751dbbc5b8e514.tar.gz scala-241c7606d0bf5f3209b9d549fb751dbbc5b8e514.tar.bz2 scala-241c7606d0bf5f3209b9d549fb751dbbc5b8e514.zip |
Generate abstract methods in scala.Byte and friends.
Rather than stub implementations. This saves over 50K of bytecode.
I also added the necessary imports to silence the feature warnings.
Diffstat (limited to 'src/library/scala/Short.scala')
-rw-r--r-- | src/library/scala/Short.scala | 229 |
1 files changed, 117 insertions, 112 deletions
diff --git a/src/library/scala/Short.scala b/src/library/scala/Short.scala index 1060a9db16..687b198a11 100644 --- a/src/library/scala/Short.scala +++ b/src/library/scala/Short.scala @@ -10,6 +10,8 @@ package scala +import language.implicitConversions + /** `Short`, a 16-bit signed integer (equivalent to Java's `short` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Short` are not * represented by an object in the underlying runtime system. @@ -17,14 +19,14 @@ package scala * There is an implicit conversion from [[scala.Short]] => [[scala.runtime.RichShort]] * which provides useful non-primitive operations. */ -final class Short private extends AnyVal { - def toByte: Byte = sys.error("stub") - def toShort: Short = sys.error("stub") - def toChar: Char = sys.error("stub") - def toInt: Int = sys.error("stub") - def toLong: Long = sys.error("stub") - def toFloat: Float = sys.error("stub") - def toDouble: Double = sys.error("stub") +final abstract class Short private extends AnyVal { + def toByte: Byte + def toShort: Short + def toChar: Char + def toInt: Int + def toLong: Long + def toFloat: Float + def toDouble: Double /** * Returns the bitwise negation of this value. @@ -34,30 +36,30 @@ final class Short private extends AnyVal { * // 11111010 * }}} */ - def unary_~ : Int = sys.error("stub") + def unary_~ : Int /** * Returns this value, unmodified. */ - def unary_+ : Int = sys.error("stub") + def unary_+ : Int /** * Returns the negation of this value. */ - def unary_- : Int = sys.error("stub") + def unary_- : Int - def +(x: String): String = sys.error("stub") + def +(x: String): String /** * Returns this value bit-shifted left by the specified number of bits, * filling in the new right bits with zeroes. * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}} */ - def <<(x: Int): Int = sys.error("stub") + def <<(x: Int): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the new right bits with zeroes. * @example {{{ 6 << 3 == 48 // in binary: 0110 << 3 == 0110000 }}} */ - def <<(x: Long): Int = sys.error("stub") + def <<(x: Long): Int /** * Returns this value bit-shifted right by the specified number of bits, * filling the new left bits with zeroes. @@ -68,7 +70,7 @@ final class Short private extends AnyVal { * // 00011111 11111111 11111111 11111101 * }}} */ - def >>>(x: Int): Int = sys.error("stub") + def >>>(x: Int): Int /** * Returns this value bit-shifted right by the specified number of bits, * filling the new left bits with zeroes. @@ -79,7 +81,7 @@ final class Short private extends AnyVal { * // 00011111 11111111 11111111 11111101 * }}} */ - def >>>(x: Long): Int = sys.error("stub") + def >>>(x: Long): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the right bits with the same value as the left-most bit of this. @@ -90,7 +92,7 @@ final class Short private extends AnyVal { * // 11111111 11111111 11111111 11111101 * }}} */ - def >>(x: Int): Int = sys.error("stub") + def >>(x: Int): Int /** * Returns this value bit-shifted left by the specified number of bits, * filling in the right bits with the same value as the left-most bit of this. @@ -101,181 +103,181 @@ final class Short private extends AnyVal { * // 11111111 11111111 11111111 11111101 * }}} */ - def >>(x: Long): Int = sys.error("stub") + def >>(x: Long): Int /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Byte): Boolean = sys.error("stub") + def ==(x: Byte): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Short): Boolean = sys.error("stub") + def ==(x: Short): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Char): Boolean = sys.error("stub") + def ==(x: Char): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Int): Boolean = sys.error("stub") + def ==(x: Int): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Long): Boolean = sys.error("stub") + def ==(x: Long): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Float): Boolean = sys.error("stub") + def ==(x: Float): Boolean /** * Returns `true` if this value is equal to x, `false` otherwise. */ - def ==(x: Double): Boolean = sys.error("stub") + def ==(x: Double): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Byte): Boolean = sys.error("stub") + def !=(x: Byte): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Short): Boolean = sys.error("stub") + def !=(x: Short): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Char): Boolean = sys.error("stub") + def !=(x: Char): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Int): Boolean = sys.error("stub") + def !=(x: Int): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Long): Boolean = sys.error("stub") + def !=(x: Long): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Float): Boolean = sys.error("stub") + def !=(x: Float): Boolean /** * Returns `true` if this value is not equal to x, `false` otherwise. */ - def !=(x: Double): Boolean = sys.error("stub") + def !=(x: Double): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Byte): Boolean = sys.error("stub") + def <(x: Byte): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Short): Boolean = sys.error("stub") + def <(x: Short): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Char): Boolean = sys.error("stub") + def <(x: Char): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Int): Boolean = sys.error("stub") + def <(x: Int): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Long): Boolean = sys.error("stub") + def <(x: Long): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Float): Boolean = sys.error("stub") + def <(x: Float): Boolean /** * Returns `true` if this value is less than x, `false` otherwise. */ - def <(x: Double): Boolean = sys.error("stub") + def <(x: Double): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Byte): Boolean = sys.error("stub") + def <=(x: Byte): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Short): Boolean = sys.error("stub") + def <=(x: Short): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Char): Boolean = sys.error("stub") + def <=(x: Char): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Int): Boolean = sys.error("stub") + def <=(x: Int): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Long): Boolean = sys.error("stub") + def <=(x: Long): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Float): Boolean = sys.error("stub") + def <=(x: Float): Boolean /** * Returns `true` if this value is less than or equal to x, `false` otherwise. */ - def <=(x: Double): Boolean = sys.error("stub") + def <=(x: Double): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Byte): Boolean = sys.error("stub") + def >(x: Byte): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Short): Boolean = sys.error("stub") + def >(x: Short): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Char): Boolean = sys.error("stub") + def >(x: Char): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Int): Boolean = sys.error("stub") + def >(x: Int): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Long): Boolean = sys.error("stub") + def >(x: Long): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Float): Boolean = sys.error("stub") + def >(x: Float): Boolean /** * Returns `true` if this value is greater than x, `false` otherwise. */ - def >(x: Double): Boolean = sys.error("stub") + def >(x: Double): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Byte): Boolean = sys.error("stub") + def >=(x: Byte): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Short): Boolean = sys.error("stub") + def >=(x: Short): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Char): Boolean = sys.error("stub") + def >=(x: Char): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Int): Boolean = sys.error("stub") + def >=(x: Int): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Long): Boolean = sys.error("stub") + def >=(x: Long): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Float): Boolean = sys.error("stub") + def >=(x: Float): Boolean /** * Returns `true` if this value is greater than or equal to x, `false` otherwise. */ - def >=(x: Double): Boolean = sys.error("stub") + def >=(x: Double): Boolean /** * Returns the bitwise OR of this value and `x`. @@ -287,7 +289,7 @@ final class Short private extends AnyVal { * // 11111010 * }}} */ - def |(x: Byte): Int = sys.error("stub") + def |(x: Byte): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -298,7 +300,7 @@ final class Short private extends AnyVal { * // 11111010 * }}} */ - def |(x: Short): Int = sys.error("stub") + def |(x: Short): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -309,7 +311,7 @@ final class Short private extends AnyVal { * // 11111010 * }}} */ - def |(x: Char): Int = sys.error("stub") + def |(x: Char): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -320,7 +322,7 @@ final class Short private extends AnyVal { * // 11111010 * }}} */ - def |(x: Int): Int = sys.error("stub") + def |(x: Int): Int /** * Returns the bitwise OR of this value and `x`. * @example {{{ @@ -331,7 +333,7 @@ final class Short private extends AnyVal { * // 11111010 * }}} */ - def |(x: Long): Long = sys.error("stub") + def |(x: Long): Long /** * Returns the bitwise AND of this value and `x`. @@ -343,7 +345,7 @@ final class Short private extends AnyVal { * // 10100000 * }}} */ - def &(x: Byte): Int = sys.error("stub") + def &(x: Byte): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -354,7 +356,7 @@ final class Short private extends AnyVal { * // 10100000 * }}} */ - def &(x: Short): Int = sys.error("stub") + def &(x: Short): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -365,7 +367,7 @@ final class Short private extends AnyVal { * // 10100000 * }}} */ - def &(x: Char): Int = sys.error("stub") + def &(x: Char): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -376,7 +378,7 @@ final class Short private extends AnyVal { * // 10100000 * }}} */ - def &(x: Int): Int = sys.error("stub") + def &(x: Int): Int /** * Returns the bitwise AND of this value and `x`. * @example {{{ @@ -387,7 +389,7 @@ final class Short private extends AnyVal { * // 10100000 * }}} */ - def &(x: Long): Long = sys.error("stub") + def &(x: Long): Long /** * Returns the bitwise XOR of this value and `x`. @@ -399,7 +401,7 @@ final class Short private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Byte): Int = sys.error("stub") + def ^(x: Byte): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -410,7 +412,7 @@ final class Short private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Short): Int = sys.error("stub") + def ^(x: Short): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -421,7 +423,7 @@ final class Short private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Char): Int = sys.error("stub") + def ^(x: Char): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -432,7 +434,7 @@ final class Short private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Int): Int = sys.error("stub") + def ^(x: Int): Int /** * Returns the bitwise XOR of this value and `x`. * @example {{{ @@ -443,157 +445,157 @@ final class Short private extends AnyVal { * // 01011010 * }}} */ - def ^(x: Long): Long = sys.error("stub") + def ^(x: Long): Long /** * Returns the sum of this value and `x`. */ - def +(x: Byte): Int = sys.error("stub") + def +(x: Byte): Int /** * Returns the sum of this value and `x`. */ - def +(x: Short): Int = sys.error("stub") + def +(x: Short): Int /** * Returns the sum of this value and `x`. */ - def +(x: Char): Int = sys.error("stub") + def +(x: Char): Int /** * Returns the sum of this value and `x`. */ - def +(x: Int): Int = sys.error("stub") + def +(x: Int): Int /** * Returns the sum of this value and `x`. */ - def +(x: Long): Long = sys.error("stub") + def +(x: Long): Long /** * Returns the sum of this value and `x`. */ - def +(x: Float): Float = sys.error("stub") + def +(x: Float): Float /** * Returns the sum of this value and `x`. */ - def +(x: Double): Double = sys.error("stub") + def +(x: Double): Double /** * Returns the difference of this value and `x`. */ - def -(x: Byte): Int = sys.error("stub") + def -(x: Byte): Int /** * Returns the difference of this value and `x`. */ - def -(x: Short): Int = sys.error("stub") + def -(x: Short): Int /** * Returns the difference of this value and `x`. */ - def -(x: Char): Int = sys.error("stub") + def -(x: Char): Int /** * Returns the difference of this value and `x`. */ - def -(x: Int): Int = sys.error("stub") + def -(x: Int): Int /** * Returns the difference of this value and `x`. */ - def -(x: Long): Long = sys.error("stub") + def -(x: Long): Long /** * Returns the difference of this value and `x`. */ - def -(x: Float): Float = sys.error("stub") + def -(x: Float): Float /** * Returns the difference of this value and `x`. */ - def -(x: Double): Double = sys.error("stub") + def -(x: Double): Double /** * Returns the product of this value and `x`. */ - def *(x: Byte): Int = sys.error("stub") + def *(x: Byte): Int /** * Returns the product of this value and `x`. */ - def *(x: Short): Int = sys.error("stub") + def *(x: Short): Int /** * Returns the product of this value and `x`. */ - def *(x: Char): Int = sys.error("stub") + def *(x: Char): Int /** * Returns the product of this value and `x`. */ - def *(x: Int): Int = sys.error("stub") + def *(x: Int): Int /** * Returns the product of this value and `x`. */ - def *(x: Long): Long = sys.error("stub") + def *(x: Long): Long /** * Returns the product of this value and `x`. */ - def *(x: Float): Float = sys.error("stub") + def *(x: Float): Float /** * Returns the product of this value and `x`. */ - def *(x: Double): Double = sys.error("stub") + def *(x: Double): Double /** * Returns the quotient of this value and `x`. */ - def /(x: Byte): Int = sys.error("stub") + def /(x: Byte): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Short): Int = sys.error("stub") + def /(x: Short): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Char): Int = sys.error("stub") + def /(x: Char): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Int): Int = sys.error("stub") + def /(x: Int): Int /** * Returns the quotient of this value and `x`. */ - def /(x: Long): Long = sys.error("stub") + def /(x: Long): Long /** * Returns the quotient of this value and `x`. */ - def /(x: Float): Float = sys.error("stub") + def /(x: Float): Float /** * Returns the quotient of this value and `x`. */ - def /(x: Double): Double = sys.error("stub") + def /(x: Double): Double /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Byte): Int = sys.error("stub") + def %(x: Byte): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Short): Int = sys.error("stub") + def %(x: Short): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Char): Int = sys.error("stub") + def %(x: Char): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Int): Int = sys.error("stub") + def %(x: Int): Int /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Long): Long = sys.error("stub") + def %(x: Long): Long /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Float): Float = sys.error("stub") + def %(x: Float): Float /** * Returns the remainder of the division of this value by `x`. */ - def %(x: Double): Double = sys.error("stub") + def %(x: Double): Double - override def getClass(): Class[Short] = sys.error("stub") + override def getClass(): Class[Short] = null } -object Short extends AnyValCompanion { +object Short extends AnyValCompanion { /** The smallest value representable as a Short. */ final val MinValue = java.lang.Short.MIN_VALUE @@ -622,6 +624,9 @@ object Short extends AnyValCompanion { /** The String representation of the scala.Short companion object. */ override def toString = "object scala.Short" + + /** Language mandated coercions from Short to "wider" types. + */ implicit def short2int(x: Short): Int = x.toInt implicit def short2long(x: Short): Long = x.toLong implicit def short2float(x: Short): Float = x.toFloat |