diff options
author | Paul Phillips <paulp@improving.org> | 2012-05-06 16:12:33 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-05-23 08:43:09 -0700 |
commit | 0d7952f90fc11f4dc055a2658b16b7183f1d6683 (patch) | |
tree | d416563515bb1df6cc97dcef7b00e5bd88adc1f3 /src/compiler | |
parent | 2ed32de2a7cee223815c7eaccb559057a3348d84 (diff) | |
download | scala-0d7952f90fc11f4dc055a2658b16b7183f1d6683.tar.gz scala-0d7952f90fc11f4dc055a2658b16b7183f1d6683.tar.bz2 scala-0d7952f90fc11f4dc055a2658b16b7183f1d6683.zip |
Cleanups in Treecheckers.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala index a6a8d6009f..fde760c752 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TreeCheckers.scala @@ -14,22 +14,7 @@ import util.returning abstract class TreeCheckers extends Analyzer { import global._ - private val everything = ListBuffer[(Phase, Map[Tree, (Symbol, Type)])]() - private val currentTrees = mutable.Map[Tree, (Symbol, Type)]() - private val tpeOfTree = mutable.HashMap[Tree, Type]() - - if (settings.debug.value) { - sys addShutdownHook { - for ((ph, map) <- everything.toList) { - println("\n>>>> " + ph + "\n") - for ((tree, (sym, tpe)) <- map.toList.sortBy(_._1.summaryString)) { - println("%20s %20s %s".format(sym, tpe, ("" + tree) take 50)) - } - } - } - } - - private def classstr(x: AnyRef) = (x.getClass.getName split """\\.|\\$""").last + private def classstr(x: AnyRef) = x.getClass.getName split """\\.|\\$""" last; private def typestr(x: Type) = " (tpe = " + x + ")" private def treestr(t: Tree) = t + " [" + classstr(t) + "]" + typestr(t.tpe) private def ownerstr(s: Symbol) = "'" + s + "'" + s.locationString @@ -50,14 +35,13 @@ abstract class TreeCheckers extends Analyzer { object SymbolTracker extends Traverser { type PhaseMap = mutable.HashMap[Symbol, List[Tree]] - val defSyms = mutable.HashMap[Symbol, List[DefTree]]() withDefaultValue Nil - val newSyms = mutable.HashSet[Symbol]() val maps = ListBuffer[(Phase, PhaseMap)]() - val movedMsgs = ListBuffer[String]() - def prev = maps.init.last._2 def latest = maps.last._2 - def sortedNewSyms = newSyms.toList.distinct sortBy (_.name) + val defSyms = mutable.HashMap[Symbol, List[DefTree]]() + val newSyms = mutable.HashSet[Symbol]() + val movedMsgs = new ListBuffer[String] + def sortedNewSyms = newSyms.toList.distinct sortBy (_.name.toString) def inPrev(sym: Symbol) = { (maps.size >= 2) && (prev contains sym) @@ -108,21 +92,18 @@ abstract class TreeCheckers extends Analyzer { if (maps.isEmpty || maps.last._1 != ph) maps += ((ph, new PhaseMap)) - currentTrees.clear() traverse(unit.body) - everything += ((ph, currentTrees.toMap)) - reportChanges() } override def traverse(tree: Tree): Unit = { val sym = tree.symbol - currentTrees(tree) = ((sym, tree.tpe)) - if (sym != null && sym != NoSymbol) { record(sym, tree) tree match { - case x: DefTree => defSyms(sym) :+= x - case _ => () + case x: DefTree => + if (defSyms contains sym) defSyms(sym) = defSyms(sym) :+ x + else defSyms(sym) = List(x) + case _ => () } } @@ -130,6 +111,8 @@ abstract class TreeCheckers extends Analyzer { } } + lazy val tpeOfTree = mutable.HashMap[Tree, Type]() + def posstr(p: Position) = try p.source.path + ":" + p.line catch { case _: UnsupportedOperationException => p.toString } @@ -144,9 +127,20 @@ abstract class TreeCheckers extends Analyzer { def assertFn(cond: Boolean, msg: => Any) = if (!cond) errorFn(msg) + private def wrap[T](msg: => Any)(body: => Unit) { + try body + catch { case x => + Console.println("Caught " + x) + Console.println(msg) + x.printStackTrace + } + } + def checkTrees() { - informFn("[consistency check at the beginning of phase " + phase + "]") - currentRun.units foreach check + if (settings.verbose.value) + Console.println("[consistency check at the beginning of phase " + phase + "]") + + currentRun.units foreach (x => wrap(x)(check(x))) } def printingTypings[T](body: => T): T = { @@ -168,7 +162,7 @@ abstract class TreeCheckers extends Analyzer { informProgress("checking "+unit) val context = rootContext(unit) context.checking = true - tpeOfTree.clear() + tpeOfTree.clear SymbolTracker.check(phase, unit) val checker = new TreeChecker(context) runWithUnit(unit) { @@ -215,11 +209,11 @@ abstract class TreeCheckers extends Analyzer { tree.tpe = null saved }) - super.typed(tree, mode, pt) match { + wrap(tree)(super.typed(tree, mode, pt) match { case _: Literal => () case x if x ne tree => treesDiffer(tree, x) case _ => () - } + }) case _ => () } @@ -286,7 +280,12 @@ abstract class TreeCheckers extends Analyzer { if (sym.owner != currentOwner) { val expected = currentOwner.ownerChain find (x => cond(x)) getOrElse fail("DefTree can't find owner: ") if (sym.owner != expected) - fail("Expected owner %s (out of %s), found %s: ".format(expected, currentOwner.ownerChain, sym.owner)) + fail("""| + | currentOwner chain: %s + | symbol chain: %s""".stripMargin.format( + currentOwner.ownerChain take 3 mkString " -> ", + sym.ownerChain mkString " -> ") + ) } } } |