From 7943084a2d06e21f112b4efd0ab70ec6e38ce510 Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Fri, 5 Jul 2013 14:37:48 +0200 Subject: SI-7624 Fix -feature warnings and build with -feature I added a language.existential import to LazyCombiner.scala which should not be necessary, but causes a spurious warning otherwise: scala/src/library/scala/collection/parallel/mutable/LazyCombiner.scala:33: warning: the existential type scala.collection.parallel.mutable.LazyCombiner[_$1,_$2,_$3] forSome { type _$1; type _$2; type _$3 <: scala.collection.generic.Growable[_$1] with scala.collection.generic.Sizing }, which cannot be expressed by wildcards, should be enabled by making the implicit value scala.language.existentials visible. if (other.isInstanceOf[LazyCombiner[_, _, _]]) { ^ I created ticket SI-7750 to track this issue. --- .../scala/tools/nsc/typechecker/Contexts.scala | 1 + src/compiler/scala/tools/nsc/typechecker/Infer.scala | 2 +- .../collection/parallel/mutable/LazyCombiner.scala | 1 + src/reflect/scala/reflect/internal/Kinds.scala | 20 ++++++++++---------- .../scala/reflect/internal/transform/Erasure.scala | 2 +- .../reflect/internal/util/ScalaClassLoader.scala | 4 ++-- .../scala/reflect/internal/util/TriState.scala | 2 ++ .../scala/tools/nsc/doc/model/ModelFactory.scala | 9 ++++----- src/xml/scala/xml/Elem.scala | 1 + 9 files changed, 23 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 1b6443a4cb..f3a22a2cee 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -1340,6 +1340,7 @@ trait Contexts { self: Analyzer => } object ContextMode { + import scala.language.implicitConversions private implicit def liftIntBitsToContextState(bits: Int): ContextMode = apply(bits) def apply(bits: Int): ContextMode = new ContextMode(bits) final val NOmode: ContextMode = 0 diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 06892053fa..8ca0d82e93 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -700,7 +700,7 @@ trait Infer extends Checkable { tp nonPrivateMember nme.apply match { case NoSymbol => tp case sym if !sym.isOverloaded && sym.isPublic => OverloadedType(tp, sym.alternatives) - case sym => OverloadedType(tp, sym filter (_.isPublic) alternatives) + case sym => OverloadedType(tp, sym.filter(_.isPublic).alternatives) } } diff --git a/src/library/scala/collection/parallel/mutable/LazyCombiner.scala b/src/library/scala/collection/parallel/mutable/LazyCombiner.scala index cc25b5b4b2..5ab2bb81c6 100644 --- a/src/library/scala/collection/parallel/mutable/LazyCombiner.scala +++ b/src/library/scala/collection/parallel/mutable/LazyCombiner.scala @@ -30,6 +30,7 @@ trait LazyCombiner[Elem, +To, Buff <: Growable[Elem] with Sizing] extends Combin def result: To = allocateAndCopy def clear() = { chain.clear() } def combine[N <: Elem, NewTo >: To](other: Combiner[N, NewTo]): Combiner[N, NewTo] = if (this ne other) { + import language.existentials // FIXME: See SI-7750 if (other.isInstanceOf[LazyCombiner[_, _, _]]) { val that = other.asInstanceOf[LazyCombiner[Elem, To, Buff]] newLazyCombiner(chain ++= that.chain) diff --git a/src/reflect/scala/reflect/internal/Kinds.scala b/src/reflect/scala/reflect/internal/Kinds.scala index 46a95c7d26..315bf7e9c4 100644 --- a/src/reflect/scala/reflect/internal/Kinds.scala +++ b/src/reflect/scala/reflect/internal/Kinds.scala @@ -233,7 +233,7 @@ trait Kinds { /** * The data structure describing the kind of a given type. - * + * * Proper types are represented using ProperTypeKind. * * Type constructors are reprented using TypeConKind. @@ -251,7 +251,7 @@ trait Kinds { * it uses prescribed letters for each level: A, F, X, Y, Z. */ def scalaNotation: String - + /** Kind notation used in http://adriaanm.github.com/files/higher.pdf. * Proper types are expressed as *. * Type constructors are expressed * -> *(lo, hi) -(+)-> *. @@ -261,13 +261,13 @@ trait Kinds { /** Contains bounds either as part of itself or its arguments. */ def hasBounds: Boolean = !bounds.isEmptyBounds - + private[internal] def buildState(sym: Symbol, v: Variance)(s: StringState): StringState } object Kind { private[internal] sealed trait ScalaNotation private[internal] sealed case class Head(order: Int, n: Option[Int], alias: Option[String]) extends ScalaNotation { - override def toString: String = { + override def toString: String = { alias getOrElse { typeAlias(order) + n.map(_.toString).getOrElse("") } @@ -285,7 +285,7 @@ trait Kinds { } private[internal] sealed case class Text(value: String) extends ScalaNotation { override def toString: String = value - } + } private[internal] case class StringState(tokens: Seq[ScalaNotation]) { override def toString: String = tokens.mkString def append(value: String): StringState = StringState(tokens :+ Text(value)) @@ -310,7 +310,7 @@ trait Kinds { ts map { case Head(`o`, _, a) => Head(o, None, a) case t => t - } + } else ts }) } @@ -332,7 +332,7 @@ trait Kinds { val order = 0 private[internal] def buildState(sym: Symbol, v: Variance)(s: StringState): StringState = { s.append(v.symbolicString).appendHead(order, sym).append(bounds.scalaNotation(_.toString)) - } + } def scalaNotation: String = Kind.Head(order, None, None) + bounds.scalaNotation(_.toString) def starNotation: String = "*" + bounds.starNotation(_.toString) } @@ -344,7 +344,7 @@ trait Kinds { class TypeConKind(val bounds: TypeBounds, val args: Seq[TypeConKind.Argument]) extends Kind { import Kind.StringState - val order = (args map {_.kind.order} max) + 1 + val order = (args map (_.kind.order)).max + 1 def description: String = if (order == 1) "This is a type constructor: a 1st-order-kinded type." else "This is a type constructor that takes type constructor(s): a higher-kinded type." @@ -389,7 +389,7 @@ trait Kinds { */ object inferKind { import TypeConKind.Argument - + abstract class InferKind { protected def infer(tpe: Type, owner: Symbol, topLevel: Boolean): Kind protected def infer(sym: Symbol, topLevel: Boolean): Kind = infer(sym.tpeHK, sym.owner, topLevel) @@ -398,7 +398,7 @@ trait Kinds { } def apply(pre: Type): InferKind = new InferKind { - protected def infer(tpe: Type, owner: Symbol, topLevel: Boolean): Kind = { + protected def infer(tpe: Type, owner: Symbol, topLevel: Boolean): Kind = { val bounds = if (topLevel) TypeBounds.empty else tpe.asSeenFrom(pre, owner).bounds if(!tpe.isHigherKinded) ProperTypeKind(bounds) diff --git a/src/reflect/scala/reflect/internal/transform/Erasure.scala b/src/reflect/scala/reflect/internal/transform/Erasure.scala index 580ada8254..90ffe9d9e7 100644 --- a/src/reflect/scala/reflect/internal/transform/Erasure.scala +++ b/src/reflect/scala/reflect/internal/transform/Erasure.scala @@ -60,7 +60,7 @@ trait Erasure { */ protected def unboundedGenericArrayLevel(tp: Type): Int = tp match { case GenericArray(level, core) if !(core <:< AnyRefTpe) => level - case RefinedType(ps, _) if ps.nonEmpty => logResult(s"Unbounded generic level for $tp is")(ps map unboundedGenericArrayLevel max) + case RefinedType(ps, _) if ps.nonEmpty => logResult(s"Unbounded generic level for $tp is")((ps map unboundedGenericArrayLevel).max) case _ => 0 } diff --git a/src/reflect/scala/reflect/internal/util/ScalaClassLoader.scala b/src/reflect/scala/reflect/internal/util/ScalaClassLoader.scala index a7fd787dfc..63ea6e2c49 100644 --- a/src/reflect/scala/reflect/internal/util/ScalaClassLoader.scala +++ b/src/reflect/scala/reflect/internal/util/ScalaClassLoader.scala @@ -44,7 +44,7 @@ trait ScalaClassLoader extends JClassLoader { /** Create an instance of a class with this classloader */ def create(path: String): AnyRef = - tryToInitializeClass[AnyRef](path) map (_.newInstance()) orNull + tryToInitializeClass[AnyRef](path).map(_.newInstance()).orNull /** The actual bytes for a class file, or an empty array if it can't be found. */ def classBytes(className: String): Array[Byte] = classAsStream(className) match { @@ -116,7 +116,7 @@ object ScalaClassLoader { /** True if supplied class exists in supplied path */ def classExists(urls: Seq[URL], name: String): Boolean = - fromURLs(urls) tryToLoadClass name isDefined + (fromURLs(urls) tryToLoadClass name).isDefined /** Finding what jar a clazz or instance came from */ def originOfClass(x: Class[_]): Option[URL] = diff --git a/src/reflect/scala/reflect/internal/util/TriState.scala b/src/reflect/scala/reflect/internal/util/TriState.scala index c7a35d4637..4074d974d2 100644 --- a/src/reflect/scala/reflect/internal/util/TriState.scala +++ b/src/reflect/scala/reflect/internal/util/TriState.scala @@ -3,6 +3,8 @@ package reflect package internal package util +import scala.language.implicitConversions + import TriState._ /** A simple true/false/unknown value, for those days when diff --git a/src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala b/src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala index c4e3c115be..8f217e087c 100644 --- a/src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala +++ b/src/scaladoc/scala/tools/nsc/doc/model/ModelFactory.scala @@ -305,10 +305,9 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { else None } + private def templateAndType(ancestor: Symbol): (TemplateImpl, TypeEntity) = (makeTemplate(ancestor), makeType(reprSymbol.info.baseType(ancestor), this)) lazy val (linearizationTemplates, linearizationTypes) = - reprSymbol.ancestors map { ancestor => - (makeTemplate(ancestor), makeType(reprSymbol.info.baseType(ancestor), this)) - } unzip + (reprSymbol.ancestors map templateAndType).unzip /* Subclass cache */ private lazy val subClassesCache = ( @@ -321,7 +320,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { } def directSubClasses = if (subClassesCache == null) Nil else subClassesCache.toList - /* Implcitly convertible class cache */ + /* Implicitly convertible class cache */ private var implicitlyConvertibleClassesCache: mutable.ListBuffer[(DocTemplateImpl, ImplicitConversionImpl)] = null def registerImplicitlyConvertibleClass(dtpl: DocTemplateImpl, conv: ImplicitConversionImpl): Unit = { if (implicitlyConvertibleClassesCache == null) @@ -841,7 +840,7 @@ class ModelFactory(val global: Global, val settings: doc.Settings) { def value = tree } } - case None => + case None => argTrees map { tree => new ValueArgument { def parameter = None diff --git a/src/xml/scala/xml/Elem.scala b/src/xml/scala/xml/Elem.scala index 484cf98744..e9b87e516c 100755 --- a/src/xml/scala/xml/Elem.scala +++ b/src/xml/scala/xml/Elem.scala @@ -37,6 +37,7 @@ object Elem { } import scala.sys.process._ + import scala.language.implicitConversions /** Implicitly convert a [[scala.xml.Elem]] into a * [[scala.sys.process.ProcessBuilder]]. This is done by obtaining the text * elements of the element, trimming spaces, and then converting the result -- cgit v1.2.3 From 91fcafe282c5e9e1a45638247a480d1f215a504f Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Mon, 29 Jul 2013 16:11:16 +0200 Subject: Formatting fixes for AnyVal The files are not regenerated here, because additional fixes will follow in the next commit. --- src/compiler/scala/tools/cmd/gen/AnyVals.scala | 101 ++++++++++--------------- 1 file changed, 42 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/cmd/gen/AnyVals.scala b/src/compiler/scala/tools/cmd/gen/AnyVals.scala index 7e01afac2b..ce2019725f 100644 --- a/src/compiler/scala/tools/cmd/gen/AnyVals.scala +++ b/src/compiler/scala/tools/cmd/gen/AnyVals.scala @@ -6,24 +6,21 @@ package scala.tools.cmd package gen -/** Code generation of the AnyVal types and their companions. - */ +/** Code generation of the AnyVal types and their companions. */ trait AnyValReps { self: AnyVals => - sealed abstract class AnyValNum(name: String, repr: Option[String], javaEquiv: String) extends AnyValRep(name,repr,javaEquiv) { + sealed abstract class AnyValNum(name: String, repr: Option[String], javaEquiv: String) + extends AnyValRep(name,repr,javaEquiv) { case class Op(op : String, doc : String) private def companionCoercions(tos: AnyValRep*) = { tos.toList map (to => - """implicit def @javaequiv@2%s(x: @name@): %s = x.to%s""".format(to.javaEquiv, to.name, to.name) + s"implicit def @javaequiv@2${to.javaEquiv}(x: @name@): ${to.name} = x.to${to.name}" ) } - def coercionCommentExtra = "" - def coercionComment = """ -/** Language mandated coercions from @name@ to "wider" types.%s - */""".format(coercionCommentExtra) + def coercionComment = """/** Language mandated coercions from @name@ to "wider" types. */""" def implicitCoercions: List[String] = { val coercions = this match { @@ -41,12 +38,8 @@ trait AnyValReps { def isCardinal: Boolean = isIntegerType(this) def unaryOps = { val ops = List( - Op("+", "/**\n" + - " * Returns this value, unmodified.\n" + - " */"), - Op("-", "/**\n" + - " * Returns the negation of this value.\n" + - " */")) + Op("+", "/** Returns this value, unmodified. */"), + Op("-", "/** Returns the negation of this value. */")) if(isCardinal) Op("~", "/**\n" + @@ -95,7 +88,7 @@ trait AnyValReps { " */")) else Nil - def shiftOps = + def shiftOps = if (isCardinal) List( Op("<<", "/**\n" + @@ -127,20 +120,20 @@ trait AnyValReps { " */")) else Nil - def comparisonOps = List( - 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 comparisonOps = List( + Op("==", "/** Returns `true` if this value is equal to x, `false` otherwise. */"), + Op("!=", "/** Returns `true` if this value is not equal to x, `false` otherwise. */"), + Op("<", "/** Returns `true` if this value is less than x, `false` otherwise. */"), + Op("<=", "/** Returns `true` if this value is less than or equal to x, `false` otherwise. */"), + Op(">", "/** Returns `true` if this value is greater than x, `false` otherwise. */"), + Op(">=", "/** Returns `true` if this value is greater than or equal to x, `false` otherwise. */")) def otherOps = List( - 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 */")) + Op("+", "/** Returns the sum of this value and `x`. */"), + Op("-", "/** Returns the difference of this value and `x`. */"), + Op("*", "/** Returns the product of this value and `x`. */"), + Op("/", "/** Returns the quotient of this value and `x`. */"), + Op("%", "/** Returns the remainder of the division of this value by `x`. */")) // 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. @@ -278,8 +271,7 @@ trait AnyValReps { } trait AnyValTemplates { - def headerTemplate = (""" -/* __ *\ + def headerTemplate = """/* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** @@ -287,12 +279,15 @@ trait AnyValTemplates { ** |/ ** \* */ -%s +// DO NOT EDIT, CHANGES WILL BE LOST +// This auto-generated code can be modified in scala.tools.cmd.gen. +// Afterwards, running tools/codegen-anyvals regenerates this source file. + package scala import scala.language.implicitConversions -""".trim.format(timestampString) + "\n\n") +""" def classDocTemplate = (""" /** `@name@`@representation@ (equivalent to Java's `@javaequiv@` primitive type) is a @@ -304,8 +299,6 @@ import scala.language.implicitConversions */ """.trim + "\n") - def timestampString = "// DO NOT EDIT, CHANGES WILL BE LOST.\n" - def allCompanions = """ /** Transform a value type into a boxed reference type. *@boxRunTimeDoc@ @@ -324,20 +317,17 @@ def box(x: @name@): @boxed@ = @boxImpl@ */ def unbox(x: java.lang.Object): @name@ = @unboxImpl@ -/** The String representation of the scala.@name@ companion object. - */ +/** The String representation of the scala.@name@ companion object. */ override def toString = "object scala.@name@" """ def nonUnitCompanions = "" // todo def cardinalCompanion = """ -/** The smallest value representable as a @name@. - */ +/** The smallest value representable as a @name@. */ final val MinValue = @boxed@.MIN_VALUE -/** The largest value representable as a @name@. - */ +/** The largest value representable as a @name@. */ final val MaxValue = @boxed@.MAX_VALUE """ @@ -372,18 +362,16 @@ class AnyVals extends AnyValReps with AnyValTemplates { object D extends AnyValNum("Double", Some("64-bit IEEE-754 floating point number"), "double") object Z extends AnyValRep("Boolean", None, "boolean") { def classLines = """ -/** - * Negates a Boolean expression. - * - * - `!a` results in `false` if and only if `a` evaluates to `true` and - * - `!a` results in `true` if and only if `a` evaluates to `false`. - * - * @return the negated expression - */ +/** Negates a Boolean expression. + * + * - `!a` results in `false` if and only if `a` evaluates to `true` and + * - `!a` results in `true` if and only if `a` evaluates to `false`. + * + * @return the negated expression + */ def unary_! : Boolean -/** - * Compares two Boolean expressions and returns `true` if they evaluate to the same value. +/** Compares two Boolean expressions and returns `true` if they evaluate to the same value. * * `a == b` returns `true` if and only if * - `a` and `b` are `true` or @@ -400,8 +388,7 @@ def ==(x: Boolean): Boolean */ def !=(x: Boolean): Boolean -/** - * Compares two Boolean expressions and returns `true` if one or both of them evaluate to true. +/** Compares two Boolean expressions and returns `true` if one or both of them evaluate to true. * * `a || b` returns `true` if and only if * - `a` is `true` or @@ -414,8 +401,7 @@ def !=(x: Boolean): Boolean */ def ||(x: Boolean): Boolean -/** - * Compares two Boolean expressions and returns `true` if both of them evaluate to true. +/** Compares two Boolean expressions and returns `true` if both of them evaluate to true. * * `a && b` returns `true` if and only if * - `a` and `b` are `true`. @@ -430,8 +416,7 @@ def &&(x: Boolean): Boolean // def ||(x: => Boolean): Boolean // def &&(x: => Boolean): Boolean -/** - * Compares two Boolean expressions and returns `true` if one or both of them evaluate to true. +/** Compares two Boolean expressions and returns `true` if one or both of them evaluate to true. * * `a | b` returns `true` if and only if * - `a` is `true` or @@ -442,8 +427,7 @@ def &&(x: Boolean): Boolean */ def |(x: Boolean): Boolean -/** - * Compares two Boolean expressions and returns `true` if both of them evaluate to true. +/** Compares two Boolean expressions and returns `true` if both of them evaluate to true. * * `a & b` returns `true` if and only if * - `a` and `b` are `true`. @@ -452,8 +436,7 @@ def |(x: Boolean): Boolean */ def &(x: Boolean): Boolean -/** - * Compares two Boolean expressions and returns `true` if they evaluate to a different value. +/** Compares two Boolean expressions and returns `true` if they evaluate to a different value. * * `a ^ b` returns `true` if and only if * - `a` is `true` and `b` is `false` or -- cgit v1.2.3 From f670e28d4da648511063c6825905c4960ee94445 Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Mon, 29 Jul 2013 16:16:38 +0200 Subject: SI-7624 Fix -Xlint warnings in AnyVal-related code The changes are actually pretty small: scala.language.implicitConversions is moved around so that it is only emitted to the source file if there is an actual implicit conversion. The rest of the diff are mostly the new generated source files reflecting that change. --- src/compiler/scala/tools/cmd/gen/AnyVals.scala | 8 +- src/compiler/scala/tools/cmd/gen/Codegen.scala | 6 +- src/library/scala/Boolean.scala | 42 ++-- src/library/scala/Byte.scala | 336 +++++++------------------ src/library/scala/Char.scala | 336 +++++++------------------ src/library/scala/Double.scala | 325 ++++++------------------ src/library/scala/Float.scala | 330 +++++++----------------- src/library/scala/Int.scala | 336 +++++++------------------ src/library/scala/Long.scala | 336 +++++++------------------ src/library/scala/Short.scala | 336 +++++++------------------ src/library/scala/Unit.scala | 9 +- 11 files changed, 629 insertions(+), 1771 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/cmd/gen/AnyVals.scala b/src/compiler/scala/tools/cmd/gen/AnyVals.scala index ce2019725f..842851b4f6 100644 --- a/src/compiler/scala/tools/cmd/gen/AnyVals.scala +++ b/src/compiler/scala/tools/cmd/gen/AnyVals.scala @@ -20,7 +20,9 @@ trait AnyValReps { s"implicit def @javaequiv@2${to.javaEquiv}(x: @name@): ${to.name} = x.to${to.name}" ) } - def coercionComment = """/** Language mandated coercions from @name@ to "wider" types. */""" + def coercionComment = +"""/** Language mandated coercions from @name@ to "wider" types. */ +import scala.language.implicitConversions""" def implicitCoercions: List[String] = { val coercions = this match { @@ -285,8 +287,6 @@ trait AnyValTemplates { package scala -import scala.language.implicitConversions - """ def classDocTemplate = (""" @@ -482,5 +482,3 @@ override def getClass(): Class[Boolean] = null def make() = values map (x => (x.name, x.make())) } - -object AnyVals extends AnyVals { } diff --git a/src/compiler/scala/tools/cmd/gen/Codegen.scala b/src/compiler/scala/tools/cmd/gen/Codegen.scala index b49322ab4a..c3aa527ef2 100644 --- a/src/compiler/scala/tools/cmd/gen/Codegen.scala +++ b/src/compiler/scala/tools/cmd/gen/Codegen.scala @@ -6,11 +6,9 @@ package scala.tools.cmd package gen -import scala.language.postfixOps - class Codegen(args: List[String]) extends { val parsed = CodegenSpec(args: _*) -} with CodegenSpec with Instance { } +} with CodegenSpec with Instance object Codegen { def echo(msg: String) = Console println msg @@ -31,7 +29,7 @@ object Codegen { val av = new AnyVals { } av.make() foreach { case (name, code ) => - val file = out / (name + ".scala") toFile; + val file = (out / (name + ".scala")).toFile echo("Writing: " + file) file writeAll code } diff --git a/src/library/scala/Boolean.scala b/src/library/scala/Boolean.scala index ddd11257c6..53b4fb2af2 100644 --- a/src/library/scala/Boolean.scala +++ b/src/library/scala/Boolean.scala @@ -6,12 +6,12 @@ ** |/ ** \* */ -// DO NOT EDIT, CHANGES WILL BE LOST. +// DO NOT EDIT, CHANGES WILL BE LOST +// This auto-generated code can be modified in scala.tools.cmd.gen. +// Afterwards, running tools/codegen-anyvals regenerates this source file. package scala -import scala.language.implicitConversions - /** `Boolean` (equivalent to Java's `boolean` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Boolean` are not * represented by an object in the underlying runtime system. @@ -20,18 +20,16 @@ import scala.language.implicitConversions * which provides useful non-primitive operations. */ final abstract class Boolean private extends AnyVal { - /** - * Negates a Boolean expression. - * - * - `!a` results in `false` if and only if `a` evaluates to `true` and - * - `!a` results in `true` if and only if `a` evaluates to `false`. - * - * @return the negated expression - */ + /** Negates a Boolean expression. + * + * - `!a` results in `false` if and only if `a` evaluates to `true` and + * - `!a` results in `true` if and only if `a` evaluates to `false`. + * + * @return the negated expression + */ def unary_! : Boolean - /** - * Compares two Boolean expressions and returns `true` if they evaluate to the same value. + /** Compares two Boolean expressions and returns `true` if they evaluate to the same value. * * `a == b` returns `true` if and only if * - `a` and `b` are `true` or @@ -48,8 +46,7 @@ final abstract class Boolean private extends AnyVal { */ def !=(x: Boolean): Boolean - /** - * Compares two Boolean expressions and returns `true` if one or both of them evaluate to true. + /** Compares two Boolean expressions and returns `true` if one or both of them evaluate to true. * * `a || b` returns `true` if and only if * - `a` is `true` or @@ -62,8 +59,7 @@ final abstract class Boolean private extends AnyVal { */ def ||(x: Boolean): Boolean - /** - * Compares two Boolean expressions and returns `true` if both of them evaluate to true. + /** Compares two Boolean expressions and returns `true` if both of them evaluate to true. * * `a && b` returns `true` if and only if * - `a` and `b` are `true`. @@ -78,8 +74,7 @@ final abstract class Boolean private extends AnyVal { // def ||(x: => Boolean): Boolean // def &&(x: => Boolean): Boolean - /** - * Compares two Boolean expressions and returns `true` if one or both of them evaluate to true. + /** Compares two Boolean expressions and returns `true` if one or both of them evaluate to true. * * `a | b` returns `true` if and only if * - `a` is `true` or @@ -90,8 +85,7 @@ final abstract class Boolean private extends AnyVal { */ def |(x: Boolean): Boolean - /** - * Compares two Boolean expressions and returns `true` if both of them evaluate to true. + /** Compares two Boolean expressions and returns `true` if both of them evaluate to true. * * `a & b` returns `true` if and only if * - `a` and `b` are `true`. @@ -100,8 +94,7 @@ final abstract class Boolean private extends AnyVal { */ def &(x: Boolean): Boolean - /** - * Compares two Boolean expressions and returns `true` if they evaluate to a different value. + /** Compares two Boolean expressions and returns `true` if they evaluate to a different value. * * `a ^ b` returns `true` if and only if * - `a` is `true` and `b` is `false` or @@ -135,8 +128,7 @@ object Boolean extends AnyValCompanion { */ def unbox(x: java.lang.Object): Boolean = x.asInstanceOf[java.lang.Boolean].booleanValue() - /** The String representation of the scala.Boolean companion object. - */ + /** The String representation of the scala.Boolean companion object. */ override def toString = "object scala.Boolean" } diff --git a/src/library/scala/Byte.scala b/src/library/scala/Byte.scala index 2510e859c0..413231c0d1 100644 --- a/src/library/scala/Byte.scala +++ b/src/library/scala/Byte.scala @@ -6,12 +6,12 @@ ** |/ ** \* */ -// DO NOT EDIT, CHANGES WILL BE LOST. +// DO NOT EDIT, CHANGES WILL BE LOST +// This auto-generated code can be modified in scala.tools.cmd.gen. +// Afterwards, running tools/codegen-anyvals regenerates this source file. package scala -import scala.language.implicitConversions - /** `Byte`, a 8-bit signed integer (equivalent to Java's `byte` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Byte` are not * represented by an object in the underlying runtime system. @@ -37,13 +37,9 @@ final abstract class Byte private extends AnyVal { * }}} */ def unary_~ : Int - /** - * Returns this value, unmodified. - */ + /** Returns this value, unmodified. */ def unary_+ : Int - /** - * Returns the negation of this value. - */ + /** Returns the negation of this value. */ def unary_- : Int def +(x: String): String @@ -105,178 +101,94 @@ final abstract class Byte private extends AnyVal { */ def >>(x: Long): Int - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Byte): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Short): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Char): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Int): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Long): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Float): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Double): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Byte): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Short): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Char): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Int): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Long): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Float): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Double): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Byte): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Short): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Char): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Int): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Long): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Float): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Double): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Byte): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Short): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Char): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Int): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Long): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Float): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Double): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Byte): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Short): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Char): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Int): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Long): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Float): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Double): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Byte): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Short): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Char): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Int): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Long): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Float): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Double): Boolean /** @@ -447,161 +359,89 @@ final abstract class Byte private extends AnyVal { */ def ^(x: Long): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Byte): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Short): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Char): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Int): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Long): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Float): Float - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Double): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Byte): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Short): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Char): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Int): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Long): Long - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Float): Float - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Double): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Byte): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Short): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Char): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Int): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Long): Long - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Float): Float - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Double): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Byte): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Short): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Char): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Int): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Long): Long - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Float): Float - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Double): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Byte): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Short): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Char): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Int): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Long): Long - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Float): Float - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double override def getClass(): Class[Byte] = null } object Byte extends AnyValCompanion { - /** The smallest value representable as a Byte. - */ + /** The smallest value representable as a Byte. */ final val MinValue = java.lang.Byte.MIN_VALUE - /** The largest value representable as a Byte. - */ + /** The largest value representable as a Byte. */ final val MaxValue = java.lang.Byte.MAX_VALUE /** Transform a value type into a boxed reference type. @@ -625,12 +465,10 @@ object Byte extends AnyValCompanion { */ def unbox(x: java.lang.Object): Byte = x.asInstanceOf[java.lang.Byte].byteValue() - /** The String representation of the scala.Byte companion object. - */ + /** The String representation of the scala.Byte companion object. */ override def toString = "object scala.Byte" - - /** Language mandated coercions from Byte to "wider" types. - */ + /** Language mandated coercions from Byte to "wider" types. */ + import scala.language.implicitConversions implicit def byte2short(x: Byte): Short = x.toShort implicit def byte2int(x: Byte): Int = x.toInt implicit def byte2long(x: Byte): Long = x.toLong diff --git a/src/library/scala/Char.scala b/src/library/scala/Char.scala index 1c9a2ba44f..ec2d48c181 100644 --- a/src/library/scala/Char.scala +++ b/src/library/scala/Char.scala @@ -6,12 +6,12 @@ ** |/ ** \* */ -// DO NOT EDIT, CHANGES WILL BE LOST. +// DO NOT EDIT, CHANGES WILL BE LOST +// This auto-generated code can be modified in scala.tools.cmd.gen. +// Afterwards, running tools/codegen-anyvals regenerates this source file. package scala -import scala.language.implicitConversions - /** `Char`, a 16-bit unsigned integer (equivalent to Java's `char` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Char` are not * represented by an object in the underlying runtime system. @@ -37,13 +37,9 @@ final abstract class Char private extends AnyVal { * }}} */ def unary_~ : Int - /** - * Returns this value, unmodified. - */ + /** Returns this value, unmodified. */ def unary_+ : Int - /** - * Returns the negation of this value. - */ + /** Returns the negation of this value. */ def unary_- : Int def +(x: String): String @@ -105,178 +101,94 @@ final abstract class Char private extends AnyVal { */ def >>(x: Long): Int - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Byte): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Short): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Char): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Int): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Long): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Float): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Double): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Byte): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Short): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Char): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Int): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Long): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Float): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Double): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Byte): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Short): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Char): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Int): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Long): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Float): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Double): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Byte): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Short): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Char): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Int): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Long): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Float): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Double): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Byte): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Short): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Char): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Int): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Long): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Float): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Double): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Byte): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Short): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Char): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Int): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Long): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Float): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Double): Boolean /** @@ -447,161 +359,89 @@ final abstract class Char private extends AnyVal { */ def ^(x: Long): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Byte): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Short): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Char): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Int): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Long): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Float): Float - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Double): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Byte): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Short): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Char): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Int): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Long): Long - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Float): Float - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Double): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Byte): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Short): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Char): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Int): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Long): Long - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Float): Float - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Double): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Byte): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Short): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Char): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Int): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Long): Long - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Float): Float - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Double): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Byte): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Short): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Char): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Int): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Long): Long - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Float): Float - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double override def getClass(): Class[Char] = null } object Char extends AnyValCompanion { - /** The smallest value representable as a Char. - */ + /** The smallest value representable as a Char. */ final val MinValue = java.lang.Character.MIN_VALUE - /** The largest value representable as a Char. - */ + /** The largest value representable as a Char. */ final val MaxValue = java.lang.Character.MAX_VALUE /** Transform a value type into a boxed reference type. @@ -625,12 +465,10 @@ object Char extends AnyValCompanion { */ def unbox(x: java.lang.Object): Char = x.asInstanceOf[java.lang.Character].charValue() - /** The String representation of the scala.Char companion object. - */ + /** The String representation of the scala.Char companion object. */ override def toString = "object scala.Char" - - /** Language mandated coercions from Char to "wider" types. - */ + /** Language mandated coercions from Char to "wider" types. */ + import scala.language.implicitConversions implicit def char2int(x: Char): Int = x.toInt implicit def char2long(x: Char): Long = x.toLong implicit def char2float(x: Char): Float = x.toFloat diff --git a/src/library/scala/Double.scala b/src/library/scala/Double.scala index ce081bbec1..a58fa3ed25 100644 --- a/src/library/scala/Double.scala +++ b/src/library/scala/Double.scala @@ -6,12 +6,12 @@ ** |/ ** \* */ -// DO NOT EDIT, CHANGES WILL BE LOST. +// DO NOT EDIT, CHANGES WILL BE LOST +// This auto-generated code can be modified in scala.tools.cmd.gen. +// Afterwards, running tools/codegen-anyvals regenerates this source file. package scala -import scala.language.implicitConversions - /** `Double`, a 64-bit IEEE-754 floating point number (equivalent to Java's `double` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Double` are not * represented by an object in the underlying runtime system. @@ -28,334 +28,176 @@ final abstract class Double private extends AnyVal { def toFloat: Float def toDouble: Double - /** - * Returns this value, unmodified. - */ + /** Returns this value, unmodified. */ def unary_+ : Double - /** - * Returns the negation of this value. - */ + /** Returns the negation of this value. */ def unary_- : Double def +(x: String): String - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Byte): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Short): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Char): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Int): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Long): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Float): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Double): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Byte): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Short): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Char): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Int): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Long): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Float): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Double): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Byte): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Short): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Char): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Int): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Long): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Float): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Double): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Byte): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Short): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Char): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Int): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Long): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Float): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Double): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Byte): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Short): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Char): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Int): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Long): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Float): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Double): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Byte): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Short): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Char): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Int): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Long): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Float): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Double): Boolean - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Byte): Double - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Short): Double - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Char): Double - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Int): Double - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Long): Double - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Float): Double - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Double): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Byte): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Short): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Char): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Int): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Long): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Float): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Double): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Byte): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Short): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Char): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Int): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Long): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Float): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Double): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Byte): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Short): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Char): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Int): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Long): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Float): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Double): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Byte): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Short): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Char): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Int): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Long): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Float): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double override def getClass(): Class[Double] = null @@ -401,8 +243,7 @@ object Double extends AnyValCompanion { */ def unbox(x: java.lang.Object): Double = x.asInstanceOf[java.lang.Double].doubleValue() - /** The String representation of the scala.Double companion object. - */ + /** The String representation of the scala.Double companion object. */ override def toString = "object scala.Double" } diff --git a/src/library/scala/Float.scala b/src/library/scala/Float.scala index 4ff2d509b8..3c59057a8d 100644 --- a/src/library/scala/Float.scala +++ b/src/library/scala/Float.scala @@ -6,12 +6,12 @@ ** |/ ** \* */ -// DO NOT EDIT, CHANGES WILL BE LOST. +// DO NOT EDIT, CHANGES WILL BE LOST +// This auto-generated code can be modified in scala.tools.cmd.gen. +// Afterwards, running tools/codegen-anyvals regenerates this source file. package scala -import scala.language.implicitConversions - /** `Float`, a 32-bit IEEE-754 floating point number (equivalent to Java's `float` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Float` are not * represented by an object in the underlying runtime system. @@ -28,334 +28,176 @@ final abstract class Float private extends AnyVal { def toFloat: Float def toDouble: Double - /** - * Returns this value, unmodified. - */ + /** Returns this value, unmodified. */ def unary_+ : Float - /** - * Returns the negation of this value. - */ + /** Returns the negation of this value. */ def unary_- : Float def +(x: String): String - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Byte): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Short): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Char): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Int): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Long): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Float): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Double): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Byte): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Short): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Char): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Int): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Long): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Float): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Double): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Byte): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Short): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Char): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Int): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Long): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Float): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Double): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Byte): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Short): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Char): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Int): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Long): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Float): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Double): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Byte): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Short): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Char): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Int): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Long): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Float): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Double): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Byte): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Short): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Char): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Int): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Long): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Float): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Double): Boolean - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Byte): Float - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Short): Float - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Char): Float - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Int): Float - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Long): Float - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Float): Float - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Double): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Byte): Float - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Short): Float - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Char): Float - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Int): Float - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Long): Float - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Float): Float - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Double): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Byte): Float - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Short): Float - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Char): Float - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Int): Float - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Long): Float - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Float): Float - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Double): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Byte): Float - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Short): Float - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Char): Float - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Int): Float - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Long): Float - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Float): Float - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Double): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Byte): Float - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Short): Float - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Char): Float - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Int): Float - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Long): Float - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Float): Float - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double override def getClass(): Class[Float] = null @@ -401,12 +243,10 @@ object Float extends AnyValCompanion { */ def unbox(x: java.lang.Object): Float = x.asInstanceOf[java.lang.Float].floatValue() - /** The String representation of the scala.Float companion object. - */ + /** The String representation of the scala.Float companion object. */ override def toString = "object scala.Float" - - /** Language mandated coercions from Float to "wider" types. - */ + /** Language mandated coercions from Float to "wider" types. */ + import scala.language.implicitConversions implicit def float2double(x: Float): Double = x.toDouble } diff --git a/src/library/scala/Int.scala b/src/library/scala/Int.scala index 6a27195b10..72e5ebf81b 100644 --- a/src/library/scala/Int.scala +++ b/src/library/scala/Int.scala @@ -6,12 +6,12 @@ ** |/ ** \* */ -// DO NOT EDIT, CHANGES WILL BE LOST. +// DO NOT EDIT, CHANGES WILL BE LOST +// This auto-generated code can be modified in scala.tools.cmd.gen. +// Afterwards, running tools/codegen-anyvals regenerates this source file. package scala -import scala.language.implicitConversions - /** `Int`, a 32-bit signed integer (equivalent to Java's `int` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Int` are not * represented by an object in the underlying runtime system. @@ -37,13 +37,9 @@ final abstract class Int private extends AnyVal { * }}} */ def unary_~ : Int - /** - * Returns this value, unmodified. - */ + /** Returns this value, unmodified. */ def unary_+ : Int - /** - * Returns the negation of this value. - */ + /** Returns the negation of this value. */ def unary_- : Int def +(x: String): String @@ -105,178 +101,94 @@ final abstract class Int private extends AnyVal { */ def >>(x: Long): Int - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Byte): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Short): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Char): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Int): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Long): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Float): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Double): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Byte): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Short): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Char): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Int): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Long): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Float): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Double): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Byte): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Short): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Char): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Int): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Long): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Float): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Double): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Byte): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Short): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Char): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Int): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Long): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Float): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Double): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Byte): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Short): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Char): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Int): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Long): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Float): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Double): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Byte): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Short): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Char): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Int): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Long): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Float): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Double): Boolean /** @@ -447,161 +359,89 @@ final abstract class Int private extends AnyVal { */ def ^(x: Long): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Byte): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Short): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Char): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Int): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Long): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Float): Float - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Double): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Byte): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Short): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Char): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Int): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Long): Long - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Float): Float - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Double): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Byte): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Short): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Char): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Int): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Long): Long - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Float): Float - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Double): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Byte): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Short): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Char): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Int): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Long): Long - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Float): Float - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Double): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Byte): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Short): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Char): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Int): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Long): Long - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Float): Float - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double override def getClass(): Class[Int] = null } object Int extends AnyValCompanion { - /** The smallest value representable as a Int. - */ + /** The smallest value representable as a Int. */ final val MinValue = java.lang.Integer.MIN_VALUE - /** The largest value representable as a Int. - */ + /** The largest value representable as a Int. */ final val MaxValue = java.lang.Integer.MAX_VALUE /** Transform a value type into a boxed reference type. @@ -625,12 +465,10 @@ object Int extends AnyValCompanion { */ def unbox(x: java.lang.Object): Int = x.asInstanceOf[java.lang.Integer].intValue() - /** The String representation of the scala.Int companion object. - */ + /** The String representation of the scala.Int companion object. */ override def toString = "object scala.Int" - - /** Language mandated coercions from Int to "wider" types. - */ + /** Language mandated coercions from Int to "wider" types. */ + import scala.language.implicitConversions implicit def int2long(x: Int): Long = x.toLong implicit def int2float(x: Int): Float = x.toFloat implicit def int2double(x: Int): Double = x.toDouble diff --git a/src/library/scala/Long.scala b/src/library/scala/Long.scala index 4d369ae010..1bd0fe88b1 100644 --- a/src/library/scala/Long.scala +++ b/src/library/scala/Long.scala @@ -6,12 +6,12 @@ ** |/ ** \* */ -// DO NOT EDIT, CHANGES WILL BE LOST. +// DO NOT EDIT, CHANGES WILL BE LOST +// This auto-generated code can be modified in scala.tools.cmd.gen. +// Afterwards, running tools/codegen-anyvals regenerates this source file. package scala -import scala.language.implicitConversions - /** `Long`, a 64-bit signed integer (equivalent to Java's `long` primitive type) is a * subtype of [[scala.AnyVal]]. Instances of `Long` are not * represented by an object in the underlying runtime system. @@ -37,13 +37,9 @@ final abstract class Long private extends AnyVal { * }}} */ def unary_~ : Long - /** - * Returns this value, unmodified. - */ + /** Returns this value, unmodified. */ def unary_+ : Long - /** - * Returns the negation of this value. - */ + /** Returns the negation of this value. */ def unary_- : Long def +(x: String): String @@ -105,178 +101,94 @@ final abstract class Long private extends AnyVal { */ def >>(x: Long): Long - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Byte): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Short): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Char): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Int): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Long): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Float): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Double): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Byte): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Short): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Char): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Int): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Long): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Float): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Double): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Byte): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Short): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Char): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Int): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Long): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Float): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Double): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Byte): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Short): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Char): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Int): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Long): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Float): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Double): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Byte): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Short): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Char): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Int): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Long): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Float): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Double): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Byte): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Short): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Char): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Int): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Long): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Float): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Double): Boolean /** @@ -447,161 +359,89 @@ final abstract class Long private extends AnyVal { */ def ^(x: Long): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Byte): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Short): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Char): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Int): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Long): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Float): Float - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Double): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Byte): Long - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Short): Long - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Char): Long - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Int): Long - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Long): Long - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Float): Float - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Double): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Byte): Long - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Short): Long - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Char): Long - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Int): Long - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Long): Long - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Float): Float - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Double): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Byte): Long - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Short): Long - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Char): Long - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Int): Long - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Long): Long - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Float): Float - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Double): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Byte): Long - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Short): Long - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Char): Long - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Int): Long - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Long): Long - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Float): Float - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double override def getClass(): Class[Long] = null } object Long extends AnyValCompanion { - /** The smallest value representable as a Long. - */ + /** The smallest value representable as a Long. */ final val MinValue = java.lang.Long.MIN_VALUE - /** The largest value representable as a Long. - */ + /** The largest value representable as a Long. */ final val MaxValue = java.lang.Long.MAX_VALUE /** Transform a value type into a boxed reference type. @@ -625,12 +465,10 @@ object Long extends AnyValCompanion { */ def unbox(x: java.lang.Object): Long = x.asInstanceOf[java.lang.Long].longValue() - /** The String representation of the scala.Long companion object. - */ + /** The String representation of the scala.Long companion object. */ override def toString = "object scala.Long" - - /** Language mandated coercions from Long to "wider" types. - */ + /** Language mandated coercions from Long to "wider" types. */ + import scala.language.implicitConversions implicit def long2float(x: Long): Float = x.toFloat implicit def long2double(x: Long): Double = x.toDouble } diff --git a/src/library/scala/Short.scala b/src/library/scala/Short.scala index 4f91c51550..36b9ec4df9 100644 --- a/src/library/scala/Short.scala +++ b/src/library/scala/Short.scala @@ -6,12 +6,12 @@ ** |/ ** \* */ -// DO NOT EDIT, CHANGES WILL BE LOST. +// DO NOT EDIT, CHANGES WILL BE LOST +// This auto-generated code can be modified in scala.tools.cmd.gen. +// Afterwards, running tools/codegen-anyvals regenerates this source file. package scala -import scala.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. @@ -37,13 +37,9 @@ final abstract class Short private extends AnyVal { * }}} */ def unary_~ : Int - /** - * Returns this value, unmodified. - */ + /** Returns this value, unmodified. */ def unary_+ : Int - /** - * Returns the negation of this value. - */ + /** Returns the negation of this value. */ def unary_- : Int def +(x: String): String @@ -105,178 +101,94 @@ final abstract class Short private extends AnyVal { */ def >>(x: Long): Int - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Byte): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Short): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Char): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Int): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Long): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Float): Boolean - /** - * Returns `true` if this value is equal to x, `false` otherwise. - */ + /** Returns `true` if this value is equal to x, `false` otherwise. */ def ==(x: Double): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Byte): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Short): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Char): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Int): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Long): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Float): Boolean - /** - * Returns `true` if this value is not equal to x, `false` otherwise. - */ + /** Returns `true` if this value is not equal to x, `false` otherwise. */ def !=(x: Double): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Byte): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Short): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Char): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Int): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Long): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Float): Boolean - /** - * Returns `true` if this value is less than x, `false` otherwise. - */ + /** Returns `true` if this value is less than x, `false` otherwise. */ def <(x: Double): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Byte): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Short): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Char): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Int): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Long): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Float): Boolean - /** - * Returns `true` if this value is less than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is less than or equal to x, `false` otherwise. */ def <=(x: Double): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Byte): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Short): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Char): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Int): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Long): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Float): Boolean - /** - * Returns `true` if this value is greater than x, `false` otherwise. - */ + /** Returns `true` if this value is greater than x, `false` otherwise. */ def >(x: Double): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Byte): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Short): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Char): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Int): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Long): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Float): Boolean - /** - * Returns `true` if this value is greater than or equal to x, `false` otherwise. - */ + /** Returns `true` if this value is greater than or equal to x, `false` otherwise. */ def >=(x: Double): Boolean /** @@ -447,161 +359,89 @@ final abstract class Short private extends AnyVal { */ def ^(x: Long): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Byte): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Short): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Char): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Int): Int - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Long): Long - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Float): Float - /** - * Returns the sum of this value and `x`. - */ + /** Returns the sum of this value and `x`. */ def +(x: Double): Double - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Byte): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Short): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Char): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Int): Int - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Long): Long - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Float): Float - /** - * Returns the difference of this value and `x`. - */ + /** Returns the difference of this value and `x`. */ def -(x: Double): Double - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Byte): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Short): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Char): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Int): Int - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Long): Long - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Float): Float - /** - * Returns the product of this value and `x`. - */ + /** Returns the product of this value and `x`. */ def *(x: Double): Double - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Byte): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Short): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Char): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Int): Int - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Long): Long - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Float): Float - /** - * Returns the quotient of this value and `x`. - */ + /** Returns the quotient of this value and `x`. */ def /(x: Double): Double - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Byte): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Short): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Char): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Int): Int - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Long): Long - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Float): Float - /** - * Returns the remainder of the division of this value by `x`. - */ + /** Returns the remainder of the division of this value by `x`. */ def %(x: Double): Double override def getClass(): Class[Short] = null } object Short extends AnyValCompanion { - /** The smallest value representable as a Short. - */ + /** The smallest value representable as a Short. */ final val MinValue = java.lang.Short.MIN_VALUE - /** The largest value representable as a Short. - */ + /** The largest value representable as a Short. */ final val MaxValue = java.lang.Short.MAX_VALUE /** Transform a value type into a boxed reference type. @@ -625,12 +465,10 @@ object Short extends AnyValCompanion { */ def unbox(x: java.lang.Object): Short = x.asInstanceOf[java.lang.Short].shortValue() - /** The String representation of the scala.Short companion object. - */ + /** The String representation of the scala.Short companion object. */ override def toString = "object scala.Short" - - /** Language mandated coercions from Short to "wider" types. - */ + /** Language mandated coercions from Short to "wider" types. */ + import scala.language.implicitConversions implicit def short2int(x: Short): Int = x.toInt implicit def short2long(x: Short): Long = x.toLong implicit def short2float(x: Short): Float = x.toFloat diff --git a/src/library/scala/Unit.scala b/src/library/scala/Unit.scala index 0e59a184d1..018ad24a99 100644 --- a/src/library/scala/Unit.scala +++ b/src/library/scala/Unit.scala @@ -6,12 +6,12 @@ ** |/ ** \* */ -// DO NOT EDIT, CHANGES WILL BE LOST. +// DO NOT EDIT, CHANGES WILL BE LOST +// This auto-generated code can be modified in scala.tools.cmd.gen. +// Afterwards, running tools/codegen-anyvals regenerates this source file. package scala -import scala.language.implicitConversions - /** `Unit` is a subtype of [[scala.AnyVal]]. There is only one value of type * `Unit`, `()`, and it is not represented by any object in the underlying @@ -41,8 +41,7 @@ object Unit extends AnyValCompanion { */ def unbox(x: java.lang.Object): Unit = () - /** The String representation of the scala.Unit companion object. - */ + /** The String representation of the scala.Unit companion object. */ override def toString = "object scala.Unit" } -- cgit v1.2.3 From 0459db43728e1dc38c3a1db6b7b1920810d0f858 Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Fri, 5 Jul 2013 17:13:47 +0200 Subject: SI-7624 Fix a few remaining -Xlint warnings ... in various places. This includes actors, compiler (mostly some new macro parts) continuations, partest, scaladoc, scalap. --- src/actors/scala/actors/Scheduler.scala | 1 - src/actors/scala/actors/remote/TcpService.scala | 2 +- .../macros/compiler/DefaultMacroCompiler.scala | 2 -- .../scala/reflect/macros/compiler/Validators.scala | 2 -- .../macros/runtime/JavaReflectionRuntimes.scala | 2 -- .../reflect/macros/runtime/MacroRuntimes.scala | 3 --- .../macros/runtime/ScalaReflectionRuntimes.scala | 2 -- .../scala/reflect/macros/util/Helpers.scala | 7 +---- src/compiler/scala/tools/ant/sabbus/Settings.scala | 2 +- .../scala/tools/cmd/CommandLineParser.scala | 10 +++---- .../nsc/symtab/classfile/ClassfileParser.scala | 3 +-- .../scala/tools/nsc/typechecker/Implicits.scala | 2 +- src/compiler/scala/tools/util/PathResolver.scala | 4 +-- .../tools/selectivecps/CPSAnnotationChecker.scala | 1 - src/partest/scala/tools/partest/BytecodeTest.scala | 2 +- src/partest/scala/tools/partest/TestState.scala | 1 - src/partest/scala/tools/partest/nest/Runner.scala | 16 +++-------- src/reflect/scala/reflect/internal/Kinds.scala | 2 +- .../scala/reflect/internal/util/WeakHashSet.scala | 31 +++++++++++----------- .../scala/reflect/runtime/ReflectSetup.scala | 2 +- .../scala/tools/nsc/doc/ScaladocAnalyzer.scala | 6 ++--- .../scala/tools/nsc/doc/ScaladocGlobal.scala | 1 - .../scala/tools/scalap/ByteArrayReader.scala | 1 - src/scalap/scala/tools/scalap/Main.scala | 2 +- src/scalap/scala/tools/scalap/MetaParser.scala | 1 - 25 files changed, 38 insertions(+), 70 deletions(-) (limited to 'src') diff --git a/src/actors/scala/actors/Scheduler.scala b/src/actors/scala/actors/Scheduler.scala index 5b5b4a946d..67c8e5cd10 100644 --- a/src/actors/scala/actors/Scheduler.scala +++ b/src/actors/scala/actors/Scheduler.scala @@ -9,7 +9,6 @@ package scala.actors -import java.util.concurrent._ import scheduler.{DelegatingScheduler, ForkJoinScheduler, ResizableThreadPoolScheduler, ThreadPoolConfig} /** diff --git a/src/actors/scala/actors/remote/TcpService.scala b/src/actors/scala/actors/remote/TcpService.scala index ad78ff784c..75e36b2738 100644 --- a/src/actors/scala/actors/remote/TcpService.scala +++ b/src/actors/scala/actors/remote/TcpService.scala @@ -67,7 +67,7 @@ object TcpService { timeout => try { val to = timeout.toInt - Debug.info("Using socket timeout $to") + Debug.info(s"Using socket timeout $to") Some(to) } catch { case e: NumberFormatException => diff --git a/src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala b/src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala index 32c6da8007..2e82e34bd9 100644 --- a/src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala +++ b/src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala @@ -2,7 +2,6 @@ package scala.reflect.macros package compiler import scala.tools.nsc.Global -import scala.reflect.macros.contexts.Context abstract class DefaultMacroCompiler extends Resolvers with Validators @@ -11,7 +10,6 @@ abstract class DefaultMacroCompiler extends Resolvers import global._ val typer: global.analyzer.Typer - private implicit val context0 = typer.context val context = typer.context val macroDdef: DefDef diff --git a/src/compiler/scala/reflect/macros/compiler/Validators.scala b/src/compiler/scala/reflect/macros/compiler/Validators.scala index 60cfc94a23..fafd79d1d7 100644 --- a/src/compiler/scala/reflect/macros/compiler/Validators.scala +++ b/src/compiler/scala/reflect/macros/compiler/Validators.scala @@ -11,8 +11,6 @@ trait Validators { import global._ import analyzer._ import definitions._ - import treeInfo._ - import typer.infer._ def validateMacroImplRef() = { sanityCheck() diff --git a/src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala b/src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala index 3ef11fad9d..450cb4d9ea 100644 --- a/src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala +++ b/src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala @@ -10,8 +10,6 @@ trait JavaReflectionRuntimes { trait JavaReflectionResolvers { self: MacroRuntimeResolver => - import global._ - def resolveJavaReflectionRuntime(classLoader: ClassLoader): MacroRuntime = { val implClass = Class.forName(className, true, classLoader) val implMeths = implClass.getDeclaredMethods.find(_.getName == methName) diff --git a/src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala b/src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala index 0f89163803..ffdbe11151 100644 --- a/src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala +++ b/src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala @@ -1,11 +1,8 @@ package scala.reflect.macros package runtime -import scala.collection.mutable.{Map => MutableMap} import scala.reflect.internal.Flags._ import scala.reflect.runtime.ReflectionUtils -import scala.tools.nsc.util.ScalaClassLoader -import scala.tools.nsc.util.AbstractFileClassLoader trait MacroRuntimes extends JavaReflectionRuntimes with ScalaReflectionRuntimes { self: scala.tools.nsc.typechecker.Analyzer => diff --git a/src/compiler/scala/reflect/macros/runtime/ScalaReflectionRuntimes.scala b/src/compiler/scala/reflect/macros/runtime/ScalaReflectionRuntimes.scala index 1999e525ff..50f64310f8 100644 --- a/src/compiler/scala/reflect/macros/runtime/ScalaReflectionRuntimes.scala +++ b/src/compiler/scala/reflect/macros/runtime/ScalaReflectionRuntimes.scala @@ -9,8 +9,6 @@ trait ScalaReflectionRuntimes { trait ScalaReflectionResolvers { self: MacroRuntimeResolver => - import global._ - def resolveScalaReflectionRuntime(classLoader: ClassLoader): MacroRuntime = { val macroMirror: ru.JavaMirror = ru.runtimeMirror(classLoader) val implContainerSym = macroMirror.classSymbol(Class.forName(className, true, classLoader)) diff --git a/src/compiler/scala/reflect/macros/util/Helpers.scala b/src/compiler/scala/reflect/macros/util/Helpers.scala index 9b7680717e..f12582a3a1 100644 --- a/src/compiler/scala/reflect/macros/util/Helpers.scala +++ b/src/compiler/scala/reflect/macros/util/Helpers.scala @@ -23,7 +23,7 @@ trait Helpers { * or to streamline creation of the list of macro arguments. */ def transformTypeTagEvidenceParams(macroImplRef: Tree, transform: (Symbol, Symbol) => Symbol): List[List[Symbol]] = { - val treeInfo.MacroImplReference(isBundle, owner, macroImpl, _) = macroImplRef + val treeInfo.MacroImplReference(isBundle, _, macroImpl, _) = macroImplRef val paramss = macroImpl.paramss if (paramss.isEmpty || paramss.last.isEmpty) return paramss // no implicit parameters in the signature => nothing to do val rc = @@ -44,11 +44,6 @@ trait Helpers { if (transformed.isEmpty) paramss.init else paramss.init :+ transformed } - private def dealiasAndRewrap(tp: Type)(fn: Type => Type): Type = { - if (isRepeatedParamType(tp)) scalaRepeatedType(fn(tp.typeArgs.head.dealias)) - else fn(tp.dealias) - } - /** Increases metalevel of the type, i.e. transforms: * * T to c.Expr[T] * diff --git a/src/compiler/scala/tools/ant/sabbus/Settings.scala b/src/compiler/scala/tools/ant/sabbus/Settings.scala index 4cbc03d8d4..a86af73fe3 100644 --- a/src/compiler/scala/tools/ant/sabbus/Settings.scala +++ b/src/compiler/scala/tools/ant/sabbus/Settings.scala @@ -93,7 +93,7 @@ class Settings { case _ => false } - override lazy val hashCode: Int = Seq( + override lazy val hashCode: Int = Seq[Any]( gBf, uncheckedBf, classpathBf, diff --git a/src/compiler/scala/tools/cmd/CommandLineParser.scala b/src/compiler/scala/tools/cmd/CommandLineParser.scala index ef55178594..6132eff557 100644 --- a/src/compiler/scala/tools/cmd/CommandLineParser.scala +++ b/src/compiler/scala/tools/cmd/CommandLineParser.scala @@ -40,16 +40,16 @@ object CommandLineParser { // parse `in` for an argument, return it and the remainder of the input (or an error message) // (argument may be in single/double quotes, taking escaping into account, quotes are stripped) private def argument(in: String): Either[String, (String, String)] = in match { - case DoubleQuoted(arg, rest) => Right(arg, rest) - case SingleQuoted(arg, rest) => Right(arg, rest) - case Word(arg, rest) => Right(arg, rest) - case _ => Left("Illegal argument: "+ in) + case DoubleQuoted(arg, rest) => Right((arg, rest)) + case SingleQuoted(arg, rest) => Right((arg, rest)) + case Word(arg, rest) => Right((arg, rest)) + case _ => Left(s"Illegal argument: $in") } // parse a list of whitespace-separated arguments (ignoring whitespace in quoted arguments) @tailrec private def commandLine(in: String, accum: List[String] = Nil): Either[String, (List[String], String)] = { val trimmed = in.trim - if (trimmed.isEmpty) Right(accum.reverse, "") + if (trimmed.isEmpty) Right((accum.reverse, "")) else argument(trimmed) match { case Right((arg, next)) => (next span Character.isWhitespace) match { diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index c6ea6b23e5..454c9db73c 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -74,7 +74,6 @@ abstract class ClassfileParser { def srcfile = srcfile0 private def optimized = settings.optimise.value - private def currentIsTopLevel = !(currentClass.decodedName containsChar '$') // u1, u2, and u4 are what these data types are called in the JVM spec. // They are an unsigned byte, unsigned char, and unsigned int respectively. @@ -349,7 +348,7 @@ abstract class ClassfileParser { /** Throws an exception signaling a bad tag at given address. */ protected def errorBadTag(start: Int) = - abort("bad constant pool tag ${in.buf(start)} at byte $start") + abort(s"bad constant pool tag ${in.buf(start)} at byte $start") } private def loadClassSymbol(name: Name): Symbol = { diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index c87de8839f..4265efc839 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -815,7 +815,7 @@ trait Implicits { if (search.isDivergent && countdown > 0) { countdown -= 1 implicitSym = i.sym - log("discarding divergent implicit ${implicitSym} during implicit search") + log(s"discarding divergent implicit $implicitSym during implicit search") SearchFailure } else search } diff --git a/src/compiler/scala/tools/util/PathResolver.scala b/src/compiler/scala/tools/util/PathResolver.scala index bdd6a02043..82f2c5dc74 100644 --- a/src/compiler/scala/tools/util/PathResolver.scala +++ b/src/compiler/scala/tools/util/PathResolver.scala @@ -8,8 +8,8 @@ package tools package util import scala.tools.reflect.WrappedProperties.AccessControl -import scala.tools.nsc.{ Settings, GenericRunnerSettings } -import scala.tools.nsc.util.{ ClassPath, JavaClassPath, ScalaClassLoader } +import scala.tools.nsc.{ Settings } +import scala.tools.nsc.util.{ ClassPath, JavaClassPath } import scala.reflect.io.{ File, Directory, Path, AbstractFile } import ClassPath.{ JavaContext, DefaultJavaContext, join, split } import PartialFunction.condOpt diff --git a/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala b/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala index f260ee4093..3963447de3 100644 --- a/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala +++ b/src/continuations/plugin/scala/tools/selectivecps/CPSAnnotationChecker.scala @@ -396,7 +396,6 @@ abstract class CPSAnnotationChecker extends CPSUtils { * for a tree. All this should do is add annotations. */ override def pluginsTyped(tpe: Type, typer: Typer, tree: Tree, mode: Mode, pt: Type): Type = { - import scala.util.control._ if (!cpsEnabled) { val report = try hasCpsParamTypes(tpe) catch { case _: MissingRequirementError => false } if (report) diff --git a/src/partest/scala/tools/partest/BytecodeTest.scala b/src/partest/scala/tools/partest/BytecodeTest.scala index 172fa29189..2690b784d1 100644 --- a/src/partest/scala/tools/partest/BytecodeTest.scala +++ b/src/partest/scala/tools/partest/BytecodeTest.scala @@ -55,7 +55,7 @@ abstract class BytecodeTest extends ASMConverters { val name2 = clazzB.name if (ms1.length != ms2.length) { - println("Different member counts in $name1 and $name2") + println(s"Different member counts in $name1 and $name2") false } else (ms1, ms2).zipped forall { (m1, m2) => diff --git a/src/partest/scala/tools/partest/TestState.scala b/src/partest/scala/tools/partest/TestState.scala index dbe8a222a5..e58b479e54 100644 --- a/src/partest/scala/tools/partest/TestState.scala +++ b/src/partest/scala/tools/partest/TestState.scala @@ -59,7 +59,6 @@ object TestState { def reason = s"caught $caught_s - ${caught.getMessage}" private def caught_s = (caught.getClass.getName split '.').last - private def stack_s = stackTraceString(caught) override def transcriptString = nljoin(super.transcriptString, caught_s) } } diff --git a/src/partest/scala/tools/partest/nest/Runner.scala b/src/partest/scala/tools/partest/nest/Runner.scala index 1d41095fce..6b09aa4689 100644 --- a/src/partest/scala/tools/partest/nest/Runner.scala +++ b/src/partest/scala/tools/partest/nest/Runner.scala @@ -17,7 +17,6 @@ import scala.reflect.internal.FatalError import scala.sys.process.{ Process, ProcessLogger } import scala.tools.nsc.Properties.{ envOrElse, isWin, jdkHome, javaHome, propOrElse, propOrEmpty, setProp } import scala.tools.nsc.{ Settings, CompilerCommand, Global } -import scala.tools.nsc.io.{ AbstractFile, PlainFile } import scala.tools.nsc.reporters.ConsoleReporter import scala.tools.nsc.util.{ Exceptional, ScalaClassLoader, stackTraceString } import scala.tools.scalap.Main.decompileScala @@ -86,7 +85,7 @@ class Runner(val testFile: File, fileManager: FileManager, val testRunParams: Te type RanOneTest = (Boolean, LogContext) def showCrashInfo(t: Throwable) { - System.err.println("Crashed running test $testIdent: " + t) + System.err.println(s"Crashed running test $testIdent: $t") if (!isPartestTerse) System.err.println(stackTraceString(t)) } @@ -490,13 +489,7 @@ class Runner(val testFile: File, fileManager: FileManager, val testRunParams: Te def fsString = fs map (_.toString stripPrefix parentFile.toString + "/") mkString " " def isOk = result.isOk - def mkScalacString(): String = { - val flags = file2String(flagsFile) match { - case "" => "" - case s => " " + s - } - s"""scalac $fsString""" - } + def mkScalacString(): String = s"""scalac $fsString""" override def toString = description + ( if (result.isOk) "" else "\n" + result.status ) } case class OnlyJava(fs: List[File]) extends CompileRound { @@ -770,7 +763,7 @@ trait DirectRunner { import PartestDefaults.{ numThreads, waitTime } setUncaughtHandler - + def runTestsForFiles(kindFiles: List[File], kind: String): List[TestState] = { NestUI.resetTestNumber(kindFiles.size) @@ -866,7 +859,6 @@ object Output { /** Use a Runner to run a test. */ class RunnerManager(kind: String, fileManager: FileManager, params: TestRunParams) { - import fileManager._ fileManager.CLASSPATH += File.pathSeparator + PathSettings.scalaCheck fileManager.CLASSPATH += File.pathSeparator + PathSettings.diffUtils // needed to put diffutils on test/partest's classpath @@ -878,7 +870,7 @@ class RunnerManager(kind: String, fileManager: FileManager, params: TestRunParam if (fileManager.failed && !runner.logFile.canRead) runner.genPass() else { - val (state, elapsed) = + val (state, _) = try timed(runner.run()) catch { case t: Throwable => throw new RuntimeException(s"Error running $testFile", t) diff --git a/src/reflect/scala/reflect/internal/Kinds.scala b/src/reflect/scala/reflect/internal/Kinds.scala index 315bf7e9c4..d1c215713e 100644 --- a/src/reflect/scala/reflect/internal/Kinds.scala +++ b/src/reflect/scala/reflect/internal/Kinds.scala @@ -380,7 +380,7 @@ trait Kinds { object TypeConKind { def apply(args: Seq[TypeConKind.Argument]): TypeConKind = this(TypeBounds.empty, args) def apply(bounds: TypeBounds, args: Seq[TypeConKind.Argument]): TypeConKind = new TypeConKind(bounds, args) - def unapply(tck: TypeConKind): Some[(TypeBounds, Seq[TypeConKind.Argument])] = Some(tck.bounds, tck.args) + def unapply(tck: TypeConKind): Some[(TypeBounds, Seq[TypeConKind.Argument])] = Some((tck.bounds, tck.args)) case class Argument(variance: Variance, kind: Kind)(val sym: Symbol) {} } diff --git a/src/reflect/scala/reflect/internal/util/WeakHashSet.scala b/src/reflect/scala/reflect/internal/util/WeakHashSet.scala index 9b792a3f43..a8bc79d832 100644 --- a/src/reflect/scala/reflect/internal/util/WeakHashSet.scala +++ b/src/reflect/scala/reflect/internal/util/WeakHashSet.scala @@ -4,7 +4,7 @@ package reflect.internal.util import java.lang.ref.{WeakReference, ReferenceQueue} import scala.annotation.tailrec import scala.collection.generic.Clearable -import scala.collection.mutable.{Set => mSet} +import scala.collection.mutable.{Set => MSet} /** * A HashSet where the elements are stored weakly. Elements in this set are elligible for GC if no other @@ -16,8 +16,8 @@ import scala.collection.mutable.{Set => mSet} * This set implmeentation is not in general thread safe without external concurrency control. However it behaves * properly when GC concurrently collects elements in this set. */ -final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: Double) extends Set[A] with Function1[A, Boolean] with mSet[A] { - +final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: Double) extends Set[A] with Function1[A, Boolean] with MSet[A] { + import WeakHashSet._ def this() = this(initialCapacity = WeakHashSet.defaultInitialCapacity, loadFactor = WeakHashSet.defaultLoadFactor) @@ -47,7 +47,7 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D candidate *= 2 } candidate - } + } /** * the underlying table of entries which is an array of Entry linked lists @@ -65,7 +65,7 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D * find the bucket associated with an elements's hash code */ private[this] def bucketFor(hash: Int): Int = { - // spread the bits around to try to avoid accidental collisions using the + // spread the bits around to try to avoid accidental collisions using the // same algorithm as java.util.HashMap var h = hash h ^= h >>> 20 ^ h >>> 12 @@ -98,7 +98,7 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D def poll(): Entry[A] = queue.poll().asInstanceOf[Entry[A]] @tailrec - def queueLoop { + def queueLoop(): Unit = { val stale = poll() if (stale != null) { val bucket = bucketFor(stale.hash) @@ -109,11 +109,11 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D linkedListLoop(null, table(bucket)) - queueLoop + queueLoop() } } - - queueLoop + + queueLoop() } /** @@ -123,7 +123,7 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D val oldTable = table table = new Array[Entry[A]](oldTable.size * 2) threshhold = computeThreshHold - + @tailrec def tableLoop(oldBucket: Int): Unit = if (oldBucket < oldTable.size) { @tailrec @@ -225,7 +225,7 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D def +=(elem: A) = this + elem // from scala.reflect.interanl.Set - override def addEntry(x: A) { this += x } + override def addEntry(x: A) { this += x } // remove an element from this set and return this set override def -(elem: A): this.type = elem match { @@ -274,6 +274,7 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D override def foreach[U](f: A => U): Unit = iterator foreach f + // It has the `()` because iterator runs `removeStaleEntries()` override def toList(): List[A] = iterator.toList // Iterator over all the elements in this set in no particular order @@ -292,7 +293,7 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D */ private[this] var entry: Entry[A] = null - /** + /** * the element that will be the result of the next call to next() */ private[this] var lookaheadelement: A = null.asInstanceOf[A] @@ -339,7 +340,7 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D * the entries must be stable. If any are garbage collected during validation * then an assertion may inappropriately fire. */ - def fullyValidate { + def fullyValidate: Unit = { var computedCount = 0 var bucket = 0 while (bucket < table.size) { @@ -407,10 +408,10 @@ final class WeakHashSet[A <: AnyRef](val initialCapacity: Int, val loadFactor: D e = e.tail } count - } + } } - private[util] def diagnostics = new Diagnostics + private[util] def diagnostics = new Diagnostics } /** diff --git a/src/reflect/scala/reflect/runtime/ReflectSetup.scala b/src/reflect/scala/reflect/runtime/ReflectSetup.scala index 84f159be00..6a364ff0be 100644 --- a/src/reflect/scala/reflect/runtime/ReflectSetup.scala +++ b/src/reflect/scala/reflect/runtime/ReflectSetup.scala @@ -2,7 +2,7 @@ package scala package reflect package runtime -import internal.{SomePhase, NoPhase, Phase, TreeGen} +import internal.{SomePhase, NoPhase, Phase} /** A helper trait to initialize things that need to be set before JavaMirrors and other * reflect specific traits are initialized */ diff --git a/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala b/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala index d407b93a4b..fe5ed47d43 100644 --- a/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala +++ b/src/scaladoc/scala/tools/nsc/doc/ScaladocAnalyzer.scala @@ -7,12 +7,10 @@ package scala.tools.nsc package doc import scala.tools.nsc.ast.parser.{ SyntaxAnalyzer, BracePatch } -import scala.reflect.internal.Chars._ -import symtab._ import typechecker.Analyzer +import scala.reflect.internal.Chars._ import scala.reflect.internal.util.{ BatchSourceFile, RangePosition } import scala.tools.nsc.doc.base.{ CommentFactoryBase, MemberLookupBase, LinkTo, LinkToExternal } -import scala.language.postfixOps trait ScaladocAnalyzer extends Analyzer { val global : Global // generally, a ScaladocGlobal @@ -168,7 +166,7 @@ abstract class ScaladocSyntaxAnalyzer[G <: Global](val global: G) extends Syntax } override def internalLink(sym: Symbol, site: Symbol): Option[LinkTo] = None - override def chooseLink(links: List[LinkTo]): LinkTo = links.headOption orNull + override def chooseLink(links: List[LinkTo]): LinkTo = links.headOption.orNull override def toString(link: LinkTo): String = "No link" override def findExternalLink(sym: Symbol, name: String): Option[LinkToExternal] = None override def warnNoLink: Boolean = false diff --git a/src/scaladoc/scala/tools/nsc/doc/ScaladocGlobal.scala b/src/scaladoc/scala/tools/nsc/doc/ScaladocGlobal.scala index 723f8b1dc8..e654678c6d 100644 --- a/src/scaladoc/scala/tools/nsc/doc/ScaladocGlobal.scala +++ b/src/scaladoc/scala/tools/nsc/doc/ScaladocGlobal.scala @@ -7,7 +7,6 @@ package scala.tools.nsc package doc import scala.tools.nsc.ast.parser.{ SyntaxAnalyzer, BracePatch } -import scala.reflect.internal.Chars._ import symtab._ import reporters.Reporter import typechecker.Analyzer diff --git a/src/scalap/scala/tools/scalap/ByteArrayReader.scala b/src/scalap/scala/tools/scalap/ByteArrayReader.scala index 9c72bdbf1e..cf160871dd 100644 --- a/src/scalap/scala/tools/scalap/ByteArrayReader.scala +++ b/src/scalap/scala/tools/scalap/ByteArrayReader.scala @@ -11,7 +11,6 @@ package tools.scalap class ByteArrayReader(content: Array[Byte]) { - import java.io._ /** the buffer containing the file */ diff --git a/src/scalap/scala/tools/scalap/Main.scala b/src/scalap/scala/tools/scalap/Main.scala index 5da4227e53..c72f416a89 100644 --- a/src/scalap/scala/tools/scalap/Main.scala +++ b/src/scalap/scala/tools/scalap/Main.scala @@ -14,7 +14,7 @@ import scalax.rules.scalasig._ import scala.tools.nsc.util.{ ClassPath, JavaClassPath } import scala.tools.util.PathResolver import ClassPath.DefaultJavaContext -import scala.tools.nsc.io.{ PlainFile, AbstractFile } +import scala.tools.nsc.io.AbstractFile /**The main object used to execute scalap on the command-line. * diff --git a/src/scalap/scala/tools/scalap/MetaParser.scala b/src/scalap/scala/tools/scalap/MetaParser.scala index 8b4ffb3efd..1ebf86268a 100644 --- a/src/scalap/scala/tools/scalap/MetaParser.scala +++ b/src/scalap/scala/tools/scalap/MetaParser.scala @@ -9,7 +9,6 @@ package scala package tools.scalap -import java.io._ import java.util._ -- cgit v1.2.3 From 6056f7efbb79de52cb0d0df12bed13cd8706f177 Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Mon, 8 Jul 2013 15:25:25 +0200 Subject: SI-7624 Replace new{Term,Type}Name with {Term,Type}Name --- src/partest/scala/tools/partest/package.scala | 6 +++--- src/reflect/scala/reflect/api/Mirrors.scala | 12 ++++++------ src/reflect/scala/reflect/api/Names.scala | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/partest/scala/tools/partest/package.scala b/src/partest/scala/tools/partest/package.scala index 5a1afeb77f..77400b1b9c 100644 --- a/src/partest/scala/tools/partest/package.scala +++ b/src/partest/scala/tools/partest/package.scala @@ -216,16 +216,16 @@ package object partest { c.Expr(Block( List(Apply( - Select(Ident(PredefModule), newTermName("println")), + Select(Ident(PredefModule), TermName("println")), List(Apply( Select(Apply( - Select(Ident(ScalaPackage), newTermName("StringContext")), + Select(Ident(ScalaPackage), TermName("StringContext")), List( Literal(Constant("trace> ")), Literal(Constant("\\nres: ")), Literal(Constant(" = ")), Literal(Constant("\\n")))), - newTermName("s")), + TermName("s")), List( Literal(Constant(show(a.tree))), Literal(Constant(show(a.actualType))), diff --git a/src/reflect/scala/reflect/api/Mirrors.scala b/src/reflect/scala/reflect/api/Mirrors.scala index d702555ba6..ec128e31a3 100644 --- a/src/reflect/scala/reflect/api/Mirrors.scala +++ b/src/reflect/scala/reflect/api/Mirrors.scala @@ -101,7 +101,7 @@ package api * via `ModuleMirror.instance`). Entry point: `val mm = im.reflectMethod()`. * Example: * {{{ - * scala> val methodX = typeOf[C].declaration(newTermName("x")).asMethod + * scala> val methodX = typeOf[C].declaration(TermName("x")).asMethod * methodX: reflect.runtime.universe.MethodSymbol = method x * * scala> val mm = im.reflectMethod(methodX) @@ -126,7 +126,7 @@ package api * scala> val im = m.reflect(new C) * im: reflect.runtime.universe.InstanceMirror = instance mirror for C@5f0c8ac1 * - * scala> val fieldX = typeOf[C].declaration(newTermName("x")).asTerm.accessed.asTerm + * scala> val fieldX = typeOf[C].declaration(TermName("x")).asTerm.accessed.asTerm * fieldX: reflect.runtime.universe.TermSymbol = value x * scala> val fmX = im.reflectField(fieldX) * fmX: reflect.runtime.universe.FieldMirror = field mirror for C.x (bound to C@5f0c8ac1) @@ -136,7 +136,7 @@ package api * * scala> fmX.set(3) // NOTE: can set an underlying value of an immutable field! * - * scala> val fieldY = typeOf[C].declaration(newTermName("y")).asTerm.accessed.asTerm + * scala> val fieldY = typeOf[C].declaration(TermName("y")).asTerm.accessed.asTerm * fieldY: reflect.runtime.universe.TermSymbol = variable y * * scala> val fmY = im.reflectField(fieldY) @@ -255,7 +255,7 @@ trait Mirrors { self: Universe => * Note also that only accessor MethodMirrors, but not FieldMirrors will accurately reflect overriding behavior. * * To get a field symbol by the name of the field you would like to reflect, - * use `.symbol.typeSignature.member(newTermName()).asTerm.accessed`. + * use `.symbol.typeSignature.member(TermName()).asTerm.accessed`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). @@ -275,7 +275,7 @@ trait Mirrors { self: Universe => * that can be used to invoke the method provided. * * To get a method symbol by the name of the method you would like to reflect, - * use `.symbol.typeSignature.member(newTermName()).asMethod`. + * use `.symbol.typeSignature.member(TermName()).asMethod`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). @@ -299,7 +299,7 @@ trait Mirrors { self: Universe => * that can be used to get the instance of the object or inspect its companion class. * * To get a module symbol by the name of the object you would like to reflect, - * use `.symbol.typeSignature.member(newTermName()).asModule`. + * use `.symbol.typeSignature.member(TermName()).asModule`. * For further information about member lookup refer to `Symbol.typeSignature`. * * The input symbol can be either private or non-private (Scala reflection transparently deals with visibility). diff --git a/src/reflect/scala/reflect/api/Names.scala b/src/reflect/scala/reflect/api/Names.scala index f74e0ce014..87d7f9fd8e 100644 --- a/src/reflect/scala/reflect/api/Names.scala +++ b/src/reflect/scala/reflect/api/Names.scala @@ -33,13 +33,13 @@ trait Names { * Enables an alternative notation `"map": TermName` as opposed to `newTermName("map")`. * @group Names */ - implicit def stringToTermName(s: String): TermName = newTermName(s) + implicit def stringToTermName(s: String): TermName = TermName(s) /** An implicit conversion from String to TypeName. * Enables an alternative notation `"List": TypeName` as opposed to `newTypeName("List")`. * @group Names */ - implicit def stringToTypeName(s: String): TypeName = newTypeName(s) + implicit def stringToTypeName(s: String): TypeName = TypeName(s) /** The abstract type of names. * @group Names -- cgit v1.2.3 From f2de2c4ec43180351ef1f306bcc5f24643ba5477 Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Mon, 29 Jul 2013 21:04:14 +0200 Subject: SI-7624 Fix -feature warnings in scala/tools/scalap ... and move scalap.scala.tools.scalap.scalax.rules to scalap.scala.tools.scalap.rules now that all the Monad/Functor/ Applicatve/... stuff has been removed. --- src/partest/scala/tools/partest/nest/Runner.scala | 2 +- src/scalap/scala/tools/scalap/Arguments.scala | 1 - .../scala/tools/scalap/ByteArrayReader.scala | 12 +- src/scalap/scala/tools/scalap/Classfile.scala | 2 - src/scalap/scala/tools/scalap/Classfiles.scala | 2 - src/scalap/scala/tools/scalap/CodeWriter.scala | 8 +- src/scalap/scala/tools/scalap/Decode.scala | 30 +- src/scalap/scala/tools/scalap/JavaWriter.scala | 4 +- src/scalap/scala/tools/scalap/Main.scala | 16 +- src/scalap/scala/tools/scalap/MetaParser.scala | 6 +- src/scalap/scala/tools/scalap/Properties.scala | 3 +- .../scala/tools/scalap/rules/Memoisable.scala | 56 +++ src/scalap/scala/tools/scalap/rules/Result.scala | 70 ++++ src/scalap/scala/tools/scalap/rules/Rule.scala | 172 ++++++++ src/scalap/scala/tools/scalap/rules/Rules.scala | 150 +++++++ src/scalap/scala/tools/scalap/rules/SeqRule.scala | 98 +++++ src/scalap/scala/tools/scalap/rules/package.scala | 6 + .../tools/scalap/scalasig/ClassFileParser.scala | 240 +++++++++++ src/scalap/scala/tools/scalap/scalasig/Flags.scala | 65 +++ .../scala/tools/scalap/scalasig/ScalaSig.scala | 307 ++++++++++++++ .../tools/scalap/scalasig/ScalaSigPrinter.scala | 434 ++++++++++++++++++++ .../scalasig/SourceFileAttributeParser.scala | 24 ++ .../scala/tools/scalap/scalasig/Symbol.scala | 70 ++++ src/scalap/scala/tools/scalap/scalasig/Type.scala | 22 ++ .../tools/scalap/scalax/rules/Memoisable.scala | 61 --- .../scala/tools/scalap/scalax/rules/Result.scala | 72 ---- .../scala/tools/scalap/scalax/rules/Rule.scala | 177 --------- .../scala/tools/scalap/scalax/rules/Rules.scala | 146 ------- .../scala/tools/scalap/scalax/rules/SeqRule.scala | 101 ----- .../scalax/rules/scalasig/ClassFileParser.scala | 249 ------------ .../tools/scalap/scalax/rules/scalasig/Flags.scala | 68 ---- .../scalap/scalax/rules/scalasig/ScalaSig.scala | 306 -------------- .../scalax/rules/scalasig/ScalaSigPrinter.scala | 439 --------------------- .../rules/scalasig/SourceFileAttributeParser.scala | 28 -- .../scalap/scalax/rules/scalasig/Symbol.scala | 73 ---- .../tools/scalap/scalax/rules/scalasig/Type.scala | 25 -- .../tools/scalap/scalax/util/StringUtil.scala | 19 - 37 files changed, 1744 insertions(+), 1820 deletions(-) create mode 100644 src/scalap/scala/tools/scalap/rules/Memoisable.scala create mode 100644 src/scalap/scala/tools/scalap/rules/Result.scala create mode 100644 src/scalap/scala/tools/scalap/rules/Rule.scala create mode 100644 src/scalap/scala/tools/scalap/rules/Rules.scala create mode 100644 src/scalap/scala/tools/scalap/rules/SeqRule.scala create mode 100644 src/scalap/scala/tools/scalap/rules/package.scala create mode 100644 src/scalap/scala/tools/scalap/scalasig/ClassFileParser.scala create mode 100644 src/scalap/scala/tools/scalap/scalasig/Flags.scala create mode 100644 src/scalap/scala/tools/scalap/scalasig/ScalaSig.scala create mode 100644 src/scalap/scala/tools/scalap/scalasig/ScalaSigPrinter.scala create mode 100644 src/scalap/scala/tools/scalap/scalasig/SourceFileAttributeParser.scala create mode 100644 src/scalap/scala/tools/scalap/scalasig/Symbol.scala create mode 100644 src/scalap/scala/tools/scalap/scalasig/Type.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/rules/Memoisable.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/rules/Result.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/rules/Rule.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/rules/Rules.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/rules/SeqRule.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/rules/scalasig/ClassFileParser.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/rules/scalasig/Flags.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/rules/scalasig/SourceFileAttributeParser.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/rules/scalasig/Symbol.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala delete mode 100644 src/scalap/scala/tools/scalap/scalax/util/StringUtil.scala (limited to 'src') diff --git a/src/partest/scala/tools/partest/nest/Runner.scala b/src/partest/scala/tools/partest/nest/Runner.scala index 6b09aa4689..fa2fb99f2f 100644 --- a/src/partest/scala/tools/partest/nest/Runner.scala +++ b/src/partest/scala/tools/partest/nest/Runner.scala @@ -20,7 +20,7 @@ import scala.tools.nsc.{ Settings, CompilerCommand, Global } import scala.tools.nsc.reporters.ConsoleReporter import scala.tools.nsc.util.{ Exceptional, ScalaClassLoader, stackTraceString } import scala.tools.scalap.Main.decompileScala -import scala.tools.scalap.scalax.rules.scalasig.ByteCode +import scala.tools.scalap.scalasig.ByteCode import scala.util.{ Try, Success, Failure } import ClassPath.{ join, split } import PartestDefaults.{ javaCmd, javacCmd } diff --git a/src/scalap/scala/tools/scalap/Arguments.scala b/src/scalap/scala/tools/scalap/Arguments.scala index 9f139cb5ea..123516bb2d 100644 --- a/src/scalap/scala/tools/scalap/Arguments.scala +++ b/src/scalap/scala/tools/scalap/Arguments.scala @@ -5,7 +5,6 @@ ** */ - package scala.tools.scalap import scala.collection.mutable diff --git a/src/scalap/scala/tools/scalap/ByteArrayReader.scala b/src/scalap/scala/tools/scalap/ByteArrayReader.scala index cf160871dd..59f083ee76 100644 --- a/src/scalap/scala/tools/scalap/ByteArrayReader.scala +++ b/src/scalap/scala/tools/scalap/ByteArrayReader.scala @@ -5,10 +5,7 @@ ** */ - -package scala -package tools.scalap - +package scala.tools.scalap class ByteArrayReader(content: Array[Byte]) { @@ -104,9 +101,6 @@ class ByteArrayReader(content: Array[Byte]) { def getDouble(bp: Int): Double = java.lang.Double.longBitsToDouble(getLong(bp)) /** skip next 'n' bytes - */ - def skip(n: Int) { - bp += n - } - + */ + def skip(n: Int): Unit = bp += n } diff --git a/src/scalap/scala/tools/scalap/Classfile.scala b/src/scalap/scala/tools/scalap/Classfile.scala index f62df285f9..d9d264bbbf 100644 --- a/src/scalap/scala/tools/scalap/Classfile.scala +++ b/src/scalap/scala/tools/scalap/Classfile.scala @@ -5,10 +5,8 @@ ** */ - package scala.tools.scalap - class Classfile(in: ByteArrayReader) { import Classfiles._ diff --git a/src/scalap/scala/tools/scalap/Classfiles.scala b/src/scalap/scala/tools/scalap/Classfiles.scala index 9295dd7aff..982a83cfa0 100644 --- a/src/scalap/scala/tools/scalap/Classfiles.scala +++ b/src/scalap/scala/tools/scalap/Classfiles.scala @@ -5,10 +5,8 @@ ** */ - package scala.tools.scalap - object Classfiles { final val JAVA_MAGIC = 0xCAFEBABE final val JAVA_MAJOR_VERSION = 45 diff --git a/src/scalap/scala/tools/scalap/CodeWriter.scala b/src/scalap/scala/tools/scalap/CodeWriter.scala index 168050096d..21c4399d5c 100644 --- a/src/scalap/scala/tools/scalap/CodeWriter.scala +++ b/src/scalap/scala/tools/scalap/CodeWriter.scala @@ -6,13 +6,9 @@ */ -package scala -package tools.scalap +package scala.tools.scalap -import java.io._ - - -class CodeWriter(writer: Writer) { +class CodeWriter(writer: java.io.Writer) { private val nl = scala.compat.Platform.EOL private var step = " " diff --git a/src/scalap/scala/tools/scalap/Decode.scala b/src/scalap/scala/tools/scalap/Decode.scala index 76ce3f4173..69325c1ec8 100644 --- a/src/scalap/scala/tools/scalap/Decode.scala +++ b/src/scalap/scala/tools/scalap/Decode.scala @@ -5,17 +5,14 @@ ** */ -// $Id$ - package scala.tools.scalap -import scala.tools.scalap.scalax.rules.scalasig._ -import scala.tools.nsc.util.ScalaClassLoader -import scala.tools.nsc.util.ScalaClassLoader.appLoader +import scala.tools.scalap.scalasig._ + +import scala.reflect.internal.util.ScalaClassLoader import scala.reflect.internal.pickling.ByteCodecs import ClassFileParser.{ ConstValueIndex, Annotation } -import Main.{ SCALA_SIG, SCALA_SIG_ANNOTATION, BYTES_VALUE } /** Temporary decoder. This would be better off in the scala.tools.nsc * but right now the compiler won't acknowledge scala.tools.scalap @@ -31,7 +28,7 @@ object Decode { /** Return the classfile bytes representing the scala sig classfile attribute. * This has been obsoleted by the switch to annotations. */ - def scalaSigBytes(name: String): Option[Array[Byte]] = scalaSigBytes(name, appLoader) + def scalaSigBytes(name: String): Option[Array[Byte]] = scalaSigBytes(name, ScalaClassLoader.appLoader) def scalaSigBytes(name: String, classLoader: ScalaClassLoader): Option[Array[Byte]] = { val bytes = classLoader.classBytes(name) val reader = new ByteArrayReader(bytes) @@ -39,17 +36,16 @@ object Decode { cf.scalaSigAttribute map (_.data) } - /** Return the bytes representing the annotation - */ - def scalaSigAnnotationBytes(name: String): Option[Array[Byte]] = scalaSigAnnotationBytes(name, appLoader) + /** Return the bytes representing the annotation. */ + def scalaSigAnnotationBytes(name: String): Option[Array[Byte]] = scalaSigAnnotationBytes(name, ScalaClassLoader.appLoader) def scalaSigAnnotationBytes(name: String, classLoader: ScalaClassLoader): Option[Array[Byte]] = { val bytes = classLoader.classBytes(name) val byteCode = ByteCode(bytes) val classFile = ClassFileParser.parse(byteCode) import classFile._ - classFile annotation SCALA_SIG_ANNOTATION map { case Annotation(_, els) => - val bytesElem = els find (x => constant(x.elementNameIndex) == BYTES_VALUE) getOrElse null + classFile annotation Main.SCALA_SIG_ANNOTATION map { case Annotation(_, els) => + val bytesElem = els find (x => constant(x.elementNameIndex) == Main.BYTES_VALUE) getOrElse null val _bytes = bytesElem.elementValue match { case ConstValueIndex(x) => constantWrapped(x) } val bytes = _bytes.asInstanceOf[StringBytesPair].bytes val length = ByteCodecs.decode(bytes) @@ -58,8 +54,7 @@ object Decode { } } - /** private[scala] so nobody gets the idea this is a supported interface. - */ + /** private[scala] so nobody gets the idea this is a supported interface. */ private[scala] def caseParamNames(path: String): Option[List[String]] = { val (outer, inner) = (path indexOf '$') match { case -1 => (path, "") @@ -67,7 +62,7 @@ object Decode { } for { - clazz <- appLoader.tryToLoadClass[AnyRef](outer) + clazz <- ScalaClassLoader.appLoader.tryToLoadClass[AnyRef](outer) ssig <- ScalaSigParser.parse(clazz) } yield { @@ -85,11 +80,10 @@ object Decode { } } - /** Returns a map of Alias -> Type for the given package. - */ + /** Returns a map of Alias -> Type for the given package. */ private[scala] def typeAliases(pkg: String) = { for { - clazz <- appLoader.tryToLoadClass[AnyRef](pkg + ".package") + clazz <- ScalaClassLoader.appLoader.tryToLoadClass[AnyRef](pkg + ".package") ssig <- ScalaSigParser.parse(clazz) } yield { diff --git a/src/scalap/scala/tools/scalap/JavaWriter.scala b/src/scalap/scala/tools/scalap/JavaWriter.scala index 772cf6eacd..1ba89e4702 100644 --- a/src/scalap/scala/tools/scalap/JavaWriter.scala +++ b/src/scalap/scala/tools/scalap/JavaWriter.scala @@ -5,13 +5,11 @@ ** */ - package scala.tools.scalap -import java.io._ import scala.reflect.NameTransformer -class JavaWriter(classfile: Classfile, writer: Writer) extends CodeWriter(writer) { +class JavaWriter(classfile: Classfile, writer: java.io.Writer) extends CodeWriter(writer) { val cf = classfile diff --git a/src/scalap/scala/tools/scalap/Main.scala b/src/scalap/scala/tools/scalap/Main.scala index c72f416a89..44d7ef6a41 100644 --- a/src/scalap/scala/tools/scalap/Main.scala +++ b/src/scalap/scala/tools/scalap/Main.scala @@ -5,17 +5,17 @@ ** */ -package scala -package tools.scalap +package scala.tools.scalap import java.io.{ PrintStream, OutputStreamWriter, ByteArrayOutputStream } -import scala.reflect.NameTransformer -import scalax.rules.scalasig._ + import scala.tools.nsc.util.{ ClassPath, JavaClassPath } -import scala.tools.util.PathResolver -import ClassPath.DefaultJavaContext +import scala.tools.nsc.util.ClassPath.DefaultJavaContext import scala.tools.nsc.io.AbstractFile +import scala.tools.scalap.scalasig._ + + /**The main object used to execute scalap on the command-line. * * @author Matthias Zenger, Stephane Micheloud, Burak Emir, Ilya Sergey @@ -104,7 +104,7 @@ class Main { // we have to encode every fragment of a name separately, otherwise the NameTransformer // will encode using unicode escaping dot separators as well // we can afford allocations because this is not a performance critical code - classname.split('.').map(NameTransformer.encode).mkString(".") + classname.split('.').map(scala.reflect.NameTransformer.encode).mkString(".") } val cls = path.findClass(encName) if (cls.isDefined && cls.get.binary.isDefined) { @@ -185,7 +185,7 @@ object Main extends Main { 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(".") // include '.' in the default classpath SI-6669 + case _ => scala.tools.util.PathResolver.fromPathString(".") // include '.' in the default classpath SI-6669 } // print the classpath if output is verbose if (verbose) diff --git a/src/scalap/scala/tools/scalap/MetaParser.scala b/src/scalap/scala/tools/scalap/MetaParser.scala index 1ebf86268a..324330466f 100644 --- a/src/scalap/scala/tools/scalap/MetaParser.scala +++ b/src/scalap/scala/tools/scalap/MetaParser.scala @@ -6,17 +6,15 @@ */ -package scala -package tools.scalap +package scala.tools.scalap -import java.util._ /** a parser class for parsing meta type information in classfiles * generated by pico. */ class MetaParser(meta: String) { - val scanner = new StringTokenizer(meta, "()[], \t<;", true) + val scanner = new java.util.StringTokenizer(meta, "()[], \t<;", true) var token: String = _ val res = new StringBuffer diff --git a/src/scalap/scala/tools/scalap/Properties.scala b/src/scalap/scala/tools/scalap/Properties.scala index 8f9a9d8606..432dd495e9 100644 --- a/src/scalap/scala/tools/scalap/Properties.scala +++ b/src/scalap/scala/tools/scalap/Properties.scala @@ -9,8 +9,7 @@ package scala.tools.scalap /** Loads decoder.properties from the jar. */ -object Properties extends scala.util.PropertiesTrait -{ +object Properties extends scala.util.PropertiesTrait { protected def propCategory = "decoder" protected def pickJarBasedOn = classOf[Classfile] } diff --git a/src/scalap/scala/tools/scalap/rules/Memoisable.scala b/src/scalap/scala/tools/scalap/rules/Memoisable.scala new file mode 100644 index 0000000000..236b993c4b --- /dev/null +++ b/src/scalap/scala/tools/scalap/rules/Memoisable.scala @@ -0,0 +1,56 @@ +// ----------------------------------------------------------------------------- +// +// Scalax - The Scala Community Library +// Copyright (c) 2005-8 The Scalax Project. All rights reserved. +// +// The primary distribution site is http://scalax.scalaforge.org/ +// +// This software is released under the terms of the Revised BSD License. +// There is NO WARRANTY. See the file LICENSE for the full text. +// +// ----------------------------------------------------------------------------- + +package scala.tools.scalap.rules + +import scala.collection.mutable + +trait MemoisableRules extends Rules { + def memo[In <: Memoisable, Out, A, X](key : AnyRef)(toRule : => In => Result[Out, A, X]) = { + lazy val rule = toRule + from[In] { in => in.memo(key, rule(in)) } + } + + override def ruleWithName[In, Out, A, X](name : String, f : In => Result[Out, A, X]) = super.ruleWithName(name, (in : In) => in match { + case s : Memoisable => s.memo(name, f(in)) + case _ => f(in) + }) +} + +trait Memoisable { + def memo[A](key : AnyRef, a : => A) : A +} + + +object DefaultMemoisable { + var debug = false +} + +trait DefaultMemoisable extends Memoisable { + protected val map = new mutable.HashMap[AnyRef, Any] + + def memo[A](key : AnyRef, a : => A) = { + map.getOrElseUpdate(key, compute(key, a)).asInstanceOf[A] + } + + protected def compute[A](key : AnyRef, a : => A): Any = a match { + case success : Success[_, _] => onSuccess(key, success); success + case other => + if(DefaultMemoisable.debug) println(key + " -> " + other) + other + } + + protected def onSuccess[S, T](key : AnyRef, result : Success[S, T]) { + val Success(out, t) = result + if(DefaultMemoisable.debug) println(key + " -> " + t + " (" + out + ")") + } +} diff --git a/src/scalap/scala/tools/scalap/rules/Result.scala b/src/scalap/scala/tools/scalap/rules/Result.scala new file mode 100644 index 0000000000..ef4d0eb8b0 --- /dev/null +++ b/src/scalap/scala/tools/scalap/rules/Result.scala @@ -0,0 +1,70 @@ +// ----------------------------------------------------------------------------- +// +// Scalax - The Scala Community Library +// Copyright (c) 2005-8 The Scalax Project. All rights reserved. +// +// The primary distribution site is http://scalax.scalaforge.org/ +// +// This software is released under the terms of the Revised BSD License. +// There is NO WARRANTY. See the file LICENSE for the full text. +// +// ----------------------------------------------------------------------------- + +package scala.tools.scalap.rules; + +/** Represents the combined value of two rules applied in sequence. + * + * @see the Scala parser combinator + */ +case class ~[+A, +B](_1 : A, _2 : B) { + override def toString = "(" + _1 + " ~ " + _2 + ")" +} + + +sealed abstract class Result[+Out, +A, +X] { + def out : Out + def value : A + def error : X + + implicit def toOption : Option[A] + + def map[B](f : A => B) : Result[Out, B, X] + def mapOut[Out2](f : Out => Out2) : Result[Out2, A, X] + def map[Out2, B](f : (Out, A) => (Out2, B)) : Result[Out2, B, X] + def flatMap[Out2, B](f : (Out, A) => Result[Out2, B, Nothing]) : Result[Out2, B, X] + def orElse[Out2 >: Out, B >: A](other : => Result[Out2, B, Nothing]) : Result[Out2, B, X] +} + +case class Success[+Out, +A](out : Out, value : A) extends Result[Out, A, Nothing] { + def error = throw new ScalaSigParserError("No error") + + def toOption = Some(value) + + def map[B](f : A => B) : Result[Out, B, Nothing] = Success(out, f(value)) + def mapOut[Out2](f : Out => Out2) : Result[Out2, A, Nothing] = Success(f(out), value) + def map[Out2, B](f : (Out, A) => (Out2, B)) : Success[Out2, B] = f(out, value) match { case (out2, b) => Success(out2, b) } + def flatMap[Out2, B](f : (Out, A) => Result[Out2, B, Nothing]) : Result[Out2, B, Nothing]= f(out, value) + def orElse[Out2 >: Out, B >: A](other : => Result[Out2, B, Nothing]) : Result[Out2, B, Nothing] = this +} + +sealed abstract class NoSuccess[+X] extends Result[Nothing, Nothing, X] { + def out = throw new ScalaSigParserError("No output") + def value = throw new ScalaSigParserError("No value") + + def toOption = None + + def map[B](f : Nothing => B) = this + def mapOut[Out2](f : Nothing => Out2) = this + def map[Out2, B](f : (Nothing, Nothing) => (Out2, B)) = this + def flatMap[Out2, B](f : (Nothing, Nothing) => Result[Out2, B, Nothing]) = this + def orElse[Out2, B](other : => Result[Out2, B, Nothing]) = other +} + +case object Failure extends NoSuccess[Nothing] { + def error = throw new ScalaSigParserError("No error") +} + +case class ScalaSigParserError(msg: String) extends RuntimeException(msg) + +case class Error[+X](error : X) extends NoSuccess[X] { +} diff --git a/src/scalap/scala/tools/scalap/rules/Rule.scala b/src/scalap/scala/tools/scalap/rules/Rule.scala new file mode 100644 index 0000000000..ccfdf7b8c1 --- /dev/null +++ b/src/scalap/scala/tools/scalap/rules/Rule.scala @@ -0,0 +1,172 @@ +// ----------------------------------------------------------------------------- +// +// Scalax - The Scala Community Library +// Copyright (c) 2005-8 The Scalax Project. All rights reserved. +// +// The primary distribution site is http://scalax.scalaforge.org/ +// +// This software is released under the terms of the Revised BSD License. +// There is NO WARRANTY. See the file LICENSE for the full text. +// +// ----------------------------------------------------------------------------- + +package scala.tools.scalap.rules + +/** A Rule is a function from some input to a Result. The result may be: + *
    + *
  • Success, with a value of some type and an output that may serve as the input to subsequent rules.
  • + *
  • Failure. A failure may result in some alternative rule being applied.
  • + *
  • Error. No further rules should be attempted.
  • + *
+ * + * @author Andrew Foggin + * + * Inspired by the Scala parser combinator. + */ +trait Rule[-In, +Out, +A, +X] extends (In => Result[Out, A, X]) { + val factory : Rules + import factory._ + + def as(name : String) = ruleWithName(name, this) + + def flatMap[Out2, B, X2 >: X](fa2ruleb : A => Out => Result[Out2, B, X2]) = mapResult { + case Success(out, a) => fa2ruleb(a)(out) + case Failure => Failure + case err @ Error(_) => err + } + + def map[B](fa2b : A => B) = flatMap { a => out => Success(out, fa2b(a)) } + + def filter(f : A => Boolean) = flatMap { a => out => if(f(a)) Success(out, a) else Failure } + + def mapResult[Out2, B, Y](f : Result[Out, A, X] => Result[Out2, B, Y]) = rule { + in : In => f(apply(in)) + } + + def orElse[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other : => Rule[In2, Out2, A2, X2]) : Rule[In2, Out2, A2, X2] = new Choice[In2, Out2, A2, X2] { + val factory = Rule.this.factory + lazy val choices = Rule.this :: other :: Nil + } + + def orError[In2 <: In] = this orElse error[Any] + + def |[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other : => Rule[In2, Out2, A2, X2]) = orElse(other) + + def ^^[B](fa2b : A => B) = map(fa2b) + + def ^^?[B](pf : PartialFunction[A, B]) = filter (pf.isDefinedAt(_)) ^^ pf + + def ??(pf : PartialFunction[A, Any]) = filter (pf.isDefinedAt(_)) + + def -^[B](b : B) = map { any => b } + + /** Maps an Error */ + def !^[Y](fx2y : X => Y) = mapResult { + case s @ Success(_, _) => s + case Failure => Failure + case Error(x) => Error(fx2y(x)) + } + + def >>[Out2, B, X2 >: X](fa2ruleb : A => Out => Result[Out2, B, X2]) = flatMap(fa2ruleb) + + def >->[Out2, B, X2 >: X](fa2resultb : A => Result[Out2, B, X2]) = flatMap { a => any => fa2resultb(a) } + + def >>?[Out2, B, X2 >: X](pf : PartialFunction[A, Rule[Out, Out2, B, X2]]) = filter(pf isDefinedAt _) flatMap pf + + def >>&[B, X2 >: X](fa2ruleb : A => Out => Result[Any, B, X2]) = flatMap { a => out => fa2ruleb(a)(out) mapOut { any => out } } + + def ~[Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next) yield new ~(a, b) + + def ~-[Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next) yield a + + def -~[Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next) yield b + + def ~++[Out2, B >: A, X2 >: X](next : => Rule[Out, Out2, Seq[B], X2]) = for (a <- this; b <- next) yield a :: b.toList + + /** Apply the result of this rule to the function returned by the next rule */ + def ~>[Out2, B, X2 >: X](next : => Rule[Out, Out2, A => B, X2]) = for (a <- this; fa2b <- next) yield fa2b(a) + + /** Apply the result of this rule to the function returned by the previous rule */ + def <~:[InPrev, B, X2 >: X](prev : => Rule[InPrev, In, A => B, X2]) = for (fa2b <- prev; a <- this) yield fa2b(a) + + def ~![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next.orError) yield new ~(a, b) + + def ~-![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next.orError) yield a + + def -~![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next.orError) yield b + + def -[In2 <: In](exclude : => Rule[In2, Any, Any, Any]) = !exclude -~ this + + /** ^~^(f) is equivalent to ^^ { case b1 ~ b2 => f(b1, b2) } + */ + def ^~^[B1, B2, B >: A <% B1 ~ B2, C](f : (B1, B2) => C) = map { a => + (a : B1 ~ B2) match { case b1 ~ b2 => f(b1, b2) } + } + + /** ^~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 => f(b1, b2, b3) } + */ + def ^~~^[B1, B2, B3, B >: A <% B1 ~ B2 ~ B3, C](f : (B1, B2, B3) => C) = map { a => + (a : B1 ~ B2 ~ B3) match { case b1 ~ b2 ~ b3 => f(b1, b2, b3) } + } + + /** ^~~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 ~ b4 => f(b1, b2, b3, b4) } + */ + def ^~~~^[B1, B2, B3, B4, B >: A <% B1 ~ B2 ~ B3 ~ B4, C](f : (B1, B2, B3, B4) => C) = map { a => + (a : B1 ~ B2 ~ B3 ~ B4) match { case b1 ~ b2 ~ b3 ~ b4 => f(b1, b2, b3, b4) } + } + + /** ^~~~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 ~ b4 ~ b5 => f(b1, b2, b3, b4, b5) } + */ + def ^~~~~^[B1, B2, B3, B4, B5, B >: A <% B1 ~ B2 ~ B3 ~ B4 ~ B5, C](f : (B1, B2, B3, B4, B5) => C) = map { a => + (a : B1 ~ B2 ~ B3 ~ B4 ~ B5) match { case b1 ~ b2 ~ b3 ~ b4 ~ b5 => f(b1, b2, b3, b4, b5) } + } + + /** ^~~~~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 => f(b1, b2, b3, b4, b5, b6) } + */ + def ^~~~~~^[B1, B2, B3, B4, B5, B6, B >: A <% B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6, C](f : (B1, B2, B3, B4, B5, B6) => C) = map { a => + (a : B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6) match { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 => f(b1, b2, b3, b4, b5, b6) } + } + + /** ^~~~~~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 => f(b1, b2, b3, b4, b5, b6) } + */ + def ^~~~~~~^[B1, B2, B3, B4, B5, B6, B7, B >: A <% B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6 ~ B7, C](f : (B1, B2, B3, B4, B5, B6, B7) => C) = map { a => + (a : B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6 ~ B7) match { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 ~b7 => f(b1, b2, b3, b4, b5, b6, b7) } + } + + /** >~>(f) is equivalent to >> { case b1 ~ b2 => f(b1, b2) } + */ + def >~>[Out2, B1, B2, B >: A <% B1 ~ B2, C, X2 >: X](f : (B1, B2) => Out => Result[Out2, C, X2]) = flatMap { a => + (a : B1 ~ B2) match { case b1 ~ b2 => f(b1, b2) } + } + + /** ^-^(f) is equivalent to ^^ { b2 => b1 => f(b1, b2) } + */ + def ^-^ [B1, B2 >: A, C](f : (B1, B2) => C) = map { b2 : B2 => b1 : B1 => f(b1, b2) } + + /** ^~>~^(f) is equivalent to ^^ { case b2 ~ b3 => b1 => f(b1, b2, b3) } + */ + def ^~>~^ [B1, B2, B3, B >: A <% B2 ~ B3, C](f : (B1, B2, B3) => C) = map { a => + (a : B2 ~ B3) match { case b2 ~ b3 => b1 : B1 => f(b1, b2, b3) } + } +} + + +trait Choice[-In, +Out, +A, +X] extends Rule[In, Out, A, X] { + def choices : List[Rule[In, Out, A, X]] + + def apply(in : In) = { + def oneOf(list : List[Rule[In, Out, A, X]]) : Result[Out, A, X] = list match { + case Nil => Failure + case first :: rest => first(in) match { + case Failure => oneOf(rest) + case result => result + } + } + oneOf(choices) + } + + override def orElse[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other : => Rule[In2, Out2, A2, X2]) : Rule[In2, Out2, A2, X2] = new Choice[In2, Out2, A2, X2] { + val factory = Choice.this.factory + lazy val choices = Choice.this.choices ::: other :: Nil + } +} diff --git a/src/scalap/scala/tools/scalap/rules/Rules.scala b/src/scalap/scala/tools/scalap/rules/Rules.scala new file mode 100644 index 0000000000..85a6b263de --- /dev/null +++ b/src/scalap/scala/tools/scalap/rules/Rules.scala @@ -0,0 +1,150 @@ +// ----------------------------------------------------------------------------- +// +// Scalax - The Scala Community Library +// Copyright (c) 2005-8 The Scalax Project. All rights reserved. +// +// The primary distribution site is http://scalax.scalaforge.org/ +// +// This software is released under the terms of the Revised BSD License. +// There is NO WARRANTY. See the file LICENSE for the full text. +// +// ----------------------------------------------------------------------------- + +package scala.tools.scalap +package rules + +trait Name { + def name : String + override def toString = name +} + +/** A factory for rules. + * + * @author Andrew Foggin + * + * Inspired by the Scala parser combinator. + */ +trait Rules { + + import scala.language.implicitConversions + implicit def rule[In, Out, A, X](f : In => Result[Out, A, X]) : Rule[In, Out, A, X] = new DefaultRule(f) + implicit def inRule[In, Out, A, X](rule : Rule[In, Out, A, X]) : InRule[In, Out, A, X] = new InRule(rule) + implicit def seqRule[In, A, X](rule : Rule[In, In, A, X]) : SeqRule[In, A, X] = new SeqRule(rule) + + trait FromRule[In] { + def apply[Out, A, X](f : In => Result[Out, A, X]): Rule[In, Out, A, X] + } + + def from[In] = new FromRule[In] { + def apply[Out, A, X](f : In => Result[Out, A, X]) = rule(f) + } + + def state[s] = new StateRules { + type S = s + val factory = Rules.this + } + + def success[Out, A](out : Out, a : A) = rule { in : Any => Success(out, a) } + + def failure = rule { in : Any => Failure } + + def error[In] = rule { in : In => Error(in) } + def error[X](err : X) = rule { in : Any => Error(err) } + + def oneOf[In, Out, A, X](rules : Rule[In, Out, A, X] *) : Rule[In, Out, A, X] = new Choice[In, Out, A, X] { + val factory = Rules.this + val choices = rules.toList + } + + def ruleWithName[In, Out, A, X](_name : String, f : In => Result[Out, A, X]) : Rule[In, Out, A, X] with Name = + new DefaultRule(f) with Name { + val name = _name + } + + class DefaultRule[In, Out, A, X](f : In => Result[Out, A, X]) extends Rule[In, Out, A, X] { + val factory = Rules.this + def apply(in : In) = f(in) + } + + /** Converts a rule into a function that throws an Exception on failure. */ + def expect[In, Out, A, Any](rule : Rule[In, Out, A, Any]) : In => A = (in) => rule(in) match { + case Success(_, a) => a + case Failure => throw new ScalaSigParserError("Unexpected failure") + case Error(x) => throw new ScalaSigParserError("Unexpected error: " + x) + } +} + +/** A factory for rules that apply to a particular context. + * + * @requires S the context to which rules apply. + * + * @author Andrew Foggin + * + * Inspired by the Scala parser combinator. + */ +trait StateRules { + type S + type Rule[+A, +X] = rules.Rule[S, S, A, X] + + val factory : Rules + import factory._ + + def apply[A, X](f : S => Result[S, A, X]) = rule(f) + + def unit[A](a : => A) = apply { s => Success(s, a) } + def read[A](f : S => A) = apply { s => Success(s, f(s)) } + + def get = apply { s => Success(s, s) } + def set(s : => S) = apply { oldS => Success(s, oldS) } + + def update(f : S => S) = apply { s => Success(s, f(s)) } + + def nil = unit(Nil) + def none = unit(None) + + /** Create a rule that identities if f(in) is true. */ + def cond(f : S => Boolean) = get filter f + + /** Create a rule that succeeds if all of the given rules succeed. + @param rules the rules to apply in sequence. + */ + def allOf[A, X](rules : Seq[Rule[A, X]]) = { + def rep(in : S, rules : List[Rule[A, X]], results : List[A]) : Result[S, List[A], X] = { + rules match { + case Nil => Success(in, results.reverse) + case rule::tl => rule(in) match { + case Failure => Failure + case Error(x) => Error(x) + case Success(out, v) => rep(out, tl, v::results) + } + } + } + in : S => rep(in, rules.toList, Nil) + } + + + /** Create a rule that succeeds with a list of all the provided rules that succeed. + @param rules the rules to apply in sequence. + */ + def anyOf[A, X](rules : Seq[Rule[A, X]]) = allOf(rules.map(_ ?)) ^^ { opts => opts.flatMap(x => x) } + + /** Repeatedly apply a rule from initial value until finished condition is met. */ + def repeatUntil[T, X](rule : Rule[T => T, X])(finished : T => Boolean)(initial : T) = apply { + // more compact using HoF but written this way so it's tail-recursive + def rep(in : S, t : T) : Result[S, T, X] = { + if (finished(t)) Success(in, t) + else rule(in) match { + case Success(out, f) => rep(out, f(t)) // SI-5189 f.asInstanceOf[T => T] + case Failure => Failure + case Error(x) => Error(x) + } + } + in => rep(in, initial) + } + + +} + +trait RulesWithState extends Rules with StateRules { + val factory = this +} diff --git a/src/scalap/scala/tools/scalap/rules/SeqRule.scala b/src/scalap/scala/tools/scalap/rules/SeqRule.scala new file mode 100644 index 0000000000..2d62ee42e6 --- /dev/null +++ b/src/scalap/scala/tools/scalap/rules/SeqRule.scala @@ -0,0 +1,98 @@ +// ----------------------------------------------------------------------------- +// +// Scalax - The Scala Community Library +// Copyright (c) 2005-8 The Scalax Project. All rights reserved. +// +// The primary distribution site is http://scalax.scalaforge.org/ +// +// This software is released under the terms of the Revised BSD License. +// There is NO WARRANTY. See the file LICENSE for the full text. +// +// ----------------------------------------------------------------------------- + +package scala.tools.scalap.rules + +/** + * A workaround for the difficulties of dealing with + * a contravariant 'In' parameter type... + */ +class InRule[In, +Out, +A, +X](rule : Rule[In, Out, A, X]) { + + def mapRule[Out2, B, Y](f : Result[Out, A, X] => In => Result[Out2, B, Y]) : Rule[In, Out2, B, Y] = rule.factory.rule { + in : In => f(rule(in))(in) + } + + /** Creates a rule that succeeds only if the original rule would fail on the given context. */ + def unary_! : Rule[In, In, Unit, Nothing] = mapRule { + case Success(_, _) => in : In => Failure + case _ => in : In => Success(in, ()) + } + + /** Creates a rule that succeeds if the original rule succeeds, but returns the original input. */ + def & : Rule[In, In, A, X] = mapRule { + case Success(_, a) => in : In => Success(in, a) + case Failure => in : In => Failure + case Error(x) => in : In => Error(x) + } +} + +class SeqRule[S, +A, +X](rule : Rule[S, S, A, X]) { + import rule.factory._ + + def ? = rule mapRule { + case Success(out, a) => in : S => Success(out, Some(a)) + case Failure => in : S => Success(in, None) + case Error(x) => in : S => Error(x) + } + + /** Creates a rule that always succeeds with a Boolean value. + * Value is 'true' if this rule succeeds, 'false' otherwise */ + def -? = ? map { _.isDefined } + + def * = from[S] { + // tail-recursive function with reverse list accumulator + def rep(in : S, acc : List[A]) : Result[S, List[A], X] = rule(in) match { + case Success(out, a) => rep(out, a :: acc) + case Failure => Success(in, acc.reverse) + case err : Error[_] => err + } + in => rep(in, Nil) + } + + def + = rule ~++ * + + def ~>?[B >: A, X2 >: X](f : => Rule[S, S, B => B, X2]) = for (a <- rule; fs <- f?) yield fs.foldLeft[B](a) { (b, f) => f(b) } + + def ~>*[B >: A, X2 >: X](f : => Rule[S, S, B => B, X2]) = for (a <- rule; fs <- f*) yield fs.foldLeft[B](a) { (b, f) => f(b) } + + def ~*~[B >: A, X2 >: X](join : => Rule[S, S, (B, B) => B, X2]) = { + this ~>* (for (f <- join; a <- rule) yield f(_ : B, a)) + } + + /** Repeats this rule one or more times with a separator (which is discarded) */ + def +/[X2 >: X](sep : => Rule[S, S, Any, X2]) = rule ~++ (sep -~ rule *) + + /** Repeats this rule zero or more times with a separator (which is discarded) */ + def */[X2 >: X](sep : => Rule[S, S, Any, X2]) = +/(sep) | state[S].nil + + def *~-[Out, X2 >: X](end : => Rule[S, Out, Any, X2]) = (rule - end *) ~- end + def +~-[Out, X2 >: X](end : => Rule[S, Out, Any, X2]) = (rule - end +) ~- end + + /** Repeats this rule num times */ + def times(num : Int) : Rule[S, S, Seq[A], X] = from[S] { + val result = new scala.collection.mutable.ArraySeq[A](num) + // more compact using HoF but written this way so it's tail-recursive + def rep(i : Int, in : S) : Result[S, Seq[A], X] = { + if (i == num) Success(in, result) + else rule(in) match { + case Success(out, a) => { + result(i) = a + rep(i + 1, out) + } + case Failure => Failure + case err : Error[_] => err + } + } + in => rep(0, in) + } +} diff --git a/src/scalap/scala/tools/scalap/rules/package.scala b/src/scalap/scala/tools/scalap/rules/package.scala new file mode 100644 index 0000000000..dcd5f7ac00 --- /dev/null +++ b/src/scalap/scala/tools/scalap/rules/package.scala @@ -0,0 +1,6 @@ +package scala.tools.scalap + +package object rules { + // make some language features in this package compile without warning + implicit def postfixOps = scala.language.postfixOps +} diff --git a/src/scalap/scala/tools/scalap/scalasig/ClassFileParser.scala b/src/scalap/scala/tools/scalap/scalasig/ClassFileParser.scala new file mode 100644 index 0000000000..ed438be7f2 --- /dev/null +++ b/src/scalap/scala/tools/scalap/scalasig/ClassFileParser.scala @@ -0,0 +1,240 @@ +package scala.tools.scalap.scalasig + +import scala.tools.scalap.rules.{ Success, Failure, ~, RulesWithState } + +object ByteCode { + def apply(bytes : Array[Byte]) = new ByteCode(bytes, 0, bytes.length) + + def forClass(clazz : Class[_]) = { + val name = clazz.getName + val subPath = name.substring(name.lastIndexOf('.') + 1) + ".class" + val in = clazz.getResourceAsStream(subPath) + + try { + var rest = in.available() + val bytes = new Array[Byte](rest) + while (rest > 0) { + val res = in.read(bytes, bytes.length - rest, rest) + if (res == -1) throw new java.io.IOException("read error") + rest -= res + } + ByteCode(bytes) + + } finally { + in.close() + } + } +} + +/** Represents a chunk of raw bytecode. Used as input for the parsers. */ +class ByteCode(val bytes : Array[Byte], val pos : Int, val length : Int) { + + assert(pos >= 0 && length >= 0 && pos + length <= bytes.length) + + def nextByte = if (length == 0) Failure else Success(drop(1), bytes(pos)) + def next(n : Int) = if (length >= n) Success(drop(n), take(n)) else Failure + + def take(n : Int) = new ByteCode(bytes, pos, n) + def drop(n : Int) = new ByteCode(bytes, pos + n, length - n) + + def fold[X](x : X)(f : (X, Byte) => X) : X = { + var result = x + var i = pos + while (i < pos + length) { + result = f(result, bytes(i)) + i += 1 + } + result + } + + override def toString = length + " bytes" + + def toInt = fold(0) { (x, b) => (x << 8) + (b & 0xFF)} + def toLong = fold(0L) { (x, b) => (x << 8) + (b & 0xFF)} + + /** + * Transforms array subsequence of the current buffer into the UTF8 String and + * stores and array of bytes for the decompiler + */ + def fromUTF8StringAndBytes = { + val chunk: Array[Byte] = new Array[Byte](length) + System.arraycopy(bytes, pos, chunk, 0, length) + val str = new String(io.Codec.fromUTF8(bytes, pos, length)) + + StringBytesPair(str, chunk) + } + + def byte(i : Int) = bytes(pos) & 0xFF +} + +/** + * The wrapper for decode UTF-8 string + */ +case class StringBytesPair(string: String, bytes: Array[Byte]) + +/** Provides rules for parsing byte-code. +*/ +trait ByteCodeReader extends RulesWithState { + type S = ByteCode + type Parser[A] = Rule[A, String] + + val byte = apply(_.nextByte) + + val u1 = byte ^^ (_ & 0xFF) + val u2 = bytes(2) ^^ (_.toInt) + val u4 = bytes(4) ^^ (_.toInt) // should map to Long?? + + def bytes(n : Int) = apply(_ next n) +} + +object ClassFileParser extends ByteCodeReader { + def parse(byteCode : ByteCode) = expect(classFile)(byteCode) + def parseAnnotations(byteCode: ByteCode) = expect(annotations)(byteCode) + + val magicNumber = (u4 filter (_ == 0xCAFEBABE)) | error("Not a valid class file") + val version = u2 ~ u2 ^^ { case minor ~ major => (major, minor) } + val constantPool = (u2 ^^ ConstantPool) >> repeatUntil(constantPoolEntry)(_.isFull) + + // NOTE currently most constants just evaluate to a string description + // TODO evaluate to useful values + val utf8String = (u2 >> bytes) ^^ add1 { raw => pool => raw.fromUTF8StringAndBytes } + val intConstant = u4 ^^ add1 { x => pool => x } + val floatConstant = bytes(4) ^^ add1 { raw => pool => "Float: TODO" } + val longConstant = bytes(8) ^^ add2 { raw => pool => raw.toLong } + val doubleConstant = bytes(8) ^^ add2 { raw => pool => "Double: TODO" } + val classRef = u2 ^^ add1 { x => pool => "Class: " + pool(x) } + val stringRef = u2 ^^ add1 { x => pool => "String: " + pool(x) } + val fieldRef = memberRef("Field") + val methodRef = memberRef("Method") + val interfaceMethodRef = memberRef("InterfaceMethod") + val nameAndType = u2 ~ u2 ^^ add1 { case name ~ descriptor => pool => "NameAndType: " + pool(name) + ", " + pool(descriptor) } + + val constantPoolEntry = u1 >> { + case 1 => utf8String + case 3 => intConstant + case 4 => floatConstant + case 5 => longConstant + case 6 => doubleConstant + case 7 => classRef + case 8 => stringRef + case 9 => fieldRef + case 10 => methodRef + case 11 => interfaceMethodRef + case 12 => nameAndType + } + + val interfaces = u2 >> u2.times + + // bytes are parametrizes by the length, declared in u4 section + val attribute = u2 ~ (u4 >> bytes) ^~^ Attribute + // parse attributes u2 times + val attributes = u2 >> attribute.times + + // parse runtime-visible annotations + abstract class ElementValue + case class AnnotationElement(elementNameIndex: Int, elementValue: ElementValue) + case class ConstValueIndex(index: Int) extends ElementValue + case class EnumConstValue(typeNameIndex: Int, constNameIndex: Int) extends ElementValue + case class ClassInfoIndex(index: Int) extends ElementValue + case class Annotation(typeIndex: Int, elementValuePairs: Seq[AnnotationElement]) extends ElementValue + case class ArrayValue(values: Seq[ElementValue]) extends ElementValue + + def element_value: Parser[ElementValue] = u1 >> { + case 'B'|'C'|'D'|'F'|'I'|'J'|'S'|'Z'|'s' => u2 ^^ ConstValueIndex + case 'e' => u2 ~ u2 ^~^ EnumConstValue + case 'c' => u2 ^^ ClassInfoIndex + case '@' => annotation //nested annotation + case '[' => u2 >> element_value.times ^^ ArrayValue + } + + val element_value_pair = u2 ~ element_value ^~^ AnnotationElement + val annotation: Parser[Annotation] = u2 ~ (u2 >> element_value_pair.times) ^~^ Annotation + val annotations = u2 >> annotation.times + + val field = u2 ~ u2 ~ u2 ~ attributes ^~~~^ Field + val fields = u2 >> field.times + + val method = u2 ~ u2 ~ u2 ~ attributes ^~~~^ Method + val methods = u2 >> method.times + + val header = magicNumber -~ u2 ~ u2 ~ constantPool ~ u2 ~ u2 ~ u2 ~ interfaces ^~~~~~~^ ClassFileHeader + val classFile = header ~ fields ~ methods ~ attributes ~- !u1 ^~~~^ ClassFile + + // TODO create a useful object, not just a string + def memberRef(description : String) = u2 ~ u2 ^^ add1 { + case classRef ~ nameAndTypeRef => pool => description + ": " + pool(classRef) + ", " + pool(nameAndTypeRef) + } + + def add1[T](f : T => ConstantPool => Any)(raw : T)(pool : ConstantPool) = pool add f(raw) + def add2[T](f : T => ConstantPool => Any)(raw : T)(pool : ConstantPool) = pool add f(raw) add { pool => "" } +} + +case class ClassFile( + header : ClassFileHeader, + fields : Seq[Field], + methods : Seq[Method], + attributes : Seq[Attribute]) { + + def majorVersion = header.major + def minorVersion = header.minor + + def className = constant(header.classIndex) + def superClass = constant(header.superClassIndex) + def interfaces = header.interfaces.map(constant) + + def constant(index : Int) = header.constants(index) match { + case StringBytesPair(str, _) => str + case z => z + } + + def constantWrapped(index: Int) = header.constants(index) + + def attribute(name : String) = attributes.find {attrib => constant(attrib.nameIndex) == name } + + val RUNTIME_VISIBLE_ANNOTATIONS = "RuntimeVisibleAnnotations" + def annotations = (attributes.find(attr => constant(attr.nameIndex) == RUNTIME_VISIBLE_ANNOTATIONS) + .map(attr => ClassFileParser.parseAnnotations(attr.byteCode))) + + def annotation(name: String) = annotations.flatMap(seq => seq.find(annot => constant(annot.typeIndex) == name)) +} + +case class Attribute(nameIndex : Int, byteCode : ByteCode) +case class Field(flags : Int, nameIndex : Int, descriptorIndex : Int, attributes : Seq[Attribute]) +case class Method(flags : Int, nameIndex : Int, descriptorIndex : Int, attributes : Seq[Attribute]) + +case class ClassFileHeader( + minor : Int, + major : Int, + constants : ConstantPool, + flags : Int, + classIndex : Int, + superClassIndex : Int, + interfaces : Seq[Int]) { + + def constant(index : Int) = constants(index) +} + +case class ConstantPool(len : Int) { + val size = len - 1 + + private val buffer = new scala.collection.mutable.ArrayBuffer[ConstantPool => Any] + private val values = Array.fill[Option[Any]](size)(None) + + def isFull = buffer.length >= size + + def apply(index : Int) = { + // Note constant pool indices are 1-based + val i = index - 1 + values(i) getOrElse { + val value = buffer(i)(this) + buffer(i) = null + values(i) = Some(value) + value + } + } + + def add(f : ConstantPool => Any) = { + buffer += f + this + } +} diff --git a/src/scalap/scala/tools/scalap/scalasig/Flags.scala b/src/scalap/scala/tools/scalap/scalasig/Flags.scala new file mode 100644 index 0000000000..de53b55b7e --- /dev/null +++ b/src/scalap/scala/tools/scalap/scalasig/Flags.scala @@ -0,0 +1,65 @@ +package scala.tools.scalap.scalasig + +trait Flags { + def hasFlag(flag : Long) : Boolean + + def isImplicit = hasFlag(0x00000001) + def isFinal = hasFlag(0x00000002) + def isPrivate = hasFlag(0x00000004) + def isProtected = hasFlag(0x00000008) + + def isSealed = hasFlag(0x00000010) + def isOverride = hasFlag(0x00000020) + def isCase = hasFlag(0x00000040) + def isAbstract = hasFlag(0x00000080) + + def isDeferred = hasFlag(0x00000100) + def isMethod = hasFlag(0x00000200) + def isModule = hasFlag(0x00000400) + def isInterface = hasFlag(0x00000800) + + def isMutable = hasFlag(0x00001000) + def isParam = hasFlag(0x00002000) + def isPackage = hasFlag(0x00004000) + def isDeprecated = hasFlag(0x00008000) + + def isCovariant = hasFlag(0x00010000) + def isCaptured = hasFlag(0x00010000) + + def isByNameParam = hasFlag(0x00010000) + def isContravariant = hasFlag(0x00020000) + def isLabel = hasFlag(0x00020000) // method symbol is a label. Set by TailCall + def isInConstructor = hasFlag(0x00020000) // class symbol is defined in this/superclass constructor + + def isAbstractOverride = hasFlag(0x00040000) + def isLocal = hasFlag(0x00080000) + + def isJava = hasFlag(0x00100000) + def isSynthetic = hasFlag(0x00200000) + def isStable = hasFlag(0x00400000) + def isStatic = hasFlag(0x00800000) + + def isCaseAccessor = hasFlag(0x01000000) + def isTrait = hasFlag(0x02000000) + def isBridge = hasFlag(0x04000000) + def isAccessor = hasFlag(0x08000000) + + def isSuperAccessor = hasFlag(0x10000000) + def isParamAccessor = hasFlag(0x20000000) + + def isModuleVar = hasFlag(0x40000000) // for variables: is the variable caching a module value + def isMonomorphic = hasFlag(0x40000000) // for type symbols: does not have type parameters + def isLazy = hasFlag(0x80000000L) // symbol is a lazy val. can't have MUTABLE unless transformed by typer + + def isError = hasFlag(0x100000000L) + def isOverloaded = hasFlag(0x200000000L) + def isLifted = hasFlag(0x400000000L) + + def isMixedIn = hasFlag(0x800000000L) + def isExistential = hasFlag(0x800000000L) + + def isExpandedName = hasFlag(0x1000000000L) + def isImplementationClass = hasFlag(0x2000000000L) + def isPreSuper = hasFlag(0x2000000000L) + +} diff --git a/src/scalap/scala/tools/scalap/scalasig/ScalaSig.scala b/src/scalap/scala/tools/scalap/scalasig/ScalaSig.scala new file mode 100644 index 0000000000..c32a3ff2d7 --- /dev/null +++ b/src/scalap/scala/tools/scalap/scalasig/ScalaSig.scala @@ -0,0 +1,307 @@ +/* ___ ____ ___ __ ___ ___ +** / _// __// _ | / / / _ | / _ \ Scala classfile decoder +** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003-2013, LAMP/EPFL +** /____/\___/_/ |_/____/_/ |_/_/ http://scala-lang.org/ +** +*/ + +package scala.tools.scalap.scalasig + +import scala.language.implicitConversions + +import scala.reflect.internal.pickling.ByteCodecs + +import scala.tools.scalap.Main +import scala.tools.scalap.rules._ + +import ClassFileParser.{ ConstValueIndex, Annotation } + +object ScalaSigParser { + + def scalaSigFromAnnotation(classFile: ClassFile): Option[ScalaSig] = { + import classFile._ + + classFile.annotation(Main.SCALA_SIG_ANNOTATION) map { + case Annotation(_, elements) => + val bytesElem = elements.find(elem => constant(elem.elementNameIndex) == Main.BYTES_VALUE).get + val bytes = ((bytesElem.elementValue match {case ConstValueIndex(index) => constantWrapped(index)}) + .asInstanceOf[StringBytesPair].bytes) + val length = ByteCodecs.decode(bytes) + + ScalaSigAttributeParsers.parse(ByteCode(bytes.take(length))) + } + } + + def scalaSigFromAttribute(classFile: ClassFile) : Option[ScalaSig] = + classFile.attribute(Main.SCALA_SIG).map(_.byteCode).map(ScalaSigAttributeParsers.parse) + + def parse(classFile: ClassFile): Option[ScalaSig] = { + val scalaSig = scalaSigFromAttribute(classFile) + + scalaSig match { + // No entries in ScalaSig attribute implies that the signature is stored in the annotation + case Some(ScalaSig(_, _, entries)) if entries.length == 0 => + scalaSigFromAnnotation(classFile) + case x => x + } + } + + def parse(clazz : Class[_]): Option[ScalaSig] = { + val byteCode = ByteCode.forClass(clazz) + val classFile = ClassFileParser.parse(byteCode) + + parse(classFile) + } +} + +object ScalaSigAttributeParsers extends ByteCodeReader { + def parse(byteCode : ByteCode) = expect(scalaSig)(byteCode) + + val nat = apply { + def natN(in : ByteCode, x : Int) : Result[ByteCode, Int, Nothing] = in.nextByte match { + case Success(out, b) => { + val y = (x << 7) + (b & 0x7f) + if ((b & 0x80) == 0) Success(out, y) else natN(out, y) + } + case _ => Failure + } + in => natN(in, 0) + } + + val rawBytes = nat >> bytes + val entry = nat ~ rawBytes + val symtab = nat >> entry.times + val scalaSig = nat ~ nat ~ symtab ^~~^ ScalaSig + + val utf8 = read(x => x.fromUTF8StringAndBytes.string) + val longValue = read(_ toLong) +} + +case class ScalaSig(majorVersion : Int, minorVersion : Int, table : Seq[Int ~ ByteCode]) extends DefaultMemoisable { + + case class Entry(index : Int, entryType : Int, byteCode : ByteCode) extends DefaultMemoisable { + def scalaSig = ScalaSig.this + + def setByteCode(byteCode : ByteCode) = Entry(index, entryType, byteCode) + } + + def hasEntry(index : Int) = table isDefinedAt index + + def getEntry(index : Int) = { + val entryType ~ byteCode = table(index) + Entry(index, entryType, byteCode) + } + + def parseEntry(index : Int) = applyRule(ScalaSigParsers.parseEntry(ScalaSigEntryParsers.entry)(index)) + + implicit def applyRule[A](parser : ScalaSigParsers.Parser[A]) = ScalaSigParsers.expect(parser)(this) + + override def toString = "ScalaSig version " + majorVersion + "." + minorVersion + { + for (i <- 0 until table.size) yield i + ":\t" + parseEntry(i) // + "\n\t" + getEntry(i) + }.mkString("\n", "\n", "") + + lazy val symbols : Seq[Symbol] = ScalaSigParsers.symbols + + lazy val topLevelClasses : List[ClassSymbol] = ScalaSigParsers.topLevelClasses + lazy val topLevelObjects : List[ObjectSymbol] = ScalaSigParsers.topLevelObjects +} + +object ScalaSigParsers extends RulesWithState with MemoisableRules { + type S = ScalaSig + type Parser[A] = Rule[A, String] + + val symTab = read(_.table) + val size = symTab ^^ (_.size) + + def entry(index : Int) = memo(("entry", index)) { + cond(_ hasEntry index) -~ read(_ getEntry index) >-> { entry => Success(entry, entry.entryType) } + } + + def parseEntry[A](parser : ScalaSigEntryParsers.EntryParser[A])(index : Int) : Parser[A] = + entry(index) -~ parser >> { a => entry => Success(entry.scalaSig, a) } + + def allEntries[A](f : ScalaSigEntryParsers.EntryParser[A]) = size >> { n => anyOf((0 until n) map parseEntry(f)) } + + lazy val entries = allEntries(ScalaSigEntryParsers.entry) as "entries" + lazy val symbols = allEntries(ScalaSigEntryParsers.symbol) as "symbols" + lazy val methods = allEntries(ScalaSigEntryParsers.methodSymbol) as "methods" + lazy val attributes = allEntries(ScalaSigEntryParsers.attributeInfo) as "attributes" + + lazy val topLevelClasses = allEntries(ScalaSigEntryParsers.topLevelClass) + lazy val topLevelObjects = allEntries(ScalaSigEntryParsers.topLevelObject) +} + +object ScalaSigEntryParsers extends RulesWithState with MemoisableRules { + import ScalaSigAttributeParsers.{nat, utf8, longValue} + + type S = ScalaSig#Entry + type EntryParser[A] = Rule[A, String] + + implicit def byteCodeEntryParser[A](rule : ScalaSigAttributeParsers.Parser[A]) : EntryParser[A] = apply { entry => + rule(entry.byteCode) mapOut (entry setByteCode _) + } + + def toEntry[A](index : Int) = apply { sigEntry => ScalaSigParsers.entry(index)(sigEntry.scalaSig) } + + def parseEntry[A](parser : EntryParser[A])(index : Int) = (toEntry(index) -~ parser) + + implicit def entryType(code : Int) = key filter (_ == code) + + val index = read(_.index) + val key = read(_.entryType) + + lazy val entry : EntryParser[Any] = symbol | typeEntry | literal | name | attributeInfo | annotInfo | children | get + + val ref = byteCodeEntryParser(nat) + + val termName = 1 -~ utf8 + val typeName = 2 -~ utf8 + + val name = termName | typeName as "name" + + def refTo[A](rule : EntryParser[A]) : EntryParser[A] = ref >>& parseEntry(rule) + + lazy val nameRef = refTo(name) + lazy val symbolRef = refTo(symbol) + lazy val typeRef = refTo(typeEntry) + lazy val constantRef = refTo(literal) + + val symbolInfo = nameRef ~ symbolRef ~ nat ~ (symbolRef?) ~ ref ~ get ^~~~~~^ SymbolInfo + + def symHeader(key: Int): EntryParser[Any] = (key -~ none | (key + 64) -~ nat) + + def symbolEntry(key : Int) = symHeader(key) -~ symbolInfo + + val noSymbol = 3 -^ NoSymbol + val typeSymbol = symbolEntry(4) ^^ TypeSymbol as "typeSymbol" + val aliasSymbol = symbolEntry(5) ^^ AliasSymbol as "alias" + val classSymbol = symbolEntry(6) ~ (ref?) ^~^ ClassSymbol as "class" + val objectSymbol = symbolEntry(7) ^^ ObjectSymbol as "object" + val methodSymbol = symHeader(8) -~ /*(ref?) -~*/ symbolInfo ~ (ref?) ^~^ MethodSymbol as "method" + val extRef = 9 -~ nameRef ~ (symbolRef?) ~ get ^~~^ ExternalSymbol as "extRef" + val extModClassRef = 10 -~ nameRef ~ (symbolRef?) ~ get ^~~^ ExternalSymbol as "extModClassRef" + + lazy val symbol : EntryParser[Symbol] = oneOf( + noSymbol, + typeSymbol, + aliasSymbol, + classSymbol, + objectSymbol, + methodSymbol, + extRef, + extModClassRef) as "symbol" + + val classSymRef = refTo(classSymbol) + val attribTreeRef = ref + val typeLevel = nat + val typeIndex = nat + + lazy val typeEntry : EntryParser[Type] = oneOf( + 11 -^ NoType, + 12 -^ NoPrefixType, + 13 -~ symbolRef ^^ ThisType, + 14 -~ typeRef ~ symbolRef ^~^ SingleType, + 15 -~ constantRef ^^ ConstantType, + 16 -~ typeRef ~ symbolRef ~ (typeRef*) ^~~^ TypeRefType, + 17 -~ typeRef ~ typeRef ^~^ TypeBoundsType, + 18 -~ classSymRef ~ (typeRef*) ^~^ RefinedType, + 19 -~ symbolRef ~ (typeRef*) ^~^ ClassInfoType, + 20 -~ typeRef ~ (symbolRef*) ^~^ MethodType, + 21 -~ typeRef ~ (refTo(typeSymbol)+) ^~^ PolyType, + // TODO: make future safe for past by doing the same transformation as in the + // full unpickler in case we're reading pre-2.9 classfiles + 21 -~ typeRef ^^ NullaryMethodType, + 22 -~ typeRef ~ (symbolRef*) ^~^ MethodType, + 42 -~ typeRef ~ (attribTreeRef*) ^~^ AnnotatedType, + 51 -~ typeRef ~ symbolRef ~ (attribTreeRef*) ^~~^ AnnotatedWithSelfType, + 48 -~ typeRef ~ (symbolRef*) ^~^ ExistentialType) as "type" + + lazy val literal: EntryParser[Any] = oneOf( + 24 -^ (()), + 25 -~ longValue ^^ (_ != 0L), + 26 -~ longValue ^^ (_.toByte), + 27 -~ longValue ^^ (_.toShort), + 28 -~ longValue ^^ (_.toChar), + 29 -~ longValue ^^ (_.toInt), + 30 -~ longValue ^^ (_.toLong), + 31 -~ longValue ^^ (l => java.lang.Float.intBitsToFloat(l.toInt)), + 32 -~ longValue ^^ (java.lang.Double.longBitsToDouble), + 33 -~ nameRef, + 34 -^ null, + 35 -~ typeRef) + + lazy val attributeInfo = 40 -~ symbolRef ~ typeRef ~ (constantRef?) ~ (nameRef ~ constantRef *) ^~~~^ AttributeInfo // sym_Ref info_Ref {constant_Ref} {nameRef constantRef} + lazy val children = 41 -~ (nat*) ^^ Children //sym_Ref {sym_Ref} + lazy val annotInfo = 43 -~ (nat*) ^^ AnnotInfo // attarg_Ref {constant_Ref attarg_Ref} + + lazy val topLevelClass = classSymbol filter isTopLevelClass + lazy val topLevelObject = objectSymbol filter isTopLevel + + def isTopLevel(symbol : Symbol) = symbol.parent match { + case Some(ext : ExternalSymbol) => true + case _ => false + } + def isTopLevelClass (symbol : Symbol) = !symbol.isModule && isTopLevel(symbol) +} + +case class AttributeInfo(symbol : Symbol, typeRef : Type, value : Option[Any], values : Seq[String ~ Any]) // sym_Ref info_Ref {constant_Ref} {nameRef constantRef} +case class Children(symbolRefs : Seq[Int]) //sym_Ref {sym_Ref} + +case class AnnotInfo(refs : Seq[Int]) // attarg_Ref {constant_Ref attarg_Ref} + + /*************************************************** + * | 49 TREE len_Nat 1 EMPTYtree + * | 49 TREE len_Nat 2 PACKAGEtree type_Ref sym_Ref mods_Ref name_Ref {tree_Ref} + * | 49 TREE len_Nat 3 CLASStree type_Ref sym_Ref mods_Ref name_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 4 MODULEtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref + * | 49 TREE len_Nat 5 VALDEFtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 6 DEFDEFtree type_Ref sym_Ref mods_Ref name_Ref numtparams_Nat {tree_Ref} numparamss_Nat {numparams_Nat {tree_Ref}} tree_Ref tree_Ref + * | 49 TREE len_Nat 7 TYPEDEFtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 8 LABELtree type_Ref sym_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 9 IMPORTtree type_Ref sym_Ref tree_Ref {name_Ref name_Ref} + * | 49 TREE len_Nat 11 DOCDEFtree type_Ref sym_Ref string_Ref tree_Ref + * | 49 TREE len_Nat 12 TEMPLATEtree type_Ref sym_Ref numparents_Nat {tree_Ref} tree_Ref {tree_Ref} + * | 49 TREE len_Nat 13 BLOCKtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 14 CASEtree type_Ref tree_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 15 SEQUENCEtree type_Ref {tree_Ref} + * | 49 TREE len_Nat 16 ALTERNATIVEtree type_Ref {tree_Ref} + * | 49 TREE len_Nat 17 STARtree type_Ref {tree_Ref} + * | 49 TREE len_Nat 18 BINDtree type_Ref sym_Ref name_Ref tree_Ref + * | 49 TREE len_Nat 19 UNAPPLYtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 20 ARRAYVALUEtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 21 FUNCTIONtree type_Ref sym_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 22 ASSIGNtree type_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 23 IFtree type_Ref tree_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 24 MATCHtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 25 RETURNtree type_Ref sym_Ref tree_Ref + * | 49 TREE len_Nat 26 TREtree type_Ref tree_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 27 THROWtree type_Ref tree_Ref + * | 49 TREE len_Nat 28 NEWtree type_Ref tree_Ref + * | 49 TREE len_Nat 29 TYPEDtree type_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 30 TYPEAPPLYtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 31 APPLYtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 32 APPLYDYNAMICtree type_Ref sym_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 33 SUPERtree type_Ref sym_Ref tree_Ref name_Ref + * | 49 TREE len_Nat 34 THIStree type_Ref sym_Ref name_Ref + * | 49 TREE len_Nat 35 SELECTtree type_Ref sym_Ref tree_Ref name_Ref + * | 49 TREE len_Nat 36 IDENTtree type_Ref sym_Ref name_Ref + * | 49 TREE len_Nat 37 LITERALtree type_Ref constant_Ref + * | 49 TREE len_Nat 38 TYPEtree type_Ref + * | 49 TREE len_Nat 39 ANNOTATEDtree type_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 40 SINGLETONTYPEtree type_Ref tree_Ref + * | 49 TREE len_Nat 41 SELECTFROMTYPEtree type_Ref tree_Ref name_Ref + * | 49 TREE len_Nat 42 COMPOUNDTYPEtree type_Ref tree_Ref + * | 49 TREE len_Nat 43 APPLIEDTYPEtree type_Ref tree_Ref {tree_Ref} + * | 49 TREE len_Nat 44 TYPEBOUNDStree type_Ref tree_Ref tree_Ref + * | 49 TREE len_Nat 45 EXISTENTIALTYPEtree type_Ref tree_Ref {tree_Ref} + * | 50 MODIFIERS len_Nat flags_Long privateWithin_Ref + * SymbolInfo = name_Ref owner_Ref flags_LongNat [privateWithin_Ref] info_Ref + * NameInfo = + * NumInfo = + * Ref = Nat + * AnnotInfoBody = info_Ref {annotArg_Ref} {name_Ref constAnnotArg_Ref} + * AnnotArg = Tree | Constant + * ConstAnnotArg = Constant | AnnotInfo | AnnotArgArray + * + * len is remaining length after `len`. + */ diff --git a/src/scalap/scala/tools/scalap/scalasig/ScalaSigPrinter.scala b/src/scalap/scala/tools/scalap/scalasig/ScalaSigPrinter.scala new file mode 100644 index 0000000000..01bef65fbe --- /dev/null +++ b/src/scalap/scala/tools/scalap/scalasig/ScalaSigPrinter.scala @@ -0,0 +1,434 @@ +/* ___ ____ ___ __ ___ ___ +** / _// __// _ | / / / _ | / _ \ Scala classfile decoder +** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003-2013, LAMP/EPFL +** /____/\___/_/ |_/____/_/ |_/_/ http://scala-lang.org/ +** +*/ + +package scala.tools.scalap.scalasig + +import scala.language.implicitConversions + +import java.io.{PrintStream, ByteArrayOutputStream} +import java.util.regex.Pattern + +import scala.tools.scalap.rules.~ + +class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) { + import stream._ + + val CONSTRUCTOR_NAME = "" + + case class TypeFlags(printRep: Boolean) + + def printSymbol(symbol: Symbol) {printSymbol(0, symbol)} + + def printSymbolAttributes(s: Symbol, onNewLine: Boolean, indent: => Unit) = s match { + case t: SymbolInfoSymbol => { + for (a <- t.attributes) { + indent; print(toString(a)) + if (onNewLine) print("\n") else print(" ") + } + } + case _ => + } + + def printSymbol(level: Int, symbol: Symbol) { + if (!symbol.isLocal && + !(symbol.isPrivate && !printPrivates)) { + def indent() {for (i <- 1 to level) print(" ")} + + printSymbolAttributes(symbol, true, indent) + symbol match { + case o: ObjectSymbol => + if (!isCaseClassObject(o)) { + indent + if (o.name == "package") { + // print package object + printPackageObject(level, o) + } else { + printObject(level, o) + } + } + case c: ClassSymbol if !refinementClass(c) && !c.isModule => + indent + printClass(level, c) + case m: MethodSymbol => + printMethod(level, m, indent) + case a: AliasSymbol => + indent + printAlias(level, a) + case t: TypeSymbol if !t.isParam && !t.name.matches("_\\$\\d+")=> + indent + printTypeSymbol(level, t) + case s => + } + } + } + + def isCaseClassObject(o: ObjectSymbol): Boolean = { + val TypeRefType(_, classSymbol: ClassSymbol, _) = o.infoType + o.isFinal && (classSymbol.children.find(x => x.isCase && x.isInstanceOf[MethodSymbol]) match { + case Some(_) => true + case None => false + }) + } + + private def underCaseClass(m: MethodSymbol) = m.parent match { + case Some(c: ClassSymbol) => c.isCase + case _ => false + } + + + private def printChildren(level: Int, symbol: Symbol) { + for (child <- symbol.children) printSymbol(level + 1, child) + } + + def printWithIndent(level: Int, s: String) { + def indent() {for (i <- 1 to level) print(" ")} + indent; + print(s) + } + + def printModifiers(symbol: Symbol) { + // print private access modifier + if (symbol.isPrivate) print("private ") + else if (symbol.isProtected) print("protected ") + else symbol match { + case sym: SymbolInfoSymbol => sym.symbolInfo.privateWithin match { + case Some(t: Symbol) => print("private[" + t.name +"] ") + case _ => + } + case _ => + } + + if (symbol.isSealed) print("sealed ") + if (symbol.isImplicit) print("implicit ") + if (symbol.isFinal && !symbol.isInstanceOf[ObjectSymbol]) print("final ") + if (symbol.isOverride) print("override ") + if (symbol.isAbstract) symbol match { + case c@(_: ClassSymbol | _: ObjectSymbol) if !c.isTrait => print("abstract ") + case _ => () + } + if (symbol.isCase && !symbol.isMethod) print("case ") + } + + private def refinementClass(c: ClassSymbol) = c.name == "" + + def printClass(level: Int, c: ClassSymbol) { + if (c.name == "" /*scala.tools.nsc.symtab.StdNames.LOCAL_CHILD.toString()*/ ) { + print("\n") + } else { + printModifiers(c) + val defaultConstructor = if (c.isCase) getPrinterByConstructor(c) else "" + if (c.isTrait) print("trait ") else print("class ") + print(processName(c.name)) + val it = c.infoType + val classType = it match { + case PolyType(typeRef, symbols) => PolyTypeWithCons(typeRef, symbols, defaultConstructor) + case ClassInfoType(a, b) if c.isCase => ClassInfoTypeWithCons(a, b, defaultConstructor) + case _ => it + } + printType(classType) + print(" {") + //Print class selftype + c.selfType match { + case Some(t: Type) => print("\n"); print(" this : " + toString(t) + " =>") + case None => + } + print("\n") + printChildren(level, c) + printWithIndent(level, "}\n") + } + } + + def getPrinterByConstructor(c: ClassSymbol) = { + c.children.find { + case m: MethodSymbol if m.name == CONSTRUCTOR_NAME => true + case _ => false + } match { + case Some(m: MethodSymbol) => + val baos = new ByteArrayOutputStream + val stream = new PrintStream(baos) + val printer = new ScalaSigPrinter(stream, printPrivates) + printer.printMethodType(m.infoType, false)(()) + baos.toString + case _ => + "" + } + } + + def printPackageObject(level: Int, o: ObjectSymbol) { + printModifiers(o) + print("package ") + print("object ") + val poName = o.symbolInfo.owner.name + print(processName(poName)) + val TypeRefType(_, classSymbol: ClassSymbol, _) = o.infoType + printType(classSymbol) + print(" {\n") + printChildren(level, classSymbol) + printWithIndent(level, "}\n") + + } + + def printObject(level: Int, o: ObjectSymbol) { + printModifiers(o) + print("object ") + print(processName(o.name)) + val TypeRefType(_, classSymbol: ClassSymbol, _) = o.infoType + printType(classSymbol) + print(" {\n") + printChildren(level, classSymbol) + printWithIndent(level, "}\n") + } + + def printMethodType(t: Type, printResult: Boolean)(cont: => Unit): Unit = { + + def _pmt(mt: MethodType) = { + + val paramEntries = mt.paramSymbols.map({ + case ms: MethodSymbol => ms.name + " : " + toString(ms.infoType)(TypeFlags(true)) + case _ => "^___^" + }) + val implicitWord = mt.paramSymbols.headOption match { + case Some(p) if p.isImplicit => "implicit " + case _ => "" + } + + // Print parameter clauses + print(paramEntries.mkString("(" + implicitWord, ", ", ")")) + + // Print result type + mt.resultType match { + case mt: MethodType => printMethodType(mt, printResult)({}) + case x => if (printResult) { + print(" : "); + printType(x) + } + } + } + + t match { + case NullaryMethodType(resType) => if (printResult) { print(" : "); printType(resType) } + case mt@MethodType(resType, paramSymbols) => _pmt(mt) + case pt@PolyType(mt, typeParams) => { + print(typeParamString(typeParams)) + printMethodType(mt, printResult)({}) + } + //todo consider another method types + case x => print(" : "); printType(x) + } + + // Print rest of the symbol output + cont + } + + def printMethod(level: Int, m: MethodSymbol, indent: () => Unit) { + def cont() = print(" = { /* compiled code */ }") + + val n = m.name + if (underCaseClass(m) && n == CONSTRUCTOR_NAME) return + if (n.matches(".+\\$default\\$\\d+")) return // skip default function parameters + if (n.startsWith("super$")) return // do not print auxiliary qualified super accessors + if (m.isAccessor && n.endsWith("_$eq")) return + indent() + printModifiers(m) + if (m.isAccessor) { + val indexOfSetter = m.parent.get.children.indexWhere(x => x.isInstanceOf[MethodSymbol] && + x.asInstanceOf[MethodSymbol].name == n + "_$eq") + print(if (indexOfSetter > 0) "var " else "val ") + } else { + print("def ") + } + n match { + case CONSTRUCTOR_NAME => + print("this") + printMethodType(m.infoType, false)(cont) + case name => + val nn = processName(name) + print(nn) + printMethodType(m.infoType, true)( + {if (!m.isDeferred) print(" = { /* compiled code */ }" /* Print body only for non-abstract methods */ )} + ) + } + print("\n") + } + + def printAlias(level: Int, a: AliasSymbol) { + print("type ") + print(processName(a.name)) + printType(a.infoType, " = ") + print("\n") + printChildren(level, a) + } + + def printTypeSymbol(level: Int, t: TypeSymbol) { + print("type ") + print(processName(t.name)) + printType(t.infoType) + print("\n") + } + + def toString(attrib: AttributeInfo): String = { + val buffer = new StringBuffer + buffer.append(toString(attrib.typeRef, "@")) + if (attrib.value.isDefined) { + buffer.append("(") + val value = attrib.value.get + val stringVal = value.isInstanceOf[String] + if (stringVal) buffer.append("\"") + val stringValue = valueToString(value) + val isMultiline = stringVal && (stringValue.contains("\n") + || stringValue.contains("\r")) + if (isMultiline) buffer.append("\"\"") + buffer.append(valueToString(value)) + if (isMultiline) buffer.append("\"\"") + if (stringVal) buffer.append("\"") + buffer.append(")") + } + if (!attrib.values.isEmpty) { + buffer.append(" {") + for (name ~ value <- attrib.values) { + buffer.append(" val ") + buffer.append(processName(name)) + buffer.append(" = ") + buffer.append(valueToString(value)) + } + buffer.append(valueToString(attrib.value)) + buffer.append(" }") + } + buffer.toString + } + + def valueToString(value: Any): String = value match { + case t: Type => toString(t) + // TODO string, char, float, etc. + case _ => value.toString + } + + implicit object _tf extends TypeFlags(false) + + def printType(sym: SymbolInfoSymbol)(implicit flags: TypeFlags): Unit = printType(sym.infoType)(flags) + + def printType(t: Type)(implicit flags: TypeFlags): Unit = print(toString(t)(flags)) + + def printType(t: Type, sep: String)(implicit flags: TypeFlags): Unit = print(toString(t, sep)(flags)) + + def toString(t: Type)(implicit flags: TypeFlags): String = toString(t, "")(flags) + + def toString(t: Type, sep: String)(implicit flags: TypeFlags): String = { + // print type itself + t match { + case ThisType(symbol) => sep + processName(symbol.path) + ".type" + case SingleType(typeRef, symbol) => sep + processName(symbol.path) + ".type" + case ConstantType(constant) => sep + (constant match { + case null => "scala.Null" + case _: Unit => "scala.Unit" + case _: Boolean => "scala.Boolean" + case _: Byte => "scala.Byte" + case _: Char => "scala.Char" + case _: Short => "scala.Short" + case _: Int => "scala.Int" + case _: Long => "scala.Long" + case _: Float => "scala.Float" + case _: Double => "scala.Double" + case _: String => "java.lang.String" + case c: Class[_] => "java.lang.Class[" + c.getComponentType.getCanonicalName.replace("$", ".") + "]" + }) + case TypeRefType(prefix, symbol, typeArgs) => sep + (symbol.path match { + case "scala." => flags match { + case TypeFlags(true) => toString(typeArgs.head) + "*" + case _ => "scala.Seq" + typeArgString(typeArgs) + } + case "scala." => "=> " + toString(typeArgs.head) + case _ => { + val path = cutSubstring(symbol.path)(".package") //remove package object reference + trimStart(processName(path) + typeArgString(typeArgs), ".") + } + }) + case TypeBoundsType(lower, upper) => { + val lb = toString(lower) + val ub = toString(upper) + val lbs = if (!lb.equals("scala.Nothing")) " >: " + lb else "" + val ubs = if (!ub.equals("scala.Any")) " <: " + ub else "" + lbs + ubs + } + case RefinedType(classSym, typeRefs) => sep + typeRefs.map(toString).mkString("", " with ", "") + case ClassInfoType(symbol, typeRefs) => sep + typeRefs.map(toString).mkString(" extends ", " with ", "") + case ClassInfoTypeWithCons(symbol, typeRefs, cons) => sep + typeRefs.map(toString). + mkString(cons + " extends ", " with ", "") + + case MethodType(resultType, _) => toString(resultType, sep) + case NullaryMethodType(resultType) => toString(resultType, sep) + + case PolyType(typeRef, symbols) => typeParamString(symbols) + toString(typeRef, sep) + case PolyTypeWithCons(typeRef, symbols, cons) => typeParamString(symbols) + processName(cons) + toString(typeRef, sep) + case AnnotatedType(typeRef, attribTreeRefs) => { + toString(typeRef, sep) + } + case AnnotatedWithSelfType(typeRef, symbol, attribTreeRefs) => toString(typeRef, sep) + case ExistentialType(typeRef, symbols) => { + val refs = symbols.map(toString _).filter(!_.startsWith("_")).map("type " + _) + toString(typeRef, sep) + (if (refs.size > 0) refs.mkString(" forSome {", "; ", "}") else "") + } + case _ => sep + t.toString + } + } + + def getVariance(t: TypeSymbol) = if (t.isCovariant) "+" else if (t.isContravariant) "-" else "" + + def toString(symbol: Symbol): String = symbol match { + case symbol: TypeSymbol => { + val attrs = (for (a <- symbol.attributes) yield toString(a)).mkString(" ") + val atrs = if (attrs.length > 0) attrs.trim + " " else "" + atrs + getVariance(symbol) + processName(symbol.name) + toString(symbol.infoType) + } + case s => symbol.toString + } + + def typeArgString(typeArgs: Seq[Type]): String = + if (typeArgs.isEmpty) "" + else typeArgs.map(toString).map(trimStart(_, "=> ")).mkString("[", ", ", "]") + + def typeParamString(params: Seq[Symbol]): String = + if (params.isEmpty) "" + else params.map(toString).mkString("[", ", ", "]") + + val _syms = Map("\\$bar" -> "|", "\\$tilde" -> "~", + "\\$bang" -> "!", "\\$up" -> "^", "\\$plus" -> "+", + "\\$minus" -> "-", "\\$eq" -> "=", "\\$less" -> "<", + "\\$times" -> "*", "\\$div" -> "/", "\\$bslash" -> "\\\\", + "\\$greater" -> ">", "\\$qmark" -> "?", "\\$percent" -> "%", + "\\$amp" -> "&", "\\$colon" -> ":", "\\$u2192" -> "→", + "\\$hash" -> "#") + val pattern = Pattern.compile(_syms.keys.foldLeft("")((x, y) => if (x == "") y else x + "|" + y)) + val placeholderPattern = "_\\$(\\d)+" + + private def stripPrivatePrefix(name: String) = { + val i = name.lastIndexOf("$$") + if (i > 0) name.substring(i + 2) else name + } + + private def processName(name: String) = { + val stripped = stripPrivatePrefix(name) + val m = pattern.matcher(stripped) + var temp = stripped + while (m.find) { + val key = m.group + val re = "\\" + key + temp = temp.replaceAll(re, _syms(re)) + } + val result = temp.replaceAll(placeholderPattern, "_") + scala.reflect.NameTransformer.decode(result) + } + + private def trimStart(s: String, prefix: String) = + if (s != null && s.startsWith(prefix)) s.substring(prefix.length) else s + + private def decapitalize(s: String) = + java.beans.Introspector.decapitalize(s) + + private def cutSubstring(dom: String)(s: String) = + if (dom != null && s != null) dom.replace(s, "") else dom +} diff --git a/src/scalap/scala/tools/scalap/scalasig/SourceFileAttributeParser.scala b/src/scalap/scala/tools/scalap/scalasig/SourceFileAttributeParser.scala new file mode 100644 index 0000000000..88d3d3b8b0 --- /dev/null +++ b/src/scalap/scala/tools/scalap/scalasig/SourceFileAttributeParser.scala @@ -0,0 +1,24 @@ +package scala.tools.scalap.scalasig + +/** + * @author ilyas + */ + +object SourceFileAttributeParser extends ByteCodeReader { + val sourceFile = u2 ^^ SourceFileInfo + + def parse(byteCode: ByteCode) = expect(sourceFile)(byteCode) +} + +/** + * + * SourceFile_attribute { + u2 attribute_name_index; + u4 attribute_length; + u2 sourcefile_index; + } + * + * Contains only file index in ConstantPool, first two fields are already treated + * by {@link scalax.rules.scalasig.ClassFile.attribute#attribute} + */ +case class SourceFileInfo(sourceFileIndex: Int) diff --git a/src/scalap/scala/tools/scalap/scalasig/Symbol.scala b/src/scalap/scala/tools/scalap/scalasig/Symbol.scala new file mode 100644 index 0000000000..dd766a6331 --- /dev/null +++ b/src/scalap/scala/tools/scalap/scalasig/Symbol.scala @@ -0,0 +1,70 @@ +package scala.tools.scalap.scalasig + +import ScalaSigEntryParsers._ + +trait Symbol extends Flags { + def name : String + def parent : Option[Symbol] + def children : Seq[Symbol] + + def path : String = parent.map(_.path + ".").getOrElse("") + name +} + +case object NoSymbol extends Symbol { + def name = "" + def parent = None + def hasFlag(flag : Long) = false + def children = Nil +} + +abstract class ScalaSigSymbol extends Symbol { + def applyRule[A](rule : EntryParser[A]) : A = expect(rule)(entry) + def applyScalaSigRule[A](rule : ScalaSigParsers.Parser[A]) = ScalaSigParsers.expect(rule)(entry.scalaSig) + + def entry : ScalaSig#Entry + def index = entry.index + + lazy val children : Seq[Symbol] = applyScalaSigRule(ScalaSigParsers.symbols) filter (_.parent == Some(this)) + lazy val attributes : Seq[AttributeInfo] = applyScalaSigRule(ScalaSigParsers.attributes) filter (_.symbol == this) +} + +case class ExternalSymbol(name : String, parent : Option[Symbol], entry : ScalaSig#Entry) extends ScalaSigSymbol { + override def toString = path + def hasFlag(flag : Long) = false +} + +case class SymbolInfo(name : String, owner : Symbol, flags : Int, privateWithin : Option[AnyRef], info : Int, entry : ScalaSig#Entry) { + def symbolString(any : AnyRef) = any match { + case sym : SymbolInfoSymbol => sym.index.toString + case other => other.toString + } + + override def toString = name + ", owner=" + symbolString(owner) + ", flags=" + flags.toHexString + ", info=" + info + (privateWithin match { + case Some(any) => ", privateWithin=" + symbolString(any) + case None => " " + }) +} + +abstract class SymbolInfoSymbol extends ScalaSigSymbol { + def symbolInfo : SymbolInfo + + def entry = symbolInfo.entry + def name = symbolInfo.name + def parent = Some(symbolInfo.owner) + def hasFlag(flag : Long) = (symbolInfo.flags & flag) != 0L + + lazy val infoType = applyRule(parseEntry(typeEntry)(symbolInfo.info)) +} + +case class TypeSymbol(symbolInfo : SymbolInfo) extends SymbolInfoSymbol{ + override def path = name +} + +case class AliasSymbol(symbolInfo : SymbolInfo) extends SymbolInfoSymbol{ + override def path = name +} +case class ClassSymbol(symbolInfo : SymbolInfo, thisTypeRef : Option[Int]) extends SymbolInfoSymbol { + lazy val selfType = thisTypeRef.map{(x: Int) => applyRule(parseEntry(typeEntry)(x))} +} +case class ObjectSymbol(symbolInfo : SymbolInfo) extends SymbolInfoSymbol +case class MethodSymbol(symbolInfo : SymbolInfo, aliasRef : Option[Int]) extends SymbolInfoSymbol diff --git a/src/scalap/scala/tools/scalap/scalasig/Type.scala b/src/scalap/scala/tools/scalap/scalasig/Type.scala new file mode 100644 index 0000000000..cad4ea4446 --- /dev/null +++ b/src/scalap/scala/tools/scalap/scalasig/Type.scala @@ -0,0 +1,22 @@ +package scala.tools.scalap.scalasig + +abstract class Type + +case object NoType extends Type +case object NoPrefixType extends Type + +case class ThisType(symbol : Symbol) extends Type +case class SingleType(typeRef : Type, symbol : Symbol) extends Type +case class ConstantType(constant : Any) extends Type +case class TypeRefType(prefix : Type, symbol : Symbol, typeArgs : Seq[Type]) extends Type +case class TypeBoundsType(lower : Type, upper : Type) extends Type +case class RefinedType(classSym : Symbol, typeRefs : List[Type]) extends Type +case class ClassInfoType(symbol : Symbol, typeRefs : Seq[Type]) extends Type +case class ClassInfoTypeWithCons(symbol : Symbol, typeRefs : Seq[Type], cons: String) extends Type +case class MethodType(resultType : Type, paramSymbols : Seq[Symbol]) extends Type +case class NullaryMethodType(resultType : Type) extends Type +case class PolyType(typeRef : Type, symbols : Seq[TypeSymbol]) extends Type +case class PolyTypeWithCons(typeRef : Type, symbols : Seq[TypeSymbol], cons: String) extends Type +case class AnnotatedType(typeRef : Type, attribTreeRefs : List[Int]) extends Type +case class AnnotatedWithSelfType(typeRef : Type, symbol : Symbol, attribTreeRefs : List[Int]) extends Type +case class ExistentialType(typeRef : Type, symbols : Seq[Symbol]) extends Type diff --git a/src/scalap/scala/tools/scalap/scalax/rules/Memoisable.scala b/src/scalap/scala/tools/scalap/scalax/rules/Memoisable.scala deleted file mode 100644 index b4ce8cab23..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/rules/Memoisable.scala +++ /dev/null @@ -1,61 +0,0 @@ -// ----------------------------------------------------------------------------- -// -// Scalax - The Scala Community Library -// Copyright (c) 2005-8 The Scalax Project. All rights reserved. -// -// The primary distribution site is http://scalax.scalaforge.org/ -// -// This software is released under the terms of the Revised BSD License. -// There is NO WARRANTY. See the file LICENSE for the full text. -// -// ----------------------------------------------------------------------------- - -package scala.tools.scalap -package scalax -package rules - -import scala.collection.mutable - -trait MemoisableRules extends Rules { - def memo[In <: Memoisable, Out, A, X](key : AnyRef)(toRule : => In => Result[Out, A, X]) = { - lazy val rule = toRule - from[In] { in => in.memo(key, rule(in)) } - } - - override def ruleWithName[In, Out, A, X](name : String, f : In => rules.Result[Out, A, X]) = super.ruleWithName(name, (in : In) => in match { - case s : Memoisable => s.memo(name, f(in)) - case _ => f(in) - }) -} - -trait Memoisable { - def memo[A](key : AnyRef, a : => A) : A -} - - -object DefaultMemoisable { - var debug = false -} - -trait DefaultMemoisable extends Memoisable { - protected val map = new mutable.HashMap[AnyRef, Any] - - def memo[A](key : AnyRef, a : => A) = { - map.getOrElseUpdate(key, compute(key, a)).asInstanceOf[A] - } - - protected def compute[A](key : AnyRef, a : => A): Any = a match { - case success : Success[_, _] => onSuccess(key, success); success - case other => - if(DefaultMemoisable.debug) println(key + " -> " + other) - other - } - - protected def onSuccess[S, T](key : AnyRef, result : Success[S, T]) { - val Success(out, t) = result - if(DefaultMemoisable.debug) println(key + " -> " + t + " (" + out + ")") - } -} - - - diff --git a/src/scalap/scala/tools/scalap/scalax/rules/Result.scala b/src/scalap/scala/tools/scalap/scalax/rules/Result.scala deleted file mode 100644 index 17ad4bd053..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/rules/Result.scala +++ /dev/null @@ -1,72 +0,0 @@ -// ----------------------------------------------------------------------------- -// -// Scalax - The Scala Community Library -// Copyright (c) 2005-8 The Scalax Project. All rights reserved. -// -// The primary distribution site is http://scalax.scalaforge.org/ -// -// This software is released under the terms of the Revised BSD License. -// There is NO WARRANTY. See the file LICENSE for the full text. -// -// ----------------------------------------------------------------------------- - -package scala.tools.scalap -package scalax -package rules; - -/** Represents the combined value of two rules applied in sequence. - * - * @see the Scala parser combinator - */ -case class ~[+A, +B](_1 : A, _2 : B) { - override def toString = "(" + _1 + " ~ " + _2 + ")" -} - - -sealed abstract class Result[+Out, +A, +X] { - def out : Out - def value : A - def error : X - - implicit def toOption : Option[A] - - def map[B](f : A => B) : Result[Out, B, X] - def mapOut[Out2](f : Out => Out2) : Result[Out2, A, X] - def map[Out2, B](f : (Out, A) => (Out2, B)) : Result[Out2, B, X] - def flatMap[Out2, B](f : (Out, A) => Result[Out2, B, Nothing]) : Result[Out2, B, X] - def orElse[Out2 >: Out, B >: A](other : => Result[Out2, B, Nothing]) : Result[Out2, B, X] -} - -case class Success[+Out, +A](out : Out, value : A) extends Result[Out, A, Nothing] { - def error = throw new ScalaSigParserError("No error") - - def toOption = Some(value) - - def map[B](f : A => B) : Result[Out, B, Nothing] = Success(out, f(value)) - def mapOut[Out2](f : Out => Out2) : Result[Out2, A, Nothing] = Success(f(out), value) - def map[Out2, B](f : (Out, A) => (Out2, B)) : Success[Out2, B] = f(out, value) match { case (out2, b) => Success(out2, b) } - def flatMap[Out2, B](f : (Out, A) => Result[Out2, B, Nothing]) : Result[Out2, B, Nothing]= f(out, value) - def orElse[Out2 >: Out, B >: A](other : => Result[Out2, B, Nothing]) : Result[Out2, B, Nothing] = this -} - -sealed abstract class NoSuccess[+X] extends Result[Nothing, Nothing, X] { - def out = throw new ScalaSigParserError("No output") - def value = throw new ScalaSigParserError("No value") - - def toOption = None - - def map[B](f : Nothing => B) = this - def mapOut[Out2](f : Nothing => Out2) = this - def map[Out2, B](f : (Nothing, Nothing) => (Out2, B)) = this - def flatMap[Out2, B](f : (Nothing, Nothing) => Result[Out2, B, Nothing]) = this - def orElse[Out2, B](other : => Result[Out2, B, Nothing]) = other -} - -case object Failure extends NoSuccess[Nothing] { - def error = throw new ScalaSigParserError("No error") -} - -case class ScalaSigParserError(msg: String) extends RuntimeException(msg) - -case class Error[+X](error : X) extends NoSuccess[X] { -} diff --git a/src/scalap/scala/tools/scalap/scalax/rules/Rule.scala b/src/scalap/scala/tools/scalap/scalax/rules/Rule.scala deleted file mode 100644 index 489a05ecd0..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/rules/Rule.scala +++ /dev/null @@ -1,177 +0,0 @@ -// ----------------------------------------------------------------------------- -// -// Scalax - The Scala Community Library -// Copyright (c) 2005-8 The Scalax Project. All rights reserved. -// -// The primary distribution site is http://scalax.scalaforge.org/ -// -// This software is released under the terms of the Revised BSD License. -// There is NO WARRANTY. See the file LICENSE for the full text. -// -// ----------------------------------------------------------------------------- - -package scala.tools.scalap -package scalax -package rules - -/** A Rule is a function from some input to a Result. The result may be: - *
    - *
  • Success, with a value of some type and an output that may serve as the input to subsequent rules.
  • - *
  • Failure. A failure may result in some alternative rule being applied.
  • - *
  • Error. No further rules should be attempted.
  • - *
- * - * @author Andrew Foggin - * - * Inspired by the Scala parser combinator. - */ -trait Rule[-In, +Out, +A, +X] extends (In => Result[Out, A, X]) { - val factory : Rules - import factory._ - - def as(name : String) = ruleWithName(name, this) - - def flatMap[Out2, B, X2 >: X](fa2ruleb : A => Out => Result[Out2, B, X2]) = mapResult { - case Success(out, a) => fa2ruleb(a)(out) - case Failure => Failure - case err @ Error(_) => err - } - - def map[B](fa2b : A => B) = flatMap { a => out => Success(out, fa2b(a)) } - - def filter(f : A => Boolean) = flatMap { a => out => if(f(a)) Success(out, a) else Failure } - - def mapResult[Out2, B, Y](f : Result[Out, A, X] => Result[Out2, B, Y]) = rule { - in : In => f(apply(in)) - } - - def orElse[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other : => Rule[In2, Out2, A2, X2]) : Rule[In2, Out2, A2, X2] = new Choice[In2, Out2, A2, X2] { - val factory = Rule.this.factory - lazy val choices = Rule.this :: other :: Nil - } - - def orError[In2 <: In] = this orElse error[Any] - - def |[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other : => Rule[In2, Out2, A2, X2]) = orElse(other) - - def ^^[B](fa2b : A => B) = map(fa2b) - - def ^^?[B](pf : PartialFunction[A, B]) = filter (pf.isDefinedAt(_)) ^^ pf - - def ??(pf : PartialFunction[A, Any]) = filter (pf.isDefinedAt(_)) - - def -^[B](b : B) = map { any => b } - - /** Maps an Error */ - def !^[Y](fx2y : X => Y) = mapResult { - case s @ Success(_, _) => s - case Failure => Failure - case Error(x) => Error(fx2y(x)) - } - - def >>[Out2, B, X2 >: X](fa2ruleb : A => Out => Result[Out2, B, X2]) = flatMap(fa2ruleb) - - def >->[Out2, B, X2 >: X](fa2resultb : A => Result[Out2, B, X2]) = flatMap { a => any => fa2resultb(a) } - - def >>?[Out2, B, X2 >: X](pf : PartialFunction[A, Rule[Out, Out2, B, X2]]) = filter(pf isDefinedAt _) flatMap pf - - def >>&[B, X2 >: X](fa2ruleb : A => Out => Result[Any, B, X2]) = flatMap { a => out => fa2ruleb(a)(out) mapOut { any => out } } - - def ~[Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next) yield new ~(a, b) - - def ~-[Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next) yield a - - def -~[Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next) yield b - - def ~++[Out2, B >: A, X2 >: X](next : => Rule[Out, Out2, Seq[B], X2]) = for (a <- this; b <- next) yield a :: b.toList - - /** Apply the result of this rule to the function returned by the next rule */ - def ~>[Out2, B, X2 >: X](next : => Rule[Out, Out2, A => B, X2]) = for (a <- this; fa2b <- next) yield fa2b(a) - - /** Apply the result of this rule to the function returned by the previous rule */ - def <~:[InPrev, B, X2 >: X](prev : => Rule[InPrev, In, A => B, X2]) = for (fa2b <- prev; a <- this) yield fa2b(a) - - def ~![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next orError) yield new ~(a, b) - - def ~-![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next orError) yield a - - def -~![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next orError) yield b - - def -[In2 <: In](exclude : => Rule[In2, Any, Any, Any]) = !exclude -~ this - - /** ^~^(f) is equivalent to ^^ { case b1 ~ b2 => f(b1, b2) } - */ - def ^~^[B1, B2, B >: A <% B1 ~ B2, C](f : (B1, B2) => C) = map { a => - (a : B1 ~ B2) match { case b1 ~ b2 => f(b1, b2) } - } - - /** ^~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 => f(b1, b2, b3) } - */ - def ^~~^[B1, B2, B3, B >: A <% B1 ~ B2 ~ B3, C](f : (B1, B2, B3) => C) = map { a => - (a : B1 ~ B2 ~ B3) match { case b1 ~ b2 ~ b3 => f(b1, b2, b3) } - } - - /** ^~~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 ~ b4 => f(b1, b2, b3, b4) } - */ - def ^~~~^[B1, B2, B3, B4, B >: A <% B1 ~ B2 ~ B3 ~ B4, C](f : (B1, B2, B3, B4) => C) = map { a => - (a : B1 ~ B2 ~ B3 ~ B4) match { case b1 ~ b2 ~ b3 ~ b4 => f(b1, b2, b3, b4) } - } - - /** ^~~~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 ~ b4 ~ b5 => f(b1, b2, b3, b4, b5) } - */ - def ^~~~~^[B1, B2, B3, B4, B5, B >: A <% B1 ~ B2 ~ B3 ~ B4 ~ B5, C](f : (B1, B2, B3, B4, B5) => C) = map { a => - (a : B1 ~ B2 ~ B3 ~ B4 ~ B5) match { case b1 ~ b2 ~ b3 ~ b4 ~ b5 => f(b1, b2, b3, b4, b5) } - } - - /** ^~~~~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 => f(b1, b2, b3, b4, b5, b6) } - */ - def ^~~~~~^[B1, B2, B3, B4, B5, B6, B >: A <% B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6, C](f : (B1, B2, B3, B4, B5, B6) => C) = map { a => - (a : B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6) match { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 => f(b1, b2, b3, b4, b5, b6) } - } - - /** ^~~~~~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 => f(b1, b2, b3, b4, b5, b6) } - */ - def ^~~~~~~^[B1, B2, B3, B4, B5, B6, B7, B >: A <% B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6 ~ B7, C](f : (B1, B2, B3, B4, B5, B6, B7) => C) = map { a => - (a : B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6 ~ B7) match { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 ~b7 => f(b1, b2, b3, b4, b5, b6, b7) } - } - - /** >~>(f) is equivalent to >> { case b1 ~ b2 => f(b1, b2) } - */ - def >~>[Out2, B1, B2, B >: A <% B1 ~ B2, C, X2 >: X](f : (B1, B2) => Out => Result[Out2, C, X2]) = flatMap { a => - (a : B1 ~ B2) match { case b1 ~ b2 => f(b1, b2) } - } - - /** ^-^(f) is equivalent to ^^ { b2 => b1 => f(b1, b2) } - */ - def ^-^ [B1, B2 >: A, C](f : (B1, B2) => C) = map { b2 : B2 => b1 : B1 => f(b1, b2) } - - /** ^~>~^(f) is equivalent to ^^ { case b2 ~ b3 => b1 => f(b1, b2, b3) } - */ - def ^~>~^ [B1, B2, B3, B >: A <% B2 ~ B3, C](f : (B1, B2, B3) => C) = map { a => - (a : B2 ~ B3) match { case b2 ~ b3 => b1 : B1 => f(b1, b2, b3) } - } -} - - -trait Choice[-In, +Out, +A, +X] extends Rule[In, Out, A, X] { - def choices : List[Rule[In, Out, A, X]] - - def apply(in : In) = { - def oneOf(list : List[Rule[In, Out, A, X]]) : Result[Out, A, X] = list match { - case Nil => Failure - case first :: rest => first(in) match { - case Failure => oneOf(rest) - case result => result - } - } - oneOf(choices) - } - - override def orElse[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other : => Rule[In2, Out2, A2, X2]) : Rule[In2, Out2, A2, X2] = new Choice[In2, Out2, A2, X2] { - val factory = Choice.this.factory - lazy val choices = Choice.this.choices ::: other :: Nil - } -} - - - diff --git a/src/scalap/scala/tools/scalap/scalax/rules/Rules.scala b/src/scalap/scala/tools/scalap/scalax/rules/Rules.scala deleted file mode 100644 index 70926208b3..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/rules/Rules.scala +++ /dev/null @@ -1,146 +0,0 @@ -// ----------------------------------------------------------------------------- -// -// Scalax - The Scala Community Library -// Copyright (c) 2005-8 The Scalax Project. All rights reserved. -// -// The primary distribution site is http://scalax.scalaforge.org/ -// -// This software is released under the terms of the Revised BSD License. -// There is NO WARRANTY. See the file LICENSE for the full text. -// -// ----------------------------------------------------------------------------- - -package scala.tools.scalap -package scalax -package rules - -trait Name { - def name : String - override def toString = name -} - -/** A factory for rules. - * - * @author Andrew Foggin - * - * Inspired by the Scala parser combinator. - */ -trait Rules { - implicit def rule[In, Out, A, X](f : In => Result[Out, A, X]) : Rule[In, Out, A, X] = new DefaultRule(f) - - implicit def inRule[In, Out, A, X](rule : Rule[In, Out, A, X]) : InRule[In, Out, A, X] = new InRule(rule) - implicit def seqRule[In, A, X](rule : Rule[In, In, A, X]) : SeqRule[In, A, X] = new SeqRule(rule) - - def from[In] = new { - def apply[Out, A, X](f : In => Result[Out, A, X]) = rule(f) - } - - def state[s] = new StateRules { - type S = s - val factory = Rules.this - } - - def success[Out, A](out : Out, a : A) = rule { in : Any => Success(out, a) } - - def failure = rule { in : Any => Failure } - - def error[In] = rule { in : In => Error(in) } - def error[X](err : X) = rule { in : Any => Error(err) } - - def oneOf[In, Out, A, X](rules : Rule[In, Out, A, X] *) : Rule[In, Out, A, X] = new Choice[In, Out, A, X] { - val factory = Rules.this - val choices = rules.toList - } - - def ruleWithName[In, Out, A, X](_name : String, f : In => Result[Out, A, X]) : Rule[In, Out, A, X] with Name = - new DefaultRule(f) with Name { - val name = _name - } - - class DefaultRule[In, Out, A, X](f : In => Result[Out, A, X]) extends Rule[In, Out, A, X] { - val factory = Rules.this - def apply(in : In) = f(in) - } - - /** Converts a rule into a function that throws an Exception on failure. */ - def expect[In, Out, A, Any](rule : Rule[In, Out, A, Any]) : In => A = (in) => rule(in) match { - case Success(_, a) => a - case Failure => throw new ScalaSigParserError("Unexpected failure") - case Error(x) => throw new ScalaSigParserError("Unexpected error: " + x) - } -} - -/** A factory for rules that apply to a particular context. - * - * @requires S the context to which rules apply. - * - * @author Andrew Foggin - * - * Inspired by the Scala parser combinator. - */ -trait StateRules { - type S - type Rule[+A, +X] = rules.Rule[S, S, A, X] - - val factory : Rules - import factory._ - - def apply[A, X](f : S => Result[S, A, X]) = rule(f) - - def unit[A](a : => A) = apply { s => Success(s, a) } - def read[A](f : S => A) = apply { s => Success(s, f(s)) } - - def get = apply { s => Success(s, s) } - def set(s : => S) = apply { oldS => Success(s, oldS) } - - def update(f : S => S) = apply { s => Success(s, f(s)) } - - def nil = unit(Nil) - def none = unit(None) - - /** Create a rule that identities if f(in) is true. */ - def cond(f : S => Boolean) = get filter f - - /** Create a rule that succeeds if all of the given rules succeed. - @param rules the rules to apply in sequence. - */ - def allOf[A, X](rules : Seq[Rule[A, X]]) = { - def rep(in : S, rules : List[Rule[A, X]], results : List[A]) : Result[S, List[A], X] = { - rules match { - case Nil => Success(in, results.reverse) - case rule::tl => rule(in) match { - case Failure => Failure - case Error(x) => Error(x) - case Success(out, v) => rep(out, tl, v::results) - } - } - } - in : S => rep(in, rules.toList, Nil) - } - - - /** Create a rule that succeeds with a list of all the provided rules that succeed. - @param rules the rules to apply in sequence. - */ - def anyOf[A, X](rules : Seq[Rule[A, X]]) = allOf(rules.map(_ ?)) ^^ { opts => opts.flatMap(x => x) } - - /** Repeatedly apply a rule from initial value until finished condition is met. */ - def repeatUntil[T, X](rule : Rule[T => T, X])(finished : T => Boolean)(initial : T) = apply { - // more compact using HoF but written this way so it's tail-recursive - def rep(in : S, t : T) : Result[S, T, X] = { - if (finished(t)) Success(in, t) - else rule(in) match { - case Success(out, f) => rep(out, f(t)) // SI-5189 f.asInstanceOf[T => T] - case Failure => Failure - case Error(x) => Error(x) - } - } - in => rep(in, initial) - } - - -} - -trait RulesWithState extends Rules with StateRules { - val factory = this -} diff --git a/src/scalap/scala/tools/scalap/scalax/rules/SeqRule.scala b/src/scalap/scala/tools/scalap/scalax/rules/SeqRule.scala deleted file mode 100644 index 51a789e041..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/rules/SeqRule.scala +++ /dev/null @@ -1,101 +0,0 @@ -// ----------------------------------------------------------------------------- -// -// Scalax - The Scala Community Library -// Copyright (c) 2005-8 The Scalax Project. All rights reserved. -// -// The primary distribution site is http://scalax.scalaforge.org/ -// -// This software is released under the terms of the Revised BSD License. -// There is NO WARRANTY. See the file LICENSE for the full text. -// -// ----------------------------------------------------------------------------- - -package scala.tools.scalap -package scalax -package rules - -/** - * A workaround for the difficulties of dealing with - * a contravariant 'In' parameter type... - */ -class InRule[In, +Out, +A, +X](rule : Rule[In, Out, A, X]) { - - def mapRule[Out2, B, Y](f : Result[Out, A, X] => In => Result[Out2, B, Y]) : Rule[In, Out2, B, Y] = rule.factory.rule { - in : In => f(rule(in))(in) - } - - /** Creates a rule that succeeds only if the original rule would fail on the given context. */ - def unary_! : Rule[In, In, Unit, Nothing] = mapRule { - case Success(_, _) => in : In => Failure - case _ => in : In => Success(in, ()) - } - - /** Creates a rule that succeeds if the original rule succeeds, but returns the original input. */ - def & : Rule[In, In, A, X] = mapRule { - case Success(_, a) => in : In => Success(in, a) - case Failure => in : In => Failure - case Error(x) => in : In => Error(x) - } -} - -class SeqRule[S, +A, +X](rule : Rule[S, S, A, X]) { - import rule.factory._ - - def ? = rule mapRule { - case Success(out, a) => in : S => Success(out, Some(a)) - case Failure => in : S => Success(in, None) - case Error(x) => in : S => Error(x) - } - - /** Creates a rule that always succeeds with a Boolean value. - * Value is 'true' if this rule succeeds, 'false' otherwise */ - def -? = ? map { _ isDefined } - - def * = from[S] { - // tail-recursive function with reverse list accumulator - def rep(in : S, acc : List[A]) : Result[S, List[A], X] = rule(in) match { - case Success(out, a) => rep(out, a :: acc) - case Failure => Success(in, acc.reverse) - case err : Error[_] => err - } - in => rep(in, Nil) - } - - def + = rule ~++ * - - def ~>?[B >: A, X2 >: X](f : => Rule[S, S, B => B, X2]) = for (a <- rule; fs <- f?) yield fs.foldLeft[B](a) { (b, f) => f(b) } - - def ~>*[B >: A, X2 >: X](f : => Rule[S, S, B => B, X2]) = for (a <- rule; fs <- f*) yield fs.foldLeft[B](a) { (b, f) => f(b) } - - def ~*~[B >: A, X2 >: X](join : => Rule[S, S, (B, B) => B, X2]) = { - this ~>* (for (f <- join; a <- rule) yield f(_ : B, a)) - } - - /** Repeats this rule one or more times with a separator (which is discarded) */ - def +/[X2 >: X](sep : => Rule[S, S, Any, X2]) = rule ~++ (sep -~ rule *) - - /** Repeats this rule zero or more times with a separator (which is discarded) */ - def */[X2 >: X](sep : => Rule[S, S, Any, X2]) = +/(sep) | state[S].nil - - def *~-[Out, X2 >: X](end : => Rule[S, Out, Any, X2]) = (rule - end *) ~- end - def +~-[Out, X2 >: X](end : => Rule[S, Out, Any, X2]) = (rule - end +) ~- end - - /** Repeats this rule num times */ - def times(num : Int) : Rule[S, S, Seq[A], X] = from[S] { - val result = new scala.collection.mutable.ArraySeq[A](num) - // more compact using HoF but written this way so it's tail-recursive - def rep(i : Int, in : S) : Result[S, Seq[A], X] = { - if (i == num) Success(in, result) - else rule(in) match { - case Success(out, a) => { - result(i) = a - rep(i + 1, out) - } - case Failure => Failure - case err : Error[_] => err - } - } - in => rep(0, in) - } -} - diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ClassFileParser.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ClassFileParser.scala deleted file mode 100644 index 1a4b3456b8..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ClassFileParser.scala +++ /dev/null @@ -1,249 +0,0 @@ -package scala.tools.scalap -package scalax -package rules -package scalasig - - -import java.io.IOException - -import scala._ -import scala.Predef._ - -object ByteCode { - def apply(bytes : Array[Byte]) = new ByteCode(bytes, 0, bytes.length) - - def forClass(clazz : Class[_]) = { - val name = clazz.getName - val subPath = name.substring(name.lastIndexOf('.') + 1) + ".class" - val in = clazz.getResourceAsStream(subPath) - - try { - var rest = in.available() - val bytes = new Array[Byte](rest) - while (rest > 0) { - val res = in.read(bytes, bytes.length - rest, rest) - if (res == -1) throw new IOException("read error") - rest -= res - } - ByteCode(bytes) - - } finally { - in.close() - } - } -} - -/** Represents a chunk of raw bytecode. Used as input for the parsers - */ -class ByteCode(val bytes : Array[Byte], val pos : Int, val length : Int) { - - assert(pos >= 0 && length >= 0 && pos + length <= bytes.length) - - def nextByte = if (length == 0) Failure else Success(drop(1), bytes(pos)) - def next(n : Int) = if (length >= n) Success(drop(n), take(n)) else Failure - - def take(n : Int) = new ByteCode(bytes, pos, n) - def drop(n : Int) = new ByteCode(bytes, pos + n, length - n) - - def fold[X](x : X)(f : (X, Byte) => X) : X = { - var result = x - var i = pos - while (i < pos + length) { - result = f(result, bytes(i)) - i += 1 - } - result - } - - override def toString = length + " bytes" - - def toInt = fold(0) { (x, b) => (x << 8) + (b & 0xFF)} - def toLong = fold(0L) { (x, b) => (x << 8) + (b & 0xFF)} - - /** - * Transforms array subsequence of the current buffer into the UTF8 String and - * stores and array of bytes for the decompiler - */ - def fromUTF8StringAndBytes = { - val chunk: Array[Byte] = new Array[Byte](length) - System.arraycopy(bytes, pos, chunk, 0, length) - val str = new String(io.Codec.fromUTF8(bytes, pos, length)) - - StringBytesPair(str, chunk) - } - - def byte(i : Int) = bytes(pos) & 0xFF -} - -/** - * The wrapper for decode UTF-8 string - */ -case class StringBytesPair(string: String, bytes: Array[Byte]) - -/** Provides rules for parsing byte-code. -*/ -trait ByteCodeReader extends RulesWithState { - type S = ByteCode - type Parser[A] = Rule[A, String] - - val byte = apply(_ nextByte) - - val u1 = byte ^^ (_ & 0xFF) - val u2 = bytes(2) ^^ (_ toInt) - val u4 = bytes(4) ^^ (_ toInt) // should map to Long?? - - def bytes(n : Int) = apply(_ next n) -} - -object ClassFileParser extends ByteCodeReader { - def parse(byteCode : ByteCode) = expect(classFile)(byteCode) - def parseAnnotations(byteCode: ByteCode) = expect(annotations)(byteCode) - - val magicNumber = (u4 filter (_ == 0xCAFEBABE)) | error("Not a valid class file") - val version = u2 ~ u2 ^^ { case minor ~ major => (major, minor) } - val constantPool = (u2 ^^ ConstantPool) >> repeatUntil(constantPoolEntry)(_ isFull) - - // NOTE currently most constants just evaluate to a string description - // TODO evaluate to useful values - val utf8String = (u2 >> bytes) ^^ add1 { raw => pool => raw.fromUTF8StringAndBytes } - val intConstant = u4 ^^ add1 { x => pool => x } - val floatConstant = bytes(4) ^^ add1 { raw => pool => "Float: TODO" } - val longConstant = bytes(8) ^^ add2 { raw => pool => raw.toLong } - val doubleConstant = bytes(8) ^^ add2 { raw => pool => "Double: TODO" } - val classRef = u2 ^^ add1 { x => pool => "Class: " + pool(x) } - val stringRef = u2 ^^ add1 { x => pool => "String: " + pool(x) } - val fieldRef = memberRef("Field") - val methodRef = memberRef("Method") - val interfaceMethodRef = memberRef("InterfaceMethod") - val nameAndType = u2 ~ u2 ^^ add1 { case name ~ descriptor => pool => "NameAndType: " + pool(name) + ", " + pool(descriptor) } - - val constantPoolEntry = u1 >> { - case 1 => utf8String - case 3 => intConstant - case 4 => floatConstant - case 5 => longConstant - case 6 => doubleConstant - case 7 => classRef - case 8 => stringRef - case 9 => fieldRef - case 10 => methodRef - case 11 => interfaceMethodRef - case 12 => nameAndType - } - - val interfaces = u2 >> u2.times - - // bytes are parametrizes by the length, declared in u4 section - val attribute = u2 ~ (u4 >> bytes) ^~^ Attribute - // parse attributes u2 times - val attributes = u2 >> attribute.times - - // parse runtime-visible annotations - abstract class ElementValue - case class AnnotationElement(elementNameIndex: Int, elementValue: ElementValue) - case class ConstValueIndex(index: Int) extends ElementValue - case class EnumConstValue(typeNameIndex: Int, constNameIndex: Int) extends ElementValue - case class ClassInfoIndex(index: Int) extends ElementValue - case class Annotation(typeIndex: Int, elementValuePairs: Seq[AnnotationElement]) extends ElementValue - case class ArrayValue(values: Seq[ElementValue]) extends ElementValue - - def element_value: Parser[ElementValue] = u1 >> { - case 'B'|'C'|'D'|'F'|'I'|'J'|'S'|'Z'|'s' => u2 ^^ ConstValueIndex - case 'e' => u2 ~ u2 ^~^ EnumConstValue - case 'c' => u2 ^^ ClassInfoIndex - case '@' => annotation //nested annotation - case '[' => u2 >> element_value.times ^^ ArrayValue - } - - val element_value_pair = u2 ~ element_value ^~^ AnnotationElement - val annotation: Parser[Annotation] = u2 ~ (u2 >> element_value_pair.times) ^~^ Annotation - val annotations = u2 >> annotation.times - - val field = u2 ~ u2 ~ u2 ~ attributes ^~~~^ Field - val fields = u2 >> field.times - - val method = u2 ~ u2 ~ u2 ~ attributes ^~~~^ Method - val methods = u2 >> method.times - - val header = magicNumber -~ u2 ~ u2 ~ constantPool ~ u2 ~ u2 ~ u2 ~ interfaces ^~~~~~~^ ClassFileHeader - val classFile = header ~ fields ~ methods ~ attributes ~- !u1 ^~~~^ ClassFile - - // TODO create a useful object, not just a string - def memberRef(description : String) = u2 ~ u2 ^^ add1 { - case classRef ~ nameAndTypeRef => pool => description + ": " + pool(classRef) + ", " + pool(nameAndTypeRef) - } - - def add1[T](f : T => ConstantPool => Any)(raw : T)(pool : ConstantPool) = pool add f(raw) - def add2[T](f : T => ConstantPool => Any)(raw : T)(pool : ConstantPool) = pool add f(raw) add { pool => "" } -} - -case class ClassFile( - header : ClassFileHeader, - fields : Seq[Field], - methods : Seq[Method], - attributes : Seq[Attribute]) { - - def majorVersion = header.major - def minorVersion = header.minor - - def className = constant(header.classIndex) - def superClass = constant(header.superClassIndex) - def interfaces = header.interfaces.map(constant) - - def constant(index : Int) = header.constants(index) match { - case StringBytesPair(str, _) => str - case z => z - } - - def constantWrapped(index: Int) = header.constants(index) - - def attribute(name : String) = attributes.find {attrib => constant(attrib.nameIndex) == name } - - val RUNTIME_VISIBLE_ANNOTATIONS = "RuntimeVisibleAnnotations" - def annotations = (attributes.find(attr => constant(attr.nameIndex) == RUNTIME_VISIBLE_ANNOTATIONS) - .map(attr => ClassFileParser.parseAnnotations(attr.byteCode))) - - def annotation(name: String) = annotations.flatMap(seq => seq.find(annot => constant(annot.typeIndex) == name)) -} - -case class Attribute(nameIndex : Int, byteCode : ByteCode) -case class Field(flags : Int, nameIndex : Int, descriptorIndex : Int, attributes : Seq[Attribute]) -case class Method(flags : Int, nameIndex : Int, descriptorIndex : Int, attributes : Seq[Attribute]) - -case class ClassFileHeader( - minor : Int, - major : Int, - constants : ConstantPool, - flags : Int, - classIndex : Int, - superClassIndex : Int, - interfaces : Seq[Int]) { - - def constant(index : Int) = constants(index) -} - -case class ConstantPool(len : Int) { - val size = len - 1 - - private val buffer = new scala.collection.mutable.ArrayBuffer[ConstantPool => Any] - private val values = Array.fill[Option[Any]](size)(None) - - def isFull = buffer.length >= size - - def apply(index : Int) = { - // Note constant pool indices are 1-based - val i = index - 1 - values(i) getOrElse { - val value = buffer(i)(this) - buffer(i) = null - values(i) = Some(value) - value - } - } - - def add(f : ConstantPool => Any) = { - buffer += f - this - } -} - diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Flags.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Flags.scala deleted file mode 100644 index 218639e4a2..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Flags.scala +++ /dev/null @@ -1,68 +0,0 @@ -package scala.tools.scalap -package scalax -package rules -package scalasig - -trait Flags { - def hasFlag(flag : Long) : Boolean - - def isImplicit = hasFlag(0x00000001) - def isFinal = hasFlag(0x00000002) - def isPrivate = hasFlag(0x00000004) - def isProtected = hasFlag(0x00000008) - - def isSealed = hasFlag(0x00000010) - def isOverride = hasFlag(0x00000020) - def isCase = hasFlag(0x00000040) - def isAbstract = hasFlag(0x00000080) - - def isDeferred = hasFlag(0x00000100) - def isMethod = hasFlag(0x00000200) - def isModule = hasFlag(0x00000400) - def isInterface = hasFlag(0x00000800) - - def isMutable = hasFlag(0x00001000) - def isParam = hasFlag(0x00002000) - def isPackage = hasFlag(0x00004000) - def isDeprecated = hasFlag(0x00008000) - - def isCovariant = hasFlag(0x00010000) - def isCaptured = hasFlag(0x00010000) - - def isByNameParam = hasFlag(0x00010000) - def isContravariant = hasFlag(0x00020000) - def isLabel = hasFlag(0x00020000) // method symbol is a label. Set by TailCall - def isInConstructor = hasFlag(0x00020000) // class symbol is defined in this/superclass constructor - - def isAbstractOverride = hasFlag(0x00040000) - def isLocal = hasFlag(0x00080000) - - def isJava = hasFlag(0x00100000) - def isSynthetic = hasFlag(0x00200000) - def isStable = hasFlag(0x00400000) - def isStatic = hasFlag(0x00800000) - - def isCaseAccessor = hasFlag(0x01000000) - def isTrait = hasFlag(0x02000000) - def isBridge = hasFlag(0x04000000) - def isAccessor = hasFlag(0x08000000) - - def isSuperAccessor = hasFlag(0x10000000) - def isParamAccessor = hasFlag(0x20000000) - - def isModuleVar = hasFlag(0x40000000) // for variables: is the variable caching a module value - def isMonomorphic = hasFlag(0x40000000) // for type symbols: does not have type parameters - def isLazy = hasFlag(0x80000000L) // symbol is a lazy val. can't have MUTABLE unless transformed by typer - - def isError = hasFlag(0x100000000L) - def isOverloaded = hasFlag(0x200000000L) - def isLifted = hasFlag(0x400000000L) - - def isMixedIn = hasFlag(0x800000000L) - def isExistential = hasFlag(0x800000000L) - - def isExpandedName = hasFlag(0x1000000000L) - def isImplementationClass = hasFlag(0x2000000000L) - def isPreSuper = hasFlag(0x2000000000L) - -} diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala deleted file mode 100644 index fd70e0de35..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSig.scala +++ /dev/null @@ -1,306 +0,0 @@ -/* ___ ____ ___ __ ___ ___ -** / _// __// _ | / / / _ | / _ \ Scala classfile decoder -** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003-2013, LAMP/EPFL -** /____/\___/_/ |_/____/_/ |_/_/ http://scala-lang.org/ -** -*/ - - -package scala.tools.scalap -package scalax -package rules -package scalasig - -import ClassFileParser.{ ConstValueIndex, Annotation } -import scala.reflect.internal.pickling.ByteCodecs - -object ScalaSigParser { - import Main.{ SCALA_SIG, SCALA_SIG_ANNOTATION, BYTES_VALUE } - - def scalaSigFromAnnotation(classFile: ClassFile): Option[ScalaSig] = { - import classFile._ - - classFile.annotation(SCALA_SIG_ANNOTATION) map { - case Annotation(_, elements) => - val bytesElem = elements.find(elem => constant(elem.elementNameIndex) == BYTES_VALUE).get - val bytes = ((bytesElem.elementValue match {case ConstValueIndex(index) => constantWrapped(index)}) - .asInstanceOf[StringBytesPair].bytes) - val length = ByteCodecs.decode(bytes) - - ScalaSigAttributeParsers.parse(ByteCode(bytes.take(length))) - } - } - - def scalaSigFromAttribute(classFile: ClassFile) : Option[ScalaSig] = - classFile.attribute(SCALA_SIG).map(_.byteCode).map(ScalaSigAttributeParsers.parse) - - def parse(classFile: ClassFile): Option[ScalaSig] = { - val scalaSig = scalaSigFromAttribute(classFile) - - scalaSig match { - // No entries in ScalaSig attribute implies that the signature is stored in the annotation - case Some(ScalaSig(_, _, entries)) if entries.length == 0 => - scalaSigFromAnnotation(classFile) - case x => x - } - } - - def parse(clazz : Class[_]): Option[ScalaSig] = { - val byteCode = ByteCode.forClass(clazz) - val classFile = ClassFileParser.parse(byteCode) - - parse(classFile) - } -} - -object ScalaSigAttributeParsers extends ByteCodeReader { - def parse(byteCode : ByteCode) = expect(scalaSig)(byteCode) - - val nat = apply { - def natN(in : ByteCode, x : Int) : Result[ByteCode, Int, Nothing] = in.nextByte match { - case Success(out, b) => { - val y = (x << 7) + (b & 0x7f) - if ((b & 0x80) == 0) Success(out, y) else natN(out, y) - } - case _ => Failure - } - in => natN(in, 0) - } - - val rawBytes = nat >> bytes - val entry = nat ~ rawBytes - val symtab = nat >> entry.times - val scalaSig = nat ~ nat ~ symtab ^~~^ ScalaSig - - val utf8 = read(x => x.fromUTF8StringAndBytes.string) - val longValue = read(_ toLong) -} - -case class ScalaSig(majorVersion : Int, minorVersion : Int, table : Seq[Int ~ ByteCode]) extends DefaultMemoisable { - - case class Entry(index : Int, entryType : Int, byteCode : ByteCode) extends DefaultMemoisable { - def scalaSig = ScalaSig.this - - def setByteCode(byteCode : ByteCode) = Entry(index, entryType, byteCode) - } - - def hasEntry(index : Int) = table isDefinedAt index - - def getEntry(index : Int) = { - val entryType ~ byteCode = table(index) - Entry(index, entryType, byteCode) - } - - def parseEntry(index : Int) = applyRule(ScalaSigParsers.parseEntry(ScalaSigEntryParsers.entry)(index)) - - implicit def applyRule[A](parser : ScalaSigParsers.Parser[A]) = ScalaSigParsers.expect(parser)(this) - - override def toString = "ScalaSig version " + majorVersion + "." + minorVersion + { - for (i <- 0 until table.size) yield i + ":\t" + parseEntry(i) // + "\n\t" + getEntry(i) - }.mkString("\n", "\n", "") - - lazy val symbols : Seq[Symbol] = ScalaSigParsers.symbols - - lazy val topLevelClasses : List[ClassSymbol] = ScalaSigParsers.topLevelClasses - lazy val topLevelObjects : List[ObjectSymbol] = ScalaSigParsers.topLevelObjects -} - -object ScalaSigParsers extends RulesWithState with MemoisableRules { - type S = ScalaSig - type Parser[A] = Rule[A, String] - - val symTab = read(_.table) - val size = symTab ^^ (_.size) - - def entry(index : Int) = memo(("entry", index)) { - cond(_ hasEntry index) -~ read(_ getEntry index) >-> { entry => Success(entry, entry.entryType) } - } - - def parseEntry[A](parser : ScalaSigEntryParsers.EntryParser[A])(index : Int) : Parser[A] = - entry(index) -~ parser >> { a => entry => Success(entry.scalaSig, a) } - - def allEntries[A](f : ScalaSigEntryParsers.EntryParser[A]) = size >> { n => anyOf((0 until n) map parseEntry(f)) } - - lazy val entries = allEntries(ScalaSigEntryParsers.entry) as "entries" - lazy val symbols = allEntries(ScalaSigEntryParsers.symbol) as "symbols" - lazy val methods = allEntries(ScalaSigEntryParsers.methodSymbol) as "methods" - lazy val attributes = allEntries(ScalaSigEntryParsers.attributeInfo) as "attributes" - - lazy val topLevelClasses = allEntries(ScalaSigEntryParsers.topLevelClass) - lazy val topLevelObjects = allEntries(ScalaSigEntryParsers.topLevelObject) -} - -object ScalaSigEntryParsers extends RulesWithState with MemoisableRules { - import ScalaSigAttributeParsers.{nat, utf8, longValue} - - type S = ScalaSig#Entry - type EntryParser[A] = Rule[A, String] - - implicit def byteCodeEntryParser[A](rule : ScalaSigAttributeParsers.Parser[A]) : EntryParser[A] = apply { entry => - rule(entry.byteCode) mapOut (entry setByteCode _) - } - - def toEntry[A](index : Int) = apply { sigEntry => ScalaSigParsers.entry(index)(sigEntry.scalaSig) } - - def parseEntry[A](parser : EntryParser[A])(index : Int) = (toEntry(index) -~ parser) - - implicit def entryType(code : Int) = key filter (_ == code) - - val index = read(_.index) - val key = read(_.entryType) - - lazy val entry : EntryParser[Any] = symbol | typeEntry | literal | name | attributeInfo | annotInfo | children | get - - val ref = byteCodeEntryParser(nat) - - val termName = 1 -~ utf8 - val typeName = 2 -~ utf8 - - val name = termName | typeName as "name" - - def refTo[A](rule : EntryParser[A]) : EntryParser[A] = ref >>& parseEntry(rule) - - lazy val nameRef = refTo(name) - lazy val symbolRef = refTo(symbol) - lazy val typeRef = refTo(typeEntry) - lazy val constantRef = refTo(literal) - - val symbolInfo = nameRef ~ symbolRef ~ nat ~ (symbolRef?) ~ ref ~ get ^~~~~~^ SymbolInfo - - def symHeader(key: Int): EntryParser[Any] = (key -~ none | (key + 64) -~ nat) - - def symbolEntry(key : Int) = symHeader(key) -~ symbolInfo - - val noSymbol = 3 -^ NoSymbol - val typeSymbol = symbolEntry(4) ^^ TypeSymbol as "typeSymbol" - val aliasSymbol = symbolEntry(5) ^^ AliasSymbol as "alias" - val classSymbol = symbolEntry(6) ~ (ref?) ^~^ ClassSymbol as "class" - val objectSymbol = symbolEntry(7) ^^ ObjectSymbol as "object" - val methodSymbol = symHeader(8) -~ /*(ref?) -~*/ symbolInfo ~ (ref?) ^~^ MethodSymbol as "method" - val extRef = 9 -~ nameRef ~ (symbolRef?) ~ get ^~~^ ExternalSymbol as "extRef" - val extModClassRef = 10 -~ nameRef ~ (symbolRef?) ~ get ^~~^ ExternalSymbol as "extModClassRef" - - lazy val symbol : EntryParser[Symbol] = oneOf( - noSymbol, - typeSymbol, - aliasSymbol, - classSymbol, - objectSymbol, - methodSymbol, - extRef, - extModClassRef) as "symbol" - - val classSymRef = refTo(classSymbol) - val attribTreeRef = ref - val typeLevel = nat - val typeIndex = nat - - lazy val typeEntry : EntryParser[Type] = oneOf( - 11 -^ NoType, - 12 -^ NoPrefixType, - 13 -~ symbolRef ^^ ThisType, - 14 -~ typeRef ~ symbolRef ^~^ SingleType, - 15 -~ constantRef ^^ ConstantType, - 16 -~ typeRef ~ symbolRef ~ (typeRef*) ^~~^ TypeRefType, - 17 -~ typeRef ~ typeRef ^~^ TypeBoundsType, - 18 -~ classSymRef ~ (typeRef*) ^~^ RefinedType, - 19 -~ symbolRef ~ (typeRef*) ^~^ ClassInfoType, - 20 -~ typeRef ~ (symbolRef*) ^~^ MethodType, - 21 -~ typeRef ~ (refTo(typeSymbol)+) ^~^ PolyType, - // TODO: make future safe for past by doing the same transformation as in the - // full unpickler in case we're reading pre-2.9 classfiles - 21 -~ typeRef ^^ NullaryMethodType, - 22 -~ typeRef ~ (symbolRef*) ^~^ MethodType, - 42 -~ typeRef ~ (attribTreeRef*) ^~^ AnnotatedType, - 51 -~ typeRef ~ symbolRef ~ (attribTreeRef*) ^~~^ AnnotatedWithSelfType, - 48 -~ typeRef ~ (symbolRef*) ^~^ ExistentialType) as "type" - - lazy val literal: EntryParser[Any] = oneOf( - 24 -^ (()), - 25 -~ longValue ^^ (_ != 0L), - 26 -~ longValue ^^ (_.toByte), - 27 -~ longValue ^^ (_.toShort), - 28 -~ longValue ^^ (_.toChar), - 29 -~ longValue ^^ (_.toInt), - 30 -~ longValue ^^ (_.toLong), - 31 -~ longValue ^^ (l => java.lang.Float.intBitsToFloat(l.toInt)), - 32 -~ longValue ^^ (java.lang.Double.longBitsToDouble), - 33 -~ nameRef, - 34 -^ null, - 35 -~ typeRef) - - lazy val attributeInfo = 40 -~ symbolRef ~ typeRef ~ (constantRef?) ~ (nameRef ~ constantRef *) ^~~~^ AttributeInfo // sym_Ref info_Ref {constant_Ref} {nameRef constantRef} - lazy val children = 41 -~ (nat*) ^^ Children //sym_Ref {sym_Ref} - lazy val annotInfo = 43 -~ (nat*) ^^ AnnotInfo // attarg_Ref {constant_Ref attarg_Ref} - - lazy val topLevelClass = classSymbol filter isTopLevelClass - lazy val topLevelObject = objectSymbol filter isTopLevel - - def isTopLevel(symbol : Symbol) = symbol.parent match { - case Some(ext : ExternalSymbol) => true - case _ => false - } - def isTopLevelClass (symbol : Symbol) = !symbol.isModule && isTopLevel(symbol) -} - - case class AttributeInfo(symbol : Symbol, typeRef : Type, value : Option[Any], values : Seq[String ~ Any]) // sym_Ref info_Ref {constant_Ref} {nameRef constantRef} - case class Children(symbolRefs : Seq[Int]) //sym_Ref {sym_Ref} - - case class AnnotInfo(refs : Seq[Int]) // attarg_Ref {constant_Ref attarg_Ref} - - /*************************************************** - * | 49 TREE len_Nat 1 EMPTYtree - * | 49 TREE len_Nat 2 PACKAGEtree type_Ref sym_Ref mods_Ref name_Ref {tree_Ref} - * | 49 TREE len_Nat 3 CLASStree type_Ref sym_Ref mods_Ref name_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 4 MODULEtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref - * | 49 TREE len_Nat 5 VALDEFtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 6 DEFDEFtree type_Ref sym_Ref mods_Ref name_Ref numtparams_Nat {tree_Ref} numparamss_Nat {numparams_Nat {tree_Ref}} tree_Ref tree_Ref - * | 49 TREE len_Nat 7 TYPEDEFtree type_Ref sym_Ref mods_Ref name_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 8 LABELtree type_Ref sym_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 9 IMPORTtree type_Ref sym_Ref tree_Ref {name_Ref name_Ref} - * | 49 TREE len_Nat 11 DOCDEFtree type_Ref sym_Ref string_Ref tree_Ref - * | 49 TREE len_Nat 12 TEMPLATEtree type_Ref sym_Ref numparents_Nat {tree_Ref} tree_Ref {tree_Ref} - * | 49 TREE len_Nat 13 BLOCKtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 14 CASEtree type_Ref tree_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 15 SEQUENCEtree type_Ref {tree_Ref} - * | 49 TREE len_Nat 16 ALTERNATIVEtree type_Ref {tree_Ref} - * | 49 TREE len_Nat 17 STARtree type_Ref {tree_Ref} - * | 49 TREE len_Nat 18 BINDtree type_Ref sym_Ref name_Ref tree_Ref - * | 49 TREE len_Nat 19 UNAPPLYtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 20 ARRAYVALUEtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 21 FUNCTIONtree type_Ref sym_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 22 ASSIGNtree type_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 23 IFtree type_Ref tree_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 24 MATCHtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 25 RETURNtree type_Ref sym_Ref tree_Ref - * | 49 TREE len_Nat 26 TREtree type_Ref tree_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 27 THROWtree type_Ref tree_Ref - * | 49 TREE len_Nat 28 NEWtree type_Ref tree_Ref - * | 49 TREE len_Nat 29 TYPEDtree type_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 30 TYPEAPPLYtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 31 APPLYtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 32 APPLYDYNAMICtree type_Ref sym_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 33 SUPERtree type_Ref sym_Ref tree_Ref name_Ref - * | 49 TREE len_Nat 34 THIStree type_Ref sym_Ref name_Ref - * | 49 TREE len_Nat 35 SELECTtree type_Ref sym_Ref tree_Ref name_Ref - * | 49 TREE len_Nat 36 IDENTtree type_Ref sym_Ref name_Ref - * | 49 TREE len_Nat 37 LITERALtree type_Ref constant_Ref - * | 49 TREE len_Nat 38 TYPEtree type_Ref - * | 49 TREE len_Nat 39 ANNOTATEDtree type_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 40 SINGLETONTYPEtree type_Ref tree_Ref - * | 49 TREE len_Nat 41 SELECTFROMTYPEtree type_Ref tree_Ref name_Ref - * | 49 TREE len_Nat 42 COMPOUNDTYPEtree type_Ref tree_Ref - * | 49 TREE len_Nat 43 APPLIEDTYPEtree type_Ref tree_Ref {tree_Ref} - * | 49 TREE len_Nat 44 TYPEBOUNDStree type_Ref tree_Ref tree_Ref - * | 49 TREE len_Nat 45 EXISTENTIALTYPEtree type_Ref tree_Ref {tree_Ref} - * | 50 MODIFIERS len_Nat flags_Long privateWithin_Ref - * SymbolInfo = name_Ref owner_Ref flags_LongNat [privateWithin_Ref] info_Ref - * NameInfo = - * NumInfo = - * Ref = Nat - * AnnotInfoBody = info_Ref {annotArg_Ref} {name_Ref constAnnotArg_Ref} - * AnnotArg = Tree | Constant - * ConstAnnotArg = Constant | AnnotInfo | AnnotArgArray - * - * len is remaining length after `len`. - */ diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala deleted file mode 100644 index e5a4ff649e..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/ScalaSigPrinter.scala +++ /dev/null @@ -1,439 +0,0 @@ -/* ___ ____ ___ __ ___ ___ -** / _// __// _ | / / / _ | / _ \ Scala classfile decoder -** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003-2013, LAMP/EPFL -** /____/\___/_/ |_/____/_/ |_/_/ http://scala-lang.org/ -** -*/ - - -package scala.tools.scalap -package scalax -package rules -package scalasig - -import java.io.{PrintStream, ByteArrayOutputStream} -import java.util.regex.Pattern -import scala.tools.scalap.scalax.util.StringUtil -import scala.reflect.NameTransformer -import java.lang.String - -class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) { - import stream._ - - val CONSTRUCTOR_NAME = "" - - case class TypeFlags(printRep: Boolean) - - def printSymbol(symbol: Symbol) {printSymbol(0, symbol)} - - def printSymbolAttributes(s: Symbol, onNewLine: Boolean, indent: => Unit) = s match { - case t: SymbolInfoSymbol => { - for (a <- t.attributes) { - indent; print(toString(a)) - if (onNewLine) print("\n") else print(" ") - } - } - case _ => - } - - def printSymbol(level: Int, symbol: Symbol) { - if (!symbol.isLocal && - !(symbol.isPrivate && !printPrivates)) { - def indent() {for (i <- 1 to level) print(" ")} - - printSymbolAttributes(symbol, true, indent) - symbol match { - case o: ObjectSymbol => - if (!isCaseClassObject(o)) { - indent - if (o.name == "package") { - // print package object - printPackageObject(level, o) - } else { - printObject(level, o) - } - } - case c: ClassSymbol if !refinementClass(c) && !c.isModule => - indent - printClass(level, c) - case m: MethodSymbol => - printMethod(level, m, indent) - case a: AliasSymbol => - indent - printAlias(level, a) - case t: TypeSymbol if !t.isParam && !t.name.matches("_\\$\\d+")=> - indent - printTypeSymbol(level, t) - case s => - } - } - } - - def isCaseClassObject(o: ObjectSymbol): Boolean = { - val TypeRefType(_, classSymbol: ClassSymbol, _) = o.infoType - o.isFinal && (classSymbol.children.find(x => x.isCase && x.isInstanceOf[MethodSymbol]) match { - case Some(_) => true - case None => false - }) - } - - private def underCaseClass(m: MethodSymbol) = m.parent match { - case Some(c: ClassSymbol) => c.isCase - case _ => false - } - - - private def printChildren(level: Int, symbol: Symbol) { - for (child <- symbol.children) printSymbol(level + 1, child) - } - - def printWithIndent(level: Int, s: String) { - def indent() {for (i <- 1 to level) print(" ")} - indent; - print(s) - } - - def printModifiers(symbol: Symbol) { - // print private access modifier - if (symbol.isPrivate) print("private ") - else if (symbol.isProtected) print("protected ") - else symbol match { - case sym: SymbolInfoSymbol => sym.symbolInfo.privateWithin match { - case Some(t: Symbol) => print("private[" + t.name +"] ") - case _ => - } - case _ => - } - - if (symbol.isSealed) print("sealed ") - if (symbol.isImplicit) print("implicit ") - if (symbol.isFinal && !symbol.isInstanceOf[ObjectSymbol]) print("final ") - if (symbol.isOverride) print("override ") - if (symbol.isAbstract) symbol match { - case c@(_: ClassSymbol | _: ObjectSymbol) if !c.isTrait => print("abstract ") - case _ => () - } - if (symbol.isCase && !symbol.isMethod) print("case ") - } - - private def refinementClass(c: ClassSymbol) = c.name == "" - - def printClass(level: Int, c: ClassSymbol) { - if (c.name == "" /*scala.tools.nsc.symtab.StdNames.LOCAL_CHILD.toString()*/ ) { - print("\n") - } else { - printModifiers(c) - val defaultConstructor = if (c.isCase) getPrinterByConstructor(c) else "" - if (c.isTrait) print("trait ") else print("class ") - print(processName(c.name)) - val it = c.infoType - val classType = it match { - case PolyType(typeRef, symbols) => PolyTypeWithCons(typeRef, symbols, defaultConstructor) - case ClassInfoType(a, b) if c.isCase => ClassInfoTypeWithCons(a, b, defaultConstructor) - case _ => it - } - printType(classType) - print(" {") - //Print class selftype - c.selfType match { - case Some(t: Type) => print("\n"); print(" this : " + toString(t) + " =>") - case None => - } - print("\n") - printChildren(level, c) - printWithIndent(level, "}\n") - } - } - - def getPrinterByConstructor(c: ClassSymbol) = { - c.children.find { - case m: MethodSymbol if m.name == CONSTRUCTOR_NAME => true - case _ => false - } match { - case Some(m: MethodSymbol) => - val baos = new ByteArrayOutputStream - val stream = new PrintStream(baos) - val printer = new ScalaSigPrinter(stream, printPrivates) - printer.printMethodType(m.infoType, false)(()) - baos.toString - case _ => - "" - } - } - - def printPackageObject(level: Int, o: ObjectSymbol) { - printModifiers(o) - print("package ") - print("object ") - val poName = o.symbolInfo.owner.name - print(processName(poName)) - val TypeRefType(_, classSymbol: ClassSymbol, _) = o.infoType - printType(classSymbol) - print(" {\n") - printChildren(level, classSymbol) - printWithIndent(level, "}\n") - - } - - def printObject(level: Int, o: ObjectSymbol) { - printModifiers(o) - print("object ") - print(processName(o.name)) - val TypeRefType(_, classSymbol: ClassSymbol, _) = o.infoType - printType(classSymbol) - print(" {\n") - printChildren(level, classSymbol) - printWithIndent(level, "}\n") - } - - def genParamNames(t: {def paramTypes: Seq[Type]}): List[String] = t.paramTypes.toList.map(x => { - var str = toString(x) - val j = str.indexOf("[") - if (j > 0) str = str.substring(0, j) - str = StringUtil.trimStart(str, "=> ") - val i = str.lastIndexOf(".") - val res = if (i > 0) str.substring(i + 1) else str - if (res.length > 1) StringUtil.decapitalize(res.substring(0, 1)) else res.toLowerCase - }) - - def printMethodType(t: Type, printResult: Boolean)(cont: => Unit): Unit = { - - def _pmt(mt: Type {def resultType: Type; def paramSymbols: Seq[Symbol]}) = { - - val paramEntries = mt.paramSymbols.map({ - case ms: MethodSymbol => ms.name + " : " + toString(ms.infoType)(TypeFlags(true)) - case _ => "^___^" - }) - val implicitWord = mt.paramSymbols.headOption match { - case Some(p) if p.isImplicit => "implicit " - case _ => "" - } - - // Print parameter clauses - print(paramEntries.mkString("(" + implicitWord, ", ", ")")) - - // Print result type - mt.resultType match { - case mt: MethodType => printMethodType(mt, printResult)({}) - case x => if (printResult) { - print(" : "); - printType(x) - } - } - } - - t match { - case NullaryMethodType(resType) => if (printResult) { print(" : "); printType(resType) } - case mt@MethodType(resType, paramSymbols) => _pmt(mt) - case pt@PolyType(mt, typeParams) => { - print(typeParamString(typeParams)) - printMethodType(mt, printResult)({}) - } - //todo consider another method types - case x => print(" : "); printType(x) - } - - // Print rest of the symbol output - cont - } - - def printMethod(level: Int, m: MethodSymbol, indent: () => Unit) { - def cont() = print(" = { /* compiled code */ }") - - val n = m.name - if (underCaseClass(m) && n == CONSTRUCTOR_NAME) return - if (n.matches(".+\\$default\\$\\d+")) return // skip default function parameters - if (n.startsWith("super$")) return // do not print auxiliary qualified super accessors - if (m.isAccessor && n.endsWith("_$eq")) return - indent() - printModifiers(m) - if (m.isAccessor) { - val indexOfSetter = m.parent.get.children.indexWhere(x => x.isInstanceOf[MethodSymbol] && - x.asInstanceOf[MethodSymbol].name == n + "_$eq") - print(if (indexOfSetter > 0) "var " else "val ") - } else { - print("def ") - } - n match { - case CONSTRUCTOR_NAME => - print("this") - printMethodType(m.infoType, false)(cont) - case name => - val nn = processName(name) - print(nn) - printMethodType(m.infoType, true)( - {if (!m.isDeferred) print(" = { /* compiled code */ }" /* Print body only for non-abstract methods */ )} - ) - } - print("\n") - } - - def printAlias(level: Int, a: AliasSymbol) { - print("type ") - print(processName(a.name)) - printType(a.infoType, " = ") - print("\n") - printChildren(level, a) - } - - def printTypeSymbol(level: Int, t: TypeSymbol) { - print("type ") - print(processName(t.name)) - printType(t.infoType) - print("\n") - } - - def toString(attrib: AttributeInfo): String = { - val buffer = new StringBuffer - buffer.append(toString(attrib.typeRef, "@")) - if (attrib.value.isDefined) { - buffer.append("(") - val value = attrib.value.get - val stringVal = value.isInstanceOf[String] - if (stringVal) buffer.append("\"") - val stringValue = valueToString(value) - val isMultiline = stringVal && (stringValue.contains("\n") - || stringValue.contains("\r")) - if (isMultiline) buffer.append("\"\"") - buffer.append(valueToString(value)) - if (isMultiline) buffer.append("\"\"") - if (stringVal) buffer.append("\"") - buffer.append(")") - } - if (!attrib.values.isEmpty) { - buffer.append(" {") - for (name ~ value <- attrib.values) { - buffer.append(" val ") - buffer.append(processName(name)) - buffer.append(" = ") - buffer.append(valueToString(value)) - } - buffer.append(valueToString(attrib.value)) - buffer.append(" }") - } - buffer.toString - } - - def valueToString(value: Any): String = value match { - case t: Type => toString(t) - // TODO string, char, float, etc. - case _ => value.toString - } - - implicit object _tf extends TypeFlags(false) - - def printType(sym: SymbolInfoSymbol)(implicit flags: TypeFlags): Unit = printType(sym.infoType)(flags) - - def printType(t: Type)(implicit flags: TypeFlags): Unit = print(toString(t)(flags)) - - def printType(t: Type, sep: String)(implicit flags: TypeFlags): Unit = print(toString(t, sep)(flags)) - - def toString(t: Type)(implicit flags: TypeFlags): String = toString(t, "")(flags) - - def toString(t: Type, sep: String)(implicit flags: TypeFlags): String = { - // print type itself - t match { - case ThisType(symbol) => sep + processName(symbol.path) + ".type" - case SingleType(typeRef, symbol) => sep + processName(symbol.path) + ".type" - case ConstantType(constant) => sep + (constant match { - case null => "scala.Null" - case _: Unit => "scala.Unit" - case _: Boolean => "scala.Boolean" - case _: Byte => "scala.Byte" - case _: Char => "scala.Char" - case _: Short => "scala.Short" - case _: Int => "scala.Int" - case _: Long => "scala.Long" - case _: Float => "scala.Float" - case _: Double => "scala.Double" - case _: String => "java.lang.String" - case c: Class[_] => "java.lang.Class[" + c.getComponentType.getCanonicalName.replace("$", ".") + "]" - }) - case TypeRefType(prefix, symbol, typeArgs) => sep + (symbol.path match { - case "scala." => flags match { - case TypeFlags(true) => toString(typeArgs.head) + "*" - case _ => "scala.Seq" + typeArgString(typeArgs) - } - case "scala." => "=> " + toString(typeArgs.head) - case _ => { - val path = StringUtil.cutSubstring(symbol.path)(".package") //remove package object reference - StringUtil.trimStart(processName(path) + typeArgString(typeArgs), ".") - } - }) - case TypeBoundsType(lower, upper) => { - val lb = toString(lower) - val ub = toString(upper) - val lbs = if (!lb.equals("scala.Nothing")) " >: " + lb else "" - val ubs = if (!ub.equals("scala.Any")) " <: " + ub else "" - lbs + ubs - } - case RefinedType(classSym, typeRefs) => sep + typeRefs.map(toString).mkString("", " with ", "") - case ClassInfoType(symbol, typeRefs) => sep + typeRefs.map(toString).mkString(" extends ", " with ", "") - case ClassInfoTypeWithCons(symbol, typeRefs, cons) => sep + typeRefs.map(toString). - mkString(cons + " extends ", " with ", "") - - case MethodType(resultType, _) => toString(resultType, sep) - case NullaryMethodType(resultType) => toString(resultType, sep) - - case PolyType(typeRef, symbols) => typeParamString(symbols) + toString(typeRef, sep) - case PolyTypeWithCons(typeRef, symbols, cons) => typeParamString(symbols) + processName(cons) + toString(typeRef, sep) - case AnnotatedType(typeRef, attribTreeRefs) => { - toString(typeRef, sep) - } - case AnnotatedWithSelfType(typeRef, symbol, attribTreeRefs) => toString(typeRef, sep) - case ExistentialType(typeRef, symbols) => { - val refs = symbols.map(toString _).filter(!_.startsWith("_")).map("type " + _) - toString(typeRef, sep) + (if (refs.size > 0) refs.mkString(" forSome {", "; ", "}") else "") - } - case _ => sep + t.toString - } - } - - def getVariance(t: TypeSymbol) = if (t.isCovariant) "+" else if (t.isContravariant) "-" else "" - - def toString(symbol: Symbol): String = symbol match { - case symbol: TypeSymbol => { - val attrs = (for (a <- symbol.attributes) yield toString(a)).mkString(" ") - val atrs = if (attrs.length > 0) attrs.trim + " " else "" - atrs + getVariance(symbol) + processName(symbol.name) + toString(symbol.infoType) - } - case s => symbol.toString - } - - def typeArgString(typeArgs: Seq[Type]): String = - if (typeArgs.isEmpty) "" - else typeArgs.map(toString).map(StringUtil.trimStart(_, "=> ")).mkString("[", ", ", "]") - - def typeParamString(params: Seq[Symbol]): String = - if (params.isEmpty) "" - else params.map(toString).mkString("[", ", ", "]") - - val _syms = Map("\\$bar" -> "|", "\\$tilde" -> "~", - "\\$bang" -> "!", "\\$up" -> "^", "\\$plus" -> "+", - "\\$minus" -> "-", "\\$eq" -> "=", "\\$less" -> "<", - "\\$times" -> "*", "\\$div" -> "/", "\\$bslash" -> "\\\\", - "\\$greater" -> ">", "\\$qmark" -> "?", "\\$percent" -> "%", - "\\$amp" -> "&", "\\$colon" -> ":", "\\$u2192" -> "→", - "\\$hash" -> "#") - val pattern = Pattern.compile(_syms.keys.foldLeft("")((x, y) => if (x == "") y else x + "|" + y)) - val placeholderPattern = "_\\$(\\d)+" - - private def stripPrivatePrefix(name: String) = { - val i = name.lastIndexOf("$$") - if (i > 0) name.substring(i + 2) else name - } - - def processName(name: String) = { - val stripped = stripPrivatePrefix(name) - val m = pattern.matcher(stripped) - var temp = stripped - while (m.find) { - val key = m.group - val re = "\\" + key - temp = temp.replaceAll(re, _syms(re)) - } - val result = temp.replaceAll(placeholderPattern, "_") - NameTransformer.decode(result) - } - -} diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/SourceFileAttributeParser.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/SourceFileAttributeParser.scala deleted file mode 100644 index fc5a75c046..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/SourceFileAttributeParser.scala +++ /dev/null @@ -1,28 +0,0 @@ -package scala.tools.scalap -package scalax -package rules -package scalasig - -/** - * @author ilyas - */ - -object SourceFileAttributeParser extends ByteCodeReader { - val sourceFile = u2 ^^ SourceFileInfo - - def parse(byteCode: ByteCode) = expect(sourceFile)(byteCode) -} - -/** - * - * SourceFile_attribute { - u2 attribute_name_index; - u4 attribute_length; - u2 sourcefile_index; - } - * - * Contains only file index in ConstantPool, first two fields are already treated - * by {@link scalax.rules.scalasig.ClassFile.attribute#attribute} - */ -case class SourceFileInfo(sourceFileIndex: Int) - diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Symbol.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Symbol.scala deleted file mode 100644 index dee1cf84ac..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Symbol.scala +++ /dev/null @@ -1,73 +0,0 @@ -package scala.tools.scalap -package scalax -package rules -package scalasig - -import ScalaSigEntryParsers._ - -trait Symbol extends Flags { - def name : String - def parent : Option[Symbol] - def children : Seq[Symbol] - - def path : String = parent.map(_.path + ".").getOrElse("") + name -} - -case object NoSymbol extends Symbol { - def name = "" - def parent = None - def hasFlag(flag : Long) = false - def children = Nil -} - -abstract class ScalaSigSymbol extends Symbol { - def applyRule[A](rule : EntryParser[A]) : A = expect(rule)(entry) - def applyScalaSigRule[A](rule : ScalaSigParsers.Parser[A]) = ScalaSigParsers.expect(rule)(entry.scalaSig) - - def entry : ScalaSig#Entry - def index = entry.index - - lazy val children : Seq[Symbol] = applyScalaSigRule(ScalaSigParsers.symbols) filter (_.parent == Some(this)) - lazy val attributes : Seq[AttributeInfo] = applyScalaSigRule(ScalaSigParsers.attributes) filter (_.symbol == this) -} - -case class ExternalSymbol(name : String, parent : Option[Symbol], entry : ScalaSig#Entry) extends ScalaSigSymbol { - override def toString = path - def hasFlag(flag : Long) = false -} - -case class SymbolInfo(name : String, owner : Symbol, flags : Int, privateWithin : Option[AnyRef], info : Int, entry : ScalaSig#Entry) { - def symbolString(any : AnyRef) = any match { - case sym : SymbolInfoSymbol => sym.index.toString - case other => other.toString - } - - override def toString = name + ", owner=" + symbolString(owner) + ", flags=" + flags.toHexString + ", info=" + info + (privateWithin match { - case Some(any) => ", privateWithin=" + symbolString(any) - case None => " " - }) -} - -abstract class SymbolInfoSymbol extends ScalaSigSymbol { - def symbolInfo : SymbolInfo - - def entry = symbolInfo.entry - def name = symbolInfo.name - def parent = Some(symbolInfo.owner) - def hasFlag(flag : Long) = (symbolInfo.flags & flag) != 0L - - lazy val infoType = applyRule(parseEntry(typeEntry)(symbolInfo.info)) -} - -case class TypeSymbol(symbolInfo : SymbolInfo) extends SymbolInfoSymbol{ - override def path = name -} - -case class AliasSymbol(symbolInfo : SymbolInfo) extends SymbolInfoSymbol{ - override def path = name -} -case class ClassSymbol(symbolInfo : SymbolInfo, thisTypeRef : Option[Int]) extends SymbolInfoSymbol { - lazy val selfType = thisTypeRef.map{(x: Int) => applyRule(parseEntry(typeEntry)(x))} -} -case class ObjectSymbol(symbolInfo : SymbolInfo) extends SymbolInfoSymbol -case class MethodSymbol(symbolInfo : SymbolInfo, aliasRef : Option[Int]) extends SymbolInfoSymbol diff --git a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala b/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala deleted file mode 100644 index 0444e701f2..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/rules/scalasig/Type.scala +++ /dev/null @@ -1,25 +0,0 @@ -package scala.tools.scalap -package scalax -package rules -package scalasig - -abstract class Type - -case object NoType extends Type -case object NoPrefixType extends Type - -case class ThisType(symbol : Symbol) extends Type -case class SingleType(typeRef : Type, symbol : Symbol) extends Type -case class ConstantType(constant : Any) extends Type -case class TypeRefType(prefix : Type, symbol : Symbol, typeArgs : Seq[Type]) extends Type -case class TypeBoundsType(lower : Type, upper : Type) extends Type -case class RefinedType(classSym : Symbol, typeRefs : List[Type]) extends Type -case class ClassInfoType(symbol : Symbol, typeRefs : Seq[Type]) extends Type -case class ClassInfoTypeWithCons(symbol : Symbol, typeRefs : Seq[Type], cons: String) extends Type -case class MethodType(resultType : Type, paramSymbols : Seq[Symbol]) extends Type -case class NullaryMethodType(resultType : Type) extends Type -case class PolyType(typeRef : Type, symbols : Seq[TypeSymbol]) extends Type -case class PolyTypeWithCons(typeRef : Type, symbols : Seq[TypeSymbol], cons: String) extends Type -case class AnnotatedType(typeRef : Type, attribTreeRefs : List[Int]) extends Type -case class AnnotatedWithSelfType(typeRef : Type, symbol : Symbol, attribTreeRefs : List[Int]) extends Type -case class ExistentialType(typeRef : Type, symbols : Seq[Symbol]) extends Type diff --git a/src/scalap/scala/tools/scalap/scalax/util/StringUtil.scala b/src/scalap/scala/tools/scalap/scalax/util/StringUtil.scala deleted file mode 100644 index 6077eded0f..0000000000 --- a/src/scalap/scala/tools/scalap/scalax/util/StringUtil.scala +++ /dev/null @@ -1,19 +0,0 @@ -package scala.tools.scalap -package scalax -package util - -import java.beans.Introspector - -/** - * @author ilyas - */ - -object StringUtil { - - def trimStart(s: String, prefix: String) = if (s != null && s.startsWith(prefix)) s.substring(prefix.length) else s - - def decapitalize(s: String) = Introspector.decapitalize(s) - - def cutSubstring(dom: String)(s: String) = if (dom != null && s != null) dom.replace(s, "") else dom - -} -- cgit v1.2.3 From a4a43a19b4b3f16285671ece2c9d82ea10adc0e8 Mon Sep 17 00:00:00 2001 From: Simon Ochsenreither Date: Mon, 29 Jul 2013 21:36:11 +0200 Subject: Whitespace fixes in scala/tools/scalap --- .../scala/tools/scalap/rules/Memoisable.scala | 16 ++-- src/scalap/scala/tools/scalap/rules/Result.scala | 45 +++++----- src/scalap/scala/tools/scalap/rules/Rule.scala | 98 +++++++++++----------- src/scalap/scala/tools/scalap/rules/Rules.scala | 56 ++++++------- src/scalap/scala/tools/scalap/rules/SeqRule.scala | 50 +++++------ .../tools/scalap/scalasig/ClassFileParser.scala | 68 +++++++-------- src/scalap/scala/tools/scalap/scalasig/Flags.scala | 2 +- .../scala/tools/scalap/scalasig/ScalaSig.scala | 64 +++++++------- .../tools/scalap/scalasig/ScalaSigPrinter.scala | 10 +-- .../scala/tools/scalap/scalasig/Symbol.scala | 44 +++++----- src/scalap/scala/tools/scalap/scalasig/Type.scala | 30 +++---- test/files/scalap/abstractClass.check | 2 +- test/files/scalap/abstractMethod.check | 6 +- test/files/scalap/caseClass.check | 32 +++---- test/files/scalap/caseObject.check | 16 ++-- test/files/scalap/cbnParam.check | 2 +- test/files/scalap/classPrivate.check | 8 +- test/files/scalap/classWithExistential.check | 2 +- test/files/scalap/classWithSelfAnnotation.check | 4 +- test/files/scalap/covariantParam.check | 2 +- test/files/scalap/defaultParameter.check | 2 +- test/files/scalap/implicitParam.check | 2 +- test/files/scalap/packageObject.check | 2 +- test/files/scalap/paramClauses.check | 2 +- test/files/scalap/paramNames.check | 2 +- test/files/scalap/sequenceParam.check | 2 +- test/files/scalap/simpleClass.check | 2 +- test/files/scalap/traitObject.check | 6 +- test/files/scalap/typeAnnotations.check | 4 +- test/files/scalap/valAndVar.check | 4 +- test/files/scalap/wildcardType.check | 2 +- 31 files changed, 293 insertions(+), 294 deletions(-) (limited to 'src') diff --git a/src/scalap/scala/tools/scalap/rules/Memoisable.scala b/src/scalap/scala/tools/scalap/rules/Memoisable.scala index 236b993c4b..418141bee7 100644 --- a/src/scalap/scala/tools/scalap/rules/Memoisable.scala +++ b/src/scalap/scala/tools/scalap/rules/Memoisable.scala @@ -15,19 +15,19 @@ package scala.tools.scalap.rules import scala.collection.mutable trait MemoisableRules extends Rules { - def memo[In <: Memoisable, Out, A, X](key : AnyRef)(toRule : => In => Result[Out, A, X]) = { + def memo[In <: Memoisable, Out, A, X](key: AnyRef)(toRule: => In => Result[Out, A, X]) = { lazy val rule = toRule from[In] { in => in.memo(key, rule(in)) } } - override def ruleWithName[In, Out, A, X](name : String, f : In => Result[Out, A, X]) = super.ruleWithName(name, (in : In) => in match { - case s : Memoisable => s.memo(name, f(in)) + override def ruleWithName[In, Out, A, X](name: String, f: In => Result[Out, A, X]) = super.ruleWithName(name, (in: In) => in match { + case s: Memoisable => s.memo(name, f(in)) case _ => f(in) }) } trait Memoisable { - def memo[A](key : AnyRef, a : => A) : A + def memo[A](key: AnyRef, a: => A): A } @@ -38,18 +38,18 @@ object DefaultMemoisable { trait DefaultMemoisable extends Memoisable { protected val map = new mutable.HashMap[AnyRef, Any] - def memo[A](key : AnyRef, a : => A) = { + def memo[A](key: AnyRef, a: => A) = { map.getOrElseUpdate(key, compute(key, a)).asInstanceOf[A] } - protected def compute[A](key : AnyRef, a : => A): Any = a match { - case success : Success[_, _] => onSuccess(key, success); success + protected def compute[A](key: AnyRef, a: => A): Any = a match { + case success: Success[_, _] => onSuccess(key, success); success case other => if(DefaultMemoisable.debug) println(key + " -> " + other) other } - protected def onSuccess[S, T](key : AnyRef, result : Success[S, T]) { + protected def onSuccess[S, T](key: AnyRef, result: Success[S, T]) { val Success(out, t) = result if(DefaultMemoisable.debug) println(key + " -> " + t + " (" + out + ")") } diff --git a/src/scalap/scala/tools/scalap/rules/Result.scala b/src/scalap/scala/tools/scalap/rules/Result.scala index ef4d0eb8b0..ae05416d7a 100644 --- a/src/scalap/scala/tools/scalap/rules/Result.scala +++ b/src/scalap/scala/tools/scalap/rules/Result.scala @@ -16,35 +16,35 @@ package scala.tools.scalap.rules; * * @see the Scala parser combinator */ -case class ~[+A, +B](_1 : A, _2 : B) { +case class ~[+A, +B](_1: A, _2: B) { override def toString = "(" + _1 + " ~ " + _2 + ")" } sealed abstract class Result[+Out, +A, +X] { - def out : Out - def value : A - def error : X + def out: Out + def value: A + def error: X - implicit def toOption : Option[A] + implicit def toOption: Option[A] - def map[B](f : A => B) : Result[Out, B, X] - def mapOut[Out2](f : Out => Out2) : Result[Out2, A, X] - def map[Out2, B](f : (Out, A) => (Out2, B)) : Result[Out2, B, X] - def flatMap[Out2, B](f : (Out, A) => Result[Out2, B, Nothing]) : Result[Out2, B, X] - def orElse[Out2 >: Out, B >: A](other : => Result[Out2, B, Nothing]) : Result[Out2, B, X] + def map[B](f: A => B): Result[Out, B, X] + def mapOut[Out2](f: Out => Out2): Result[Out2, A, X] + def map[Out2, B](f: (Out, A) => (Out2, B)): Result[Out2, B, X] + def flatMap[Out2, B](f: (Out, A) => Result[Out2, B, Nothing]): Result[Out2, B, X] + def orElse[Out2 >: Out, B >: A](other: => Result[Out2, B, Nothing]): Result[Out2, B, X] } -case class Success[+Out, +A](out : Out, value : A) extends Result[Out, A, Nothing] { +case class Success[+Out, +A](out: Out, value: A) extends Result[Out, A, Nothing] { def error = throw new ScalaSigParserError("No error") def toOption = Some(value) - def map[B](f : A => B) : Result[Out, B, Nothing] = Success(out, f(value)) - def mapOut[Out2](f : Out => Out2) : Result[Out2, A, Nothing] = Success(f(out), value) - def map[Out2, B](f : (Out, A) => (Out2, B)) : Success[Out2, B] = f(out, value) match { case (out2, b) => Success(out2, b) } - def flatMap[Out2, B](f : (Out, A) => Result[Out2, B, Nothing]) : Result[Out2, B, Nothing]= f(out, value) - def orElse[Out2 >: Out, B >: A](other : => Result[Out2, B, Nothing]) : Result[Out2, B, Nothing] = this + def map[B](f: A => B): Result[Out, B, Nothing] = Success(out, f(value)) + def mapOut[Out2](f: Out => Out2): Result[Out2, A, Nothing] = Success(f(out), value) + def map[Out2, B](f: (Out, A) => (Out2, B)): Success[Out2, B] = f(out, value) match { case (out2, b) => Success(out2, b) } + def flatMap[Out2, B](f: (Out, A) => Result[Out2, B, Nothing]): Result[Out2, B, Nothing]= f(out, value) + def orElse[Out2 >: Out, B >: A](other: => Result[Out2, B, Nothing]): Result[Out2, B, Nothing] = this } sealed abstract class NoSuccess[+X] extends Result[Nothing, Nothing, X] { @@ -53,11 +53,11 @@ sealed abstract class NoSuccess[+X] extends Result[Nothing, Nothing, X] { def toOption = None - def map[B](f : Nothing => B) = this - def mapOut[Out2](f : Nothing => Out2) = this - def map[Out2, B](f : (Nothing, Nothing) => (Out2, B)) = this - def flatMap[Out2, B](f : (Nothing, Nothing) => Result[Out2, B, Nothing]) = this - def orElse[Out2, B](other : => Result[Out2, B, Nothing]) = other + def map[B](f: Nothing => B) = this + def mapOut[Out2](f: Nothing => Out2) = this + def map[Out2, B](f: (Nothing, Nothing) => (Out2, B)) = this + def flatMap[Out2, B](f: (Nothing, Nothing) => Result[Out2, B, Nothing]) = this + def orElse[Out2, B](other: => Result[Out2, B, Nothing]) = other } case object Failure extends NoSuccess[Nothing] { @@ -66,5 +66,4 @@ case object Failure extends NoSuccess[Nothing] { case class ScalaSigParserError(msg: String) extends RuntimeException(msg) -case class Error[+X](error : X) extends NoSuccess[X] { -} +case class Error[+X](error: X) extends NoSuccess[X] diff --git a/src/scalap/scala/tools/scalap/rules/Rule.scala b/src/scalap/scala/tools/scalap/rules/Rule.scala index ccfdf7b8c1..0a00111f7a 100644 --- a/src/scalap/scala/tools/scalap/rules/Rule.scala +++ b/src/scalap/scala/tools/scalap/rules/Rule.scala @@ -24,138 +24,138 @@ package scala.tools.scalap.rules * Inspired by the Scala parser combinator. */ trait Rule[-In, +Out, +A, +X] extends (In => Result[Out, A, X]) { - val factory : Rules + val factory: Rules import factory._ - def as(name : String) = ruleWithName(name, this) + def as(name: String) = ruleWithName(name, this) - def flatMap[Out2, B, X2 >: X](fa2ruleb : A => Out => Result[Out2, B, X2]) = mapResult { + def flatMap[Out2, B, X2 >: X](fa2ruleb: A => Out => Result[Out2, B, X2]) = mapResult { case Success(out, a) => fa2ruleb(a)(out) case Failure => Failure case err @ Error(_) => err } - def map[B](fa2b : A => B) = flatMap { a => out => Success(out, fa2b(a)) } + def map[B](fa2b: A => B) = flatMap { a => out => Success(out, fa2b(a)) } - def filter(f : A => Boolean) = flatMap { a => out => if(f(a)) Success(out, a) else Failure } + def filter(f: A => Boolean) = flatMap { a => out => if(f(a)) Success(out, a) else Failure } - def mapResult[Out2, B, Y](f : Result[Out, A, X] => Result[Out2, B, Y]) = rule { - in : In => f(apply(in)) + def mapResult[Out2, B, Y](f: Result[Out, A, X] => Result[Out2, B, Y]) = rule { + in: In => f(apply(in)) } - def orElse[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other : => Rule[In2, Out2, A2, X2]) : Rule[In2, Out2, A2, X2] = new Choice[In2, Out2, A2, X2] { + def orElse[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other: => Rule[In2, Out2, A2, X2]): Rule[In2, Out2, A2, X2] = new Choice[In2, Out2, A2, X2] { val factory = Rule.this.factory lazy val choices = Rule.this :: other :: Nil } def orError[In2 <: In] = this orElse error[Any] - def |[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other : => Rule[In2, Out2, A2, X2]) = orElse(other) + def |[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other: => Rule[In2, Out2, A2, X2]) = orElse(other) - def ^^[B](fa2b : A => B) = map(fa2b) + def ^^[B](fa2b: A => B) = map(fa2b) - def ^^?[B](pf : PartialFunction[A, B]) = filter (pf.isDefinedAt(_)) ^^ pf + def ^^?[B](pf: PartialFunction[A, B]) = filter (pf.isDefinedAt(_)) ^^ pf - def ??(pf : PartialFunction[A, Any]) = filter (pf.isDefinedAt(_)) + def ??(pf: PartialFunction[A, Any]) = filter (pf.isDefinedAt(_)) - def -^[B](b : B) = map { any => b } + def -^[B](b: B) = map { any => b } /** Maps an Error */ - def !^[Y](fx2y : X => Y) = mapResult { + def !^[Y](fx2y: X => Y) = mapResult { case s @ Success(_, _) => s case Failure => Failure case Error(x) => Error(fx2y(x)) } - def >>[Out2, B, X2 >: X](fa2ruleb : A => Out => Result[Out2, B, X2]) = flatMap(fa2ruleb) + def >>[Out2, B, X2 >: X](fa2ruleb: A => Out => Result[Out2, B, X2]) = flatMap(fa2ruleb) - def >->[Out2, B, X2 >: X](fa2resultb : A => Result[Out2, B, X2]) = flatMap { a => any => fa2resultb(a) } + def >->[Out2, B, X2 >: X](fa2resultb: A => Result[Out2, B, X2]) = flatMap { a => any => fa2resultb(a) } - def >>?[Out2, B, X2 >: X](pf : PartialFunction[A, Rule[Out, Out2, B, X2]]) = filter(pf isDefinedAt _) flatMap pf + def >>?[Out2, B, X2 >: X](pf: PartialFunction[A, Rule[Out, Out2, B, X2]]) = filter(pf isDefinedAt _) flatMap pf - def >>&[B, X2 >: X](fa2ruleb : A => Out => Result[Any, B, X2]) = flatMap { a => out => fa2ruleb(a)(out) mapOut { any => out } } + def >>&[B, X2 >: X](fa2ruleb: A => Out => Result[Any, B, X2]) = flatMap { a => out => fa2ruleb(a)(out) mapOut { any => out } } - def ~[Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next) yield new ~(a, b) + def ~[Out2, B, X2 >: X](next: => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next) yield new ~(a, b) - def ~-[Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next) yield a + def ~-[Out2, B, X2 >: X](next: => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next) yield a - def -~[Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next) yield b + def -~[Out2, B, X2 >: X](next: => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next) yield b - def ~++[Out2, B >: A, X2 >: X](next : => Rule[Out, Out2, Seq[B], X2]) = for (a <- this; b <- next) yield a :: b.toList + def ~++[Out2, B >: A, X2 >: X](next: => Rule[Out, Out2, Seq[B], X2]) = for (a <- this; b <- next) yield a :: b.toList /** Apply the result of this rule to the function returned by the next rule */ - def ~>[Out2, B, X2 >: X](next : => Rule[Out, Out2, A => B, X2]) = for (a <- this; fa2b <- next) yield fa2b(a) + def ~>[Out2, B, X2 >: X](next: => Rule[Out, Out2, A => B, X2]) = for (a <- this; fa2b <- next) yield fa2b(a) /** Apply the result of this rule to the function returned by the previous rule */ - def <~:[InPrev, B, X2 >: X](prev : => Rule[InPrev, In, A => B, X2]) = for (fa2b <- prev; a <- this) yield fa2b(a) + def <~:[InPrev, B, X2 >: X](prev: => Rule[InPrev, In, A => B, X2]) = for (fa2b <- prev; a <- this) yield fa2b(a) - def ~![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next.orError) yield new ~(a, b) + def ~![Out2, B, X2 >: X](next: => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next.orError) yield new ~(a, b) - def ~-![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next.orError) yield a + def ~-![Out2, B, X2 >: X](next: => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next.orError) yield a - def -~![Out2, B, X2 >: X](next : => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next.orError) yield b + def -~![Out2, B, X2 >: X](next: => Rule[Out, Out2, B, X2]) = for (a <- this; b <- next.orError) yield b - def -[In2 <: In](exclude : => Rule[In2, Any, Any, Any]) = !exclude -~ this + def -[In2 <: In](exclude: => Rule[In2, Any, Any, Any]) = !exclude -~ this /** ^~^(f) is equivalent to ^^ { case b1 ~ b2 => f(b1, b2) } */ - def ^~^[B1, B2, B >: A <% B1 ~ B2, C](f : (B1, B2) => C) = map { a => - (a : B1 ~ B2) match { case b1 ~ b2 => f(b1, b2) } + def ^~^[B1, B2, B >: A <% B1 ~ B2, C](f: (B1, B2) => C) = map { a => + (a: B1 ~ B2) match { case b1 ~ b2 => f(b1, b2) } } /** ^~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 => f(b1, b2, b3) } */ - def ^~~^[B1, B2, B3, B >: A <% B1 ~ B2 ~ B3, C](f : (B1, B2, B3) => C) = map { a => - (a : B1 ~ B2 ~ B3) match { case b1 ~ b2 ~ b3 => f(b1, b2, b3) } + def ^~~^[B1, B2, B3, B >: A <% B1 ~ B2 ~ B3, C](f: (B1, B2, B3) => C) = map { a => + (a: B1 ~ B2 ~ B3) match { case b1 ~ b2 ~ b3 => f(b1, b2, b3) } } /** ^~~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 ~ b4 => f(b1, b2, b3, b4) } */ - def ^~~~^[B1, B2, B3, B4, B >: A <% B1 ~ B2 ~ B3 ~ B4, C](f : (B1, B2, B3, B4) => C) = map { a => - (a : B1 ~ B2 ~ B3 ~ B4) match { case b1 ~ b2 ~ b3 ~ b4 => f(b1, b2, b3, b4) } + def ^~~~^[B1, B2, B3, B4, B >: A <% B1 ~ B2 ~ B3 ~ B4, C](f: (B1, B2, B3, B4) => C) = map { a => + (a: B1 ~ B2 ~ B3 ~ B4) match { case b1 ~ b2 ~ b3 ~ b4 => f(b1, b2, b3, b4) } } /** ^~~~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 ~ b4 ~ b5 => f(b1, b2, b3, b4, b5) } */ - def ^~~~~^[B1, B2, B3, B4, B5, B >: A <% B1 ~ B2 ~ B3 ~ B4 ~ B5, C](f : (B1, B2, B3, B4, B5) => C) = map { a => - (a : B1 ~ B2 ~ B3 ~ B4 ~ B5) match { case b1 ~ b2 ~ b3 ~ b4 ~ b5 => f(b1, b2, b3, b4, b5) } + def ^~~~~^[B1, B2, B3, B4, B5, B >: A <% B1 ~ B2 ~ B3 ~ B4 ~ B5, C](f: (B1, B2, B3, B4, B5) => C) = map { a => + (a: B1 ~ B2 ~ B3 ~ B4 ~ B5) match { case b1 ~ b2 ~ b3 ~ b4 ~ b5 => f(b1, b2, b3, b4, b5) } } /** ^~~~~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 => f(b1, b2, b3, b4, b5, b6) } */ - def ^~~~~~^[B1, B2, B3, B4, B5, B6, B >: A <% B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6, C](f : (B1, B2, B3, B4, B5, B6) => C) = map { a => - (a : B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6) match { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 => f(b1, b2, b3, b4, b5, b6) } + def ^~~~~~^[B1, B2, B3, B4, B5, B6, B >: A <% B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6, C](f: (B1, B2, B3, B4, B5, B6) => C) = map { a => + (a: B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6) match { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 => f(b1, b2, b3, b4, b5, b6) } } /** ^~~~~~~^(f) is equivalent to ^^ { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 => f(b1, b2, b3, b4, b5, b6) } */ - def ^~~~~~~^[B1, B2, B3, B4, B5, B6, B7, B >: A <% B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6 ~ B7, C](f : (B1, B2, B3, B4, B5, B6, B7) => C) = map { a => - (a : B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6 ~ B7) match { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 ~b7 => f(b1, b2, b3, b4, b5, b6, b7) } + def ^~~~~~~^[B1, B2, B3, B4, B5, B6, B7, B >: A <% B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6 ~ B7, C](f: (B1, B2, B3, B4, B5, B6, B7) => C) = map { a => + (a: B1 ~ B2 ~ B3 ~ B4 ~ B5 ~ B6 ~ B7) match { case b1 ~ b2 ~ b3 ~ b4 ~ b5 ~ b6 ~b7 => f(b1, b2, b3, b4, b5, b6, b7) } } /** >~>(f) is equivalent to >> { case b1 ~ b2 => f(b1, b2) } */ - def >~>[Out2, B1, B2, B >: A <% B1 ~ B2, C, X2 >: X](f : (B1, B2) => Out => Result[Out2, C, X2]) = flatMap { a => - (a : B1 ~ B2) match { case b1 ~ b2 => f(b1, b2) } + def >~>[Out2, B1, B2, B >: A <% B1 ~ B2, C, X2 >: X](f: (B1, B2) => Out => Result[Out2, C, X2]) = flatMap { a => + (a: B1 ~ B2) match { case b1 ~ b2 => f(b1, b2) } } /** ^-^(f) is equivalent to ^^ { b2 => b1 => f(b1, b2) } */ - def ^-^ [B1, B2 >: A, C](f : (B1, B2) => C) = map { b2 : B2 => b1 : B1 => f(b1, b2) } + def ^-^ [B1, B2 >: A, C](f: (B1, B2) => C) = map { b2: B2 => b1: B1 => f(b1, b2) } /** ^~>~^(f) is equivalent to ^^ { case b2 ~ b3 => b1 => f(b1, b2, b3) } */ - def ^~>~^ [B1, B2, B3, B >: A <% B2 ~ B3, C](f : (B1, B2, B3) => C) = map { a => - (a : B2 ~ B3) match { case b2 ~ b3 => b1 : B1 => f(b1, b2, b3) } + def ^~>~^ [B1, B2, B3, B >: A <% B2 ~ B3, C](f: (B1, B2, B3) => C) = map { a => + (a: B2 ~ B3) match { case b2 ~ b3 => b1: B1 => f(b1, b2, b3) } } } trait Choice[-In, +Out, +A, +X] extends Rule[In, Out, A, X] { - def choices : List[Rule[In, Out, A, X]] + def choices: List[Rule[In, Out, A, X]] - def apply(in : In) = { - def oneOf(list : List[Rule[In, Out, A, X]]) : Result[Out, A, X] = list match { + def apply(in: In) = { + def oneOf(list: List[Rule[In, Out, A, X]]): Result[Out, A, X] = list match { case Nil => Failure case first :: rest => first(in) match { case Failure => oneOf(rest) @@ -165,7 +165,7 @@ trait Choice[-In, +Out, +A, +X] extends Rule[In, Out, A, X] { oneOf(choices) } - override def orElse[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other : => Rule[In2, Out2, A2, X2]) : Rule[In2, Out2, A2, X2] = new Choice[In2, Out2, A2, X2] { + override def orElse[In2 <: In, Out2 >: Out, A2 >: A, X2 >: X](other: => Rule[In2, Out2, A2, X2]): Rule[In2, Out2, A2, X2] = new Choice[In2, Out2, A2, X2] { val factory = Choice.this.factory lazy val choices = Choice.this.choices ::: other :: Nil } diff --git a/src/scalap/scala/tools/scalap/rules/Rules.scala b/src/scalap/scala/tools/scalap/rules/Rules.scala index 85a6b263de..bdcc81c22d 100644 --- a/src/scalap/scala/tools/scalap/rules/Rules.scala +++ b/src/scalap/scala/tools/scalap/rules/Rules.scala @@ -14,7 +14,7 @@ package scala.tools.scalap package rules trait Name { - def name : String + def name: String override def toString = name } @@ -27,16 +27,16 @@ trait Name { trait Rules { import scala.language.implicitConversions - implicit def rule[In, Out, A, X](f : In => Result[Out, A, X]) : Rule[In, Out, A, X] = new DefaultRule(f) - implicit def inRule[In, Out, A, X](rule : Rule[In, Out, A, X]) : InRule[In, Out, A, X] = new InRule(rule) - implicit def seqRule[In, A, X](rule : Rule[In, In, A, X]) : SeqRule[In, A, X] = new SeqRule(rule) + implicit def rule[In, Out, A, X](f: In => Result[Out, A, X]): Rule[In, Out, A, X] = new DefaultRule(f) + implicit def inRule[In, Out, A, X](rule: Rule[In, Out, A, X]): InRule[In, Out, A, X] = new InRule(rule) + implicit def seqRule[In, A, X](rule: Rule[In, In, A, X]): SeqRule[In, A, X] = new SeqRule(rule) trait FromRule[In] { - def apply[Out, A, X](f : In => Result[Out, A, X]): Rule[In, Out, A, X] + def apply[Out, A, X](f: In => Result[Out, A, X]): Rule[In, Out, A, X] } def from[In] = new FromRule[In] { - def apply[Out, A, X](f : In => Result[Out, A, X]) = rule(f) + def apply[Out, A, X](f: In => Result[Out, A, X]) = rule(f) } def state[s] = new StateRules { @@ -44,30 +44,30 @@ trait Rules { val factory = Rules.this } - def success[Out, A](out : Out, a : A) = rule { in : Any => Success(out, a) } + def success[Out, A](out: Out, a: A) = rule { in: Any => Success(out, a) } - def failure = rule { in : Any => Failure } + def failure = rule { in: Any => Failure } - def error[In] = rule { in : In => Error(in) } - def error[X](err : X) = rule { in : Any => Error(err) } + def error[In] = rule { in: In => Error(in) } + def error[X](err: X) = rule { in: Any => Error(err) } - def oneOf[In, Out, A, X](rules : Rule[In, Out, A, X] *) : Rule[In, Out, A, X] = new Choice[In, Out, A, X] { + def oneOf[In, Out, A, X](rules: Rule[In, Out, A, X] *): Rule[In, Out, A, X] = new Choice[In, Out, A, X] { val factory = Rules.this val choices = rules.toList } - def ruleWithName[In, Out, A, X](_name : String, f : In => Result[Out, A, X]) : Rule[In, Out, A, X] with Name = + def ruleWithName[In, Out, A, X](_name: String, f: In => Result[Out, A, X]): Rule[In, Out, A, X] with Name = new DefaultRule(f) with Name { val name = _name } - class DefaultRule[In, Out, A, X](f : In => Result[Out, A, X]) extends Rule[In, Out, A, X] { + class DefaultRule[In, Out, A, X](f: In => Result[Out, A, X]) extends Rule[In, Out, A, X] { val factory = Rules.this - def apply(in : In) = f(in) + def apply(in: In) = f(in) } /** Converts a rule into a function that throws an Exception on failure. */ - def expect[In, Out, A, Any](rule : Rule[In, Out, A, Any]) : In => A = (in) => rule(in) match { + def expect[In, Out, A, Any](rule: Rule[In, Out, A, Any]): In => A = (in) => rule(in) match { case Success(_, a) => a case Failure => throw new ScalaSigParserError("Unexpected failure") case Error(x) => throw new ScalaSigParserError("Unexpected error: " + x) @@ -86,30 +86,30 @@ trait StateRules { type S type Rule[+A, +X] = rules.Rule[S, S, A, X] - val factory : Rules + val factory: Rules import factory._ - def apply[A, X](f : S => Result[S, A, X]) = rule(f) + def apply[A, X](f: S => Result[S, A, X]) = rule(f) - def unit[A](a : => A) = apply { s => Success(s, a) } - def read[A](f : S => A) = apply { s => Success(s, f(s)) } + def unit[A](a: => A) = apply { s => Success(s, a) } + def read[A](f: S => A) = apply { s => Success(s, f(s)) } def get = apply { s => Success(s, s) } - def set(s : => S) = apply { oldS => Success(s, oldS) } + def set(s: => S) = apply { oldS => Success(s, oldS) } - def update(f : S => S) = apply { s => Success(s, f(s)) } + def update(f: S => S) = apply { s => Success(s, f(s)) } def nil = unit(Nil) def none = unit(None) /** Create a rule that identities if f(in) is true. */ - def cond(f : S => Boolean) = get filter f + def cond(f: S => Boolean) = get filter f /** Create a rule that succeeds if all of the given rules succeed. @param rules the rules to apply in sequence. */ - def allOf[A, X](rules : Seq[Rule[A, X]]) = { - def rep(in : S, rules : List[Rule[A, X]], results : List[A]) : Result[S, List[A], X] = { + def allOf[A, X](rules: Seq[Rule[A, X]]) = { + def rep(in: S, rules: List[Rule[A, X]], results: List[A]): Result[S, List[A], X] = { rules match { case Nil => Success(in, results.reverse) case rule::tl => rule(in) match { @@ -119,19 +119,19 @@ trait StateRules { } } } - in : S => rep(in, rules.toList, Nil) + in: S => rep(in, rules.toList, Nil) } /** Create a rule that succeeds with a list of all the provided rules that succeed. @param rules the rules to apply in sequence. */ - def anyOf[A, X](rules : Seq[Rule[A, X]]) = allOf(rules.map(_ ?)) ^^ { opts => opts.flatMap(x => x) } + def anyOf[A, X](rules: Seq[Rule[A, X]]) = allOf(rules.map(_ ?)) ^^ { opts => opts.flatMap(x => x) } /** Repeatedly apply a rule from initial value until finished condition is met. */ - def repeatUntil[T, X](rule : Rule[T => T, X])(finished : T => Boolean)(initial : T) = apply { + def repeatUntil[T, X](rule: Rule[T => T, X])(finished: T => Boolean)(initial: T) = apply { // more compact using HoF but written this way so it's tail-recursive - def rep(in : S, t : T) : Result[S, T, X] = { + def rep(in: S, t: T): Result[S, T, X] = { if (finished(t)) Success(in, t) else rule(in) match { case Success(out, f) => rep(out, f(t)) // SI-5189 f.asInstanceOf[T => T] diff --git a/src/scalap/scala/tools/scalap/rules/SeqRule.scala b/src/scalap/scala/tools/scalap/rules/SeqRule.scala index 2d62ee42e6..e96a38b6be 100644 --- a/src/scalap/scala/tools/scalap/rules/SeqRule.scala +++ b/src/scalap/scala/tools/scalap/rules/SeqRule.scala @@ -16,33 +16,33 @@ package scala.tools.scalap.rules * A workaround for the difficulties of dealing with * a contravariant 'In' parameter type... */ -class InRule[In, +Out, +A, +X](rule : Rule[In, Out, A, X]) { +class InRule[In, +Out, +A, +X](rule: Rule[In, Out, A, X]) { - def mapRule[Out2, B, Y](f : Result[Out, A, X] => In => Result[Out2, B, Y]) : Rule[In, Out2, B, Y] = rule.factory.rule { - in : In => f(rule(in))(in) + def mapRule[Out2, B, Y](f: Result[Out, A, X] => In => Result[Out2, B, Y]): Rule[In, Out2, B, Y] = rule.factory.rule { + in: In => f(rule(in))(in) } /** Creates a rule that succeeds only if the original rule would fail on the given context. */ def unary_! : Rule[In, In, Unit, Nothing] = mapRule { - case Success(_, _) => in : In => Failure - case _ => in : In => Success(in, ()) + case Success(_, _) => in: In => Failure + case _ => in: In => Success(in, ()) } /** Creates a rule that succeeds if the original rule succeeds, but returns the original input. */ def & : Rule[In, In, A, X] = mapRule { - case Success(_, a) => in : In => Success(in, a) - case Failure => in : In => Failure - case Error(x) => in : In => Error(x) + case Success(_, a) => in: In => Success(in, a) + case Failure => in: In => Failure + case Error(x) => in: In => Error(x) } } -class SeqRule[S, +A, +X](rule : Rule[S, S, A, X]) { +class SeqRule[S, +A, +X](rule: Rule[S, S, A, X]) { import rule.factory._ def ? = rule mapRule { - case Success(out, a) => in : S => Success(out, Some(a)) - case Failure => in : S => Success(in, None) - case Error(x) => in : S => Error(x) + case Success(out, a) => in: S => Success(out, Some(a)) + case Failure => in: S => Success(in, None) + case Error(x) => in: S => Error(x) } /** Creates a rule that always succeeds with a Boolean value. @@ -51,38 +51,38 @@ class SeqRule[S, +A, +X](rule : Rule[S, S, A, X]) { def * = from[S] { // tail-recursive function with reverse list accumulator - def rep(in : S, acc : List[A]) : Result[S, List[A], X] = rule(in) match { + def rep(in: S, acc: List[A]): Result[S, List[A], X] = rule(in) match { case Success(out, a) => rep(out, a :: acc) case Failure => Success(in, acc.reverse) - case err : Error[_] => err + case err: Error[_] => err } in => rep(in, Nil) } def + = rule ~++ * - def ~>?[B >: A, X2 >: X](f : => Rule[S, S, B => B, X2]) = for (a <- rule; fs <- f?) yield fs.foldLeft[B](a) { (b, f) => f(b) } + def ~>?[B >: A, X2 >: X](f: => Rule[S, S, B => B, X2]) = for (a <- rule; fs <- f?) yield fs.foldLeft[B](a) { (b, f) => f(b) } - def ~>*[B >: A, X2 >: X](f : => Rule[S, S, B => B, X2]) = for (a <- rule; fs <- f*) yield fs.foldLeft[B](a) { (b, f) => f(b) } + def ~>*[B >: A, X2 >: X](f: => Rule[S, S, B => B, X2]) = for (a <- rule; fs <- f*) yield fs.foldLeft[B](a) { (b, f) => f(b) } - def ~*~[B >: A, X2 >: X](join : => Rule[S, S, (B, B) => B, X2]) = { - this ~>* (for (f <- join; a <- rule) yield f(_ : B, a)) + def ~*~[B >: A, X2 >: X](join: => Rule[S, S, (B, B) => B, X2]) = { + this ~>* (for (f <- join; a <- rule) yield f(_: B, a)) } /** Repeats this rule one or more times with a separator (which is discarded) */ - def +/[X2 >: X](sep : => Rule[S, S, Any, X2]) = rule ~++ (sep -~ rule *) + def +/[X2 >: X](sep: => Rule[S, S, Any, X2]) = rule ~++ (sep -~ rule *) /** Repeats this rule zero or more times with a separator (which is discarded) */ - def */[X2 >: X](sep : => Rule[S, S, Any, X2]) = +/(sep) | state[S].nil + def */[X2 >: X](sep: => Rule[S, S, Any, X2]) = +/(sep) | state[S].nil - def *~-[Out, X2 >: X](end : => Rule[S, Out, Any, X2]) = (rule - end *) ~- end - def +~-[Out, X2 >: X](end : => Rule[S, Out, Any, X2]) = (rule - end +) ~- end + def *~-[Out, X2 >: X](end: => Rule[S, Out, Any, X2]) = (rule - end *) ~- end + def +~-[Out, X2 >: X](end: => Rule[S, Out, Any, X2]) = (rule - end +) ~- end /** Repeats this rule num times */ - def times(num : Int) : Rule[S, S, Seq[A], X] = from[S] { + def times(num: Int): Rule[S, S, Seq[A], X] = from[S] { val result = new scala.collection.mutable.ArraySeq[A](num) // more compact using HoF but written this way so it's tail-recursive - def rep(i : Int, in : S) : Result[S, Seq[A], X] = { + def rep(i: Int, in: S): Result[S, Seq[A], X] = { if (i == num) Success(in, result) else rule(in) match { case Success(out, a) => { @@ -90,7 +90,7 @@ class SeqRule[S, +A, +X](rule : Rule[S, S, A, X]) { rep(i + 1, out) } case Failure => Failure - case err : Error[_] => err + case err: Error[_] => err } } in => rep(0, in) diff --git a/src/scalap/scala/tools/scalap/scalasig/ClassFileParser.scala b/src/scalap/scala/tools/scalap/scalasig/ClassFileParser.scala index ed438be7f2..9bd8402ccc 100644 --- a/src/scalap/scala/tools/scalap/scalasig/ClassFileParser.scala +++ b/src/scalap/scala/tools/scalap/scalasig/ClassFileParser.scala @@ -3,9 +3,9 @@ package scala.tools.scalap.scalasig import scala.tools.scalap.rules.{ Success, Failure, ~, RulesWithState } object ByteCode { - def apply(bytes : Array[Byte]) = new ByteCode(bytes, 0, bytes.length) + def apply(bytes: Array[Byte]) = new ByteCode(bytes, 0, bytes.length) - def forClass(clazz : Class[_]) = { + def forClass(clazz: Class[_]) = { val name = clazz.getName val subPath = name.substring(name.lastIndexOf('.') + 1) + ".class" val in = clazz.getResourceAsStream(subPath) @@ -27,17 +27,17 @@ object ByteCode { } /** Represents a chunk of raw bytecode. Used as input for the parsers. */ -class ByteCode(val bytes : Array[Byte], val pos : Int, val length : Int) { +class ByteCode(val bytes: Array[Byte], val pos: Int, val length: Int) { assert(pos >= 0 && length >= 0 && pos + length <= bytes.length) def nextByte = if (length == 0) Failure else Success(drop(1), bytes(pos)) - def next(n : Int) = if (length >= n) Success(drop(n), take(n)) else Failure + def next(n: Int) = if (length >= n) Success(drop(n), take(n)) else Failure - def take(n : Int) = new ByteCode(bytes, pos, n) - def drop(n : Int) = new ByteCode(bytes, pos + n, length - n) + def take(n: Int) = new ByteCode(bytes, pos, n) + def drop(n: Int) = new ByteCode(bytes, pos + n, length - n) - def fold[X](x : X)(f : (X, Byte) => X) : X = { + def fold[X](x: X)(f: (X, Byte) => X): X = { var result = x var i = pos while (i < pos + length) { @@ -64,7 +64,7 @@ class ByteCode(val bytes : Array[Byte], val pos : Int, val length : Int) { StringBytesPair(str, chunk) } - def byte(i : Int) = bytes(pos) & 0xFF + def byte(i: Int) = bytes(pos) & 0xFF } /** @@ -84,11 +84,11 @@ trait ByteCodeReader extends RulesWithState { val u2 = bytes(2) ^^ (_.toInt) val u4 = bytes(4) ^^ (_.toInt) // should map to Long?? - def bytes(n : Int) = apply(_ next n) + def bytes(n: Int) = apply(_ next n) } object ClassFileParser extends ByteCodeReader { - def parse(byteCode : ByteCode) = expect(classFile)(byteCode) + def parse(byteCode: ByteCode) = expect(classFile)(byteCode) def parseAnnotations(byteCode: ByteCode) = expect(annotations)(byteCode) val magicNumber = (u4 filter (_ == 0xCAFEBABE)) | error("Not a valid class file") @@ -161,19 +161,19 @@ object ClassFileParser extends ByteCodeReader { val classFile = header ~ fields ~ methods ~ attributes ~- !u1 ^~~~^ ClassFile // TODO create a useful object, not just a string - def memberRef(description : String) = u2 ~ u2 ^^ add1 { + def memberRef(description: String) = u2 ~ u2 ^^ add1 { case classRef ~ nameAndTypeRef => pool => description + ": " + pool(classRef) + ", " + pool(nameAndTypeRef) } - def add1[T](f : T => ConstantPool => Any)(raw : T)(pool : ConstantPool) = pool add f(raw) - def add2[T](f : T => ConstantPool => Any)(raw : T)(pool : ConstantPool) = pool add f(raw) add { pool => "" } + def add1[T](f: T => ConstantPool => Any)(raw: T)(pool: ConstantPool) = pool add f(raw) + def add2[T](f: T => ConstantPool => Any)(raw: T)(pool: ConstantPool) = pool add f(raw) add { pool => "" } } case class ClassFile( - header : ClassFileHeader, - fields : Seq[Field], - methods : Seq[Method], - attributes : Seq[Attribute]) { + header: ClassFileHeader, + fields: Seq[Field], + methods: Seq[Method], + attributes: Seq[Attribute]) { def majorVersion = header.major def minorVersion = header.minor @@ -182,14 +182,14 @@ case class ClassFile( def superClass = constant(header.superClassIndex) def interfaces = header.interfaces.map(constant) - def constant(index : Int) = header.constants(index) match { + def constant(index: Int) = header.constants(index) match { case StringBytesPair(str, _) => str case z => z } def constantWrapped(index: Int) = header.constants(index) - def attribute(name : String) = attributes.find {attrib => constant(attrib.nameIndex) == name } + def attribute(name: String) = attributes.find {attrib => constant(attrib.nameIndex) == name } val RUNTIME_VISIBLE_ANNOTATIONS = "RuntimeVisibleAnnotations" def annotations = (attributes.find(attr => constant(attr.nameIndex) == RUNTIME_VISIBLE_ANNOTATIONS) @@ -198,23 +198,23 @@ case class ClassFile( def annotation(name: String) = annotations.flatMap(seq => seq.find(annot => constant(annot.typeIndex) == name)) } -case class Attribute(nameIndex : Int, byteCode : ByteCode) -case class Field(flags : Int, nameIndex : Int, descriptorIndex : Int, attributes : Seq[Attribute]) -case class Method(flags : Int, nameIndex : Int, descriptorIndex : Int, attributes : Seq[Attribute]) +case class Attribute(nameIndex: Int, byteCode: ByteCode) +case class Field(flags: Int, nameIndex: Int, descriptorIndex: Int, attributes: Seq[Attribute]) +case class Method(flags: Int, nameIndex: Int, descriptorIndex: Int, attributes: Seq[Attribute]) case class ClassFileHeader( - minor : Int, - major : Int, - constants : ConstantPool, - flags : Int, - classIndex : Int, - superClassIndex : Int, - interfaces : Seq[Int]) { - - def constant(index : Int) = constants(index) + minor: Int, + major: Int, + constants: ConstantPool, + flags: Int, + classIndex: Int, + superClassIndex: Int, + interfaces: Seq[Int]) { + + def constant(index: Int) = constants(index) } -case class ConstantPool(len : Int) { +case class ConstantPool(len: Int) { val size = len - 1 private val buffer = new scala.collection.mutable.ArrayBuffer[ConstantPool => Any] @@ -222,7 +222,7 @@ case class ConstantPool(len : Int) { def isFull = buffer.length >= size - def apply(index : Int) = { + def apply(index: Int) = { // Note constant pool indices are 1-based val i = index - 1 values(i) getOrElse { @@ -233,7 +233,7 @@ case class ConstantPool(len : Int) { } } - def add(f : ConstantPool => Any) = { + def add(f: ConstantPool => Any) = { buffer += f this } diff --git a/src/scalap/scala/tools/scalap/scalasig/Flags.scala b/src/scalap/scala/tools/scalap/scalasig/Flags.scala index de53b55b7e..b9925150d2 100644 --- a/src/scalap/scala/tools/scalap/scalasig/Flags.scala +++ b/src/scalap/scala/tools/scalap/scalasig/Flags.scala @@ -1,7 +1,7 @@ package scala.tools.scalap.scalasig trait Flags { - def hasFlag(flag : Long) : Boolean + def hasFlag(flag: Long): Boolean def isImplicit = hasFlag(0x00000001) def isFinal = hasFlag(0x00000002) diff --git a/src/scalap/scala/tools/scalap/scalasig/ScalaSig.scala b/src/scalap/scala/tools/scalap/scalasig/ScalaSig.scala index c32a3ff2d7..311e4acd6f 100644 --- a/src/scalap/scala/tools/scalap/scalasig/ScalaSig.scala +++ b/src/scalap/scala/tools/scalap/scalasig/ScalaSig.scala @@ -32,7 +32,7 @@ object ScalaSigParser { } } - def scalaSigFromAttribute(classFile: ClassFile) : Option[ScalaSig] = + def scalaSigFromAttribute(classFile: ClassFile): Option[ScalaSig] = classFile.attribute(Main.SCALA_SIG).map(_.byteCode).map(ScalaSigAttributeParsers.parse) def parse(classFile: ClassFile): Option[ScalaSig] = { @@ -46,7 +46,7 @@ object ScalaSigParser { } } - def parse(clazz : Class[_]): Option[ScalaSig] = { + def parse(clazz: Class[_]): Option[ScalaSig] = { val byteCode = ByteCode.forClass(clazz) val classFile = ClassFileParser.parse(byteCode) @@ -55,10 +55,10 @@ object ScalaSigParser { } object ScalaSigAttributeParsers extends ByteCodeReader { - def parse(byteCode : ByteCode) = expect(scalaSig)(byteCode) + def parse(byteCode: ByteCode) = expect(scalaSig)(byteCode) val nat = apply { - def natN(in : ByteCode, x : Int) : Result[ByteCode, Int, Nothing] = in.nextByte match { + def natN(in: ByteCode, x: Int): Result[ByteCode, Int, Nothing] = in.nextByte match { case Success(out, b) => { val y = (x << 7) + (b & 0x7f) if ((b & 0x80) == 0) Success(out, y) else natN(out, y) @@ -77,33 +77,33 @@ object ScalaSigAttributeParsers extends ByteCodeReader { val longValue = read(_ toLong) } -case class ScalaSig(majorVersion : Int, minorVersion : Int, table : Seq[Int ~ ByteCode]) extends DefaultMemoisable { +case class ScalaSig(majorVersion: Int, minorVersion: Int, table: Seq[Int ~ ByteCode]) extends DefaultMemoisable { - case class Entry(index : Int, entryType : Int, byteCode : ByteCode) extends DefaultMemoisable { + case class Entry(index: Int, entryType: Int, byteCode: ByteCode) extends DefaultMemoisable { def scalaSig = ScalaSig.this - def setByteCode(byteCode : ByteCode) = Entry(index, entryType, byteCode) + def setByteCode(byteCode: ByteCode) = Entry(index, entryType, byteCode) } - def hasEntry(index : Int) = table isDefinedAt index + def hasEntry(index: Int) = table isDefinedAt index - def getEntry(index : Int) = { + def getEntry(index: Int) = { val entryType ~ byteCode = table(index) Entry(index, entryType, byteCode) } - def parseEntry(index : Int) = applyRule(ScalaSigParsers.parseEntry(ScalaSigEntryParsers.entry)(index)) + def parseEntry(index: Int) = applyRule(ScalaSigParsers.parseEntry(ScalaSigEntryParsers.entry)(index)) - implicit def applyRule[A](parser : ScalaSigParsers.Parser[A]) = ScalaSigParsers.expect(parser)(this) + implicit def applyRule[A](parser: ScalaSigParsers.Parser[A]) = ScalaSigParsers.expect(parser)(this) override def toString = "ScalaSig version " + majorVersion + "." + minorVersion + { for (i <- 0 until table.size) yield i + ":\t" + parseEntry(i) // + "\n\t" + getEntry(i) }.mkString("\n", "\n", "") - lazy val symbols : Seq[Symbol] = ScalaSigParsers.symbols + lazy val symbols: Seq[Symbol] = ScalaSigParsers.symbols - lazy val topLevelClasses : List[ClassSymbol] = ScalaSigParsers.topLevelClasses - lazy val topLevelObjects : List[ObjectSymbol] = ScalaSigParsers.topLevelObjects + lazy val topLevelClasses: List[ClassSymbol] = ScalaSigParsers.topLevelClasses + lazy val topLevelObjects: List[ObjectSymbol] = ScalaSigParsers.topLevelObjects } object ScalaSigParsers extends RulesWithState with MemoisableRules { @@ -113,14 +113,14 @@ object ScalaSigParsers extends RulesWithState with MemoisableRules { val symTab = read(_.table) val size = symTab ^^ (_.size) - def entry(index : Int) = memo(("entry", index)) { + def entry(index: Int) = memo(("entry", index)) { cond(_ hasEntry index) -~ read(_ getEntry index) >-> { entry => Success(entry, entry.entryType) } } - def parseEntry[A](parser : ScalaSigEntryParsers.EntryParser[A])(index : Int) : Parser[A] = + def parseEntry[A](parser: ScalaSigEntryParsers.EntryParser[A])(index: Int): Parser[A] = entry(index) -~ parser >> { a => entry => Success(entry.scalaSig, a) } - def allEntries[A](f : ScalaSigEntryParsers.EntryParser[A]) = size >> { n => anyOf((0 until n) map parseEntry(f)) } + def allEntries[A](f: ScalaSigEntryParsers.EntryParser[A]) = size >> { n => anyOf((0 until n) map parseEntry(f)) } lazy val entries = allEntries(ScalaSigEntryParsers.entry) as "entries" lazy val symbols = allEntries(ScalaSigEntryParsers.symbol) as "symbols" @@ -137,20 +137,20 @@ object ScalaSigEntryParsers extends RulesWithState with MemoisableRules { type S = ScalaSig#Entry type EntryParser[A] = Rule[A, String] - implicit def byteCodeEntryParser[A](rule : ScalaSigAttributeParsers.Parser[A]) : EntryParser[A] = apply { entry => + implicit def byteCodeEntryParser[A](rule: ScalaSigAttributeParsers.Parser[A]): EntryParser[A] = apply { entry => rule(entry.byteCode) mapOut (entry setByteCode _) } - def toEntry[A](index : Int) = apply { sigEntry => ScalaSigParsers.entry(index)(sigEntry.scalaSig) } + def toEntry[A](index: Int) = apply { sigEntry => ScalaSigParsers.entry(index)(sigEntry.scalaSig) } - def parseEntry[A](parser : EntryParser[A])(index : Int) = (toEntry(index) -~ parser) + def parseEntry[A](parser: EntryParser[A])(index: Int) = (toEntry(index) -~ parser) - implicit def entryType(code : Int) = key filter (_ == code) + implicit def entryType(code: Int) = key filter (_ == code) val index = read(_.index) val key = read(_.entryType) - lazy val entry : EntryParser[Any] = symbol | typeEntry | literal | name | attributeInfo | annotInfo | children | get + lazy val entry: EntryParser[Any] = symbol | typeEntry | literal | name | attributeInfo | annotInfo | children | get val ref = byteCodeEntryParser(nat) @@ -159,7 +159,7 @@ object ScalaSigEntryParsers extends RulesWithState with MemoisableRules { val name = termName | typeName as "name" - def refTo[A](rule : EntryParser[A]) : EntryParser[A] = ref >>& parseEntry(rule) + def refTo[A](rule: EntryParser[A]): EntryParser[A] = ref >>& parseEntry(rule) lazy val nameRef = refTo(name) lazy val symbolRef = refTo(symbol) @@ -170,7 +170,7 @@ object ScalaSigEntryParsers extends RulesWithState with MemoisableRules { def symHeader(key: Int): EntryParser[Any] = (key -~ none | (key + 64) -~ nat) - def symbolEntry(key : Int) = symHeader(key) -~ symbolInfo + def symbolEntry(key: Int) = symHeader(key) -~ symbolInfo val noSymbol = 3 -^ NoSymbol val typeSymbol = symbolEntry(4) ^^ TypeSymbol as "typeSymbol" @@ -181,7 +181,7 @@ object ScalaSigEntryParsers extends RulesWithState with MemoisableRules { val extRef = 9 -~ nameRef ~ (symbolRef?) ~ get ^~~^ ExternalSymbol as "extRef" val extModClassRef = 10 -~ nameRef ~ (symbolRef?) ~ get ^~~^ ExternalSymbol as "extModClassRef" - lazy val symbol : EntryParser[Symbol] = oneOf( + lazy val symbol: EntryParser[Symbol] = oneOf( noSymbol, typeSymbol, aliasSymbol, @@ -196,7 +196,7 @@ object ScalaSigEntryParsers extends RulesWithState with MemoisableRules { val typeLevel = nat val typeIndex = nat - lazy val typeEntry : EntryParser[Type] = oneOf( + lazy val typeEntry: EntryParser[Type] = oneOf( 11 -^ NoType, 12 -^ NoPrefixType, 13 -~ symbolRef ^^ ThisType, @@ -237,17 +237,17 @@ object ScalaSigEntryParsers extends RulesWithState with MemoisableRules { lazy val topLevelClass = classSymbol filter isTopLevelClass lazy val topLevelObject = objectSymbol filter isTopLevel - def isTopLevel(symbol : Symbol) = symbol.parent match { - case Some(ext : ExternalSymbol) => true + def isTopLevel(symbol: Symbol) = symbol.parent match { + case Some(ext: ExternalSymbol) => true case _ => false } - def isTopLevelClass (symbol : Symbol) = !symbol.isModule && isTopLevel(symbol) + def isTopLevelClass (symbol: Symbol) = !symbol.isModule && isTopLevel(symbol) } -case class AttributeInfo(symbol : Symbol, typeRef : Type, value : Option[Any], values : Seq[String ~ Any]) // sym_Ref info_Ref {constant_Ref} {nameRef constantRef} -case class Children(symbolRefs : Seq[Int]) //sym_Ref {sym_Ref} +case class AttributeInfo(symbol: Symbol, typeRef: Type, value: Option[Any], values: Seq[String ~ Any]) // sym_Ref info_Ref {constant_Ref} {nameRef constantRef} +case class Children(symbolRefs: Seq[Int]) //sym_Ref {sym_Ref} -case class AnnotInfo(refs : Seq[Int]) // attarg_Ref {constant_Ref attarg_Ref} +case class AnnotInfo(refs: Seq[Int]) // attarg_Ref {constant_Ref attarg_Ref} /*************************************************** * | 49 TREE len_Nat 1 EMPTYtree diff --git a/src/scalap/scala/tools/scalap/scalasig/ScalaSigPrinter.scala b/src/scalap/scala/tools/scalap/scalasig/ScalaSigPrinter.scala index 01bef65fbe..5929e0f59f 100644 --- a/src/scalap/scala/tools/scalap/scalasig/ScalaSigPrinter.scala +++ b/src/scalap/scala/tools/scalap/scalasig/ScalaSigPrinter.scala @@ -133,7 +133,7 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) { print(" {") //Print class selftype c.selfType match { - case Some(t: Type) => print("\n"); print(" this : " + toString(t) + " =>") + case Some(t: Type) => print("\n"); print(" this: " + toString(t) + " =>") case None => } print("\n") @@ -188,7 +188,7 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) { def _pmt(mt: MethodType) = { val paramEntries = mt.paramSymbols.map({ - case ms: MethodSymbol => ms.name + " : " + toString(ms.infoType)(TypeFlags(true)) + case ms: MethodSymbol => ms.name + ": " + toString(ms.infoType)(TypeFlags(true)) case _ => "^___^" }) val implicitWord = mt.paramSymbols.headOption match { @@ -203,21 +203,21 @@ class ScalaSigPrinter(stream: PrintStream, printPrivates: Boolean) { mt.resultType match { case mt: MethodType => printMethodType(mt, printResult)({}) case x => if (printResult) { - print(" : "); + print(": "); printType(x) } } } t match { - case NullaryMethodType(resType) => if (printResult) { print(" : "); printType(resType) } + case NullaryMethodType(resType) => if (printResult) { print(": "); printType(resType) } case mt@MethodType(resType, paramSymbols) => _pmt(mt) case pt@PolyType(mt, typeParams) => { print(typeParamString(typeParams)) printMethodType(mt, printResult)({}) } //todo consider another method types - case x => print(" : "); printType(x) + case x => print(": "); printType(x) } // Print rest of the symbol output diff --git a/src/scalap/scala/tools/scalap/scalasig/Symbol.scala b/src/scalap/scala/tools/scalap/scalasig/Symbol.scala index dd766a6331..0656938150 100644 --- a/src/scalap/scala/tools/scalap/scalasig/Symbol.scala +++ b/src/scalap/scala/tools/scalap/scalasig/Symbol.scala @@ -3,39 +3,39 @@ package scala.tools.scalap.scalasig import ScalaSigEntryParsers._ trait Symbol extends Flags { - def name : String - def parent : Option[Symbol] - def children : Seq[Symbol] + def name: String + def parent: Option[Symbol] + def children: Seq[Symbol] - def path : String = parent.map(_.path + ".").getOrElse("") + name + def path: String = parent.map(_.path + ".").getOrElse("") + name } case object NoSymbol extends Symbol { def name = "" def parent = None - def hasFlag(flag : Long) = false + def hasFlag(flag: Long) = false def children = Nil } abstract class ScalaSigSymbol extends Symbol { - def applyRule[A](rule : EntryParser[A]) : A = expect(rule)(entry) - def applyScalaSigRule[A](rule : ScalaSigParsers.Parser[A]) = ScalaSigParsers.expect(rule)(entry.scalaSig) + def applyRule[A](rule: EntryParser[A]): A = expect(rule)(entry) + def applyScalaSigRule[A](rule: ScalaSigParsers.Parser[A]) = ScalaSigParsers.expect(rule)(entry.scalaSig) - def entry : ScalaSig#Entry + def entry: ScalaSig#Entry def index = entry.index - lazy val children : Seq[Symbol] = applyScalaSigRule(ScalaSigParsers.symbols) filter (_.parent == Some(this)) - lazy val attributes : Seq[AttributeInfo] = applyScalaSigRule(ScalaSigParsers.attributes) filter (_.symbol == this) + lazy val children: Seq[Symbol] = applyScalaSigRule(ScalaSigParsers.symbols) filter (_.parent == Some(this)) + lazy val attributes: Seq[AttributeInfo] = applyScalaSigRule(ScalaSigParsers.attributes) filter (_.symbol == this) } -case class ExternalSymbol(name : String, parent : Option[Symbol], entry : ScalaSig#Entry) extends ScalaSigSymbol { +case class ExternalSymbol(name: String, parent: Option[Symbol], entry: ScalaSig#Entry) extends ScalaSigSymbol { override def toString = path - def hasFlag(flag : Long) = false + def hasFlag(flag: Long) = false } -case class SymbolInfo(name : String, owner : Symbol, flags : Int, privateWithin : Option[AnyRef], info : Int, entry : ScalaSig#Entry) { - def symbolString(any : AnyRef) = any match { - case sym : SymbolInfoSymbol => sym.index.toString +case class SymbolInfo(name: String, owner: Symbol, flags: Int, privateWithin: Option[AnyRef], info: Int, entry: ScalaSig#Entry) { + def symbolString(any: AnyRef) = any match { + case sym: SymbolInfoSymbol => sym.index.toString case other => other.toString } @@ -46,25 +46,25 @@ case class SymbolInfo(name : String, owner : Symbol, flags : Int, privateWithin } abstract class SymbolInfoSymbol extends ScalaSigSymbol { - def symbolInfo : SymbolInfo + def symbolInfo: SymbolInfo def entry = symbolInfo.entry def name = symbolInfo.name def parent = Some(symbolInfo.owner) - def hasFlag(flag : Long) = (symbolInfo.flags & flag) != 0L + def hasFlag(flag: Long) = (symbolInfo.flags & flag) != 0L lazy val infoType = applyRule(parseEntry(typeEntry)(symbolInfo.info)) } -case class TypeSymbol(symbolInfo : SymbolInfo) extends SymbolInfoSymbol{ +case class TypeSymbol(symbolInfo: SymbolInfo) extends SymbolInfoSymbol{ override def path = name } -case class AliasSymbol(symbolInfo : SymbolInfo) extends SymbolInfoSymbol{ +case class AliasSymbol(symbolInfo: SymbolInfo) extends SymbolInfoSymbol{ override def path = name } -case class ClassSymbol(symbolInfo : SymbolInfo, thisTypeRef : Option[Int]) extends SymbolInfoSymbol { +case class ClassSymbol(symbolInfo: SymbolInfo, thisTypeRef: Option[Int]) extends SymbolInfoSymbol { lazy val selfType = thisTypeRef.map{(x: Int) => applyRule(parseEntry(typeEntry)(x))} } -case class ObjectSymbol(symbolInfo : SymbolInfo) extends SymbolInfoSymbol -case class MethodSymbol(symbolInfo : SymbolInfo, aliasRef : Option[Int]) extends SymbolInfoSymbol +case class ObjectSymbol(symbolInfo: SymbolInfo) extends SymbolInfoSymbol +case class MethodSymbol(symbolInfo: SymbolInfo, aliasRef: Option[Int]) extends SymbolInfoSymbol diff --git a/src/scalap/scala/tools/scalap/scalasig/Type.scala b/src/scalap/scala/tools/scalap/scalasig/Type.scala index cad4ea4446..97dc28d223 100644 --- a/src/scalap/scala/tools/scalap/scalasig/Type.scala +++ b/src/scalap/scala/tools/scalap/scalasig/Type.scala @@ -5,18 +5,18 @@ abstract class Type case object NoType extends Type case object NoPrefixType extends Type -case class ThisType(symbol : Symbol) extends Type -case class SingleType(typeRef : Type, symbol : Symbol) extends Type -case class ConstantType(constant : Any) extends Type -case class TypeRefType(prefix : Type, symbol : Symbol, typeArgs : Seq[Type]) extends Type -case class TypeBoundsType(lower : Type, upper : Type) extends Type -case class RefinedType(classSym : Symbol, typeRefs : List[Type]) extends Type -case class ClassInfoType(symbol : Symbol, typeRefs : Seq[Type]) extends Type -case class ClassInfoTypeWithCons(symbol : Symbol, typeRefs : Seq[Type], cons: String) extends Type -case class MethodType(resultType : Type, paramSymbols : Seq[Symbol]) extends Type -case class NullaryMethodType(resultType : Type) extends Type -case class PolyType(typeRef : Type, symbols : Seq[TypeSymbol]) extends Type -case class PolyTypeWithCons(typeRef : Type, symbols : Seq[TypeSymbol], cons: String) extends Type -case class AnnotatedType(typeRef : Type, attribTreeRefs : List[Int]) extends Type -case class AnnotatedWithSelfType(typeRef : Type, symbol : Symbol, attribTreeRefs : List[Int]) extends Type -case class ExistentialType(typeRef : Type, symbols : Seq[Symbol]) extends Type +case class ThisType(symbol: Symbol) extends Type +case class SingleType(typeRef: Type, symbol: Symbol) extends Type +case class ConstantType(constant: Any) extends Type +case class TypeRefType(prefix: Type, symbol: Symbol, typeArgs: Seq[Type]) extends Type +case class TypeBoundsType(lower: Type, upper: Type) extends Type +case class RefinedType(classSym: Symbol, typeRefs: List[Type]) extends Type +case class ClassInfoType(symbol: Symbol, typeRefs: Seq[Type]) extends Type +case class ClassInfoTypeWithCons(symbol: Symbol, typeRefs: Seq[Type], cons: String) extends Type +case class MethodType(resultType: Type, paramSymbols: Seq[Symbol]) extends Type +case class NullaryMethodType(resultType: Type) extends Type +case class PolyType(typeRef: Type, symbols: Seq[TypeSymbol]) extends Type +case class PolyTypeWithCons(typeRef: Type, symbols: Seq[TypeSymbol], cons: String) extends Type +case class AnnotatedType(typeRef: Type, attribTreeRefs: List[Int]) extends Type +case class AnnotatedWithSelfType(typeRef: Type, symbol: Symbol, attribTreeRefs: List[Int]) extends Type +case class ExistentialType(typeRef: Type, symbols: Seq[Symbol]) extends Type diff --git a/test/files/scalap/abstractClass.check b/test/files/scalap/abstractClass.check index ef1daac23d..95e80ac3c9 100644 --- a/test/files/scalap/abstractClass.check +++ b/test/files/scalap/abstractClass.check @@ -1,4 +1,4 @@ abstract class AbstractClass extends scala.AnyRef { def this() = { /* compiled code */ } - def foo : scala.Predef.String + def foo: scala.Predef.String } diff --git a/test/files/scalap/abstractMethod.check b/test/files/scalap/abstractMethod.check index 40fa02d408..0d0b1b7421 100644 --- a/test/files/scalap/abstractMethod.check +++ b/test/files/scalap/abstractMethod.check @@ -1,5 +1,5 @@ trait AbstractMethod extends scala.AnyRef { - def $init$() : scala.Unit = { /* compiled code */ } - def arity : scala.Int - def isCool : scala.Boolean = { /* compiled code */ } + def $init$(): scala.Unit = { /* compiled code */ } + def arity: scala.Int + def isCool: scala.Boolean = { /* compiled code */ } } diff --git a/test/files/scalap/caseClass.check b/test/files/scalap/caseClass.check index 7d7aa4fd8f..51ad90d9b2 100644 --- a/test/files/scalap/caseClass.check +++ b/test/files/scalap/caseClass.check @@ -1,20 +1,20 @@ -case class CaseClass[A <: scala.Seq[scala.Int]](i : A, s : scala.Predef.String) extends scala.AnyRef with scala.Product with scala.Serializable { - val i : A = { /* compiled code */ } - val s : scala.Predef.String = { /* compiled code */ } - def foo : scala.Int = { /* compiled code */ } - def copy[A <: scala.Seq[scala.Int]](i : A, s : scala.Predef.String) : CaseClass[A] = { /* compiled code */ } - override def productPrefix : java.lang.String = { /* compiled code */ } - def productArity : scala.Int = { /* compiled code */ } - def productElement(x$1 : scala.Int) : scala.Any = { /* compiled code */ } - override def productIterator : scala.collection.Iterator[scala.Any] = { /* compiled code */ } - def canEqual(x$1 : scala.Any) : scala.Boolean = { /* compiled code */ } - override def hashCode() : scala.Int = { /* compiled code */ } - override def toString() : java.lang.String = { /* compiled code */ } - override def equals(x$1 : scala.Any) : scala.Boolean = { /* compiled code */ } +case class CaseClass[A <: scala.Seq[scala.Int]](i: A, s: scala.Predef.String) extends scala.AnyRef with scala.Product with scala.Serializable { + val i: A = { /* compiled code */ } + val s: scala.Predef.String = { /* compiled code */ } + def foo: scala.Int = { /* compiled code */ } + def copy[A <: scala.Seq[scala.Int]](i: A, s: scala.Predef.String): CaseClass[A] = { /* compiled code */ } + override def productPrefix: java.lang.String = { /* compiled code */ } + def productArity: scala.Int = { /* compiled code */ } + def productElement(x$1: scala.Int): scala.Any = { /* compiled code */ } + override def productIterator: scala.collection.Iterator[scala.Any] = { /* compiled code */ } + def canEqual(x$1: scala.Any): scala.Boolean = { /* compiled code */ } + override def hashCode(): scala.Int = { /* compiled code */ } + override def toString(): java.lang.String = { /* compiled code */ } + override def equals(x$1: scala.Any): scala.Boolean = { /* compiled code */ } } object CaseClass extends scala.AnyRef with scala.Serializable { def this() = { /* compiled code */ } - final override def toString() : java.lang.String = { /* compiled code */ } - def apply[A <: scala.Seq[scala.Int]](i : A, s : scala.Predef.String) : CaseClass[A] = { /* compiled code */ } - def unapply[A <: scala.Seq[scala.Int]](x$0 : CaseClass[A]) : scala.Option[scala.Tuple2[A, scala.Predef.String]] = { /* compiled code */ } + final override def toString(): java.lang.String = { /* compiled code */ } + def apply[A <: scala.Seq[scala.Int]](i: A, s: scala.Predef.String): CaseClass[A] = { /* compiled code */ } + def unapply[A <: scala.Seq[scala.Int]](x$0: CaseClass[A]): scala.Option[scala.Tuple2[A, scala.Predef.String]] = { /* compiled code */ } } diff --git a/test/files/scalap/caseObject.check b/test/files/scalap/caseObject.check index 867a4b2162..a342e5ff1a 100644 --- a/test/files/scalap/caseObject.check +++ b/test/files/scalap/caseObject.check @@ -1,10 +1,10 @@ case object CaseObject extends scala.AnyRef with scala.Product with scala.Serializable { - def bar : scala.Int = { /* compiled code */ } - override def productPrefix : java.lang.String = { /* compiled code */ } - def productArity : scala.Int = { /* compiled code */ } - def productElement(x$1 : scala.Int) : scala.Any = { /* compiled code */ } - override def productIterator : scala.collection.Iterator[scala.Any] = { /* compiled code */ } - def canEqual(x$1 : scala.Any) : scala.Boolean = { /* compiled code */ } - override def hashCode() : scala.Int = { /* compiled code */ } - override def toString() : java.lang.String = { /* compiled code */ } + def bar: scala.Int = { /* compiled code */ } + override def productPrefix: java.lang.String = { /* compiled code */ } + def productArity: scala.Int = { /* compiled code */ } + def productElement(x$1: scala.Int): scala.Any = { /* compiled code */ } + override def productIterator: scala.collection.Iterator[scala.Any] = { /* compiled code */ } + def canEqual(x$1: scala.Any): scala.Boolean = { /* compiled code */ } + override def hashCode(): scala.Int = { /* compiled code */ } + override def toString(): java.lang.String = { /* compiled code */ } } diff --git a/test/files/scalap/cbnParam.check b/test/files/scalap/cbnParam.check index 52ecb6ae66..abe01297b9 100644 --- a/test/files/scalap/cbnParam.check +++ b/test/files/scalap/cbnParam.check @@ -1,3 +1,3 @@ class CbnParam extends scala.AnyRef { - def this(s : => scala.Predef.String) = { /* compiled code */ } + def this(s: => scala.Predef.String) = { /* compiled code */ } } diff --git a/test/files/scalap/classPrivate.check b/test/files/scalap/classPrivate.check index ab2d40cdaf..cf0ffe0cb2 100644 --- a/test/files/scalap/classPrivate.check +++ b/test/files/scalap/classPrivate.check @@ -1,10 +1,10 @@ class ClassPrivate extends scala.AnyRef { def this() = { /* compiled code */ } - def baz : scala.Int = { /* compiled code */ } + def baz: scala.Int = { /* compiled code */ } class Outer extends scala.AnyRef { def this() = { /* compiled code */ } - private[ClassPrivate] def qux : scala.Int = { /* compiled code */ } + private[ClassPrivate] def qux: scala.Int = { /* compiled code */ } } - protected def quux : scala.Int = { /* compiled code */ } - private[ClassPrivate] def bar : scala.Int = { /* compiled code */ } + protected def quux: scala.Int = { /* compiled code */ } + private[ClassPrivate] def bar: scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/classWithExistential.check b/test/files/scalap/classWithExistential.check index caee3fd6de..7df6bfb765 100644 --- a/test/files/scalap/classWithExistential.check +++ b/test/files/scalap/classWithExistential.check @@ -1,4 +1,4 @@ class ClassWithExistential extends scala.AnyRef { def this() = { /* compiled code */ } - def foo[A, B] : scala.Function1[A, B forSome {type A <: scala.Seq[scala.Int]; type B >: scala.Predef.String}] = { /* compiled code */ } + def foo[A, B]: scala.Function1[A, B forSome {type A <: scala.Seq[scala.Int]; type B >: scala.Predef.String}] = { /* compiled code */ } } diff --git a/test/files/scalap/classWithSelfAnnotation.check b/test/files/scalap/classWithSelfAnnotation.check index 82bbd9e8df..7a1c206e33 100644 --- a/test/files/scalap/classWithSelfAnnotation.check +++ b/test/files/scalap/classWithSelfAnnotation.check @@ -1,5 +1,5 @@ class ClassWithSelfAnnotation extends scala.AnyRef { - this : ClassWithSelfAnnotation with java.lang.CharSequence => + this: ClassWithSelfAnnotation with java.lang.CharSequence => def this() = { /* compiled code */ } - def foo : scala.Int = { /* compiled code */ } + def foo: scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/covariantParam.check b/test/files/scalap/covariantParam.check index f7a3c98966..85b1400fce 100644 --- a/test/files/scalap/covariantParam.check +++ b/test/files/scalap/covariantParam.check @@ -1,4 +1,4 @@ class CovariantParam[+A] extends scala.AnyRef { def this() = { /* compiled code */ } - def foo[A](a : A) : scala.Int = { /* compiled code */ } + def foo[A](a: A): scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/defaultParameter.check b/test/files/scalap/defaultParameter.check index 0c775ea7b5..4e244d18f1 100644 --- a/test/files/scalap/defaultParameter.check +++ b/test/files/scalap/defaultParameter.check @@ -1,3 +1,3 @@ trait DefaultParameter extends scala.AnyRef { - def foo(s : scala.Predef.String) : scala.Unit + def foo(s: scala.Predef.String): scala.Unit } diff --git a/test/files/scalap/implicitParam.check b/test/files/scalap/implicitParam.check index a2cfd6092d..46e995652e 100644 --- a/test/files/scalap/implicitParam.check +++ b/test/files/scalap/implicitParam.check @@ -1,4 +1,4 @@ class ImplicitParam extends scala.AnyRef { def this() = { /* compiled code */ } - def foo(i : scala.Int)(implicit f : scala.Float, d : scala.Double) : scala.Int = { /* compiled code */ } + def foo(i: scala.Int)(implicit f: scala.Float, d: scala.Double): scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/packageObject.check b/test/files/scalap/packageObject.check index 5732d92958..d1d0bbf122 100644 --- a/test/files/scalap/packageObject.check +++ b/test/files/scalap/packageObject.check @@ -1,5 +1,5 @@ package object PackageObject extends scala.AnyRef { def this() = { /* compiled code */ } type A = scala.Predef.String - def foo(i : scala.Int) : scala.Int = { /* compiled code */ } + def foo(i: scala.Int): scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/paramClauses.check b/test/files/scalap/paramClauses.check index 3a141e8faf..11c5e4bbd6 100644 --- a/test/files/scalap/paramClauses.check +++ b/test/files/scalap/paramClauses.check @@ -1,4 +1,4 @@ class ParamClauses extends scala.AnyRef { def this() = { /* compiled code */ } - def foo(i : scala.Int)(s : scala.Predef.String)(t : scala.Double) : scala.Int = { /* compiled code */ } + def foo(i: scala.Int)(s: scala.Predef.String)(t: scala.Double): scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/paramNames.check b/test/files/scalap/paramNames.check index 85e37f858d..836b3d0e7b 100644 --- a/test/files/scalap/paramNames.check +++ b/test/files/scalap/paramNames.check @@ -1,4 +1,4 @@ class ParamNames extends scala.AnyRef { def this() = { /* compiled code */ } - def foo(s : => scala.Seq[scala.Int], s2 : => scala.Seq[scala.Any]) : scala.Unit = { /* compiled code */ } + def foo(s: => scala.Seq[scala.Int], s2: => scala.Seq[scala.Any]): scala.Unit = { /* compiled code */ } } diff --git a/test/files/scalap/sequenceParam.check b/test/files/scalap/sequenceParam.check index 142d92fea3..f7bf83f6b2 100644 --- a/test/files/scalap/sequenceParam.check +++ b/test/files/scalap/sequenceParam.check @@ -1,3 +1,3 @@ class SequenceParam extends scala.AnyRef { - def this(s : scala.Predef.String, i : scala.Int*) = { /* compiled code */ } + def this(s: scala.Predef.String, i: scala.Int*) = { /* compiled code */ } } diff --git a/test/files/scalap/simpleClass.check b/test/files/scalap/simpleClass.check index 4fdf25d1cf..4675cbf665 100644 --- a/test/files/scalap/simpleClass.check +++ b/test/files/scalap/simpleClass.check @@ -1,4 +1,4 @@ class SimpleClass extends scala.AnyRef { def this() = { /* compiled code */ } - def foo : scala.Int = { /* compiled code */ } + def foo: scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/traitObject.check b/test/files/scalap/traitObject.check index 104ba14f1a..f7ae4fd2f4 100644 --- a/test/files/scalap/traitObject.check +++ b/test/files/scalap/traitObject.check @@ -1,8 +1,8 @@ trait TraitObject extends scala.AnyRef { - def $init$() : scala.Unit = { /* compiled code */ } - def foo : scala.Int = { /* compiled code */ } + def $init$(): scala.Unit = { /* compiled code */ } + def foo: scala.Int = { /* compiled code */ } } object TraitObject extends scala.AnyRef { def this() = { /* compiled code */ } - def bar : scala.Int = { /* compiled code */ } + def bar: scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/typeAnnotations.check b/test/files/scalap/typeAnnotations.check index 407b0235c6..cba69f8e41 100644 --- a/test/files/scalap/typeAnnotations.check +++ b/test/files/scalap/typeAnnotations.check @@ -1,8 +1,8 @@ abstract class TypeAnnotations[@scala.specialized R] extends scala.AnyRef { def this() = { /* compiled code */ } @scala.specialized - val x : scala.Int = { /* compiled code */ } + val x: scala.Int = { /* compiled code */ } @scala.specialized type T - def compose[@scala.specialized A](x : A, y : R) : A = { /* compiled code */ } + def compose[@scala.specialized A](x: A, y: R): A = { /* compiled code */ } } diff --git a/test/files/scalap/valAndVar.check b/test/files/scalap/valAndVar.check index e940da9801..98eae5192d 100644 --- a/test/files/scalap/valAndVar.check +++ b/test/files/scalap/valAndVar.check @@ -1,5 +1,5 @@ class ValAndVar extends scala.AnyRef { def this() = { /* compiled code */ } - val foo : java.lang.String = { /* compiled code */ } - var bar : scala.Int = { /* compiled code */ } + val foo: java.lang.String = { /* compiled code */ } + var bar: scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/wildcardType.check b/test/files/scalap/wildcardType.check index e43261db32..6ea696647e 100644 --- a/test/files/scalap/wildcardType.check +++ b/test/files/scalap/wildcardType.check @@ -1,3 +1,3 @@ class WildcardType extends scala.AnyRef { - def this(f : scala.Function1[scala.Int, _]) = { /* compiled code */ } + def this(f: scala.Function1[scala.Int, _]) = { /* compiled code */ } } -- cgit v1.2.3