From b2dbde80667b753510abf97948be02aac67cba81 Mon Sep 17 00:00:00 2001 From: mihaylov Date: Fri, 24 Jun 2005 15:20:58 +0000 Subject: Implemented support for the scala.cloneable att... Implemented support for the scala.cloneable attribute --- sources/scalac/backend/jvm/GenJVM.java | 23 +++++++++++++---------- sources/scalac/symtab/Definitions.java | 17 ++++++++++++++++- sources/scalac/util/Names.java | 1 + 3 files changed, 30 insertions(+), 11 deletions(-) (limited to 'sources/scalac') diff --git a/sources/scalac/backend/jvm/GenJVM.java b/sources/scalac/backend/jvm/GenJVM.java index b3ec16c879..2ba2fb1a6b 100644 --- a/sources/scalac/backend/jvm/GenJVM.java +++ b/sources/scalac/backend/jvm/GenJVM.java @@ -87,8 +87,6 @@ public class GenJVM { protected final Symbol JAVA_RMI_REMOTE_CLASS; protected final Symbol SCALA_SERIAL_VERSION_UID_CONSTR; - protected final Symbol SCALA_TRANSIENT_CONSTR; - protected final Symbol SCALA_VOLATILE_CONSTR; protected final Global global; protected final Definitions defs; @@ -118,10 +116,6 @@ public class GenJVM { JAVA_RMI_REMOTE_CLASS = defs.getClass(JAVA_RMI_REMOTE); SCALA_SERIAL_VERSION_UID_CONSTR = defs.getClass("scala.SerialVersionUID") .primaryConstructor(); - SCALA_TRANSIENT_CONSTR = - defs.getClass("scala.transient").primaryConstructor(); - SCALA_VOLATILE_CONSTR = - defs.getClass("scala.volatile").primaryConstructor(); } /// Code generation @@ -1634,6 +1628,9 @@ public class GenJVM { boolean serializable = global.getAttrArguments(cSym, defs.SCALA_SERIALIZABLE_CONSTR) != null; + boolean cloneable = + global.getAttrArguments(cSym, defs.SCALA_CLONEABLE_CONSTR) != null; + scalac.symtab.Type[] baseTps = cSym.info().parents(); assert baseTps.length > 0 : Debug.show(cSym); @@ -1647,14 +1644,18 @@ public class GenJVM { superClassName = javaName(baseTps[0].symbol()); } String[] interfaceNames = new String[baseTps.length - offset - + (serializable ? 1 : 0)]; + + (serializable ? 1 : 0) + + (cloneable ? 1 : 0)]; for (int i = offset; i < baseTps.length; ++i) { Symbol baseSym = baseTps[i].symbol(); assert baseSym.isInterface() : cSym + " implements " + baseSym; interfaceNames[i - offset] = javaName(baseSym); } if (serializable) - interfaceNames[interfaceNames.length - 1] = "java.io.Serializable"; + interfaceNames[interfaceNames.length - 1 - (cloneable ? 1 : 0)] = + "java.io.Serializable"; + if (cloneable) + interfaceNames[interfaceNames.length - 1] = "java.lang.Cloneable"; JClass cls = fjbgContext.JClass(javaModifiers(cSym) & ~JAccessFlags.ACC_STATIC @@ -1788,9 +1789,11 @@ public class GenJVM { Symbol member = memberIt.next(); if (member.isTerm() && !member.isMethod()) { int flags = javaModifiers(member); - if (global.getAttrArguments(member,SCALA_TRANSIENT_CONSTR)!=null) + if (global.getAttrArguments(member,defs.SCALA_TRANSIENT_CONSTR) + != null) flags |= JAccessFlags.ACC_TRANSIENT; - if (global.getAttrArguments(member,SCALA_VOLATILE_CONSTR)!=null) + if (global.getAttrArguments(member,defs.SCALA_VOLATILE_CONSTR) + != null) flags |= JAccessFlags.ACC_VOLATILE; ctx.clazz.addNewField(flags, member.name.toString(), diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java index f09740708a..70386c9d1a 100644 --- a/sources/scalac/symtab/Definitions.java +++ b/sources/scalac/symtab/Definitions.java @@ -253,6 +253,9 @@ public class Definitions { // attributes public final Symbol SCALA_SERIALIZABLE_CONSTR; + public final Symbol SCALA_TRANSIENT_CONSTR; + public final Symbol SCALA_VOLATILE_CONSTR; + public final Symbol SCALA_CLONEABLE_CONSTR; //######################################################################## // Public Fields & Methods - Scala primitive types @@ -337,6 +340,7 @@ public class Definitions { /** Some java.lang.Object methods */ public final Symbol OBJECT_EQ; public final Symbol OBJECT_NE; + public final Symbol OBJECT_CLONE; public final Symbol OBJECT_SYNCHRONIZED; /** Some java.lang.String methods */ @@ -835,6 +839,12 @@ public class Definitions { SCALA_SERIALIZABLE_CONSTR = getClass("scala.serializable") .primaryConstructor(); + SCALA_TRANSIENT_CONSTR = getClass("scala.transient") + .primaryConstructor(); + SCALA_VOLATILE_CONSTR = getClass("scala.volatile") + .primaryConstructor(); + SCALA_CLONEABLE_CONSTR = getClass("scala.cloneable") + .primaryConstructor(); // initialize generated classes and aliases initClass(ANY_CLASS, Type.EMPTY_ARRAY); @@ -924,6 +934,9 @@ public class Definitions { OBJECT_SYNCHRONIZED_TPARAM.type()))); if (forMSIL) { + OBJECT_CLONE = newMethod(OBJECT_CLASS, Names.clone, Modifiers.PROTECTED); + initMethod(OBJECT_CLONE, Type.EMPTY_ARRAY, ANYREF_TYPE()); + Symbol WAIT0 = newMethod(OBJECT_CLASS, Names.wait, Modifiers.FINAL); initMethod(WAIT0, Type.EMPTY_ARRAY, UNIT_TYPE()); @@ -943,7 +956,9 @@ public class Definitions { Symbol JLOA = newAlias(JAVALANG, Names.Object, 0); initAlias(JLOA, OBJECT_TYPE()); - } + } else { + OBJECT_CLONE = null; + } // add members to java.lang.String STRING_PLUS = newMethod(STRING_CLASS, Names.PLUS, Modifiers.FINAL); diff --git a/sources/scalac/util/Names.java b/sources/scalac/util/Names.java index 0a2883d0aa..9bde7b9b5c 100644 --- a/sources/scalac/util/Names.java +++ b/sources/scalac/util/Names.java @@ -168,6 +168,7 @@ public class Names { public static final Name caseElement = Name.fromString("caseElement"); public static final Name cur = Name.fromString("cur"); // used in translation of automata public static final Name cast = Name.fromString("cast"); + public static final Name clone = Name.fromString("clone"); public static final Name coerce = Name.fromString("coerce"); public static final Name defaultValue = Name.fromString("defaultValue"); public static final Name elem = Name.fromString("elem"); -- cgit v1.2.3