Complete re-design.
This commit is contained in:
parent
5861bedf02
commit
0382167bff
|
@ -10,48 +10,24 @@
|
||||||
|
|
||||||
package eu.aniketos.dasca.crosslanguage.cg;
|
package eu.aniketos.dasca.crosslanguage.cg;
|
||||||
|
|
||||||
import java.util.ArrayList
|
|
||||||
import com.ibm.wala.classLoader.CallSiteReference
|
|
||||||
import com.ibm.wala.classLoader.Language
|
|
||||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||||
import com.ibm.wala.cast.js.loader.JavaScriptLoader
|
|
||||||
import com.ibm.wala.cast.js.types.JavaScriptMethods
|
|
||||||
|
|
||||||
class CallTree( data:CGNode, parent:CallTree,level:Integer){
|
class CallTree(value: CGNode, children: List[CallTree]) {
|
||||||
|
def this(value: CGNode) = this(value, null)
|
||||||
|
|
||||||
private var children = List[CallTree]()
|
|
||||||
private val indent = 5
|
private val indent = 5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def this(data:CGNode) = this(data, null, 0)
|
|
||||||
|
|
||||||
def addChildren(data:CGNode) = children :+ new CallTree(data, this, level+1)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this method return the path from current Node to root
|
|
||||||
* @return
|
|
||||||
* return An ArrayList which contains path of currentNode
|
|
||||||
*/
|
|
||||||
def getPathOfNode():List[CGNode] = {
|
|
||||||
var path = List[CGNode]()
|
|
||||||
var currentNode = this
|
|
||||||
do{
|
|
||||||
path :+ this
|
|
||||||
currentNode = currentNode.getParent()
|
|
||||||
if(currentNode.getParent()==null){
|
|
||||||
path :+ currentNode.getValue()
|
|
||||||
}
|
|
||||||
}while(currentNode.getParent()!=null);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
def getValue() = data
|
|
||||||
def getParent() = parent
|
|
||||||
def getChildren() = children
|
|
||||||
def getLevel() = level
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def contains(v: CGNode): Boolean = {
|
||||||
|
if (value == v) {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
(children.map { c => c.contains(v) }).fold(false) { (a, b) => a || b }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override def toString(): String = {
|
||||||
|
value.getMethod().getName().toString() + "\n" + ((children.map { c => "├── " + c.toString() + "\n" })
|
||||||
|
.fold("") { (a, b) => a + b })
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,70 +27,28 @@ import eu.aniketos.dasca.crosslanguage.builder.CordovaCGBuilder
|
||||||
import eu.aniketos.dasca.crosslanguage.builder.CrossBuilderOption
|
import eu.aniketos.dasca.crosslanguage.builder.CrossBuilderOption
|
||||||
import collection.JavaConverters._
|
import collection.JavaConverters._
|
||||||
|
|
||||||
class CallTreeBuilder {
|
object CallTreeBuilder {
|
||||||
var queue = new LinkedList[CGNode]();
|
def buildCallForest(cg: MergedCallGraph, sources: List[CGNode], sinks: List[CGNode]): List[CallTree] = {
|
||||||
var rootqueue = new LinkedList[CallTree]();
|
return sources.map { src => buildCallTree(cg, src, sinks) }.filter { x => null != x }
|
||||||
|
}
|
||||||
def buildCallForest(cg:MergedCallGraph, sources:List[CGNode], sinks:List[CGNode]):List[CallTree] = {
|
|
||||||
return sources.map { src => buildCallTree(cg,src,sinks) }.filter { x => null != x }
|
def buildCallTree(cg: MergedCallGraph, root: CGNode, sinks: List[CGNode]): CallTree = {
|
||||||
}
|
build(cg, List[CGNode](), sinks, root)
|
||||||
|
}
|
||||||
def buildCallTree(cg:MergedCallGraph, root: CGNode, sinks:List[CGNode]):CallTree = {
|
|
||||||
var ct = null:CallTree
|
private def build(cg: MergedCallGraph, visited: List[CGNode], sinks: List[CGNode], root: CGNode): CallTree = {
|
||||||
var visited = List[CGNode]()
|
if (sinks.contains(root)) {
|
||||||
var NumofCount = 0;
|
return new CallTree(root)
|
||||||
queue.add(root)
|
} else {
|
||||||
while(!queue.isEmpty()){
|
val targetNodes = cg.getAllPossibleTargetNodes(root).filterNot { n => visited.contains(n) }
|
||||||
var currentNode = queue.poll()
|
if (targetNodes.isEmpty) {
|
||||||
var RootOfCurrentNode = rootqueue.poll()
|
return null
|
||||||
|
} else {
|
||||||
if(!visited.contains(currentNode)){
|
val children = targetNodes.toList.map { x => build(cg, visited ++ targetNodes, sinks, x) }
|
||||||
visited :+ currentNode
|
.filterNot { x => (null == x) }
|
||||||
// search for the whether this node contains the method
|
return new CallTree(root, children)
|
||||||
var it = currentNode.iterateCallSites()
|
|
||||||
var method = null:CallSiteReference
|
|
||||||
|
|
||||||
while (it.hasNext())
|
|
||||||
method = it.next()
|
|
||||||
// if this node contains the method we want
|
|
||||||
// print the path
|
|
||||||
if(sinks.contains(method.asInstanceOf[CallSiteReference].getDeclaredTarget())){
|
|
||||||
// RootOfCurrentNode.printPath(method)
|
|
||||||
NumofCount = NumofCount+1
|
|
||||||
}else{
|
|
||||||
// if not find the method in current Node,
|
|
||||||
// add this node to the Node tree which used to create the path
|
|
||||||
if(currentNode.equals(root)){
|
|
||||||
var tree = new CallTree(currentNode)
|
|
||||||
createTree(cg,currentNode,method,tree)
|
|
||||||
}else{
|
|
||||||
createTree(cg,currentNode,method,RootOfCurrentNode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return ct
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* this method is used to create the Node Tree.
|
|
||||||
* @param cg cg is the call graph
|
|
||||||
* @param currentNode this parameter is the node that be search
|
|
||||||
* @param method method is the function that need to find in a particular node
|
|
||||||
* @param RootOfCurrentNode the previous node that has be search which is the parent of current node
|
|
||||||
*/
|
|
||||||
def createTree(cg:MergedCallGraph, currentNode: CGNode, method:CallSiteReference, RootOfCurrentNode:CallTree) = {
|
|
||||||
var n = null:CGNode
|
|
||||||
var child = null:CallTree
|
|
||||||
var targetNode = cg.getAllPossibleTargetNodes(currentNode)
|
|
||||||
var it = targetNode.iterator
|
|
||||||
for (n <- it){
|
|
||||||
queue.add(n);
|
|
||||||
if(RootOfCurrentNode!=null){
|
|
||||||
child = new CallTree(n,RootOfCurrentNode,RootOfCurrentNode.getLevel()+1);
|
|
||||||
rootqueue.add(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue