Update git submodules
[LibreOffice.git] / compilerplugins / clang / finalclasses.py
blob55b3d1c5acb170beae24573a31edeb0e5751dd7e
1 #!/usr/bin/python3
3 import re
5 definitionSet = set()
6 inheritFromSet = set()
7 definitionToFileDict = {}
9 with open("workdir/loplugin.finalclasses.log") as txt:
10 for line in txt:
11 tokens = line.strip().split("\t")
13 if len(tokens) == 1:
14 pass
16 elif tokens[0] == "definition:":
17 clazzName = tokens[1]
18 # the 1.. is so we skip the leading /
19 fileName = tokens[2][1:]
20 definitionSet.add(clazzName)
21 definitionToFileDict[clazzName] = fileName
23 elif tokens[0] == "inherited-from:":
24 parent = tokens[1]
25 if (parent.startswith("class ")):
26 parent = parent[6:]
27 elif (parent.startswith("struct ")):
28 parent = parent[7:]
29 inheritFromSet.add(parent)
31 else:
32 print( "unknown line: " + line)
34 match_module_inc1 = re.compile(r'^\w+/inc/')
35 match_module_inc2 = re.compile(r'^\w+/.*/inc/')
36 tmpset = set()
37 for clazz in sorted(definitionSet - inheritFromSet):
38 file = definitionToFileDict[clazz]
39 # ignore classes defined inside compilation units, the compiler knows they are final already
40 if (".cxx" in file): continue
41 # ignore test and external code
42 if ("/qa/" in file): continue
43 if (file.startswith("workdir/")): continue
44 # We are only really interested in classes that are shared between linkage units, where the compiler
45 # is not able to figure out for itself that classes are final.
46 if not(file.startswith("include/") or match_module_inc1.match(file) or match_module_inc2.match(file)): continue
47 #if not(file.endswith(".hxx")): continue
48 # Exclude URE
49 if file.startswith("include/com/"): continue
50 if file.startswith("include/cppu/"): continue
51 if file.startswith("include/cppuhelper/"): continue
52 if file.startswith("include/osl/"): continue
53 if file.startswith("include/rtl/"): continue
54 if file.startswith("include/sal/"): continue
55 if file.startswith("include/salhelper/"): continue
56 if file.startswith("include/typelib/"): continue
57 if file.startswith("include/uno/"): continue
58 # some kind of template noise
59 if file.startswith("include/unotest/"): continue
60 # no point optimising test code
61 if file.startswith("include/test/"): continue
62 tmpset.add((clazz, file))
64 # sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
65 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
66 return [int(text) if text.isdigit() else text.lower()
67 for text in re.split(_nsre, s)]
68 # sort by both the source-line and the datatype, so the output file ordering is stable
69 # when we have multiple items on the same source line
70 def v_sort_key(v):
71 return natural_sort_key(v[1]) + [v[0]]
72 def sort_set_by_natural_key(s):
73 return sorted(s, key=lambda v: v_sort_key(v))
75 # print output, sorted by name and line number
76 with open("compilerplugins/clang/finalclasses.results", "wt") as f:
77 for t in sort_set_by_natural_key(tmpset):
78 f.write(t[1] + "\n")
79 f.write(" " + t[0] + "\n")