Skip to content

Instantly share code, notes, and snippets.

Created June 23, 2016 11:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
the description for this gist
object MacroImplementation {
def apply(c: scala.reflect.macros.whitebox.Context)(treeToTransform: c.Tree): c.Tree = {
import c.universe._
val resultName = "_result_"
val lineNum = treeToTransform.pos.line
c.Expr {
Function(List(),
Block(
List(
ValDef(Modifiers(), TermName(resultName), TypeTree(), Apply(treeToTransform, List())),
Apply(Ident(TermName("println")), List(Literal(Constant("Going to return")))),
Apply(Ident(TermName("println")), List(Ident(TermName(resultName)))),
Apply(Ident(TermName("println")), List(Literal(Constant("at line")))),
Apply(Ident(TermName("println")), List(Literal(Constant(lineNum))))
),
Ident(TermName(resultName))
))
}.tree
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment