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 globalclass = re.compile(
"^edm::global::ED(Producer|Filter|Analyzer)$")
11 getfunc = re.compile(
"edm::eventsetup::EventSetupRecord::get<.*>\((.*)&\) const")
12 handle = re.compile(
"(.*),?class edm::ES(.*)Handle<(.*)>")
13 skip = re.compile(
"edm::serviceregistry::ServicesManager::MakerHolder::add() const")
14 rootclass = re.compile(
"T(H1|Tree|Enum|DataType|Class|Branch|Named|File)")
15 stdcl = re.compile(
"^std::(.*)[^>]$")
16 stdptr = re.compile(
"(.*)_ptr$")
20 dataclassfuncs = set()
28 flaggedclasses = set()
35 f = open(
'class-checker.txt')
38 fields = line.split(
"'")
41 badclasses.add(classname)
42 badfuncs.add(funcname)
46 f = open(
'classes.txt.dumperall')
48 if mbcl.search(line) :
49 fields = line.split(
"'")
50 if fields[2] ==
' member data class ':
51 H.add_edge(fields[1],fields[3],kind=fields[2])
52 if fields[2] ==
' templated member data class ':
53 H.add_edge(fields[1],fields[3],kind=fields[2])
54 if fields[2] ==
' base class ':
55 H.add_edge(fields[1],fields[3],kind=fields[2])
56 I.add_edge(fields[3],fields[1],kind=
' derived class')
57 if globalclass.match(fields[3]):
58 globalclasses.add(fields[1])
59 print "class '"+fields[1]+
"' base class '"+fields[3]+
"'"
63 for line
in fileinput.input(files =(
'function-statics-db.txt',
'function-calls-db.txt')):
64 if not bfunc.search(line) :
continue
65 fields = line.split(
"'")
66 if skip.search(fields[1])
or skip.search(fields[3]) :
continue
67 if fields[2] ==
' calls function ' :
68 G.add_edge(fields[1],fields[3],kind=
' calls function ')
69 if getfunc.search(fields[3]) :
70 dataclassfuncs.add(fields[3])
71 m = getfunc.match(fields[3])
72 n = handle.match(m.group(1))
75 p = re.sub(
"class ",
"",o)
76 dataclass = re.sub(
"struct ",
"",p)
77 dataclasses.add(dataclass)
78 if fields[2] ==
' overrides function ' :
79 if baseclass.search(fields[3]) :
80 G.add_edge(fields[1],fields[3],kind=
' overrides function ')
81 if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
82 else : G.add_edge(fields[3],fields[1], kind=
' calls override function ')
83 if fields[2] ==
' static variable ' :
84 G.add_edge(fields[1],fields[3],kind=
' static variable ')
85 statics.add(fields[3])
90 for n,nbrdict
in G.adjacency_iter():
91 for nbr,eattr
in nbrdict.items():
92 if n
in badfuncs
or nbr
in badfuncs :
93 if 'kind' in eattr
and eattr[
'kind'] ==
' overrides function ' :
94 print "'"+n+
"'"+eattr[
'kind']+
"'"+nbr+
"'"
98 print "-----------------------------------------------"
99 print "flagged functions found by checker"
100 print "-----------------------------------------------"
101 for dfunc
in sorted(badfuncs) :
105 print "-----------------------------------------------"
106 print "flagged classes found by checker "
107 print "-----------------------------------------------"
108 for dclass
in sorted(badclasses) :
112 nodes = sorted(badclasses)
118 if node
in H : stack = [(node,iter(H[node]))]
120 Q=nx.dfs_preorder_nodes(I,node)
123 stack.append( ( q, iter( H[q] ) ) )
125 parent,children = stack[-1]
128 if globalclass.search(child): visited.add(child)
129 if rootclass.search(child): visited.add(child)
130 if child
not in visited:
132 stack.append( ( child, iter( H[child] ) ) )
133 kind=H[parent][child][
'kind']
134 if stdptr.search(kind):
136 Q=nx.dfs_preorder_nodes(I,child)
139 stack.append( ( q, iter( H[q] ) ) )
140 except StopIteration:
142 print "flagged class "+node+
" contains or inherits from classes ",
143 for v
in visited :
print v+
",",
145 for v
in sorted(visited) :
146 if v
in globalclasses:
147 print "EDM global class '"+v+
"' is flagged because it is connected to flagged class '"+node+
"'"