@@ -11,6 +11,8 @@ import dotty.tools.dotc.core.Mode
11
11
import dotty .tools .dotc .core .Phases .Phase
12
12
import dotty .tools .dotc .fromtasty ._
13
13
import dotty .tools .dotc .util .ClasspathFromClassloader
14
+ import dotty .tools .dotc .CompilationUnit
15
+ import dotty .tools .unsupported
14
16
15
17
import java .io .File .pathSeparator
16
18
@@ -20,6 +22,9 @@ trait TastyInspector:
20
22
/** Process a TASTy file using TASTy reflect */
21
23
protected def processCompilationUnit (using QuoteContext )(root : qctx.reflect.Tree ): Unit
22
24
25
+ /** Called after all compilation units are processed */
26
+ protected def postProcess (using QuoteContext ): Unit = ()
27
+
23
28
/** Load and process TASTy files using TASTy reflect
24
29
*
25
30
* @param tastyFiles List of paths of `.tasty` files
@@ -70,7 +75,8 @@ trait TastyInspector:
70
75
override protected def transformPhases : List [List [Phase ]] = Nil
71
76
72
77
override protected def backendPhases : List [List [Phase ]] =
73
- List (new TastyInspectorPhase ) :: // Print all loaded classes
78
+ List (new TastyInspectorPhase ) :: // Perform a callback for each compilation unit
79
+ List (new TastyInspectorFinishPhase ) :: // Perform a final callback
74
80
Nil
75
81
76
82
override def newRun (implicit ctx : Context ): Run =
@@ -89,6 +95,19 @@ trait TastyInspector:
89
95
90
96
end TastyInspectorPhase
91
97
98
+ class TastyInspectorFinishPhase extends Phase :
99
+
100
+ override def phaseName : String = " tastyInspectorFinish"
101
+
102
+ override def runOn (units : List [CompilationUnit ])(using Context ): List [CompilationUnit ] =
103
+ val qctx = QuoteContextImpl ()
104
+ self.postProcess(using qctx)
105
+ units
106
+
107
+ override def run (implicit ctx : Context ): Unit = unsupported(" run" )
108
+
109
+ end TastyInspectorFinishPhase
110
+
92
111
val currentClasspath = ClasspathFromClassloader (getClass.getClassLoader)
93
112
val fullClasspath = (classpath :+ currentClasspath).mkString(pathSeparator)
94
113
val args = " -from-tasty" :: " -Yretain-trees" :: " -classpath" :: fullClasspath :: classes
0 commit comments