diff --git a/src/funcheck/AnalysisComponent.scala b/src/funcheck/AnalysisComponent.scala index 19acd5c7d96e7a81e922e02dec3e57a26e6a3bd8..286d6f71668bae3a5b0b07e4edd0a6aa54be0f33 100644 --- a/src/funcheck/AnalysisComponent.scala +++ b/src/funcheck/AnalysisComponent.scala @@ -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.")) diff --git a/src/funcheck/CodeExtraction.scala b/src/funcheck/CodeExtraction.scala index dbe28467e92c24f63550c8675e47848207e61ae8..d371cae6c5739b1a00bc5bcb627ce977f04d3453 100644 --- a/src/funcheck/CodeExtraction.scala +++ b/src/funcheck/CodeExtraction.scala @@ -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. */ diff --git a/src/funcheck/Common.scala b/src/funcheck/purescala/Common.scala similarity index 63% rename from src/funcheck/Common.scala rename to src/funcheck/purescala/Common.scala index 1f124e94db0dcf65842e94bdf0942c7be6211401..a4a8273e9e0772df28005c3ff38b28c2eecdd4b9 100644 --- a/src/funcheck/Common.scala +++ b/src/funcheck/purescala/Common.scala @@ -1,4 +1,4 @@ -package funcheck +package funcheck.purescala object Common { type Identifier = String