summaryrefslogtreecommitdiff
path: root/test
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 /test
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 'test')
-rw-r--r--test/files/neg/macro-incompatible-macro-engine/Plugin_1.scala2
-rw-r--r--test/files/run/macroPlugins-macroArgs/Plugin_1.scala2
-rw-r--r--test/files/run/macroPlugins-namerHooks.scala4
-rw-r--r--test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala2
4 files changed, 5 insertions, 5 deletions
diff --git a/test/files/neg/macro-incompatible-macro-engine/Plugin_1.scala b/test/files/neg/macro-incompatible-macro-engine/Plugin_1.scala
index a450573755..44ed91d2fb 100644
--- a/test/files/neg/macro-incompatible-macro-engine/Plugin_1.scala
+++ b/test/files/neg/macro-incompatible-macro-engine/Plugin_1.scala
@@ -25,7 +25,7 @@ class Plugin(val global: Global) extends NscPlugin {
}.transform(tree)
override def pluginsTypedMacroBody(typer: Typer, ddef: DefDef): Option[Tree] = {
- val result = typedMacroBody(typer, ddef)
+ val result = standardTypedMacroBody(typer, ddef)
val List(AnnotationInfo(atp, List(Apply(nucleus, _ :: others)), Nil)) = ddef.symbol.annotations
val updatedBinding = Apply(nucleus, Assign(Literal(Constant("macroEngine")), Literal(Constant("vxxx (implemented in the incompatibleMacroEngine plugin)"))) :: others)
ddef.symbol.setAnnotations(List(AnnotationInfo(atp, List(fixupBinding(updatedBinding)), Nil)))
diff --git a/test/files/run/macroPlugins-macroArgs/Plugin_1.scala b/test/files/run/macroPlugins-macroArgs/Plugin_1.scala
index 04cedbdc64..23e80ced3b 100644
--- a/test/files/run/macroPlugins-macroArgs/Plugin_1.scala
+++ b/test/files/run/macroPlugins-macroArgs/Plugin_1.scala
@@ -14,7 +14,7 @@ class Plugin(val global: Global) extends NscPlugin {
object MacroPlugin extends MacroPlugin {
override def pluginsMacroArgs(typer: Typer, expandee: Tree): Option[MacroArgs] = {
- val MacroArgs(c, List(Literal(Constant(s: String)))) = macroArgs(typer, expandee)
+ val MacroArgs(c, List(Literal(Constant(s: String)))) = standardMacroArgs(typer, expandee)
Some(MacroArgs(c, List(Literal(Constant("hijacked " + s)))))
}
}
diff --git a/test/files/run/macroPlugins-namerHooks.scala b/test/files/run/macroPlugins-namerHooks.scala
index b0f29cbbed..a71d685f7f 100644
--- a/test/files/run/macroPlugins-namerHooks.scala
+++ b/test/files/run/macroPlugins-namerHooks.scala
@@ -18,12 +18,12 @@ object Test extends DirectTest {
object macroPlugin extends MacroPlugin {
override def pluginsEnterSym(namer: Namer, tree: Tree): Boolean = {
output += s"enterSym(${tree.toString.replace('\n', ' ')})"
- namer.enterSym(tree)
+ namer.standardEnterSym(tree)
true
}
override def pluginsEnsureCompanionObject(namer: Namer, cdef: ClassDef, creator: ClassDef => Tree = companionModuleDef(_)): Option[Symbol] = {
output += s"ensureCompanionObject(${cdef.toString.replace('\n', ' ')}, ...)"
- Some(namer.ensureCompanionObject(cdef, creator))
+ Some(namer.standardEnsureCompanionObject(cdef, creator))
}
override def pluginsEnterStats(typer: Typer, stats: List[Tree]): List[Tree] = {
stats.foreach(stat => output += s"enterStat(${stat.toString.replace('\n', ' ')})")
diff --git a/test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala b/test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala
index 4632c36ef5..e99cf7f75d 100644
--- a/test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala
+++ b/test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala
@@ -15,7 +15,7 @@ class Plugin(val global: Global) extends NscPlugin {
object MacroPlugin extends MacroPlugin {
override def pluginsTypedMacroBody(typer: Typer, ddef: DefDef): Option[Tree] = {
val DefDef(_, _, _, _, _, Literal(Constant(num: Int))) = ddef
- Some(typedMacroBody(typer, copyDefDef(ddef)(rhs = Ident(TermName("impl" + num)))))
+ Some(standardTypedMacroBody(typer, copyDefDef(ddef)(rhs = Ident(TermName("impl" + num)))))
}
}
} \ No newline at end of file