File indexing completed on 2024-12-01 23:40:44
0001
0002 import fileinput
0003 import networkx as nx
0004 import re
0005 datacl = re.compile("^class ")
0006 bfunc = re.compile("^function ")
0007 mbcl = re.compile("(base|data|flagged) class")
0008 farg = re.compile(r"(.*)\(\w+\)")
0009 nsep = re.compile(r"\:\:")
0010 topfunc = re.compile(
0011 r"::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream)\(")
0012 baseclass = re.compile(
0013 r"edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
0014 globalclass = re.compile("^edm::global::ED(Producer|Filter|Analyzer)$")
0015 getfunc = re.compile(
0016 r"edm::eventsetup::EventSetupRecord::get\<.*\>\((.*)&\) const")
0017 handle = re.compile("(.*),?class edm::ES(.*)Handle<(.*)>")
0018 skip = re.compile(
0019 r"edm::serviceregistry::ServicesManager::MakerHolder::add() const")
0020 rootclass = re.compile("T(H1|Tree|Enum|DataType|Class|Branch|Named|File)")
0021 stdcl = re.compile("^std::(.*)[^>]$")
0022 stdptr = re.compile("(.*)_ptr$")
0023 statics = set()
0024 toplevelfuncs = set()
0025 onefuncs = set()
0026 dataclassfuncs = set()
0027 virtfuncs = set()
0028 virtclasses = set()
0029 badfuncs = set()
0030 badclasses = set()
0031 esdclasses = set()
0032 dclasses = set()
0033 dataclasses = set()
0034 flaggedclasses = set()
0035 globalclasses = set()
0036 Gdg = nx.DiGraph()
0037 Hdg = nx.DiGraph()
0038 Idg = nx.DiGraph()
0039
0040 f = open('class-checker.txt')
0041 for line in f:
0042 if mbcl.search(line):
0043 fields = line.split("'")
0044 classname = fields[1]
0045 funcname = fields[3]
0046 badclasses.add(classname)
0047 badfuncs.add(funcname)
0048 f.close()
0049
0050 f = open('const-checker.txt')
0051 for line in f:
0052 if mbcl.search(line):
0053 fields = line.split("'")
0054 classname = fields[1]
0055 badclasses.add(classname)
0056 f.close()
0057
0058
0059 f = open('classes.txt.dumperall')
0060 for line in f:
0061 if mbcl.search(line):
0062 fields = line.split("'")
0063 if fields[2] == ' member data class ':
0064 Hdg.add_edge(fields[1], fields[3], kind=fields[2])
0065 if fields[2] == ' templated member data class ':
0066 Hdg.add_edge(fields[1], fields[3], kind=fields[2])
0067 if fields[2] == ' base class ':
0068 Hdg.add_edge(fields[1], fields[3], kind=fields[2])
0069 Idg.add_edge(fields[3], fields[1], kind=' derived class')
0070 if globalclass.match(fields[3]):
0071 globalclasses.add(fields[1])
0072 print("class '"+fields[1]+"' base class '"+fields[3]+"'")
0073 f.close()
0074
0075 for line in fileinput.input(files=('function-statics-db.txt', 'function-calls-db.txt')):
0076 if not bfunc.search(line):
0077 continue
0078 fields = line.split("'")
0079 if skip.search(fields[1]) or skip.search(fields[3]):
0080 continue
0081 if fields[2] == ' calls function ':
0082 Gdg.add_edge(fields[1], fields[3], kind=' calls function ')
0083 if getfunc.search(fields[3]):
0084 dataclassfuncs.add(fields[3])
0085 m = getfunc.match(fields[3])
0086 n = handle.match(m.group(1))
0087 if n:
0088 o = n.group(3)
0089 else:
0090 o = m.group(1)
0091 p = re.sub("class ", "", o)
0092 dataclass = re.sub("struct ", "", p)
0093 dataclasses.add(dataclass)
0094 if fields[2] == ' overrides function ':
0095 if baseclass.search(fields[3]):
0096 Gdg.add_edge(fields[1], fields[3], kind=' overrides function ')
0097 if topfunc.search(fields[3]):
0098 toplevelfuncs.add(fields[1])
0099 else:
0100 Gdg.add_edge(fields[3], fields[1], kind=' calls override function ')
0101 if fields[2] == ' static variable ':
0102 Gdg.add_edge(fields[1], fields[3], kind=' static variable ')
0103 statics.add(fields[3])
0104 fileinput.close()
0105
0106
0107 for n, nbrdict in Gdg.adjacency():
0108 for nbr, eattr in nbrdict.items():
0109 if n in badfuncs or nbr in badfuncs:
0110 if 'kind' in eattr and eattr['kind'] == ' overrides function ':
0111 print("'"+n+"'"+eattr['kind']+"'"+nbr+"'")
0112 virtfuncs.add(nbr)
0113 print()
0114
0115 print("-----------------------------------------------")
0116 print("flagged functions found by checker")
0117 print("-----------------------------------------------")
0118 for dfunc in sorted(badfuncs):
0119 print(dfunc)
0120 print()
0121
0122 print("-----------------------------------------------")
0123 print("flagged classes found by checker ")
0124 print("-----------------------------------------------")
0125 for dclass in sorted(badclasses):
0126 print(dclass)
0127 print()
0128
0129 nodes = sorted(badclasses)
0130 for node in nodes:
0131 visited = set()
0132 if node in visited:
0133 continue
0134 visited.add(node)
0135 if node in Hdg:
0136 stack = [(node, iter(Hdg[node]))]
0137 else:
0138 stack = []
0139 if node in Idg:
0140 Qdg = nx.dfs_preorder_nodes(Idg, node)
0141 for q in Qdg:
0142 if q in Hdg:
0143 stack.append((q, iter(Hdg[q])))
0144 while stack:
0145 parent, children = stack[-1]
0146 try:
0147 child = next(children)
0148 if globalclass.search(child):
0149 visited.add(child)
0150 if rootclass.search(child):
0151 visited.add(child)
0152 if child not in visited:
0153 visited.add(child)
0154 stack.append((child, iter(Hdg[child])))
0155 kind = Hdg[parent][child]['kind']
0156 if stdptr.search(kind):
0157 if child in Idg:
0158 Qdg = nx.dfs_preorder_nodes(Idg, child)
0159 for q in Qdg:
0160 if q in Hdg:
0161 stack.append((q, iter(Hdg[q])))
0162 except StopIteration:
0163 stack.pop()
0164 print("flagged class " + node + " contains or inherits from classes ", end=' ')
0165 for v in visited:
0166 print(v + ",", end=' ')
0167 print("\n\n")
0168 for v in sorted(visited):
0169 if v in globalclasses:
0170 print("EDM global class '" + v +
0171 "' is flagged because it is connected to flagged class '" + node + "'")