File: finalmethods.py

package info (click to toggle)
libreoffice 4%3A25.8.3~rc1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,818,980 kB
  • sloc: cpp: 4,379,645; xml: 498,929; java: 257,215; python: 80,901; ansic: 33,824; perl: 30,304; javascript: 18,239; sh: 11,717; makefile: 10,624; cs: 8,865; yacc: 8,549; objc: 2,131; lex: 1,379; asm: 1,231; awk: 996; pascal: 914; csh: 20; sed: 5
file content (85 lines) | stat: -rwxr-xr-x 2,824 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python3

import re

definitionSet = set()
overriddenSet = set()
definitionToFileDict = {}

with open("workdir/loplugin.finalmethods.log") as txt:
    for line in txt:
        tokens = line.strip().split("\t")

        if len(tokens) == 1:
            pass

        elif tokens[0] == "definition:":
            methodName = tokens[1]
            fileName  = tokens[2]
            definitionSet.add(methodName)
            definitionToFileDict[methodName] = fileName

        elif tokens[0] == "overridden:":
            methodName = tokens[1]
            overriddenSet.add(methodName)

        else:
            print( "unknown line: " + line)

match_module_inc1 = re.compile(r'^\w+/inc/')
match_module_inc2 = re.compile(r'^\w+/.*/inc/')
tmpset = set()
for method in sorted(definitionSet - overriddenSet):
    file = definitionToFileDict[method]
    # ignore classes defined inside compilation units, the compiler knows they are final already
    if (".cxx" in file):
        continue
    # ignore test and external code
    if ("/qa/" in file):
        continue
    if (file.startswith("workdir/")):
        continue
    # We are only really interested in classes that are shared between linkage units, where the compiler
    # is not able to figure out for itself that classes are final.
    if not(file.startswith("include/") or match_module_inc1.match(file) or match_module_inc2.match(file)):
        continue
    #if not(file.endswith(".hxx")):
        continue
    # Exclude URE
    if file.startswith("include/com/"):
        continue
    if file.startswith("include/cppu/"):
        continue
    if file.startswith("include/cppuhelper/"):
        continue
    if file.startswith("include/osl/"):
        continue
    if file.startswith("include/rtl/"):
        continue
    if file.startswith("include/sal/"):
        continue
    if file.startswith("include/salhelper/"):
        continue
    if file.startswith("include/typelib/"):
        continue
    if file.startswith("include/uno/"):
        continue
    tmpset.add((method, file))

# sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
    return [int(text) if text.isdigit() else text.lower()
            for text in re.split(_nsre, s)]
# sort by both the source-line and the datatype, so the output file ordering is stable
# when we have multiple items on the same source line
def v_sort_key(v):
    return natural_sort_key(v[1]) + [v[0]]
def sort_set_by_natural_key(s):
    return sorted(s, key=lambda v: v_sort_key(v))

# print output, sorted by name and line number
with open("compilerplugins/clang/finalmethods.results", "wt") as f:
    for t in sort_set_by_natural_key(tmpset):
        f.write(t[1] + "\n")
        f.write("    " + t[0] + "\n")