From 40fd53a2383ba353054ed440c45f2319a9b8efef Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 18 Oct 2016 08:15:21 +0200 Subject: loplugins: extract some common functionality Change-Id: If470e1d9b481c9eda0829aa985152baf8fb46d7a --- compilerplugins/clang/constantparam.cxx | 2 +- compilerplugins/clang/constparams.cxx | 3 +-- compilerplugins/clang/countusersofdefaultparams.cxx | 3 +-- compilerplugins/clang/inlineablemethods.cxx | 3 +-- compilerplugins/clang/inlinesimplememberfunctions.cxx | 3 +-- compilerplugins/clang/passstuffbyref.cxx | 6 ++---- compilerplugins/clang/plugin.cxx | 5 +++++ compilerplugins/clang/plugin.hxx | 1 + compilerplugins/clang/salbool.cxx | 8 ++------ compilerplugins/clang/staticmethods.cxx | 2 +- compilerplugins/clang/store/constantfunction.cxx | 2 +- compilerplugins/clang/store/removevirtuals.cxx | 3 +-- compilerplugins/clang/store/returnbyref.cxx | 3 +-- compilerplugins/clang/unnecessaryvirtual.cxx | 3 +-- compilerplugins/clang/unreffun.cxx | 4 +--- compilerplugins/clang/unusedmethods.cxx | 5 ++--- compilerplugins/clang/unusedmethodsremove.cxx | 3 +-- 17 files changed, 24 insertions(+), 35 deletions(-) diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx index 550cdd16499e..f5a3d5317dd1 100644 --- a/compilerplugins/clang/constantparam.cxx +++ b/compilerplugins/clang/constantparam.cxx @@ -100,7 +100,7 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde if (ignoreLocation(functionDecl)) return; // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(functionDecl->getLocation()))) + if (isInUnoIncludeFile(functionDecl)) return; SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( functionDecl->getLocation() ); StringRef filename = compiler.getSourceManager().getFilename(expansionLoc); diff --git a/compilerplugins/clang/constparams.cxx b/compilerplugins/clang/constparams.cxx index 291a4e7db4d2..52f1ffe12e19 100644 --- a/compilerplugins/clang/constparams.cxx +++ b/compilerplugins/clang/constparams.cxx @@ -52,8 +52,7 @@ bool ConstParams::VisitFunctionDecl(FunctionDecl * functionDecl) return true; } // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( - functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) { + if (isInUnoIncludeFile(functionDecl)) { return true; } // TODO ignore these for now, requires some extra work diff --git a/compilerplugins/clang/countusersofdefaultparams.cxx b/compilerplugins/clang/countusersofdefaultparams.cxx index b6323d054bd0..d17377bc6bd6 100644 --- a/compilerplugins/clang/countusersofdefaultparams.cxx +++ b/compilerplugins/clang/countusersofdefaultparams.cxx @@ -234,8 +234,7 @@ bool CountUsersOfDefaultParams::VisitFunctionDecl( const FunctionDecl* functionD return true; } // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( - functionDecl->getNameInfo().getLoc()))) { + if (isInUnoIncludeFile(functionDecl)) { return true; } if (isa(functionDecl)) { diff --git a/compilerplugins/clang/inlineablemethods.cxx b/compilerplugins/clang/inlineablemethods.cxx index 032853be326e..c9feb7595110 100644 --- a/compilerplugins/clang/inlineablemethods.cxx +++ b/compilerplugins/clang/inlineablemethods.cxx @@ -293,8 +293,7 @@ void InlineableMethods::functionTouchedFromExpr( const FunctionDecl* calleeFunct bool InlineableMethods::isCalleeFunctionInteresting(const FunctionDecl* functionDecl) { // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( - functionDecl->getNameInfo().getLoc()))) { + if (isInUnoIncludeFile(functionDecl)) { return false; } if (isa(functionDecl)) { diff --git a/compilerplugins/clang/inlinesimplememberfunctions.cxx b/compilerplugins/clang/inlinesimplememberfunctions.cxx index b1515382205a..9048bb4fe480 100644 --- a/compilerplugins/clang/inlinesimplememberfunctions.cxx +++ b/compilerplugins/clang/inlinesimplememberfunctions.cxx @@ -71,8 +71,7 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct return true; } // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( - functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) { + if (isInUnoIncludeFile(functionDecl)) { return true; } // ignore stuff like: diff --git a/compilerplugins/clang/passstuffbyref.cxx b/compilerplugins/clang/passstuffbyref.cxx index b1b3169f94c9..ad6c10018fdf 100644 --- a/compilerplugins/clang/passstuffbyref.cxx +++ b/compilerplugins/clang/passstuffbyref.cxx @@ -205,8 +205,7 @@ void PassStuffByRef::checkParams(const FunctionDecl * functionDecl) { } } // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( - functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) { + if (isInUnoIncludeFile(functionDecl)) { return; } // these functions are passed as parameters to another function @@ -245,8 +244,7 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C } // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( - functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) { + if (isInUnoIncludeFile(functionDecl)) { return; } loplugin::DeclCheck dc(functionDecl); diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx index 3507371c0ab5..dc48101f6e13 100644 --- a/compilerplugins/clang/plugin.cxx +++ b/compilerplugins/clang/plugin.cxx @@ -170,6 +170,11 @@ bool Plugin::isInUnoIncludeFile(SourceLocation spellingLocation) const { || name.startswith(WORKDIR "/")); } +bool Plugin::isInUnoIncludeFile(const FunctionDecl* functionDecl) const { + return isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( + functionDecl->getCanonicalDecl()->getNameInfo().getLoc())); +} + namespace { class ParentBuilder diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx index 635dcfe4c0d3..6248ef705134 100644 --- a/compilerplugins/clang/plugin.hxx +++ b/compilerplugins/clang/plugin.hxx @@ -75,6 +75,7 @@ class Plugin which is not allowed to be changed. */ bool isInUnoIncludeFile(SourceLocation spellingLocation) const; + bool isInUnoIncludeFile(const FunctionDecl*) const; static void normalizeDotDotInFilePath(std::string&); private: diff --git a/compilerplugins/clang/salbool.cxx b/compilerplugins/clang/salbool.cxx index 040512c35780..a443234e779c 100644 --- a/compilerplugins/clang/salbool.cxx +++ b/compilerplugins/clang/salbool.cxx @@ -479,9 +479,7 @@ bool SalBool::VisitParmVarDecl(ParmVarDecl const * decl) { if (f != nullptr) { // e.g.: typedef sal_Bool (* FuncPtr )( sal_Bool ); f = f->getCanonicalDecl(); if (!(hasCLanguageLinkageType(f) - || (isInUnoIncludeFile( - compiler.getSourceManager().getSpellingLoc( - f->getNameInfo().getLoc())) + || (isInUnoIncludeFile(f) && (!f->isInlined() || f->hasAttr() || decl->getType()->isReferenceType() || hasBoolOverload(f, false))) @@ -654,9 +652,7 @@ bool SalBool::VisitFunctionDecl(FunctionDecl const * decl) { OverrideKind k = getOverrideKind(f); if (k != OverrideKind::YES && !(hasCLanguageLinkageType(f) - || (isInUnoIncludeFile( - compiler.getSourceManager().getSpellingLoc( - f->getNameInfo().getLoc())) + || (isInUnoIncludeFile(f) && (!f->isInlined() || f->hasAttr())))) { SourceLocation loc { decl->getLocStart() }; diff --git a/compilerplugins/clang/staticmethods.cxx b/compilerplugins/clang/staticmethods.cxx index 5b88d0c1851c..588e534c482c 100644 --- a/compilerplugins/clang/staticmethods.cxx +++ b/compilerplugins/clang/staticmethods.cxx @@ -87,7 +87,7 @@ bool StaticMethods::TraverseCXXMethodDecl(const CXXMethodDecl * pCXXMethodDecl) if (isa(pCXXMethodDecl) || isa(pCXXMethodDecl) || isa(pCXXMethodDecl)) { return true; } - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(pCXXMethodDecl->getCanonicalDecl()->getNameInfo().getLoc()))) { + if (isInUnoIncludeFile(pCXXMethodDecl)) { return true; } if ( pCXXMethodDecl != pCXXMethodDecl->getCanonicalDecl() ) { diff --git a/compilerplugins/clang/store/constantfunction.cxx b/compilerplugins/clang/store/constantfunction.cxx index 943cc7d87606..cd14c48d981a 100644 --- a/compilerplugins/clang/store/constantfunction.cxx +++ b/compilerplugins/clang/store/constantfunction.cxx @@ -152,7 +152,7 @@ bool ConstantFunction::VisitFunctionDecl(const FunctionDecl * pFunctionDecl) { return true; } SourceLocation canonicalLoc = pFunctionDecl->getCanonicalDecl()->getNameInfo().getLoc(); - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(canonicalLoc))) { + if (isInUnoIncludeFile(pFunctionDecl)) { return true; } diff --git a/compilerplugins/clang/store/removevirtuals.cxx b/compilerplugins/clang/store/removevirtuals.cxx index da204d393b43..6ed3dd60e191 100644 --- a/compilerplugins/clang/store/removevirtuals.cxx +++ b/compilerplugins/clang/store/removevirtuals.cxx @@ -97,8 +97,7 @@ bool RemoveVirtuals::VisitCXXMethodDecl( const CXXMethodDecl* functionDecl ) return true; } // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( - functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) { + if (isInUnoIncludeFile(functionDecl)) { return true; } diff --git a/compilerplugins/clang/store/returnbyref.cxx b/compilerplugins/clang/store/returnbyref.cxx index d5052d685312..aacfd7d833cf 100644 --- a/compilerplugins/clang/store/returnbyref.cxx +++ b/compilerplugins/clang/store/returnbyref.cxx @@ -52,8 +52,7 @@ bool ReturnByRef::VisitCXXMethodDecl(const CXXMethodDecl * functionDecl) { return true; } // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( - functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) { + if (isInUnoIncludeFile(functionDecl)) { return true; } QualType t1 { compat::getReturnType(*functionDecl) }; diff --git a/compilerplugins/clang/unnecessaryvirtual.cxx b/compilerplugins/clang/unnecessaryvirtual.cxx index 940321309bae..1ecc47114a0b 100644 --- a/compilerplugins/clang/unnecessaryvirtual.cxx +++ b/compilerplugins/clang/unnecessaryvirtual.cxx @@ -154,8 +154,7 @@ bool UnnecessaryVirtual::VisitCXXMethodDecl( const CXXMethodDecl* methodDecl ) } if (methodDecl->size_overridden_methods() == 0) { // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( - methodDecl->getNameInfo().getLoc()))) { + if (isInUnoIncludeFile(methodDecl)) { return true; } // ignore templates and template instantiations, diff --git a/compilerplugins/clang/unreffun.cxx b/compilerplugins/clang/unreffun.cxx index bf381f9f07fc..0284d36ef87c 100644 --- a/compilerplugins/clang/unreffun.cxx +++ b/compilerplugins/clang/unreffun.cxx @@ -112,9 +112,7 @@ bool UnrefFun::VisitFunctionDecl(FunctionDecl const * decl) { || !(canon->isDefined() ? decl->isThisDeclarationADefinition() : decl->isFirstDecl()) || !compiler.getSourceManager().isInMainFile(canon->getLocation()) - || isInUnoIncludeFile( - compiler.getSourceManager().getSpellingLoc( - canon->getNameInfo().getLoc())) + || isInUnoIncludeFile(canon) || canon->isMain() || (decl->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate && (decl->getDescribedFunctionTemplate()->spec_begin() diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx index 80af02484a32..c26538122c6a 100644 --- a/compilerplugins/clang/unusedmethods.cxx +++ b/compilerplugins/clang/unusedmethods.cxx @@ -312,12 +312,11 @@ bool UnusedMethods::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr bool UnusedMethods::VisitFunctionDecl( const FunctionDecl* functionDecl ) { - const FunctionDecl* canonicalFunctionDecl = functionDecl->getCanonicalDecl(); // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( - canonicalFunctionDecl->getNameInfo().getLoc()))) { + if (isInUnoIncludeFile(functionDecl)) { return true; } + const FunctionDecl* canonicalFunctionDecl = functionDecl->getCanonicalDecl(); if (isa(functionDecl)) { return true; } diff --git a/compilerplugins/clang/unusedmethodsremove.cxx b/compilerplugins/clang/unusedmethodsremove.cxx index 273b4153c325..09187edfc7c0 100644 --- a/compilerplugins/clang/unusedmethodsremove.cxx +++ b/compilerplugins/clang/unusedmethodsremove.cxx @@ -102,8 +102,7 @@ bool UnusedMethodsRemove::VisitCXXMethodDecl( const CXXMethodDecl* functionDecl return true; } // ignore stuff that forms part of the stable URE interface - if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( - functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) { + if (isInUnoIncludeFile(functionDecl)) { return true; } -- cgit v1.2.3