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 networkx as nx
0004 import re
0005 stdcl = re.compile("^std::(.*)[^>]$")
0006 stdptr = re.compile("(.*)_ptr$")
0007 datacl = re.compile("^class ")
0008 bfunc = re.compile("^function ")
0009 mbcl = re.compile("(base|data) class")
0010 farg = re.compile(r"(.*)\(\w+\)")
0011 nsep = re.compile(r"\:\:")
0012 topfunc = re.compile(
0013     r"::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream)\(")
0014 baseclass = re.compile(
0015     "edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
0016 getfunc = re.compile(
0017     r"edm::eventsetup::EventSetupRecord::get\<.*\>\((.*)&\) const")
0018 handle = re.compile("(.*),?class edm::ES(.*)Handle<(.*)>")
0019 statics = set()
0020 toplevelfuncs = set()
0021 onefuncs = set()
0022 dataclassfuncs = set()
0023 virtfuncs = set()
0024 virtclasses = set()
0025 badfuncs = set()
0026 badclasses = set()
0027 esdclasses = set()
0028 dataclasses = set()
0029 flaggedclasses = set()
0030 memberclasses = set()
0031 derivedclasses = set()
0032 
0033 Gdg = nx.DiGraph()
0034 Hdg = nx.DiGraph()
0035 Idg = nx.DiGraph()
0036 
0037 
0038 f = open('classes.txt.dumperall')
0039 for line in f:
0040     if mbcl.search(line):
0041         fields = line.split("'")
0042         if fields[2] == ' member data class ':
0043             if not stdcl.search(fields[2]):
0044                 Hdg.add_edge(fields[1], fields[3], kind=fields[2])
0045         if fields[2] == ' templated member data class ':
0046             Hdg.add_edge(fields[1], fields[5], kind=fields[3])
0047         if fields[2] == ' base class ':
0048             Hdg.add_edge(fields[1], fields[3], kind=fields[2])
0049             Idg.add_edge(fields[3], fields[1], kind=' derived class')
0050 f.close()
0051 
0052 f = open('function-calls-db.txt')
0053 
0054 for line in f:
0055     if not bfunc.search(line):
0056         continue
0057     fields = line.split("'")
0058     if fields[2] == ' calls function ':
0059         Gdg.add_edge(fields[1], fields[3], kind=' calls function ')
0060         if getfunc.search(fields[3]):
0061             dataclassfuncs.add(fields[3])
0062             m = getfunc.match(fields[3])
0063             n = handle.match(m.group(1))
0064             if n:
0065                 o = n.group(3)
0066             else:
0067                 o = m.group(1)
0068             p = re.sub("class ", "", o)
0069             dataclass = re.sub("struct ", "", p)
0070             dataclasses.add(dataclass)
0071     if fields[2] == ' overrides function ':
0072         if baseclass.search(fields[3]):
0073             Gdg.add_edge(fields[1], fields[3], kind=' overrides function ')
0074             if topfunc.search(fields[3]):
0075                 toplevelfuncs.add(fields[1])
0076         else:
0077             Gdg.add_edge(fields[3], fields[1], kind=' calls override function ')
0078     if fields[2] == ' static variable ':
0079         Gdg.add_edge(fields[1], fields[3], kind=' static variable ')
0080         statics.add(fields[3])
0081 f.close()
0082 
0083 visited = set()
0084 nodes = sorted(dataclasses)
0085 for node in nodes:
0086     if node in visited:
0087         continue
0088     visited.add(node)
0089     if node in Hdg:
0090         stack = [(node, iter(Hdg[node]))]
0091     if node in Idg:
0092         Qdg = nx.dfs_preorder_nodes(Idg, node)
0093         for q in Qdg:
0094             print("class '"+q+"'")
0095             if q in Hdg:
0096                 stack.append((q, iter(Hdg[q])))
0097     while stack:
0098         parent, children = stack[-1]
0099         print("class '"+parent+"'")
0100         try:
0101             child = next(children)
0102             if child not in visited:
0103                 visited.add(child)
0104                 if not stdcl.search(child):
0105                     print("class '"+child+"'")
0106                     stack.append((child, iter(Hdg[child])))
0107                     kind = Hdg[parent][child]['kind']
0108                     print(parent, kind, child)
0109                     if stdptr.search(kind):
0110                         if child in Idg:
0111                             Qdg = nx.dfs_preorder_nodes(Idg, child)
0112                             for q in Qdg:
0113                                 print("class '"+q+"'")
0114                                 if q in Hdg:
0115                                     stack.append((q, iter(Hdg[q])))
0116         except StopIteration:
0117             stack.pop()