|
1 | 1 | #! /usr/bin/env python3 |
2 | 2 | from __future__ import print_function |
| 3 | +import networkx as nx |
3 | 4 | import re |
4 | 5 | stdcl = re.compile("^std::(.*)[^>]$") |
5 | 6 | stdptr = re.compile("(.*)_ptr$") |
6 | 7 | datacl = re.compile("^class ") |
7 | 8 | bfunc = re.compile("^function ") |
8 | 9 | mbcl = re.compile("(base|data) class") |
9 | | -farg = re.compile("(.*)\(\w+\)") |
10 | | -nsep = re.compile("\:\:") |
11 | | -topfunc = re.compile("::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream)\(") |
12 | | -baseclass = re.compile("edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?") |
13 | | -getfunc = re.compile("edm::eventsetup::EventSetupRecord::get\<.*\>\((.*)&\) const") |
| 10 | +farg = re.compile(r"(.*)\(\w+\)") |
| 11 | +nsep = re.compile(r"\:\:") |
| 12 | +topfunc = re.compile( |
| 13 | + r"::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream)\(") |
| 14 | +baseclass = re.compile( |
| 15 | + "edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?") |
| 16 | +getfunc = re.compile( |
| 17 | + r"edm::eventsetup::EventSetupRecord::get\<.*\>\((.*)&\) const") |
14 | 18 | handle = re.compile("(.*),?class edm::ES(.*)Handle<(.*)>") |
15 | 19 | statics = set() |
16 | 20 | toplevelfuncs = set() |
|
26 | 30 | memberclasses = set() |
27 | 31 | derivedclasses = set() |
28 | 32 |
|
29 | | -import networkx as nx |
30 | | -G=nx.DiGraph() |
31 | | -H=nx.DiGraph() |
32 | | -I=nx.DiGraph() |
| 33 | +Gdg = nx.DiGraph() |
| 34 | +Hdg = nx.DiGraph() |
| 35 | +Idg = nx.DiGraph() |
33 | 36 |
|
34 | 37 |
|
35 | 38 | f = open('classes.txt.dumperall') |
36 | | -for line in f : |
37 | | - if mbcl.search(line) : |
38 | | - fields = line.split("'") |
39 | | - if fields[2] == ' member data class ': |
40 | | - if not stdcl.search(fields[2]) : H.add_edge(fields[1],fields[3],kind=fields[2]) |
41 | | - if fields[2] == ' templated member data class ': |
42 | | - H.add_edge(fields[1],fields[5],kind=fields[3]) |
43 | | - if fields[2] == ' base class ': |
44 | | - H.add_edge(fields[1],fields[3],kind=fields[2]) |
45 | | - I.add_edge(fields[3],fields[1],kind=' derived class') |
| 39 | +for line in f: |
| 40 | + if mbcl.search(line): |
| 41 | + fields = line.split("'") |
| 42 | + if fields[2] == ' member data class ': |
| 43 | + if not stdcl.search(fields[2]): |
| 44 | + Hdg.add_edge(fields[1], fields[3], kind=fields[2]) |
| 45 | + if fields[2] == ' templated member data class ': |
| 46 | + Hdg.add_edge(fields[1], fields[5], kind=fields[3]) |
| 47 | + if fields[2] == ' base class ': |
| 48 | + Hdg.add_edge(fields[1], fields[3], kind=fields[2]) |
| 49 | + Idg.add_edge(fields[3], fields[1], kind=' derived class') |
46 | 50 | f.close() |
47 | 51 |
|
48 | 52 | f = open('function-calls-db.txt') |
49 | 53 |
|
50 | | -for line in f : |
51 | | - if not bfunc.search(line) : continue |
52 | | - fields = line.split("'") |
53 | | - if fields[2] == ' calls function ' : |
54 | | - G.add_edge(fields[1],fields[3],kind=' calls function ') |
55 | | - if getfunc.search(fields[3]) : |
56 | | - dataclassfuncs.add(fields[3]) |
57 | | - m = getfunc.match(fields[3]) |
58 | | - n = handle.match(m.group(1)) |
59 | | - if n : o = n.group(3) |
60 | | - else : o = m.group(1) |
61 | | - p = re.sub("class ","",o) |
62 | | - dataclass = re.sub("struct ","",p) |
63 | | - dataclasses.add(dataclass) |
64 | | - if fields[2] == ' overrides function ' : |
65 | | - if baseclass.search(fields[3]) : |
66 | | - G.add_edge(fields[1],fields[3],kind=' overrides function ') |
67 | | - if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1]) |
68 | | - else : G.add_edge(fields[3],fields[1], kind=' calls override function ') |
69 | | - if fields[2] == ' static variable ' : |
70 | | - G.add_edge(fields[1],fields[3],kind=' static variable ') |
71 | | - statics.add(fields[3]) |
| 54 | +for line in f: |
| 55 | + if not bfunc.search(line): |
| 56 | + continue |
| 57 | + fields = line.split("'") |
| 58 | + if fields[2] == ' calls function ': |
| 59 | + Gdg.add_edge(fields[1], fields[3], kind=' calls function ') |
| 60 | + if getfunc.search(fields[3]): |
| 61 | + dataclassfuncs.add(fields[3]) |
| 62 | + m = getfunc.match(fields[3]) |
| 63 | + n = handle.match(m.group(1)) |
| 64 | + if n: |
| 65 | + o = n.group(3) |
| 66 | + else: |
| 67 | + o = m.group(1) |
| 68 | + p = re.sub("class ", "", o) |
| 69 | + dataclass = re.sub("struct ", "", p) |
| 70 | + dataclasses.add(dataclass) |
| 71 | + if fields[2] == ' overrides function ': |
| 72 | + if baseclass.search(fields[3]): |
| 73 | + Gdg.add_edge(fields[1], fields[3], kind=' overrides function ') |
| 74 | + if topfunc.search(fields[3]): |
| 75 | + toplevelfuncs.add(fields[1]) |
| 76 | + else: |
| 77 | + Gdg.add_edge(fields[3], fields[1], kind=' calls override function ') |
| 78 | + if fields[2] == ' static variable ': |
| 79 | + Gdg.add_edge(fields[1], fields[3], kind=' static variable ') |
| 80 | + statics.add(fields[3]) |
72 | 81 | f.close() |
73 | 82 |
|
74 | 83 | visited = set() |
75 | 84 | nodes = sorted(dataclasses) |
76 | 85 | for node in nodes: |
77 | | - if node in visited: |
78 | | - continue |
79 | | - visited.add(node) |
80 | | - if node in H : stack = [(node,iter(H[node]))] |
81 | | - if node in I : |
82 | | - Q=nx.dfs_preorder_nodes(I,node) |
83 | | - for q in Q: |
84 | | - print("class '"+q+"'") |
85 | | - if q in H : |
86 | | - stack.append( ( q, iter( H[q] ) ) ) |
87 | | - while stack: |
88 | | - parent,children = stack[-1] |
89 | | - print("class '"+parent+"'") |
90 | | - try: |
91 | | - child = next(children) |
92 | | - if child not in visited: |
93 | | - visited.add(child) |
94 | | - if not stdcl.search(child): |
95 | | - print("class '"+child+"'") |
96 | | - stack.append( ( child, iter( H[child] ) ) ) |
97 | | - kind=H[parent][child]['kind'] |
98 | | - print(parent, kind, child) |
99 | | - if stdptr.search(kind): |
100 | | - if child in I : |
101 | | - Q=nx.dfs_preorder_nodes(I,child) |
102 | | - for q in Q : |
103 | | - print("class '"+q+"'") |
104 | | - if q in H : |
105 | | - stack.append( ( q, iter( H[q] ) ) ) |
106 | | - except StopIteration: |
107 | | - stack.pop() |
| 86 | + if node in visited: |
| 87 | + continue |
| 88 | + visited.add(node) |
| 89 | + if node in Hdg: |
| 90 | + stack = [(node, iter(Hdg[node]))] |
| 91 | + if node in Idg: |
| 92 | + Qdg = nx.dfs_preorder_nodes(Idg, node) |
| 93 | + for q in Qdg: |
| 94 | + print("class '"+q+"'") |
| 95 | + if q in Hdg: |
| 96 | + stack.append((q, iter(Hdg[q]))) |
| 97 | + while stack: |
| 98 | + parent, children = stack[-1] |
| 99 | + print("class '"+parent+"'") |
| 100 | + try: |
| 101 | + child = next(children) |
| 102 | + if child not in visited: |
| 103 | + visited.add(child) |
| 104 | + if not stdcl.search(child): |
| 105 | + print("class '"+child+"'") |
| 106 | + stack.append((child, iter(Hdg[child]))) |
| 107 | + kind = Hdg[parent][child]['kind'] |
| 108 | + print(parent, kind, child) |
| 109 | + if stdptr.search(kind): |
| 110 | + if child in Idg: |
| 111 | + Qdg = nx.dfs_preorder_nodes(Idg, child) |
| 112 | + for q in Qdg: |
| 113 | + print("class '"+q+"'") |
| 114 | + if q in Hdg: |
| 115 | + stack.append((q, iter(Hdg[q]))) |
| 116 | + except StopIteration: |
| 117 | + stack.pop() |
0 commit comments