summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sources/scala/Enumeration.scala53
-rw-r--r--sources/scala/Ord.scala40
-rw-r--r--sources/scala/tools/scalap/Entity.scala2
-rw-r--r--sources/scala/tools/scalap/EntityTable.scala2
-rw-r--r--sources/scala/tools/scalap/Flags.scala1
-rw-r--r--sources/scala/tools/scalap/JavaWriter.scala9
-rw-r--r--sources/scala/tools/scalap/Main.scala2
-rw-r--r--sources/scala/tools/scalap/Names.scala1
-rw-r--r--sources/scala/tools/scalap/ScalaAttribute.scala4
-rw-r--r--sources/scala/tools/scalap/ScalaWriter.scala88
10 files changed, 115 insertions, 87 deletions
diff --git a/sources/scala/Enumeration.scala b/sources/scala/Enumeration.scala
index c084c717e7..09022e4d70 100644
--- a/sources/scala/Enumeration.scala
+++ b/sources/scala/Enumeration.scala
@@ -19,13 +19,13 @@ abstract class Enumeration(initial: Int, names: String*) {
def this(names: String*) = this(0, names: _*);
def name = {
- val cname = getClass().getName();
- if (cname.endsWith("$"))
- cname.substring(0, cname.length() - 1);
- else if (cname.endsWith("$class"))
- cname.substring(0, cname.length() - 6);
- else
- cname;
+ val cname = getClass().getName();
+ if (cname.endsWith("$"))
+ cname.substring(0, cname.length() - 1);
+ else if (cname.endsWith("$class"))
+ cname.substring(0, cname.length() - 6);
+ else
+ cname;
}
/** A mapping between the enumeration value id and the enumeration
@@ -38,11 +38,11 @@ abstract class Enumeration(initial: Int, names: String*) {
private var vcache: List[Value] = null;
private def updateCache: List[Value] =
- if (vcache == null) {
- vcache = values.values.toList.sort((p1, p2) => p1.id < p2.id);
- vcache
- } else
- vcache;
+ if (vcache == null) {
+ vcache = values.values.toList.sort((p1, p2) => p1.id < p2.id);
+ vcache
+ } else
+ vcache;
protected var nextId = initial;
@@ -75,39 +75,38 @@ abstract class Enumeration(initial: Int, names: String*) {
override def toString(): String = updateCache.mkString("{", ", ", "}");
protected final def Value: Value =
- new Val(nextId, if (nextName.hasNext) nextName.next else null);
+ new Val(nextId, if (nextName.hasNext) nextName.next else null);
protected final def Value(i: Int): Value =
- new Val(i, if (nextName.hasNext) nextName.next else null);
+ new Val(i, if (nextName.hasNext) nextName.next else null);
protected final def Value(name: String): Value = new Val(nextId, name);
protected final def Value(i: Int, name: String): Value = new Val(i, name);
- trait Value extends Ord[Value] {
+ trait Value extends Ordered[Value] {
def id: Int;
- def < [S >: Value <: Ord[S]](that: S): Boolean = that match {
- case that1: Value => id < that1.id
- case _ => that > this
- }
+ def compareTo[S >: Value <% Ordered[S]](that: S): Int = that match {
+ case that1: Value => id - that1.id
+ case _ => -(that compareTo this)
+ }
}
protected class Val(i: Int, name: String) extends Value {
def this(i: Int) =
- this(i, if (nextName.hasNext) nextName.next else i.toString());
+ this(i, if (nextName.hasNext) nextName.next else i.toString());
def this(name: String) = this(nextId, name);
def this() =
- this(nextId, if (nextName.hasNext) nextName.next else nextId.toString());
+ this(nextId, if (nextName.hasNext) nextName.next else nextId.toString());
assert(!values.isDefinedAt(i));
values(i) = this;
nextId = i + 1;
if (nextId > topId)
- topId = nextId;
+ topId = nextId;
def id = i;
- override def toString() =
- if (name == null)
- Enumeration.this.name + "(" + i + ")";
- else
- name;
+ override def toString() = if (name == null)
+ Enumeration.this.name + "(" + i + ")";
+ else
+ name;
}
}
diff --git a/sources/scala/Ord.scala b/sources/scala/Ord.scala
deleted file mode 100644
index 07619d552e..0000000000
--- a/sources/scala/Ord.scala
+++ /dev/null
@@ -1,40 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-** $Id$
-\* */
-
-package scala;
-
-/* Shall we use a nonvariant Ord?
-
-trait Ord[t <: Ord[t]]: t {
- def < (that: t): Boolean;
- def <=(that: t): Boolean = this < that || this == that;
- def > (that: t): Boolean = that < this;
- def >=(that: t): Boolean = that <= this;
-}
-
-*/
-
-trait Ord[+T <: Ord[T]]: T {
- def < [S >: T <: Ord[S]](that: S): Boolean;
- def <=[S >: T <: Ord[S]](that: S): Boolean = this < that || this == that;
- def > [S >: T <: Ord[S]](that: S): Boolean = that < this;
- def >=[S >: T <: Ord[S]](that: S): Boolean = that <= this;
- def min[S >: T <: Ord[S]](that: S): S = if (this < that) this else that;
- def max[S >: T <: Ord[S]](that: S): S = if (this < that) that else this;
-}
-
-/*
-trait Ord[+a] {
- def compareTo [b >: a <% Ord[b]](that: b): int;
- def < [b >: a <% Ord[b]](that: b): boolean = (this compareTo that) < 0;
- def > [b >: a <% Ord[b]](that: b): boolean = (this compareTo that) > 0;
- def <= [b >: a <% Ord[b]](that: b): boolean = (this compareTo that) <= 0;
- def >= [b >: a <% Ord[b]](that: b): boolean = (this compareTo that) >= 0;
-}
-*/
diff --git a/sources/scala/tools/scalap/Entity.scala b/sources/scala/tools/scalap/Entity.scala
index 8d0fe750b4..b9ce65ddd6 100644
--- a/sources/scala/tools/scalap/Entity.scala
+++ b/sources/scala/tools/scalap/Entity.scala
@@ -152,7 +152,7 @@ class ClassSymbol(name: String, flags: Int) extends Symbol(name, flags) {
override def fix(sym: Symbol): Unit = {
constr = sym;
}
- override def enter(sym: Symbol): Unit = scope += sym;
+ override def enter(sym: Symbol): Unit = scope.prepend(sym);
override def members: Buffer[Symbol] = scope;
}
diff --git a/sources/scala/tools/scalap/EntityTable.scala b/sources/scala/tools/scalap/EntityTable.scala
index 51307496f9..90bf758781 100644
--- a/sources/scala/tools/scalap/EntityTable.scala
+++ b/sources/scala/tools/scalap/EntityTable.scala
@@ -121,7 +121,7 @@ class EntityTable(attrib: ScalaAttribute) {
def getSymbol(i: Int): Symbol =
if (i < 0) NoSymbol else table(i).asInstanceOf[Symbol];
- def getSymbols(is: List[Int]): List[Symbol] = is map {i => getSymbol(i)};
+ def getSymbols(is: List[Int]): List[Symbol] = is map getSymbol;
def getType(i: Int): Type = {
if (i < 0)
diff --git a/sources/scala/tools/scalap/Flags.scala b/sources/scala/tools/scalap/Flags.scala
index 4a70113e02..6956bb3667 100644
--- a/sources/scala/tools/scalap/Flags.scala
+++ b/sources/scala/tools/scalap/Flags.scala
@@ -34,6 +34,7 @@ object Flags {
final val JAVA = 0x00001000; // defined by a Java class
final val OBJECT = 0x00002000; // a singleton object
final val MUTABLE = 0x00004000; // a mutable variable
+ final val VIEWBOUND = 0x00004000; // a type variable is bound by a view
final val PARAM = 0x00008000; // a (type) parameter of a method
final val PACKAGE = 0x00100000; // a java package
diff --git a/sources/scala/tools/scalap/JavaWriter.scala b/sources/scala/tools/scalap/JavaWriter.scala
index 7c14b9d9e4..72db125ba8 100644
--- a/sources/scala/tools/scalap/JavaWriter.scala
+++ b/sources/scala/tools/scalap/JavaWriter.scala
@@ -33,7 +33,12 @@ class JavaWriter(classfile: Classfile, writer: Writer) extends CodeWriter(writer
def nameToClass(str: String) = {
val res = Names.decode(str.replace('/', '.'));
- if (res == "java.lang.Object") "scala.AnyRef" else res
+ if (res == "java.lang.Object") "scala.Any" else res
+ }
+
+ def nameToClass0(str: String) = {
+ val res = Names.decode(str.replace('/', '.'));
+ if (res == "java.lang.Object") "scala.AnyRef" else res
}
def nameToSimpleClass(str: String) =
@@ -148,7 +153,7 @@ class JavaWriter(classfile: Classfile, writer: Writer) extends CodeWriter(writer
} else {
print("class " + getSimpleClassName(cf.classname));
if (cf.pool(cf.superclass) != null)
- print(" extends " + getClassName(cf.superclass));
+ print(" extends " + nameToClass0(getName(cf.superclass)));
}
cf.interfaces foreach {
n => print(" with " + getClassName(n));
diff --git a/sources/scala/tools/scalap/Main.scala b/sources/scala/tools/scalap/Main.scala
index bd83c41c9e..baf675f417 100644
--- a/sources/scala/tools/scalap/Main.scala
+++ b/sources/scala/tools/scalap/Main.scala
@@ -20,7 +20,7 @@ object Main {
/** The version number.
*/
- val VERSION = "1.0.1";
+ val VERSION = "1.1.0";
/** Verbose program run?
*/
diff --git a/sources/scala/tools/scalap/Names.scala b/sources/scala/tools/scalap/Names.scala
index bac6268743..d77132470a 100644
--- a/sources/scala/tools/scalap/Names.scala
+++ b/sources/scala/tools/scalap/Names.scala
@@ -25,6 +25,7 @@ object Names {
operatorName('|') = "$bar";
operatorName('*') = "$times";
operatorName('/') = "$div";
+ operatorName('\\') = "$bslash";
operatorName('+') = "$plus";
operatorName('-') = "$minus";
operatorName(':') = "$colon";
diff --git a/sources/scala/tools/scalap/ScalaAttribute.scala b/sources/scala/tools/scalap/ScalaAttribute.scala
index 8e582e83e1..34125f08a0 100644
--- a/sources/scala/tools/scalap/ScalaAttribute.scala
+++ b/sources/scala/tools/scalap/ScalaAttribute.scala
@@ -63,7 +63,7 @@ class ScalaAttribute(in: ByteArrayReader) {
def readTableEntry: AttribEntry = {
val tag = in.nextByte;
- // Console.println("tag = " + tag);
+ //Console.println("tag = " + tag);
val len = in.nextNat;
val end = in.bp + len;
tag match {
@@ -124,7 +124,7 @@ class ScalaAttribute(in: ByteArrayReader) {
LONG_LIT |
FLOAT_LIT |
DOUBLE_LIT =>
- Literal(tag, in.nextLong)
+ Literal(tag, in.nextNum(len))
case _ =>
error("unknown meta data tag: " + tag);
}
diff --git a/sources/scala/tools/scalap/ScalaWriter.scala b/sources/scala/tools/scalap/ScalaWriter.scala
index 32e08878f7..1a19ce63f4 100644
--- a/sources/scala/tools/scalap/ScalaWriter.scala
+++ b/sources/scala/tools/scalap/ScalaWriter.scala
@@ -31,11 +31,13 @@ class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) {
print("/*deferred*/ ");
if (Flags.is(Flags.OBJECT, s.flags))
print("object " + s.name);
- else if (Flags.is(Flags.TRAIT, s.flags))
+ else if (Flags.is(Flags.TRAIT, s.flags)) {
print("trait " + s.name);
- else
+ printConstr(s.constr);
+ } else {
print("class " + s.name);
- printConstr(s.constr);
+ printConstr(s.constr);
+ }
print(" extends ");
printType(s.tpe);
case s: ValSymbol =>
@@ -74,9 +76,9 @@ class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) {
}
}
print("]");
- printTypes(argtpes, "(", ", ", ")");
+ printParameterTypes(argtpes, "(", ", ", ")", false);
case MethodType(argtpes, _) =>
- printTypes(argtpes, "(", ", ", ")");
+ printParameterTypes(argtpes, "(", ", ", ")", false);
case _ =>
}
}
@@ -101,6 +103,37 @@ class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) {
newline.undent.print("}")
}
+ def printParameterType(tpe: Type, basic: Boolean): Unit = tpe match {
+ case TypeRef(SingletonType(ThisType(root), top), sym, args) =>
+ if ((root.name.equals("<root>") || root.name.equals("")) &&
+ top.name.equals("scala") &&
+ sym.name.startsWith("Function")) {
+ if ((args.length == 2) && !isFunctionType(args.head)) {
+ printType(args.head);
+ print(" => ");
+ printParameterType(args.tail.head, basic);
+ } else {
+ printParameterTypes(args.take(args.length - 1), "(", ", ", ")", basic);
+ print(" => ");
+ printParameterType(args.last, basic);
+ }
+ } else if (basic)
+ printType0(tpe);
+ else
+ printType(tpe);
+ case _ => if (basic) printType0(tpe); else printType(tpe);
+ }
+
+ def printParameterTypes(tpes: List[Type], begin: String, infix: String,
+ end: String, basic: Boolean): Unit = {
+ print(begin);
+ if (!tpes.isEmpty) {
+ printParameterType(tpes.head, basic);
+ tpes.tail foreach (t => { print(infix); printParameterType(t, basic) });
+ }
+ print(end);
+ }
+
def printType(tpe: Type): Unit = {
printType0(tpe);
tpe match {
@@ -125,10 +158,14 @@ class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) {
case SingletonType(tpe, sym) =>
printPrefix(tpe);
print(sym.name)
- case TypeRef(tpe, sym, args) =>
- printPrefix(tpe);
- print(sym.name);
- printTypes(args, "[", ", ", "]");
+ case TypeRef(pre, sym, args) =>
+ if (isJavaRoot(tpe))
+ print("scala.AnyRef");
+ else {
+ printPrefix(pre);
+ print(sym.name);
+ printTypes(args, "[", ", ", "]");
+ }
case CompoundType(clazz, components) =>
printTypes(components, "", " with ", "");
if (clazz != NoSymbol)
@@ -138,7 +175,7 @@ class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) {
while (tpe0.isInstanceOf[MethodType]) {
tpe0 match {
case MethodType(argtpes, restpe) =>
- printTypes0(argtpes, "(", ", ", ")");
+ printParameterTypes(argtpes, "(", ", ", ")", true);
tpe0 = restpe;
}
}
@@ -212,11 +249,14 @@ class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) {
else
print(sym.name);
if (!isExternalType(sym.tpe, "Any")) {
- print(" <: ")*;
+ if (Flags.is(Flags.VIEWBOUND, sym.flags))
+ print(" <% ");
+ else
+ print(" <: ");
printType(sym.tpe);
}
if (!isExternalType(sym.lower, "All")) {
- print(" >: ")*;
+ print(" >: ");
printType(sym.lower);
}
}
@@ -231,9 +271,31 @@ class ScalaWriter(args: Arguments, writer: Writer) extends CodeWriter(writer) {
case _ => false
}
+ def isJavaRoot(tpe: Type): Boolean = tpe match {
+ case TypeRef(SingletonType(SingletonType(ThisType(root), top), mid), sym, Nil) =>
+ (root.name.equals("<root>") || root.name.equals("")) &&
+ top.name.equals("java") &&
+ mid.name.equals("lang") &&
+ sym.name.equals("Object")
+ case _ => false
+ }
+
+ def isFunctionType(tpe: Type): Boolean = tpe match {
+ case TypeRef(SingletonType(ThisType(root), top), sym, Nil) =>
+ (root.name.equals("<root>") || root.name.equals("")) &&
+ top.name.equals("scala") &&
+ sym.name.startsWith("Function")
+ case _ => false
+ }
+
def ignoreDef(s: Symbol) =
(Flags.is(Flags.PRIVATE, s.flags) &&
!((args != null) && (args contains "-private"))) ||
(s.name == "<init>") ||
- Flags.is(Flags.CASEACCESSOR, s.flags);
+ Flags.is(Flags.CASEACCESSOR, s.flags) ||
+ (Flags.is(Flags.CASE, s.flags) &&
+ (s match {
+ case sym: ValSymbol => true
+ case _ => false
+ }))
}