summaryrefslogtreecommitdiff
path: root/src/scalap
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-04-21 17:06:38 +0000
committerPaul Phillips <paulp@improving.org>2010-04-21 17:06:38 +0000
commita17a4dc15730ce004ca8c9495c850dfca1062c24 (patch)
tree5dbd27fc4476a3bd3f16d1fbbee4647b633f242b /src/scalap
parentcf26f620707be4bd9f8bc30a733eb4a987894421 (diff)
downloadscala-a17a4dc15730ce004ca8c9495c850dfca1062c24.tar.gz
scala-a17a4dc15730ce004ca8c9495c850dfca1062c24.tar.bz2
scala-a17a4dc15730ce004ca8c9495c850dfca1062c24.zip
Since pickled data moved into annotations ShowP...
Since pickled data moved into annotations ShowPickled has been confusedly scratching its head. Made tools/showPickled work again. In the process created a simple interface for creating command line tools for the (majority of) commands which would just like to specify a handful of options. No review.
Diffstat (limited to 'src/scalap')
-rw-r--r--src/scalap/scala/tools/scalap/Decode.scala27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/scalap/scala/tools/scalap/Decode.scala b/src/scalap/scala/tools/scalap/Decode.scala
index e9f9a390c5..5189009584 100644
--- a/src/scalap/scala/tools/scalap/Decode.scala
+++ b/src/scalap/scala/tools/scalap/Decode.scala
@@ -12,7 +12,10 @@ package scala.tools.scalap
import scala.tools.scalap.scalax.rules.scalasig._
import scala.tools.nsc.util.ScalaClassLoader
import scala.tools.nsc.util.ScalaClassLoader.getSystemLoader
-import Main.SCALA_SIG
+import scala.reflect.generic.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
@@ -25,7 +28,8 @@ object Decode {
case _ => NoSymbol
}
- /** Return the classfile bytes representing the scala sig attribute.
+ /** 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, getSystemLoader())
def scalaSigBytes(name: String, classLoader: ScalaClassLoader): Option[Array[Byte]] = {
@@ -35,6 +39,25 @@ object Decode {
cf.scalaSigAttribute map (_.data)
}
+ /** Return the bytes representing the annotation
+ */
+ def scalaSigAnnotationBytes(name: String): Option[Array[Byte]] = scalaSigAnnotationBytes(name, getSystemLoader())
+ def scalaSigAnnotationBytes(name: String, classLoader: ScalaClassLoader): Option[Array[Byte]] = {
+ val bytes = classLoader.findBytesForClassName(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) get
+ val _bytes = bytesElem.elementValue match { case ConstValueIndex(x) => constantWrapped(x) }
+ val bytes = _bytes.asInstanceOf[StringBytesPair].bytes
+ val length = ByteCodecs.decode(bytes)
+
+ bytes take length
+ }
+ }
+
/** private[scala] so nobody gets the idea this is a supported interface.
*/
private[scala] def caseParamNames(path: String): Option[List[String]] = {