summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2011-12-05 00:05:57 +0100
committerEugene Burmako <xeno.by@gmail.com>2011-12-05 00:05:57 +0100
commit7193d21a9be25bf8a705492493971f3267687098 (patch)
tree0f03cd92cc5898cb7c809019e475005f3bc3603a
parent3e9e4ecf360e6eda5c26f798abfcb9bb882cf772 (diff)
downloadscala-7193d21a9be25bf8a705492493971f3267687098.tar.gz
scala-7193d21a9be25bf8a705492493971f3267687098.tar.bz2
scala-7193d21a9be25bf8a705492493971f3267687098.zip
Test pack for various flavors of reflection.
-rw-r--r--test/files/run/reify_anonymous.check1
-rw-r--r--test/files/run/reify_anonymous.scala14
-rw-r--r--test/files/run/reify_generic.check1
-rw-r--r--test/files/run/reify_generic.scala15
-rw-r--r--test/files/run/reify_inheritance.check1
-rw-r--r--test/files/run/reify_inheritance.scala23
-rw-r--r--test/files/run/reify_printf.check0
-rw-r--r--test/files/run/reify_printf.scala75
-rw-r--r--test/pending/run/reify_csv.check10
-rw-r--r--test/pending/run/reify_csv.scala42
-rw-r--r--test/pending/run/t5224.check9
-rw-r--r--test/pending/run/t5224.scala8
-rw-r--r--test/pending/run/t5225_1.check4
-rw-r--r--test/pending/run/t5225_1.scala8
-rw-r--r--test/pending/run/t5225_2.check4
-rw-r--r--test/pending/run/t5225_2.scala8
-rw-r--r--test/pending/run/t5229_1.check0
-rw-r--r--test/pending/run/t5229_1.scala14
-rw-r--r--test/pending/run/t5229_2.check2
-rw-r--r--test/pending/run/t5229_2.scala19
-rw-r--r--test/pending/run/t5266_1.check2
-rw-r--r--test/pending/run/t5266_1.scala23
-rw-r--r--test/pending/run/t5266_2.check2
-rw-r--r--test/pending/run/t5266_2.scala17
-rw-r--r--test/pending/run/t5269.check1
-rw-r--r--test/pending/run/t5269.scala22
-rw-r--r--test/pending/run/t5270.check1
-rw-r--r--test/pending/run/t5270.scala26
28 files changed, 352 insertions, 0 deletions
diff --git a/test/files/run/reify_anonymous.check b/test/files/run/reify_anonymous.check
new file mode 100644
index 0000000000..b8626c4cff
--- /dev/null
+++ b/test/files/run/reify_anonymous.check
@@ -0,0 +1 @@
+4
diff --git a/test/files/run/reify_anonymous.scala b/test/files/run/reify_anonymous.scala
new file mode 100644
index 0000000000..1e7f3fe856
--- /dev/null
+++ b/test/files/run/reify_anonymous.scala
@@ -0,0 +1,14 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ println(new {def x = 2; def y = x * x}.y)
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/files/run/reify_generic.check b/test/files/run/reify_generic.check
new file mode 100644
index 0000000000..b8626c4cff
--- /dev/null
+++ b/test/files/run/reify_generic.check
@@ -0,0 +1 @@
+4
diff --git a/test/files/run/reify_generic.scala b/test/files/run/reify_generic.scala
new file mode 100644
index 0000000000..aef038b2d8
--- /dev/null
+++ b/test/files/run/reify_generic.scala
@@ -0,0 +1,15 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ val product = List(1, 2, 3).head * List[Any](4, 2, 0).head.asInstanceOf[Int]
+ println(product)
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/files/run/reify_inheritance.check b/test/files/run/reify_inheritance.check
new file mode 100644
index 0000000000..25bf17fc5a
--- /dev/null
+++ b/test/files/run/reify_inheritance.check
@@ -0,0 +1 @@
+18 \ No newline at end of file
diff --git a/test/files/run/reify_inheritance.scala b/test/files/run/reify_inheritance.scala
new file mode 100644
index 0000000000..2a1b5f764f
--- /dev/null
+++ b/test/files/run/reify_inheritance.scala
@@ -0,0 +1,23 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ class C {
+ def x = 2
+ def y = x * x
+ }
+
+ class D extends C {
+ override def x = 3
+ }
+
+ println(new D().y * new C().x)
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/files/run/reify_printf.check b/test/files/run/reify_printf.check
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/files/run/reify_printf.check
diff --git a/test/files/run/reify_printf.scala b/test/files/run/reify_printf.scala
new file mode 100644
index 0000000000..30901b98c2
--- /dev/null
+++ b/test/files/run/reify_printf.scala
@@ -0,0 +1,75 @@
+import java.io.{ ByteArrayOutputStream, PrintStream }
+import scala.reflect.Code
+import scala.reflect.mirror._
+import scala.reflect.api._
+import scala.reflect.api.Trees
+import scala.reflect.internal.Types
+import reflect.runtime.Mirror.ToolBox
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import scala.util.matching.Regex
+
+object Test extends App {
+ val tree = tree_printf(Code.lift("hello %s").tree, Code.lift("world").tree)
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter, args mkString " ")
+ val ttree = toolbox.typeCheck(tree)
+
+ val output = new ByteArrayOutputStream()
+ Console.setOut(new PrintStream(output))
+ val evaluated = toolbox.runExpr(ttree)
+
+ assert(output.toString() == "hello world", output.toString() +" == hello world")
+
+ /*
+ macro def printf(format: String, params: Any*) : String = tree_printf(format: Tree, (params: Seq[Tree]): _*)
+ */
+
+ var i = 0
+ def gensym(name: String) = { i += 1; newTermName(name + i) }
+
+ def createTempValDef( value : Tree, tpe : Type ) : (Option[Tree],Tree) = {
+ val local = gensym("temp")
+ (
+ Some(
+ ValDef(
+ Modifiers()
+ , local
+ , TypeTree().setType(tpe)
+ , value
+ )
+ )
+ , Ident(local)
+ )
+ }
+
+ def tree_printf(format: Tree, params: Tree*) = {
+ val Literal(Constant(s_format: String)) = format
+ val paramsStack = scala.collection.mutable.Stack(params: _*)
+ val parsed = s_format.split("(?<=%[\\w%])|(?=%[\\w%])") map {
+ case "%d" => createTempValDef( paramsStack.pop, classToType(classOf[Int]) )
+ case "%s" => createTempValDef( paramsStack.pop, classToType(classOf[String]) )
+ case "%%" => {
+ (None:Option[Tree], Literal(Constant("%")))
+ }
+ case part => {
+ (None:Option[Tree], Literal(Constant(part)))
+ }
+ }
+
+ val evals = for ((Some(eval), _) <- parsed if eval != None) yield (eval: Tree)
+ val prints = for ((_, ref) <- parsed) yield
+ Apply(
+ Select(
+ Select(
+ Ident( newTermName("scala") )
+ , newTermName("Predef")
+ )
+ , newTermName("print")
+ )
+ , List(ref)
+ ): Tree
+ Block((evals ++ prints).toList, Literal(Constant(())))
+ }
+}
diff --git a/test/pending/run/reify_csv.check b/test/pending/run/reify_csv.check
new file mode 100644
index 0000000000..b56f4bb50b
--- /dev/null
+++ b/test/pending/run/reify_csv.check
@@ -0,0 +1,10 @@
+List(phase name, id, description)
+record(parser,1,parse source into ASTs, perform simple desugaring)
+record(namer,2,resolve names, attach symbols to named trees)
+record(packageobjects,3,load package objects)
+record(typer,4,the meat and potatoes: type the trees)
+record(superaccessors,5,add super accessors in traits and nested classes)
+record(pickler,6,serialize symbol tables)
+record(refchecks,7,reference/override checking, translate nested objects)
+record(selectiveanf,8,)
+record(liftcode,9,reify trees)
diff --git a/test/pending/run/reify_csv.scala b/test/pending/run/reify_csv.scala
new file mode 100644
index 0000000000..a05a3b55d4
--- /dev/null
+++ b/test/pending/run/reify_csv.scala
@@ -0,0 +1,42 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val csv = """
+ | phase name; id; description
+ | parser; 1; parse source into ASTs, perform simple desugaring
+ | namer; 2; resolve names, attach symbols to named trees
+ |packageobjects; 3; load package objects
+ | typer; 4; the meat and potatoes: type the trees
+ |superaccessors; 5; add super accessors in traits and nested classes
+ | pickler; 6; serialize symbol tables
+ | refchecks; 7; reference/override checking, translate nested objects
+ | selectiveanf; 8;
+ | liftcode; 9; reify trees""".stripMargin.split("\n").map{_.trim()}.drop(1).toList
+
+ val fields = csv.head.split(";").map{_.trim()}.toList
+ println(fields)
+
+ val code = scala.reflect.Code.lift({
+ object Csv {
+ case class record(`phase name`: String, id: String, description: String)
+
+ object record {
+ def parse(lines: List[String]) = {
+ lines drop(1) map { line => line.split(";", -1).toList match {
+ case phase$whitespace$name :: id :: description :: _ => record(phase$whitespace$name.trim(), id.trim(), description.trim())
+ case _ => throw new Exception("format error")
+ }}
+ }
+ }
+ }
+
+ Csv.record.parse(csv) foreach println
+ })
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/pending/run/t5224.check b/test/pending/run/t5224.check
new file mode 100644
index 0000000000..2b920773c0
--- /dev/null
+++ b/test/pending/run/t5224.check
@@ -0,0 +1,9 @@
+{
+ @serializable class C extends Object with ScalaObject {
+ def <init>() = {
+ super.<init>();
+ ()
+ }
+ };
+ ()
+} \ No newline at end of file
diff --git a/test/pending/run/t5224.scala b/test/pending/run/t5224.scala
new file mode 100644
index 0000000000..865ce4bfe9
--- /dev/null
+++ b/test/pending/run/t5224.scala
@@ -0,0 +1,8 @@
+import scala.reflect._
+import scala.reflect.api._
+
+object Test extends App {
+ println(scala.reflect.Code.lift{
+ @serializable class C
+ }.tree.toString)
+} \ No newline at end of file
diff --git a/test/pending/run/t5225_1.check b/test/pending/run/t5225_1.check
new file mode 100644
index 0000000000..b29cd9c365
--- /dev/null
+++ b/test/pending/run/t5225_1.check
@@ -0,0 +1,4 @@
+{
+ @transient @volatile var x: Int = 2;
+ ()
+} \ No newline at end of file
diff --git a/test/pending/run/t5225_1.scala b/test/pending/run/t5225_1.scala
new file mode 100644
index 0000000000..454502e810
--- /dev/null
+++ b/test/pending/run/t5225_1.scala
@@ -0,0 +1,8 @@
+import scala.reflect._
+import scala.reflect.api._
+
+object Test extends App {
+ println(scala.reflect.Code.lift{
+ @transient @volatile var x = 2
+ }.tree.toString)
+} \ No newline at end of file
diff --git a/test/pending/run/t5225_2.check b/test/pending/run/t5225_2.check
new file mode 100644
index 0000000000..88972fd27f
--- /dev/null
+++ b/test/pending/run/t5225_2.check
@@ -0,0 +1,4 @@
+{
+ def foo(@cloneable x: Int): String = "";
+ ()
+}
diff --git a/test/pending/run/t5225_2.scala b/test/pending/run/t5225_2.scala
new file mode 100644
index 0000000000..82bad0f353
--- /dev/null
+++ b/test/pending/run/t5225_2.scala
@@ -0,0 +1,8 @@
+import scala.reflect._
+import scala.reflect.api._
+
+object Test extends App {
+ println(scala.reflect.Code.lift{
+ def foo(@cloneable x: Int) = ""
+ }.tree.toString)
+} \ No newline at end of file
diff --git a/test/pending/run/t5229_1.check b/test/pending/run/t5229_1.check
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/pending/run/t5229_1.check
diff --git a/test/pending/run/t5229_1.scala b/test/pending/run/t5229_1.scala
new file mode 100644
index 0000000000..1d7bf0590b
--- /dev/null
+++ b/test/pending/run/t5229_1.scala
@@ -0,0 +1,14 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ object C
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/pending/run/t5229_2.check b/test/pending/run/t5229_2.check
new file mode 100644
index 0000000000..5db6ec9b38
--- /dev/null
+++ b/test/pending/run/t5229_2.check
@@ -0,0 +1,2 @@
+2
+evaluated = null
diff --git a/test/pending/run/t5229_2.scala b/test/pending/run/t5229_2.scala
new file mode 100644
index 0000000000..67be7328a6
--- /dev/null
+++ b/test/pending/run/t5229_2.scala
@@ -0,0 +1,19 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ object C {
+ val x = 2
+ }
+
+ println(C.x)
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ val evaluated = toolbox.runExpr(ttree)
+ println("evaluated = " + evaluated)
+}
diff --git a/test/pending/run/t5266_1.check b/test/pending/run/t5266_1.check
new file mode 100644
index 0000000000..3feac16a0b
--- /dev/null
+++ b/test/pending/run/t5266_1.check
@@ -0,0 +1,2 @@
+2
+evaluated = null \ No newline at end of file
diff --git a/test/pending/run/t5266_1.scala b/test/pending/run/t5266_1.scala
new file mode 100644
index 0000000000..06a81a04ea
--- /dev/null
+++ b/test/pending/run/t5266_1.scala
@@ -0,0 +1,23 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ def x = 2
+ println(x)
+ };
+
+ val settings = new Settings
+ settings.debug.value = true
+ settings.Xshowtrees.value = true
+ settings.Xprint.value = List("typer")
+ settings.printtypes.value = true
+ settings.Ytyperdebug.value = true
+
+ val reporter = new ConsoleReporter(settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ val evaluated = toolbox.runExpr(ttree)
+ println("evaluated = " + evaluated)
+} \ No newline at end of file
diff --git a/test/pending/run/t5266_2.check b/test/pending/run/t5266_2.check
new file mode 100644
index 0000000000..3feac16a0b
--- /dev/null
+++ b/test/pending/run/t5266_2.check
@@ -0,0 +1,2 @@
+2
+evaluated = null \ No newline at end of file
diff --git a/test/pending/run/t5266_2.scala b/test/pending/run/t5266_2.scala
new file mode 100644
index 0000000000..cd841da021
--- /dev/null
+++ b/test/pending/run/t5266_2.scala
@@ -0,0 +1,17 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ def x = 2
+ def y = x
+ println(y)
+ };
+
+ val reporter = new ConsoleReporter(settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ val evaluated = toolbox.runExpr(ttree)
+ println("evaluated = " + evaluated)
+}
diff --git a/test/pending/run/t5269.check b/test/pending/run/t5269.check
new file mode 100644
index 0000000000..0cfbf08886
--- /dev/null
+++ b/test/pending/run/t5269.check
@@ -0,0 +1 @@
+2
diff --git a/test/pending/run/t5269.scala b/test/pending/run/t5269.scala
new file mode 100644
index 0000000000..a30509f3fe
--- /dev/null
+++ b/test/pending/run/t5269.scala
@@ -0,0 +1,22 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ trait Z {
+ val z = 2
+ }
+
+ class X extends Z {
+ def println() = Predef.println(z)
+ }
+
+ new X().println()
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}
diff --git a/test/pending/run/t5270.check b/test/pending/run/t5270.check
new file mode 100644
index 0000000000..08839f6bb2
--- /dev/null
+++ b/test/pending/run/t5270.check
@@ -0,0 +1 @@
+200
diff --git a/test/pending/run/t5270.scala b/test/pending/run/t5270.scala
new file mode 100644
index 0000000000..10f79790b0
--- /dev/null
+++ b/test/pending/run/t5270.scala
@@ -0,0 +1,26 @@
+import scala.tools.nsc.reporters._
+import scala.tools.nsc.Settings
+import reflect.runtime.Mirror.ToolBox
+
+object Test extends App {
+ val code = scala.reflect.Code.lift{
+ class Y {
+ def y = 100
+ }
+
+ trait Z { this: Y =>
+ val z = 2 * y
+ }
+
+ class X extends Y with Z {
+ def println() = Predef.println(z)
+ }
+
+ new X().println()
+ };
+
+ val reporter = new ConsoleReporter(new Settings)
+ val toolbox = new ToolBox(reporter)
+ val ttree = toolbox.typeCheck(code.tree)
+ toolbox.runExpr(ttree)
+}