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

Noel Grandin noel.grandin at collabora.co.uk
Tue Nov 28 06:32:03 UTC 2017


 compilerplugins/clang/unusedmethods.cxx |   43 +++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

New commits:
commit ac50f685c7cf77fdc6ad9bac4030bfa82c5ce29b
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Nov 27 21:58:12 2017 +0200

    loplugin:unusedmethods ignore recursive calls
    
    Change-Id: I651a7bf0c705acc5580af8b7742d2d035ec64388

diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx
index ef681f12c561..e33bb0c01c0a 100644
--- a/compilerplugins/clang/unusedmethods.cxx
+++ b/compilerplugins/clang/unusedmethods.cxx
@@ -115,12 +115,17 @@ public:
     bool VisitDeclRefExpr( const DeclRefExpr* );
     bool VisitCXXConstructExpr( const CXXConstructExpr* );
     bool TraverseCXXRecordDecl( CXXRecordDecl* );
+    bool TraverseFunctionDecl( FunctionDecl* );
+    bool TraverseCXXMethodDecl( CXXMethodDecl* );
+    bool TraverseCXXConversionDecl( CXXConversionDecl* );
+    bool TraverseCXXDeductionGuideDecl( CXXDeductionGuideDecl* );
 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;
+    FunctionDecl const * currentFunctionDecl = nullptr;
 };
 
 MyFuncInfo UnusedMethods::niceName(const FunctionDecl* functionDecl)
@@ -227,7 +232,10 @@ bool UnusedMethods::VisitCallExpr(CallExpr* expr)
     }
 
 gotfunc:
-    logCallToRootMethods(calleeFunctionDecl, callSet);
+
+    // for "unused method" analysis, ignore recursive calls
+    if (currentFunctionDecl != calleeFunctionDecl)
+        logCallToRootMethods(calleeFunctionDecl, callSet);
 
     const Stmt* parent = getParentStmt(expr);
 
@@ -356,6 +364,39 @@ bool UnusedMethods::TraverseCXXRecordDecl(CXXRecordDecl* cxxRecordDecl)
     return ret;
 }
 
+bool UnusedMethods::TraverseFunctionDecl(FunctionDecl* f)
+{
+    auto copy = currentFunctionDecl;
+    currentFunctionDecl = f;
+    bool ret = RecursiveASTVisitor::TraverseFunctionDecl(f);
+    currentFunctionDecl = copy;
+    return ret;
+}
+bool UnusedMethods::TraverseCXXMethodDecl(CXXMethodDecl* f)
+{
+    auto copy = currentFunctionDecl;
+    currentFunctionDecl = f;
+    bool ret = RecursiveASTVisitor::TraverseCXXMethodDecl(f);
+    currentFunctionDecl = copy;
+    return ret;
+}
+bool UnusedMethods::TraverseCXXConversionDecl(CXXConversionDecl* f)
+{
+    auto copy = currentFunctionDecl;
+    currentFunctionDecl = f;
+    bool ret = RecursiveASTVisitor::TraverseCXXConversionDecl(f);
+    currentFunctionDecl = copy;
+    return ret;
+}
+bool UnusedMethods::TraverseCXXDeductionGuideDecl(CXXDeductionGuideDecl* f)
+{
+    auto copy = currentFunctionDecl;
+    currentFunctionDecl = f;
+    bool ret = RecursiveASTVisitor::TraverseCXXDeductionGuideDecl(f);
+    currentFunctionDecl = copy;
+    return ret;
+}
+
 loplugin::Plugin::Registration< UnusedMethods > X("unusedmethods", false);
 
 }


More information about the Libreoffice-commits mailing list