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<(.*)>")
12 skip = re.compile(
"edm::serviceregistry::ServicesManager::MakerHolder::add() const")
16 dataclassfuncs = set()
24 flaggedclasses = set()
29 f = open(
'classes.txt.dumperft')
31 if datacl.search(line) :
32 classname = line.split(
"'")[1]
33 dclasses.add(classname)
36 f = open(
'classes.txt.inherits')
38 if datacl.search(line) :
39 classname = line.split(
"'")[1]
40 dataclasses.add(classname)
44 f = open(
'class-checker.txt')
47 fields = line.split(
"'")
50 badclasses.add(classname)
51 badfuncs.add(funcname)
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])
71 if not bfunc.search(line) :
continue
72 fields = line.split(
"'")
73 if skip.search(fields[1])
or skip.search(fields[3]) :
continue
74 if fields[2] ==
' calls function ' :
75 G.add_edge(fields[1],fields[3],kind=
' calls function ')
76 if getfunc.search(fields[3]) :
77 dataclassfuncs.add(fields[3])
78 m = getfunc.match(fields[3])
79 n = handle.match(m.group(1))
82 p = re.sub(
"class ",
"",o)
83 dataclass = re.sub(
"struct ",
"",p)
84 dataclasses.add(dataclass)
85 if fields[2] ==
' overrides function ' :
86 if baseclass.search(fields[3]) :
87 G.add_edge(fields[1],fields[3],kind=
' overrides function ')
88 if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
89 else : G.add_edge(fields[3],fields[1], kind=
' calls override function ')
90 if fields[2] ==
' static variable ' :
91 G.add_edge(fields[1],fields[3],kind=
' static variable ')
92 statics.add(fields[3])
96 for n,nbrdict
in G.adjacency_iter():
97 for nbr,eattr
in nbrdict.items():
98 if n
in badfuncs
or nbr
in badfuncs :
99 if 'kind' in eattr
and eattr[
'kind'] ==
' overrides function ' :
100 print "'"+n+
"'"+eattr[
'kind']+
"'"+nbr+
"'"
104 for n,nbrdict
in H.adjacency_iter():
105 for nbr,eattr
in nbrdict.items():
106 if n
in badclasses
and 'kind' in eattr
and eattr[
'kind'] ==
' base class ' :
110 for n,nbrdict
in H.adjacency_iter():
111 for nbr,eattr
in nbrdict.items():
112 if nbr
in dclasses
and 'kind' in eattr
and eattr[
'kind'] ==
' base class ' :
115 print "flagged functions found by checker"
116 for dfunc
in sorted(badfuncs) :
120 print "flagged classes found by checker "
121 for dclass
in sorted(badclasses) :
125 print "flagged classes found by checker union get"
126 for dclass
in sorted(dclasses.intersection(badclasses)) :
131 print "classes inheriting from flagged classes"
132 for dclass
in sorted(virtclasses):
136 print "functions overridden by flagged functions"
137 for dfunc
in sorted(virtfuncs):
142 for badclass
in sorted(badclasses):
143 print "Event setup data class '"+badclass+
"' is flagged."
144 flaggedclasses.add(badclass)
147 for virtclass
in sorted(virtclasses):
148 print "Event setup data class '"+virtclass+
"' is flagged because inheriting class is flagged"
149 flaggedclasses.add(virtclass)
152 for badclass
in sorted(badclasses):
153 for dataclass
in sorted(dataclasses):
154 if H.has_node(badclass)
and H.has_node(dataclass):
155 if nx.has_path(H,dataclass, badclass) :
156 print "Event setup data class '"+dataclass+
"' contains or inherits from flagged class '"+badclass+
"'."
157 flaggedclasses.add(dataclass)
162 for dataclassfunc
in sorted(dataclassfuncs):
163 for tfunc
in sorted(toplevelfuncs):
164 if nx.has_path(G,tfunc,dataclassfunc):
165 m = getfunc.match(dataclassfunc)
166 n = handle.match(m.group(1))
167 if n : o = n.group(3)
168 else : o = m.group(1)
169 p = re.sub(
"class ",
"",o)
170 q = re.sub(
"struct ",
"",p)
171 dataclass = re.sub(
"<.*> ",
"",q)
172 for flaggedclass
in sorted(flaggedclasses):
173 exact=
r"^" + re.escape(flaggedclass) +
r"$"
174 exactmatch=re.match(exact,dataclass)
176 print "Flagged event setup data class '"+dataclass+
"' is accessed in call stack '",
177 path = nx.shortest_path(G,tfunc,dataclassfunc)
181 for key
in G[tfunc].
keys() :
182 if 'kind' in G[tfunc][key]
and G[tfunc][key][
'kind'] ==
' overrides function ' :
183 print "'"+tfunc+
"'"+G[tfunc][key][
'kind']+
"'"+key+
"'",
185 print "In call stack '",
186 path = nx.shortest_path(G,tfunc,dataclassfunc)
189 print "' flagged event setup data class '"+dataclass+
"' is accessed. ",
190 for key
in G[tfunc].
keys() :
191 if 'kind' in G[tfunc][key]
and G[tfunc][key][
'kind'] ==
' overrides function ' :
192 print "'"+tfunc+
"'"+G[tfunc][key][
'kind']+
"'"+key+
"'",