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