summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-06-27 16:04:37 +0200
committerJason Zaugg <jzaugg@gmail.com>2014-06-27 16:04:37 +0200
commitfbfce33cb03bc2b41dd0f46fa9f4630036b4f2ca (patch)
tree9219c9a2f186d51eceff3c7094412481a4b99b8d /src
parent856fe4ad0472ab71d91a6ab442fba77c4cf9950b (diff)
parenta907887158a469b6a21d027fd37bc360e9009b2f (diff)
downloadscala-fbfce33cb03bc2b41dd0f46fa9f4630036b4f2ca.tar.gz
scala-fbfce33cb03bc2b41dd0f46fa9f4630036b4f2ca.tar.bz2
scala-fbfce33cb03bc2b41dd0f46fa9f4630036b4f2ca.zip
Merge pull request #3778 from xeno-by/topic/plugins-is-blackbox
adds MacroPlugin.pluginsIsBlackbox
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/AnalyzerPlugins.scala18
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Macros.scala7
2 files changed, 24 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/AnalyzerPlugins.scala b/src/compiler/scala/tools/nsc/typechecker/AnalyzerPlugins.scala
index fa6e5399eb..5a70d4c524 100644
--- a/src/compiler/scala/tools/nsc/typechecker/AnalyzerPlugins.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/AnalyzerPlugins.scala
@@ -190,6 +190,16 @@ trait AnalyzerPlugins { self: Analyzer =>
def pluginsTypedMacroBody(typer: Typer, ddef: DefDef): Option[Tree] = None
/**
+ * Figures out whether the given macro definition is blackbox or whitebox.
+ *
+ * Default implementation provided in `self.standardIsBlackbox` loads the macro impl binding
+ * and fetches boxity from the "isBlackbox" field of the macro signature.
+ *
+ * $nonCumulativeReturnValueDoc.
+ */
+ def pluginsIsBlackbox(macroDef: Symbol): Option[Boolean] = None
+
+ /**
* Expands an application of a def macro (i.e. of a symbol that has the MACRO flag set),
* possibly using the current typer mode and the provided prototype.
*
@@ -375,6 +385,14 @@ trait AnalyzerPlugins { self: Analyzer =>
def custom(plugin: MacroPlugin) = plugin.pluginsTypedMacroBody(typer, ddef)
})
+ /** @see MacroPlugin.pluginsIsBlackbox */
+ def pluginsIsBlackbox(macroDef: Symbol): Boolean = invoke(new NonCumulativeOp[Boolean] {
+ def position = macroDef.pos
+ def description = "compute boxity for this macro definition"
+ def default = standardIsBlackbox(macroDef)
+ def custom(plugin: MacroPlugin) = plugin.pluginsIsBlackbox(macroDef)
+ })
+
/** @see MacroPlugin.pluginsMacroExpand */
def pluginsMacroExpand(typer: Typer, expandee: Tree, mode: Mode, pt: Type): Tree = invoke(new NonCumulativeOp[Tree] {
def position = expandee.pos
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
index f40a92f8e5..ef74beec62 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
@@ -263,7 +263,12 @@ trait Macros extends MacroRuntimes with Traces with Helpers {
}
def isBlackbox(expandee: Tree): Boolean = isBlackbox(dissectApplied(expandee).core.symbol)
- def isBlackbox(macroDef: Symbol): Boolean = {
+ def isBlackbox(macroDef: Symbol): Boolean = pluginsIsBlackbox(macroDef)
+
+ /** Default implementation of `isBlackbox`.
+ * Can be overridden by analyzer plugins (see AnalyzerPlugins.pluginsIsBlackbox for more details)
+ */
+ def standardIsBlackbox(macroDef: Symbol): Boolean = {
val fastTrackBoxity = fastTrack.get(macroDef).map(_.isBlackbox)
val bindingBoxity = loadMacroImplBinding(macroDef).map(_.isBlackbox)
fastTrackBoxity orElse bindingBoxity getOrElse false