diff options
author | michelou <michelou@epfl.ch> | 2005-05-26 13:39:03 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2005-05-26 13:39:03 +0000 |
commit | 2a99a8010f8b129893d046976195997bc9feb363 (patch) | |
tree | 657cabc17fdc86ab26bf722d7c6bb2c1467703a7 | |
parent | de1ca7103e206e53353cfe8cf49e643ff5c6006e (diff) | |
download | scala-2a99a8010f8b129893d046976195997bc9feb363.tar.gz scala-2a99a8010f8b129893d046976195997bc9feb363.tar.bz2 scala-2a99a8010f8b129893d046976195997bc9feb363.zip |
- made Scala traits implement java.io.Serializa...
- made Scala traits implement java.io.Serializable in 'enterClass'.
-rw-r--r-- | sources/scalac/backend/jvm/GenJVM.java | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/sources/scalac/backend/jvm/GenJVM.java b/sources/scalac/backend/jvm/GenJVM.java index 5095a3b024..6dee5a32f3 100644 --- a/sources/scalac/backend/jvm/GenJVM.java +++ b/sources/scalac/backend/jvm/GenJVM.java @@ -1,6 +1,6 @@ /* ____ ____ ____ ____ ______ *\ ** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** -** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002-2005, LAMP/EPFL ** ** /_____/\____/\___/\____/____/ ** \* */ @@ -61,6 +61,8 @@ public class GenJVM { protected final static String JAVA_LANG_STRING = "java.lang.String"; protected final static String JAVA_LANG_STRINGBUFFER = "java.lang.StringBuffer"; + protected final static String JAVA_IO_SERIALIZABLE = + "java.io.Serializable"; protected final static String JAVA_RMI_REMOTE = "java.rmi.Remote"; protected final static String JAVA_RMI_REMOTEEXCEPTION = "java.rmi.RemoteException"; @@ -1618,6 +1620,18 @@ public class GenJVM { ////////////////////////////////////////////////////////////////////// /** + * Appends Serializable name to the list of interface names + * (we assume Serializable is not yet present in the list) + */ + private static String[] appendSerializable(String[] names) { + int n = names.length; + String[] names1 = new String[n + 1]; + System.arraycopy(names, 0, names1, 0, n); + names1[n] = JAVA_IO_SERIALIZABLE; + return names1; + } + + /** * Record the entry into a class, and return the appropriate * context. */ @@ -1629,26 +1643,34 @@ public class GenJVM { int offset; String superClassName; + boolean addSerializableName = false; if (cSym.isInterface()) { offset = baseTps[0].symbol() == defs.ANY_CLASS ? 1 : 0; superClassName = JAVA_LANG_OBJECT; } else { offset = 1; superClassName = javaName(baseTps[0].symbol()); + // assume Scala traits with/without RTT are serializable + addSerializableName = cSym.isTrait(); } String[] interfaceNames = new String[baseTps.length - offset]; for (int i = offset; i < baseTps.length; ++i) { Symbol baseSym = baseTps[i].symbol(); + addSerializableName = + addSerializableName && baseSym != defs.SERIALIZABLE_CLASS; assert baseSym.isInterface() : cSym + " implements " + baseSym; interfaceNames[i - offset] = javaName(baseSym); } + String[] interfaceNames1 = (addSerializableName) + ? appendSerializable(interfaceNames) + : interfaceNames; JClass cls = fjbgContext.JClass(javaModifiers(cSym) & ~JAccessFlags.ACC_STATIC | JAccessFlags.ACC_SUPER, javaName, superClassName, - interfaceNames, + interfaceNames1, ctx.sourceFileName); return ctx.withClass(cls, |