Skip to content

Try to fix paths in TastyInspector #10777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CommentExpanderTests {

def processCompilationUnit(using quoted.Quotes)(root: quotes.reflect.Tree): Unit = ()

override def postProcess(using quoted.Quotes): Unit =
override def postProcess(using quoted.Quotes)(): Unit =
check()

Inspector().inspectTastyFiles(TestUtils.listOurClasses())
Expand Down
28 changes: 22 additions & 6 deletions tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,22 @@ import java.io.File.pathSeparator
trait TastyInspector:
self =>

trait TastyVisitor(using val quotes: Quotes):
def processCompilationUnit(root: quotes.reflect.Tree): Unit
def postProcess(): Unit = ()

protected def tastyVisitor(using q: Quotes): TastyVisitor = new {
def processCompilationUnit(root: quotes.reflect.Tree): Unit =
TastyInspector.this.processCompilationUnit(root)
override def postProcess(): Unit =
TastyInspector.this.postProcess()
}

/** Process a TASTy file using TASTy reflect */
protected def processCompilationUnit(using Quotes)(root: quotes.reflect.Tree): Unit

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

/** Load and process TASTy files using TASTy reflect
*
Expand Down Expand Up @@ -71,22 +82,27 @@ trait TastyInspector:


private def inspectorDriver() =
var visitor: TastyVisitor = null
class InspectorDriver extends Driver:
override protected def newCompiler(implicit ctx: Context): Compiler = new TastyFromClass
override protected def newCompiler(implicit ctx: Context): Compiler =
new TastyFromClass

class TastyInspectorPhase extends Phase:
override def phaseName: String = "tastyInspector"

override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
visitor = tastyVisitor(using QuotesImpl())
super.runOn(units)

override def run(implicit ctx: Context): Unit =
val qctx = QuotesImpl()
self.processCompilationUnit(using qctx)(ctx.compilationUnit.tpdTree.asInstanceOf[qctx.reflect.Tree])
val v = visitor
v.processCompilationUnit(ctx.compilationUnit.tpdTree.asInstanceOf[v.quotes.reflect.Tree])

class TastyInspectorFinishPhase extends Phase:
override def phaseName: String = "tastyInspectorFinish"

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

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