aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/typer/FrontEnd.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-11-02 11:08:28 +0100
committerGuillaume Martres <smarter@ubuntu.com>2016-11-22 01:35:07 +0100
commit8a61ff432543a29234193cd1f7c14abd3f3d31a0 (patch)
treea8147561d307af862c295cfc8100d271063bb0dd /compiler/src/dotty/tools/dotc/typer/FrontEnd.scala
parent6a455fe6da5ff9c741d91279a2dc6fe2fb1b472f (diff)
downloaddotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.tar.gz
dotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.tar.bz2
dotty-8a61ff432543a29234193cd1f7c14abd3f3d31a0.zip
Move compiler and compiler tests to compiler dir
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer/FrontEnd.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/typer/FrontEnd.scala83
1 files changed, 83 insertions, 0 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/FrontEnd.scala b/compiler/src/dotty/tools/dotc/typer/FrontEnd.scala
new file mode 100644
index 000000000..c444631ae
--- /dev/null
+++ b/compiler/src/dotty/tools/dotc/typer/FrontEnd.scala
@@ -0,0 +1,83 @@
+package dotty.tools.dotc
+package typer
+
+import core._
+import Phases._
+import Contexts._
+import Symbols._
+import dotty.tools.dotc.parsing.JavaParsers.JavaParser
+import parsing.Parsers.Parser
+import config.Config
+import config.Printers.{typr, default}
+import util.Stats._
+import scala.util.control.NonFatal
+import ast.Trees._
+
+class FrontEnd extends Phase {
+
+ override def phaseName = "frontend"
+ override def isTyper = true
+ import ast.tpd
+
+ def monitor(doing: String)(body: => Unit)(implicit ctx: Context) =
+ try body
+ catch {
+ case NonFatal(ex) =>
+ ctx.echo(s"exception occurred while $doing ${ctx.compilationUnit}")
+ throw ex
+ }
+
+ def parse(implicit ctx: Context) = monitor("parsing") {
+ val unit = ctx.compilationUnit
+ unit.untpdTree =
+ if (unit.isJava) new JavaParser(unit.source).parse()
+ else new Parser(unit.source).parse()
+ val printer = if (ctx.settings.Xprint.value.contains("parser")) default else typr
+ printer.println("parsed:\n" + unit.untpdTree.show)
+ if (Config.checkPositions)
+ unit.untpdTree.checkPos(nonOverlapping = !unit.isJava && !ctx.reporter.hasErrors)
+ }
+
+ def enterSyms(implicit ctx: Context) = monitor("indexing") {
+ val unit = ctx.compilationUnit
+ ctx.typer.index(unit.untpdTree)
+ typr.println("entered: " + unit.source)
+ }
+
+ def typeCheck(implicit ctx: Context) = monitor("typechecking") {
+ val unit = ctx.compilationUnit
+ unit.tpdTree = ctx.typer.typedExpr(unit.untpdTree)
+ typr.println("typed: " + unit.source)
+ record("retained untyped trees", unit.untpdTree.treeSize)
+ record("retained typed trees after typer", unit.tpdTree.treeSize)
+ }
+
+ private def firstTopLevelDef(trees: List[tpd.Tree])(implicit ctx: Context): Symbol = trees match {
+ case PackageDef(_, defs) :: _ => firstTopLevelDef(defs)
+ case Import(_, _) :: defs => firstTopLevelDef(defs)
+ case (tree @ TypeDef(_, _)) :: _ => tree.symbol
+ case _ => NoSymbol
+ }
+
+ protected def discardAfterTyper(unit: CompilationUnit)(implicit ctx: Context) =
+ unit.isJava || firstTopLevelDef(unit.tpdTree :: Nil).isPrimitiveValueClass
+
+ override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
+ val unitContexts = for (unit <- units) yield {
+ ctx.inform(s"compiling ${unit.source}")
+ ctx.fresh.setCompilationUnit(unit)
+ }
+ unitContexts foreach (parse(_))
+ record("parsedTrees", ast.Trees.ntrees)
+ unitContexts foreach (enterSyms(_))
+ unitContexts foreach (typeCheck(_))
+ record("total trees after typer", ast.Trees.ntrees)
+ unitContexts.map(_.compilationUnit).filterNot(discardAfterTyper)
+ }
+
+ override def run(implicit ctx: Context): Unit = {
+ parse
+ enterSyms
+ typeCheck
+ }
+}