Skip to content

Commit 1ce60bc

Browse files
authored
Merge pull request #10310 from dotty-staging/tasty-final-callback
Add a "terminal" callback to TastyInspector
2 parents c961308 + b8c33c7 commit 1ce60bc

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import dotty.tools.dotc.core.Mode
1111
import dotty.tools.dotc.core.Phases.Phase
1212
import dotty.tools.dotc.fromtasty._
1313
import dotty.tools.dotc.util.ClasspathFromClassloader
14+
import dotty.tools.dotc.CompilationUnit
15+
import dotty.tools.unsupported
1416

1517
import java.io.File.pathSeparator
1618

@@ -20,6 +22,9 @@ trait TastyInspector:
2022
/** Process a TASTy file using TASTy reflect */
2123
protected def processCompilationUnit(using QuoteContext)(root: qctx.reflect.Tree): Unit
2224

25+
/** Called after all compilation units are processed */
26+
protected def postProcess(using QuoteContext): Unit = ()
27+
2328
/** Load and process TASTy files using TASTy reflect
2429
*
2530
* @param tastyFiles List of paths of `.tasty` files
@@ -70,7 +75,8 @@ trait TastyInspector:
7075
override protected def transformPhases: List[List[Phase]] = Nil
7176

7277
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
7480
Nil
7581

7682
override def newRun(implicit ctx: Context): Run =
@@ -89,6 +95,19 @@ trait TastyInspector:
8995

9096
end TastyInspectorPhase
9197

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+
92111
val currentClasspath = ClasspathFromClassloader(getClass.getClassLoader)
93112
val fullClasspath = (classpath :+ currentClasspath).mkString(pathSeparator)
94113
val args = "-from-tasty" :: "-Yretain-trees" :: "-classpath" :: fullClasspath :: classes

0 commit comments

Comments
 (0)