diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2018-05-29 11:28:07 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2018-07-06 14:12:58 +0200 |
commit | ff002524c12471668e63837a804b6006f9136a34 (patch) | |
tree | a1dabcdde981ca377809b9a720ab01b71b3b21fb /compilerplugins | |
parent | 243f7d73a0b6ef9cea63bfcca0a07aa9c19e259c (diff) |
compilerplugins: try to make these work with icecream
There are some problems here, this should fix one of them: the
getFilename function returns "<stdin>" for spelling locations, because
the input to clang is sort of preprocessed via -frewrite-includes if
icecream is used and the file is built on a remote host (whereas it's
apparently not preprocessed if the file is compiled locally by icecream).
Using getPresumedLoc() uses the #line directives in the preprocessed
input, which avoids the problem but is more expensive, so try to use it
only when necessary.
The getFileEntry(getMainFileID())->getName() pattern will also result
in "<stdin>", but fortunately icecream passes -main-file-name,
which oddly enough isn't used by the SourceManager's spelling locations,
but is available separately via CodeGenOptions.
This builds everything successfully with clang version 6.0.0:
ICECC_PREFERRED_HOST=myremote make check gb_SUPPRESS_TESTS=t
Change-Id: Ic121511683e5302d7b9d85186c8b9c4a5443fa1b
Reviewed-on: https://gerrit.libreoffice.org/54993
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'compilerplugins')
34 files changed, 103 insertions, 75 deletions
diff --git a/compilerplugins/clang/automem.cxx b/compilerplugins/clang/automem.cxx index 52bfdf43d6b3..4675c02325be 100644 --- a/compilerplugins/clang/automem.cxx +++ b/compilerplugins/clang/automem.cxx @@ -51,7 +51,7 @@ bool AutoMem::VisitCXXDeleteExpr(const CXXDeleteExpr* expr) { if (ignoreLocation( expr )) return true; - StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(expr->getLocStart())); + StringRef aFileName = getFileNameOfSpellingLoc(compiler.getSourceManager().getSpellingLoc(expr->getLocStart())); if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/salhelper/") || loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/osl/") || loplugin::hasPathnamePrefix(aFileName, SRCDIR "/salhelper/") diff --git a/compilerplugins/clang/blockblock.cxx b/compilerplugins/clang/blockblock.cxx index 065e4572e0e1..bdb7d1361410 100644 --- a/compilerplugins/clang/blockblock.cxx +++ b/compilerplugins/clang/blockblock.cxx @@ -28,8 +28,7 @@ public: virtual void run() override { - StringRef fn( compiler.getSourceManager().getFileEntryForID( - compiler.getSourceManager().getMainFileID())->getName() ); + StringRef fn(handler.getMainFileName()); if (loplugin::isSamePathname(fn, SRCDIR "/sal/osl/unx/file_misc.cxx")) return; diff --git a/compilerplugins/clang/checkunusedparams.cxx b/compilerplugins/clang/checkunusedparams.cxx index 31dae1c66e61..84f05dca4dab 100644 --- a/compilerplugins/clang/checkunusedparams.cxx +++ b/compilerplugins/clang/checkunusedparams.cxx @@ -44,8 +44,7 @@ private: void CheckUnusedParams::run() { - StringRef fn( compiler.getSourceManager().getFileEntryForID( - compiler.getSourceManager().getMainFileID())->getName() ); + StringRef fn(handler.getMainFileName()); if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sal/")) return; // Taking pointer to function @@ -200,7 +199,7 @@ bool CheckUnusedParams::VisitFunctionDecl(FunctionDecl const * decl) { return true; if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(canon->getLocation()))) return true; - StringRef fn = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(canon->getLocStart())); + StringRef fn = getFileNameOfSpellingLoc(compiler.getSourceManager().getSpellingLoc(canon->getLocStart())); // Some backwards compat magic. // TODO Can probably be removed, but need to do some checking if (loplugin::isSamePathname(fn, SRCDIR "/include/sax/fshelper.hxx")) diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx index 3cbcbc8e4043..efff4ac896d5 100644 --- a/compilerplugins/clang/constantparam.cxx +++ b/compilerplugins/clang/constantparam.cxx @@ -62,8 +62,7 @@ public: virtual void run() override { // ignore some files that make clang crash inside EvaluateAsInt - std::string fn( compiler.getSourceManager().getFileEntryForID( - compiler.getSourceManager().getMainFileID())->getName() ); + std::string fn(handler.getMainFileName()); loplugin::normalizeDotDotInFilePath(fn); if (loplugin::isSamePathname(fn, SRCDIR "/basegfx/source/matrix/b2dhommatrix.cxx") || loplugin::isSamePathname(fn, SRCDIR "/basegfx/source/matrix/b3dhommatrix.cxx")) diff --git a/compilerplugins/clang/constparams.cxx b/compilerplugins/clang/constparams.cxx index 471da7367dc0..08e6aa2f1dc1 100644 --- a/compilerplugins/clang/constparams.cxx +++ b/compilerplugins/clang/constparams.cxx @@ -38,8 +38,7 @@ public: explicit ConstParams(loplugin::InstantiationData const & data): loplugin::FunctionAddress<ConstParams>(data) {} virtual void run() override { - std::string fn( compiler.getSourceManager().getFileEntryForID( - compiler.getSourceManager().getMainFileID())->getName() ); + std::string fn(handler.getMainFileName()); loplugin::normalizeDotDotInFilePath(fn); if (startswith(fn, SRCDIR "/sal/") || fn == SRCDIR "/jurt/source/pipe/staticsalhack.cxx" diff --git a/compilerplugins/clang/convertlong.cxx b/compilerplugins/clang/convertlong.cxx index b706d7dffaa4..8038b8a6371b 100644 --- a/compilerplugins/clang/convertlong.cxx +++ b/compilerplugins/clang/convertlong.cxx @@ -35,9 +35,7 @@ public: virtual void run() override { - std::string fn(compiler.getSourceManager() - .getFileEntryForID(compiler.getSourceManager().getMainFileID()) - ->getName()); + std::string fn(handler.getMainFileName()); loplugin::normalizeDotDotInFilePath(fn); // using sal_uIntPtr as in-between type when converting void* to rtl_TextEncoding if (fn == SRCDIR "/sal/osl/unx/thread.cxx") @@ -74,7 +72,7 @@ bool ConvertLong::VisitVarDecl(VarDecl const* varDecl) { if (ignoreLocation(varDecl)) return true; - StringRef fileName{ compiler.getSourceManager().getFilename(varDecl->getLocation()) }; + StringRef fileName{ getFileNameOfSpellingLoc(varDecl->getLocation()) }; if (loplugin::isSamePathname(fileName, SRCDIR "/include/tools/bigint.hxx")) return true; if (loplugin::isSamePathname(fileName, SRCDIR "/include/tools/solar.h")) diff --git a/compilerplugins/clang/datamembershadow.cxx b/compilerplugins/clang/datamembershadow.cxx index 6e71ce57a4e7..35c96c6f240f 100644 --- a/compilerplugins/clang/datamembershadow.cxx +++ b/compilerplugins/clang/datamembershadow.cxx @@ -44,8 +44,8 @@ bool DataMemberShadow::VisitFieldDecl(FieldDecl const * fieldDecl) if (ignoreLocation(fieldDecl)) { return true; } - StringRef aFileName = compiler.getSourceManager().getFilename( - compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocStart())); + StringRef aFileName = getFileNameOfSpellingLoc( + compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocStart())); // FIXME complex stuff to fix later diff --git a/compilerplugins/clang/dyncastvisibility.cxx b/compilerplugins/clang/dyncastvisibility.cxx index afc500f61f61..6a1d84d91d3e 100644 --- a/compilerplugins/clang/dyncastvisibility.cxx +++ b/compilerplugins/clang/dyncastvisibility.cxx @@ -115,7 +115,7 @@ public: // at least some interesting cases (though it would still not be aggressive enough to // have found ff570b4b58dbf274d3094d21d974f18b613e9b4b "DocumentSettingsSerializer must // be SAL_DLLPUBLIC_RTTI for dynamic_cast"): - auto const file = compiler.getSourceManager().getFilename( + auto const file = getFileNameOfSpellingLoc( compiler.getSourceManager().getSpellingLoc(rdd->getLocation())); if (loplugin::hasPathnamePrefix(file, SRCDIR "/include/")) { std::size_t const n1 = std::strlen(SRCDIR "/include/"); @@ -127,10 +127,7 @@ public: auto prefix = std::string(SRCDIR "/"); prefix += seg; if (!loplugin::hasPathnamePrefix( - (compiler.getSourceManager() - .getFileEntryForID(compiler.getSourceManager().getMainFileID()) - ->getName()), - prefix)) + handler.getMainFileName(), prefix)) { report( DiagnosticsEngine::Warning, diff --git a/compilerplugins/clang/expressionalwayszero.cxx b/compilerplugins/clang/expressionalwayszero.cxx index 6633f138cfb3..0f0eb7a541e6 100644 --- a/compilerplugins/clang/expressionalwayszero.cxx +++ b/compilerplugins/clang/expressionalwayszero.cxx @@ -35,8 +35,9 @@ public: virtual void run() override { - std::string fn( compiler.getSourceManager().getFileEntryForID( - compiler.getSourceManager().getMainFileID())->getName() ); + // don't use getMainFileID, it may return "<stdin>" + std::string fn(handler.getMainFileName()); + loplugin::normalizeDotDotInFilePath(fn); // encoding of constant value for binary file format if (startswith(fn, SRCDIR "/package/source/zipapi/ZipFile.cxx")) diff --git a/compilerplugins/clang/externandnotdefined.cxx b/compilerplugins/clang/externandnotdefined.cxx index df5455d0dddf..97dff5a8dfa3 100644 --- a/compilerplugins/clang/externandnotdefined.cxx +++ b/compilerplugins/clang/externandnotdefined.cxx @@ -57,7 +57,7 @@ bool ExternAndNotDefined::VisitFunctionDecl(const FunctionDecl * functionDecl) { { return true; } - StringRef fileName { compiler.getSourceManager().getFilename(functionDecl->getLocation()) }; + StringRef fileName { getFileNameOfSpellingLoc(functionDecl->getLocation()) }; // the filters use some kind of dynamic loading stunt if (loplugin::hasPathnamePrefix(fileName, SRCDIR "/filter/qa/")) { return true; diff --git a/compilerplugins/clang/fragiledestructor.cxx b/compilerplugins/clang/fragiledestructor.cxx index f8a0ea50660c..d1bff95ddf72 100644 --- a/compilerplugins/clang/fragiledestructor.cxx +++ b/compilerplugins/clang/fragiledestructor.cxx @@ -47,7 +47,7 @@ bool FragileDestructor::TraverseCXXDestructorDecl(CXXDestructorDecl* pCXXDestruc return RecursiveASTVisitor::TraverseCXXDestructorDecl(pCXXDestructorDecl); } // ignore this for now, too tricky for me to work out - StringRef aFileName = compiler.getSourceManager().getFilename( + StringRef aFileName = getFileNameOfSpellingLoc( compiler.getSourceManager().getSpellingLoc(pCXXDestructorDecl->getLocStart())); if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/comphelper/") || loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/cppuhelper/") @@ -87,7 +87,8 @@ bool FragileDestructor::VisitCXXMemberCallExpr(const CXXMemberCallExpr* callExpr return true; } // e.g. osl/thread.hxx and cppuhelper/compbase.hxx - StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(methodDecl->getLocStart())); + StringRef aFileName = getFileNameOfSpellingLoc( + compiler.getSourceManager().getSpellingLoc(methodDecl->getLocStart())); if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/osl/") || loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/comphelper/") || loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/cppuhelper/")) diff --git a/compilerplugins/clang/memoryvar.cxx b/compilerplugins/clang/memoryvar.cxx index 17cb2701acd0..590af94b7c7a 100644 --- a/compilerplugins/clang/memoryvar.cxx +++ b/compilerplugins/clang/memoryvar.cxx @@ -50,7 +50,7 @@ private: StringRef MemoryVar::getFilename(SourceLocation loc) { SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(loc); - StringRef name { compiler.getSourceManager().getFilename(spellingLocation) }; + StringRef name { getFileNameOfSpellingLoc(spellingLocation) }; return name; } diff --git a/compilerplugins/clang/nullptr.cxx b/compilerplugins/clang/nullptr.cxx index bc1f7b505243..ccd5837b226f 100644 --- a/compilerplugins/clang/nullptr.cxx +++ b/compilerplugins/clang/nullptr.cxx @@ -233,7 +233,7 @@ bool Nullptr::TraverseLinkageSpecDecl(LinkageSpecDecl * decl) { bool Nullptr::isInLokIncludeFile(SourceLocation spellingLocation) const { return loplugin::hasPathnamePrefix( - compiler.getSourceManager().getFilename(spellingLocation), + getFileNameOfSpellingLoc(spellingLocation), SRCDIR "/include/LibreOfficeKit/"); } diff --git a/compilerplugins/clang/oncevar.cxx b/compilerplugins/clang/oncevar.cxx index a8a56f5a7e33..afb1b0fa85e9 100644 --- a/compilerplugins/clang/oncevar.cxx +++ b/compilerplugins/clang/oncevar.cxx @@ -83,8 +83,7 @@ public: virtual void run() override { // ignore some files with problematic macros - std::string fn( compiler.getSourceManager().getFileEntryForID( - compiler.getSourceManager().getMainFileID())->getName() ); + std::string fn(handler.getMainFileName()); loplugin::normalizeDotDotInFilePath(fn); // platform-specific stuff if (fn == SRCDIR "/sal/osl/unx/thread.cxx" diff --git a/compilerplugins/clang/overrideparam.cxx b/compilerplugins/clang/overrideparam.cxx index 820127e1343d..10e664c75326 100644 --- a/compilerplugins/clang/overrideparam.cxx +++ b/compilerplugins/clang/overrideparam.cxx @@ -43,8 +43,7 @@ private: void OverrideParam::run() { /* - StringRef fn( compiler.getSourceManager().getFileEntryForID( - compiler.getSourceManager().getMainFileID())->getName() ); + StringRef fn(handler.getMainFileName()); if (fn == SRCDIR "/include/svx/checklbx.hxx") return; */ diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx index 56d40e337bf9..1348c3f0f00f 100644 --- a/compilerplugins/clang/plugin.cxx +++ b/compilerplugins/clang/plugin.cxx @@ -215,11 +215,37 @@ const FunctionDecl* Plugin::getParentFunctionDecl( const Stmt* stmt ) return nullptr; } +StringRef Plugin::getFileNameOfSpellingLoc(SourceLocation spellingLocation) const +{ + static enum { NOINIT, STDIN, GOOD } s_Mode(NOINIT); + if (s_Mode == GOOD) + { + return compiler.getSourceManager().getFilename(spellingLocation); + } + else if (s_Mode == STDIN + || !compiler.getSourceManager().isInMainFile(spellingLocation)) + { + const char* bufferName = compiler.getSourceManager().getPresumedLoc(spellingLocation).getFilename(); + return bufferName; + } + else + { + auto const fn(compiler.getSourceManager().getFilename(spellingLocation)); + if (!fn.data()) // wtf? happens in sot/source/sdstor/stg.cxx + { + return fn; + } +#if !defined _WIN32 + assert(fn.startswith("/") || fn == "<stdin>"); +#endif + s_Mode = fn == "<stdin>" ? STDIN : GOOD; + return getFileNameOfSpellingLoc(spellingLocation); + } +} bool Plugin::isInUnoIncludeFile(SourceLocation spellingLocation) const { - StringRef name { - compiler.getSourceManager().getFilename(spellingLocation) }; + StringRef name{ getFileNameOfSpellingLoc(spellingLocation) }; return compiler.getSourceManager().isInMainFile(spellingLocation) ? (isSamePathname(name, SRCDIR "/cppu/source/cppu/compat.cxx") || isSamePathname(name, SRCDIR "/cppuhelper/source/compat.cxx") diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx index 5299e7f2eac3..4c4d9a70fcb3 100644 --- a/compilerplugins/clang/plugin.hxx +++ b/compilerplugins/clang/plugin.hxx @@ -72,6 +72,9 @@ protected: const Stmt* getParentStmt( const Stmt* stmt ); Stmt* getParentStmt( Stmt* stmt ); const FunctionDecl* getParentFunctionDecl( const Stmt* stmt ); + + /// to check file names against whitelists, so that it works with preprocessed input too + StringRef getFileNameOfSpellingLoc(SourceLocation spellingLocation) const; /** Checks if the location is inside an UNO file, more specifically, if it forms part of the URE stable interface, which is not allowed to be changed. diff --git a/compilerplugins/clang/pluginhandler.cxx b/compilerplugins/clang/pluginhandler.cxx index b1e789a4a8c5..a4637cd78e6d 100644 --- a/compilerplugins/clang/pluginhandler.cxx +++ b/compilerplugins/clang/pluginhandler.cxx @@ -55,9 +55,21 @@ static int pluginCount = 0; static bool bPluginObjectsCreated = false; static bool unitTestMode = false; +StringRef initMainFileName(CompilerInstance& compiler) +{ + StringRef const& fn(compiler.getASTContext().getSourceManager().getFileEntryForID( + compiler.getASTContext().getSourceManager().getMainFileID())->getName()); + if (fn == "<stdin>") + // stdin means icecream, so we can rely on -main-file-name containing the full path name + return compiler.getCodeGenOpts().MainFileName; + else + // this is always a full path name + return fn; +} + PluginHandler::PluginHandler( CompilerInstance& compiler, const std::vector< std::string >& args ) : compiler( compiler ) - , mainFileName(compiler.getASTContext().getSourceManager().getFileEntryForID(compiler.getASTContext().getSourceManager().getMainFileID())->getName()) + , mainFileName(initMainFileName(compiler)) , rewriter( compiler.getSourceManager(), compiler.getLangOpts()) , scope( "mainfile" ) , warningsAsErrors( false ) diff --git a/compilerplugins/clang/pluginhandler.hxx b/compilerplugins/clang/pluginhandler.hxx index 0b53d7043f00..1cb405d54d35 100644 --- a/compilerplugins/clang/pluginhandler.hxx +++ b/compilerplugins/clang/pluginhandler.hxx @@ -60,6 +60,7 @@ public: // without corrupting the source bool checkOverlap(SourceRange range); void addSourceModification(SourceRange range); + StringRef const& getMainFileName() const { return mainFileName; } private: void handleOption( const std::string& option ); void createPlugins( std::set< std::string > rewriters ); diff --git a/compilerplugins/clang/refcounting.cxx b/compilerplugins/clang/refcounting.cxx index 8133e281d8aa..f4e7e8e5929b 100644 --- a/compilerplugins/clang/refcounting.cxx +++ b/compilerplugins/clang/refcounting.cxx @@ -507,7 +507,8 @@ bool RefCounting::VisitVarDecl(const VarDecl * varDecl) { << varDecl->getSourceRange(); } if (containsSalhelperReferenceObjectSubclass(varDecl->getType().getTypePtr())) { - StringRef name { compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(varDecl->getLocation())) }; + StringRef name { getFileNameOfSpellingLoc( + compiler.getSourceManager().getSpellingLoc(varDecl->getLocation())) }; // this is playing games that it believes is safe if (loplugin::isSamePathname(name, SRCDIR "/stoc/source/security/permissions.cxx")) return true; diff --git a/compilerplugins/clang/reservedid.cxx b/compilerplugins/clang/reservedid.cxx index cfb9a5b35818..e3cb737cf6b5 100644 --- a/compilerplugins/clang/reservedid.cxx +++ b/compilerplugins/clang/reservedid.cxx @@ -104,8 +104,7 @@ void ReservedId::run() { if (d->getKind() == MacroDirective::MD_Define) { auto loc = d->getLocation(); if (loc.isValid() && !ignoreLocation(loc)) { - auto file = compiler.getSourceManager() - .getFilename(loc); + auto file = getFileNameOfSpellingLoc(loc); if (!loplugin::isSamePathname( file, SRCDIR @@ -137,7 +136,7 @@ bool ReservedId::VisitNamedDecl(NamedDecl const * decl) { if (ignoreLocation(spelLoc)) { return true; } - auto filename = compiler.getSourceManager().getFilename(spelLoc); + auto filename = getFileNameOfSpellingLoc(spelLoc); if (loplugin::hasPathnamePrefix(filename, SRCDIR "/bridges/source/cpp_uno/") && filename.endswith("share.hxx")) { @@ -268,7 +267,7 @@ ReservedId::Kind ReservedId::determineKind(llvm::StringRef const & id) { bool ReservedId::isInLokIncludeFile(SourceLocation spellingLocation) const { return loplugin::hasPathnamePrefix( - compiler.getSourceManager().getFilename(spellingLocation), + getFileNameOfSpellingLoc(spellingLocation), SRCDIR "/include/LibreOfficeKit/"); } diff --git a/compilerplugins/clang/salbool.cxx b/compilerplugins/clang/salbool.cxx index e828dbfcfc55..02cc2f609661 100644 --- a/compilerplugins/clang/salbool.cxx +++ b/compilerplugins/clang/salbool.cxx @@ -767,7 +767,7 @@ bool SalBool::TraverseStaticAssertDecl(StaticAssertDecl * decl) { // inside static_assert in cppu/source/uno/check.cxx: return loplugin::isSamePathname( - compiler.getSourceManager().getFilename(decl->getLocation()), + getFileNameOfSpellingLoc(decl->getLocation()), SRCDIR "/cppu/source/uno/check.cxx") || RecursiveASTVisitor::TraverseStaticAssertDecl(decl); } @@ -803,7 +803,7 @@ bool SalBool::isInSpecialMainFile(SourceLocation spellingLocation) const { if (!compiler.getSourceManager().isInMainFile(spellingLocation)) { return false; } - auto f = compiler.getSourceManager().getFilename(spellingLocation); + auto f = getFileNameOfSpellingLoc(spellingLocation); return loplugin::isSamePathname(f, SRCDIR "/cppu/qa/test_any.cxx") || loplugin::isSamePathname(f, SRCDIR "/cppu/source/uno/check.cxx"); // TODO: the offset checks diff --git a/compilerplugins/clang/shouldreturnbool.cxx b/compilerplugins/clang/shouldreturnbool.cxx index d993bf25f21e..ea9e696674de 100644 --- a/compilerplugins/clang/shouldreturnbool.cxx +++ b/compilerplugins/clang/shouldreturnbool.cxx @@ -36,9 +36,7 @@ public: { if (!compiler.getLangOpts().CPlusPlus) return; - StringRef fn(compiler.getSourceManager() - .getFileEntryForID(compiler.getSourceManager().getMainFileID()) - ->getName()); + StringRef fn(handler.getMainFileName()); // functions used as function pointers if (loplugin::isSamePathname(fn, SRCDIR "/sal/rtl/alloc_cache.cxx")) return; diff --git a/compilerplugins/clang/simplifydynamiccast.cxx b/compilerplugins/clang/simplifydynamiccast.cxx index f305f8cbeaef..eb5d111d11a7 100644 --- a/compilerplugins/clang/simplifydynamiccast.cxx +++ b/compilerplugins/clang/simplifydynamiccast.cxx @@ -29,8 +29,7 @@ public: virtual void run() override { - // StringRef fn( compiler.getSourceManager().getFileEntryForID( - // compiler.getSourceManager().getMainFileID())->getName() ); + // StringRef fn(handler.getMainFileName()); // if (loplugin::isSamePathname(fn, WORKDIR "/YaccTarget/unoidl/source/sourceprovider-parser.cxx")) // return; diff --git a/compilerplugins/clang/staticmethods.cxx b/compilerplugins/clang/staticmethods.cxx index 50d432081f00..aa1b97e01015 100644 --- a/compilerplugins/clang/staticmethods.cxx +++ b/compilerplugins/clang/staticmethods.cxx @@ -60,7 +60,7 @@ bool isDerivedFromTestFixture(const CXXRecordDecl *decl) { StringRef StaticMethods::getFilename(SourceLocation loc) { SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc(loc); - return compiler.getSourceManager().getFilename(spellingLocation); + return getFileNameOfSpellingLoc(spellingLocation); } bool startsWith(const std::string& rStr, const char* pSubStr) { diff --git a/compilerplugins/clang/stringconcat.cxx b/compilerplugins/clang/stringconcat.cxx index f5b8d8c2d2ea..818d8314fa45 100644 --- a/compilerplugins/clang/stringconcat.cxx +++ b/compilerplugins/clang/stringconcat.cxx @@ -97,7 +97,7 @@ bool StringConcat::VisitCallExpr(CallExpr const * expr) { leftLoc = left->getArg(1)->getLocStart(); } StringRef name { - compiler.getSourceManager().getFilename( + getFileNameOfSpellingLoc( compiler.getSourceManager().getSpellingLoc(expr->getLocStart())) }; if (loplugin::isSamePathname( name, SRCDIR "/sal/qa/rtl/strings/test_ostring_concat.cxx") diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx index 0555b20af24a..8c01c9e5c017 100644 --- a/compilerplugins/clang/stringconstant.cxx +++ b/compilerplugins/clang/stringconstant.cxx @@ -325,7 +325,8 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { { // u.equalsIgnoreAsciiCaseAscii("foo") -> // u.equalsIngoreAsciiCase("foo"): - auto file = compiler.getSourceManager().getFilename( + + auto file = getFileNameOfSpellingLoc( compiler.getSourceManager().getSpellingLoc(expr->getLocStart())); if (loplugin::isSamePathname( file, SRCDIR "/sal/qa/rtl/strings/test_oustring_compare.cxx")) @@ -343,7 +344,7 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { { // u.equalsIgnoreAsciiCaseAsciiL("foo", 3) -> // u.equalsIngoreAsciiCase("foo"): - auto file = compiler.getSourceManager().getFilename( + auto file = getFileNameOfSpellingLoc( compiler.getSourceManager().getSpellingLoc(expr->getLocStart())); if (loplugin::isSamePathname( file, SRCDIR "/sal/qa/rtl/strings/test_oustring_compare.cxx")) @@ -710,7 +711,7 @@ bool StringConstant::VisitCallExpr(CallExpr const * expr) { case 2: { // b.append("foo", 3) -> b.append("foo"): - auto file = compiler.getSourceManager().getFilename( + auto file = getFileNameOfSpellingLoc( compiler.getSourceManager().getSpellingLoc( expr->getLocStart())); if (loplugin::isSamePathname( @@ -1077,8 +1078,7 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) { if (dc.Operator(OO_Plus).Namespace("rtl") .GlobalNamespace()) { - auto file = - compiler.getSourceManager().getFilename( + auto file = getFileNameOfSpellingLoc( compiler.getSourceManager() .getSpellingLoc( expr->getLocStart())); diff --git a/compilerplugins/clang/stringstatic.cxx b/compilerplugins/clang/stringstatic.cxx index 00f1c9f6eab1..7fa14c0766c7 100644 --- a/compilerplugins/clang/stringstatic.cxx +++ b/compilerplugins/clang/stringstatic.cxx @@ -40,8 +40,7 @@ private: void StringStatic::run() { - StringRef fn( compiler.getSourceManager().getFileEntryForID( - compiler.getSourceManager().getMainFileID())->getName() ); + StringRef fn(handler.getMainFileName()); // passing around pointers to global OUString if (loplugin::hasPathnamePrefix(fn, SRCDIR "/filter/source/svg/")) return; diff --git a/compilerplugins/clang/unnecessaryoverride.cxx b/compilerplugins/clang/unnecessaryoverride.cxx index 338598985289..092decc797fc 100644 --- a/compilerplugins/clang/unnecessaryoverride.cxx +++ b/compilerplugins/clang/unnecessaryoverride.cxx @@ -72,8 +72,7 @@ public: virtual void run() override { // ignore some files with problematic macros - StringRef fn( compiler.getSourceManager().getFileEntryForID( - compiler.getSourceManager().getMainFileID())->getName() ); + StringRef fn(handler.getMainFileName()); if (loplugin::isSamePathname(fn, SRCDIR "/sd/source/ui/framework/factories/ChildWindowPane.cxx")) return; if (loplugin::isSamePathname(fn, SRCDIR "/forms/source/component/Date.cxx")) @@ -113,7 +112,8 @@ bool UnnecessaryOverride::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) return true; } - StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(methodDecl->getLocStart())); + StringRef aFileName = getFileNameOfSpellingLoc( + compiler.getSourceManager().getSpellingLoc(methodDecl->getLocStart())); if (isa<CXXDestructorDecl>(methodDecl) && !isInUnoIncludeFile(methodDecl)) diff --git a/compilerplugins/clang/unnecessaryparen.cxx b/compilerplugins/clang/unnecessaryparen.cxx index caeadcac0072..0cad779ca7dd 100644 --- a/compilerplugins/clang/unnecessaryparen.cxx +++ b/compilerplugins/clang/unnecessaryparen.cxx @@ -67,8 +67,7 @@ public: virtual void run() override { - StringRef fn( compiler.getSourceManager().getFileEntryForID( - compiler.getSourceManager().getMainFileID())->getName() ); + StringRef fn(handler.getMainFileName()); // fixing this, makes the source in the .y files look horrible if (loplugin::isSamePathname(fn, WORKDIR "/YaccTarget/unoidl/source/sourceprovider-parser.cxx")) return; diff --git a/compilerplugins/clang/unoany.cxx b/compilerplugins/clang/unoany.cxx index db20779746bc..8caa7c2a54cf 100644 --- a/compilerplugins/clang/unoany.cxx +++ b/compilerplugins/clang/unoany.cxx @@ -28,7 +28,8 @@ bool UnoAny::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const * expr) if (ignoreLocation(expr)) { return true; } - StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(expr->getLocStart())); + StringRef aFileName = getFileNameOfSpellingLoc( + compiler.getSourceManager().getSpellingLoc(expr->getLocStart())); if (loplugin::isSamePathname(aFileName, SRCDIR "/include/com/sun/star/uno/Any.hxx")) { return true; } diff --git a/compilerplugins/clang/unusedvariablemore.cxx b/compilerplugins/clang/unusedvariablemore.cxx index ead91586c460..fa2ff366052b 100644 --- a/compilerplugins/clang/unusedvariablemore.cxx +++ b/compilerplugins/clang/unusedvariablemore.cxx @@ -63,9 +63,7 @@ static bool startswith(const std::string& rStr, const char* pSubStr) void UnusedVariableMore::run() { - std::string fn(compiler.getSourceManager() - .getFileEntryForID(compiler.getSourceManager().getMainFileID()) - ->getName()); + std::string fn(handler.getMainFileName()); loplugin::normalizeDotDotInFilePath(fn); // ignore QA folders diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index 7a3722b785f8..5d8d6c57a2fb 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -32,9 +32,7 @@ public: virtual void run() override { - std::string fn(compiler.getSourceManager() - .getFileEntryForID(compiler.getSourceManager().getMainFileID()) - ->getName()); + std::string fn(handler.getMainFileName()); loplugin::normalizeDotDotInFilePath(fn); // can't change these because we pass them down to the SfxItemPool stuff if (fn == SRCDIR "/sc/source/core/data/docpool.cxx") @@ -249,7 +247,8 @@ void UseUniquePtr::CheckDeleteExpr(const CXXMethodDecl* methodDecl, const CXXDel if (ignoreLocation(fieldDecl)) return; // to ignore things like the CPPUNIT macros - StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocStart())); + StringRef aFileName = getFileNameOfSpellingLoc( + compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocStart())); if (loplugin::hasPathnamePrefix(aFileName, WORKDIR "/")) return; // passes and stores pointers to member fields diff --git a/compilerplugins/clang/vclwidgets.cxx b/compilerplugins/clang/vclwidgets.cxx index af2b1bf46cdd..84d7ffea6bb2 100644 --- a/compilerplugins/clang/vclwidgets.cxx +++ b/compilerplugins/clang/vclwidgets.cxx @@ -239,7 +239,7 @@ bool VCLWidgets::VisitCXXDestructorDecl(const CXXDestructorDecl* pCXXDestructorD if (!bOk) { SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc( pCXXDestructorDecl->getLocStart()); - StringRef filename = compiler.getSourceManager().getFilename(spellingLocation); + StringRef filename = getFileNameOfSpellingLoc(spellingLocation); if ( !(loplugin::isSamePathname(filename, SRCDIR "/vcl/source/window/window.cxx")) && !(loplugin::isSamePathname(filename, SRCDIR "/vcl/source/gdi/virdev.cxx")) && !(loplugin::isSamePathname(filename, SRCDIR "/vcl/qa/cppunit/lifecycle.cxx")) ) @@ -278,7 +278,7 @@ void VCLWidgets::checkAssignmentForVclPtrToRawConversion(const SourceLocation& s if (!rhs) { return; } - StringRef filename = compiler.getSourceManager().getFilename(spellingLocation); + StringRef filename = getFileNameOfSpellingLoc(spellingLocation); if (loplugin::isSamePathname(filename, SRCDIR "/include/rtl/ref.hxx")) { return; } @@ -360,7 +360,7 @@ bool VCLWidgets::VisitVarDecl(const VarDecl * pVarDecl) { if (pVarDecl->getInit()) { checkAssignmentForVclPtrToRawConversion(spellingLocation, pVarDecl->getType().getTypePtr(), pVarDecl->getInit()); } - StringRef aFileName = compiler.getSourceManager().getFilename(spellingLocation); + StringRef aFileName = getFileNameOfSpellingLoc(spellingLocation); if (loplugin::isSamePathname(aFileName, SRCDIR "/include/vcl/vclptr.hxx")) return true; if (loplugin::isSamePathname(aFileName, SRCDIR "/vcl/source/window/layout.cxx")) @@ -412,7 +412,8 @@ bool VCLWidgets::VisitFieldDecl(const FieldDecl * fieldDecl) { if (ignoreLocation(fieldDecl)) { return true; } - StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocStart())); + StringRef aFileName = getFileNameOfSpellingLoc( + compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocStart())); if (loplugin::isSamePathname(aFileName, SRCDIR "/include/vcl/vclptr.hxx")) return true; if (loplugin::isSamePathname(aFileName, SRCDIR "/include/rtl/ref.hxx")) @@ -669,7 +670,7 @@ bool VCLWidgets::VisitCXXDeleteExpr(const CXXDeleteExpr *pCXXDeleteExpr) if (pPointee && isDerivedFromVclReferenceBase(pPointee)) { SourceLocation spellingLocation = compiler.getSourceManager().getSpellingLoc( pCXXDeleteExpr->getLocStart()); - StringRef filename = compiler.getSourceManager().getFilename(spellingLocation); + StringRef filename = getFileNameOfSpellingLoc(spellingLocation); if ( !(loplugin::isSamePathname(filename, SRCDIR "/include/vcl/vclreferencebase.hxx"))) { report( @@ -845,7 +846,8 @@ bool VCLWidgets::VisitCXXConstructExpr( const CXXConstructExpr* constructExpr ) const CXXConstructorDecl* pConstructorDecl = constructExpr->getConstructor(); const CXXRecordDecl* recordDecl = pConstructorDecl->getParent(); if (isDerivedFromVclReferenceBase(recordDecl)) { - StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(constructExpr->getLocStart())); + StringRef aFileName = getFileNameOfSpellingLoc( + compiler.getSourceManager().getSpellingLoc(constructExpr->getLocStart())); if (!loplugin::isSamePathname(aFileName, SRCDIR "/include/vcl/vclptr.hxx")) { report( DiagnosticsEngine::Warning, |