@@ -2,14 +2,20 @@ package dotty.tools
2
2
package dotc
3
3
4
4
import core ._
5
- import Contexts ._ , Periods ._ , Symbols ._ , Phases ._ , Decorators ._
5
+ import Contexts ._
6
+ import Periods ._
7
+ import Symbols ._
8
+ import Phases ._
9
+ import Decorators ._
6
10
import dotty .tools .dotc .transform .TreeTransforms .TreeTransformer
7
11
import io .PlainFile
8
- import util .{ SourceFile , NoSource , Stats , SimpleMap }
12
+ import util ._
9
13
import reporting .Reporter
10
14
import transform .TreeChecker
11
15
import rewrite .Rewrites
12
16
import java .io .{BufferedWriter , OutputStreamWriter }
17
+
18
+ import scala .annotation .tailrec
13
19
import scala .reflect .io .VirtualFile
14
20
import scala .util .control .NonFatal
15
21
@@ -56,26 +62,48 @@ class Run(comp: Compiler)(implicit ctx: Context) {
56
62
val phases = ctx.squashPhases(ctx.phasePlan,
57
63
ctx.settings.Yskip .value, ctx.settings.YstopBefore .value, ctx.settings.YstopAfter .value, ctx.settings.Ycheck .value)
58
64
ctx.usePhases(phases)
65
+ var lastPrintedTree : PrintedTree = NoPrintedTree
59
66
for (phase <- ctx.allPhases)
60
67
if (! ctx.reporter.hasErrors) {
61
68
val start = System .currentTimeMillis
62
69
units = phase.runOn(units)
63
- def foreachUnit (op : Context => Unit )(implicit ctx : Context ): Unit =
64
- for (unit <- units) op(ctx.fresh.setPhase(phase.next).setCompilationUnit(unit))
65
- if (ctx.settings.Xprint .value.containsPhase(phase))
66
- foreachUnit(printTree)
70
+ if (ctx.settings.Xprint .value.containsPhase(phase)) {
71
+ for (unit <- units) {
72
+ lastPrintedTree =
73
+ printTree(lastPrintedTree)(ctx.fresh.setPhase(phase.next).setCompilationUnit(unit))
74
+ }
75
+ }
67
76
ctx.informTime(s " $phase " , start)
68
77
}
69
78
if (! ctx.reporter.hasErrors) Rewrites .writeBack()
70
79
}
71
80
72
- private def printTree (ctx : Context ) = {
81
+ private sealed trait PrintedTree
82
+ private final case class SomePrintedTree (phase : String , tree : String ) extends PrintedTree
83
+ private object NoPrintedTree extends PrintedTree
84
+
85
+ private def printTree (last : PrintedTree )(implicit ctx : Context ): PrintedTree = {
73
86
val unit = ctx.compilationUnit
74
87
val prevPhase = ctx.phase.prev // can be a mini-phase
75
88
val squashedPhase = ctx.squashed(prevPhase)
89
+ val treeString = unit.tpdTree.show
90
+
91
+ ctx.echo(s " result of $unit after $squashedPhase: " )
76
92
77
- ctx.echo(s " result of $unit after ${squashedPhase}: " )
78
- ctx.echo(unit.tpdTree.show(ctx))
93
+ last match {
94
+ case SomePrintedTree (phase, lastTreeSting) if lastTreeSting != treeString =>
95
+ val diff = DiffUtil .mkColoredCodeDiff(treeString, lastTreeSting, ctx.settings.XprintDiffDel .value)
96
+ ctx.echo(diff)
97
+ SomePrintedTree (squashedPhase.toString, treeString)
98
+
99
+ case SomePrintedTree (phase, lastTreeSting) =>
100
+ ctx.echo(" Unchanged since " + phase)
101
+ last
102
+
103
+ case NoPrintedTree =>
104
+ ctx.echo(treeString)
105
+ SomePrintedTree (squashedPhase.toString, treeString)
106
+ }
79
107
}
80
108
81
109
def compile (sourceCode : String ): Unit = {
0 commit comments