summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2014-01-08 11:17:08 -0800
committerEugene Burmako <xeno.by@gmail.com>2014-01-08 11:17:08 -0800
commit4e4c15177b92ef25f098277dcce3f874c24640b2 (patch)
treef46a594ffb47c53cde502d3e172dd4b1c6c2e109 /test/files/run
parentada8d9156baad2d8a24c1a40e032eb4bc7154bac (diff)
parent87913661e199e3894190b7b8aa0900d7237feec0 (diff)
downloadscala-4e4c15177b92ef25f098277dcce3f874c24640b2.tar.gz
scala-4e4c15177b92ef25f098277dcce3f874c24640b2.tar.bz2
scala-4e4c15177b92ef25f098277dcce3f874c24640b2.zip
Merge pull request #3235 from xeno-by/topic/macro-plugin-interface
new hooks in AnalyzerPlugins to enable macro experimentation
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/macro-whitebox-fundep-materialization/Test_2.scala2
-rw-r--r--test/files/run/macroPlugins-macroArgs.check2
-rw-r--r--test/files/run/macroPlugins-macroArgs/Macros_2.scala11
-rw-r--r--test/files/run/macroPlugins-macroArgs/Plugin_1.scala21
-rw-r--r--test/files/run/macroPlugins-macroArgs/Test_3.flags1
-rw-r--r--test/files/run/macroPlugins-macroArgs/Test_3.scala4
-rw-r--r--test/files/run/macroPlugins-macroArgs/scalac-plugin.xml4
-rw-r--r--test/files/run/macroPlugins-macroExpand.check2
-rw-r--r--test/files/run/macroPlugins-macroExpand/Macros_2.scala18
-rw-r--r--test/files/run/macroPlugins-macroExpand/Plugin_1.scala27
-rw-r--r--test/files/run/macroPlugins-macroExpand/Test_3.flags1
-rw-r--r--test/files/run/macroPlugins-macroExpand/Test_3.scala4
-rw-r--r--test/files/run/macroPlugins-macroExpand/scalac-plugin.xml4
-rw-r--r--test/files/run/macroPlugins-macroRuntime.check2
-rw-r--r--test/files/run/macroPlugins-macroRuntime/Macros_2.scala11
-rw-r--r--test/files/run/macroPlugins-macroRuntime/Plugin_1.scala20
-rw-r--r--test/files/run/macroPlugins-macroRuntime/Test_3.flags1
-rw-r--r--test/files/run/macroPlugins-macroRuntime/Test_3.scala4
-rw-r--r--test/files/run/macroPlugins-macroRuntime/scalac-plugin.xml4
-rw-r--r--test/files/run/macroPlugins-namerHooks.check45
-rw-r--r--test/files/run/macroPlugins-namerHooks.scala38
-rw-r--r--test/files/run/macroPlugins-typedMacroBody.check2
-rw-r--r--test/files/run/macroPlugins-typedMacroBody/Macros_2.flags1
-rw-r--r--test/files/run/macroPlugins-typedMacroBody/Macros_2.scala18
-rw-r--r--test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala21
-rw-r--r--test/files/run/macroPlugins-typedMacroBody/Test_3.scala4
-rw-r--r--test/files/run/macroPlugins-typedMacroBody/scalac-plugin.xml4
27 files changed, 275 insertions, 1 deletions
diff --git a/test/files/run/macro-whitebox-fundep-materialization/Test_2.scala b/test/files/run/macro-whitebox-fundep-materialization/Test_2.scala
index a00f4ed7db..40ca1d549c 100644
--- a/test/files/run/macro-whitebox-fundep-materialization/Test_2.scala
+++ b/test/files/run/macro-whitebox-fundep-materialization/Test_2.scala
@@ -1,4 +1,4 @@
-// see the comments for macroExpandApply.onDelayed for an explanation of what's tested here
+// see the comments for macroExpand.onDelayed for an explanation of what's tested here
object Test extends App {
case class Foo(i: Int, s: String, b: Boolean)
def foo[C, L](c: C)(implicit iso: Iso[C, L]): L = iso.to(c)
diff --git a/test/files/run/macroPlugins-macroArgs.check b/test/files/run/macroPlugins-macroArgs.check
new file mode 100644
index 0000000000..a68f8069b6
--- /dev/null
+++ b/test/files/run/macroPlugins-macroArgs.check
@@ -0,0 +1,2 @@
+hijacked 1
+hijacked 2
diff --git a/test/files/run/macroPlugins-macroArgs/Macros_2.scala b/test/files/run/macroPlugins-macroArgs/Macros_2.scala
new file mode 100644
index 0000000000..d6521dfbcb
--- /dev/null
+++ b/test/files/run/macroPlugins-macroArgs/Macros_2.scala
@@ -0,0 +1,11 @@
+import scala.language.experimental.macros
+import scala.reflect.macros.BlackboxContext
+
+object Macros {
+ def impl(c: BlackboxContext)(arg: c.Tree) = {
+ import c.universe._
+ q"""println($arg)"""
+ }
+
+ def foo(arg: String): Unit = macro impl
+} \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroArgs/Plugin_1.scala b/test/files/run/macroPlugins-macroArgs/Plugin_1.scala
new file mode 100644
index 0000000000..23e80ced3b
--- /dev/null
+++ b/test/files/run/macroPlugins-macroArgs/Plugin_1.scala
@@ -0,0 +1,21 @@
+package macroArgs
+
+import scala.tools.nsc.Global
+import scala.tools.nsc.plugins.{Plugin => NscPlugin}
+
+class Plugin(val global: Global) extends NscPlugin {
+ import global._
+ import analyzer._
+
+ val name = "macroArgs"
+ val description = "A sample analyzer plugin that overrides macroArgs."
+ val components = Nil
+ addMacroPlugin(MacroPlugin)
+
+ object MacroPlugin extends MacroPlugin {
+ override def pluginsMacroArgs(typer: Typer, expandee: Tree): Option[MacroArgs] = {
+ val MacroArgs(c, List(Literal(Constant(s: String)))) = standardMacroArgs(typer, expandee)
+ Some(MacroArgs(c, List(Literal(Constant("hijacked " + s)))))
+ }
+ }
+} \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroArgs/Test_3.flags b/test/files/run/macroPlugins-macroArgs/Test_3.flags
new file mode 100644
index 0000000000..966df731d0
--- /dev/null
+++ b/test/files/run/macroPlugins-macroArgs/Test_3.flags
@@ -0,0 +1 @@
+-Xplugin:. \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroArgs/Test_3.scala b/test/files/run/macroPlugins-macroArgs/Test_3.scala
new file mode 100644
index 0000000000..a54d608178
--- /dev/null
+++ b/test/files/run/macroPlugins-macroArgs/Test_3.scala
@@ -0,0 +1,4 @@
+object Test extends App {
+ Macros.foo("1")
+ Macros.foo("2")
+} \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroArgs/scalac-plugin.xml b/test/files/run/macroPlugins-macroArgs/scalac-plugin.xml
new file mode 100644
index 0000000000..0849f0f4ea
--- /dev/null
+++ b/test/files/run/macroPlugins-macroArgs/scalac-plugin.xml
@@ -0,0 +1,4 @@
+<plugin>
+ <name>macro-args</name>
+ <classname>macroArgs.Plugin</classname>
+</plugin> \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroExpand.check b/test/files/run/macroPlugins-macroExpand.check
new file mode 100644
index 0000000000..6f685c2af4
--- /dev/null
+++ b/test/files/run/macroPlugins-macroExpand.check
@@ -0,0 +1,2 @@
+expanded into println("impl1")
+expanded into println("impl2")
diff --git a/test/files/run/macroPlugins-macroExpand/Macros_2.scala b/test/files/run/macroPlugins-macroExpand/Macros_2.scala
new file mode 100644
index 0000000000..f16503b415
--- /dev/null
+++ b/test/files/run/macroPlugins-macroExpand/Macros_2.scala
@@ -0,0 +1,18 @@
+import scala.language.experimental.macros
+import scala.reflect.macros.BlackboxContext
+
+object Macros {
+ def impl1(c: BlackboxContext) = {
+ import c.universe._
+ q"""println("impl1")"""
+ }
+
+ def impl2(c: BlackboxContext) = {
+ import c.universe._
+ q"""println("impl2")"""
+ }
+
+ def foo1: Unit = macro impl1
+
+ def foo2: Unit = macro impl2
+} \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroExpand/Plugin_1.scala b/test/files/run/macroPlugins-macroExpand/Plugin_1.scala
new file mode 100644
index 0000000000..13df85cb23
--- /dev/null
+++ b/test/files/run/macroPlugins-macroExpand/Plugin_1.scala
@@ -0,0 +1,27 @@
+package macroExpand
+
+import scala.tools.nsc.Global
+import scala.tools.nsc.plugins.{Plugin => NscPlugin}
+
+class Plugin(val global: Global) extends NscPlugin {
+ import global._
+ import analyzer._
+ import scala.reflect.internal.Mode
+
+ val name = "macroExpand"
+ val description = "A sample analyzer plugin that overrides macroExpand."
+ val components = Nil
+ addMacroPlugin(MacroPlugin)
+
+ object MacroPlugin extends MacroPlugin {
+ override def pluginsMacroExpand(typer: Typer, expandee: Tree, mode: Mode, pt: Type): Option[Tree] = {
+ object expander extends DefMacroExpander(typer, expandee, mode, pt) {
+ override def onSuccess(expanded: Tree) = {
+ val message = s"expanded into ${expanded.toString}"
+ typer.typed(q"println($message)")
+ }
+ }
+ Some(expander(expandee))
+ }
+ }
+} \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroExpand/Test_3.flags b/test/files/run/macroPlugins-macroExpand/Test_3.flags
new file mode 100644
index 0000000000..966df731d0
--- /dev/null
+++ b/test/files/run/macroPlugins-macroExpand/Test_3.flags
@@ -0,0 +1 @@
+-Xplugin:. \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroExpand/Test_3.scala b/test/files/run/macroPlugins-macroExpand/Test_3.scala
new file mode 100644
index 0000000000..def9b5608a
--- /dev/null
+++ b/test/files/run/macroPlugins-macroExpand/Test_3.scala
@@ -0,0 +1,4 @@
+object Test extends App {
+ Macros.foo1
+ Macros.foo2
+} \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroExpand/scalac-plugin.xml b/test/files/run/macroPlugins-macroExpand/scalac-plugin.xml
new file mode 100644
index 0000000000..860150865c
--- /dev/null
+++ b/test/files/run/macroPlugins-macroExpand/scalac-plugin.xml
@@ -0,0 +1,4 @@
+<plugin>
+ <name>macro-expand</name>
+ <classname>macroExpand.Plugin</classname>
+</plugin> \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroRuntime.check b/test/files/run/macroPlugins-macroRuntime.check
new file mode 100644
index 0000000000..af16d1ac36
--- /dev/null
+++ b/test/files/run/macroPlugins-macroRuntime.check
@@ -0,0 +1,2 @@
+hijacked
+hijacked
diff --git a/test/files/run/macroPlugins-macroRuntime/Macros_2.scala b/test/files/run/macroPlugins-macroRuntime/Macros_2.scala
new file mode 100644
index 0000000000..d6521dfbcb
--- /dev/null
+++ b/test/files/run/macroPlugins-macroRuntime/Macros_2.scala
@@ -0,0 +1,11 @@
+import scala.language.experimental.macros
+import scala.reflect.macros.BlackboxContext
+
+object Macros {
+ def impl(c: BlackboxContext)(arg: c.Tree) = {
+ import c.universe._
+ q"""println($arg)"""
+ }
+
+ def foo(arg: String): Unit = macro impl
+} \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroRuntime/Plugin_1.scala b/test/files/run/macroPlugins-macroRuntime/Plugin_1.scala
new file mode 100644
index 0000000000..a55adadb48
--- /dev/null
+++ b/test/files/run/macroPlugins-macroRuntime/Plugin_1.scala
@@ -0,0 +1,20 @@
+package macroRuntime
+
+import scala.tools.nsc.Global
+import scala.tools.nsc.plugins.{Plugin => NscPlugin}
+
+class Plugin(val global: Global) extends NscPlugin {
+ import global._
+ import analyzer._
+
+ val name = "macroRuntime"
+ val description = "A sample analyzer plugin that overrides macroRuntime."
+ val components = Nil
+ addMacroPlugin(MacroPlugin)
+
+ object MacroPlugin extends MacroPlugin {
+ override def pluginsMacroRuntime(expandee: Tree): Option[MacroRuntime] = Some({
+ case MacroArgs(_, List(msg)) => q"""println("hijacked")"""
+ })
+ }
+} \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroRuntime/Test_3.flags b/test/files/run/macroPlugins-macroRuntime/Test_3.flags
new file mode 100644
index 0000000000..966df731d0
--- /dev/null
+++ b/test/files/run/macroPlugins-macroRuntime/Test_3.flags
@@ -0,0 +1 @@
+-Xplugin:. \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroRuntime/Test_3.scala b/test/files/run/macroPlugins-macroRuntime/Test_3.scala
new file mode 100644
index 0000000000..a54d608178
--- /dev/null
+++ b/test/files/run/macroPlugins-macroRuntime/Test_3.scala
@@ -0,0 +1,4 @@
+object Test extends App {
+ Macros.foo("1")
+ Macros.foo("2")
+} \ No newline at end of file
diff --git a/test/files/run/macroPlugins-macroRuntime/scalac-plugin.xml b/test/files/run/macroPlugins-macroRuntime/scalac-plugin.xml
new file mode 100644
index 0000000000..8001af1054
--- /dev/null
+++ b/test/files/run/macroPlugins-macroRuntime/scalac-plugin.xml
@@ -0,0 +1,4 @@
+<plugin>
+ <name>macro-runtime</name>
+ <classname>macroRuntime.Plugin</classname>
+</plugin> \ No newline at end of file
diff --git a/test/files/run/macroPlugins-namerHooks.check b/test/files/run/macroPlugins-namerHooks.check
new file mode 100644
index 0000000000..c2db5935d4
--- /dev/null
+++ b/test/files/run/macroPlugins-namerHooks.check
@@ -0,0 +1,45 @@
+enterSym(package <empty> { case class C extends scala.Product with scala.Serializable { <caseaccessor> <paramaccessor> val x: Int = _; <caseaccessor> <paramaccessor> val y: Int = _; def <init>(x: Int, y: Int) = { super.<init>(); () } } })
+enterSym(case class C extends scala.Product with scala.Serializable { <caseaccessor> <paramaccessor> val x: Int = _; <caseaccessor> <paramaccessor> val y: Int = _; def <init>(x: Int, y: Int) = { super.<init>(); () } })
+ensureCompanionObject(case class C extends scala.Product with scala.Serializable { <caseaccessor> <paramaccessor> val x: Int = _; <caseaccessor> <paramaccessor> val y: Int = _; def <init>(x: Int, y: Int) = { super.<init>(); () } }, ...)
+enterSym(<synthetic> object C extends runtime.this.AbstractFunction2[Int, Int, C] { def <init>() = { super.<init>(); () }; final override <synthetic> def toString() = "C" })
+enterStat(case class C extends scala.Product with scala.Serializable { <caseaccessor> <paramaccessor> val x: Int = _; <caseaccessor> <paramaccessor> val y: Int = _; def <init>(x: Int, y: Int) = { super.<init>(); () } })
+enterSym(<caseaccessor> <paramaccessor> val x: Int = _)
+enterSym(<caseaccessor> <paramaccessor> val y: Int = _)
+enterSym(def <init>(x: Int, y: Int) = { super.<init>(); () })
+enterSym(<synthetic> def copy(x = x, y = y) = new C(x, y))
+enterStat(<caseaccessor> <paramaccessor> private[this] val x: Int = _)
+enterStat(<caseaccessor> <paramaccessor> private[this] val y: Int = _)
+enterStat(def <init>(x: Int, y: Int) = { super.<init>(); () })
+enterSym(<caseaccessor> <paramaccessor> private[this] val x: Int = _)
+enterSym(<caseaccessor> <paramaccessor> private[this] val y: Int = _)
+enterSym(def <init>(x: Int, y: Int) = { super.<init>(); () })
+enterSym(super.<init>())
+enterStat(super.<init>())
+enterSym(<synthetic> def copy$default$1 = x)
+enterSym(<synthetic> def copy$default$2 = y)
+enterSym(<synthetic> var acc: Int = -889275714)
+enterSym(acc = Statics.this.mix(acc, x))
+enterSym(acc = Statics.this.mix(acc, y))
+enterStat(<synthetic> var acc: Int = -889275714)
+enterStat(acc = Statics.this.mix(acc, x))
+enterStat(acc = Statics.this.mix(acc, y))
+enterSym(<synthetic> val C$1: C = x$1.asInstanceOf[C])
+enterStat(<synthetic> val C$1: C = x$1.asInstanceOf[C])
+enterSym(def <init>() = { super.<init>(); () })
+enterSym(final override <synthetic> def toString() = "C")
+enterSym(case <synthetic> def apply(x: Int, y: Int): C = new C(x, y))
+enterSym(case <synthetic> def unapply(x$0: C) = if (x$0.==(null)) scala.this.None else Some(scala.Tuple2(x$0.x, x$0.y)))
+enterStat(def <init>() = { super.<init>(); () })
+enterStat(final override <synthetic> def toString() = "C")
+enterSym(def <init>() = { super.<init>(); () })
+enterSym(final override <synthetic> def toString() = "C")
+enterSym(super.<init>())
+enterStat(super.<init>())
+enterSym(case <synthetic> val x1: Int = x$1)
+enterStat(case <synthetic> val x1: Int = x$1)
+enterSym(case <synthetic> val x1: Any = x$1)
+enterSym(case5(){ if (x1.isInstanceOf[C]) matchEnd4(true) else case6() })
+enterSym(case6(){ matchEnd4(false) })
+enterStat(case <synthetic> val x1: Any = x$1)
+enterStat(case5(){ if (x1.isInstanceOf[C]) matchEnd4(true) else case6() })
+enterStat(case6(){ matchEnd4(false) })
diff --git a/test/files/run/macroPlugins-namerHooks.scala b/test/files/run/macroPlugins-namerHooks.scala
new file mode 100644
index 0000000000..a71d685f7f
--- /dev/null
+++ b/test/files/run/macroPlugins-namerHooks.scala
@@ -0,0 +1,38 @@
+import scala.tools.partest._
+import scala.tools.nsc._
+
+object Test extends DirectTest {
+ override def extraSettings: String = "-usejavacp"
+
+ def code = """
+ case class C(x: Int, y: Int)
+ """.trim
+
+ def show() {
+ val global = newCompiler()
+ import global._
+ import analyzer._
+
+ val output = collection.mutable.ListBuffer[String]()
+
+ object macroPlugin extends MacroPlugin {
+ override def pluginsEnterSym(namer: Namer, tree: Tree): Boolean = {
+ output += s"enterSym(${tree.toString.replace('\n', ' ')})"
+ 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.standardEnsureCompanionObject(cdef, creator))
+ }
+ override def pluginsEnterStats(typer: Typer, stats: List[Tree]): List[Tree] = {
+ stats.foreach(stat => output += s"enterStat(${stat.toString.replace('\n', ' ')})")
+ stats
+ }
+ }
+
+ addMacroPlugin(macroPlugin)
+ compileString(global)(code)
+ println(output.mkString("\n"))
+ }
+}
diff --git a/test/files/run/macroPlugins-typedMacroBody.check b/test/files/run/macroPlugins-typedMacroBody.check
new file mode 100644
index 0000000000..b6f8436189
--- /dev/null
+++ b/test/files/run/macroPlugins-typedMacroBody.check
@@ -0,0 +1,2 @@
+impl1
+impl2
diff --git a/test/files/run/macroPlugins-typedMacroBody/Macros_2.flags b/test/files/run/macroPlugins-typedMacroBody/Macros_2.flags
new file mode 100644
index 0000000000..966df731d0
--- /dev/null
+++ b/test/files/run/macroPlugins-typedMacroBody/Macros_2.flags
@@ -0,0 +1 @@
+-Xplugin:. \ No newline at end of file
diff --git a/test/files/run/macroPlugins-typedMacroBody/Macros_2.scala b/test/files/run/macroPlugins-typedMacroBody/Macros_2.scala
new file mode 100644
index 0000000000..fa8522e729
--- /dev/null
+++ b/test/files/run/macroPlugins-typedMacroBody/Macros_2.scala
@@ -0,0 +1,18 @@
+import scala.language.experimental.macros
+import scala.reflect.macros.BlackboxContext
+
+object Macros {
+ def impl1(c: BlackboxContext) = {
+ import c.universe._
+ q"""println("impl1")"""
+ }
+
+ def impl2(c: BlackboxContext) = {
+ import c.universe._
+ q"""println("impl2")"""
+ }
+
+ def foo1: Unit = macro 1
+
+ def foo2: Unit = macro 2
+} \ No newline at end of file
diff --git a/test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala b/test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala
new file mode 100644
index 0000000000..e99cf7f75d
--- /dev/null
+++ b/test/files/run/macroPlugins-typedMacroBody/Plugin_1.scala
@@ -0,0 +1,21 @@
+package typedMacroBody
+
+import scala.tools.nsc.Global
+import scala.tools.nsc.plugins.{Plugin => NscPlugin}
+
+class Plugin(val global: Global) extends NscPlugin {
+ import global._
+ import analyzer._
+
+ val name = "typedMacroBody"
+ val description = "A sample analyzer plugin that overrides typedMacroBody."
+ val components = Nil
+ addMacroPlugin(MacroPlugin)
+
+ object MacroPlugin extends MacroPlugin {
+ override def pluginsTypedMacroBody(typer: Typer, ddef: DefDef): Option[Tree] = {
+ val DefDef(_, _, _, _, _, Literal(Constant(num: Int))) = ddef
+ Some(standardTypedMacroBody(typer, copyDefDef(ddef)(rhs = Ident(TermName("impl" + num)))))
+ }
+ }
+} \ No newline at end of file
diff --git a/test/files/run/macroPlugins-typedMacroBody/Test_3.scala b/test/files/run/macroPlugins-typedMacroBody/Test_3.scala
new file mode 100644
index 0000000000..def9b5608a
--- /dev/null
+++ b/test/files/run/macroPlugins-typedMacroBody/Test_3.scala
@@ -0,0 +1,4 @@
+object Test extends App {
+ Macros.foo1
+ Macros.foo2
+} \ No newline at end of file
diff --git a/test/files/run/macroPlugins-typedMacroBody/scalac-plugin.xml b/test/files/run/macroPlugins-typedMacroBody/scalac-plugin.xml
new file mode 100644
index 0000000000..e223fa5dca
--- /dev/null
+++ b/test/files/run/macroPlugins-typedMacroBody/scalac-plugin.xml
@@ -0,0 +1,4 @@
+<plugin>
+ <name>typed-macro-body</name>
+ <classname>typedMacroBody.Plugin</classname>
+</plugin> \ No newline at end of file