aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/ast/Trees.scala
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2016-10-06 15:02:17 +0200
committerGitHub <noreply@github.com>2016-10-06 15:02:17 +0200
commit87a775724173bd803a0c4956408e61fd0d5812af (patch)
treec564a236f9247b085ed26c1fb007dad74ed049dd /src/dotty/tools/dotc/ast/Trees.scala
parenta3064622e7ce4d73ddd91de0fc6bebfe0ec23ae9 (diff)
parente0a14e7939eda6a7f4914831975b2ac8877696f2 (diff)
downloaddotty-87a775724173bd803a0c4956408e61fd0d5812af.tar.gz
dotty-87a775724173bd803a0c4956408e61fd0d5812af.tar.bz2
dotty-87a775724173bd803a0c4956408e61fd0d5812af.zip
Merge pull request #1492 from dotty-staging/add-inline
Implement inline
Diffstat (limited to 'src/dotty/tools/dotc/ast/Trees.scala')
-rw-r--r--src/dotty/tools/dotc/ast/Trees.scala34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala
index bb6fbd5ba..6986e40e7 100644
--- a/src/dotty/tools/dotc/ast/Trees.scala
+++ b/src/dotty/tools/dotc/ast/Trees.scala
@@ -12,7 +12,7 @@ import collection.immutable.IndexedSeq
import collection.mutable.ListBuffer
import parsing.Tokens.Token
import printing.Printer
-import util.{Stats, Attachment, DotClass}
+import util.{Stats, Attachment, Property, DotClass}
import annotation.unchecked.uncheckedVariance
import language.implicitConversions
import parsing.Scanners.Comment
@@ -30,8 +30,8 @@ object Trees {
/** The total number of created tree nodes, maintained if Stats.enabled */
@sharable var ntrees = 0
- /** Attachment key for trees with documentation strings attached */
- val DocComment = new Attachment.Key[Comment]
+ /** Property key for trees with documentation strings attached */
+ val DocComment = new Property.Key[Comment]
@sharable private var nextId = 0 // for debugging
@@ -503,6 +503,25 @@ object Trees {
override def toString = s"JavaSeqLiteral($elems, $elemtpt)"
}
+ /** A tree representing inlined code.
+ *
+ * @param call The original call that was inlined
+ * @param bindings Bindings for proxies to be used in the inlined code
+ * @param expansion The inlined tree, minus bindings.
+ *
+ * The full inlined code is equivalent to
+ *
+ * { bindings; expansion }
+ *
+ * The reason to keep `bindings` separate is because they are typed in a
+ * different context: `bindings` represent the arguments to the inlined
+ * call, whereas `expansion` represents the body of the inlined function.
+ */
+ case class Inlined[-T >: Untyped] private[ast] (call: tpd.Tree, bindings: List[MemberDef[T]], expansion: Tree[T])
+ extends Tree[T] {
+ type ThisTree[-T >: Untyped] = Inlined[T]
+ }
+
/** A type tree that represents an existing or inferred type */
case class TypeTree[-T >: Untyped] private[ast] (original: Tree[T])
extends DenotingTree[T] with TypTree[T] {
@@ -797,6 +816,7 @@ object Trees {
type Try = Trees.Try[T]
type SeqLiteral = Trees.SeqLiteral[T]
type JavaSeqLiteral = Trees.JavaSeqLiteral[T]
+ type Inlined = Trees.Inlined[T]
type TypeTree = Trees.TypeTree[T]
type SingletonTypeTree = Trees.SingletonTypeTree[T]
type AndTypeTree = Trees.AndTypeTree[T]
@@ -939,6 +959,10 @@ object Trees {
case tree: SeqLiteral if (elems eq tree.elems) && (elemtpt eq tree.elemtpt) => tree
case _ => finalize(tree, untpd.SeqLiteral(elems, elemtpt))
}
+ def Inlined(tree: Tree)(call: tpd.Tree, bindings: List[MemberDef], expansion: Tree)(implicit ctx: Context): Inlined = tree match {
+ case tree: Inlined if (call eq tree.call) && (bindings eq tree.bindings) && (expansion eq tree.expansion) => tree
+ case _ => finalize(tree, untpd.Inlined(call, bindings, expansion))
+ }
def TypeTree(tree: Tree)(original: Tree): TypeTree = tree match {
case tree: TypeTree if original eq tree.original => tree
case _ => finalize(tree, untpd.TypeTree(original))
@@ -1083,6 +1107,8 @@ object Trees {
cpy.Try(tree)(transform(block), transformSub(cases), transform(finalizer))
case SeqLiteral(elems, elemtpt) =>
cpy.SeqLiteral(tree)(transform(elems), transform(elemtpt))
+ case Inlined(call, bindings, expansion) =>
+ cpy.Inlined(tree)(call, transformSub(bindings), transform(expansion))
case TypeTree(original) =>
tree
case SingletonTypeTree(ref) =>
@@ -1185,6 +1211,8 @@ object Trees {
this(this(this(x, block), handler), finalizer)
case SeqLiteral(elems, elemtpt) =>
this(this(x, elems), elemtpt)
+ case Inlined(call, bindings, expansion) =>
+ this(this(x, bindings), expansion)
case TypeTree(original) =>
x
case SingletonTypeTree(ref) =>