summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/unusedfields.py
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-07-18 20:09:31 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-07-19 09:25:52 +0200
commit32878b68574f8fb27a122dd3a356e369391bdfa6 (patch)
tree7bc3e64776a188d765ef21a9892912609359fd4e /compilerplugins/clang/unusedfields.py
parent2303d4f1a2b7e25fe864323adeec398057cebe72 (diff)
enhance unusedfields plugin to find readonly fields
Change-Id: I4da97443fc7eb14fd94959a026ab45a9256c055f Reviewed-on: https://gerrit.libreoffice.org/40158 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/unusedfields.py')
-rwxr-xr-xcompilerplugins/clang/unusedfields.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/compilerplugins/clang/unusedfields.py b/compilerplugins/clang/unusedfields.py
index 4e8e60fa1622..f5b882969258 100755
--- a/compilerplugins/clang/unusedfields.py
+++ b/compilerplugins/clang/unusedfields.py
@@ -10,6 +10,7 @@ definitionToSourceLocationMap = dict()
definitionToTypeMap = dict()
touchedFromInsideSet = set()
readFromSet = set()
+writeToSet = set()
sourceLocationSet = set()
touchedFromOutsideSet = set()
@@ -51,6 +52,8 @@ with io.open("loplugin.unusedfields.log", "rb", buffering=1024*1024) as txt:
touchedFromOutsideSet.add(parseFieldInfo(tokens))
elif tokens[0] == "read:":
readFromSet.add(parseFieldInfo(tokens))
+ elif tokens[0] == "write:":
+ writeToSet.add(parseFieldInfo(tokens))
else:
print( "unknown line: " + line)
@@ -145,6 +148,15 @@ for d in definitionSet:
writeonlySet.add((d[0] + " " + d[1] + " " + definitionToTypeMap[d], srcLoc))
+readonlySet = set()
+for d in definitionSet:
+ parentClazz = d[0];
+ if d in writeToSet:
+ continue
+ srcLoc = definitionToSourceLocationMap[d];
+ readonlySet.add((d[0] + " " + d[1] + " " + definitionToTypeMap[d], srcLoc))
+
+
canBePrivateSet = set()
for d in protectedAndPublicDefinitionSet:
clazz = d[0] + " " + d[1]
@@ -164,6 +176,7 @@ def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
tmp1list = sorted(untouchedSet, key=lambda v: natural_sort_key(v[1]))
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]))
# print out the results
with open("compilerplugins/clang/unusedfields.untouched.results", "wt") as f:
@@ -179,5 +192,9 @@ with open("loplugin.unusedfields.report-can-be-private", "wt") as f:
for t in tmp3list:
f.write( t[1] + "\n" )
f.write( " " + t[0] + "\n" )
+with open("compilerplugins/clang/unusedfields.readonly.results", "wt") as f:
+ for t in tmp4list:
+ f.write( t[1] + "\n" )
+ f.write( " " + t[0] + "\n" )