aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/Run.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc/Run.scala')
-rw-r--r--src/dotty/tools/dotc/Run.scala46
1 files changed, 37 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/Run.scala b/src/dotty/tools/dotc/Run.scala
index 928a59214..1c500c913 100644
--- a/src/dotty/tools/dotc/Run.scala
+++ b/src/dotty/tools/dotc/Run.scala
@@ -2,14 +2,20 @@ package dotty.tools
package dotc
import core._
-import Contexts._, Periods._, Symbols._, Phases._, Decorators._
+import Contexts._
+import Periods._
+import Symbols._
+import Phases._
+import Decorators._
import dotty.tools.dotc.transform.TreeTransforms.TreeTransformer
import io.PlainFile
-import util.{SourceFile, NoSource, Stats, SimpleMap}
+import util._
import reporting.Reporter
import transform.TreeChecker
import rewrite.Rewrites
import java.io.{BufferedWriter, OutputStreamWriter}
+
+import scala.annotation.tailrec
import scala.reflect.io.VirtualFile
import scala.util.control.NonFatal
@@ -56,26 +62,48 @@ class Run(comp: Compiler)(implicit ctx: Context) {
val phases = ctx.squashPhases(ctx.phasePlan,
ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, ctx.settings.YstopAfter.value, ctx.settings.Ycheck.value)
ctx.usePhases(phases)
+ var lastPrintedTree: PrintedTree = NoPrintedTree
for (phase <- ctx.allPhases)
if (!ctx.reporter.hasErrors) {
val start = System.currentTimeMillis
units = phase.runOn(units)
- 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.Xprint.value.containsPhase(phase)) {
+ for (unit <- units) {
+ lastPrintedTree =
+ printTree(lastPrintedTree)(ctx.fresh.setPhase(phase.next).setCompilationUnit(unit))
+ }
+ }
ctx.informTime(s"$phase ", start)
}
if (!ctx.reporter.hasErrors) Rewrites.writeBack()
}
- private def printTree(ctx: Context) = {
+ private sealed trait PrintedTree
+ private final case class SomePrintedTree(phase: String, tree: String) extends PrintedTree
+ private object NoPrintedTree extends PrintedTree
+
+ private def printTree(last: PrintedTree)(implicit ctx: Context): PrintedTree = {
val unit = ctx.compilationUnit
val prevPhase = ctx.phase.prev // can be a mini-phase
val squashedPhase = ctx.squashed(prevPhase)
+ val treeString = unit.tpdTree.show
+
+ ctx.echo(s"result of $unit after $squashedPhase:")
- ctx.echo(s"result of $unit after ${squashedPhase}:")
- ctx.echo(unit.tpdTree.show(ctx))
+ last match {
+ case SomePrintedTree(phase, lastTreeSting) if lastTreeSting != treeString =>
+ val diff = DiffUtil.mkColoredCodeDiff(treeString, lastTreeSting, ctx.settings.XprintDiffDel.value)
+ ctx.echo(diff)
+ SomePrintedTree(squashedPhase.toString, treeString)
+
+ case SomePrintedTree(phase, lastTreeSting) =>
+ ctx.echo(" Unchanged since " + phase)
+ last
+
+ case NoPrintedTree =>
+ ctx.echo(treeString)
+ SomePrintedTree(squashedPhase.toString, treeString)
+ }
}
def compile(sourceCode: String): Unit = {