summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-02-25 10:24:55 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-02-27 07:34:52 +0100
commit19240f625f8bd7b772481abc8e678d7b0fadd921 (patch)
treedf98eb1d1d2bf11179aea13de58aa38548458b9d /compilerplugins
parent60c7725a20ff0d77e3025ed60608f57d46e50b58 (diff)
loplugin:unusedfields look for classes where we can make all the..
fields private Change-Id: Id3c6b123f06ab5dcf87628de4c347626110d2d27 Reviewed-on: https://gerrit.libreoffice.org/68302 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rwxr-xr-xcompilerplugins/clang/unusedfields.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/compilerplugins/clang/unusedfields.py b/compilerplugins/clang/unusedfields.py
index 5ec0388bc0d2..dd7a4d65c8de 100755
--- a/compilerplugins/clang/unusedfields.py
+++ b/compilerplugins/clang/unusedfields.py
@@ -211,6 +211,29 @@ for d in protectedAndPublicDefinitionSet:
canBePrivateSet.add((clazz + " " + definitionToTypeMap[d], srcLoc))
+
+# --------------------------------------------------------------------------------------------
+# "all fields in class can be made private" analysis
+# --------------------------------------------------------------------------------------------
+
+potentialClasses = set()
+excludedClasses = set()
+potentialClassesSourceLocationMap = dict()
+matchClassName = re.compile(r"(\w+)::")
+for d in protectedAndPublicDefinitionSet:
+ clazz = d[0]
+ if d in touchedFromOutsideSet:
+ excludedClasses.add(clazz)
+ else:
+ potentialClasses.add(clazz)
+ potentialClassesSourceLocationMap[clazz] = definitionToSourceLocationMap[d]
+allFieldsCanBePrivateSet = set()
+for d in (potentialClasses - excludedClasses):
+ sourceLoc = potentialClassesSourceLocationMap[d]
+ # when the class is inside a compile unit, assume that the compiler can figure this out for itself, much less interesting to me
+ if not ".cxx" in sourceLoc:
+ allFieldsCanBePrivateSet.add((d, sourceLoc))
+
# sort the results using a "natural order" so sequences like [item1,item2,item10] sort nicely
def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
return [int(text) if text.isdigit() else text.lower()
@@ -222,6 +245,7 @@ tmp2list = sorted(writeonlySet, key=lambda v: natural_sort_key(v[1]))
tmp3list = sorted(canBePrivateSet, key=lambda v: natural_sort_key(v[1]))
tmp4list = sorted(readonlySet, key=lambda v: natural_sort_key(v[1]))
tmp5list = sorted(onlyUsedInConstructorSet, key=lambda v: natural_sort_key(v[1]))
+tmp6list = sorted(allFieldsCanBePrivateSet, key=lambda v: natural_sort_key(v[1]))
# print out the results
with open("compilerplugins/clang/unusedfields.untouched.results", "wt") as f:
@@ -245,5 +269,9 @@ with open("compilerplugins/clang/unusedfields.only-used-in-constructor.results",
for t in tmp5list:
f.write( t[1] + "\n" )
f.write( " " + t[0] + "\n" )
+with open("compilerplugins/clang/unusedfields.report-all-can-be-private", "wt") as f:
+ for t in tmp6list:
+ f.write( t[1] + "\n" )
+ f.write( " " + t[0] + "\n" )