diff options
author | Paul Phillips <paulp@improving.org> | 2010-02-15 20:00:36 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-02-15 20:00:36 +0000 |
commit | 821229741d41ab5a0087ddf289ee01b92e9c0685 (patch) | |
tree | 1306ddc619017d903c2bceb35ba37ba27cc27dbf /src/compiler | |
parent | 369d3ca26f05ab848807c109e464f90f2e668c81 (diff) | |
download | scala-821229741d41ab5a0087ddf289ee01b92e9c0685.tar.gz scala-821229741d41ab5a0087ddf289ee01b92e9c0685.tar.bz2 scala-821229741d41ab5a0087ddf289ee01b92e9c0685.zip |
Some new tools for the tools directory.
amounts to a yak shaving expedition to enable this, which now works:
tools/diffPickled scala.Either
and since stability is presently broken you will see the following.
(When it's not broken you will see nothing.)
541,544c541,544
< 538,4090: EXTref 3: 539(Left) 2
< 539,4095: TYPEname 4: Left
< 540,4101: EXTref 3: 541(Right) 2
< 541,4106: TYPEname 5: Right
---
> 538,4090: EXTref 3: 539(Right) 2
> 539,4095: TYPEname 5: Right
> 540,4102: EXTref 3: 541(Left) 2
> 541,4107: TYPEname 4: Left
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/interpreter/ByteCode.scala | 10 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/util/ShowPickled.scala | 26 |
2 files changed, 28 insertions, 8 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) } } } |