3 datacl = re.compile(
"^class ")
4 bfunc = re.compile(
"^function ")
5 mbcl = re.compile(
"(base|data|flagged) 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)
45 f = open(
'const-checker.txt')
48 fields = line.split(
"'")
50 badclasses.add(classname)
54 f = open(
'classes.txt.dumperall')
56 if mbcl.search(line) :
57 fields = line.split(
"'")
58 if fields[2] ==
' member data class ':
59 H.add_edge(fields[1],fields[3],kind=fields[2])
60 if fields[2] ==
' templated member data class ':
61 H.add_edge(fields[1],fields[3],kind=fields[2])
62 if fields[2] ==
' base class ':
63 H.add_edge(fields[1],fields[3],kind=fields[2])
64 I.add_edge(fields[3],fields[1],kind=
' derived class')
65 if globalclass.match(fields[3]):
66 globalclasses.add(fields[1])
67 print "class '"+fields[1]+
"' base class '"+fields[3]+
"'" 71 for line
in fileinput.input(files =(
'function-statics-db.txt',
'function-calls-db.txt')):
72 if not bfunc.search(line) :
continue 73 fields = line.split(
"'")
74 if skip.search(fields[1])
or skip.search(fields[3]) :
continue 75 if fields[2] ==
' calls function ' :
76 G.add_edge(fields[1],fields[3],kind=
' calls function ')
77 if getfunc.search(fields[3]) :
78 dataclassfuncs.add(fields[3])
79 m = getfunc.match(fields[3])
80 n = handle.match(m.group(1))
83 p = re.sub(
"class ",
"",o)
84 dataclass = re.sub(
"struct ",
"",p)
85 dataclasses.add(dataclass)
86 if fields[2] ==
' overrides function ' :
87 if baseclass.search(fields[3]) :
88 G.add_edge(fields[1],fields[3],kind=
' overrides function ')
89 if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
90 else : G.add_edge(fields[3],fields[1], kind=
' calls override function ')
91 if fields[2] ==
' static variable ' :
92 G.add_edge(fields[1],fields[3],kind=
' static variable ')
93 statics.add(fields[3])
98 for n,nbrdict
in G.adjacency_iter():
99 for nbr,eattr
in nbrdict.items():
100 if n
in badfuncs
or nbr
in badfuncs :
101 if 'kind' in eattr
and eattr[
'kind'] ==
' overrides function ' :
102 print "'"+n+
"'"+eattr[
'kind']+
"'"+nbr+
"'" 106 print "-----------------------------------------------" 107 print "flagged functions found by checker" 108 print "-----------------------------------------------" 109 for dfunc
in sorted(badfuncs) :
113 print "-----------------------------------------------" 114 print "flagged classes found by checker " 115 print "-----------------------------------------------" 116 for dclass
in sorted(badclasses) :
120 nodes = sorted(badclasses)
126 if node
in H : stack = [(node,iter(H[node]))]
128 Q=nx.dfs_preorder_nodes(I,node)
131 stack.append( ( q, iter( H[q] ) ) )
133 parent,children = stack[-1]
136 if globalclass.search(child): visited.add(child)
137 if rootclass.search(child): visited.add(child)
138 if child
not in visited:
140 stack.append( ( child, iter( H[child] ) ) )
141 kind=H[parent][child][
'kind']
142 if stdptr.search(kind):
144 Q=nx.dfs_preorder_nodes(I,child)
147 stack.append( ( q, iter( H[q] ) ) )
148 except StopIteration:
150 print "flagged class "+node+
" contains or inherits from classes ",
151 for v
in visited :
print v+
",",
153 for v
in sorted(visited) :
154 if v
in globalclasses:
155 print "EDM global class '"+v+
"' is flagged because it is connected to flagged class '"+node+
"'"