Skip to content
Snippets Groups Projects
Commit 78b370b5 authored by Philippe Suter's avatar Philippe Suter
Browse files

No commit message

No commit message
parent 5b109a79
Branches
Tags
No related merge requests found
......@@ -5,7 +5,6 @@ import scala.tools.nsc.plugins._
class AnalysisComponent(val global: Global, val pluginInstance: FunCheckPlugin) extends PluginComponent
with Extractors
// all these traits define functions applied during tree traversals
with CodeExtraction
with ForallInjection
{
......@@ -17,17 +16,23 @@ class AnalysisComponent(val global: Global, val pluginInstance: FunCheckPlugin)
val phaseName = pluginInstance.name
private def stopIfErrors: Unit = {
if(reporter.hasErrors) {
println("There were errors.")
exit(0)
}
}
def newPhase(prev: Phase) = new AnalysisPhase(prev)
class AnalysisPhase(prev: Phase) extends StdPhase(prev) {
import StructuralExtractors._
def apply(unit: CompilationUnit): Unit = {
// (new ForeachTreeTraverser(firstFilter(unit))).traverse(unit.body)
// stopIfErrors
(new ForeachTreeTraverser(firstFilter(unit))).traverse(unit.body)
stopIfErrors
// (new ForeachTreeTraverser(findContracts)).traverse(unit.body)
// stopIfErrors
(new ForeachTreeTraverser(extractCode(unit))).traverse(unit.body)
extractCode(unit)
if(pluginInstance.stopAfterAnalysis) {
println("Analysis complete. Now terminating the compiler process.")
......@@ -35,34 +40,11 @@ class AnalysisComponent(val global: Global, val pluginInstance: FunCheckPlugin)
}
}
private def stopIfErrors: Unit = {
if(reporter.hasErrors) {
println("There were errors.")
exit(0)
}
}
/** Weeds out programs containing unsupported features. */
def firstFilter(unit: CompilationUnit)(tree: Tree): Unit = {
def unsup(s: String): String = "FunCheck: Unsupported construct: " + s
tree match {
case c @ ClassDef(mods, name, tparams, impl) => {
/*
val s = c.symbol
println(s)
if(s.isTrait)
unit.error(tree.pos, unsup("trait."))
else if(s.isModule)
println("Seems like " + name + " is an object.")
else if(s.isClass && !(mods.isCase || mods.isAbstract))
unit.error(tree.pos, unsup("non-abstract, non-case class."))
*/
}
case ValDef(mods, name, tpt, rhs) if mods.isVariable =>
unit.error(tree.pos, unsup("mutable variable/field."))
case LabelDef(name, params, rhs) => unit.error(tree.pos, unsup("loop."))
......
......@@ -2,7 +2,11 @@ package funcheck
import scala.tools.nsc._
import scala.tools.nsc.plugins._
import purescala.Definitions._
import purescala.Trees._
import purescala.TypeTrees._
import purescala.Common._
trait CodeExtraction {
self: AnalysisComponent =>
......@@ -36,20 +40,23 @@ trait CodeExtraction {
case _ => ;
}
def extractCode(unit: CompilationUnit)(tree: Tree): Unit = tree match {
case d @ DefDef(mods, name, tparams, vparamss, tpt, body) if !d.symbol.isConstructor => {
println("In: " + name)
println(d.symbol)
println(d.mods)
toPureScala(unit)(body) match {
case Some(t) => println(" the body was extracted as: " + t)
case None => println(" the body could not be extracted. Is it pure Scala?")
def extractCode(unit: CompilationUnit): Unit = {
def trav(tree: Tree): Unit = tree match {
case d @ DefDef(mods, name, tparams, vparamss, tpt, body) if !d.symbol.isConstructor => {
println("In: " + name)
println(d.symbol)
println(d.mods)
toPureScala(unit)(body) match {
case Some(t) => println(" the body was extracted as: " + t)
case None => println(" the body could not be extracted. Is it pure Scala?")
}
}
case _ => ;
}
case _ => ;
(new ForeachTreeTraverser(trav)).traverse(unit.body)
}
/** An exception thrown when non-purescala compatible code is encountered. */
......
package funcheck
package funcheck.purescala
object Common {
type Identifier = String
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment