8 definitionToSourceLocationMap
= dict()
13 with io
.open("workdir/loplugin.unnecessaryvirtual.log", "rb", buffering
=1024*1024) as 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
)
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
41 if clazz
== "X11SalFrame::void-updateGraphics(_Bool,)": continue
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
49 if clazz
== "GtkSalDisplay::int-CaptureMouse(class SalFrame *,)": continue
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
) )
67 for clazz
in (definitionSet
- nonEmptySet
):
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
:
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
96 with
open("compilerplugins/clang/unnecessaryvirtual-dead.results", "wt") as f
:
98 f
.write( t
[1] + "\n" )
99 f
.write( " " + t
[0] + "\n" )