diff options
author | Noel Grandin <noel@peralex.com> | 2015-07-22 10:20:03 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2015-07-22 13:02:57 +0000 |
commit | 96d44c9b077a6cc8068067a795dc63248ab90fea (patch) | |
tree | 3a6df22d2df616d8c2568264e47a5219475cfc90 /compilerplugins/clang/unusedmethods.cxx | |
parent | 561cebeeba2155a7ebedbea885c9d7bf43102ec6 (diff) |
loplugin:unusedmethods sc
Change-Id: I7bdb1889a942d63370731764a58f4ab524dedd8a
Reviewed-on: https://gerrit.libreoffice.org/17287
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'compilerplugins/clang/unusedmethods.cxx')
-rw-r--r-- | compilerplugins/clang/unusedmethods.cxx | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx index 692e91e932bc..c22c1db2cbf5 100644 --- a/compilerplugins/clang/unusedmethods.cxx +++ b/compilerplugins/clang/unusedmethods.cxx @@ -74,13 +74,31 @@ public: bool VisitVarDecl( const VarDecl* ); }; -static std::string niceName(const FunctionDecl* functionDecl) +/** + * We need to include the template params when we are building the set + * of functions we have walked already, because we need to rewalk anything instantiated with different params + */ +enum class NiceNameIncludeTemplateParams { NO, YES }; +static std::string niceName(const FunctionDecl* functionDecl, NiceNameIncludeTemplateParams eIncludeTemplateParams = NiceNameIncludeTemplateParams::NO) { std::string s = compat::getReturnType(*functionDecl).getCanonicalType().getAsString() + " "; if (isa<CXXMethodDecl>(functionDecl)) { - s += dyn_cast<CXXMethodDecl>(functionDecl)->getParent()->getQualifiedNameAsString() + "::"; + const CXXRecordDecl* recordDecl = dyn_cast<CXXMethodDecl>(functionDecl)->getParent(); + s += recordDecl->getQualifiedNameAsString(); + if (eIncludeTemplateParams == NiceNameIncludeTemplateParams::YES + && isa<ClassTemplateSpecializationDecl>(recordDecl)) + { + const ClassTemplateSpecializationDecl* templateDecl = dyn_cast<ClassTemplateSpecializationDecl>(recordDecl); + s += "<"; + for(size_t i=0; i < templateDecl->getTemplateArgs().size(); i++) + { + s += " ," + templateDecl->getTemplateArgs()[i].getAsType().getAsString(); + } + s += ">"; + } + s += "::"; } s += functionDecl->getNameAsString() + "("; bool bFirst = true; @@ -164,7 +182,7 @@ bool UnusedMethods::VisitCallExpr(CallExpr* expr) // if the function is templated. However, if we are inside a template function, // calling another function on the same template, the same problem occurs. // Rather than tracking all of that, just traverse anything we have not already traversed. - if (traversedFunctionSet.insert(niceName(calleeFunctionDecl)).second) + if (traversedFunctionSet.insert(niceName(calleeFunctionDecl, NiceNameIncludeTemplateParams::YES)).second) TraverseFunctionDecl(calleeFunctionDecl); logCallToRootMethods(calleeFunctionDecl); |