From 5d29697365245707af1a037678a7b48b0fef341c Mon Sep 17 00:00:00 2001 From: James Iry Date: Wed, 28 Aug 2013 20:41:12 -0700 Subject: Flesh out the Delambdafy phase. This commit puts a real body on the Delambdafy phase. From a lambda, Delambdafy will create 1) a static forwarder at the top level of the class that contained the lambda 2) a new top level class that a) has fields and a constructor taking the captured environment (including possbily the "this" reference) b) an apply method that calls the static forwarder c) if needed a bridge method for the apply method 3) an instantiation of the newly created class which replaces the lambda Trees.scala is modified to add two more convenient factories for templates and classdefs. A few basic tests are included to verify that it works as expected. Further commits will have additional tests. --- src/reflect/scala/reflect/internal/StdNames.scala | 1 + src/reflect/scala/reflect/internal/Trees.scala | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src/reflect') diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala index 9f56e78059..02f22a16f6 100644 --- a/src/reflect/scala/reflect/internal/StdNames.scala +++ b/src/reflect/scala/reflect/internal/StdNames.scala @@ -609,6 +609,7 @@ trait StdNames { val TypeRef: NameType = "TypeRef" val TypeTree: NameType = "TypeTree" val UNIT : NameType = "UNIT" + val accessor: NameType = "accessor" val add_ : NameType = "add" val annotation: NameType = "annotation" val anyValClass: NameType = "anyValClass" diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index 9adddeed50..743c674eea 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -1001,7 +1001,8 @@ trait Trees extends api.Trees { // ---- values and creators --------------------------------------- /** @param sym the class symbol - * @return the implementation template + * @param impl the implementation template + * @return the class definition */ def ClassDef(sym: Symbol, impl: Template): ClassDef = atPos(sym.pos) { @@ -1011,6 +1012,25 @@ trait Trees extends api.Trees { impl) setSymbol sym } + /** @param sym the class symbol + * @param body trees that constitute the body of the class + * @return the class definition + */ + def ClassDef(sym: Symbol, body: List[Tree]): ClassDef = + ClassDef(sym, Template(sym, body)) + + /** @param sym the template's symbol + * @param body trees that constitute the body of the template + * @return the template + */ + def Template(sym: Symbol, body: List[Tree]): Template = { + atPos(sym.pos) { + Template(sym.info.parents map TypeTree, + if (sym.thisSym == sym) noSelfType else ValDef(sym), + body) + } + } + /** * @param sym the class symbol * @param impl the implementation template -- cgit v1.2.3