summaryrefslogtreecommitdiff
path: root/test/files/run/macro-openmacros/Impls_Macros_1.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/files/run/macro-openmacros/Impls_Macros_1.scala')
-rw-r--r--test/files/run/macro-openmacros/Impls_Macros_1.scala26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/files/run/macro-openmacros/Impls_Macros_1.scala b/test/files/run/macro-openmacros/Impls_Macros_1.scala
new file mode 100644
index 0000000000..9fd658656e
--- /dev/null
+++ b/test/files/run/macro-openmacros/Impls_Macros_1.scala
@@ -0,0 +1,26 @@
+import scala.reflect.makro.Context
+
+object Macros {
+ def impl(c: Context): c.Expr[Unit] = {
+ // we're macros, so we can reflect against our source path
+ // so we don't need any partests to clean up after us!
+ val c.CompilationUnit(file, _, _) = c.enclosingUnit
+ val dir = file.getParentFile
+ def normalizePaths(s: String) = {
+ val base = (dir.getCanonicalPath + java.io.File.separator).replace('\\', '/')
+ var regex = """\Q%s\E""" format base
+ val isWin = System.getProperty("os.name", "") startsWith "Windows"
+ if (isWin) regex = "(?i)" + regex
+ s.replace('\\', '/').replaceAll(regex, "")
+ }
+
+ import c.mirror._
+ val next = if (c.enclosingMacros.length < 3) Expr[Unit](Select(Ident(staticModule("Macros")), newTermName("foo"))) else c.literalUnit
+ c.reify {
+ println(c.literal(normalizePaths(c.enclosingMacros.toString)).eval)
+ next.eval
+ }
+ }
+
+ def foo = macro impl
+} \ No newline at end of file