Skip to content
Snippets Groups Projects
  • Manos Koukoutos's avatar
    59b0b60a
    Refactor how command line options are handled by Leon · 59b0b60a
    Manos Koukoutos authored
    - Command line option definitions are now represented by a type
      parametric class.
    - Components can declare legal option definitions.
    - Options are parsed according to those definitions in Main,
      and stored in LeonContext.
    - Components can then retrieve back the options from LeonContext.
      This is not perfect, as it requires some type casts.
    - leon.Settings only contained redundant information and has been
      removed.
    - Unused options from SynthesisSettings have been removed.
    59b0b60a
    History
    Refactor how command line options are handled by Leon
    Manos Koukoutos authored
    - Command line option definitions are now represented by a type
      parametric class.
    - Components can declare legal option definitions.
    - Options are parsed according to those definitions in Main,
      and stored in LeonContext.
    - Components can then retrieve back the options from LeonContext.
      This is not perfect, as it requires some type casts.
    - leon.Settings only contained redundant information and has been
      removed.
    - Unused options from SynthesisSettings have been removed.
LeonContext.scala 970 B
/* Copyright 2009-2015 EPFL, Lausanne */

package leon

import leon.utils._

import java.io.File

/** Everything that is part of a compilation unit, except the actual program tree.
 *  Contexts are immutable, and so should all there fields (with the possible
 *  exception of the reporter). */
case class LeonContext(
  reporter: Reporter,
  interruptManager: InterruptManager,
  options: Seq[LeonOption[Any]] = Seq(),
  files: Seq[File] = Seq(),
  timers: TimerStorage = new TimerStorage
) {

  // @mk: This is not typesafe, because equality for options is implemented as name equality.
  // It will fail if an LeonOptionDef is passed that has the same name
  // with one in Main,allOptions, but is different
  def findOption[A](optDef: LeonOptionDef[A]): Option[A] = options.collectFirst {
    case LeonOption(`optDef`, value) => value.asInstanceOf[A]
  }

  def findOptionOrDefault[A](optDef: LeonOptionDef[A]): A =
    findOption(optDef).getOrElse(optDef.default)
}