summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorMatthias Zenger <mzenger@gmail.com>2004-02-10 09:32:43 +0000
committerMatthias Zenger <mzenger@gmail.com>2004-02-10 09:32:43 +0000
commitdf78dc64f75187a3a3915c90a008cc964f8ec252 (patch)
tree88b137e2ecdf36adc2acdc4c96a322587c87335d /sources
parentd6963262b4a68577925b1281d246e30e3265e97a (diff)
downloadscala-df78dc64f75187a3a3915c90a008cc964f8ec252.tar.gz
scala-df78dc64f75187a3a3915c90a008cc964f8ec252.tar.bz2
scala-df78dc64f75187a3a3915c90a008cc964f8ec252.zip
- Fixed broken UnPickle.
- Added support for PiCo's Meta attribute.
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/tools/scalap/JavaWriter.scala35
-rw-r--r--sources/scala/tools/scalap/MetaParser.scala193
-rw-r--r--sources/scala/tools/scalap/ScalaAttribute.scala6
3 files changed, 226 insertions, 8 deletions
diff --git a/sources/scala/tools/scalap/JavaWriter.scala b/sources/scala/tools/scalap/JavaWriter.scala
index 9ba45aefea..670406383d 100644
--- a/sources/scala/tools/scalap/JavaWriter.scala
+++ b/sources/scala/tools/scalap/JavaWriter.scala
@@ -111,12 +111,35 @@ class JavaWriter(classfile: Classfile, writer: Writer) extends CodeWriter(writer
def printMethod(flags: Int, name: Int, tpe: Int, attribs: List[cf.Attribute]) = {
if (getName(name) == "<init>")
- print(flagsToStr(false, flags))*;
- if (getName(name) == "<init>") {
- print("def this" + getType(tpe) + ";").newline*;
- } else {
- print("def " + Names.decode(getName(name)))*;
- print(getType(tpe) + ";").newline*;
+ print(flagsToStr(false, flags));
+ attribs find {
+ case cf.Attribute(name, _) => getName(name) == "JacoMeta"
+ } match {
+ case Some(cf.Attribute(_, data)) =>
+ Console.println(data.length);
+ val mp = new MetaParser(getName(
+ ((data(0) & 0xff) << 8) + (data(1) & 0xff)).trim());
+ mp.parse match {
+ case None =>
+ if (getName(name) == "<init>") {
+ print("def this" + getType(tpe) + ";").newline;
+ } else {
+ print("def " + Names.decode(getName(name)));
+ print(getType(tpe) + ";").newline;
+ }
+ case Some(str) =>
+ if (getName(name) == "<init>")
+ print("def this" + str + ";").newline;
+ else
+ print("def " + Names.decode(getName(name)) + str + ";").newline;
+ }
+ case None =>
+ if (getName(name) == "<init>") {
+ print("def this" + getType(tpe) + ";").newline*;
+ } else {
+ print("def " + Names.decode(getName(name)))*;
+ print(getType(tpe) + ";").newline*;
+ }
}
}
diff --git a/sources/scala/tools/scalap/MetaParser.scala b/sources/scala/tools/scalap/MetaParser.scala
new file mode 100644
index 0000000000..ed9034904c
--- /dev/null
+++ b/sources/scala/tools/scalap/MetaParser.scala
@@ -0,0 +1,193 @@
+/* ___ ____ ___ __ ___ ___
+** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
+** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003, LAMP/EPFL
+** /____/\___/_/ |_/____/_/ |_/_/
+**
+** $Id$
+*/
+
+package scala.tools.scalap;
+
+import java.io._;
+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);
+ var token: String = _;
+ val res = new StringBuffer;
+
+ private def nextToken: String = {
+ do {
+ token = scanner.nextToken().trim();
+ } while (token.length() == 0);
+ token
+ }
+
+ protected def parseType: Unit = {
+ if (token.startsWith("?"))
+ res.append(token.substring(1));
+ else
+ res.append(token);
+ nextToken;
+ if (token == "[") {
+ do {
+ if (token == ",")
+ res.append(", ");
+ else
+ res.append("[");
+ nextToken;
+ parseType;
+ } while (token == ",");
+ nextToken;
+ res.append("]");
+ }
+ }
+
+ def parse: Option[String] =
+ if (scanner.hasMoreTokens()) {
+ nextToken;
+ try {
+ if (!scanner.hasMoreTokens())
+ None
+ else if (token == "class")
+ Some(parseMetaClass);
+ else if (token == "method")
+ Some(parseMetaMethod);
+ else if (token == "field")
+ Some(parseMetaField);
+ else if (token == "constr")
+ Some(parseConstrField);
+ else
+ None;
+ } catch { case _ =>
+ None;
+ }
+ } else
+ None;
+
+ protected def parseMetaClass: String = {
+ nextToken;
+ if (token == "[") {
+ do {
+ if (token == "[")
+ res.append('[');
+ else
+ res.append(", ");
+ nextToken;
+ if (token == "+") {
+ nextToken;
+ res.append('+');
+ } else if (token == "-") {
+ nextToken;
+ res.append('-');
+ }
+ res.append(token.substring(1));
+ nextToken;
+ if (token == "<") {
+ nextToken;
+ res.append(" <: ");
+ parseType;
+ }
+ } while (token == ",");
+ nextToken;
+ res.append("]");
+ }
+ if (token == "extends") {
+ do {
+ if (token == "extends")
+ res.append(" extends ");
+ else
+ res.append(" with ");
+ nextToken;
+ parseType;
+ } while (token == "with");
+ }
+ res.toString();
+ }
+
+ protected def parseMetaMethod: String = {
+ nextToken;
+ if (token == "[") {
+ nextToken;
+ if (token == "]") {
+ nextToken;
+ } else {
+ var loop = true;
+ res.append("[");
+ while (loop) {
+ res.append(token.substring(1));
+ nextToken;
+ if (token == "<") {
+ nextToken;
+ res.append(" <: ");
+ parseType;
+ }
+ if (token == ",") {
+ nextToken;
+ res.append(", ");
+ } else
+ loop = false;
+ }
+ nextToken;
+ res.append("]");
+ }
+ }
+ if (token == "(") {
+ do {
+ if (token == ",") {
+ nextToken;
+ if (token != ")")
+ res.append(", ");
+ } else {
+ nextToken;
+ res.append("(");
+ }
+ if (token != ")") {
+ if (token == "def") {
+ nextToken;
+ res.append("def ");
+ }
+ parseType;
+ }
+ } while (token == ",");
+ nextToken;
+ res.append("): ");
+ parseType;
+ } else {
+ res.append(": ");
+ parseType;
+ }
+ res.toString();
+ }
+
+ protected def parseMetaField: String = {
+ nextToken;
+ res.append(": ");
+ parseType;
+ res.toString();
+ }
+
+ protected def parseConstrField: String = {
+ nextToken;
+ if (token == "(") {
+ do {
+ if (token == "(")
+ res.append("(");
+ else
+ res.append(", ");
+ nextToken;
+ if (token != ")")
+ parseType;
+ } while (token == ",");
+ nextToken;
+ res.append(")");
+ } else {
+
+ }
+ res.toString();
+ }
+}
diff --git a/sources/scala/tools/scalap/ScalaAttribute.scala b/sources/scala/tools/scalap/ScalaAttribute.scala
index faad3cc00f..ebf19316fa 100644
--- a/sources/scala/tools/scalap/ScalaAttribute.scala
+++ b/sources/scala/tools/scalap/ScalaAttribute.scala
@@ -32,8 +32,10 @@ class ScalaAttribute(in: ByteArrayReader) {
final val METHOD_TYPE = 17;
final val POLY_TYPE = 18;
final val OVERLOADED_TYPE = 19;
- final val FLAGGED_TYPE = 20;
-
+ final val UNBOXED_TYPE = 20;
+ final val UNBOXEDARRAY_TYPE = 21;
+ final val FLAGGED_TYPE = 22;
+ final val ERROR_TYPE = 23;
val table = readTable;