test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
edm-global-class.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 import re
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$")
17 statics = set()
18 toplevelfuncs = set()
19 onefuncs = set()
20 dataclassfuncs = set()
21 virtfuncs = set()
22 virtclasses = set()
23 badfuncs = set()
24 badclasses = set()
25 esdclasses = set()
26 dclasses = set()
27 dataclasses = set()
28 flaggedclasses = set()
29 globalclasses = set()
30 import networkx as nx
31 G=nx.DiGraph()
32 H=nx.DiGraph()
33 I=nx.DiGraph()
34 
35 f = open('class-checker.txt')
36 for line in f:
37  if mbcl.search(line):
38  fields = line.split("'")
39  classname = fields[1]
40  funcname = fields[3]
41  badclasses.add(classname)
42  badfuncs.add(funcname)
43 f.close()
44 
45 
46 f = open('classes.txt.dumperall')
47 for line in f :
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]+"'"
60 f.close()
61 
62 import fileinput
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))
73  if n : o = n.group(3)
74  else : o = 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])
86 fileinput.close()
87 
88 
89 
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+"'"
95  virtfuncs.add(nbr)
96 print
97 
98 print "-----------------------------------------------"
99 print "flagged functions found by checker"
100 print "-----------------------------------------------"
101 for dfunc in sorted(badfuncs) :
102  print dfunc
103 print
104 
105 print "-----------------------------------------------"
106 print "flagged classes found by checker "
107 print "-----------------------------------------------"
108 for dclass in sorted(badclasses) :
109  print dclass
110 print
111 
112 nodes = sorted(badclasses)
113 for node in nodes:
114  visited = set()
115  if node in visited:
116  continue
117  visited.add(node)
118  if node in H : stack = [(node,iter(H[node]))]
119  if node in I :
120  Q=nx.dfs_preorder_nodes(I,node)
121  for q in Q:
122  if q in H :
123  stack.append( ( q, iter( H[q] ) ) )
124  while stack:
125  parent,children = stack[-1]
126  try:
127  child = next(children)
128  if globalclass.search(child): visited.add(child)
129  if rootclass.search(child): visited.add(child)
130  if child not in visited:
131  visited.add(child)
132  stack.append( ( child, iter( H[child] ) ) )
133  kind=H[parent][child]['kind']
134  if stdptr.search(kind):
135  if child in I :
136  Q=nx.dfs_preorder_nodes(I,child)
137  for q in Q :
138  if q in H :
139  stack.append( ( q, iter( H[q] ) ) )
140  except StopIteration:
141  stack.pop()
142  print "flagged class "+node+" contains or inherits from classes ",
143  for v in visited : print v+",",
144  print "\n\n"
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+"'"
148