improve unusedfields loplugin to find constructor-only fields

ie. fields that are only touched in the constructor

Change-Id: Ia714cbfed9710e47e69ca9f0eb0eac4f7e8b8a86
Reviewed-on: https://gerrit.libreoffice.org/54412
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2018-05-16 09:28:54 +02:00
parent 2c244e6f53
commit 6ac83797e0
2 changed files with 50 additions and 2 deletions

View File

@@ -67,6 +67,7 @@ bool operator < (const MyFieldInfo &lhs, const MyFieldInfo &rhs)
// try to limit the voluminous output a little
static std::set<MyFieldInfo> touchedFromInsideSet;
static std::set<MyFieldInfo> touchedFromOutsideSet;
static std::set<MyFieldInfo> touchedFromOutsideConstructorSet;
static std::set<MyFieldInfo> readFromSet;
static std::set<MyFieldInfo> writeToSet;
static std::set<MyFieldInfo> definitionSet;
@@ -186,6 +187,8 @@ void UnusedFields::run()
output += "inside:\t" + s.parentClass + "\t" + s.fieldName + "\n";
for (const MyFieldInfo & s : touchedFromOutsideSet)
output += "outside:\t" + s.parentClass + "\t" + s.fieldName + "\n";
for (const MyFieldInfo & s : touchedFromOutsideConstructorSet)
output += "outside-constructor:\t" + s.parentClass + "\t" + s.fieldName + "\n";
for (const MyFieldInfo & s : readFromSet)
output += "read:\t" + s.parentClass + "\t" + s.fieldName + "\n";
for (const MyFieldInfo & s : writeToSet)
@@ -989,6 +992,8 @@ void UnusedFields::checkTouchedFromOutside(const FieldDecl* fieldDecl, const Exp
} else {
if (memberExprParentFunction->getParent() == fieldDecl->getParent()) {
touchedFromInsideSet.insert(fieldInfo);
if (!constructorDecl)
touchedFromOutsideConstructorSet.insert(fieldInfo);
} else {
touchedFromOutsideSet.insert(fieldInfo);
}