diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala | 30 | ||||
-rw-r--r-- | src/library/scala/SerialVersionUID.scala | 2 | ||||
-rw-r--r-- | src/library/scala/throws.scala | 17 |
3 files changed, 48 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index 17f02944e0..03c45cef94 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -68,6 +68,7 @@ abstract class GenJVM extends SubComponent { val TransientAtt = definitions.getClass("scala.transient").tpe; val VolatileAttr = definitions.getClass("scala.volatile").tpe; val RemoteAttr = definitions.getClass("scala.remote").tpe; + val ThrowsAttr = definitions.getClass("scala.throws").tpe val CloneableClass = if (forCLDC) null else definitions.getClass("java.lang.Cloneable"); val RemoteInterface = if (forCLDC) null else definitions.getClass("java.rmi.Remote"); @@ -175,6 +176,34 @@ abstract class GenJVM extends SubComponent { emitClass(jclass, c.symbol) } + def addExceptionsAttribute(jm: JMethod, throws: List[AttrInfo]): Unit = { + if (throws.forall(a => a match { + case Pair(ThrowsAttr, _) => false + case _ => true + })) return; + + val cpool = jm.getConstantPool(); + val buf: ByteBuffer = ByteBuffer.allocate(512); + var nattr = 0; + + // put some radom value; the actual number is determined at the end + buf.putShort(0xbaba.toShort) + + for (val Pair(ThrowsAttr, List(exc)) <- throws) { + buf.putShort(cpool.addClass(exc.typeValue.toString()).shortValue) + nattr = nattr + 1; + } + + assert (nattr > 0); + val length = buf.position(); + buf.putShort(0, nattr.toShort) + val arr = buf.array().subArray(0, length); + + val attr = jm.getContext().JOtherAttribute(jm.getJClass(), jm, + nme.ExceptionsATTR.toString(), + arr, length) + jm.addAttribute(attr) + } def addAttributes(jmember: JMember, attributes: List[AttrInfo]): Unit = { if (attributes.isEmpty) return; @@ -330,6 +359,7 @@ abstract class GenJVM extends SubComponent { genLocalVariableTable; } + addExceptionsAttribute(jmethod, m.symbol.attributes) addAttributes(jmethod, m.symbol.attributes) } diff --git a/src/library/scala/SerialVersionUID.scala b/src/library/scala/SerialVersionUID.scala index 152e9ba86e..f74d60fc1e 100644 --- a/src/library/scala/SerialVersionUID.scala +++ b/src/library/scala/SerialVersionUID.scala @@ -16,4 +16,4 @@ package scala; * Attribute for specifying the static SerialVersionUID field * of a serializable class */ -case class SerialVersionUID(uid: Long) extends Attribute {} +class SerialVersionUID(uid: Long) extends Attribute {} diff --git a/src/library/scala/throws.scala b/src/library/scala/throws.scala new file mode 100644 index 0000000000..c26559e19c --- /dev/null +++ b/src/library/scala/throws.scala @@ -0,0 +1,17 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +*/ + +// $Id$ + + +package scala; + +/** + * Attribute for specifying the exceptions thrown by a method. + */ +class throws(clazz: java.lang.Class) extends Attribute; |