aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/UntypedTrees.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-05-28 14:56:22 +0200
committerMartin Odersky <odersky@gmail.com>2013-05-28 14:56:22 +0200
commitc53ac49cbe7c98c05a99fea3c8e1dcad75275a82 (patch)
tree0eef0f9b2cf63f025f70183846bb90ef7b83dabb /src/dotty/tools/dotc/ast/UntypedTrees.scala
parent41c54e9b3df245defd774cf06132880479128cb5 (diff)
downloaddotty-c53ac49cbe7c98c05a99fea3c8e1dcad75275a82.tar.gz
dotty-c53ac49cbe7c98c05a99fea3c8e1dcad75275a82.tar.bz2
dotty-c53ac49cbe7c98c05a99fea3c8e1dcad75275a82.zip
wip namer.
Diffstat (limited to 'src/dotty/tools/dotc/ast/UntypedTrees.scala')
-rw-r--r--src/dotty/tools/dotc/ast/UntypedTrees.scala26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/ast/UntypedTrees.scala b/src/dotty/tools/dotc/ast/UntypedTrees.scala
index 3087772a8..bc64bc465 100644
--- a/src/dotty/tools/dotc/ast/UntypedTrees.scala
+++ b/src/dotty/tools/dotc/ast/UntypedTrees.scala
@@ -70,13 +70,18 @@ object untpd extends Trees.Instance[Untyped] {
case _ => Tuple(ts)
}
+ def makeParameter(pname: TermName, tpe: Tree, mods: Modifiers = Modifiers()): ValDef =
+ ValDef(mods | Param, pname, tpe, emptyTree())
+
+ def makeSyntheticParameter(n: Int = 1, tpt: Tree = EmptyTree)(implicit ctx: Context): ValDef =
+ ValDef(Modifiers(SyntheticTermParam), nme.syntheticParamName(n), TypeTree(), EmptyTree)
+
+ def refOfDef(tree: NameTree) = Ident(tree.name)
+
// ------ Untyped tree desugaring ------------------------------------------
def desugar(tree: Tree, mode: Mode.Value)(implicit ctx: Context): Tree = {
- def makeSyntheticParameter(): ValDef =
- ValDef(Modifiers(SyntheticTermParam), ctx.freshName().toTermName, TypeTree(), EmptyTree)
-
def labelDefAndCall(lname: TermName, rhs: Tree, call: Tree) = {
val ldef = DefDef(Modifiers(Label), lname, Nil, ListOfNil, TypeTree(), rhs)
Block(ldef, call)
@@ -439,6 +444,21 @@ object untpd extends Trees.Instance[Untyped] {
case _ => tree
}
+ /** Expand to:
+ * <module> val name: name$ = New(name$)
+ * <module> final class name$ extends parents { self: name.type => body }
+ */
+ def desugarModuleDef(mdef: ModuleDef): Tree = {
+ val ModuleDef(mods, name, tmpl @ Template(constr, parents, self, body)) = mdef
+ val clsName = name.moduleClassName
+ val clsRef = Ident(clsName)
+ val modul = ValDef(mods | ModuleCreationFlags, name, clsRef, New(clsRef, Nil))
+ val clsSelf = self.derivedValDef(self.mods, self.name, SingletonTypeTree(Ident(name)), self.rhs)
+ val clsTmpl = tmpl.derivedTemplate(constr, parents, clsSelf, body)
+ val cls = ClassDef(mods.toTypeFlags & AccessFlags | ModuleClassCreationFlags, clsName, Nil, clsTmpl)
+ Thicket(modul, cls)
+ }
+
def desugarAnonClass(templ: Template): Tree = {
val x = tpnme.ANON_CLASS
val clsDef = ClassDef(Modifiers(Final), x, Nil, templ)