diff options
author | Paul Phillips <paulp@improving.org> | 2012-04-25 15:39:18 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-04-25 18:32:28 -0700 |
commit | 1297d87d5e5bfa25022568b6e20fbd92f6d6c40a (patch) | |
tree | 6e950211fb78a5d657ea1d895077586a9a7e285d /src/compiler | |
parent | 6ea732424238ce4a664aedd416655836ef16d1c4 (diff) | |
download | scala-1297d87d5e5bfa25022568b6e20fbd92f6d6c40a.tar.gz scala-1297d87d5e5bfa25022568b6e20fbd92f6d6c40a.tar.bz2 scala-1297d87d5e5bfa25022568b6e20fbd92f6d6c40a.zip |
More style tips for team macros.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/reflect/makro/runtime/Enclosures.scala | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/src/compiler/scala/reflect/makro/runtime/Enclosures.scala b/src/compiler/scala/reflect/makro/runtime/Enclosures.scala index 72e9e568c0..ab38fc024d 100644 --- a/src/compiler/scala/reflect/makro/runtime/Enclosures.scala +++ b/src/compiler/scala/reflect/makro/runtime/Enclosures.scala @@ -6,31 +6,18 @@ trait Enclosures { import mirror._ + private def site = callsiteTyper.context + private def enclTrees = site.enclosingContextChain map (_.tree) + private def enclPoses = enclosingMacros map (_.macroApplication.pos) filterNot (_ eq NoPosition) + // vals are eager to simplify debugging // after all we wouldn't save that much time by making them lazy - - val macroApplication: Tree = expandee - - val enclosingMacros: List[Context] = this :: mirror.analyzer.openMacros // include self - - val enclosingImplicits: List[(Type, Tree)] = callsiteTyper.context.openImplicits - - val enclosingPosition: Position = enclosingMacros.find(c => c.macroApplication.pos != NoPosition).map(_.macroApplication.pos).getOrElse(NoPosition) - - val enclosingApplication: Tree = { - def loop(context: analyzer.Context): Tree = context match { - case analyzer.NoContext => EmptyTree - case context if context.tree.isInstanceOf[Apply] => context.tree - case context => loop(context.outer) - } - - val context = callsiteTyper.context - loop(context) - } - - val enclosingMethod: Tree = callsiteTyper.context.enclMethod.tree - - val enclosingClass: Tree = callsiteTyper.context.enclClass.tree - - val enclosingUnit: CompilationUnit = currentRun.currentUnit -}
\ No newline at end of file + val macroApplication: Tree = expandee + val enclosingApplication: Tree = enclTrees collectFirst { case t: Apply => t } getOrElse EmptyTree + val enclosingClass: Tree = site.enclClass.tree + val enclosingImplicits: List[(Type, Tree)] = site.openImplicits + val enclosingMacros: List[Context] = this :: mirror.analyzer.openMacros // include self + val enclosingMethod: Tree = site.enclMethod.tree + val enclosingPosition: Position = if (enclPoses.isEmpty) NoPosition else enclPoses.head.pos + val enclosingUnit: CompilationUnit = currentRun.currentUnit +} |