Skip to content
Snippets Groups Projects
Commit b1416b57 authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Adding type annotations considered harmful

parent d83ff17e
Branches
Tags
No related merge requests found
/* Copyright 2009-2015 EPFL, Lausanne */
package leon
package frontends.scalac
import scala.tools.nsc._
trait AddTypeAnnotations extends SubComponent with ASTExtractors {
import global._
import ExtractorHelpers._
val phaseName = "addtypeannotations"
val ctx: LeonContext
var imports : Map[RefTree,List[Import]] = Map()
def newPhase(prev: scala.tools.nsc.Phase): StdPhase = new Phase(prev)
class Phase(prev: scala.tools.nsc.Phase) extends StdPhase(prev) {
def apply(unit: CompilationUnit): Unit = {
val transformer = new Transformer {
override def transform(tree : Tree) : Tree = tree match {
case d@DefDef(_,_,_,_,tpt,
a@Apply(
s@Select(
bd,
nameEns@ExNamed("ensuring")
),
f
)
) => (bd,tpt.symbol) match {
case (Typed(_,_), _) | (_, null) => d
case _ => d.copy(rhs =
Apply(
Select(
Typed(bd,tpt.duplicate.setPos(bd.pos.focus)).setPos(bd.pos),
nameEns
).setPos(s.pos),
f
).setPos(a.pos)
).setPos(d.pos)
}
case other => super.transform(other)
}
}
unit.body = transformer.transform(unit.body)
}
}
}
......@@ -22,17 +22,9 @@ class ScalaCompiler(settings : NSCSettings, ctx: LeonContext) extends Global(set
val ctx = ScalaCompiler.this.ctx
} with SaveImports
object addTypeAnnotations extends {
val global: ScalaCompiler.this.type = ScalaCompiler.this
val runsAfter = List[String]()
val runsRightAfter = Some("parser")
val ctx = ScalaCompiler.this.ctx
} with AddTypeAnnotations
override protected def computeInternalPhases() : Unit = {
val phs = List(
syntaxAnalyzer -> "parse source into ASTs, perform simple desugaring",
addTypeAnnotations -> "add type annotations useful for Leon",
analyzer.namerFactory -> "resolve names, attach symbols to named trees",
analyzer.packageObjects -> "load package objects",
analyzer.typerFactory -> "the meat and potatoes: type the trees",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment