diff options
Diffstat (limited to 'src/scalap')
-rw-r--r-- | src/scalap/scala/tools/scalap/Decode.scala | 27 |
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]] = { |