diff options
author | Martin Odersky <odersky@gmail.com> | 2003-08-25 15:26:29 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2003-08-25 15:26:29 +0000 |
commit | 1cfdffddd1d0d8d71426ef6c1b43aba3e9187561 (patch) | |
tree | dff7c39b217d268626af1014bb972d90036ec031 /sources/scalac/ast/TreeGen.java | |
parent | 4f8b58c0aed01c7a2659963ab658e5dd4239d9c4 (diff) | |
download | scala-1cfdffddd1d0d8d71426ef6c1b43aba3e9187561.tar.gz scala-1cfdffddd1d0d8d71426ef6c1b43aba3e9187561.tar.bz2 scala-1cfdffddd1d0d8d71426ef6c1b43aba3e9187561.zip |
*** empty log message ***
Diffstat (limited to 'sources/scalac/ast/TreeGen.java')
-rw-r--r-- | sources/scalac/ast/TreeGen.java | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java index 36729e3270..e3c2315005 100644 --- a/sources/scalac/ast/TreeGen.java +++ b/sources/scalac/ast/TreeGen.java @@ -659,6 +659,7 @@ public class TreeGen implements Kinds, Modifiers { return Block(new Tree[]{classDef, alloc}); } + public Tree mkPartialFunction(int pos, Tree applyVisitor, Tree isDefinedAtVisitor, Type pattype, Type restype, Symbol owner) { Type pft = definitions.partialFunctionType(pattype, restype); @@ -688,8 +689,12 @@ public class TreeGen implements Kinds, Modifiers { meth.setInfo(Type.MethodType(new Symbol[]{param}, restype)); clazz.info().members().enter(meth); changeOwner(visitor, prevOwner, meth); - Tree body = Apply( - Select(Ident(param), definitions.MATCH), new Tree[]{visitor}) + Tree body = + Apply( + TypeApply( + Select(Ident(param), definitions.MATCH), + new Tree[]{mkType(pos, pattype), mkType(pos, restype)}), + new Tree[]{visitor}) .setType(restype); return DefDef(meth, body); } @@ -710,4 +715,20 @@ public class TreeGen implements Kinds, Modifiers { }; lifter.traverse(tree); } + + /** Build a postfix function application + */ + public Tree postfixApply(Tree obj, Tree fn, Symbol owner) { + if (TreeInfo.isPureExpr(obj) || TreeInfo.isPureExpr(fn)) { + return Apply(Select(fn, Names.apply), new Tree[]{obj}); + } else { + Name tmpname = global.freshNameCreator.newName("tmp", '$'); + Symbol tmp = new TermSymbol( + obj.pos, tmpname, owner, SYNTHETIC | FINAL) + .setInfo(obj.type); + Tree tmpdef = ValDef(tmp, obj); + Tree expr = postfixApply(Ident(tmp), fn, owner); + return Block(new Tree[]{tmpdef, expr}); + } + } } |