summaryrefslogtreecommitdiff
path: root/src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-12-09 09:45:31 +0100
committerEugene Burmako <xeno.by@gmail.com>2013-12-30 19:07:05 +0300
commit87913661e199e3894190b7b8aa0900d7237feec0 (patch)
treedb22c710438c8f2cf35886b8014456a911a25855 /src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala
parent4d92aec651def608628a2275e1b6bf2d1fcbabe7 (diff)
downloadscala-87913661e199e3894190b7b8aa0900d7237feec0.tar.gz
scala-87913661e199e3894190b7b8aa0900d7237feec0.tar.bz2
scala-87913661e199e3894190b7b8aa0900d7237feec0.zip
hooks for naming and synthesis in Namers.scala and Typers.scala
Interestingly enough, despite of the implementation surface being quite noticeable, it is enough to hijack just `enterSym` and typechecking of stats for packages, templates and blocks in order to enable macro annotations. That and `ensureCompanionObject`, which I couldn't abstract away so far. An architectural note: given that a hooked method is called `X`, there are two implementations of this method. `pluginsX` is defined in AnalyzerPlugins.scala and lets macro plugins customize `X`. `standardX` is defined next to `X` and provides a default implementation. Finally `X` is changed to trivially forward to `pluginsX`. Existing and future callers of `X` now can be completely oblivious of the introduced hooks, because calls to `X` will continue working and will be correctly hooked. This makes the infrastructure more robust. The only downside is that in case when a macro plugin wants to call into the default implementation, it needs to call `standardX`, because `X` will lead to a stack overflow. However, in my opinion this not a big problem, because such failures are load and clear + for every `pluginsX` we actually provide documentation that says what is its standard impl is.
Diffstat (limited to 'src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala')
-rw-r--r--src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala b/src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala
index 2b73d932d4..14b0c6baba 100644
--- a/src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala
+++ b/src/compiler/scala/reflect/macros/runtime/MacroRuntimes.scala
@@ -19,8 +19,13 @@ trait MacroRuntimes extends JavaReflectionRuntimes with ScalaReflectionRuntimes
* @return Requested runtime if macro implementation can be loaded successfully from either of the mirrors,
* `null` otherwise.
*/
+ def macroRuntime(expandee: Tree): MacroRuntime = pluginsMacroRuntime(expandee)
+
+ /** Default implementation of `macroRuntime`.
+ * Can be overridden by analyzer plugins (see AnalyzerPlugins.pluginsMacroRuntime for more details)
+ */
private val macroRuntimesCache = perRunCaches.newWeakMap[Symbol, MacroRuntime]
- def macroRuntime(expandee: Tree): MacroRuntime = {
+ def standardMacroRuntime(expandee: Tree): MacroRuntime = {
val macroDef = expandee.symbol
macroLogVerbose(s"looking for macro implementation: $macroDef")
if (fastTrack contains macroDef) {