[Libreoffice-commits] core.git: compilerplugins/clang

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Mon May 25 13:46:52 UTC 2020


 compilerplugins/clang/plugin.cxx       |    2 +-
 compilerplugins/clang/plugin.hxx       |    2 ++
 compilerplugins/clang/unusedfields.cxx |   25 +------------------------
 3 files changed, 4 insertions(+), 25 deletions(-)

New commits:
commit cc146f7a12ee0c0e829d2827117558f9cba11858
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Mon May 25 13:29:30 2020 +0200
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Mon May 25 15:46:01 2020 +0200

    Code duplication
    
    Change-Id: I1af2948e0332044ef88bc7dbd837e8c7afe7af19
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94785
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

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;


More information about the Libreoffice-commits mailing list