loplugin:unusedmethods new analysis

look for classes containing protected methods where we can convert them
all to private

Change-Id: I4a448341943e0a613cde30501c4012da61dba713
Reviewed-on: https://gerrit.libreoffice.org/44588
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2017-11-10 11:33:41 +02:00
parent 42344398a8
commit 4cc7ebcca3
2 changed files with 48 additions and 0 deletions

View File

@@ -114,11 +114,13 @@ public:
bool VisitFunctionDecl( const FunctionDecl* decl );
bool VisitDeclRefExpr( const DeclRefExpr* );
bool VisitCXXConstructExpr( const CXXConstructExpr* );
bool TraverseCXXRecordDecl( CXXRecordDecl* );
private:
void logCallToRootMethods(const FunctionDecl* functionDecl, std::set<MyFuncInfo>& funcSet);
MyFuncInfo niceName(const FunctionDecl* functionDecl);
std::string toString(SourceLocation loc);
void functionTouchedFromExpr( const FunctionDecl* calleeFunctionDecl, const Expr* expr );
CXXRecordDecl const * currentCxxRecordDecl = nullptr;
};
MyFuncInfo UnusedMethods::niceName(const FunctionDecl* functionDecl)
@@ -281,6 +283,10 @@ bool UnusedMethods::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr
logCallToRootMethods(constructorDecl, callSet);
// Now do the checks necessary for the "can be private" analysis
if (constructorDecl->getParent() != currentCxxRecordDecl)
calledFromOutsideSet.insert(niceName(constructorDecl));
return true;
}
@@ -341,6 +347,15 @@ bool UnusedMethods::VisitDeclRefExpr( const DeclRefExpr* declRefExpr )
return true;
}
bool UnusedMethods::TraverseCXXRecordDecl(CXXRecordDecl* cxxRecordDecl)
{
auto copy = currentCxxRecordDecl;
currentCxxRecordDecl = cxxRecordDecl;
bool ret = RecursiveASTVisitor::TraverseCXXRecordDecl(cxxRecordDecl);
currentCxxRecordDecl = copy;
return ret;
}
loplugin::Plugin::Registration< UnusedMethods > X("unusedmethods", false);
}