CMS 3D CMS Logo

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