summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2016-01-11 16:02:17 +0200
committerNoel Grandin <noelgrandin@gmail.com>2016-01-12 07:39:42 +0000
commit1f9a610de1e1e540386972c010ebfc99e5f55df7 (patch)
treeaabfe490a5de78c0936e7237695c2ef6680f75df /compilerplugins
parentc93486bbb85ae19b6d15395afbd7aec3c5db7e89 (diff)
loplugin:unusedmethods unused return value in include/editeng
Change-Id: I1314480950b0d3a3e5ed066d71c175604dd41970 Reviewed-on: https://gerrit.libreoffice.org/21361 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'compilerplugins')
-rwxr-xr-xcompilerplugins/clang/unusedmethods.py57
1 files changed, 36 insertions, 21 deletions
diff --git a/compilerplugins/clang/unusedmethods.py b/compilerplugins/clang/unusedmethods.py
index 48344279349a..fb2ad7f15029 100755
--- a/compilerplugins/clang/unusedmethods.py
+++ b/compilerplugins/clang/unusedmethods.py
@@ -141,6 +141,31 @@ for k, definitions in sourceLocationToDefinitionMap.iteritems():
if len(definitions) > 1:
for d in definitions:
definitionSet.remove(d)
+
+def isOtherConstness( d, callSet ):
+ clazz = d[0] + " " + d[1]
+ # if this method is const, and there is a non-const variant of it, and the non-const variant is in use, then leave it alone
+ if d[0].startswith("const ") and d[1].endswith(" const"):
+ if ((d[0][6:],d[1][:-6]) in callSet):
+ return True
+ elif clazz.endswith(" const"):
+ clazz2 = clazz[:len(clazz)-6] # strip off " const"
+ if ((d[0],clazz2) in callSet):
+ return True
+ if clazz.endswith(" const") and ("::iterator" in clazz):
+ clazz2 = clazz[:len(clazz)-6] # strip off " const"
+ clazz2 = clazz2.replace("::const_iterator", "::iterator")
+ if ((d[0],clazz2) in callSet):
+ return True
+ # if this method is non-const, and there is a const variant of it, and the const variant is in use, then leave it alone
+ if (not clazz.endswith(" const")) and ((d[0],"const " + clazz + " const") in callSet):
+ return True
+ if (not clazz.endswith(" const")) and ("::iterator" in clazz):
+ clazz2 = clazz.replace("::iterator", "::const_iterator") + " const"
+ if ((d[0],clazz2) in callSet):
+ return True
+ return False
+
# -------------------------------------------
# Do the "unused methods" part
@@ -161,26 +186,8 @@ for d in definitionSet:
or ("::IsA(" in d[1])
or ("::Type()" in d[1])):
continue
- # if this method is const, and there is a non-const variant of it, and the non-const variant is in use, then leave it alone
- if d[0].startswith("const ") and d[1].endswith(" const"):
- if ((d[0][6:],d[1][:-6]) in callSet):
- continue
- elif clazz.endswith(" const"):
- clazz2 = clazz[:len(clazz)-6] # strip off " const"
- if ((d[0],clazz2) in callSet):
- continue
- if clazz.endswith(" const") and ("::iterator" in clazz):
- clazz2 = clazz[:len(clazz)-6] # strip off " const"
- clazz2 = clazz2.replace("::const_iterator", "::iterator")
- if ((d[0],clazz2) in callSet):
- continue
- # if this method is non-const, and there is a const variant of it, and the const variant is in use, then leave it alone
- if (not clazz.endswith(" const")) and ((d[0],"const " + clazz + " const") in callSet):
- continue
- if (not clazz.endswith(" const")) and ("::iterator" in clazz):
- clazz2 = clazz.replace("::iterator", "::const_iterator") + " const"
- if ((d[0],clazz2) in callSet):
- continue
+ if isOtherConstness(d, callSet):
+ continue
# just ignore iterators, they normally occur in pairs, and we typically want to leave one constness version alone
# alone if the other one is in use.
if d[1] == "begin() const" or d[1] == "begin()" or d[1] == "end()" or d[1] == "end() const":
@@ -252,6 +259,8 @@ for d in definitionSet:
continue
if d in returnSet:
continue
+ if isOtherConstness(d, returnSet):
+ continue
if d[0] == "void":
continue
# ignore UNO constructor method entrypoints
@@ -261,11 +270,17 @@ for d in definitionSet:
if "operator new" in d[1]:
continue
# unused return type is not a problem here
- if "operator=(" in d[1]:
+ if ("operator=(" in d[1] or "operator&=" in d[1] or "operator|=" in d[1] or "operator^=" in d[1]
+ or "operator+=" in d[1] or "operator-=" in d[1]
+ or "operator<<" in d[1] or "operator>>" in d[1]
+ or "operator++" in d[1] or "operator--" in d[1]):
continue
# ignore external code
if definitionToSourceLocationMap[d].startswith("external/"):
continue
+ # ignore the SfxPoolItem CreateDefault methods for now
+ if "::CreateDefault" in d[1]:
+ continue
tmp2set.add((clazz, definitionToSourceLocationMap[d]))
# sort results by name and line number