new loplugin:constfields
look for fields which are only assigned to in the constructor, so they can be made const Change-Id: I0b76817c2181227b04f6a29d6a808f5e31999765 Reviewed-on: https://gerrit.libreoffice.org/60393 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
@@ -70,7 +70,6 @@ static std::set<MyFieldInfo> touchedFromOutsideSet;
|
||||
static std::set<MyFieldInfo> touchedFromOutsideConstructorSet;
|
||||
static std::set<MyFieldInfo> readFromSet;
|
||||
static std::set<MyFieldInfo> writeToSet;
|
||||
static std::set<MyFieldInfo> writeToOutsideConstructorSet;
|
||||
static std::set<MyFieldInfo> definitionSet;
|
||||
|
||||
/**
|
||||
@@ -160,7 +159,6 @@ public:
|
||||
private:
|
||||
MyFieldInfo niceName(const FieldDecl*);
|
||||
void checkTouchedFromOutside(const FieldDecl* fieldDecl, const Expr* memberExpr);
|
||||
void checkWriteFromOutsideConstructor(const FieldDecl* fieldDecl, const Expr* memberExpr);
|
||||
void checkWriteOnly(const FieldDecl* fieldDecl, const Expr* memberExpr);
|
||||
void checkReadOnly(const FieldDecl* fieldDecl, const Expr* memberExpr);
|
||||
bool isSomeKindOfZero(const Expr* arg);
|
||||
@@ -195,8 +193,6 @@ void UnusedFields::run()
|
||||
output += "read:\t" + s.parentClass + "\t" + s.fieldName + "\n";
|
||||
for (const MyFieldInfo & s : writeToSet)
|
||||
output += "write:\t" + s.parentClass + "\t" + s.fieldName + "\n";
|
||||
for (const MyFieldInfo & s : writeToOutsideConstructorSet)
|
||||
output += "write-outside-constructor:\t" + s.parentClass + "\t" + s.fieldName + "\n";
|
||||
for (const MyFieldInfo & s : definitionSet)
|
||||
output += "definition:\t" + s.access + "\t" + s.parentClass + "\t" + s.fieldName + "\t" + s.fieldType + "\t" + s.sourceLocation + "\n";
|
||||
std::ofstream myfile;
|
||||
@@ -676,8 +672,6 @@ void UnusedFields::checkReadOnly(const FieldDecl* fieldDecl, const Expr* memberE
|
||||
// we don't care about writes to a field when inside the copy/move constructor/operator= for that field
|
||||
if (cxxRecordDecl1 && (cxxRecordDecl1 == insideMoveOrCopyOrCloneDeclParent))
|
||||
{
|
||||
// ... but they matter to tbe can-be-const analysis
|
||||
checkWriteFromOutsideConstructor(fieldDecl, memberExpr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -891,7 +885,6 @@ void UnusedFields::checkReadOnly(const FieldDecl* fieldDecl, const Expr* memberE
|
||||
if (bPotentiallyWrittenTo)
|
||||
{
|
||||
writeToSet.insert(fieldInfo);
|
||||
checkWriteFromOutsideConstructor(fieldDecl, memberExpr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1021,27 +1014,6 @@ void UnusedFields::checkTouchedFromOutside(const FieldDecl* fieldDecl, const Exp
|
||||
}
|
||||
}
|
||||
|
||||
// For the const-field analysis.
|
||||
// Called when we have a write to a field, and we want to record that write only if it's writing from
|
||||
// outside the constructor.
|
||||
void UnusedFields::checkWriteFromOutsideConstructor(const FieldDecl* fieldDecl, const Expr* memberExpr) {
|
||||
const FunctionDecl* memberExprParentFunction = getParentFunctionDecl(memberExpr);
|
||||
bool doWrite = false;
|
||||
|
||||
if (!memberExprParentFunction)
|
||||
// If we are not inside a function
|
||||
doWrite = true;
|
||||
else if (memberExprParentFunction->getParent() != fieldDecl->getParent())
|
||||
// or we are inside a method from another class (than the one the field belongs to)
|
||||
doWrite = true;
|
||||
else if (!isa<CXXConstructorDecl>(memberExprParentFunction))
|
||||
// or we are not inside constructor
|
||||
doWrite = true;
|
||||
|
||||
if (doWrite)
|
||||
writeToOutsideConstructorSet.insert(niceName(fieldDecl));
|
||||
}
|
||||
|
||||
llvm::Optional<CalleeWrapper> UnusedFields::getCallee(CallExpr const * callExpr)
|
||||
{
|
||||
FunctionDecl const * functionDecl = callExpr->getDirectCallee();
|
||||
|
Reference in New Issue
Block a user