summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-01-05 00:25:28 +0300
committerEugene Burmako <xeno.by@gmail.com>2013-01-09 08:10:46 +0100
commitd17e3fc29cd48a3d4cbbbfc1fc9eb021d787d4d7 (patch)
tree2c658d3779ebbee4789160f2cc8f11e2484b3274 /src/compiler
parent816bcdf382ea0469f6c5eadcff44901921ba6075 (diff)
downloadscala-d17e3fc29cd48a3d4cbbbfc1fc9eb021d787d4d7.tar.gz
scala-d17e3fc29cd48a3d4cbbbfc1fc9eb021d787d4d7.tar.bz2
scala-d17e3fc29cd48a3d4cbbbfc1fc9eb021d787d4d7.zip
adds c.macroRole
Currently there's only one flavor of macros - def macros, and the plan was to gradually introduce additional flavors, such as type macros and macro annotations. However as shown by the experience with type macros, it makes sense to distinguish subflavors of macros that tell us in which context the macro gets expanded. For def macros we have the only role - expansion of an application. But for type macros there are multiple.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/reflect/macros/runtime/Enclosures.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Macros.scala7
2 files changed, 11 insertions, 0 deletions
diff --git a/src/compiler/scala/reflect/macros/runtime/Enclosures.scala b/src/compiler/scala/reflect/macros/runtime/Enclosures.scala
index e8b2961611..8fe0b09700 100644
--- a/src/compiler/scala/reflect/macros/runtime/Enclosures.scala
+++ b/src/compiler/scala/reflect/macros/runtime/Enclosures.scala
@@ -8,6 +8,10 @@ trait Enclosures {
import universe._
+ type MacroRole = analyzer.MacroRole
+ def APPLY_ROLE = analyzer.APPLY_ROLE
+ def macroRole: MacroRole
+
private lazy val site = callsiteTyper.context
private lazy val enclTrees = site.enclosingContextChain map (_.tree)
private lazy val enclPoses = enclosingMacros map (_.macroApplication.pos) filterNot (_ eq NoPosition)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
index 768d739b4b..23e00960d4 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
@@ -538,6 +538,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
val universe: self.global.type = self.global
val callsiteTyper: universe.analyzer.Typer = typer.asInstanceOf[global.analyzer.Typer]
val expandee = expandeeTree
+ val macroRole = APPLY_ROLE
} with UnaffiliatedMacroContext {
val prefix = Expr[Nothing](prefixTree)(TypeTag.Nothing)
override def toString = "MacroContext(%s@%s +%d)".format(expandee.symbol.name, expandee.pos, enclosingMacros.length - 1 /* exclude myself */)
@@ -645,6 +646,12 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
private def popMacroContext() = _openMacros = _openMacros.tail
def enclosingMacroPosition = openMacros map (_.macroApplication.pos) find (_ ne NoPosition) getOrElse NoPosition
+ /** Describes the role that the macro expandee is performing.
+ */
+ type MacroRole = String
+ final def APPLY_ROLE: MacroRole = "APPLY_ROLE"
+ private val roleNames = Map(APPLY_ROLE -> "apply")
+
private sealed abstract class MacroExpansionResult
private case class Success(expanded: Tree) extends MacroExpansionResult
private case class Fallback(fallback: Tree) extends MacroExpansionResult { currentRun.seenMacroExpansionsFallingBack = true }