From fc4648d33a051ff5d220c2fea097fc99b5883ecc Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 29 Mar 2014 15:05:07 +0100 Subject: Add -Ycheck capability Right now uses a super-rudementary tree checker: we only check that every tree has a type. --- src/dotty/tools/dotc/Run.scala | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/dotty/tools/dotc/Run.scala') diff --git a/src/dotty/tools/dotc/Run.scala b/src/dotty/tools/dotc/Run.scala index 3f15bd4c3..264373baf 100644 --- a/src/dotty/tools/dotc/Run.scala +++ b/src/dotty/tools/dotc/Run.scala @@ -6,6 +6,7 @@ import Contexts._, Periods._, Symbols._, Phases._, Decorators._ import io.PlainFile import util.{SourceFile, NoSource, Stats, SimpleMap} import reporting.Reporter +import transform.TreeChecker import java.io.{BufferedWriter, OutputStreamWriter} import scala.reflect.io.VirtualFile @@ -39,18 +40,19 @@ class Run(comp: Compiler)(implicit ctx: Context) { for (phase <- phasesToRun) { if (!ctx.reporter.hasErrors) { phase.runOn(units) - if (ctx.settings.Xprint.value.containsPhase(phase)) - for (unit <- units) - printTree(ctx.fresh.setPhase(phase).setCompilationUnit(unit)) + def foreachUnit(op: Context => Unit)(implicit ctx: Context): Unit = + for (unit <- units) op(ctx.fresh.setPhase(phase.next).setCompilationUnit(unit)) + if (ctx.settings.Xprint.value.containsPhase(phase)) foreachUnit(printTree) + if (ctx.settings.Ycheck.value.containsPhase(phase)) foreachUnit(TreeChecker.check) } } } } - private def printTree(implicit ctx: Context) = { + private def printTree(ctx: Context) = { val unit = ctx.compilationUnit println(s"result of $unit after ${ctx.phase}:") - println(unit.tpdTree.show) + println(unit.tpdTree.show(ctx)) } def compile(sourceCode: String): Unit = { -- cgit v1.2.3