Skip to content
Snippets Groups Projects
Commit 715fe63a authored by Lars Hupel's avatar Lars Hupel Committed by Etienne Kneuss
Browse files

track dependencies on unapply patterns in CallGraph

Fixes #143.
parent bbd4170b
No related branches found
No related tags found
No related merge requests found
...@@ -69,13 +69,20 @@ class CallGraph(p: Program) { ...@@ -69,13 +69,20 @@ class CallGraph(p: Program) {
transitiveClosure() transitiveClosure()
} }
private def collectCallsInPats(fd: FunDef)(p: Pattern): Set[(FunDef, FunDef)] =
(p match {
case u: UnapplyPattern => Set((fd, u.unapplyFun.fd))
case _ => Set()
}) ++ p.subPatterns.flatMap(collectCallsInPats(fd))
private def collectCalls(fd: FunDef)(e: Expr): Set[(FunDef, FunDef)] = e match { private def collectCalls(fd: FunDef)(e: Expr): Set[(FunDef, FunDef)] = e match {
case f @ FunctionInvocation(f2, _) => Set((fd, f2.fd)) case f @ FunctionInvocation(f2, _) => Set((fd, f2.fd))
case MatchExpr(_, cases) => cases.toSet.flatMap((mc: MatchCase) => collectCallsInPats(fd)(mc.pattern))
case _ => Set() case _ => Set()
} }
private def scanForCalls(fd: FunDef) { private def scanForCalls(fd: FunDef) {
for( (from, to) <- collect(collectCalls(fd)(_))(fd.fullBody) ) { for( (from, to) <- collect(collectCalls(fd))(fd.fullBody) ) {
_calls += (from -> to) _calls += (from -> to)
_callees += (from -> (_callees.getOrElse(from, Set()) + to)) _callees += (from -> (_callees.getOrElse(from, Set()) + to))
_callers += (to -> (_callers.getOrElse(to, Set()) + from)) _callers += (to -> (_callers.getOrElse(to, Set()) + from))
......
/* Copyright 2009-2015 EPFL, Lausanne */
package leon.integration.purescala
import leon.test._
import leon._
import leon.purescala.Definitions._
import leon.utils._
class CallGraphSuite extends LeonTestSuiteWithProgram with helpers.ExpressionsDSL {
val sources = List(
"""object Matches {
| import leon.collection._
| def aMatch(a: List[Int]) = a match {
| case _ :: _ => 0
| }
|}""".stripMargin
)
test("CallGraph tracks dependency to unapply pattern") { implicit fix =>
val fd1 = funDef("Matches.aMatch")
val fd2 = funDef("leon.collection.::.unapply")
assert(implicitly[Program].callGraph.calls(fd1, fd2))
}
}
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