2016-03-08 09:04:18 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import io
|
|
|
|
|
2016-09-14 09:01:06 +02:00
|
|
|
callDict = dict()
|
2016-03-08 09:04:18 +02:00
|
|
|
|
|
|
|
# clang does not always use exactly the same numbers in the type-parameter vars it generates
|
|
|
|
# so I need to substitute them to ensure we can match correctly.
|
|
|
|
normalizeTypeParamsRegex = re.compile(r"type-parameter-\d+-\d+")
|
|
|
|
def normalizeTypeParams( line ):
|
|
|
|
return normalizeTypeParamsRegex.sub("type-parameter-?-?", line)
|
|
|
|
|
2016-03-23 13:26:16 +02:00
|
|
|
# reading as binary (since we known it is pure ascii) is much faster than reading as unicode
|
2016-07-25 13:22:38 +02:00
|
|
|
with io.open("loplugin.constantparam.log", "rb", buffering=1024*1024) as txt:
|
2016-03-08 09:04:18 +02:00
|
|
|
for line in txt:
|
2016-09-14 09:01:06 +02:00
|
|
|
tokens = line.strip().split("\t")
|
|
|
|
returnType = normalizeTypeParams(tokens[0])
|
|
|
|
nameAndParams = normalizeTypeParams(tokens[1])
|
|
|
|
sourceLocation = tokens[2]
|
|
|
|
paramName = tokens[3]
|
|
|
|
paramType = normalizeTypeParams(tokens[4])
|
|
|
|
callValue = tokens[5]
|
|
|
|
callInfo = (returnType, nameAndParams, paramName, paramType, sourceLocation)
|
|
|
|
if not callInfo in callDict:
|
|
|
|
callDict[callInfo] = set()
|
|
|
|
callDict[callInfo].add(callValue)
|
2016-03-23 13:26:16 +02:00
|
|
|
|
|
|
|
tmp1list = list()
|
2016-09-14 09:01:06 +02:00
|
|
|
for callInfo, callValues in callDict.iteritems():
|
2016-03-23 13:26:16 +02:00
|
|
|
nameAndParams = callInfo[1]
|
|
|
|
if len(callValues) != 1:
|
|
|
|
continue
|
2016-09-06 12:01:29 +02:00
|
|
|
callValue = next(iter(callValues))
|
|
|
|
if "unknown" in callValue:
|
2016-03-23 13:26:16 +02:00
|
|
|
continue
|
2016-09-29 12:43:17 +02:00
|
|
|
sourceLoc = callInfo[4]
|
|
|
|
functionSig = callInfo[0] + " " + callInfo[1]
|
|
|
|
|
2016-09-06 12:01:29 +02:00
|
|
|
# try and ignore setter methods
|
|
|
|
if ("," not in nameAndParams) and (("::set" in nameAndParams) or ("::Set" in nameAndParams)):
|
2016-03-23 13:26:16 +02:00
|
|
|
continue
|
2016-09-29 12:43:17 +02:00
|
|
|
# ignore code that follows a common pattern
|
|
|
|
if sourceLoc.startswith("sw/inc/swatrset.hxx"): continue
|
|
|
|
if sourceLoc.startswith("sw/inc/format.hxx"): continue
|
|
|
|
# template generated code
|
|
|
|
if sourceLoc.startswith("include/sax/fshelper.hxx"): continue
|
|
|
|
# debug code
|
|
|
|
if sourceLoc.startswith("include/oox/dump"): continue
|
|
|
|
# part of our binary API
|
|
|
|
if sourceLoc.startswith("include/LibreOfficeKit"): continue
|
|
|
|
|
2016-09-14 09:01:06 +02:00
|
|
|
v2 = callInfo[3] + " " + callInfo[2] + " " + callValue
|
2016-09-29 12:43:17 +02:00
|
|
|
tmp1list.append((sourceLoc, functionSig, v2))
|
2016-03-08 09:04:18 +02:00
|
|
|
|
2016-03-23 13:26:16 +02:00
|
|
|
# sort results by filename:lineno
|
2016-03-08 09:04:18 +02:00
|
|
|
def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
|
|
|
|
return [int(text) if text.isdigit() else text.lower()
|
|
|
|
for text in re.split(_nsre, s)]
|
2016-09-14 09:01:06 +02:00
|
|
|
tmp1list.sort(key=lambda v: natural_sort_key(v[0]))
|
2016-03-08 09:04:18 +02:00
|
|
|
|
|
|
|
# print out the results
|
2016-08-08 15:38:59 +02:00
|
|
|
with open("loplugin.constantparam.report", "wt") as f:
|
2016-03-23 13:26:16 +02:00
|
|
|
for v in tmp1list:
|
2016-09-14 09:01:06 +02:00
|
|
|
f.write(v[0] + "\n")
|
2016-03-23 13:26:16 +02:00
|
|
|
f.write(" " + v[1] + "\n")
|
2016-09-14 09:01:06 +02:00
|
|
|
f.write(" " + v[2] + "\n")
|
2016-03-08 09:04:18 +02:00
|
|
|
|
|
|
|
|