Skip to content
Snippets Groups Projects
Commit 11a91e68 authored by Emmanouil (Manos) Koukoutos's avatar Emmanouil (Manos) Koukoutos Committed by Etienne Kneuss
Browse files

Automatically add type annotations to type ensuring

parent 23469e1e
No related branches found
No related tags found
No related merge requests found
/* Copyright 2009-2014 EPFL, Lausanne */
package leon
package frontends.scalac
import scala.tools.nsc._
import scala.tools.nsc.plugins._
trait AddTypeAnnotations extends SubComponent with ASTExtractors {
import global._
import global.definitions._
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,9 +22,17 @@ class ScalaCompiler(settings : NSCSettings, ctx: LeonContext) extends Global(set ...@@ -22,9 +22,17 @@ class ScalaCompiler(settings : NSCSettings, ctx: LeonContext) extends Global(set
val ctx = ScalaCompiler.this.ctx val ctx = ScalaCompiler.this.ctx
} with SaveImports } 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 = { override protected def computeInternalPhases() : Unit = {
val phs = List( val phs = List(
syntaxAnalyzer -> "parse source into ASTs, perform simple desugaring", 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.namerFactory -> "resolve names, attach symbols to named trees",
analyzer.packageObjects -> "load package objects", analyzer.packageObjects -> "load package objects",
analyzer.typerFactory -> "the meat and potatoes: type the trees", 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