summaryrefslogtreecommitdiff
path: root/test/files/run/macro-toplevel/Macros_1.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-01-06 20:17:49 -0800
committerEugene Burmako <xeno.by@gmail.com>2013-01-06 20:17:49 -0800
commita03e77b8670faa133c76f4d7b29bf362246d20b5 (patch)
tree4657735c741511f7703f65614cc3bbb375055435 /test/files/run/macro-toplevel/Macros_1.scala
parent2d0fb869fc7b813f562417372120bb25cb636642 (diff)
parent1f1e36922af099d647931a61ebdf5cec97ab54ac (diff)
downloadscala-2.11.0-M1.tar.gz
scala-2.11.0-M1.tar.bz2
scala-2.11.0-M1.zip
Merge pull request #1817 from scalamacros/topic/introduce-top-levelv2.11.0-M1
adds c.introduceTopLevel
Diffstat (limited to 'test/files/run/macro-toplevel/Macros_1.scala')
-rw-r--r--test/files/run/macro-toplevel/Macros_1.scala15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/files/run/macro-toplevel/Macros_1.scala b/test/files/run/macro-toplevel/Macros_1.scala
new file mode 100644
index 0000000000..f681c86735
--- /dev/null
+++ b/test/files/run/macro-toplevel/Macros_1.scala
@@ -0,0 +1,15 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+object Macros {
+ def impl(c: Context) = {
+ import c.universe._
+ val msg = "I've been created from " + c.macroApplication
+ val Block(List(synthetic: ClassDef), _) = reify{ class SomeUniqueName { def hello = c.literal(msg).splice } }.tree
+ val ref = c.topLevelRef(synthetic.name) orElse c.introduceTopLevel(nme.EMPTY_PACKAGE_NAME.toString, synthetic)
+ c.Expr[String](Select(Apply(Select(New(ref), nme.CONSTRUCTOR), List()), TermName("hello")))
+ }
+
+ def foo = macro impl
+ def foo2 = macro impl
+}