aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-03-29 15:05:07 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-03-31 14:52:08 +0200
commitfc4648d33a051ff5d220c2fea097fc99b5883ecc (patch)
tree90306579eb4bcb1862e7e642ce68ca40471b00b8
parent26b8ec48adec709cf2b07b470ada774c708e96a4 (diff)
downloaddotty-fc4648d33a051ff5d220c2fea097fc99b5883ecc.tar.gz
dotty-fc4648d33a051ff5d220c2fea097fc99b5883ecc.tar.bz2
dotty-fc4648d33a051ff5d220c2fea097fc99b5883ecc.zip
Add -Ycheck capability
Right now uses a super-rudementary tree checker: we only check that every tree has a type.
-rw-r--r--src/dotty/tools/dotc/Run.scala12
-rw-r--r--src/dotty/tools/dotc/config/ScalaSettings.scala2
-rw-r--r--src/dotty/tools/dotc/transform/TreeChecker.scala37
3 files changed, 45 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/Run.scala b/src/dotty/tools/dotc/Run.scala
index 3f15bd4c3..264373baf 100644
--- a/src/dotty/tools/dotc/Run.scala
+++ b/src/dotty/tools/dotc/Run.scala
@@ -6,6 +6,7 @@ import Contexts._, Periods._, Symbols._, Phases._, Decorators._
import io.PlainFile
import util.{SourceFile, NoSource, Stats, SimpleMap}
import reporting.Reporter
+import transform.TreeChecker
import java.io.{BufferedWriter, OutputStreamWriter}
import scala.reflect.io.VirtualFile
@@ -39,18 +40,19 @@ class Run(comp: Compiler)(implicit ctx: Context) {
for (phase <- phasesToRun) {
if (!ctx.reporter.hasErrors) {
phase.runOn(units)
- if (ctx.settings.Xprint.value.containsPhase(phase))
- for (unit <- units)
- printTree(ctx.fresh.setPhase(phase).setCompilationUnit(unit))
+ def foreachUnit(op: Context => Unit)(implicit ctx: Context): Unit =
+ for (unit <- units) op(ctx.fresh.setPhase(phase.next).setCompilationUnit(unit))
+ if (ctx.settings.Xprint.value.containsPhase(phase)) foreachUnit(printTree)
+ if (ctx.settings.Ycheck.value.containsPhase(phase)) foreachUnit(TreeChecker.check)
}
}
}
}
- private def printTree(implicit ctx: Context) = {
+ private def printTree(ctx: Context) = {
val unit = ctx.compilationUnit
println(s"result of $unit after ${ctx.phase}:")
- println(unit.tpdTree.show)
+ println(unit.tpdTree.show(ctx))
}
def compile(sourceCode: String): Unit = {
diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala
index 8ed725e36..144e146c1 100644
--- a/src/dotty/tools/dotc/config/ScalaSettings.scala
+++ b/src/dotty/tools/dotc/config/ScalaSettings.scala
@@ -97,7 +97,7 @@ class ScalaSettings extends Settings.SettingGroup {
val overrideVars = BooleanSetting("-Yoverride-vars", "Allow vars to be overridden.")
val Yhelp = BooleanSetting("-Y", "Print a synopsis of private options.")
val browse = PhasesSetting("-Ybrowse", "Browse the abstract syntax tree after")
- val check = PhasesSetting("-Ycheck", "Check the tree at the end of")
+ val Ycheck = PhasesSetting("-Ycheck", "Check the tree at the end of")
val YcheckTypedTrees = BooleanSetting("-YcheckTypedTrees", "Check all constructured typed trees for type correctness")
val Yshow = PhasesSetting("-Yshow", "(Requires -Xshow-class or -Xshow-object) Show after")
val Xcloselim = BooleanSetting("-Yclosure-elim", "Perform closure elimination.")
diff --git a/src/dotty/tools/dotc/transform/TreeChecker.scala b/src/dotty/tools/dotc/transform/TreeChecker.scala
new file mode 100644
index 000000000..ea3afc679
--- /dev/null
+++ b/src/dotty/tools/dotc/transform/TreeChecker.scala
@@ -0,0 +1,37 @@
+package dotty.tools.dotc
+package transform
+
+import TreeTransforms._
+import core.DenotTransformers._
+import core.Denotations._
+import core.SymDenotations._
+import core.Contexts._
+import core.Symbols._
+import core.Types._
+import core.Constants._
+import core.StdNames._
+import core.transform.Erasure.isUnboundedGeneric
+import typer.ErrorReporting._
+import ast.Trees._
+
+/** This transform eliminates patterns. Right now it's a dummy.
+ * Awaiting the real pattern matcher.
+ */
+class TreeChecker {
+ import ast.tpd._
+
+ def check(ctx: Context) = {
+ println(s"checking ${ctx.compilationUnit} after phase ${ctx.phase.prev}")
+ Checker.transform(ctx.compilationUnit.tpdTree)(ctx)
+ }
+
+ object Checker extends TreeMap {
+ override def transform(tree: Tree)(implicit ctx: Context) = {
+ println(i"checking $tree")
+ assert(tree.isEmpty || tree.hasType, tree.show)
+ super.transform(tree)
+ }
+ }
+}
+
+object TreeChecker extends TreeChecker \ No newline at end of file