-
Notifications
You must be signed in to change notification settings - Fork 239
/
CallInOut.py
88 lines (74 loc) · 2.7 KB
/
CallInOut.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import re
import copy
import sys
class CallInOut:
invokeDir={} # invokeDir:{the invoked method ---> the invoking method}
invokeDir2 = {} # invokeDir2:{the invoking method ---> the invoked method}
def __init__(self, methodInvokeList):
self.preprocess(methodInvokeList)
def preprocess(self, methodInvokeList):
"""
This function is to pre-process the invoke relations.
@param methodInvokeList: the list of method ---> method
"""
pattern="(.*) ---> (.*)"
for line in methodInvokeList:
li=re.search(pattern,line).groups()
# if the recursion exists, the detect loop will not be end
if li[0] == li[1]:
continue
m0 = li[1].split("^")[0]
m1 = li[1].split("^")[1]
if m0 not in list(self.invokeDir.keys()):
self.invokeDir[m0]=[li[0]+"^" +m1]
else:
if li[0] not in self.invokeDir[m0]:
self.invokeDir[m0].append(li[0]+"^" +m1)
if li[0] not in list(self.invokeDir2.keys()):
self.invokeDir2[li[0]]=[li[1]]
else:
if li[1] not in self.invokeDir2[li[0]]:
self.invokeDir2[li[0]].append(li[1])
file = open('invokedir.txt','a')
file.write("%s\n" % self.invokeDir)
file.close
file = open('invokedir2.txt','a')
file.write("%s\n" % self.invokeDir2)
file.close
# yuan build the call graph
def callTree(self, method):
import Global
mcalltree = []
# self.firstmethod = Global.FM
self.endmethod = Global.endmethod
branch = self.searchCallOut(method)
mcalltree.append(method)
mcalltree.append(" ---> ")
mcalltree.append(branch)
i = 0
while (i < 10):
branch = self.searchCallOut(branch)
mcalltree.append(" ---> ")
mcalltree.append(branch)
i += 1
return mcalltree
def searchCallOut(self, method):
"""
This function is to search the "call out" methods
"""
callOutIdList = []
if method not in self.invokeDir2.keys():
return []
else:
callOutIdList = self.invokeDir2[method]
return callOutIdList
def searchCallIn(self, method):
"""
This function is to search the "call in" methods
"""
callInIdList = []
if method not in self.invokeDir.keys():
return []
else:
callInIdList = self.invokeDir[method]
return callInIdList