diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-05-25 13:29:30 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-05-25 15:46:01 +0200 |
commit | cc146f7a12ee0c0e829d2827117558f9cba11858 (patch) | |
tree | 816d6e1704eca9d927ad31fa9b84d0c2137fe468 | |
parent | 953d2704025ef31198f5546ad95cc54401b592a9 (diff) |
Code duplication
Change-Id: I1af2948e0332044ef88bc7dbd837e8c7afe7af19
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94785
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | compilerplugins/clang/plugin.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/plugin.hxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/unusedfields.cxx | 25 |
3 files changed, 4 insertions, 25 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx index ff15e06750e5..b885ab5e5555 100644 --- a/compilerplugins/clang/plugin.cxx +++ b/compilerplugins/clang/plugin.cxx @@ -200,7 +200,7 @@ Stmt* Plugin::getParentStmt( Stmt* stmt ) return const_cast<Stmt*>(parentsRange.begin()->get<Stmt>()); } -static const Decl* getFunctionDeclContext(ASTContext& context, const Stmt* stmt) +const Decl* getFunctionDeclContext(ASTContext& context, const Stmt* stmt) { auto const parents = context.getParents(*stmt); auto it = parents.begin(); diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx index bf238eb7767d..361bca922035 100644 --- a/compilerplugins/clang/plugin.hxx +++ b/compilerplugins/clang/plugin.hxx @@ -309,6 +309,8 @@ bool hasExternalLinkage(VarDecl const * decl); bool isSmartPointerType(const clang::Type*); bool isSmartPointerType(const Expr*); +const Decl* getFunctionDeclContext(ASTContext& context, const Stmt* stmt); + } // namespace #endif // COMPILEPLUGIN_H diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx index e4f3f5ba7983..6bbb35930696 100644 --- a/compilerplugins/clang/unusedfields.cxx +++ b/compilerplugins/clang/unusedfields.cxx @@ -1144,29 +1144,6 @@ bool UnusedFields::VisitDeclRefExpr( const DeclRefExpr* declRefExpr ) return true; } -static const Decl* getFunctionDeclContext(ASTContext& context, const Stmt* stmt) -{ - auto const parents = context.getParents(*stmt); - auto it = parents.begin(); - - if (it == parents.end()) - return nullptr; - - const Decl *decl = it->get<Decl>(); - if (decl) - { - if (isa<VarDecl>(decl)) - return dyn_cast<FunctionDecl>(decl->getDeclContext()); - return decl; - } - - stmt = it->get<Stmt>(); - if (stmt) - return getFunctionDeclContext(context, stmt); - - return nullptr; -} - void UnusedFields::checkTouchedFromOutside(const FieldDecl* fieldDecl, const Expr* memberExpr) { const FunctionDecl* memberExprParentFunction = getParentFunctionDecl(memberExpr); const CXXMethodDecl* methodDecl = dyn_cast_or_null<CXXMethodDecl>(memberExprParentFunction); @@ -1180,7 +1157,7 @@ void UnusedFields::checkTouchedFromOutside(const FieldDecl* fieldDecl, const Exp if (memberExprParentFunction) memberExprParentFunction->dump(); memberExpr->dump(); - const Decl *decl = getFunctionDeclContext(compiler.getASTContext(), memberExpr); + const Decl *decl = loplugin::getFunctionDeclContext(compiler.getASTContext(), memberExpr); if (decl) decl->dump(); std::cout << "site1" << std::endl; |