Skip to content
Snippets Groups Projects
Commit 64b75637 authored by Mikaël Mayer's avatar Mikaël Mayer Committed by Ravi
Browse files

Added the function invocation coverage.

parent 936eed24
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,8 @@ import bonsai.enumerators.MemoizedEnumerator ...@@ -17,8 +17,8 @@ import bonsai.enumerators.MemoizedEnumerator
import solvers.Model import solvers.Model
import solvers.ModelBuilder import solvers.ModelBuilder
import scala.collection.mutable.ListBuffer import scala.collection.mutable.ListBuffer
import leon.LeonContext import leon.LeonContext
import leon.purescala.Definitions.TypedFunDef
/** /**
* @author Mikael * @author Mikael
...@@ -63,6 +63,7 @@ class InputCoverage(fd: FunDef, fds: Set[FunDef])(implicit c: LeonContext, p: Pr ...@@ -63,6 +63,7 @@ class InputCoverage(fd: FunDef, fds: Set[FunDef])(implicit c: LeonContext, p: Pr
}).unzip // TODO: Check for unapply with function pattern ? }).unzip // TODO: Check for unapply with function pattern ?
(MatchExpr(c1, new_cases).copiedFrom(e), variables.flatten) (MatchExpr(c1, new_cases).copiedFrom(e), variables.flatten)
case Operator(lhsrhs, builder) => case Operator(lhsrhs, builder) =>
// The exprBuilder adds variable definitions needed to compute the arguments.
val (exprBuilder, children, ids) = (((e: Expr) => e, List[Expr](), ListBuffer[Identifier]()) /: lhsrhs) { val (exprBuilder, children, ids) = (((e: Expr) => e, List[Expr](), ListBuffer[Identifier]()) /: lhsrhs) {
case ((exprBuilder, children, ids), arg) => case ((exprBuilder, children, ids), arg) =>
val (arg1, argv1) = markBranches(arg) val (arg1, argv1) = markBranches(arg)
...@@ -75,13 +76,23 @@ class InputCoverage(fd: FunDef, fds: Set[FunDef])(implicit c: LeonContext, p: Pr ...@@ -75,13 +76,23 @@ class InputCoverage(fd: FunDef, fds: Set[FunDef])(implicit c: LeonContext, p: Pr
(exprBuilder, arg::children, ids) (exprBuilder, arg::children, ids)
} }
} }
if(e.isInstanceOf[FunctionInvocation]) { e match {
// Should be different. case FunctionInvocation(TypedFunDef(fd, targs), args) =>
} else if(ids.isEmpty) { // Should be different since functions will return a boolean as well.
(e, Seq.empty) val res_id = FreshIdentifier("res", fd.returnType)
} else { val res_b = FreshIdentifier("b", BooleanType)
val body = tupleWrap(Seq(builder(children).copiedFrom(e), or(ids.map(Variable): _*))) val finalIds = (ids :+ res_b)
(exprBuilder(body), ids) val finalExpr =
tupleWrap(Seq(Variable(res_id), or(finalIds.map(Variable(_)): _*)))
val funCall = letTuple(Seq(res_id, res_b), builder(children).copiedFrom(e), finalExpr)
(exprBuilder(funCall), finalIds)
case _ =>
if(ids.isEmpty) {
(e, Seq.empty)
} else {
val finalExpr = tupleWrap(Seq(builder(children).copiedFrom(e), or(ids.map(Variable): _*)))
(exprBuilder(finalExpr), ids)
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment