package scala.tools.nsc
package backend
package icode
import scala.collection.{ mutable, immutable, generic }
import util.{ Position, NoPosition }
trait ExceptionHandlers {
self: ICodes =>
import global.{ definitions, Symbol, NoSymbol }
import definitions.{ ThrowableClass }
class ExceptionHandler(val method: IMethod, val label: String, val cls: Symbol, val pos: Position) {
def loadExceptionClass = if (cls == NoSymbol) ThrowableClass else cls
private var _startBlock: BasicBlock = _;
var finalizer: Finalizer = _;
var resultKind: TypeKind = _;
def setStartBlock(b: BasicBlock) = {
_startBlock = b;
b.exceptionHandlerStart = true
}
def startBlock = _startBlock
var covered: immutable.Set[BasicBlock] = immutable.HashSet.empty[BasicBlock]
def addCoveredBlock(b: BasicBlock): this.type = {
covered = covered + b
this
}
def covers(b: BasicBlock): Boolean = covered(b)
var blocks: List[BasicBlock] = Nil;
def addBlock(b: BasicBlock): Unit = blocks = b :: blocks;
override def toString() = "exh_" + label + "(" + cls.simpleName + ")";
def this(other: ExceptionHandler) = {
this(other.method, other.label, other.cls, other.pos)
covered = other.covered
setStartBlock(other.startBlock)
finalizer = other.finalizer
}
def dup: ExceptionHandler = new ExceptionHandler(this)
}
class Finalizer(method: IMethod, label: String, pos: Position) extends ExceptionHandler(method, label, NoSymbol, pos) {
override def toString() = "finalizer_" + label
override def dup: Finalizer = new Finalizer(method, label, pos)
}
object NoFinalizer extends Finalizer(null, "<no finalizer>", NoPosition) {
override def startBlock: BasicBlock = sys.error("NoFinalizer cannot have a start block.");
override def setStartBlock(b: BasicBlock): Unit = sys.error("NoFinalizer cannot have a start block.");
override def dup = this
}
}