Commit 253b53eb authored by Eva Darulova's avatar Eva Darulova

fixing style of top-level functions

parent 351084a1
......@@ -11,6 +11,7 @@
<parameters>
<parameter name="tabSize">2</parameter>
<parameter name="methodParamIndentSize">2</parameter>
<parameter name="classParamIndentSize">2</parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.file.WhitespaceEndOfLineChecker" enabled="true"></check>
......@@ -29,6 +30,17 @@
<parameter name="regex"><![CDATA[^[a-z][A-Za-z]*$]]></parameter>
</parameters>
</check>
<check enabled="true" class="org.scalastyle.scalariform.FieldNamesChecker" level="warning">
<parameters>
<parameter name="regex">^[a-z_][A-Za-z0-9]*$</parameter>
<parameter name="objectFieldRegex">^[A-Za-z][A-Za-z0-9]*$</parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.MethodNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[a-z][A-Za-z0-9]*$]]></parameter>
</parameters>
</check>
<check enabled="true" class="org.scalastyle.scalariform.ClassTypeParameterChecker" level="warning">
<parameters>
<parameter name="regex">^[A-Z_]$</parameter>
......@@ -54,16 +66,6 @@
<parameter name="tokens">LPAREN</parameter>
</parameters>
</check>
<check enabled="true" class="org.scalastyle.scalariform.FieldNamesChecker" level="warning">
<parameters>
<parameter name="regex">^[a-z][A-Za-z0-9]*$</parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.MethodNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[a-z][A-Za-z0-9]*$]]></parameter>
</parameters>
</check>
<check enabled="false" class="org.scalastyle.scalariform.ForBraceChecker" level="warning"/>
<check level="warning" class="org.scalastyle.scalariform.IfBraceChecker" enabled="true">
<parameters>
......
......@@ -11,14 +11,14 @@ import lang.Trees.Program
/**
A common trait for everything that processes command line options.
*/
*/
trait Component {
val name : String
val description : String
val name: String
val description: String
val definedOptions : Set[CmdLineOptionDef[Any]] = Set()
val definedOptions: Set[CmdLineOptionDef[Any]] = Set()
def functionsToConsider(ctx:Context, prg: Program): Seq[String] = {
def functionsToConsider(ctx: Context, prg: Program): Seq[String] = {
ctx.findOption(Main.optionFunctions) match {
case Some(fncs) => fncs
case None => prg.defs.map(_.id.toString)
......
......@@ -12,5 +12,5 @@ package daisy
case class DaisyFatalError(msg: Option[String]) extends Exception(msg.getOrElse(""))
object DaisyFatalError {
def apply(msg: String) = new DaisyFatalError(Some(msg))
def apply(msg: String): DaisyFatalError = new DaisyFatalError(Some(msg))
}
......@@ -14,6 +14,4 @@ import lang.Trees.Program
/** One logical analysis/synthesis step, e.g. computing ranges, replacing trig functions.
* This should be as immutable as possible so that we can (possibly) run it in parallel.
*/
trait DaisyPhase extends Pipeline[Program, Program] with Component {
}
trait DaisyPhase extends Pipeline[Program, Program] with Component
\ No newline at end of file
......@@ -24,17 +24,17 @@ object InfoPhase extends DaisyPhase {
override val name = "info phase"
override val description = "prints interesting information"
override val definedOptions: Set[CmdLineOptionDef[Any]] = Set(
ParamOptionDef("info-log", "which file to write analysis results to, "+
ParamOptionDef("info-log", "which file to write analysis results to, " +
"default prints nothing, output file is created in rawdata/", "")
)
//implicit val debugSection = ???
// implicit val debugSection = ???
var reporter: Reporter = null
override def run(ctx: Context, prg: Program): (Context, Program) = {
reporter = ctx.reporter
reporter.info(s"\nStarting $name")
reporter.info(s"----- Results: -----")
val timer = ctx.timers.info.start
var out: BufferedWriter = null
......@@ -53,10 +53,10 @@ object InfoPhase extends DaisyPhase {
val absError = ctx.resultAbsoluteErrors(fnc.id)
val range = ctx.resultRealRanges(fnc.id)
val relError: Double = if (range.xlo <= zero && zero <= range.xhi) {
Double.NaN
} else {
max(abs(absError / range.xlo), abs(absError / range.xhi)).toDouble
}
Double.NaN
} else {
max(abs(absError / range.xlo), abs(absError / range.xhi)).toDouble
}
val infoString: String =
s"abs-error: ${absError}, real range: ${range},\nrel-error: ${relError}"
......@@ -74,7 +74,7 @@ object InfoPhase extends DaisyPhase {
if (out != null){ out.close }
timer.stop
ctx.reporter.info(s"Finished $name")
ctx.reporter.info(s"--------------------")
(ctx, prg)
}
......
......@@ -14,7 +14,7 @@ import lang.Trees.Program
object Main {
val optionFunctions = ListOptionDef("functions", "Which functions to consider (currently only for error analysis).",
List("f1", "f2"))
List("f1", "f2"))
val optionPrintToughSMTCalls = FlagOptionDef("print-tough-smt-calls",
"If enabled, will print those SMT queries to file which take longer.")
......@@ -22,7 +22,7 @@ object Main {
val globalOptions: Set[CmdLineOptionDef[Any]] = Set(
FlagOptionDef("help", "Show this message."),
FlagOptionDef("dynamic", "Run dynamic analysis."),
//ParamOptionDef("timeout", "Timeout in ms.", "1000"),
// ParamOptionDef("timeout", "Timeout in ms.", "1000"),
ListOptionDef("debug", "For which sections to print debug info.",
List("analysis","solver")),
FlagOptionDef("codegen", "Generate code (as opposed to just doing analysis)."),
......@@ -34,7 +34,7 @@ object Main {
For now these are phases, but it should be anything that
needs command-line options.
*/
lazy val allComponents : Set[DaisyPhase] = Set(
lazy val allComponents: Set[DaisyPhase] = Set(
analysis.SpecsProcessingPhase,
analysis.RangeErrorPhase,
backend.CodeGenerationPhase,
......@@ -42,7 +42,7 @@ object Main {
analysis.DynamicPhase,
InfoPhase)
def main(args: Array[String]) {
def main(args: Array[String]): Unit = {
val ctx = processOptions(args.toList)
......@@ -52,7 +52,7 @@ object Main {
val timerTotal = ctx.timers.total.start
// this is the old frontend going through Leon
//val inputPrg = frontend.ScalaExtraction.run(ctx)
// val inputPrg = frontend.ScalaExtraction.run(ctx)
// new frontend going directly through Scala compiler
val inputPrg = frontend.ExtractionPhase(ctx)
......@@ -90,7 +90,7 @@ object Main {
opt.drop(2).split("=", 2).toList match {
case List(name, value) =>
allOptions.get(name) match {
case Some(ints: ParamOptionDef) => //if (value.forall(_.isDigit))
case Some(ints: ParamOptionDef) =>
validOptions +:= ParamOption(name, value)
case Some(lists: ListOptionDef) =>
......@@ -127,7 +127,8 @@ object Main {
case Some(rs) =>
debugSections += rs
case None =>
initReporter.error("Section "+ x +" not found, available: "+DebugSections.all.map(_.name).mkString(", "))
initReporter.error("Section " + x + " not found, available: " +
DebugSections.all.map(_.name).mkString(", "))
}
}}
......@@ -143,7 +144,7 @@ object Main {
)
}
private def showHelp(reporter: Reporter) {
private def showHelp(reporter: Reporter): Unit = {
reporter.info("usage: [--help] [--debug=<N>] [..] <files>")
reporter.info("")
for (opt <- globalOptions.toSeq.sortBy(_.name)) {
......
......@@ -13,7 +13,7 @@ abstract class Pipeline[-F, +T] {
def andThen[G](thenn: Pipeline[T, G]): Pipeline[F, G] = new Pipeline[F,G] {
def run(ctx: Context, v: F): (Context, G) = {
val (ctx2, s) = self.run(ctx, v)
//if(ctx.findOptionOrDefault(SharedOptions.optStrictPhases)) ctx.reporter.terminateIfError()
// if(ctx.findOptionOrDefault(SharedOptions.optStrictPhases)) ctx.reporter.terminateIfError()
thenn.run(ctx2, s)
}
}
......
......@@ -22,11 +22,11 @@ abstract class Reporter(val debugSections: Set[DebugSection]) {
case class Message(severity: Severity, position: Position, msg: Any)
private var _errorCount : Int = 0
private var _warningCount : Int = 0
private var _errorCount: Int = 0
private var _warningCount: Int = 0
final def errorCount : Int = _errorCount
final def warningCount : Int = _warningCount
final def errorCount: Int = _errorCount
final def warningCount: Int = _warningCount
def account(msg: Message): Message = {
msg.severity match {
......@@ -44,28 +44,29 @@ abstract class Reporter(val debugSections: Set[DebugSection]) {
throw DaisyFatalError(None)
}
def onCompilerProgress(current: Int, total: Int) = {}
def onCompilerProgress(current: Int, total: Int): Unit = {}
final def info(pos: Position, msg: Any): Unit = emit(account(Message(INFO, pos, msg)))
final def warning(pos: Position, msg: Any): Unit = emit(account(Message(WARNING, pos, msg)))
final def error(pos: Position, msg: Any): Unit = emit(account(Message(ERROR, pos, msg)))
final def title(pos: Position, msg: Any): Unit = emit(account(Message(INFO, pos, Console.BOLD + msg + Console.RESET)))
final def title(pos: Position, msg: Any): Unit = emit(account(Message(INFO, pos,
Console.BOLD + msg + Console.RESET)))
final def fatalError(pos: Position, msg: Any): Nothing = {
emit(account(Message(FATAL, pos, msg)))
onFatal()
}
final def internalError(pos: Position, msg : Any) : Nothing = {
final def internalError(pos: Position, msg: Any): Nothing = {
emit(account(Message(INTERNAL, pos, msg.toString +
"\nPlease inform the authors of Daisy about this message"
)))
onFatal()
}
final def internalAssertion(cond : Boolean, pos: Position, msg : Any) : Unit = {
final def internalAssertion(cond: Boolean, pos: Position, msg: Any): Unit = {
if (!cond) internalError(pos,msg)
}
def terminateIfError() = {
def terminateIfError(): Unit = {
if (errorCount > 0) {
_errorCount = 0
_warningCount = 0
......@@ -80,15 +81,15 @@ abstract class Reporter(val debugSections: Set[DebugSection]) {
(debugMask & section.mask) == section.mask
}
def ifDebug(pos: Position, body: (Any => Unit) => Any)(implicit section: DebugSection) = {
def ifDebug(pos: Position, body: (Any => Unit) => Any)(implicit section: DebugSection): Unit = {
if (isDebugEnabled) {
body( { (msg: Any) => emit(account(Message(DEBUG(section), pos, msg))) } )
body({ (msg: Any) => emit(account(Message(DEBUG(section), pos, msg))) })
}
}
def whenDebug(pos: Position, section: DebugSection)(body: (Any => Unit) => Any) {
def whenDebug(pos: Position, section: DebugSection)(body: (Any => Unit) => Any): Unit = {
if (isDebugEnabled(section)) {
body( { (msg: Any) => emit(account(Message(DEBUG(section), pos, msg))) } )
body({ (msg: Any) => emit(account(Message(DEBUG(section), pos, msg))) })
}
}
......@@ -106,8 +107,8 @@ abstract class Reporter(val debugSections: Set[DebugSection]) {
final def error(msg: Any): Unit = error(NoPosition, msg)
final def title(msg: Any): Unit = title(NoPosition, msg)
final def fatalError(msg: Any): Nothing = fatalError(NoPosition, msg)
final def internalError(msg: Any) : Nothing = internalError(NoPosition, msg)
final def internalAssertion(cond : Boolean, msg: Any) : Unit = internalAssertion(cond,NoPosition, msg)
final def internalError(msg: Any): Nothing = internalError(NoPosition, msg)
final def internalAssertion(cond: Boolean, msg: Any): Unit = internalAssertion(cond,NoPosition, msg)
final def debug(msg: => Any)(implicit section: DebugSection): Unit = debug(NoPosition, msg)
final def ifDebug(body: (Any => Unit) => Any)(implicit section: DebugSection): Unit =
ifDebug(NoPosition, body)
......@@ -117,12 +118,12 @@ abstract class Reporter(val debugSections: Set[DebugSection]) {
class DefaultReporter(debugSections: Set[DebugSection]) extends Reporter(debugSections) {
protected def severityToPrefix(sev: Severity): String = sev match {
case ERROR => "["+Console.RED +" Error "+Console.RESET+"]"
case WARNING => "["+Console.YELLOW +"Warning "+Console.RESET+"]"
case INFO => "["+Console.BLUE +" Info "+Console.RESET+"]"
case FATAL => "["+Console.RED+Console.BOLD +" Fatal "+Console.RESET+"]"
case INTERNAL => "["+ Console.BOLD +"Internal"+Console.RESET+"]"
case DEBUG(_) => "["+Console.MAGENTA +" Debug "+Console.RESET+"]"
case ERROR => "[" + Console.RED + " Error " + Console.RESET + "]"
case WARNING => "[" + Console.YELLOW + "Warning " + Console.RESET + "]"
case INFO => "[" + Console.BLUE + " Info " + Console.RESET + "]"
case FATAL => "[" + Console.RED + Console.BOLD + " Fatal " + Console.RESET + "]"
case INTERNAL => "[" + Console.BOLD + "Internal" + Console.RESET + "]"
case DEBUG(_) => "[" + Console.MAGENTA + " Debug " + Console.RESET + "]"
}
def smartPos(p: Position): String = {
......@@ -133,13 +134,13 @@ class DefaultReporter(debugSections: Set[DebugSection]) extends Reporter(debugSe
val here = new java.io.File(".").getAbsolutePath().stripSuffix(".")
val diff = target.stripPrefix(here)
val filePos = diff+":"
val filePos = diff + ":"
filePos + p + ": "
}
}
def emit(msg: Message) = {
def emit(msg: Message): Unit = {
println(reline(severityToPrefix(msg.severity), smartPos(msg.position) + msg.msg.toString))
printLineContent(msg.position)
}
......@@ -175,7 +176,7 @@ class DefaultReporter(debugSections: Set[DebugSection]) extends Reporter(debugSe
def printLineContent(pos: Position): Unit = {
getLine(pos) match {
case Some(line) =>
println(blankPrefix+line)
println(blankPrefix + line)
pos match {
case rp: RangePosition =>
val bp = rp.focusBegin
......@@ -185,21 +186,21 @@ class DefaultReporter(debugSections: Set[DebugSection]) extends Reporter(debugSe
val width = Math.max(ep.col - bp.col, 1)
"^" * width
} else {
val width = Math.max(line.length+1-bp.col, 1)
("^" * width)+"..."
val width = Math.max(line.length + 1 - bp.col, 1)
("^" * width) + "..."
}
println(blankPrefix+(" " * (bp.col - 1) + Console.RED+carret+Console.RESET))
println(blankPrefix + (" " * (bp.col - 1) + Console.RED + carret + Console.RESET))
case op: OffsetPosition =>
println(blankPrefix+(" " * (op.col - 1) + Console.RED+"^"+Console.RESET))
println(blankPrefix + (" " * (op.col - 1) + Console.RED + "^" + Console.RESET))
}
case None =>
}
}
protected def reline(pfx: String, msg: String) : String = {
pfx+" "+msg.replaceAll("\n", s"\n$pfx ")
protected def reline(pfx: String, msg: String): String = {
pfx + " " + msg.replaceAll("\n", s"\n$pfx ")
}
}
......
......@@ -21,11 +21,11 @@ class Timer {
this
}
def stop = {
def stop: Unit = {
end = System.currentTimeMillis
}
override def toString = {
override def toString: String = {
"%6d ms".format((end - beginning))
}
......
......@@ -157,7 +157,7 @@ object RangeErrorPhase extends DaisyPhase with RoundoffEvaluators with IntervalS
}).toMap
timer.stop
ctx.reporter.info(s"Finished $name")
//ctx.reporter.info(s"Finished $name")
(ctx.copy(resultAbsoluteErrors = res.map(x => (x._1 -> x._2._1)),
resultRealRanges = res.map(x => (x._1 -> x._2._2))), prg)
}
......
......@@ -39,7 +39,7 @@ object SpecsProcessingPhase extends DaisyPhase {
def run(ctx:Context, prg: Program): (Context, Program) = {
reporter = ctx.reporter
reporter.info("\nStarting specs preprocessing phase")
//reporter.info("\nStarting specs preprocessing phase")
val timer = ctx.timers.preprocess.start
var allRanges: Map[Identifier, Map[Identifier, Interval]] = Map()
......@@ -115,7 +115,7 @@ object SpecsProcessingPhase extends DaisyPhase {
}
timer.stop
reporter.info("Finished specs preprocessing phase\n")
//reporter.info("Finished specs preprocessing phase\n")
reporter.debug(lang.RangePrinter(prg))
reporter.debug("range bounds: " + resRanges.mkString("\n"))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment