diff options
author | Noel Grandin <noel@peralex.com> | 2016-03-23 13:26:16 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-03-23 12:05:37 +0000 |
commit | ef3ca022d9de6eab86b7db5c9d7a88b0c4c8bba2 (patch) | |
tree | 2a6d85400ba8d0a9d4758b17d352521dc0610443 /compilerplugins | |
parent | 8d411a4a1ef6844c00bc714f8b144d3729e4f4e8 (diff) |
constantparam loplugin improvements
clean up the python code, filter out setter methods
Change-Id: I8294dd305a30708cf0e81c5328935ec8f6cdc8d4
Reviewed-on: https://gerrit.libreoffice.org/23466
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'compilerplugins')
-rwxr-xr-x | compilerplugins/clang/constantparam.py | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/compilerplugins/clang/constantparam.py b/compilerplugins/clang/constantparam.py index a23be74be50f..49f2f9d30d22 100755 --- a/compilerplugins/clang/constantparam.py +++ b/compilerplugins/clang/constantparam.py @@ -8,54 +8,59 @@ definitionSet = set() definitionToSourceLocationMap = dict() callParamSet = dict() -# things we need to exclude for reasons like : -# - it's a weird template thingy that confuses the plugin -exclusionSet = set([ -]) - # 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) -# The parsing here is designed to avoid grabbing stuff which is mixed in from gbuild. -# I have not yet found a way of suppressing the gbuild output. +# reading as binary (since we known it is pure ascii) is much faster than reading as unicode with io.open(sys.argv[1], "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 = line[:idx1] - nameAndParams = line[idx1+1:idx2] - sourceLocation = line[idx2+1:idx3] - paramName = line[idx3+1:idx4] - callValue = line[idx4+1:].strip() - callInfo = (normalizeTypeParams(returnType), normalizeTypeParams(nameAndParams), paramName) - if callInfo in callParamSet: - callParamSet[callInfo].add(callValue) - else: - callParamSet[callInfo] = set([callValue]) - definitionToSourceLocationMap[callInfo] = sourceLocation - -tmp1set = set() + 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 + +tmp1list = list() for callInfo, callValues in callParamSet.iteritems(): - if len(callValues) == 1 and "unknown" not in callValues and ("0" in callValues or "1" in callValues or "nullptr" in callValues): - v1 = (" ".join(callInfo)) + " " + (",".join(callValues)) - v2 = definitionToSourceLocationMap[callInfo] - tmp1set.add((v1,v2)) + nameAndParams = callInfo[1] + if len(callValues) != 1: + continue + if "unknown" in callValues: + continue + # ignore anything with only one parameter, normally just setter methods + if nameAndParams.find(",") == -1: + continue + # if it contains anything other than this set, ignore it + if len(callValues - set(["0", "1", "-1", "nullptr"])) > 0: + continue + v0 = callInfo[0] + " " + callInfo[1] + v1 = callInfo[2] + " " + (",".join(callValues)) + v2 = definitionToSourceLocationMap[callInfo] + tmp1list.append((v0,v1,v2)) -# sort results by name and line number +# 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 = sorted(tmp1set, key=lambda v: natural_sort_key(v[1])) +tmp1list.sort(key=lambda v: natural_sort_key(v[2])) # print out the results with open("unused.constantparams", "wt") as f: - for t in tmp1list: - f.write(t[1] + "\n") - f.write(" " + t[0] + "\n") + for v in tmp1list: + f.write(v[2] + "\n") + f.write(" " + v[0] + "\n") + f.write(" " + v[1] + "\n") |