Skip to content
Snippets Groups Projects
Commit de2d1b5c authored by Etienne Kneuss's avatar Etienne Kneuss
Browse files

Compute transitive callgraph differently

parent 496c4fa7
No related branches found
No related tags found
No related merge requests found
...@@ -140,32 +140,28 @@ object Definitions { ...@@ -140,32 +140,28 @@ object Definitions {
def calls(f1: FunDef, f2: FunDef) : Boolean = callGraph((f1,f2)) def calls(f1: FunDef, f2: FunDef) : Boolean = callGraph((f1,f2))
lazy val (transitiveCallGraph, transitiveCallers, transitiveCallees) = { lazy val (transitiveCallGraph, transitiveCallers, transitiveCallees) = {
var resSet : Set[(FunDef,FunDef)] = callGraph var tCallees: Map[FunDef, Set[FunDef]] = callGraph.groupBy(_._1).mapValues(_.map(_._2).toSet)
var change = true var change = true
while(change) { while(change) {
change = false change = false
for(f1 <- definedFunctions; f2 <- callers(f1); f3 <- callees(f1)) { for ((fd, calls) <- tCallees) {
if(!resSet(f2,f3)) { val newCalls = calls ++ calls.flatMap(tCallees.getOrElse(_, Set()))
if (newCalls != calls) {
change = true change = true
resSet = resSet + ((f2,f3)) tCallees += fd -> newCalls
} }
} }
} }
var tCallers: Map[FunDef,Set[FunDef]] = val tCallGraph: Set[(FunDef, FunDef)] = tCallees.toSeq.flatMap {
new scala.collection.immutable.HashMap[FunDef,Set[FunDef]] case (fd, calls) => calls.map(fd -> _)
var tCallees: Map[FunDef,Set[FunDef]] = }.toSet
new scala.collection.immutable.HashMap[FunDef,Set[FunDef]]
for(funDef <- definedFunctions) { val tCallers: Map[FunDef, Set[FunDef]] = tCallGraph.groupBy(_._2).mapValues(_.map(_._1).toSet)
val clrs = resSet.filter(_._2 == funDef).map(_._1)
val cles = resSet.filter(_._1 == funDef).map(_._2)
tCallers = tCallers + (funDef -> clrs)
tCallees = tCallees + (funDef -> cles)
}
(resSet, tCallers, tCallees) (tCallGraph, tCallers, tCallees)
} }
def transitivelyCalls(f1: FunDef, f2: FunDef) : Boolean = transitiveCallGraph((f1,f2)) def transitivelyCalls(f1: FunDef, f2: FunDef) : Boolean = transitiveCallGraph((f1,f2))
......
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