diff options
author | Noel Grandin <noel@peralex.com> | 2016-01-11 08:41:55 +0200 |
---|---|---|
committer | Noel Grandin <noel@peralex.com> | 2016-01-11 10:49:24 +0200 |
commit | 86bb6fdf9cf14342bcf8ee72aa3233dd9dee1b3a (patch) | |
tree | c1d70077b3c483835b1d271fba2cc88b1a112328 /compilerplugins/clang/unusedmethods.py | |
parent | loplugin:unusedmethods unused return value in dbaccess (diff) | |
download | core-86bb6fdf9cf14342bcf8ee72aa3233dd9dee1b3a.tar.gz core-86bb6fdf9cf14342bcf8ee72aa3233dd9dee1b3a.zip |
update unusedmethods loplugin to update unused return values
Change-Id: I825d022d09282bc9b6cffd9178e40e4090d335da
Diffstat (limited to 'compilerplugins/clang/unusedmethods.py')
-rwxr-xr-x | compilerplugins/clang/unusedmethods.py | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/compilerplugins/clang/unusedmethods.py b/compilerplugins/clang/unusedmethods.py index 0c2cdff7f640..aca8591fe0a8 100755 --- a/compilerplugins/clang/unusedmethods.py +++ b/compilerplugins/clang/unusedmethods.py @@ -7,6 +7,7 @@ import io definitionSet = set() definitionToSourceLocationMap = dict() callSet = set() +returnSet = set() sourceLocationSet = set() # things we need to exclude for reasons like : # - it's a weird template thingy that confuses the plugin @@ -125,6 +126,9 @@ with io.open(sys.argv[1], "rb", buffering=1024*1024) as txt: elif line.startswith("call:\t"): idx1 = line.find("\t",6) callSet.add((normalizeTypeParams(line[6:idx1]), normalizeTypeParams(line[idx1+1:].strip()))) + elif line.startswith("usedReturn:\t"): + idx1 = line.find("\t",12) + returnSet.add((normalizeTypeParams(line[12:idx1]), normalizeTypeParams(line[idx1+1:].strip()))) # Invert the definitionToSourceLocationMap # If we see more than one method at the same sourceLocation, it's being autogenerated as part of a template @@ -138,6 +142,10 @@ for k, definitions in sourceLocationToDefinitionMap.iteritems(): for d in definitions: definitionSet.remove(d) +# ------------------------------------------- +# Do the "unused methods" part +# ------------------------------------------- + tmp1set = set() for d in definitionSet: clazz = d[0] + " " + d[1] @@ -228,11 +236,44 @@ def natural_sort_key(s, _nsre=re.compile('([0-9]+)')): tmp1list = sorted(tmp1set, key=lambda v: natural_sort_key(v[1])) # print out the results -for t in tmp1list: - print t[1] - print " ", t[0] +#for t in tmp1list: +# print t[1] +# print " ", t[0] + + +# ------------------------------------------- +# Do the "unused return types" part +# ------------------------------------------- + +tmp2set = set() +for d in definitionSet: + clazz = d[0] + " " + d[1] + if clazz in exclusionSet: + continue + if d in returnSet: + continue + if d[0] == "void": + continue + # ignore UNO constructor method entrypoints + if "_get_implementation" in d[1]: + continue + # the plugin can't see calls to these + if "operator new" in d[1]: + continue + # unused return type is not a problem here + if "operator=(" in d[1]: + continue + # ignore external code + if definitionToSourceLocationMap[d].startswith("external/"): + continue + tmp2set.add((clazz, definitionToSourceLocationMap[d])) +# sort results by name and line number +tmp2list = sorted(tmp2set, key=lambda v: natural_sort_key(v[1])) +for t in tmp2list: + print t[1] + print " ", t[0] # add an empty line at the end to make it easier for the unusedmethodsremove plugin to mmap() the output file print |