aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Annotations.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-09-15 18:08:10 +0200
committerMartin Odersky <odersky@gmail.com>2016-10-02 16:12:28 +0200
commit95e488eab2a686671b2a6ffd8fce05c043b3afab (patch)
tree397e7af116478809048f82b5469e6d7101b160ca /src/dotty/tools/dotc/core/Annotations.scala
parent5a46d19dde76b739f6672c9b6f57355cfd38159a (diff)
downloaddotty-95e488eab2a686671b2a6ffd8fce05c043b3afab.tar.gz
dotty-95e488eab2a686671b2a6ffd8fce05c043b3afab.tar.bz2
dotty-95e488eab2a686671b2a6ffd8fce05c043b3afab.zip
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.
Diffstat (limited to 'src/dotty/tools/dotc/core/Annotations.scala')
-rw-r--r--src/dotty/tools/dotc/core/Annotations.scala28
1 files changed, 28 insertions, 0 deletions
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)