bump product version to 6.4.0.3
[LibreOffice.git] / compilerplugins / clang / countusersofdefaultparams.py
blobeabb7d5ef30e552454468d73708adb7c5f4eade0
1 #!/usr/bin/python
3 import sys
4 import re
5 import io
7 definitionToSourceLocationMap = dict()
8 callDict = dict()
10 # clang does not always use exactly the same numbers in the type-parameter vars it generates
11 # so I need to substitute them to ensure we can match correctly.
12 normalizeTypeParamsRegex1 = re.compile(r"type-parameter-\d+-\d+")
13 normalizeTypeParamsRegex2 = re.compile(r"typename enable_if<.*")
14 def normalizeTypeParams( line ):
15 line = normalizeTypeParamsRegex1.sub("type-parameter-?-?", line)
16 return normalizeTypeParamsRegex2.sub("type-parameter-?-?", line)
18 with io.open("workdir/loplugin.countusersofdefaultparams.log", "rb", buffering=1024*1024) as txt:
19 for line in txt:
20 tokens = line.strip().split("\t")
21 if tokens[0] == "defn:":
22 access = tokens[1]
23 returnType = tokens[2]
24 nameAndParams = tokens[3]
25 sourceLocation = tokens[4]
26 funcInfo = normalizeTypeParams(returnType) + " " + normalizeTypeParams(nameAndParams)
27 definitionToSourceLocationMap[funcInfo] = sourceLocation
28 if not funcInfo in callDict:
29 callDict[funcInfo] = set()
30 elif tokens[0] == "call:":
31 returnType = tokens[1]
32 nameAndParams = tokens[2]
33 sourceLocationOfCall = tokens[3]
34 funcInfo = normalizeTypeParams(returnType) + " " + normalizeTypeParams(nameAndParams)
35 if not funcInfo in callDict:
36 callDict[funcInfo] = set()
37 callDict[funcInfo].add(sourceLocationOfCall)
38 else:
39 print( "unknown line: " + line)
41 tmp1list = list()
42 for k,v in callDict.iteritems():
43 if len(v) >= 1:
44 continue
45 # created by macros
46 if k.endswith("::RegisterInterface(class SfxModule *)"):
47 continue
48 if k.endswith("::RegisterChildWindow(_Bool,class SfxModule *,enum SfxChildWindowFlags)"):
49 continue
50 if k.endswith("::RegisterChildWindowContext(unsigned short,class SfxModule *)"):
51 continue
52 if k.endswith("::RegisterControl(unsigned short,class SfxModule *)"):
53 continue
54 if k.endswith("::RegisterFactory(unsigned short)"):
55 continue
56 # windows-only stuff
57 if "ShutdownIcon::OpenURL" in k:
58 continue
59 # template magic
60 if k.startswith("void VclPtr::VclPtr(const VclPtr<type-parameter-?-?> &,typename UpCast<"):
61 continue
62 if k in definitionToSourceLocationMap:
63 tmp1list.append((k, definitionToSourceLocationMap[k]))
65 # sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
66 def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
67 return [int(text) if text.isdigit() else text.lower()
68 for text in re.split(_nsre, s)]
70 # sort results by name and line number
71 tmp1list.sort(key=lambda v: natural_sort_key(v[1]))
73 # print out the results
74 with open("loplugin.countusersofdefaultparams.report", "wt") as f:
75 for t in tmp1list:
76 f.write(t[1] + "\n")
77 f.write(" " + t[0] + "\n")