aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2014-10-14 14:50:18 +0200
committerGuillaume Martres <smarter@ubuntu.com>2015-02-17 14:01:54 +0100
commit63fa5ad4971e3fd93febe5002c4a8eb32965bef5 (patch)
tree2895af253d000d8136aac9d2dbe54fcc1ae44f50 /test
parent778072d5bd7763d7c5181e405db84e341be27ca3 (diff)
downloaddotty-63fa5ad4971e3fd93febe5002c4a8eb32965bef5.tar.gz
dotty-63fa5ad4971e3fd93febe5002c4a8eb32965bef5.tar.bz2
dotty-63fa5ad4971e3fd93febe5002c4a8eb32965bef5.zip
Type stealer that allows to steal types after typer
Proposed to be used from repl: it gives you internal representation of types after frontend and a context to play with them
Diffstat (limited to 'test')
-rw-r--r--test/test/DottyTypeStealer.scala32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/test/DottyTypeStealer.scala b/test/test/DottyTypeStealer.scala
new file mode 100644
index 000000000..3b7137dcc
--- /dev/null
+++ b/test/test/DottyTypeStealer.scala
@@ -0,0 +1,32 @@
+package test
+
+import dotty.tools.dotc.ast.tpd
+import dotty.tools.dotc.core.Names._
+import dotty.tools.dotc.ast.tpd._
+import dotty.tools.dotc.core.Contexts.Context
+import dotty.tools.dotc.core.Decorators._
+import dotty.tools.dotc.core.Types.Type
+
+object DottyTypeStealer {
+ 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
+ new DottyTest().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)
+ scontext = context
+ }
+ (scontext, tp)
+ }
+}