blob: ff6e67e4161496ba09a7842e1a089c448f20fb7d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package dotty.tools
import dotc.ast.tpd
import dotc.core.Names._
import dotc.ast.tpd._
import dotc.core.Contexts.Context
import dotc.core.Decorators._
import dotc.core.Types.Type
object DottyTypeStealer extends DottyTest {
def stealType(source: String, typeStrings: String*): (Context, List[Type]) = {
val dummyName = "x_x_x"
val vals = typeStrings.zipWithIndex.map{case (s, x)=> s"val ${dummyName}$x: $s = ???"}.mkString("\n")
val gatheredSource = s" ${source}\n object A$dummyName {$vals}"
var scontext : Context = null
var tp: List[Type] = null
checkCompile("frontend",gatheredSource) {
(tree, context) =>
implicit val ctx = context
val findValDef: (List[ValDef], tpd.Tree) => List[ValDef] =
(acc , tree) => { tree match {
case t: ValDef if t.name.startsWith(dummyName.toTermName) => t :: acc
case _ => acc
}
}
val d = new DeepFolder[List[ValDef]](findValDef).foldOver(Nil, tree)
tp = d.map(_.tpe.widen).reverse
scontext = context
}
(scontext, tp)
}
}
|