3 datacl = re.compile(
"^class ")
4 bfunc = re.compile(
"^function ")
5 mbcl = re.compile(
"(base|data) class")
6 farg = re.compile(
"(.*)\(\w+\)")
7 nsep = re.compile(
"\:\:")
8 topfunc = re.compile(
"::(produce|analyze|filter|beginLuminosityBlock|beginRun)\(")
9 baseclass = re.compile(
"edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
10 getfunc = re.compile(
"edm::eventsetup::EventSetupRecord::get\((.*)&\) const")
11 handle = re.compile(
"(.*),?class edm::ES(.*)Handle<(.*)>")
15 dataclassfuncs = set()
22 flaggedclasses = set()
27 f = open(
'classes.txt.dumperft')
29 if datacl.search(line) :
30 classname = line.split(
"'")[1]
31 esdclasses.add(classname)
34 f = open(
'classes.txt.inherits')
36 if datacl.search(line) :
37 classname = line.split(
"'")[1]
38 esdclasses.add(classname)
42 f = open(
'class-checker.txt')
45 fields = line.split(
"'")
48 badclasses.add(classname)
49 badfuncs.add(funcname)
53 f = open(
'classes.txt.dumperall')
55 if mbcl.search(line) :
56 fields = line.split(
"'")
57 if fields[2] ==
' member data class ':
58 H.add_edge(fields[1],fields[3],kind=fields[2])
59 if fields[2] ==
' templated member data class ':
60 H.add_edge(fields[1],fields[3],kind=fields[2])
61 if fields[2] ==
' base class ':
62 H.add_edge(fields[1],fields[3],kind=fields[2])
69 if not bfunc.search(line) :
continue
70 fields = line.split(
"'")
71 if fields[2] ==
' calls function ' :
72 G.add_edge(fields[1],fields[3],kind=
' calls function ')
73 if getfunc.search(fields[3]) :
74 dataclassfuncs.add(fields[3])
75 m = getfunc.match(fields[3])
76 n = handle.match(m.group(1))
79 p = re.sub(
"class ",
"",o)
80 dataclass = re.sub(
"struct ",
"",p)
81 dataclasses.add(dataclass)
82 if fields[2] ==
' overrides function ' :
83 if baseclass.search(fields[3]) :
84 G.add_edge(fields[1],fields[3],kind=
' overrides function ')
85 if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
86 else : G.add_edge(fields[3],fields[1], kind=
' calls override function ')
87 if fields[2] ==
' static variable ' :
88 G.add_edge(fields[1],fields[3],kind=
' static variable ')
89 statics.add(fields[3])
93 for n,nbrdict
in G.adjacency_iter():
94 for nbr,eattr
in nbrdict.items():
95 if n
in badfuncs
or nbr
in badfuncs :
96 if 'kind' in eattr
and eattr[
'kind'] ==
' overrides function ' :
97 print "'"+n+
"'"+eattr[
'kind']+
"'"+nbr+
"'"
101 for n,nbrdict
in H.adjacency_iter():
102 for nbr,eattr
in nbrdict.items():
103 if n
in badclasses
and 'kind' in eattr
and eattr[
'kind'] ==
' base class ' :
107 for n,nbrdict
in H.adjacency_iter():
108 for nbr,eattr
in nbrdict.items():
109 if nbr
in dataclasses
and 'kind' in eattr
and eattr[
'kind'] ==
' base class ' :
112 print "flagged functions found by checker"
113 for dfunc
in sorted(badfuncs) :
117 print "flagged classes found by checker "
118 for dclass
in sorted(badclasses) :
122 print "flagged classes found by checker union get"
123 for dclass
in sorted(dataclasses.intersection(badclasses)) :
127 print "flagged classes found by checker union dumper"
128 for dclass
in sorted(esdclasses.intersection(badclasses)) :
132 print "classes inheriting from flagged classes"
133 for dclass
in sorted(virtclasses):
137 print "functions overridden by flagged functions"
138 for dfunc
in sorted(virtfuncs):
143 for badclass
in sorted(badclasses):
144 print "Event setup data class '"+badclass+
"' is flagged."
145 flaggedclasses.add(badclass)
148 for virtclass
in sorted(virtclasses):
149 print "Event setup data class '"+virtclass+
"' is flagged because inheriting class is flagged"
150 flaggedclasses.add(virtclass)
153 for badclass
in sorted(badclasses):
154 for dataclass
in sorted(dataclasses):
155 if H.has_node(badclass)
and H.has_node(dataclass):
156 if nx.has_path(H,dataclass, badclass) :
157 print "Event setup data class '"+dataclass+
"' contains or inherits from flagged class '"+badclass+
"'."
158 flaggedclasses.add(dataclass)
163 for dataclassfunc
in sorted(dataclassfuncs):
164 for tfunc
in sorted(toplevelfuncs):
165 if nx.has_path(G,tfunc,dataclassfunc):
166 m = getfunc.match(dataclassfunc)
167 n = handle.match(m.group(1))
168 if n : o = n.group(3)
169 else : o = m.group(1)
170 p = re.sub(
"class ",
"",o)
171 dataclass = re.sub(
"struct ",
"",p)
172 for flaggedclass
in sorted(flaggedclasses):
173 if re.search(flaggedclass,dataclass) :
174 print "Flagged event setup data class '"+dataclass+
"' is accessed in call stack '",
175 path = nx.shortest_path(G,tfunc,dataclassfunc)
179 for key
in G[tfunc].
keys() :
180 if 'kind' in G[tfunc][key]
and G[tfunc][key][
'kind'] ==
' overrides function ' :
181 print "'"+tfunc+
"'"+G[tfunc][key][
'kind']+
"'"+key+
"'",
183 print "In call stack '",
184 path = nx.shortest_path(G,tfunc,dataclassfunc)
187 print "' flagged event setup data class '"+dataclass+
"' is accessed. ",
188 for key
in G[tfunc].
keys() :
189 if 'kind' in G[tfunc][key]
and G[tfunc][key][
'kind'] ==
' overrides function ' :
190 print "'"+tfunc+
"'"+G[tfunc][key][
'kind']+
"'"+key+
"'",