2 from __future__
import print_function
4 datacl = re.compile(
"^class ")
5 bfunc = re.compile(
"^function ")
6 mbcl = re.compile(
"(base|data|flagged) class")
7 farg = re.compile(
"(.*)\(\w+\)")
8 nsep = re.compile(
"\:\:")
9 topfunc = re.compile(
"::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream)\(")
10 baseclass = re.compile(
"edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
11 globalclass = re.compile(
"^edm::global::ED(Producer|Filter|Analyzer)$")
12 getfunc = re.compile(
"edm::eventsetup::EventSetupRecord::get<.*>\((.*)&\) const")
13 handle = re.compile(
"(.*),?class edm::ES(.*)Handle<(.*)>")
14 skip = re.compile(
"edm::serviceregistry::ServicesManager::MakerHolder::add() const")
15 rootclass = re.compile(
"T(H1|Tree|Enum|DataType|Class|Branch|Named|File)")
16 stdcl = re.compile(
"^std::(.*)[^>]$")
17 stdptr = re.compile(
"(.*)_ptr$")
21 dataclassfuncs = set()
29 flaggedclasses = set()
36 f = open(
'class-checker.txt')
39 fields = line.split(
"'")
42 badclasses.add(classname)
43 badfuncs.add(funcname)
46 f = open(
'const-checker.txt')
49 fields = line.split(
"'")
51 badclasses.add(classname)
55 f = open(
'classes.txt.dumperall')
57 if mbcl.search(line) :
58 fields = line.split(
"'")
59 if fields[2] ==
' member data class ':
60 H.add_edge(fields[1],fields[3],kind=fields[2])
61 if fields[2] ==
' templated member data class ':
62 H.add_edge(fields[1],fields[3],kind=fields[2])
63 if fields[2] ==
' base class ':
64 H.add_edge(fields[1],fields[3],kind=fields[2])
65 I.add_edge(fields[3],fields[1],kind=
' derived class')
66 if globalclass.match(fields[3]):
67 globalclasses.add(fields[1])
68 print(
"class '"+fields[1]+
"' base class '"+fields[3]+
"'")
72 for line
in fileinput.input(files =(
'function-statics-db.txt',
'function-calls-db.txt')):
73 if not bfunc.search(line) :
continue
74 fields = line.split(
"'")
75 if skip.search(fields[1])
or skip.search(fields[3]) :
continue
76 if fields[2] ==
' calls function ' :
77 G.add_edge(fields[1],fields[3],kind=
' calls function ')
78 if getfunc.search(fields[3]) :
79 dataclassfuncs.add(fields[3])
80 m = getfunc.match(fields[3])
81 n = handle.match(m.group(1))
84 p = re.sub(
"class ",
"",o)
85 dataclass = re.sub(
"struct ",
"",p)
86 dataclasses.add(dataclass)
87 if fields[2] ==
' overrides function ' :
88 if baseclass.search(fields[3]) :
89 G.add_edge(fields[1],fields[3],kind=
' overrides function ')
90 if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
91 else : G.add_edge(fields[3],fields[1], kind=
' calls override function ')
92 if fields[2] ==
' static variable ' :
93 G.add_edge(fields[1],fields[3],kind=
' static variable ')
94 statics.add(fields[3])
99 for n,nbrdict
in G.adjacency_iter():
100 for nbr,eattr
in nbrdict.items():
101 if n
in badfuncs
or nbr
in badfuncs :
102 if 'kind' in eattr
and eattr[
'kind'] ==
' overrides function ' :
103 print(
"'"+n+
"'"+eattr[
'kind']+
"'"+nbr+
"'")
107 print(
"-----------------------------------------------")
108 print(
"flagged functions found by checker")
109 print(
"-----------------------------------------------")
110 for dfunc
in sorted(badfuncs) :
114 print(
"-----------------------------------------------")
115 print(
"flagged classes found by checker ")
116 print(
"-----------------------------------------------")
117 for dclass
in sorted(badclasses) :
121 nodes = sorted(badclasses)
127 if node
in H : stack = [(node,iter(H[node]))]
129 Q=nx.dfs_preorder_nodes(I,node)
132 stack.append( ( q, iter( H[q] ) ) )
134 parent,children = stack[-1]
137 if globalclass.search(child): visited.add(child)
138 if rootclass.search(child): visited.add(child)
139 if child
not in visited:
141 stack.append( ( child, iter( H[child] ) ) )
142 kind=H[parent][child][
'kind']
143 if stdptr.search(kind):
145 Q=nx.dfs_preorder_nodes(I,child)
148 stack.append( ( q, iter( H[q] ) ) )
149 except StopIteration:
151 print(
"flagged class "+node+
" contains or inherits from classes ", end=
' ')
152 for v
in visited :
print(v+
",", end=
' ')
154 for v
in sorted(visited) :
155 if v
in globalclasses:
156 print(
"EDM global class '"+v+
"' is flagged because it is connected to flagged class '"+node+
"'")