diff options
author | mihaylov <mihaylov@epfl.ch> | 2006-05-19 14:53:45 +0000 |
---|---|---|
committer | mihaylov <mihaylov@epfl.ch> | 2006-05-19 14:53:45 +0000 |
commit | f746ce36d86a08c8456f5fae04459addcdd2c62d (patch) | |
tree | 28f83ab373c91db2939243f0d29339d92b6c312a /src/compiler | |
parent | 16b00da844c40cc76cee72088bd6dc49fa38d98c (diff) | |
download | scala-f746ce36d86a08c8456f5fae04459addcdd2c62d.tar.gz scala-f746ce36d86a08c8456f5fae04459addcdd2c62d.tar.bz2 scala-f746ce36d86a08c8456f5fae04459addcdd2c62d.zip |
Added scala.throws(java.lang.Class) attribute t...
Added scala.throws(java.lang.Class) attribute to specify the checked
exceptions thrown by a method
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala | 30 |
1 files changed, 30 insertions, 0 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) } |