7 definitionToFileDict
= {}
9 with
open("workdir/loplugin.finalclasses.log") as txt
:
11 tokens
= line
.strip().split("\t")
16 elif tokens
[0] == "definition:":
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:":
25 if (parent
.startswith("class ")):
27 elif (parent
.startswith("struct ")):
29 inheritFromSet
.add(parent
)
32 print( "unknown line: " + line
)
34 match_module_inc1
= re
.compile(r
'^\w+/inc/')
35 match_module_inc2
= re
.compile(r
'^\w+/.*/inc/')
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
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
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
):
79 f
.write(" " + t
[0] + "\n")