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|beginStream)\(")
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])
69 for line
in fileinput.input(files =(
'function-statics-db.txt',
'function-calls-db.txt')):
70 if not bfunc.search(line) :
continue
71 fields = line.split(
"'")
72 if skip.search(fields[1])
or skip.search(fields[3]) :
continue
73 if fields[2] ==
' calls function ' :
74 G.add_edge(fields[1],fields[3],kind=
' calls function ')
75 if getfunc.search(fields[3]) :
76 dataclassfuncs.add(fields[3])
77 m = getfunc.match(fields[3])
78 n = handle.match(m.group(1))
81 p = re.sub(
"class ",
"",o)
82 dataclass = re.sub(
"struct ",
"",p)
83 dataclasses.add(dataclass)
84 if fields[2] ==
' overrides function ' :
85 if baseclass.search(fields[3]) :
86 G.add_edge(fields[1],fields[3],kind=
' overrides function ')
87 if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
88 else : G.add_edge(fields[3],fields[1], kind=
' calls override function ')
89 if fields[2] ==
' static variable ' :
90 G.add_edge(fields[1],fields[3],kind=
' static variable ')
91 statics.add(fields[3])
94 for n,nbrdict
in G.adjacency_iter():
95 for nbr,eattr
in nbrdict.items():
96 if n
in badfuncs
or nbr
in badfuncs :
97 if 'kind' in eattr
and eattr[
'kind'] ==
' overrides function ' :
98 print "'"+n+
"'"+eattr[
'kind']+
"'"+nbr+
"'"
102 for n,nbrdict
in H.adjacency_iter():
103 for nbr,eattr
in nbrdict.items():
104 if n
in badclasses
and 'kind' in eattr
and eattr[
'kind'] ==
' base class ' :
108 for n,nbrdict
in H.adjacency_iter():
109 for nbr,eattr
in nbrdict.items():
110 if nbr
in dclasses
and 'kind' in eattr
and eattr[
'kind'] ==
' base class ' :
113 print "flagged functions found by checker"
114 for dfunc
in sorted(badfuncs) :
118 print "flagged classes found by checker "
119 for dclass
in sorted(badclasses) :
123 print "flagged classes found by checker union get"
124 for dclass
in sorted(dclasses.intersection(badclasses)) :
129 print "classes inheriting from flagged classes"
130 for dclass
in sorted(virtclasses):
134 print "functions overridden by flagged functions"
135 for dfunc
in sorted(virtfuncs):
140 for badclass
in sorted(badclasses):
141 print "Event setup data class '"+badclass+
"' is flagged."
142 flaggedclasses.add(badclass)
145 for virtclass
in sorted(virtclasses):
146 print "Event setup data class '"+virtclass+
"' is flagged because inheriting class is flagged"
147 flaggedclasses.add(virtclass)
150 for badclass
in sorted(badclasses):
151 for dataclass
in sorted(dataclasses):
152 if H.has_node(badclass)
and H.has_node(dataclass):
153 if nx.has_path(H,dataclass, badclass) :
154 print "Event setup data class '"+dataclass+
"' contains or inherits from flagged class '"+badclass+
"'."
155 flaggedclasses.add(dataclass)
160 for dataclassfunc
in sorted(dataclassfuncs):
161 for tfunc
in sorted(toplevelfuncs):
162 if nx.has_path(G,tfunc,dataclassfunc):
163 m = getfunc.match(dataclassfunc)
164 n = handle.match(m.group(1))
165 if n : o = n.group(3)
166 else : o = m.group(1)
167 p = re.sub(
"class ",
"",o)
168 q = re.sub(
"struct ",
"",p)
169 dataclass = re.sub(
"<.*> ",
"",q)
170 for flaggedclass
in sorted(flaggedclasses):
171 exact=
r"^" + re.escape(flaggedclass) +
r"$"
172 exactmatch=re.match(exact,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+
"'",