Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import dotty.tools.dotc.core.Mode
import dotty.tools.dotc.core.Phases.Phase
import dotty.tools.dotc.fromtasty._
import dotty.tools.dotc.util.ClasspathFromClassloader
import dotty.tools.dotc.CompilationUnit
import dotty.tools.unsupported

import java.io.File.pathSeparator

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

/** Called after all compilation units are processed */
protected def postProcess(using QuoteContext): Unit = ()

/** Load and process TASTy files using TASTy reflect
*
* @param tastyFiles List of paths of `.tasty` files
Expand Down Expand Up @@ -70,7 +75,8 @@ trait TastyInspector:
override protected def transformPhases: List[List[Phase]] = Nil

override protected def backendPhases: List[List[Phase]] =
List(new TastyInspectorPhase) :: // Print all loaded classes
List(new TastyInspectorPhase) :: // Perform a callback for each compilation unit
List(new TastyInspectorFinishPhase) :: // Perform a final callback
Nil

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

end TastyInspectorPhase

class TastyInspectorFinishPhase extends Phase:

override def phaseName: String = "tastyInspectorFinish"

override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
val qctx = QuoteContextImpl()
self.postProcess(using qctx)
units

override def run(implicit ctx: Context): Unit = unsupported("run")

end TastyInspectorFinishPhase

val currentClasspath = ClasspathFromClassloader(getClass.getClassLoader)
val fullClasspath = (classpath :+ currentClasspath).mkString(pathSeparator)
val args = "-from-tasty" :: "-Yretain-trees" :: "-classpath" :: fullClasspath :: classes
Expand Down