summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2011-03-04 16:10:36 +0000
committerIulian Dragos <jaguarul@gmail.com>2011-03-04 16:10:36 +0000
commite586206e08e70b22d33152c7802d658577fddcf5 (patch)
treef97b4c71b6a69b22c64da4c1d687bedc74908b45
parent305e7aa380452199139ccdd86f93caa2c923fc2a (diff)
downloadscala-e586206e08e70b22d33152c7802d658577fddcf5.tar.gz
scala-e586206e08e70b22d33152c7802d658577fddcf5.tar.bz2
scala-e586206e08e70b22d33152c7802d658577fddcf5.zip
Renamed some methods in icode exception handler...
Renamed some methods in icode exception handlers for clarification, fixed finalizers for 'return' inside a catch block. closes #4240. review by rytz.
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala25
-rw-r--r--test/files/run/finally.check2
-rw-r--r--test/files/run/finally.scala14
3 files changed, 27 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index 2d71a00f61..ad67eb3025 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -19,8 +19,6 @@ import PartialFunction._
* @author Iulian Dragos
* @version 1.0
*/
-// TODO:
-// - switches with alternatives
abstract class GenICode extends SubComponent {
import global._
import icodes._
@@ -2008,7 +2006,7 @@ abstract class GenICode extends SubComponent {
* 'covered' by this exception handler (in addition to the
* previously active handlers).
*/
- def newHandler(cls: Symbol, resultKind: TypeKind, pos: Position): ExceptionHandler = {
+ private def newExceptionHandler(cls: Symbol, resultKind: TypeKind, pos: Position): ExceptionHandler = {
handlerCount += 1
val exh = new ExceptionHandler(method, "" + handlerCount, cls, pos)
exh.resultKind = resultKind
@@ -2032,7 +2030,7 @@ abstract class GenICode extends SubComponent {
/** Return a new context for generating code for the given
* exception handler.
*/
- def enterHandler(exh: ExceptionHandler): Context = {
+ private def enterExceptionHandler(exh: ExceptionHandler): Context = {
currentExceptionHandlers ::= exh
val ctx = newBlock
exh.setStartBlock(ctx.bb)
@@ -2044,7 +2042,7 @@ abstract class GenICode extends SubComponent {
}
/** Remove the given handler from the list of active exception handlers. */
- def removeHandler(exh: ExceptionHandler): Unit = {
+ def removeActiveHandler(exh: ExceptionHandler): Unit = {
assert(handlerCount > 0 && handlers.head == exh,
"Wrong nesting of exception handlers." + this + " for " + exh)
handlerCount -= 1
@@ -2118,9 +2116,9 @@ abstract class GenICode extends SubComponent {
val finalizerExh = if (finalizer != EmptyTree) Some({
- val exh = outerCtx.newHandler(NoSymbol, toTypeKind(finalizer.tpe), finalizer.pos) // finalizer covers exception handlers
+ val exh = outerCtx.newExceptionHandler(NoSymbol, toTypeKind(finalizer.tpe), finalizer.pos) // finalizer covers exception handlers
this.addActiveHandler(exh) // .. and body aswell
- val ctx = finalizerCtx.enterHandler(exh)
+ val ctx = finalizerCtx.enterExceptionHandler(exh)
val exception = ctx.makeLocal(finalizer.pos, ThrowableClass.tpe, "exc")
loadException(ctx, exh, finalizer.pos)
ctx.bb.emit(STORE_LOCAL(exception));
@@ -2134,8 +2132,9 @@ abstract class GenICode extends SubComponent {
}) else None
val exhs = handlers.map { handler =>
- val exh = this.newHandler(handler._1, handler._2, tree.pos)
- var ctx1 = outerCtx.enterHandler(exh)
+ val exh = this.newExceptionHandler(handler._1, handler._2, tree.pos)
+ var ctx1 = outerCtx.enterExceptionHandler(exh)
+ ctx1.addFinalizer(finalizer)
loadException(ctx1, exh, tree.pos)
ctx1 = handler._3(ctx1)
// emit finalizer
@@ -2187,9 +2186,9 @@ abstract class GenICode extends SubComponent {
if (finalizer != EmptyTree) {
// finalizer is covers try and all catch blocks, i.e.
// try { try { .. } catch { ..} } finally { .. }
- val exh = outerCtx.newHandler(NoSymbol, UNIT, tree.pos)
+ val exh = outerCtx.newExceptionHandler(NoSymbol, UNIT, tree.pos)
this.addActiveHandler(exh)
- val ctx = finalizerCtx.enterHandler(exh)
+ val ctx = finalizerCtx.enterExceptionHandler(exh)
loadException(ctx, exh, tree.pos)
val ctx1 = genLoad(finalizer, ctx, UNIT)
// need jump for the ICode to be valid. MSIL backend will emit `Endfinally` instead.
@@ -2198,8 +2197,8 @@ abstract class GenICode extends SubComponent {
}
for (handler <- handlers) {
- val exh = this.newHandler(handler._1, handler._2, tree.pos)
- var ctx1 = outerCtx.enterHandler(exh)
+ val exh = this.newExceptionHandler(handler._1, handler._2, tree.pos)
+ var ctx1 = outerCtx.enterExceptionHandler(exh)
loadException(ctx1, exh, tree.pos)
ctx1 = handler._3(ctx1)
// msil backend will emit `Leave` to jump out of a handler
diff --git a/test/files/run/finally.check b/test/files/run/finally.check
index 4e66e2b5cb..fa565c8e8a 100644
--- a/test/files/run/finally.check
+++ b/test/files/run/finally.check
@@ -1,3 +1,5 @@
hi
In Finally
java.lang.RuntimeException: ouch
+java.lang.Exception
+in finally
diff --git a/test/files/run/finally.scala b/test/files/run/finally.scala
index e4715c59ae..0da616cfdd 100644
--- a/test/files/run/finally.scala
+++ b/test/files/run/finally.scala
@@ -6,7 +6,7 @@ object Test extends App {
println("hi")
}
catch {
- case e => println("GOT HERE")
+ case e => println("SHOULD NOT GET HERE")
}
finally {
println("In Finally")
@@ -14,9 +14,21 @@ object Test extends App {
}
}
+ def m1 {
+ try {
+ throw new Exception
+ } catch {
+ case e =>
+ println(e);
+ return
+ } finally println("in finally")
+ }
+
try {
bar
} catch {
case e => println(e)
}
+
+ m1
}