Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-29 02:32:58

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