aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-07-10 11:58:54 +0200
committerMartin Odersky <odersky@gmail.com>2014-07-17 11:02:01 +0200
commit05120fc7ea83a00485a68d2854e5b62c1dbb8c01 (patch)
treecd4d45cb00df8d7d6499ba082c95a4d90d86bbe1 /src/dotty/tools
parent7b13a861787eb1e7823957b156dbb989f7b415d3 (diff)
downloaddotty-05120fc7ea83a00485a68d2854e5b62c1dbb8c01.tar.gz
dotty-05120fc7ea83a00485a68d2854e5b62c1dbb8c01.tar.bz2
dotty-05120fc7ea83a00485a68d2854e5b62c1dbb8c01.zip
Fixes to MacroTransform and TreeTransformer
1) Make local context go to module class if the tree symbol is a package val. Perviously, this gave the wrong context owner for package definitions. 2) Add a hook to define the phase in which a transform should be run.
Diffstat (limited to 'src/dotty/tools')
-rw-r--r--src/dotty/tools/dotc/transform/MacroTransform.scala16
-rw-r--r--src/dotty/tools/dotc/transform/TreeTransform.scala8
2 files changed, 20 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/transform/MacroTransform.scala b/src/dotty/tools/dotc/transform/MacroTransform.scala
index 1ed9e68c2..0ee92bccd 100644
--- a/src/dotty/tools/dotc/transform/MacroTransform.scala
+++ b/src/dotty/tools/dotc/transform/MacroTransform.scala
@@ -7,6 +7,7 @@ import Phases._
import ast.Trees._
import Contexts._
import Symbols._
+import Flags.PackageVal
import Decorators._
/** A base class for transforms.
@@ -18,15 +19,24 @@ abstract class MacroTransform extends Phase {
override def run(implicit ctx: Context): Unit = {
val unit = ctx.compilationUnit
- unit.tpdTree = newTransformer.transform(unit.tpdTree)
+ unit.tpdTree = newTransformer.transform(unit.tpdTree)(ctx.withPhase(transformPhase))
}
protected def newTransformer(implicit ctx: Context): Transformer
+ /** The phase in which the transformation should be run.
+ * By default this is the phase given by the this macro transformer,
+ * but it could be overridden to be the phase following that one.
+ */
+ protected def transformPhase(implicit ctx: Context): Phase = this
+
class Transformer extends TreeMap {
- protected def localCtx(tree: Tree)(implicit ctx: Context) =
- ctx.fresh.setTree(tree).setOwner(tree.symbol)
+ protected def localCtx(tree: Tree)(implicit ctx: Context) = {
+ val sym = tree.symbol
+ val owner = if (sym is PackageVal) sym.moduleClass else sym
+ ctx.fresh.setTree(tree).setOwner(owner)
+ }
/** The current enclosing class
* @pre We must be inside a class
diff --git a/src/dotty/tools/dotc/transform/TreeTransform.scala b/src/dotty/tools/dotc/transform/TreeTransform.scala
index 2bc733465..8e7c4f6d0 100644
--- a/src/dotty/tools/dotc/transform/TreeTransform.scala
+++ b/src/dotty/tools/dotc/transform/TreeTransform.scala
@@ -5,6 +5,7 @@ import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Phases.Phase
import dotty.tools.dotc.core.Symbols.Symbol
+import dotty.tools.dotc.core.Flags.PackageVal
import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.core.Decorators._
import scala.annotation.tailrec
@@ -883,7 +884,12 @@ object TreeTransforms {
}
} else tree
- def localContext(owner: Symbol)(implicit ctx: Context) = ctx.fresh.setOwner(owner)
+ // TODO merge with localCtx in MacroTransform
+ // Generally: If we will keep MacroTransform, merge common behavior with TreeTransform
+ def localContext(sym: Symbol)(implicit ctx: Context) = {
+ val owner = if (sym is PackageVal) sym.moduleClass else sym
+ ctx.fresh.setOwner(owner)
+ }
final private[TreeTransforms] def transformNamed(tree: NameTree, info: TransformerInfo, cur: Int)(implicit ctx: Context): Tree =
tree match {