diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/ByteCode.scala | 10 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/util/ShowPickled.scala | 26 | ||||
-rw-r--r-- | src/scalap/scala/tools/scalap/Classfile.scala | 1 | ||||
-rw-r--r-- | src/scalap/scala/tools/scalap/Decode.scala | 12 |
4 files changed, 40 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/ByteCode.scala b/src/compiler/scala/tools/nsc/interpreter/ByteCode.scala index dc4e173fff..4b8e0ae60c 100644 --- a/src/compiler/scala/tools/nsc/interpreter/ByteCode.scala +++ b/src/compiler/scala/tools/nsc/interpreter/ByteCode.scala @@ -29,6 +29,16 @@ object ByteCode { method.invoke(module, _: String).asInstanceOf[Option[Map[String, String]]] } + /** Scala sig bytes. + */ + def scalaSigBytesForPath(path: String) = + for { + module <- DECODER + method <- decoderMethod("scalaSigBytes", classOf[String]) + names <- method.invoke(module, path).asInstanceOf[Option[Array[Byte]]] + } + yield names + /** Attempts to retrieve case parameter names for given class name. */ def caseParamNamesForPath(path: String) = diff --git a/src/compiler/scala/tools/nsc/util/ShowPickled.scala b/src/compiler/scala/tools/nsc/util/ShowPickled.scala index f99f63dcda..20ae9c7eeb 100644 --- a/src/compiler/scala/tools/nsc/util/ShowPickled.scala +++ b/src/compiler/scala/tools/nsc/util/ShowPickled.scala @@ -14,6 +14,7 @@ import java.lang.Double.longBitsToDouble import symtab.{Flags, Names} import symtab.classfile.{PickleBuffer, PickleFormat} +import interpreter.ByteCode.scalaSigBytesForPath object ShowPickled extends Names { @@ -193,17 +194,26 @@ object ShowPickled extends Names { for (i <- 0 until index.length) printEntry(i) } - def main(args: Array[String]) { - val file = new File(args(0)) + def fromBytes(what: String, data: => Array[Byte]): Boolean = { try { - val stream = new FileInputStream(file) - val data = new Array[Byte](stream.available()) - stream.read(data) val pickle = new PickleBuffer(data, 0, data.length) + Console.println(what + ": ") printFile(pickle, Console.out) - } catch { - case ex: IOException => - Console.println("cannot read " + file + ": " + ex.getMessage()) + true + } + catch { + case _: Exception => false + } + } + + def fromFile(path: String) = fromBytes(path, io.File(path).toByteArray) + def fromName(name: String) = fromBytes(name, scalaSigBytesForPath(name) getOrElse Array()) + + def main(args: Array[String]) { + args foreach { arg => + val res = fromFile(arg) || fromName(arg) + if (!res) + Console.println("Cannot read " + arg) } } } diff --git a/src/scalap/scala/tools/scalap/Classfile.scala b/src/scalap/scala/tools/scalap/Classfile.scala index 44f687bd85..c4f273c5aa 100644 --- a/src/scalap/scala/tools/scalap/Classfile.scala +++ b/src/scalap/scala/tools/scalap/Classfile.scala @@ -26,6 +26,7 @@ class Classfile(in: ByteArrayReader) { val fields = readMembers(true) val methods = readMembers(false) val attribs = readAttribs + def scalaSigAttribute = attribs find (_.toString == Main.SCALA_SIG) def readAttribs = { val n = in.nextChar diff --git a/src/scalap/scala/tools/scalap/Decode.scala b/src/scalap/scala/tools/scalap/Decode.scala index 04d72c015b..6e55558249 100644 --- a/src/scalap/scala/tools/scalap/Decode.scala +++ b/src/scalap/scala/tools/scalap/Decode.scala @@ -10,7 +10,8 @@ package scala.tools.scalap import scala.tools.scalap.scalax.rules.scalasig._ -import scala.tools.nsc.util.ScalaClassLoader.getSystemLoader +import scala.tools.nsc.util.ScalaClassLoader.{ getSystemLoader, findBytesForClassName } +import Main.SCALA_SIG /** Temporary decoder. This would be better off in the scala.tools.nsc * but right now the compiler won't acknowledge scala.tools.scalap @@ -23,6 +24,15 @@ object Decode { case _ => NoSymbol } + /** Return the classfile bytes representing the scala sig attribute. + */ + def scalaSigBytes(name: String): Option[Array[Byte]] = { + val bytes = findBytesForClassName(name) + val reader = new ByteArrayReader(bytes) + val cf = new Classfile(reader) + cf.scalaSigAttribute map (_.data) + } + /** private[scala] so nobody gets the idea this is a supported interface. */ private[scala] def caseParamNames(path: String): Option[List[String]] = { |