diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-06-03 11:08:50 -0700 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-06-03 11:08:50 -0700 |
commit | 69887ddd682057c4787e2e4377830390faf8ecf1 (patch) | |
tree | 1158f24dd50dac397e867a6d2d861171e7335c4f /src/compiler/scala/reflect/macros/contexts/Reifiers.scala | |
parent | c1cd65bb5276b715141df6d09fc95b0c44d2b4c2 (diff) | |
parent | 82f0925b69db8b5f9a3b10f58926c574433ca423 (diff) | |
download | scala-69887ddd682057c4787e2e4377830390faf8ecf1.tar.gz scala-69887ddd682057c4787e2e4377830390faf8ecf1.tar.bz2 scala-69887ddd682057c4787e2e4377830390faf8ecf1.zip |
Merge pull request #2577 from scalamacros/pullrequest/paradise
Backport from paradise/macros
Diffstat (limited to 'src/compiler/scala/reflect/macros/contexts/Reifiers.scala')
-rw-r--r-- | src/compiler/scala/reflect/macros/contexts/Reifiers.scala | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/compiler/scala/reflect/macros/contexts/Reifiers.scala b/src/compiler/scala/reflect/macros/contexts/Reifiers.scala new file mode 100644 index 0000000000..ecef1c7289 --- /dev/null +++ b/src/compiler/scala/reflect/macros/contexts/Reifiers.scala @@ -0,0 +1,77 @@ +/* NSC -- new Scala compiler + * Copyright 2005-2013 LAMP/EPFL + * @author Gilles Dubochet + */ + +package scala.reflect.macros +package contexts + +trait Reifiers { + self: Context => + + val global: universe.type = universe + import universe._ + import definitions._ + + def reifyTree(universe: Tree, mirror: Tree, tree: Tree): Tree = { + assert(ExprClass != NoSymbol) + val result = scala.reflect.reify.`package`.reifyTree(self.universe)(callsiteTyper, universe, mirror, tree) + logFreeVars(enclosingPosition, result) + result + } + + def reifyType(universe: Tree, mirror: Tree, tpe: Type, concrete: Boolean = false): Tree = { + assert(TypeTagsClass != NoSymbol) + val result = scala.reflect.reify.`package`.reifyType(self.universe)(callsiteTyper, universe, mirror, tpe, concrete) + logFreeVars(enclosingPosition, result) + result + } + + def reifyRuntimeClass(tpe: Type, concrete: Boolean = true): Tree = + scala.reflect.reify.`package`.reifyRuntimeClass(universe)(callsiteTyper, tpe, concrete = concrete) + + def reifyEnclosingRuntimeClass: Tree = + scala.reflect.reify.`package`.reifyEnclosingRuntimeClass(universe)(callsiteTyper) + + def unreifyTree(tree: Tree): Tree = { + assert(ExprSplice != NoSymbol) + Select(tree, ExprSplice) + } + + // fixme: if I put utils here, then "global" from utils' early initialization syntax + // and "global" that comes from here conflict with each other when incrementally compiling + // the problem is that both are pickled with the same owner - trait Reifiers + // and this upsets the compiler, so that oftentimes it throws assertion failures + // Martin knows the details + // + // object utils extends { + // val global: self.global.type = self.global + // val typer: global.analyzer.Typer = self.callsiteTyper + // } with scala.reflect.reify.utils.Utils + // import utils._ + + private def logFreeVars(position: Position, reification: Tree): Unit = { + object utils extends { + val global: self.global.type = self.global + val typer: global.analyzer.Typer = self.callsiteTyper + } with scala.reflect.reify.utils.Utils + import utils._ + + def logFreeVars(symtab: SymbolTable): Unit = + // logging free vars only when they are untyped prevents avalanches of duplicate messages + symtab.syms map (sym => symtab.symDef(sym)) foreach { + case FreeTermDef(_, _, binding, _, origin) if universe.settings.logFreeTerms && binding.tpe == null => + reporter.echo(position, "free term: %s %s".format(showRaw(binding), origin)) + case FreeTypeDef(_, _, binding, _, origin) if universe.settings.logFreeTypes && binding.tpe == null => + reporter.echo(position, "free type: %s %s".format(showRaw(binding), origin)) + case _ => + // do nothing + } + + if (universe.settings.logFreeTerms || universe.settings.logFreeTypes) + reification match { + case ReifiedTree(_, _, symtab, _, _, _, _) => logFreeVars(symtab) + case ReifiedType(_, _, symtab, _, _, _) => logFreeVars(symtab) + } + } +} |