diff options
Diffstat (limited to 'compilerplugins/clang/referencecasting.cxx')
-rw-r--r-- | compilerplugins/clang/referencecasting.cxx | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/compilerplugins/clang/referencecasting.cxx b/compilerplugins/clang/referencecasting.cxx index 496654237b7d..cff5b050ea9f 100644 --- a/compilerplugins/clang/referencecasting.cxx +++ b/compilerplugins/clang/referencecasting.cxx @@ -10,9 +10,9 @@ */ #ifndef LO_CLANG_SHARED_PLUGINS -#include "compat.hxx" #include "plugin.hxx" #include "check.hxx" +#include "config_clang.h" #include <iostream> /* @@ -78,7 +78,7 @@ bool ReferenceCasting::VisitInitListExpr(const InitListExpr* ile) { if (CheckForUnnecessaryGet(expr, /*includeRtlReference*/ true)) { - report(DiagnosticsEngine::Warning, "unnecessary get() call", compat::getBeginLoc(expr)) + report(DiagnosticsEngine::Warning, "unnecessary get() call", expr->getBeginLoc()) << expr->getSourceRange(); return true; } @@ -90,8 +90,8 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) if (ignoreLocation(cce)) return true; // don't bother processing anything in the Reference.h file. Makes my life easier when debugging this. - StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(cce))); + StringRef aFileName + = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(cce->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.h")) return true; if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.hxx")) @@ -112,7 +112,7 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) if (CheckForUnnecessaryGet(cce->getArg(0), /*includeRtlReference*/ cce->getNumArgs() == 1)) { report(DiagnosticsEngine::Warning, "unnecessary get() call", - compat::getBeginLoc(cce->getArg(0))) + cce->getArg(0)->getBeginLoc()) << cce->getArg(0)->getSourceRange(); return true; } @@ -120,7 +120,7 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) if (CheckForUnnecessaryGet(cce->getArg(0), /*includeRtlReference*/ true)) { report(DiagnosticsEngine::Warning, "unnecessary get() call", - compat::getBeginLoc(cce->getArg(0))) + cce->getArg(0)->getBeginLoc()) << cce->getArg(0)->getSourceRange(); return true; } @@ -132,7 +132,7 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) // ignore the up-casting constructor, which has a std::enable_if second parameter if (isUnoReference && cce->getNumArgs() == 2 - && !isa<EnumType>(cce->getConstructor()->getParamDecl(1)->getType())) + && !cce->getConstructor()->getParamDecl(1)->getType()->isEnumeralType()) return true; // extract the type parameter passed to the template @@ -151,12 +151,12 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) { if (auto castExpr = dyn_cast<CastExpr>(constructorArg0)) { - constructorArg0 = castExpr->getSubExpr(); + constructorArg0 = castExpr->getSubExprAsWritten(); continue; } if (auto matTempExpr = dyn_cast<MaterializeTemporaryExpr>(constructorArg0)) { - constructorArg0 = compat::getSubExpr(matTempExpr); + constructorArg0 = matTempExpr->getSubExpr(); continue; } if (auto bindTempExpr = dyn_cast<CXXBindTemporaryExpr>(constructorArg0)) @@ -174,6 +174,15 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) constructorArg0 = parenExpr->getSubExpr(); continue; } + // for the "uno::Reference<X>(*this, UNO_QUERY)" case + if (auto unaryOper = dyn_cast<UnaryOperator>(constructorArg0)) + { + if (unaryOper->getOpcode() == UO_Deref) + { + constructorArg0 = unaryOper->getSubExpr(); + continue; + } + } argType = constructorArg0->getType(); break; } @@ -215,7 +224,7 @@ bool ReferenceCasting::VisitCXXConstructExpr(const CXXConstructExpr* cce) { report(DiagnosticsEngine::Warning, "the source reference is already a subtype of the destination reference, just use =", - compat::getBeginLoc(cce)) + cce->getBeginLoc()) << cce->getSourceRange(); } return true; @@ -226,8 +235,8 @@ bool ReferenceCasting::VisitCXXMemberCallExpr(const CXXMemberCallExpr* mce) if (ignoreLocation(mce)) return true; // don't bother processing anything in the Reference.h file. Makes my life easier when debugging this. - StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(mce))); + StringRef aFileName + = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(mce->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.h")) return true; if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.hxx")) @@ -248,8 +257,7 @@ bool ReferenceCasting::VisitCXXMemberCallExpr(const CXXMemberCallExpr* mce) if (CheckForUnnecessaryGet(mce->getArg(0), /*includeRtlReference*/ mce->getNumArgs() == 1)) { - report(DiagnosticsEngine::Warning, "unnecessary get() call", - compat::getBeginLoc(mce->getArg(0))) + report(DiagnosticsEngine::Warning, "unnecessary get() call", mce->getArg(0)->getBeginLoc()) << mce->getArg(0)->getSourceRange(); return true; } @@ -279,7 +287,7 @@ bool ReferenceCasting::VisitCXXMemberCallExpr(const CXXMemberCallExpr* mce) } if (auto matTempExpr = dyn_cast<MaterializeTemporaryExpr>(arg0)) { - arg0 = compat::getSubExpr(matTempExpr); + arg0 = matTempExpr->getSubExpr(); continue; } if (auto bindTempExpr = dyn_cast<CXXBindTemporaryExpr>(arg0)) @@ -337,7 +345,7 @@ bool ReferenceCasting::VisitCXXMemberCallExpr(const CXXMemberCallExpr* mce) { report(DiagnosticsEngine::Warning, "the source reference is already a subtype of the destination reference, just use =", - compat::getBeginLoc(mce)) + mce->getBeginLoc()) << mce->getSourceRange(); } return true; @@ -348,8 +356,8 @@ bool ReferenceCasting::VisitCallExpr(const CallExpr* ce) if (ignoreLocation(ce)) return true; // don't bother processing anything in the Reference.h file. Makes my life easier when debugging this. - StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(ce))); + StringRef aFileName + = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(ce->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.h")) return true; if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Reference.hxx")) @@ -368,8 +376,7 @@ bool ReferenceCasting::VisitCallExpr(const CallExpr* ce) return true; if (CheckForUnnecessaryGet(ce->getArg(0), /*includeRtlReference*/ true)) - report(DiagnosticsEngine::Warning, "unnecessary get() call", - compat::getBeginLoc(ce->getArg(0))) + report(DiagnosticsEngine::Warning, "unnecessary get() call", ce->getArg(0)->getBeginLoc()) << ce->getArg(0)->getSourceRange(); // extract the type parameter passed to the template @@ -394,7 +401,7 @@ bool ReferenceCasting::VisitCallExpr(const CallExpr* ce) } if (auto matTempExpr = dyn_cast<MaterializeTemporaryExpr>(arg0)) { - arg0 = compat::getSubExpr(matTempExpr); + arg0 = matTempExpr->getSubExpr(); continue; } if (auto bindTempExpr = dyn_cast<CXXBindTemporaryExpr>(arg0)) @@ -437,7 +444,7 @@ bool ReferenceCasting::VisitCallExpr(const CallExpr* ce) { report(DiagnosticsEngine::Warning, "the source reference is already a subtype of the destination reference, just use =", - compat::getBeginLoc(ce)) + ce->getBeginLoc()) << ce->getSourceRange(); } return true; @@ -450,7 +457,7 @@ bool ReferenceCasting::VisitCallExpr(const CallExpr* ce) */ bool ReferenceCasting::CheckForUnnecessaryGet(const Expr* expr, bool includeRtlReference) { - expr = compat::IgnoreImplicit(expr); + expr = expr->IgnoreImplicit(); auto cxxMemberCallExpr = dyn_cast<CXXMemberCallExpr>(expr); if (!cxxMemberCallExpr) return false; @@ -470,8 +477,8 @@ bool ReferenceCasting::CheckForUnnecessaryGet(const Expr* expr, bool includeRtlR else return false; - StringRef aFileName = getFilenameOfLocation( - compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(expr))); + StringRef aFileName + = getFilenameOfLocation(compiler.getSourceManager().getSpellingLoc(expr->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/cppu/qa/test_reference.cxx")) return false; @@ -511,9 +518,10 @@ static const RecordType* extractTemplateType(QualType cceType) auto cceTST = dyn_cast<TemplateSpecializationType>(cceType); if (!cceTST) return NULL; - if (cceTST->getNumArgs() != 1) + auto const args = cceTST->template_arguments(); + if (args.size() != 1) return NULL; - const TemplateArgument& cceTA = cceTST->getArg(0); + const TemplateArgument& cceTA = args[0]; QualType templateParamType = cceTA.getAsType(); if (auto elaboratedType = dyn_cast<ElaboratedType>(templateParamType)) templateParamType = elaboratedType->desugar(); |