@@ -20,6 +20,9 @@ trait TastyInspector:
2020 /** Process a TASTy file using TASTy reflect */
2121 protected def processCompilationUnit (using QuoteContext )(root : qctx.reflect.Tree ): Unit
2222
23+ /** Called after all compilation units are processed */
24+ protected def finishProcessingCompilationUnits (using QuoteContext ): Unit = ()
25+
2326 /** Load and process TASTy files using TASTy reflect
2427 *
2528 * @param tastyFiles List of paths of `.tasty` files
@@ -70,7 +73,8 @@ trait TastyInspector:
7073 override protected def transformPhases : List [List [Phase ]] = Nil
7174
7275 override protected def backendPhases : List [List [Phase ]] =
73- List (new TastyInspectorPhase ) :: // Print all loaded classes
76+ List (new TastyInspectorPhase ) :: // Perform a callback for each compilation unit
77+ List (new TastyInspectorFinishPhase ) :: // Perform a final callback
7478 Nil
7579
7680 override def newRun (implicit ctx : Context ): Run =
@@ -89,6 +93,19 @@ trait TastyInspector:
8993
9094 end TastyInspectorPhase
9195
96+ class TastyInspectorFinishPhase extends Phase :
97+
98+ override def phaseName : String = " tastyInspectorFinish"
99+
100+ override def run (implicit ctx : Context ): Unit =
101+ if ! alreadyRan then
102+ val qctx = QuoteContextImpl ()
103+ self.finishProcessingCompilationUnits(using qctx)
104+ alreadyRan = true
105+
106+ var alreadyRan = false
107+ end TastyInspectorFinishPhase
108+
92109 val currentClasspath = ClasspathFromClassloader (getClass.getClassLoader)
93110 val fullClasspath = (classpath :+ currentClasspath).mkString(pathSeparator)
94111 val args = " -from-tasty" :: " -Yretain-trees" :: " -classpath" :: fullClasspath :: classes
0 commit comments