loplugin: move parentFunctionDecl() into common code

Change-Id: Ia10a76a98a63c6ea3b516d9146281f672b213ab3
This commit is contained in:
Noel Grandin
2016-06-28 14:52:54 +02:00
parent e3e79246cb
commit 442dd6a153
5 changed files with 42 additions and 61 deletions

View File

@@ -221,33 +221,6 @@ void UnusedMethods::logCallToRootMethods(const FunctionDecl* functionDecl, std::
// prevent recursive templates from blowing up the stack
static std::set<std::string> traversedFunctionSet;
const Decl* get_DeclContext_from_Stmt(ASTContext& context, const Stmt& stmt)
{
auto it = context.getParents(stmt).begin();
if (it == context.getParents(stmt).end())
return nullptr;
const Decl *aDecl = it->get<Decl>();
if (aDecl)
return aDecl;
const Stmt *aStmt = it->get<Stmt>();
if (aStmt)
return get_DeclContext_from_Stmt(context, *aStmt);
return nullptr;
}
static const FunctionDecl* get_top_FunctionDecl_from_Stmt(ASTContext& context, const Stmt& stmt)
{
const Decl *decl = get_DeclContext_from_Stmt(context, stmt);
if (decl)
return static_cast<const FunctionDecl*>(decl->getNonClosureContext());
return nullptr;
}
bool UnusedMethods::VisitCallExpr(CallExpr* expr)
{
// Note that I don't ignore ANYTHING here, because I want to get calls to my code that result
@@ -285,9 +258,9 @@ gotfunc:
CXXMethodDecl* calleeMethodDecl = dyn_cast<CXXMethodDecl>(calleeFunctionDecl);
if (calleeMethodDecl && calleeMethodDecl->getAccess() == AS_public)
{
const FunctionDecl* parentFunctionDecl = get_top_FunctionDecl_from_Stmt(compiler.getASTContext(), *expr);
if (parentFunctionDecl && parentFunctionDecl != calleeFunctionDecl) {
calledFromOutsideSet.insert(niceName(parentFunctionDecl));
const FunctionDecl* parentFunction = parentFunctionDecl(expr);
if (parentFunction && parentFunction != calleeFunctionDecl) {
calledFromOutsideSet.insert(niceName(parentFunction));
}
}