CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
class-composition.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 import re
3 stdcl = re.compile("^std::(.*)[^>]$")
4 stdptr = re.compile("(.*)_ptr$")
5 datacl = re.compile("^class ")
6 bfunc = re.compile("^function ")
7 mbcl = re.compile("(base|data) class")
8 farg = re.compile("(.*)\(\w+\)")
9 nsep = re.compile("\:\:")
10 topfunc = re.compile("::(produce|analyze|filter|beginLuminosityBlock|beginRun|beginStream)\(")
11 baseclass = re.compile("edm::(one::|stream::|global::)?ED(Producer|Filter|Analyzer)(Base)?")
12 getfunc = re.compile("edm::eventsetup::EventSetupRecord::get<.*>\((.*)&\) const")
13 handle = re.compile("(.*),?class edm::ES(.*)Handle<(.*)>")
14 statics = set()
15 toplevelfuncs = set()
16 onefuncs = set()
17 dataclassfuncs = set()
18 virtfuncs = set()
19 virtclasses = set()
20 badfuncs = set()
21 badclasses = set()
22 esdclasses = set()
23 dataclasses = set()
24 flaggedclasses = set()
25 memberclasses = set()
26 derivedclasses = set()
27 
28 import networkx as nx
29 G=nx.DiGraph()
30 H=nx.DiGraph()
31 I=nx.DiGraph()
32 
33 
34 f = open('classes.txt.dumperall')
35 for line in f :
36  if mbcl.search(line) :
37  fields = line.split("'")
38  if fields[2] == ' member data class ':
39  if not stdcl.search(fields[2]) : H.add_edge(fields[1],fields[3],kind=fields[2])
40  if fields[2] == ' templated member data class ':
41  H.add_edge(fields[1],fields[5],kind=fields[3])
42  if fields[2] == ' base class ':
43  H.add_edge(fields[1],fields[3],kind=fields[2])
44  I.add_edge(fields[3],fields[1],kind=' derived class')
45 f.close()
46 
47 f = open('function-calls-db.txt')
48 
49 for line in f :
50  if not bfunc.search(line) : continue
51  fields = line.split("'")
52  if fields[2] == ' calls function ' :
53  G.add_edge(fields[1],fields[3],kind=' calls function ')
54  if getfunc.search(fields[3]) :
55  dataclassfuncs.add(fields[3])
56  m = getfunc.match(fields[3])
57  n = handle.match(m.group(1))
58  if n : o = n.group(3)
59  else : o = m.group(1)
60  p = re.sub("class ","",o)
61  dataclass = re.sub("struct ","",p)
62  dataclasses.add(dataclass)
63  if fields[2] == ' overrides function ' :
64  if baseclass.search(fields[3]) :
65  G.add_edge(fields[1],fields[3],kind=' overrides function ')
66  if topfunc.search(fields[3]) : toplevelfuncs.add(fields[1])
67  else : G.add_edge(fields[3],fields[1], kind=' calls override function ')
68  if fields[2] == ' static variable ' :
69  G.add_edge(fields[1],fields[3],kind=' static variable ')
70  statics.add(fields[3])
71 f.close()
72 
73 visited = set()
74 nodes = sorted(dataclasses)
75 for node in nodes:
76  if node in visited:
77  continue
78  visited.add(node)
79  if node in H : stack = [(node,iter(H[node]))]
80  if node in I :
81  Q=nx.dfs_preorder_nodes(I,node)
82  for q in Q:
83  print "class '"+q+"'"
84  if q in H :
85  stack.append( ( q, iter( H[q] ) ) )
86  while stack:
87  parent,children = stack[-1]
88  print "class '"+parent+"'"
89  try:
90  child = next(children)
91  if child not in visited:
92  visited.add(child)
93  if not stdcl.search(child):
94  print "class '"+child+"'"
95  stack.append( ( child, iter( H[child] ) ) )
96  kind=H[parent][child]['kind']
97  print parent, kind, child
98  if stdptr.search(kind):
99  if child in I :
100  Q=nx.dfs_preorder_nodes(I,child)
101  for q in Q :
102  print "class '"+q+"'"
103  if q in H :
104  stack.append( ( q, iter( H[q] ) ) )
105  except StopIteration:
106  stack.pop()