aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-09-01 17:31:10 +0200
committerMartin Odersky <odersky@gmail.com>2016-10-02 16:11:21 +0200
commit8a3762a62d12b7f57de27c840425184df56b2689 (patch)
tree35db0a16b8361568290c20dcb5d215af7178cc62 /src/dotty/tools/dotc/transform
parentd63a6ba8540fb8ea7d01350ea68ff1ef0b53c5d4 (diff)
downloaddotty-8a3762a62d12b7f57de27c840425184df56b2689.tar.gz
dotty-8a3762a62d12b7f57de27c840425184df56b2689.tar.bz2
dotty-8a3762a62d12b7f57de27c840425184df56b2689.zip
Add Inlined tree node
... to tag inlined calls. Perform typings and transformations of inlined calls in a context that refers to the INlined node in its InlinedCall property. The idea is that we can use this to issue better error positions. This remains to be implemented.
Diffstat (limited to 'src/dotty/tools/dotc/transform')
-rw-r--r--src/dotty/tools/dotc/transform/TreeChecker.scala3
-rw-r--r--src/dotty/tools/dotc/transform/TreeTransform.scala32
2 files changed, 34 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/transform/TreeChecker.scala b/src/dotty/tools/dotc/transform/TreeChecker.scala
index e7342aec9..074a278ca 100644
--- a/src/dotty/tools/dotc/transform/TreeChecker.scala
+++ b/src/dotty/tools/dotc/transform/TreeChecker.scala
@@ -396,6 +396,9 @@ class TreeChecker extends Phase with SymTransformer {
override def typedBlock(tree: untpd.Block, pt: Type)(implicit ctx: Context) =
withDefinedSyms(tree.stats) { super.typedBlock(tree, pt) }
+ override def typedInlined(tree: untpd.Inlined, pt: Type)(implicit ctx: Context) =
+ withDefinedSyms(tree.bindings) { super.typedInlined(tree, pt) }
+
/** Check that all defined symbols have legal owners.
* An owner is legal if it is either the same as the context's owner
* or there's an owner chain of valdefs starting at the context's owner and
diff --git a/src/dotty/tools/dotc/transform/TreeTransform.scala b/src/dotty/tools/dotc/transform/TreeTransform.scala
index 05961508a..40a5cb0bf 100644
--- a/src/dotty/tools/dotc/transform/TreeTransform.scala
+++ b/src/dotty/tools/dotc/transform/TreeTransform.scala
@@ -15,6 +15,7 @@ import dotty.tools.dotc.core.Mode
import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.core.Decorators._
import dotty.tools.dotc.util.DotClass
+import dotty.tools.dotc.typer.Inliner
import scala.annotation.tailrec
import config.Printers.transforms
import scala.util.control.NonFatal
@@ -81,6 +82,7 @@ object TreeTransforms {
def prepareForReturn(tree: Return)(implicit ctx: Context) = this
def prepareForTry(tree: Try)(implicit ctx: Context) = this
def prepareForSeqLiteral(tree: SeqLiteral)(implicit ctx: Context) = this
+ def prepareForInlined(tree: Inlined)(implicit ctx: Context) = this
def prepareForTypeTree(tree: TypeTree)(implicit ctx: Context) = this
def prepareForBind(tree: Bind)(implicit ctx: Context) = this
def prepareForAlternative(tree: Alternative)(implicit ctx: Context) = this
@@ -112,6 +114,7 @@ object TreeTransforms {
def transformReturn(tree: Return)(implicit ctx: Context, info: TransformerInfo): Tree = tree
def transformTry(tree: Try)(implicit ctx: Context, info: TransformerInfo): Tree = tree
def transformSeqLiteral(tree: SeqLiteral)(implicit ctx: Context, info: TransformerInfo): Tree = tree
+ def transformInlined(tree: Inlined)(implicit ctx: Context, info: TransformerInfo): Tree = tree
def transformTypeTree(tree: TypeTree)(implicit ctx: Context, info: TransformerInfo): Tree = tree
def transformBind(tree: Bind)(implicit ctx: Context, info: TransformerInfo): Tree = tree
def transformAlternative(tree: Alternative)(implicit ctx: Context, info: TransformerInfo): Tree = tree
@@ -273,6 +276,7 @@ object TreeTransforms {
nxPrepReturn = index(transformations, "prepareForReturn")
nxPrepTry = index(transformations, "prepareForTry")
nxPrepSeqLiteral = index(transformations, "prepareForSeqLiteral")
+ nxPrepInlined = index(transformations, "prepareForInlined")
nxPrepTypeTree = index(transformations, "prepareForTypeTree")
nxPrepBind = index(transformations, "prepareForBind")
nxPrepAlternative = index(transformations, "prepareForAlternative")
@@ -303,6 +307,7 @@ object TreeTransforms {
nxTransReturn = index(transformations, "transformReturn")
nxTransTry = index(transformations, "transformTry")
nxTransSeqLiteral = index(transformations, "transformSeqLiteral")
+ nxTransInlined = index(transformations, "transformInlined")
nxTransTypeTree = index(transformations, "transformTypeTree")
nxTransBind = index(transformations, "transformBind")
nxTransAlternative = index(transformations, "transformAlternative")
@@ -343,6 +348,7 @@ object TreeTransforms {
nxPrepReturn = indexUpdate(prev.nxPrepReturn, changedTransformationClass, transformationIndex, "prepareForReturn", copy)
nxPrepTry = indexUpdate(prev.nxPrepTry, changedTransformationClass, transformationIndex, "prepareForTry", copy)
nxPrepSeqLiteral = indexUpdate(prev.nxPrepSeqLiteral, changedTransformationClass, transformationIndex, "prepareForSeqLiteral", copy)
+ nxPrepInlined = indexUpdate(prev.nxPrepInlined, changedTransformationClass, transformationIndex, "prepareForInlined", copy)
nxPrepTypeTree = indexUpdate(prev.nxPrepTypeTree, changedTransformationClass, transformationIndex, "prepareForTypeTree", copy)
nxPrepBind = indexUpdate(prev.nxPrepBind, changedTransformationClass, transformationIndex, "prepareForBind", copy)
nxPrepAlternative = indexUpdate(prev.nxPrepAlternative, changedTransformationClass, transformationIndex, "prepareForAlternative", copy)
@@ -372,6 +378,7 @@ object TreeTransforms {
nxTransReturn = indexUpdate(prev.nxTransReturn, changedTransformationClass, transformationIndex, "transformReturn", copy)
nxTransTry = indexUpdate(prev.nxTransTry, changedTransformationClass, transformationIndex, "transformTry", copy)
nxTransSeqLiteral = indexUpdate(prev.nxTransSeqLiteral, changedTransformationClass, transformationIndex, "transformSeqLiteral", copy)
+ nxTransInlined = indexUpdate(prev.nxTransInlined, changedTransformationClass, transformationIndex, "transformInlined", copy)
nxTransTypeTree = indexUpdate(prev.nxTransTypeTree, changedTransformationClass, transformationIndex, "transformTypeTree", copy)
nxTransBind = indexUpdate(prev.nxTransBind, changedTransformationClass, transformationIndex, "transformBind", copy)
nxTransAlternative = indexUpdate(prev.nxTransAlternative, changedTransformationClass, transformationIndex, "transformAlternative", copy)
@@ -407,6 +414,7 @@ object TreeTransforms {
var nxPrepReturn: Array[Int] = _
var nxPrepTry: Array[Int] = _
var nxPrepSeqLiteral: Array[Int] = _
+ var nxPrepInlined: Array[Int] = _
var nxPrepTypeTree: Array[Int] = _
var nxPrepBind: Array[Int] = _
var nxPrepAlternative: Array[Int] = _
@@ -437,6 +445,7 @@ object TreeTransforms {
var nxTransReturn: Array[Int] = _
var nxTransTry: Array[Int] = _
var nxTransSeqLiteral: Array[Int] = _
+ var nxTransInlined: Array[Int] = _
var nxTransTypeTree: Array[Int] = _
var nxTransBind: Array[Int] = _
var nxTransAlternative: Array[Int] = _
@@ -515,6 +524,7 @@ object TreeTransforms {
val prepForReturn: Mutator[Return] = (trans, tree, ctx) => trans.prepareForReturn(tree)(ctx)
val prepForTry: Mutator[Try] = (trans, tree, ctx) => trans.prepareForTry(tree)(ctx)
val prepForSeqLiteral: Mutator[SeqLiteral] = (trans, tree, ctx) => trans.prepareForSeqLiteral(tree)(ctx)
+ val prepForInlined: Mutator[Inlined] = (trans, tree, ctx) => trans.prepareForInlined(tree)(ctx)
val prepForTypeTree: Mutator[TypeTree] = (trans, tree, ctx) => trans.prepareForTypeTree(tree)(ctx)
val prepForBind: Mutator[Bind] = (trans, tree, ctx) => trans.prepareForBind(tree)(ctx)
val prepForAlternative: Mutator[Alternative] = (trans, tree, ctx) => trans.prepareForAlternative(tree)(ctx)
@@ -741,6 +751,17 @@ object TreeTransforms {
}
@tailrec
+ final private[TreeTransforms] def goInlined(tree: Inlined, cur: Int)(implicit ctx: Context, info: TransformerInfo): Tree = {
+ if (cur < info.transformers.length) {
+ val trans = info.transformers(cur)
+ trans.transformInlined(tree)(ctx.withPhase(trans.treeTransformPhase), info) match {
+ case t: Inlined => goInlined(t, info.nx.nxTransInlined(cur + 1))
+ case t => transformSingle(t, cur + 1)
+ }
+ } else tree
+ }
+
+ @tailrec
final private[TreeTransforms] def goTypeTree(tree: TypeTree, cur: Int)(implicit ctx: Context, info: TransformerInfo): Tree = {
if (cur < info.transformers.length) {
val trans = info.transformers(cur)
@@ -884,7 +905,8 @@ object TreeTransforms {
case tree: CaseDef => goCaseDef(tree, info.nx.nxTransCaseDef(cur))
case tree: Return => goReturn(tree, info.nx.nxTransReturn(cur))
case tree: Try => goTry(tree, info.nx.nxTransTry(cur))
- case tree: SeqLiteral => goSeqLiteral(tree, info.nx.nxTransLiteral(cur))
+ case tree: SeqLiteral => goSeqLiteral(tree, info.nx.nxTransSeqLiteral(cur))
+ case tree: Inlined => goInlined(tree, info.nx.nxTransInlined(cur))
case tree: TypeTree => goTypeTree(tree, info.nx.nxTransTypeTree(cur))
case tree: Alternative => goAlternative(tree, info.nx.nxTransAlternative(cur))
case tree: UnApply => goUnApply(tree, info.nx.nxTransUnApply(cur))
@@ -1090,6 +1112,14 @@ object TreeTransforms {
val elemtpt = transform(tree.elemtpt, mutatedInfo, cur)
goSeqLiteral(cpy.SeqLiteral(tree)(elems, elemtpt), mutatedInfo.nx.nxTransSeqLiteral(cur))
}
+ case tree: Inlined =>
+ implicit val mutatedInfo: TransformerInfo = mutateTransformers(info, prepForInlined, info.nx.nxPrepInlined, tree, cur)
+ if (mutatedInfo eq null) tree
+ else {
+ val bindings = transformSubTrees(tree.bindings, mutatedInfo, cur)
+ val expansion = transform(tree.expansion, mutatedInfo, cur)(Inliner.inlineContext(tree))
+ goInlined(cpy.Inlined(tree)(tree.call, bindings, expansion), mutatedInfo.nx.nxTransInlined(cur))
+ }
case tree: TypeTree =>
implicit val mutatedInfo: TransformerInfo = mutateTransformers(info, prepForTypeTree, info.nx.nxPrepTypeTree, tree, cur)
if (mutatedInfo eq null) tree