summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/unusedfields.py
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-03-24 08:31:25 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-03-24 08:57:01 +0000
commitf0593478571009139cd12bac11a9b38e51c42f96 (patch)
tree7901d4c671ac3a8d8622cccabbffbbdf91f5cc6a /compilerplugins/clang/unusedfields.py
parentad5bf6b72c89caf0ed7110e4a84e2d6bf1807a24 (diff)
loplugin:unusedfields
improve the plugin to find fields which are only assigned to in the constructor Change-Id: I95b5be238ebba83d950ca15093abdd1849740359 Reviewed-on: https://gerrit.libreoffice.org/35613 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang/unusedfields.py')
-rwxr-xr-xcompilerplugins/clang/unusedfields.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/compilerplugins/clang/unusedfields.py b/compilerplugins/clang/unusedfields.py
index 7bf910f62d80..77e6446e18e3 100755
--- a/compilerplugins/clang/unusedfields.py
+++ b/compilerplugins/clang/unusedfields.py
@@ -8,7 +8,8 @@ definitionSet = set()
protectedAndPublicDefinitionSet = set() # set of tuple(type, name)
definitionToSourceLocationMap = dict()
definitionToTypeMap = dict()
-callSet = set()
+touchedFromInsideSet = set()
+touchedFromConstructorSet = set()
readFromSet = set()
sourceLocationSet = set()
touchedFromOutsideSet = set()
@@ -45,20 +46,20 @@ with io.open("loplugin.unusedfields.log", "rb", buffering=1024*1024) as txt:
if access == "protected" or access == "public":
protectedAndPublicDefinitionSet.add(fieldInfo)
definitionToSourceLocationMap[fieldInfo] = tokens[5]
- elif tokens[0] == "touch:":
- callSet.add(parseFieldInfo(tokens))
- elif tokens[0] == "read:":
- readFromSet.add(parseFieldInfo(tokens))
- elif tokens[0] == "read:":
- readFromSet.add(parseFieldInfo(tokens))
+ elif tokens[0] == "inside:":
+ touchedFromInsideSet.add(parseFieldInfo(tokens))
+ elif tokens[0] == "constructor:":
+ touchedFromConstructorSet.add(parseFieldInfo(tokens))
elif tokens[0] == "outside:":
touchedFromOutsideSet.add(parseFieldInfo(tokens))
+ elif tokens[0] == "read:":
+ readFromSet.add(parseFieldInfo(tokens))
else:
print( "unknown line: " + line)
# Invert the definitionToSourceLocationMap
# If we see more than one method at the same sourceLocation, it's being autogenerated as part of a template
-# and we should just ignore
+# and we should just ignore it
sourceLocationToDefinitionMap = {}
for k, v in definitionToSourceLocationMap.iteritems():
sourceLocationToDefinitionMap[v] = sourceLocationToDefinitionMap.get(v, [])
@@ -68,9 +69,10 @@ for k, definitions in sourceLocationToDefinitionMap.iteritems():
for d in definitions:
definitionSet.remove(d)
+# Calculate untouched or untouched-except-for-in-constructor
untouchedSet = set()
for d in definitionSet:
- if d in callSet:
+ if d in touchedFromOutsideSet or d in touchedFromInsideSet:
continue
srcLoc = definitionToSourceLocationMap[d];
# this is all representations of on-disk data structures