diff options
author | Martin Odersky <odersky@gmail.com> | 2013-02-27 12:45:22 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-02-27 12:45:22 +0100 |
commit | 89e3da3cba740bc8eb64c9145c449e376481b377 (patch) | |
tree | 339fc7b604f7dfbc649fb7a877df3aa5446959d9 /src/dotty/tools | |
parent | 5b786065301ecab3fd1b38ac9089b5d58acc9082 (diff) | |
download | dotty-89e3da3cba740bc8eb64c9145c449e376481b377.tar.gz dotty-89e3da3cba740bc8eb64c9145c449e376481b377.tar.bz2 dotty-89e3da3cba740bc8eb64c9145c449e376481b377.zip |
Fixed ModuleDefs so that they produce code that keeps invariants of tree maps.
We need to make sure that every symbol that needs to be changed in a treemap is visible in the tree. For that reason,
ModuleDefs now generate ClassDefs that are integrated in the regular tree, next to the ValDef the represents the module.
Diffstat (limited to 'src/dotty/tools')
-rw-r--r-- | src/dotty/tools/dotc/core/TypedTrees.scala | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/core/TypedTrees.scala b/src/dotty/tools/dotc/core/TypedTrees.scala index 354d28d5e..7f2838c66 100644 --- a/src/dotty/tools/dotc/core/TypedTrees.scala +++ b/src/dotty/tools/dotc/core/TypedTrees.scala @@ -335,11 +335,11 @@ object TypedTrees { * the RHS of a method contains a class owned by the method, this would be * an error. */ - def ModuleDef(sym: TermSymbol, body: List[Tree])(implicit ctx: Context): ValDef = { + def ModuleDef(sym: TermSymbol, body: List[Tree])(implicit ctx: Context): TempTrees = { val modcls = sym.moduleClass.asClass val clsdef = ClassDef(modcls, Nil, body) - val rhs = Block(List(clsdef), New(modcls.typeConstructor)) - ValDef(sym, rhs) + val valdef = ValDef(sym, New(modcls.typeConstructor)) + TempTrees(valdef :: clsdef :: Nil) } /** A function def @@ -376,6 +376,26 @@ object TypedTrees { else sym } else foldOver(sym, tree) } + + /** Temporary class that results from translation of ModuleDefs + * (and possibly other statements). + * The contained trees will be integrated in enclosing Blocks or Templates + */ + case class TempTrees(trees: List[Tree]) extends Tree { + override def pos: Position = unsupported("pos") + override def tpe: Type = unsupported("tpe") + } + + /** Integrates nested TempTrees in given list of trees */ + def flatten(trees: List[Tree]): List[Tree] = + if (trees exists isTempTrees) + trees flatMap { + case TempTrees(ts) => ts + case t => t :: Nil + } + else trees + + private val isTempTrees: Tree => Boolean = (_.isInstanceOf[TempTrees]) } import Trees._ |