From 95e488eab2a686671b2a6ffd8fce05c043b3afab Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 15 Sep 2016 18:08:10 +0200 Subject: Use BodyAnnot to indicate rhs of inline method Since fundamental operations such as treeCopy have to know about inline bodies, it seems better to represent this information directly in an annotation. --- src/dotty/tools/dotc/core/Annotations.scala | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/dotty/tools/dotc/core/Annotations.scala') diff --git a/src/dotty/tools/dotc/core/Annotations.scala b/src/dotty/tools/dotc/core/Annotations.scala index 5f96a60e6..fde41ef76 100644 --- a/src/dotty/tools/dotc/core/Annotations.scala +++ b/src/dotty/tools/dotc/core/Annotations.scala @@ -42,6 +42,34 @@ object Annotations { override def symbol(implicit ctx: Context): Symbol = sym } + /** An annotation indicating the body of a right-hand side, + * typically of an inline method. Treated specially in + * pickling/unpickling and treecopies + */ + abstract class BodyAnnotation extends Annotation { + override def symbol(implicit ctx: Context) = defn.BodyAnnot + override def derivedAnnotation(tree: Tree)(implicit ctx: Context) = + if (tree eq this.tree) this else ConcreteBodyAnnotation(tree) + override def arguments(implicit ctx: Context) = Nil + } + + case class ConcreteBodyAnnotation(body: Tree) extends BodyAnnotation { + def tree(implicit ctx: Context) = body + } + + case class LazyBodyAnnotation(bodyExpr: Context => Tree) extends BodyAnnotation { + private var evaluated = false + private var myBody: Tree = _ + def tree(implicit ctx: Context) = { + if (evaluated) assert(myBody != null) + else { + evaluated = true + myBody = bodyExpr(ctx) + } + myBody + } + } + object Annotation { def apply(tree: Tree) = ConcreteAnnotation(tree) -- cgit v1.2.3