Scala Compiler2.12.3-1 < Back
 

# Packages

-  package root

  The Scala compiler and reflection APIs.

  The Scala compiler and reflection APIs.

  Definition Classes
    root
-  package scala
  Definition Classes
    root
-  package tools
  Definition Classes
    scala
-  package nsc
  Definition Classes
    tools
-  package typechecker
  Definition Classes
    nsc
-  trait Macros extends MacroRuntimes with Traces with Helpers

  Code to deal with macros, namely with: * Compilation of macro definitions * Expansion of macro applications

  Code to deal with macros, namely with: * Compilation of macro definitions * Expansion of macro applications

  Say we have in a class C:

  def foo[T](xs: List[T]): T = macro fooBar

  Then fooBar needs to point to a static method of the following form:

  def fooBar[T: c.WeakTypeTag] // type tag annotation is optional (c: scala.reflect.macros.blackbox.Context) (xs: c.Expr[List[T]]) : c.Expr[T] = { ... }

  Then, if foo is called in qual.foo[Int](elems), where qual: D, the macro application is expanded to a reflective invocation of fooBar with parameters:

  (simpleMacroContext{ type PrefixType = D; val prefix = qual }) (Expr(elems)) (TypeTag(Int))

  Definition Classes
    typechecker
- DefMacroExpander
- Delayed
- Failure
- Fallback
- JavaReflectionResolvers
- MacroArgs
- MacroExpander
- MacroImplBinding
- MacroRuntimeResolver
- MacroStatus
- Skipped
- Success

c

scala.tools.nsc.typechecker.Macros

# MacroExpander 

###

#### abstract class MacroExpander extends AnyRef

Performs macro expansion:

###### Expandable trees

A term of one of the following shapes:

Ident(<term macro>) Select(<any qualifier>, <term macro>) TypeApply(<any of the above>, <targs>) Apply(...Apply(<any of the above>, <args1>)...<argsN>)

###### Macro expansion

First of all `macroExpandXXX`: 1) If necessary desugars the `expandee` to fit into the default expansion scheme that is understood by `macroExpandWithRuntime` / `macroExpandWithoutRuntime`

Then `macroExpandWithRuntime`: 2) Checks whether the expansion needs to be delayed 3) Loads macro implementation using `macroMirror` 4) Synthesizes invocation arguments for the macro implementation 5) Checks that the result is a tree or an expr bound to this universe

Finally `macroExpandXXX`: 6) Validates the expansion against the white list of supported tree shapes 7) Typechecks the result as required by the circumstances of the macro application

If -Ymacro-debug-lite is enabled, you will get basic notifications about macro expansion along with macro expansions logged in the form that can be copy/pasted verbatim into REPL.

If -Ymacro-debug-verbose is enabled, you will get detailed log of how exactly this function performs class loading and method resolution in order to load the macro implementation. The log will also include other non-trivial steps of macro expansion.

returns

  the expansion result if the expansion has been successful, the fallback tree if the expansion has been unsuccessful, but there is a fallback, the expandee unchanged if the expansion has been delayed, the expandee fully expanded if the expansion has been delayed before and has been expanded now, the expandee with an error marker set if the expansion has been cancelled due malformed arguments or implementation the expandee with an error marker set if there has been an error

Source
  Macros.scala

Linear Supertypes
AnyRef, Any
Known Subclasses
DefMacroExpander
Type Hierarchy
 
Ordering

1. Alphabetic
2. By Inheritance

Inherited

1. MacroExpander
2. AnyRef
3. Any

Implicitly

1. by any2stringadd
2. by StringFormat
3. by Ensuring
4. by ArrowAssoc

1. Hide All
2. Show All

Visibility

1. Public
2. All

### Instance Constructors

1.  new MacroExpander(typer: Analyzer.Typer, expandee: Global.Tree)

### Abstract Value Members

1.  abstract def onFallback(expanded: Global.Tree): Global.Tree
2.  abstract def onSuccess(expanded: Global.Tree): Global.Tree

### Concrete Value Members

1.  final def !=(arg0: Any): Boolean
   Definition Classes
     AnyRef → Any
2.  final def ##(): Int
   Definition Classes
     AnyRef → Any
3.  def +(other: String): String
   Implicit
     This member is added by an implicit conversion from Analyzer.MacroExpander to any2stringadd[Analyzer.MacroExpander] performed by method any2stringadd in scala.Predef.
   Definition Classes
     any2stringadd
4.  def ->[B](y: B): (Analyzer.MacroExpander, B)
   Implicit
     This member is added by an implicit conversion from Analyzer.MacroExpander to ArrowAssoc[Analyzer.MacroExpander] performed by method ArrowAssoc in scala.Predef.
   Definition Classes
     ArrowAssoc
   Annotations
     @inline()
5.  final def ==(arg0: Any): Boolean
   Definition Classes
     AnyRef → Any
6.  def apply(desugared: Global.Tree): Global.Tree
7.  final def asInstanceOf[T0]: T0
   Definition Classes
     Any
8.  def clone(): AnyRef
   Attributes
     protected[java.lang]
   Definition Classes
     AnyRef
   Annotations
     @throws( ... )
9.  def ensuring(cond: (Analyzer.MacroExpander) ⇒ Boolean, msg: ⇒ Any): Analyzer.MacroExpander
   Implicit
     This member is added by an implicit conversion from Analyzer.MacroExpander to Ensuring[Analyzer.MacroExpander] performed by method Ensuring in scala.Predef.
   Definition Classes
     Ensuring
10.  def ensuring(cond: (Analyzer.MacroExpander) ⇒ Boolean): Analyzer.MacroExpander
    Implicit
      This member is added by an implicit conversion from Analyzer.MacroExpander to Ensuring[Analyzer.MacroExpander] performed by method Ensuring in scala.Predef.
    Definition Classes
      Ensuring
11.  def ensuring(cond: Boolean, msg: ⇒ Any): Analyzer.MacroExpander
    Implicit
      This member is added by an implicit conversion from Analyzer.MacroExpander to Ensuring[Analyzer.MacroExpander] performed by method Ensuring in scala.Predef.
    Definition Classes
      Ensuring
12.  def ensuring(cond: Boolean): Analyzer.MacroExpander
    Implicit
      This member is added by an implicit conversion from Analyzer.MacroExpander to Ensuring[Analyzer.MacroExpander] performed by method Ensuring in scala.Predef.
    Definition Classes
      Ensuring
13.  final def eq(arg0: AnyRef): Boolean
    Definition Classes
      AnyRef
14.  def equals(arg0: Any): Boolean
    Definition Classes
      AnyRef → Any
15.  def expand(desugared: Global.Tree): Global.Tree
    Attributes
      protected
16.  val expandee: Global.Tree
17.  def finalize(): Unit
    Attributes
      protected[java.lang]
    Definition Classes
      AnyRef
    Annotations
      @throws( classOf[java.lang.Throwable] )
18.  def formatted(fmtstr: String): String
    Implicit
      This member is added by an implicit conversion from Analyzer.MacroExpander to StringFormat[Analyzer.MacroExpander] performed by method StringFormat in scala.Predef.
    Definition Classes
      StringFormat
    Annotations
      @inline()
19.  final def getClass(): Class[_]
    Definition Classes
      AnyRef → Any
20.  def hashCode(): Int
    Definition Classes
      AnyRef → Any
21.  final def isInstanceOf[T0]: Boolean
    Definition Classes
      Any
22.  final def ne(arg0: AnyRef): Boolean
    Definition Classes
      AnyRef
23.  final def notify(): Unit
    Definition Classes
      AnyRef
24.  final def notifyAll(): Unit
    Definition Classes
      AnyRef
25.  def onDelayed(expanded: Global.Tree): Global.Tree
26.  def onFailure(expanded: Global.Tree): Global.Tree
27.  def onSkipped(expanded: Global.Tree): Global.Tree
28.  def onSuppressed(expandee: Global.Tree): Global.Tree
29.  final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
      AnyRef
30.  def toString(): String
    Definition Classes
      AnyRef → Any
31.  val typer: Analyzer.Typer
32.  final def wait(): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws( ... )
33.  final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws( ... )
34.  final def wait(arg0: Long): Unit
    Definition Classes
      AnyRef
    Annotations
      @throws( ... )
35.  def →[B](y: B): (Analyzer.MacroExpander, B)
    Implicit
      This member is added by an implicit conversion from Analyzer.MacroExpander to ArrowAssoc[Analyzer.MacroExpander] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
      ArrowAssoc

### Inherited from AnyRef

### Inherited from Any

### Inherited by implicit conversion any2stringadd from Analyzer.MacroExpander to any2stringadd[Analyzer.MacroExpander]

### Inherited by implicit conversion StringFormat from Analyzer.MacroExpander to StringFormat[Analyzer.MacroExpander]

### Inherited by implicit conversion Ensuring from Analyzer.MacroExpander to Ensuring[Analyzer.MacroExpander]

### Inherited by implicit conversion ArrowAssoc from Analyzer.MacroExpander to ArrowAssoc[Analyzer.MacroExpander]

### Ungrouped