CMS 3D CMS Logo

edm-global-class.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 from __future__ import print_function
3 import re
4 datacl = re.compile("^class ")
5 bfunc = re.compile("^function ")
6 mbcl = re.compile("(base|data|flagged) class")
7 farg = re.compile("(.*)\(\w+\)")
8 nsep = re.compile("\:\:")
9 topfunc = re.compile("::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream)\(")
10 baseclass = re.compile("edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
11 globalclass = re.compile("^edm::global::ED(Producer|Filter|Analyzer)$")
12 getfunc = re.compile("edm::eventsetup::EventSetupRecord::get<.*>\((.*)&\) const")
13 handle = re.compile("(.*),?class edm::ES(.*)Handle<(.*)>")
14 skip = re.compile("edm::serviceregistry::ServicesManager::MakerHolder::add() const")
15 rootclass = re.compile("T(H1|Tree|Enum|DataType|Class|Branch|Named|File)")
16 stdcl = re.compile("^std::(.*)[^>]$")
17 stdptr = re.compile("(.*)_ptr$")
18 statics = set()
19 toplevelfuncs = set()
20 onefuncs = set()
21 dataclassfuncs = set()
22 virtfuncs = set()
23 virtclasses = set()
24 badfuncs = set()
25 badclasses = set()
26 esdclasses = set()
27 dclasses = set()
28 dataclasses = set()
29 flaggedclasses = set()
30 globalclasses = set()
31 import networkx as nx
32 G=nx.DiGraph()
33 H=nx.DiGraph()
34 I=nx.DiGraph()
35 
36 f = open('class-checker.txt')
37 for line in f:
38  if mbcl.search(line):
39  fields = line.split("'")
40  classname = fields[1]
41  funcname = fields[3]
42  badclasses.add(classname)
43  badfuncs.add(funcname)
44 f.close()
45 
46 f = open('const-checker.txt')
47 for line in f:
48  if mbcl.search(line):
49  fields = line.split("'")
50  classname = fields[1]
51  badclasses.add(classname)
52 f.close()
53 
54 
55 f = open('classes.txt.dumperall')
56 for line in f :
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])
65  I.add_edge(fields[3],fields[1],kind=' derived class')
66  if globalclass.match(fields[3]):
67  globalclasses.add(fields[1])
68  print("class '"+fields[1]+"' base class '"+fields[3]+"'")
69 f.close()
70 
71 import fileinput
72 for line in fileinput.input(files =('function-statics-db.txt','function-calls-db.txt')):
73  if not bfunc.search(line) : continue
74  fields = line.split("'")
75  if skip.search(fields[1]) or skip.search(fields[3]) : continue
76  if fields[2] == ' calls function ' :
77  G.add_edge(fields[1],fields[3],kind=' calls function ')
78  if getfunc.search(fields[3]) :
79  dataclassfuncs.add(fields[3])
80  m = getfunc.match(fields[3])
81  n = handle.match(m.group(1))
82  if n : o = n.group(3)
83  else : o = m.group(1)
84  p = re.sub("class ","",o)
85  dataclass = re.sub("struct ","",p)
86  dataclasses.add(dataclass)
87  if fields[2] == ' overrides function ' :
88  if baseclass.search(fields[3]) :
89  G.add_edge(fields[1],fields[3],kind=' overrides function ')
90  if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
91  else : G.add_edge(fields[3],fields[1], kind=' calls override function ')
92  if fields[2] == ' static variable ' :
93  G.add_edge(fields[1],fields[3],kind=' static variable ')
94  statics.add(fields[3])
95 fileinput.close()
96 
97 
98 
99 for n,nbrdict in G.adjacency_iter():
100  for nbr,eattr in nbrdict.items():
101  if n in badfuncs or nbr in badfuncs :
102  if 'kind' in eattr and eattr['kind'] == ' overrides function ' :
103  print("'"+n+"'"+eattr['kind']+"'"+nbr+"'")
104  virtfuncs.add(nbr)
105 print()
106 
107 print("-----------------------------------------------")
108 print("flagged functions found by checker")
109 print("-----------------------------------------------")
110 for dfunc in sorted(badfuncs) :
111  print(dfunc)
112 print()
113 
114 print("-----------------------------------------------")
115 print("flagged classes found by checker ")
116 print("-----------------------------------------------")
117 for dclass in sorted(badclasses) :
118  print(dclass)
119 print()
120 
121 nodes = sorted(badclasses)
122 for node in nodes:
123  visited = set()
124  if node in visited:
125  continue
126  visited.add(node)
127  if node in H : stack = [(node,iter(H[node]))]
128  if node in I :
129  Q=nx.dfs_preorder_nodes(I,node)
130  for q in Q:
131  if q in H :
132  stack.append( ( q, iter( H[q] ) ) )
133  while stack:
134  parent,children = stack[-1]
135  try:
136  child = next(children)
137  if globalclass.search(child): visited.add(child)
138  if rootclass.search(child): visited.add(child)
139  if child not in visited:
140  visited.add(child)
141  stack.append( ( child, iter( H[child] ) ) )
142  kind=H[parent][child]['kind']
143  if stdptr.search(kind):
144  if child in I :
145  Q=nx.dfs_preorder_nodes(I,child)
146  for q in Q :
147  if q in H :
148  stack.append( ( q, iter( H[q] ) ) )
149  except StopIteration:
150  stack.pop()
151  print("flagged class "+node+" contains or inherits from classes ", end=' ')
152  for v in visited : print(v+",", end=' ')
153  print("\n\n")
154  for v in sorted(visited) :
155  if v in globalclasses:
156  print("EDM global class '"+v+"' is flagged because it is connected to flagged class '"+node+"'")
157 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66