diff options
author | Martin Odersky <odersky@gmail.com> | 2013-02-15 16:39:00 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-02-15 16:39:00 +0100 |
commit | ddb301187b471f002716e5c0ced98f3d4fae1781 (patch) | |
tree | 27a98c57e491daa53fd47a5f8d5c0a08b671cbb2 /src | |
parent | 5e219c1d8426da4fba6c4604e24f4bceb3573392 (diff) | |
download | dotty-ddb301187b471f002716e5c0ced98f3d4fae1781.tar.gz dotty-ddb301187b471f002716e5c0ced98f3d4fae1781.tar.bz2 dotty-ddb301187b471f002716e5c0ced98f3d4fae1781.zip |
Consolidating error handling in unpickler and classfileparser.
MissingRequirement eliminated; it got replaced by new StubSymbol handling.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/SymbolLoaders.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/ClassfileParser.scala | 27 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/pickling/UnPickler.scala | 44 | ||||
-rw-r--r-- | src/dotty/tools/package.scala | 4 |
4 files changed, 23 insertions, 56 deletions
diff --git a/src/dotty/tools/dotc/core/SymbolLoaders.scala b/src/dotty/tools/dotc/core/SymbolLoaders.scala index 191772fd2..8a5dd70d2 100644 --- a/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -178,9 +178,7 @@ abstract class SymbolLoader extends ClassCompleter { ctx.informTime("loaded " + description, start) } catch { case ex: IOException => - signalError(ex) - case ex: MissingRequirementError => - signalError(ex) + signalError(ex) } finally { root.linkedClass.denot match { case companion: LazyClassDenotation => companion.completer = null diff --git a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala index 2ece39dbb..9e9ea6257 100644 --- a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala +++ b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala @@ -31,39 +31,28 @@ class ClassfileParser( protected var currentClassName: Name = _ // JVM name of the current class protected var classTParams = Map[Name,Symbol]() - protected var srcfile0 : Option[AbstractFile] = None //needs freshing out + protected var srcfile0 : Option[AbstractFile] = None //needs fleshing out def srcfile = srcfile0 private def currentIsTopLevel = !(classRoot.name contains '$') private val mk = makeTypedTree - private def handleMissing(e: MissingRequirementError) = { - if (settings.debug.value) e.printStackTrace - throw new IOException("Missing dependency '" + e.req + "', required by " + in.file) - } - private def handleError(e: Exception) = { - if (settings.debug.value) e.printStackTrace() - throw new IOException("class file '%s' is broken\n(%s/%s)".format( - in.file, - e.getClass, - if (e.getMessage eq null) "" else e.getMessage) - ) - } private def mismatchError(c: Symbol) = { throw new IOException("class file '%s' has location not matching its contents: contains ".format(in.file) + c) } - private def parseErrorHandler[T]: PartialFunction[Throwable, T] = { - case e: MissingRequirementError => handleMissing(e) - case e: RuntimeException => handleError(e) - } - - def run(): Unit = { + def run(): Unit = try { debuglog("[class] >> " + classRoot.fullName) parseHeader this.pool = new ConstantPool parseClass() + } catch { + case e: RuntimeException => + if (settings.debug.value) e.printStackTrace() + throw new IOException( + s"""class file $classfile is broken, reading aborted with a + |${e.getClass}/${Option(e.getMessage).getOrElse("")}""".stripMargin) } private def parseHeader() { diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala index 6a4dff9e2..9822ac222 100644 --- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala +++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala @@ -18,6 +18,9 @@ import scala.annotation.switch object UnPickler { + /** Exception thrown if classfile is corrupted */ + class BadSignature(msg: String) extends RuntimeException(msg) + case class TempPolyType(tparams: List[Symbol], tpe: Type) extends UncachedGroundType /** Temporary type for classinfos, will be decomposed on completion of the class */ @@ -95,7 +98,13 @@ class UnPickler(bytes: Array[Byte], classRoot: LazyClassDenotation, moduleRoot: private val mk = makeTypedTree - //println("unpickled " + classRoot + ":" + classRoot.rawInfo + ", " + moduleRoot + ":" + moduleRoot.rawInfo);//debug + protected def errorBadSignature(msg: String) = { + val ex = new BadSignature( + s"""error reading Scala signature of $classRoot from $source: + |error occured at position $readIndex: $msg""".stripMargin) + /*if (settings.debug.value)*/ ex.printStackTrace() + throw ex + } // Laboriously unrolled for performance. def run() = @@ -129,13 +138,10 @@ class UnPickler(bytes: Array[Byte], classRoot: LazyClassDenotation, moduleRoot: i += 1 } } catch { - case ex: IOException => - throw ex - case ex: MissingRequirementError => + case ex: BadSignature => throw ex - case ex: Throwable => - /*if (settings.debug.value)*/ ex.printStackTrace() - throw new RuntimeException("error reading Scala signature of " + source + ": " + ex.getMessage()) + case ex: RuntimeException => + errorBadSignature(s"a runtime exception occured: $ex $ex.getMessage()") } def source: AbstractFile = { @@ -416,11 +422,7 @@ class UnPickler(bytes: Array[Byte], classRoot: LazyClassDenotation, moduleRoot: assignClassFields(denot, tp, selfType) } } - try { - atReadPos(denot.symbol.offset.value, parseToCompletion) - } catch { - case e: MissingRequirementError => throw toTypeError(e) - } + atReadPos(denot.symbol.offset.value, parseToCompletion) } private object symUnpickler extends SymCompleter { @@ -1007,22 +1009,4 @@ class UnPickler(bytes: Array[Byte], classRoot: LazyClassDenotation, moduleRoot: errorBadSignature("expected an TypeDef (" + other + ")") } */ - protected def errorBadSignature(msg: String) = - throw new RuntimeException("malformed Scala signature of " + classRoot.name + " at " + readIndex + "; " + msg) - - protected def errorMissingRequirement(name: Name, owner: Symbol): Symbol = - MissingRequirementError.signal( - s"bad reference while unpickling source: ${cctx.showDetailed(name)} not found in $owner") - - // def inferMethodAlternative(fun: Tree, argtpes: List[Type], restpe: Type) {} // can't do it; need a compiler for that. - - /** Convert to a type error, that is printed gracefully instead of crashing. - * - * Similar in intent to what SymbolLoader does (but here we don't have access to - * error reporting, so we rely on the typechecker to report the error). - */ - def toTypeError(e: MissingRequirementError) = { - // e.printStackTrace() - new TypeError(e.msg) - } } diff --git a/src/dotty/tools/package.scala b/src/dotty/tools/package.scala index eca4216ad..021e7360b 100644 --- a/src/dotty/tools/package.scala +++ b/src/dotty/tools/package.scala @@ -3,9 +3,5 @@ package dotty package object tools { type FatalError = scala.reflect.internal.FatalError val FatalError = scala.reflect.internal.FatalError - - type MissingRequirementError = scala.reflect.internal.MissingRequirementError - val MissingRequirementError = scala.reflect.internal.MissingRequirementError - val ListOfNil = List(Nil) } |