diff options
author | Martin Odersky <odersky@gmail.com> | 2016-09-01 17:44:27 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-10-02 16:11:21 +0200 |
commit | faba2b7999bf73bf10116b391efbdd751054ead0 (patch) | |
tree | 220e1956858d92066949faf63aeb623e6d6fa63a /src | |
parent | 8a3762a62d12b7f57de27c840425184df56b2689 (diff) | |
download | dotty-faba2b7999bf73bf10116b391efbdd751054ead0.tar.gz dotty-faba2b7999bf73bf10116b391efbdd751054ead0.tar.bz2 dotty-faba2b7999bf73bf10116b391efbdd751054ead0.zip |
Track Inlined nodes in ctx.source
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/Contexts.scala | 10 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/DropInlined.scala | 15 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Inliner.scala | 9 |
3 files changed, 30 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index 6f9d19c40..ea0ab95e6 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -18,7 +18,7 @@ import util.Positions._ import ast.Trees._ import ast.untpd import util.{FreshNameCreator, SimpleMap, SourceFile, NoSource} -import typer.{Implicits, ImplicitRunInfo, ImportInfo, NamerContextOps, SearchHistory, TypeAssigner, Typer} +import typer.{Implicits, ImplicitRunInfo, ImportInfo, Inliner, NamerContextOps, SearchHistory, TypeAssigner, Typer} import Implicits.ContextualImplicits import config.Settings._ import config.Config @@ -370,8 +370,12 @@ object Contexts { /** The current source file; will be derived from current * compilation unit. */ - def source: SourceFile = - if (compilationUnit == null) NoSource else compilationUnit.source + def source: SourceFile = { + val file = Inliner.inlinedSource + if (file.exists) file + else if (compilationUnit == null) NoSource + else compilationUnit.source + } /** Does current phase use an erased types interpretation? */ def erasedTypes: Boolean = phase.erasedTypes diff --git a/src/dotty/tools/dotc/transform/DropInlined.scala b/src/dotty/tools/dotc/transform/DropInlined.scala new file mode 100644 index 000000000..775663b5c --- /dev/null +++ b/src/dotty/tools/dotc/transform/DropInlined.scala @@ -0,0 +1,15 @@ +package dotty.tools.dotc +package transform + +import typer.Inliner +import core.Contexts.Context +import TreeTransforms.{MiniPhaseTransform, TransformerInfo} + +/** Drop Inlined nodes */ +class DropInlined extends MiniPhaseTransform { + import ast.tpd._ + override def phaseName = "dropInlined" + + override def transformInlined(tree: Inlined)(implicit ctx: Context, info: TransformerInfo): Tree = + Inliner.dropInlined(tree) +} diff --git a/src/dotty/tools/dotc/typer/Inliner.scala b/src/dotty/tools/dotc/typer/Inliner.scala index 51efca3f4..28c725b33 100644 --- a/src/dotty/tools/dotc/typer/Inliner.scala +++ b/src/dotty/tools/dotc/typer/Inliner.scala @@ -18,7 +18,7 @@ import Annotations.Annotation import transform.ExplicitOuter import config.Printers.inlining import ErrorReporting.errorTree -import util.Property +import util.{Property, SourceFile, NoSource} import collection.mutable object Inliner { @@ -81,6 +81,13 @@ object Inliner { def inlineContext(tree: untpd.Inlined)(implicit ctx: Context): Context = ctx.fresh.setProperty(InlinedCall, tree) + + def inlinedSource(implicit ctx: Context): SourceFile = ctx.property(InlinedCall) match { + case Some(inlined) => + val file = inlined.call.symbol.sourceFile + if (file.exists) new SourceFile(file) else NoSource + case _ => NoSource + } } class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) { |