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