@@ -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
*
@@ -72,26 +83,26 @@ trait TastyInspector:
72
83
73
84
private def inspectorDriver () =
74
85
class InspectorDriver extends Driver :
75
- override protected def newCompiler (implicit ctx : Context ): Compiler = new TastyFromClass
86
+ override protected def newCompiler (implicit ctx : Context ): Compiler =
87
+ val visitor = tastyVisitor(using QuotesImpl ())
88
+ new TastyFromClass (visitor)
76
89
77
- class TastyInspectorPhase extends Phase :
90
+ class TastyInspectorPhase ( visitor : TastyVisitor ) extends Phase :
78
91
override def phaseName : String = " tastyInspector"
79
92
80
93
override def run (implicit ctx : Context ): Unit =
81
- val qctx = QuotesImpl ()
82
- self.processCompilationUnit(using qctx)(ctx.compilationUnit.tpdTree.asInstanceOf [qctx.reflect.Tree ])
94
+ visitor.processCompilationUnit(ctx.compilationUnit.tpdTree.asInstanceOf [visitor.quotes.reflect.Tree ])
83
95
84
- class TastyInspectorFinishPhase extends Phase :
96
+ class TastyInspectorFinishPhase ( visitor : TastyVisitor ) extends Phase :
85
97
override def phaseName : String = " tastyInspectorFinish"
86
98
87
99
override def runOn (units : List [CompilationUnit ])(using Context ): List [CompilationUnit ] =
88
- val qctx = QuotesImpl ()
89
- self.postProcess(using qctx)
100
+ visitor.postProcess()
90
101
units
91
102
92
103
override def run (implicit ctx : Context ): Unit = unsupported(" run" )
93
104
94
- class TastyFromClass extends TASTYCompiler :
105
+ class TastyFromClass ( visitor : TastyVisitor ) extends TASTYCompiler :
95
106
96
107
override protected def frontendPhases : List [List [Phase ]] =
97
108
List (new ReadTasty ) :: // Load classes from tasty
@@ -102,8 +113,8 @@ trait TastyInspector:
102
113
override protected def transformPhases : List [List [Phase ]] = Nil
103
114
104
115
override protected def backendPhases : List [List [Phase ]] =
105
- List (new TastyInspectorPhase ) :: // Perform a callback for each compilation unit
106
- List (new TastyInspectorFinishPhase ) :: // Perform a final callback
116
+ List (new TastyInspectorPhase (visitor) ) :: // Perform a callback for each compilation unit
117
+ List (new TastyInspectorFinishPhase (visitor) ) :: // Perform a final callback
107
118
Nil
108
119
109
120
override def newRun (implicit ctx : Context ): Run =
0 commit comments