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

moved list of extensions to, well, Extensions

parent 287dc3d4
Branches
Tags
No related merge requests found
...@@ -10,30 +10,11 @@ class Analysis(val program: Program) { ...@@ -10,30 +10,11 @@ class Analysis(val program: Program) {
// we always use the global reporter for this class // we always use the global reporter for this class
val reporter = Settings.reporter val reporter = Settings.reporter
// ...but not always for the extensions // ...but not always for the extensions
val extensionsReporter =
if(Settings.quietExtensions) {
Settings.quietReporter
} else {
Settings.reporter
}
// these extensions are always loaded, unless specified otherwise Extensions.loadAll
val defaultExtensions: Seq[Extension] =
if(Settings.runDefaultExtensions) {
(new Z3Solver(extensionsReporter)) :: Nil
} else {
Nil
}
// we load additional extensions val analysisExtensions: Seq[Analyser] = loadedAnalysisExtensions
val moreExtensions: Seq[Extension] = loadAll(extensionsReporter) val solverExtensions: Seq[Solver] = loadedSolverExtensions
if(!moreExtensions.isEmpty) {
reporter.info("The following extensions are loaded:\n" + moreExtensions.toList.map(_.description).mkString(" ", "\n ", ""))
}
// ...and split the final list between solvers and analysers
val extensions: Seq[Extension] = defaultExtensions ++ moreExtensions
val analysisExtensions: Seq[Analyser] = extensions.filter(_.isInstanceOf[Analyser]).map(_.asInstanceOf[Analyser])
val solverExtensions: Seq[Solver] = extensions.filter(_.isInstanceOf[Solver]).map(_.asInstanceOf[Solver])
// Calling this method will run all analyses on the program passed at // Calling this method will run all analyses on the program passed at
// construction time. If at least one solver is loaded, verification // construction time. If at least one solver is loaded, verification
......
...@@ -18,6 +18,8 @@ object Extensions { ...@@ -18,6 +18,8 @@ object Extensions {
// Returns Some(true) if valid, Some(false) if invalid, // Returns Some(true) if valid, Some(false) if invalid,
// None if unknown. // None if unknown.
def solve(expression: Expr) : Option[Boolean] def solve(expression: Expr) : Option[Boolean]
def isSat(expression: Expr) : Option[Boolean] = solve(expression).map(!_)
} }
abstract class Analyser(reporter: Reporter) extends Extension(reporter) { abstract class Analyser(reporter: Reporter) extends Extension(reporter) {
...@@ -28,9 +30,20 @@ object Extensions { ...@@ -28,9 +30,20 @@ object Extensions {
// The rest of the code is for dynamically loading extensions // The rest of the code is for dynamically loading extensions
def loadAll(reporter: Reporter) : Seq[Extension] = { private var allLoaded : Seq[Extension] = Nil
private var analysisExtensions : Seq[Analyser] = Nil
private var solverExtensions : Seq[Solver] = Nil
// Returns the list of the newly loaded.
def loadAll : Seq[Extension] = {
val extensionsReporter =
if(Settings.quietExtensions) {
Settings.quietReporter
} else {
Settings.reporter
}
val allNames: Seq[String] = Settings.extensionNames val allNames: Seq[String] = Settings.extensionNames
if(!allNames.isEmpty) { val loaded = (if(!allNames.isEmpty) {
val classLoader = Extensions.getClass.getClassLoader val classLoader = Extensions.getClass.getClassLoader
val classes: Seq[Class[_]] = (for(name <- allNames) yield { val classes: Seq[Class[_]] = (for(name <- allNames) yield {
...@@ -47,7 +60,7 @@ object Extensions { ...@@ -47,7 +60,7 @@ object Extensions {
classes.map(cl => { classes.map(cl => {
try { try {
val cons = cl.getConstructor(classOf[Reporter]) val cons = cl.getConstructor(classOf[Reporter])
cons.newInstance(reporter).asInstanceOf[Extension] cons.newInstance(extensionsReporter).asInstanceOf[Extension]
} catch { } catch {
case _ => { case _ => {
Settings.reporter.error("Extension class " + cl.getName + " does not seem to be of a proper type.") Settings.reporter.error("Extension class " + cl.getName + " does not seem to be of a proper type.")
...@@ -57,6 +70,23 @@ object Extensions { ...@@ -57,6 +70,23 @@ object Extensions {
}).filter(_ != null) }).filter(_ != null)
} else { } else {
Nil Nil
})
if(!loaded.isEmpty) {
Settings.reporter.info("The following extensions are loaded:\n" + loaded.toList.map(_.description).mkString(" ", "\n ", ""))
}
// these extensions are always loaded, unless specified otherwise
val defaultExtensions: Seq[Extension] = if(Settings.runDefaultExtensions) {
(new Z3Solver(extensionsReporter)) :: Nil
} else {
Nil
} }
allLoaded = defaultExtensions ++ loaded
analysisExtensions = allLoaded.filter(_.isInstanceOf[Analyser]).map(_.asInstanceOf[Analyser])
solverExtensions = allLoaded.filter(_.isInstanceOf[Solver]).map(_.asInstanceOf[Solver])
loaded
} }
def loadedExtensions : Seq[Extension] = allLoaded
def loadedAnalysisExtensions : Seq[Analyser] = analysisExtensions
def loadedSolverExtensions : Seq[Solver] = solverExtensions
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment