summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/macros/WhiteboxMacro.scala
blob: 1c581313eb83cb98625402eee4588cf965b94553 (plain) (blame)
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
package scala.reflect
package macros

/**
 * <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
 *
 *  Traditionally macro implementations are defined as methods,
 *  but this trait provides an alternative way of encoding macro impls as
 *  bundles, traits which extend `scala.reflect.macros.BlackboxMacro` or`scala.reflect.macros.WhiteboxMacro` .
 *
 *  Instead of:
 *
 *    def impl[T: c.WeakTypeTag](c: WhiteboxContext)(x: c.Expr[Int]) = ...
 *
 *  One can write:
 *
 *    trait Impl extends WhiteboxMacro {
 *      def apply[T: c.WeakTypeTag](x: c.Expr[Int]) = ...
 *    }
 *
 *  Without changing anything else at all.
 *
 *  This language feature is useful in itself in cases when macro implementations
 *  are complex and need to be modularized. State of the art technique of addressing this need is quite heavyweight:
 *  http://docs.scala-lang.org/overviews/macros/overview.html#writing_bigger_macros.
 *
 *  @see `scala.reflect.macros.BlackboxMacro`
 */
trait WhiteboxMacro {
  /** The context to be used by the macro implementation.
   *
   *  Vanilla macro implementations have to carry it in their signatures, however when a macro is a full-fledged module,
   *  it can define the context next to the implementation, makes implementation signature more lightweight.
   */
  val c: WhiteboxContext
}