tdf#161878 Ignore nested SYMBOL field inside IF field
[LibreOffice.git] / compilerplugins / clang / virtualdown.py
blob29a8f24037b9d86dfb4a64405084aa902a46f8f2
1 #!/usr/bin/python
3 import io
4 import re
6 definitionSet = set()
7 definitionToSourceLocationMap = dict()
8 callSet = set()
11 with io.open("workdir/loplugin.virtualdown.log", "rb", buffering=1024*1024) as txt:
12 for line in txt:
13 tokens = line.strip().split("\t")
14 if tokens[0] == "definition:":
15 fullMethodName = tokens[1]
16 sourceLocation = tokens[2]
17 definitionSet.add(fullMethodName)
18 definitionToSourceLocationMap[fullMethodName] = sourceLocation
19 elif tokens[0] == "call:":
20 fullMethodName = tokens[1]
21 callSet.add(fullMethodName)
22 else:
23 print( "unknown line: " + line)
25 unnecessaryVirtualSet = set()
27 for clazz in (definitionSet - callSet):
28 # if clazz.startswith("canvas::"): continue
29 # if clazz == "basegfx::unotools::UnoPolyPolygon::void-modifying()const": continue
30 # ignore external code
31 if definitionToSourceLocationMap[clazz].startswith("external/"):
32 continue
34 unnecessaryVirtualSet.add((clazz,definitionToSourceLocationMap[clazz] ))
37 # sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
38 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
39 return [int(text) if text.isdigit() else text.lower()
40 for text in re.split(_nsre, s)]
41 # sort by both the source-line and the datatype, so the output file ordering is stable
42 # when we have multiple items on the same source line
43 def v_sort_key(v):
44 return natural_sort_key(v[1]) + [v[0]]
46 # sort results by name and line number
47 tmp1list = sorted(unnecessaryVirtualSet, key=lambda v: v_sort_key(v))
49 with open("compilerplugins/clang/virtualdown.results", "wt") as f:
50 for t in tmp1list:
51 f.write( t[1] + "\n" )
52 f.write( " " + t[0] + "\n" )
53 # add an empty line at the end to make it easier for the removevirtuals plugin to mmap() the output file
54 f.write("\n")