diff options
author | Noel Grandin <noel@peralex.com> | 2015-07-15 13:41:11 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2015-07-16 05:47:52 +0000 |
commit | 4ca2cf1b7e57c823e911bcbae0c87102a7c9851e (patch) | |
tree | 28725536883828d5d7af2cb8a4e7733968888d9d /compilerplugins/clang | |
parent | Translate German comments (diff) | |
download | core-4ca2cf1b7e57c823e911bcbae0c87102a7c9851e.tar.gz core-4ca2cf1b7e57c823e911bcbae0c87102a7c9851e.zip |
loplugin:unusedmethods sfx2
Change-Id: I98c455d89f76fbcacf74929a4e8775b4da697f62
Reviewed-on: https://gerrit.libreoffice.org/17069
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r-- | compilerplugins/clang/unusedmethods.cxx | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx index 782c1b395e30..6d0303dbf56f 100644 --- a/compilerplugins/clang/unusedmethods.cxx +++ b/compilerplugins/clang/unusedmethods.cxx @@ -35,8 +35,6 @@ to get it to work :-) TODO deal with calls to superclass/member constructors from other constructors, so we can find unused constructors -TODO need to handle places where the code takes the address of a method, that needs to count - as a use-site. TODO deal with free functions and static methods TODO track instantiations of template class constructor methods TODO track instantiation of overridden methods when a template class is instantiated @@ -142,9 +140,12 @@ static std::set<std::string> traversedFunctionSet; bool UnusedMethods::VisitCallExpr(CallExpr* expr) { - if (ignoreLocation(expr)) { + // I don't use the normal ignoreLocation() here, because I __want__ to include files that are + // compiled in the $WORKDIR since they may refer to normal code + SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( expr->getLocStart() ); + if( compiler.getSourceManager().isInSystemHeader( expansionLoc )) return true; - } + FunctionDecl* calleeFunctionDecl = expr->getDirectCallee(); if (calleeFunctionDecl == nullptr) { return true; @@ -166,9 +167,12 @@ bool UnusedMethods::VisitCallExpr(CallExpr* expr) bool UnusedMethods::VisitCXXMethodDecl( const CXXMethodDecl* functionDecl ) { - if (ignoreLocation(functionDecl)) { + // I don't use the normal ignoreLocation() here, because I __want__ to include files that are + // compiled in the $WORKDIR since they may refer to normal code + SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( functionDecl->getLocStart() ); + if( compiler.getSourceManager().isInSystemHeader( expansionLoc )) return true; - } + functionDecl = functionDecl->getCanonicalDecl(); // ignore method overrides, since the call will show up as being directed to the root method if (functionDecl->size_overridden_methods() != 0 || functionDecl->hasAttr<OverrideAttr>()) { @@ -203,14 +207,17 @@ bool UnusedMethods::VisitCXXMethodDecl( const CXXMethodDecl* functionDecl ) // this catches places that take the address of a method bool UnusedMethods::VisitDeclRefExpr( const DeclRefExpr* declRefExpr ) { - if (ignoreLocation(declRefExpr)) { + // I don't use the normal ignoreLocation() here, because I __want__ to include files that are + // compiled in the $WORKDIR since they may refer to normal code + SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( declRefExpr->getLocStart() ); + if( compiler.getSourceManager().isInSystemHeader( expansionLoc )) return true; - } + const Decl* functionDecl = declRefExpr->getDecl(); if (!isa<CXXMethodDecl>(functionDecl)) { return true; } - logCallToRootMethods(dyn_cast<CXXMethodDecl>(functionDecl)); + logCallToRootMethods(dyn_cast<CXXMethodDecl>(functionDecl)->getCanonicalDecl()); return true; } |