@@ -20,11 +20,22 @@ import java.io.File.pathSeparator
20
20
trait TastyInspector :
21
21
self =>
22
22
23
+ trait TastyVisitor (using val quotes : Quotes ):
24
+ def processCompilationUnit (root : quotes.reflect.Tree ): Unit
25
+ def postProcess (): Unit = ()
26
+
27
+ protected def tastyVisitor (using q : Quotes ): TastyVisitor = new {
28
+ def processCompilationUnit (root : quotes.reflect.Tree ): Unit =
29
+ TastyInspector .this .processCompilationUnit(root)
30
+ override def postProcess (): Unit =
31
+ TastyInspector .this .postProcess()
32
+ }
33
+
23
34
/** Process a TASTy file using TASTy reflect */
24
35
protected def processCompilationUnit (using Quotes )(root : quotes.reflect.Tree ): Unit
25
36
26
37
/** Called after all compilation units are processed */
27
- protected def postProcess (using Quotes ): Unit = ()
38
+ protected def postProcess (using Quotes )() : Unit = ()
28
39
29
40
/** Load and process TASTy files using TASTy reflect
30
41
*
@@ -71,22 +82,27 @@ trait TastyInspector:
71
82
72
83
73
84
private def inspectorDriver () =
85
+ var visitor : TastyVisitor = null
74
86
class InspectorDriver extends Driver :
75
- override protected def newCompiler (implicit ctx : Context ): Compiler = new TastyFromClass
87
+ override protected def newCompiler (implicit ctx : Context ): Compiler =
88
+ new TastyFromClass
76
89
77
90
class TastyInspectorPhase extends Phase :
78
91
override def phaseName : String = " tastyInspector"
79
92
93
+ override def runOn (units : List [CompilationUnit ])(using Context ): List [CompilationUnit ] =
94
+ visitor = tastyVisitor(using QuotesImpl ())
95
+ super .runOn(units)
96
+
80
97
override def run (implicit ctx : Context ): Unit =
81
- val qctx = QuotesImpl ()
82
- self .processCompilationUnit(using qctx)( ctx.compilationUnit.tpdTree.asInstanceOf [qctx .reflect.Tree ])
98
+ val v = visitor
99
+ v .processCompilationUnit(ctx.compilationUnit.tpdTree.asInstanceOf [v.quotes .reflect.Tree ])
83
100
84
101
class TastyInspectorFinishPhase extends Phase :
85
102
override def phaseName : String = " tastyInspectorFinish"
86
103
87
104
override def runOn (units : List [CompilationUnit ])(using Context ): List [CompilationUnit ] =
88
- val qctx = QuotesImpl ()
89
- self.postProcess(using qctx)
105
+ visitor.postProcess()
90
106
units
91
107
92
108
override def run (implicit ctx : Context ): Unit = unsupported(" run" )
0 commit comments