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
|
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.{Context => BlackboxContext}
import scala.reflect.macros.whitebox.{Context => WhiteboxContext}
object Module {
type BBC = BlackboxContext
type RBBC = BBC { type PrefixType = C }
type WBC = WhiteboxContext
type RWBC = WBC { type PrefixType = C }
class BlackboxBundle(val c: BBC) {
import c.universe._
def impl = q"${c.prefix}"
}
class RefinedBlackboxBundle(val c: RBBC) {
import c.universe._
def impl = reify(c.prefix.splice)
}
class WhiteboxBundle(val c: WBC) {
import c.universe._
def impl = q"${c.prefix}"
}
class RefinedWhiteboxBundle(val c: RWBC) {
import c.universe._
def impl = reify(c.prefix.splice)
}
}
class C {
def blackbox: C = macro Module.BlackboxBundle.impl
def refinedBlackbox: C = macro Module.RefinedBlackboxBundle.impl
def whitebox: C = macro Module.WhiteboxBundle.impl
def refinedWhitebox: C = macro Module.RefinedWhiteboxBundle.impl
override def toString = "C"
}
|