loplugin:constantparam

clean up the plugin a little, and try to catch params which are default
constructed, which doesn't seem to be working yet

Change-Id: Ife45f18502a45cd26306424b7432c55fcbb0fd12
Reviewed-on: https://gerrit.libreoffice.org/28861
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2016-09-14 09:01:06 +02:00
committed by Noel Grandin
parent 0761f97525
commit 20a9e101d9
30 changed files with 116 additions and 185 deletions

View File

@@ -4,9 +4,7 @@ import sys
import re
import io
definitionSet = set()
definitionToSourceLocationMap = dict()
callParamSet = dict()
callDict = dict()
# 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.
@@ -17,23 +15,20 @@ def normalizeTypeParams( line ):
# reading as binary (since we known it is pure ascii) is much faster than reading as unicode
with io.open("loplugin.constantparam.log", "rb", buffering=1024*1024) as txt:
for line in txt:
idx1 = line.find("\t")
idx2 = line.find("\t",idx1+1)
idx3 = line.find("\t",idx2+1)
idx4 = line.find("\t",idx3+1)
returnType = normalizeTypeParams(line[:idx1])
nameAndParams = normalizeTypeParams(line[idx1+1:idx2])
sourceLocation = line[idx2+1:idx3]
paramName = line[idx3+1:idx4]
callValue = line[idx4+1:].strip()
callInfo = (returnType, nameAndParams, paramName)
if not callInfo in callParamSet:
callParamSet[callInfo] = set()
callParamSet[callInfo].add(callValue)
definitionToSourceLocationMap[callInfo] = sourceLocation
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)
tmp1list = list()
for callInfo, callValues in callParamSet.iteritems():
for callInfo, callValues in callDict.iteritems():
nameAndParams = callInfo[1]
if len(callValues) != 1:
continue
@@ -43,22 +38,22 @@ for callInfo, callValues in callParamSet.iteritems():
# try and ignore setter methods
if ("," not in nameAndParams) and (("::set" in nameAndParams) or ("::Set" in nameAndParams)):
continue
v0 = callInfo[0] + " " + callInfo[1]
v1 = callInfo[2] + " " + callValue
v2 = definitionToSourceLocationMap[callInfo]
v0 = callInfo[4]
v1 = callInfo[0] + " " + callInfo[1]
v2 = callInfo[3] + " " + callInfo[2] + " " + callValue
tmp1list.append((v0,v1,v2))
# sort results by filename:lineno
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)]
tmp1list.sort(key=lambda v: natural_sort_key(v[2]))
tmp1list.sort(key=lambda v: natural_sort_key(v[0]))
# print out the results
with open("loplugin.constantparam.report", "wt") as f:
for v in tmp1list:
f.write(v[2] + "\n")
f.write(" " + v[0] + "\n")
f.write(v[0] + "\n")
f.write(" " + v[1] + "\n")
f.write(" " + v[2] + "\n")