7 definitionToSourceLocationMap
= 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
:
20 tokens
= line
.strip().split("\t")
21 if tokens
[0] == "defn:":
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
)
39 print( "unknown line: " + line
)
42 for k
,v
in callDict
.iteritems():
46 if k
.endswith("::RegisterInterface(class SfxModule *)"):
48 if k
.endswith("::RegisterChildWindow(_Bool,class SfxModule *,enum SfxChildWindowFlags)"):
50 if k
.endswith("::RegisterChildWindowContext(unsigned short,class SfxModule *)"):
52 if k
.endswith("::RegisterControl(unsigned short,class SfxModule *)"):
54 if k
.endswith("::RegisterFactory(unsigned short)"):
57 if "ShutdownIcon::OpenURL" in k
:
60 if k
.startswith("void VclPtr::VclPtr(const VclPtr<type-parameter-?-?> &,typename UpCast<"):
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
:
77 f
.write(" " + t
[0] + "\n")