-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree_parser.py
More file actions
55 lines (49 loc) · 1.79 KB
/
tree_parser.py
File metadata and controls
55 lines (49 loc) · 1.79 KB
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
import ast
import astpretty
import astdump
from simMatrix import simMatrix
def parse_tree(f1,f2):
with open(f1, "r+") as myfile:
source = myfile.read()
with open(f2, "r+") as myfile2:
source2 = myfile2.read()
module_tree = ast.parse(source)
module_tree2 = ast.parse(source2)
# astpretty.pprint(module)
# print("----------------------")
# astpretty.pprint(module2)
fndetails = []
fnnames1 = []
function_segments = [node for node in ast.walk(module_tree) if isinstance(node, ast.FunctionDef)]
for f in function_segments:
details = []
details.append(f.name)
fnnames1.append(f.name)
details.append([a.arg for a in f.args.args])
returnstatements = [node for node in ast.walk(module_tree) if isinstance(node, ast.Return)]
for b in returnstatements:
new = [a.id for a in b.value.elts]
details.append(new)
s = str(astdump.indented(f, printres=False))
stri = s.split()
details.append(stri)
fndetails.append(details)
fndetails2 = []
fnnames2 = []
function_segments2 = [node for node in ast.walk(module_tree2) if isinstance(node, ast.FunctionDef)]
for f in function_segments2:
details2 = []
details2.append(f.name)
fnnames2.append(f.name)
details2.append([a.arg for a in f.args.args])
for b in f.body:
if isinstance(b, ast.Return):
new = [a.id for a in b.value.elts]
details2.append(new)
s = str(astdump.indented(f, printres=False))
stri = s.split()
details2.append(stri)
fndetails2.append(details2)
return fndetails,fndetails2,fnnames1,fnnames2,f1,f2
if __name__ == "__main__":
main()