-
Notifications
You must be signed in to change notification settings - Fork 20
/
SelectTreeTransform.scala
57 lines (39 loc) · 1.68 KB
/
SelectTreeTransform.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package cps.macros.forest
import scala.quoted._
import cps._
import cps.macros._
import cps.macros.misc._
trait SelectTreeTransform[F[_], CT, CC<:CpsMonadContext[F]]:
thisScope: TreeTransformScope[F, CT, CC] =>
import quotes.reflect._
// case selectTerm @ Select(qualifier,name)
def runSelect( selectTerm: Select )(owner: Symbol): CpsTree = {
val symbol = selectTerm.symbol
val qual = runRoot(selectTerm.qualifier)(owner)
val r = if (qual.isSync && !qual.isChanged) then {
CpsTree.pure(owner, selectTerm)
} else {
qual.select(selectTerm, symbol, selectTerm.tpe)
}
r
}
end SelectTreeTransform
object SelectTreeTransform:
def run[F[_]:Type,T:Type, C<:CpsMonadContext[F]:Type](using qctx1: Quotes)(cpsCtx1: TransformationContext[F,T,C],
selectTerm: qctx1.reflect.Select): CpsExpr[F,T] = {
val tmpFType = summon[Type[F]]
val tmpCTType = summon[Type[T]]
val tmpCCType = summon[Type[C]]
class Bridge(tc:TransformationContext[F,T,C]) extends
TreeTransformScope[F,T,C]
with TreeTransformScopeInstance[F,T,C](tc) {
implicit val fType: quoted.Type[F] = tmpFType
implicit val ctType: quoted.Type[T] = tmpCTType
implicit val ccType: quoted.Type[C] = tmpCCType
def bridge(): CpsExpr[F,T] =
val origin = selectTerm.asInstanceOf[quotes.reflect.Select]
val owner = quotes.reflect.Symbol.spliceOwner
runSelect(origin)(owner).toResult[T]
}
(new Bridge(cpsCtx1)).bridge()
}