Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / compilerplugins / clang / finalclasses.py
blobd2d4f695b8a1b2947641cf5a658bf3af8e6682dd
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 tmpset = set()
33 for clazz in sorted(definitionSet - inheritFromSet):
34 file = definitionToFileDict[clazz]
35 # ignore classes defined inside compilation units, the compiler knows they are final already
36 if (".cxx" in file): continue
37 # ignore test and external code
38 if ("/qa/" in file): continue
39 if (file.startswith("workdir/")): continue
40 tmpset.add((clazz, file))
42 # sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
43 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
44 return [int(text) if text.isdigit() else text.lower()
45 for text in re.split(_nsre, s)]
46 def sort_set_by_natural_key(s):
47 return sorted(s, key=lambda v: natural_sort_key(v[1]))
49 # print output, sorted by name and line number
50 with open("compilerplugins/clang/finalclasses.results", "wt") as f:
51 for t in sort_set_by_natural_key(tmpset):
52 f.write(t[1] + "\n")
53 f.write(" " + t[0] + "\n")