Remove exec bits from docx
[LibreOffice.git] / compilerplugins / clang / virtualdown.py
blobf71ec576adb438ccaf60edf3868957aa65c81811
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/"): continue
33 unnecessaryVirtualSet.add((clazz,definitionToSourceLocationMap[clazz] ))
36 # sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
37 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
38 return [int(text) if text.isdigit() else text.lower()
39 for text in re.split(_nsre, s)]
40 # sort by both the source-line and the datatype, so the output file ordering is stable
41 # when we have multiple items on the same source line
42 def v_sort_key(v):
43 return natural_sort_key(v[1]) + [v[0]]
45 # sort results by name and line number
46 tmp1list = sorted(unnecessaryVirtualSet, key=lambda v: v_sort_key(v))
48 with open("compilerplugins/clang/virtualdown.results", "wt") as f:
49 for t in tmp1list:
50 f.write( t[1] + "\n" )
51 f.write( " " + t[0] + "\n" )
52 # add an empty line at the end to make it easier for the removevirtuals plugin to mmap() the output file
53 f.write("\n")