6 definitionToSourceLocationMap
= 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
:
19 tokens
= line
.strip().split("\t")
20 if tokens
[0] == "defn:":
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
)
38 print( "unknown line: " + line
)
41 for k
,v
in callDict
.iteritems():
45 if k
.endswith("::RegisterInterface(class SfxModule *)"):
47 if k
.endswith("::RegisterChildWindow(_Bool,class SfxModule *,enum SfxChildWindowFlags)"):
49 if k
.endswith("::RegisterControl(unsigned short,class SfxModule *)"):
51 if k
.endswith("::RegisterFactory(unsigned short)"):
54 if "ShutdownIcon::OpenURL" in k
:
57 if k
.startswith("void VclPtr::VclPtr(const VclPtr<type-parameter-?-?> &,typename UpCast<"):
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
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
:
78 f
.write(" " + t
[0] + "\n")