bump product version to 6.4.0.3
[LibreOffice.git] / compilerplugins / clang / unnecessaryvirtual.py
blob187aafcbb2d883e15f99492e2b55d5439b1b49d2
1 #!/usr/bin/python
3 import io
4 import re
5 import sys
7 definitionSet = set()
8 definitionToSourceLocationMap = dict()
9 overridingSet = set()
10 nonEmptySet = set()
13 with io.open("workdir/loplugin.unnecessaryvirtual.log", "rb", buffering=1024*1024) as txt:
14 for line in txt:
15 tokens = line.strip().split("\t")
16 if tokens[0] == "definition:":
17 fullMethodName = tokens[1]
18 sourceLocation = tokens[2]
19 definitionSet.add(fullMethodName)
20 definitionToSourceLocationMap[fullMethodName] = sourceLocation
21 elif tokens[0] == "overriding:":
22 fullMethodName = tokens[1]
23 overridingSet.add(fullMethodName)
24 elif tokens[0] == "nonempty:":
25 fullMethodName = tokens[1]
26 nonEmptySet.add(fullMethodName)
27 else:
28 print( "unknown line: " + line)
30 unnecessaryVirtualSet = set()
32 for clazz in (definitionSet - overridingSet):
33 # windows-specific stuff
34 if clazz.startswith("canvas::"): continue
35 if clazz.startswith("psp::PrinterInfoManager"): continue
36 if clazz.startswith("DdeTopic::"): continue
37 if clazz == "basegfx::unotools::UnoPolyPolygon::void-modifying()const": continue
38 if clazz == "SalLayout::_Bool-IsKashidaPosValid(int,)const": continue
39 if clazz == "SalLayout::void-DisableGlyphInjection(_Bool,)": continue
40 # Linux-TDF specific
41 if clazz == "X11SalFrame::void-updateGraphics(_Bool,)": continue
42 # OSX specific
43 if clazz == "SalFrame::void-SetRepresentedURL(const class rtl::OUString &,)": continue
44 if clazz == "SalMenu::_Bool-AddMenuBarButton(const struct SalMenuButtonItem &,)": continue
45 if clazz == "SalMenu::class Rectangle-GetMenuBarButtonRectPixel(sal_uInt16,class SalFrame *,)": continue
46 if clazz == "SalMenu::void-RemoveMenuBarButton(sal_uInt16,)": continue
47 if clazz == "SalLayout::_Bool-DrawTextSpecial(class SalGraphics &,sal_uInt32,)const": continue
48 # GTK < 3
49 if clazz == "GtkSalDisplay::int-CaptureMouse(class SalFrame *,)": continue
50 # some test magic
51 if clazz.startswith("apitest::"): continue
53 loc = definitionToSourceLocationMap[clazz]
55 # ignore external code
56 if loc.startswith("external/"): continue
57 # there is a bunch of Windows specific code that we don't see
58 if loc.startswith("include/canvas/"): continue
59 # not sure what the problem is here
60 if loc.startswith("include/test/"): continue
62 unnecessaryVirtualSet.add( (clazz,loc) )
65 deadSet = set()
67 for clazz in (definitionSet - nonEmptySet):
69 # ignore destructors
70 if "::~" in clazz: continue
72 loc = definitionToSourceLocationMap[clazz]
74 # ignore external code
75 if loc.startswith("external/"): continue
77 deadSet.add( (clazz,loc) )
80 # sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
81 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
82 return [int(text) if text.isdigit() else text.lower()
83 for text in re.split(_nsre, s)]
85 # sort results by name and line number
86 tmp1list = sorted(unnecessaryVirtualSet, key=lambda v: natural_sort_key(v[1]))
87 tmp2list = sorted(deadSet, key=lambda v: natural_sort_key(v[1]))
89 with open("compilerplugins/clang/unnecessaryvirtual.results", "wt") as f:
90 for t in tmp1list:
91 f.write( t[1] + "\n" )
92 f.write( " " + t[0] + "\n" )
93 # add an empty line at the end to make it easier for the removevirtuals plugin to mmap() the output file
94 f.write("\n")
96 with open("compilerplugins/clang/unnecessaryvirtual-dead.results", "wt") as f:
97 for t in tmp2list:
98 f.write( t[1] + "\n" )
99 f.write( " " + t[0] + "\n" )