Kaydet (Commit) 40fd53a2 authored tarafından Noel Grandin's avatar Noel Grandin

loplugins: extract some common functionality

Change-Id: If470e1d9b481c9eda0829aa985152baf8fb46d7a
üst 9d8d2e07
...@@ -100,7 +100,7 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde ...@@ -100,7 +100,7 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde
if (ignoreLocation(functionDecl)) if (ignoreLocation(functionDecl))
return; return;
// ignore stuff that forms part of the stable URE interface // ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(functionDecl->getLocation()))) if (isInUnoIncludeFile(functionDecl))
return; return;
SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( functionDecl->getLocation() ); SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( functionDecl->getLocation() );
StringRef filename = compiler.getSourceManager().getFilename(expansionLoc); StringRef filename = compiler.getSourceManager().getFilename(expansionLoc);
......
...@@ -52,8 +52,7 @@ bool ConstParams::VisitFunctionDecl(FunctionDecl * functionDecl) ...@@ -52,8 +52,7 @@ bool ConstParams::VisitFunctionDecl(FunctionDecl * functionDecl)
return true; return true;
} }
// ignore stuff that forms part of the stable URE interface // ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( if (isInUnoIncludeFile(functionDecl)) {
functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) {
return true; return true;
} }
// TODO ignore these for now, requires some extra work // TODO ignore these for now, requires some extra work
......
...@@ -234,8 +234,7 @@ bool CountUsersOfDefaultParams::VisitFunctionDecl( const FunctionDecl* functionD ...@@ -234,8 +234,7 @@ bool CountUsersOfDefaultParams::VisitFunctionDecl( const FunctionDecl* functionD
return true; return true;
} }
// ignore stuff that forms part of the stable URE interface // ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( if (isInUnoIncludeFile(functionDecl)) {
functionDecl->getNameInfo().getLoc()))) {
return true; return true;
} }
if (isa<CXXDestructorDecl>(functionDecl)) { if (isa<CXXDestructorDecl>(functionDecl)) {
......
...@@ -293,8 +293,7 @@ void InlineableMethods::functionTouchedFromExpr( const FunctionDecl* calleeFunct ...@@ -293,8 +293,7 @@ void InlineableMethods::functionTouchedFromExpr( const FunctionDecl* calleeFunct
bool InlineableMethods::isCalleeFunctionInteresting(const FunctionDecl* functionDecl) bool InlineableMethods::isCalleeFunctionInteresting(const FunctionDecl* functionDecl)
{ {
// ignore stuff that forms part of the stable URE interface // ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( if (isInUnoIncludeFile(functionDecl)) {
functionDecl->getNameInfo().getLoc()))) {
return false; return false;
} }
if (isa<CXXDestructorDecl>(functionDecl)) { if (isa<CXXDestructorDecl>(functionDecl)) {
......
...@@ -71,8 +71,7 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct ...@@ -71,8 +71,7 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct
return true; return true;
} }
// ignore stuff that forms part of the stable URE interface // ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( if (isInUnoIncludeFile(functionDecl)) {
functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) {
return true; return true;
} }
// ignore stuff like: // ignore stuff like:
......
...@@ -205,8 +205,7 @@ void PassStuffByRef::checkParams(const FunctionDecl * functionDecl) { ...@@ -205,8 +205,7 @@ void PassStuffByRef::checkParams(const FunctionDecl * functionDecl) {
} }
} }
// ignore stuff that forms part of the stable URE interface // ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( if (isInUnoIncludeFile(functionDecl)) {
functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) {
return; return;
} }
// these functions are passed as parameters to another function // these functions are passed as parameters to another function
...@@ -245,8 +244,7 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C ...@@ -245,8 +244,7 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C
} }
// ignore stuff that forms part of the stable URE interface // ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( if (isInUnoIncludeFile(functionDecl)) {
functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) {
return; return;
} }
loplugin::DeclCheck dc(functionDecl); loplugin::DeclCheck dc(functionDecl);
......
...@@ -170,6 +170,11 @@ bool Plugin::isInUnoIncludeFile(SourceLocation spellingLocation) const { ...@@ -170,6 +170,11 @@ bool Plugin::isInUnoIncludeFile(SourceLocation spellingLocation) const {
|| name.startswith(WORKDIR "/")); || name.startswith(WORKDIR "/"));
} }
bool Plugin::isInUnoIncludeFile(const FunctionDecl* functionDecl) const {
return isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(
functionDecl->getCanonicalDecl()->getNameInfo().getLoc()));
}
namespace namespace
{ {
class ParentBuilder class ParentBuilder
......
...@@ -75,6 +75,7 @@ class Plugin ...@@ -75,6 +75,7 @@ class Plugin
which is not allowed to be changed. which is not allowed to be changed.
*/ */
bool isInUnoIncludeFile(SourceLocation spellingLocation) const; bool isInUnoIncludeFile(SourceLocation spellingLocation) const;
bool isInUnoIncludeFile(const FunctionDecl*) const;
static void normalizeDotDotInFilePath(std::string&); static void normalizeDotDotInFilePath(std::string&);
private: private:
......
...@@ -479,9 +479,7 @@ bool SalBool::VisitParmVarDecl(ParmVarDecl const * decl) { ...@@ -479,9 +479,7 @@ bool SalBool::VisitParmVarDecl(ParmVarDecl const * decl) {
if (f != nullptr) { // e.g.: typedef sal_Bool (* FuncPtr )( sal_Bool ); if (f != nullptr) { // e.g.: typedef sal_Bool (* FuncPtr )( sal_Bool );
f = f->getCanonicalDecl(); f = f->getCanonicalDecl();
if (!(hasCLanguageLinkageType(f) if (!(hasCLanguageLinkageType(f)
|| (isInUnoIncludeFile( || (isInUnoIncludeFile(f)
compiler.getSourceManager().getSpellingLoc(
f->getNameInfo().getLoc()))
&& (!f->isInlined() || f->hasAttr<DeprecatedAttr>() && (!f->isInlined() || f->hasAttr<DeprecatedAttr>()
|| decl->getType()->isReferenceType() || decl->getType()->isReferenceType()
|| hasBoolOverload(f, false))) || hasBoolOverload(f, false)))
...@@ -654,9 +652,7 @@ bool SalBool::VisitFunctionDecl(FunctionDecl const * decl) { ...@@ -654,9 +652,7 @@ bool SalBool::VisitFunctionDecl(FunctionDecl const * decl) {
OverrideKind k = getOverrideKind(f); OverrideKind k = getOverrideKind(f);
if (k != OverrideKind::YES if (k != OverrideKind::YES
&& !(hasCLanguageLinkageType(f) && !(hasCLanguageLinkageType(f)
|| (isInUnoIncludeFile( || (isInUnoIncludeFile(f)
compiler.getSourceManager().getSpellingLoc(
f->getNameInfo().getLoc()))
&& (!f->isInlined() || f->hasAttr<DeprecatedAttr>())))) && (!f->isInlined() || f->hasAttr<DeprecatedAttr>()))))
{ {
SourceLocation loc { decl->getLocStart() }; SourceLocation loc { decl->getLocStart() };
......
...@@ -87,7 +87,7 @@ bool StaticMethods::TraverseCXXMethodDecl(const CXXMethodDecl * pCXXMethodDecl) ...@@ -87,7 +87,7 @@ bool StaticMethods::TraverseCXXMethodDecl(const CXXMethodDecl * pCXXMethodDecl)
if (isa<CXXConstructorDecl>(pCXXMethodDecl) || isa<CXXDestructorDecl>(pCXXMethodDecl) || isa<CXXConversionDecl>(pCXXMethodDecl)) { if (isa<CXXConstructorDecl>(pCXXMethodDecl) || isa<CXXDestructorDecl>(pCXXMethodDecl) || isa<CXXConversionDecl>(pCXXMethodDecl)) {
return true; return true;
} }
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(pCXXMethodDecl->getCanonicalDecl()->getNameInfo().getLoc()))) { if (isInUnoIncludeFile(pCXXMethodDecl)) {
return true; return true;
} }
if ( pCXXMethodDecl != pCXXMethodDecl->getCanonicalDecl() ) { if ( pCXXMethodDecl != pCXXMethodDecl->getCanonicalDecl() ) {
......
...@@ -152,7 +152,7 @@ bool ConstantFunction::VisitFunctionDecl(const FunctionDecl * pFunctionDecl) { ...@@ -152,7 +152,7 @@ bool ConstantFunction::VisitFunctionDecl(const FunctionDecl * pFunctionDecl) {
return true; return true;
} }
SourceLocation canonicalLoc = pFunctionDecl->getCanonicalDecl()->getNameInfo().getLoc(); SourceLocation canonicalLoc = pFunctionDecl->getCanonicalDecl()->getNameInfo().getLoc();
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(canonicalLoc))) { if (isInUnoIncludeFile(pFunctionDecl)) {
return true; return true;
} }
......
...@@ -97,8 +97,7 @@ bool RemoveVirtuals::VisitCXXMethodDecl( const CXXMethodDecl* functionDecl ) ...@@ -97,8 +97,7 @@ bool RemoveVirtuals::VisitCXXMethodDecl( const CXXMethodDecl* functionDecl )
return true; return true;
} }
// ignore stuff that forms part of the stable URE interface // ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( if (isInUnoIncludeFile(functionDecl)) {
functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) {
return true; return true;
} }
......
...@@ -52,8 +52,7 @@ bool ReturnByRef::VisitCXXMethodDecl(const CXXMethodDecl * functionDecl) { ...@@ -52,8 +52,7 @@ bool ReturnByRef::VisitCXXMethodDecl(const CXXMethodDecl * functionDecl) {
return true; return true;
} }
// ignore stuff that forms part of the stable URE interface // ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( if (isInUnoIncludeFile(functionDecl)) {
functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) {
return true; return true;
} }
QualType t1 { compat::getReturnType(*functionDecl) }; QualType t1 { compat::getReturnType(*functionDecl) };
......
...@@ -154,8 +154,7 @@ bool UnnecessaryVirtual::VisitCXXMethodDecl( const CXXMethodDecl* methodDecl ) ...@@ -154,8 +154,7 @@ bool UnnecessaryVirtual::VisitCXXMethodDecl( const CXXMethodDecl* methodDecl )
} }
if (methodDecl->size_overridden_methods() == 0) { if (methodDecl->size_overridden_methods() == 0) {
// ignore stuff that forms part of the stable URE interface // ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( if (isInUnoIncludeFile(methodDecl)) {
methodDecl->getNameInfo().getLoc()))) {
return true; return true;
} }
// ignore templates and template instantiations, // ignore templates and template instantiations,
......
...@@ -112,9 +112,7 @@ bool UnrefFun::VisitFunctionDecl(FunctionDecl const * decl) { ...@@ -112,9 +112,7 @@ bool UnrefFun::VisitFunctionDecl(FunctionDecl const * decl) {
|| !(canon->isDefined() || !(canon->isDefined()
? decl->isThisDeclarationADefinition() : decl->isFirstDecl()) ? decl->isThisDeclarationADefinition() : decl->isFirstDecl())
|| !compiler.getSourceManager().isInMainFile(canon->getLocation()) || !compiler.getSourceManager().isInMainFile(canon->getLocation())
|| isInUnoIncludeFile( || isInUnoIncludeFile(canon)
compiler.getSourceManager().getSpellingLoc(
canon->getNameInfo().getLoc()))
|| canon->isMain() || canon->isMain()
|| (decl->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate || (decl->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate
&& (decl->getDescribedFunctionTemplate()->spec_begin() && (decl->getDescribedFunctionTemplate()->spec_begin()
......
...@@ -312,12 +312,11 @@ bool UnusedMethods::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr ...@@ -312,12 +312,11 @@ bool UnusedMethods::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr
bool UnusedMethods::VisitFunctionDecl( const FunctionDecl* functionDecl ) bool UnusedMethods::VisitFunctionDecl( const FunctionDecl* functionDecl )
{ {
const FunctionDecl* canonicalFunctionDecl = functionDecl->getCanonicalDecl();
// ignore stuff that forms part of the stable URE interface // ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( if (isInUnoIncludeFile(functionDecl)) {
canonicalFunctionDecl->getNameInfo().getLoc()))) {
return true; return true;
} }
const FunctionDecl* canonicalFunctionDecl = functionDecl->getCanonicalDecl();
if (isa<CXXDestructorDecl>(functionDecl)) { if (isa<CXXDestructorDecl>(functionDecl)) {
return true; return true;
} }
......
...@@ -102,8 +102,7 @@ bool UnusedMethodsRemove::VisitCXXMethodDecl( const CXXMethodDecl* functionDecl ...@@ -102,8 +102,7 @@ bool UnusedMethodsRemove::VisitCXXMethodDecl( const CXXMethodDecl* functionDecl
return true; return true;
} }
// ignore stuff that forms part of the stable URE interface // ignore stuff that forms part of the stable URE interface
if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc( if (isInUnoIncludeFile(functionDecl)) {
functionDecl->getCanonicalDecl()->getNameInfo().getLoc()))) {
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment