diff options
author | Martin Odersky <odersky@gmail.com> | 2013-05-23 14:33:25 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-05-23 14:33:25 +0200 |
commit | e1be722f469c45e7546388359b5870a07f4c14b8 (patch) | |
tree | 53720d33f176dcb18cb4443867cd378bcdb62ef1 /src/dotty/tools/dotc/ast/TypedTrees.scala | |
parent | db39f1a5f5062f00e09e20a897e8f6d26e1e4193 (diff) | |
download | dotty-e1be722f469c45e7546388359b5870a07f4c14b8.tar.gz dotty-e1be722f469c45e7546388359b5870a07f4c14b8.tar.bz2 dotty-e1be722f469c45e7546388359b5870a07f4c14b8.zip |
More tweaks to desugaring
(1) Made desugaring reaching a fixed point.
(2) Systematic encoding of names.
(3) Introduced Closure nodes which represent anonymous functions
Diffstat (limited to 'src/dotty/tools/dotc/ast/TypedTrees.scala')
-rw-r--r-- | src/dotty/tools/dotc/ast/TypedTrees.scala | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/src/dotty/tools/dotc/ast/TypedTrees.scala b/src/dotty/tools/dotc/ast/TypedTrees.scala index e5e0c99fd..93b83bdb0 100644 --- a/src/dotty/tools/dotc/ast/TypedTrees.scala +++ b/src/dotty/tools/dotc/ast/TypedTrees.scala @@ -90,6 +90,30 @@ object tpd extends Trees.Instance[Type] { def If(cond: Tree, thenp: Tree, elsep: Tree)(implicit ctx: Context): If = Trees.If(cond, thenp, elsep).withType(thenp.tpe | elsep.tpe).checked + /** A function def + * + * vparams => expr + * + * gets expanded to + * + * { def $anonfun(vparams) = expr; Closure($anonfun) } + * + * where the closure's type is the target type of the expression (FunctionN, unless + * otherwise specified). + */ + def Closure(meth: TermSymbol, body: Tree, target: Type = NoType)(implicit ctx: Context): Block = { + val funtpe = + if (target.exists) target + else meth.info match { + case mt @ MethodType(_, formals) => + assert(!mt.isDependent) + defn.FunctionType(formals, mt.resultType) + } + Block( + DefDef(meth, body) :: Nil, + Trees.Closure(Nil, Ident(TermRef.withSym(NoPrefix, meth)))).withType(funtpe).checked + } + def Match(selector: Tree, cases: List[CaseDef])(implicit ctx: Context): Match = Trees.Match(selector, cases).withType(ctx.lub(cases map (_.body.tpe))).checked @@ -284,30 +308,6 @@ object tpd extends Trees.Instance[Type] { TempTrees(valdef :: clsdef :: Nil) } - /** A function def - * - * vparams => expr - * - * gets expanded to - * - * { def $anonfun(vparams) = expr; $anonfun: pt } - * - * where pt is the target type of the expression (FunctionN) unless - * otherwise specified. - */ - def Function(meth: TermSymbol, body: Tree, target: Type = NoType)(implicit ctx: Context): Block = { - val funtpe = - if (target.exists) target - else meth.info match { - case mt @ MethodType(_, formals) => - assert(!mt.isDependent) - defn.FunctionType(formals, mt.resultType) - } - Block( - DefDef(meth, body) :: Nil, - Typed(Ident(TermRef.withSym(NoPrefix, meth)), TypeTree(funtpe))) - } - private class FindLocalDummyAccumulator(cls: ClassSymbol)(implicit ctx: Context) extends TreeAccumulator[Symbol] { def apply(sym: Symbol, tree: Tree) = if (sym.exists) sym |