Kaydet (Commit) df8d092c authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Adapt pathname checks to mixed usage of \ and / on Windows

Change-Id: I91bc89a9076c6642e06b238f65f2d31a1d20c6b5
üst 33cbc99f
......@@ -52,11 +52,11 @@ bool AutoMem::VisitCXXDeleteExpr(const CXXDeleteExpr* expr)
if (ignoreLocation( expr ))
return true;
StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(expr->getLocStart()));
if (aFileName.startswith(SRCDIR "/include/salhelper/")
|| aFileName.startswith(SRCDIR "/include/osl/")
|| aFileName.startswith(SRCDIR "/salhelper/")
|| aFileName.startswith(SRCDIR "/store/")
|| aFileName.startswith(SRCDIR "/sal/"))
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/salhelper/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/osl/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/salhelper/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/store/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sal/"))
return true;
if (mbInsideDestructor)
......
......@@ -67,8 +67,8 @@ void CheckConfigMacros::MacroDefined( const Token& macroToken, const MacroDirect
SourceLocation location = info->getLocation();
const char* filename = compiler.getSourceManager().getPresumedLoc( location ).getFilename();
if( filename != NULL
&& ( strncmp( filename, BUILDDIR "/config_host/", strlen( BUILDDIR "/config_host/" )) == 0
|| strncmp( filename, BUILDDIR "/config_build/", strlen( BUILDDIR "/config_build/" )) == 0 ))
&& ( hasPathnamePrefix(filename, BUILDDIR "/config_host/")
|| hasPathnamePrefix(filename, BUILDDIR "/config_build/") ))
{
// fprintf(stderr,"DEF: %s %s\n", macroToken.getIdentifierInfo()->getName().data(), filename );
configMacros.insert( macroToken.getIdentifierInfo()->getName());
......@@ -105,7 +105,7 @@ void CheckConfigMacros::checkMacro( const Token& macroToken, SourceLocation loca
{
const char* filename = compiler.getSourceManager().getPresumedLoc( location ).getFilename();
if( filename == NULL
|| strncmp( filename, SRCDIR "/include/LibreOfficeKit/", strlen( SRCDIR "/include/LibreOfficeKit/" )) != 0 )
|| !hasPathnamePrefix(filename, SRCDIR "/include/LibreOfficeKit/") )
{
report( DiagnosticsEngine::Error, "checking whether a config macro %0 is defined",
location ) << macroToken.getIdentifierInfo()->getName();
......
......@@ -39,23 +39,23 @@ void CheckUnusedParams::run()
{
StringRef fn( compiler.getSourceManager().getFileEntryForID(
compiler.getSourceManager().getMainFileID())->getName() );
if (fn.startswith(SRCDIR "/sal/"))
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/sal/"))
return;
// Taking pointer to function
if (fn == SRCDIR "/l10ntools/source/xmlparse.cxx")
if (loplugin::isSamePathname(fn, SRCDIR "/l10ntools/source/xmlparse.cxx"))
return;
// macro magic which declares something needed by an external library
if (fn == SRCDIR "/svl/source/misc/gridprinter.cxx")
if (loplugin::isSamePathname(fn, SRCDIR "/svl/source/misc/gridprinter.cxx"))
return;
// valid test/qa code
if (fn.startswith(SRCDIR "/compilerplugins/clang/test/"))
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/compilerplugins/clang/test/"))
return;
if (fn == SRCDIR "/cppu/qa/test_reference.cxx")
if (loplugin::isSamePathname(fn, SRCDIR "/cppu/qa/test_reference.cxx"))
return;
// leave this alone for now
if (fn.startswith(SRCDIR "/libreofficekit/"))
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/libreofficekit/"))
return;
m_phase = PluginPhase::FindAddressOf;
......@@ -135,104 +135,104 @@ bool CheckUnusedParams::VisitFunctionDecl(FunctionDecl const * decl) {
StringRef fn = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(canon->getLocStart()));
// Some backwards compat magic.
// TODO Can probably be removed, but need to do some checking
if (fn == SRCDIR "/include/sax/fshelper.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/include/sax/fshelper.hxx"))
return true;
// Platform-specific code
if (fn == SRCDIR "/include/svl/svdde.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/include/svl/svdde.hxx"))
return true;
if (fn == SRCDIR "/include/vcl/svmain.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/include/vcl/svmain.hxx"))
return true;
// passing pointer to function
if (fn == SRCDIR "/include/vcl/bitmapaccess.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/include/vcl/bitmapaccess.hxx"))
return true;
if (fn == SRCDIR "/vcl/inc/unx/gtk/gtkobject.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/vcl/inc/unx/gtk/gtkobject.hxx"))
return true;
if (fn == SRCDIR "/vcl/inc/unx/gtk/gtksalframe.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/vcl/inc/unx/gtk/gtksalframe.hxx"))
return true;
if (fn == SRCDIR "/vcl/inc/unx/gtk/gtkframe.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/vcl/inc/unx/gtk/gtkframe.hxx"))
return true;
if (fn == SRCDIR "/vcl/unx/gtk/fpicker/SalGtkFilePicker.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/vcl/unx/gtk/fpicker/SalGtkFilePicker.hxx"))
return true;
if (fn == SRCDIR "/extensions/source/propctrlr/propertyeditor.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/extensions/source/propctrlr/propertyeditor.hxx"))
return true;
if (fn == SRCDIR "/forms/source/solar/inc/navtoolbar.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/forms/source/solar/inc/navtoolbar.hxx"))
return true;
if (fn == SRCDIR "/hwpfilter/source/grammar.cxx")
if (loplugin::isSamePathname(fn, SRCDIR "/hwpfilter/source/grammar.cxx"))
return true;
if (fn == SRCDIR "/hwpfilter/source/lexer.cxx")
if (loplugin::isSamePathname(fn, SRCDIR "/hwpfilter/source/lexer.cxx"))
return true;
// marked with a TODO/FIXME
if (fn == SRCDIR "/vcl/inc/sallayout.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/vcl/inc/sallayout.hxx"))
return true;
if (fn == SRCDIR "/accessibility/inc/standard/vclxaccessiblelist.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/accessibility/inc/standard/vclxaccessiblelist.hxx"))
return true;
// these are "extern C" but clang doesn't seem to report that accurately
if (fn == SRCDIR "/sax/source/fastparser/fastparser.cxx")
if (loplugin::isSamePathname(fn, SRCDIR "/sax/source/fastparser/fastparser.cxx"))
return true;
// these all follow the same pattern, seems a pity to break that
if (fn == SRCDIR "/include/vcl/graphicfilter.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/include/vcl/graphicfilter.hxx"))
return true;
// looks like work in progress
if (fn == SRCDIR "/vcl/source/filter/ipdf/pdfdocument.cxx")
if (loplugin::isSamePathname(fn, SRCDIR "/vcl/source/filter/ipdf/pdfdocument.cxx"))
return true;
// macro magic
if (fn == SRCDIR "/basctl/source/inc/basidesh.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/basctl/source/inc/basidesh.hxx"))
return true;
// template magic
if (fn.startswith(SRCDIR "/canvas/"))
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/canvas/"))
return true;
if (fn.startswith(SRCDIR "/include/canvas/"))
if (loplugin::hasPathnamePrefix(fn, SRCDIR "/include/canvas/"))
return true;
if (fn == SRCDIR "/include/comphelper/unwrapargs.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/include/comphelper/unwrapargs.hxx"))
return true;
// this looks like vaguely useful code (ParseError) that I'm loathe to remove
if (fn == SRCDIR "/connectivity/source/inc/RowFunctionParser.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/connectivity/source/inc/RowFunctionParser.hxx"))
return true;
if (fn == SRCDIR "/include/svx/EnhancedCustomShapeFunctionParser.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/include/svx/EnhancedCustomShapeFunctionParser.hxx"))
return true;
// TODO marker parameter in constructor, should probably be using an enum
if (fn == SRCDIR "/framework/inc/uielement/uicommanddescription.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/framework/inc/uielement/uicommanddescription.hxx"))
return true;
if (fn == SRCDIR "/sd/source/ui/inc/SlideTransitionPane.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/sd/source/ui/inc/SlideTransitionPane.hxx"))
return true;
if (fn == SRCDIR "/sd/source/ui/animations/CustomAnimationPane.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/sd/source/ui/animations/CustomAnimationPane.hxx"))
return true;
if (fn == SRCDIR "/sd/source/ui/table/TableDesignPane.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/sd/source/ui/table/TableDesignPane.hxx"))
return true;
// debug stuff
if (fn == SRCDIR "/sc/source/core/data/column2.cxx")
if (loplugin::isSamePathname(fn, SRCDIR "/sc/source/core/data/column2.cxx"))
return true;
// weird stuff
if (fn == SRCDIR "/scaddins/source/analysis/analysishelper.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/scaddins/source/analysis/analysishelper.hxx"))
return true;
// SFX_DECL_CHILDWINDOWCONTEXT macro stuff
if (fn == SRCDIR "/sd/source/ui/inc/NavigatorChildWindow.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/sd/source/ui/inc/NavigatorChildWindow.hxx"))
return true;
// TODO, need to remove this from the .sdi file too
if (fn == SRCDIR "/sd/source/ui/inc/SlideSorterViewShell.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/sd/source/ui/inc/SlideSorterViewShell.hxx"))
return true;
if (fn == SRCDIR "/sd/source/ui/inc/OutlineViewShell.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/sd/source/ui/inc/OutlineViewShell.hxx"))
return true;
// SFX_DECL_INTERFACE macro stuff
if (fn == SRCDIR "/sd/source/ui/inc/ViewShellBase.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/sd/source/ui/inc/ViewShellBase.hxx"))
return true;
// debug stuff
if (fn == SRCDIR "/sd/source/filter/ppt/pptinanimations.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/sd/source/filter/ppt/pptinanimations.hxx"))
return true;
// takes pointer to fn
if (fn == SRCDIR "/include/sfx2/shell.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/include/sfx2/shell.hxx"))
return true;
// TODO, need to remove this from the .sdi file too
if (fqn == "SfxObjectShell::StateView_Impl")
return true;
// SFX_DECL_CHILDWINDOW_WITHID macro
if (fn == SRCDIR "/include/sfx2/infobar.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/include/sfx2/infobar.hxx"))
return true;
// this looks like vaguely useful code (ParseError) that I'm loathe to remove
if (fn == SRCDIR "/slideshow/source/inc/slideshowexceptions.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/slideshow/source/inc/slideshowexceptions.hxx"))
return true;
// SFX_DECL_VIEWFACTORY macro
if (fn == SRCDIR "/starmath/inc/view.hxx")
if (loplugin::isSamePathname(fn, SRCDIR "/starmath/inc/view.hxx"))
return true;
// debugging
if (fqn == "BrowseBox::DoShowCursor" || fqn == "BrowseBox::DoHideCursor")
......
......@@ -64,8 +64,8 @@ public:
std::string fn( compiler.getSourceManager().getFileEntryForID(
compiler.getSourceManager().getMainFileID())->getName() );
normalizeDotDotInFilePath(fn);
if (fn == SRCDIR "/basegfx/source/matrix/b2dhommatrix.cxx"
|| fn == SRCDIR "/basegfx/source/matrix/b3dhommatrix.cxx")
if (loplugin::isSamePathname(fn, SRCDIR "/basegfx/source/matrix/b2dhommatrix.cxx")
|| loplugin::isSamePathname(fn, SRCDIR "/basegfx/source/matrix/b3dhommatrix.cxx"))
return;
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
......@@ -118,7 +118,7 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde
return;
SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( functionDecl->getLocation() );
StringRef filename = compiler.getSourceManager().getFilename(expansionLoc);
if (!filename.startswith(SRCDIR))
if (!loplugin::hasPathnamePrefix(filename, SRCDIR))
return;
filename = filename.substr(strlen(SRCDIR)+1);
......
......@@ -94,16 +94,16 @@ bool ConstParams::VisitFunctionDecl(FunctionDecl * functionDecl)
}
StringRef aFileName = getFilename(functionDecl->getLocStart());
if (aFileName.startswith(SRCDIR "/sal/")
|| aFileName.startswith(SRCDIR "/bridges/")
|| aFileName.startswith(SRCDIR "/binaryurp/")
|| aFileName.startswith(SRCDIR "/stoc/")
|| aFileName.startswith(WORKDIR "/YaccTarget/unoidl/source/sourceprovider-parser.cxx")
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sal/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/bridges/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/binaryurp/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/stoc/")
|| loplugin::hasPathnamePrefix(aFileName, WORKDIR "/YaccTarget/unoidl/source/sourceprovider-parser.cxx")
// some weird calling through a function pointer
|| aFileName.startswith(SRCDIR "/svtools/source/table/defaultinputhandler.cxx")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/svtools/source/table/defaultinputhandler.cxx")
// windows only
|| aFileName.startswith(SRCDIR "/basic/source/sbx/sbxdec.cxx")
|| aFileName.startswith(SRCDIR "/sfx2/source/doc/syspath.cxx")) {
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/basic/source/sbx/sbxdec.cxx")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sfx2/source/doc/syspath.cxx")) {
return true;
}
......
......@@ -47,53 +47,53 @@ bool DataMemberShadow::VisitFieldDecl(FieldDecl const * fieldDecl)
// FIXME complex stuff to fix later
if (aFileName == SRCDIR "/connectivity/source/inc/calc/CTable.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/connectivity/source/inc/calc/CTable.hxx"))
return true;
if (aFileName.startswith(SRCDIR "/chart2/source/"))
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/chart2/source/"))
return true;
if (aFileName == SRCDIR "/cppcanvas/source/mtfrenderer/emfplus.cxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/cppcanvas/source/mtfrenderer/emfplus.cxx"))
return true;
if (aFileName == SRCDIR "/cui/source/customize/eventdlg.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/cui/source/customize/eventdlg.hxx"))
return true;
if (aFileName == SRCDIR "/include/sfx2/recentdocsview.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/include/sfx2/recentdocsview.hxx"))
return true;
if (aFileName == SRCDIR "/include/sfx2/templatelocalview.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/include/sfx2/templatelocalview.hxx"))
return true;
if (aFileName == SRCDIR "/filter/source/graphicfilter/idxf/dxfentrd.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/filter/source/graphicfilter/idxf/dxfentrd.hxx"))
return true;
if (aFileName == SRCDIR "/framework/source/uielement/popuptoolbarcontroller.cxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/framework/source/uielement/popuptoolbarcontroller.cxx"))
return true;
if (aFileName == SRCDIR "/lotuswordpro/source/filter/xfilter/xfcellstyle.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/lotuswordpro/source/filter/xfilter/xfcellstyle.hxx"))
return true;
if (aFileName == SRCDIR "/lotuswordpro/source/filter/xfilter/xfdrawobj.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/lotuswordpro/source/filter/xfilter/xfdrawobj.hxx"))
return true;
if (aFileName == SRCDIR "/sc/source/ui/vba/vbastyles.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/sc/source/ui/vba/vbastyles.hxx"))
return true;
if (aFileName == SRCDIR "/sd/inc/Outliner.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/sd/inc/Outliner.hxx"))
return true;
if (aFileName == SRCDIR "/sd/source/ui/annotations/annotationtag.cxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/sd/source/ui/annotations/annotationtag.cxx"))
return true;
if (aFileName == SRCDIR "/sd/source/ui/inc/FrameView.hxx"
|| aFileName == SRCDIR "/sd/source/filter/ppt/../../ui/inc/FrameView.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/sd/source/ui/inc/FrameView.hxx")
|| loplugin::isSamePathname(aFileName, SRCDIR "/sd/source/filter/ppt/../../ui/inc/FrameView.hxx"))
return true;
if (aFileName == SRCDIR "/sd/source/ui/inc/unopage.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/sd/source/ui/inc/unopage.hxx"))
return true;
if (aFileName == SRCDIR "/sd/source/ui/view/viewoverlaymanager.cxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/sd/source/ui/view/viewoverlaymanager.cxx"))
return true;
if (aFileName == SRCDIR "/sdext/source/presenter/PresenterSpritePane.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/sdext/source/presenter/PresenterSpritePane.hxx"))
return true;
if (aFileName == SRCDIR "/store/source/stortree.hxx"
|| aFileName == SRCDIR "/store/source/stordata.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/store/source/stortree.hxx")
|| loplugin::isSamePathname(aFileName, SRCDIR "/store/source/stordata.hxx"))
return true;
if (aFileName == SRCDIR "/svx/source/table/cell.hxx"
|| aFileName == SRCDIR "/svx/source/unodraw/../table/cell.hxx"
|| aFileName == SRCDIR "/svx/source/accessibility/../table/cell.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/svx/source/table/cell.hxx")
|| loplugin::isSamePathname(aFileName, SRCDIR "/svx/source/unodraw/../table/cell.hxx")
|| loplugin::isSamePathname(aFileName, SRCDIR "/svx/source/accessibility/../table/cell.hxx"))
return true;
if (aFileName == SRCDIR "/sw/source/uibase/inc/dbtree.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/sw/source/uibase/inc/dbtree.hxx"))
return true;
if (aFileName == SRCDIR "/vcl/unx/generic/print/genpspgraphics.cxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/vcl/unx/generic/print/genpspgraphics.cxx"))
return true;
if (aFileName == SRCDIR "/xmloff/source/draw/ximplink.hxx")
if (loplugin::isSamePathname(aFileName, SRCDIR "/xmloff/source/draw/ximplink.hxx"))
return true;
const CXXRecordDecl* parentCXXRecordDecl = dyn_cast<CXXRecordDecl>(fieldDecl->getDeclContext());
......
......@@ -59,7 +59,7 @@ bool ExternAndNotDefined::VisitFunctionDecl(const FunctionDecl * functionDecl) {
}
StringRef fileName { compiler.getSourceManager().getFilename(functionDecl->getLocation()) };
// the filters use some kind of dynamic loading stunt
if (fileName.startswith(SRCDIR "/filter/qa/")) {
if (loplugin::hasPathnamePrefix(fileName, SRCDIR "/filter/qa/")) {
return true;
}
report(
......
......@@ -70,7 +70,7 @@ bool FpComparison::ignore(FunctionDecl* function)
}
// we assume that these modules know what they are doing with FP stuff
StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(function->getLocStart()));
if (aFileName.startswith(SRCDIR "/sc/")) {
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sc/")) {
return true;
}
if (!function->doesThisDeclarationHaveABody()) {
......
......@@ -48,12 +48,12 @@ bool FragileDestructor::TraverseCXXDestructorDecl(CXXDestructorDecl* pCXXDestruc
// ignore this for now, too tricky for me to work out
StringRef aFileName = compiler.getSourceManager().getFilename(
compiler.getSourceManager().getSpellingLoc(pCXXDestructorDecl->getLocStart()));
if (aFileName.startswith(SRCDIR "/include/comphelper/")
|| aFileName.startswith(SRCDIR "/include/cppuhelper/")
|| aFileName.startswith(SRCDIR "/cppuhelper/")
|| aFileName.startswith(SRCDIR "/comphelper/")
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/comphelper/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/cppuhelper/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/cppuhelper/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/comphelper/")
// don't know how to detect this in clang - it is making an explicit call to it's own method, so presumably OK
|| aFileName == SRCDIR "/basic/source/sbx/sbxvalue.cxx"
|| loplugin::isSamePathname(aFileName, SRCDIR "/basic/source/sbx/sbxvalue.cxx")
)
return RecursiveASTVisitor::TraverseCXXDestructorDecl(pCXXDestructorDecl);
mbChecking = true;
......@@ -87,9 +87,9 @@ bool FragileDestructor::VisitCXXMemberCallExpr(const CXXMemberCallExpr* callExpr
}
// e.g. osl/thread.hxx and cppuhelper/compbase.hxx
StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(methodDecl->getLocStart()));
if (aFileName.startswith(SRCDIR "/include/osl/")
|| aFileName.startswith(SRCDIR "/include/comphelper/")
|| aFileName.startswith(SRCDIR "/include/cppuhelper/"))
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/osl/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/comphelper/")
|| loplugin::hasPathnamePrefix(aFileName, SRCDIR "/include/cppuhelper/"))
return true;
report(
DiagnosticsEngine::Warning,
......
......@@ -80,10 +80,10 @@ bool MemoryVar::TraverseFunctionDecl(FunctionDecl * decl)
// I'm not getting accurate results from clang right now
StringRef aFileName = getFilename(varLoc);
// TODO these files are doing some weird stuff I don't know how to ignore yet
if (aFileName.startswith(SRCDIR "/vcl/source/filter")) {
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/vcl/source/filter")) {
return true;
}
if (aFileName.startswith(SRCDIR "/sw/source/core/layout/frmtool.cxx")) {
if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/sw/source/core/layout/frmtool.cxx")) {
return true;
}
......
......@@ -230,8 +230,9 @@ bool Nullptr::TraverseLinkageSpecDecl(LinkageSpecDecl * decl) {
}
bool Nullptr::isInLokIncludeFile(SourceLocation spellingLocation) const {
return compiler.getSourceManager().getFilename(spellingLocation)
.startswith(SRCDIR "/include/LibreOfficeKit/");
return loplugin::hasPathnamePrefix(
compiler.getSourceManager().getFilename(spellingLocation),
SRCDIR "/include/LibreOfficeKit/");
}
bool Nullptr::isFromCIncludeFile(SourceLocation spellingLocation) const {
......
......@@ -12,6 +12,7 @@
#include "plugin.hxx"
#include <cassert>
#include <cstddef>
#include <string>
#include <clang/Basic/FileManager.h>
......@@ -42,8 +43,8 @@ bool Plugin::ignoreLocation( SourceLocation loc )
return true;
const char* bufferName = compiler.getSourceManager().getPresumedLoc( expansionLoc ).getFilename();
if (bufferName == NULL
|| strncmp( bufferName, SRCDIR "/external/", strlen( SRCDIR "/external/" )) == 0
|| strcmp( bufferName, SRCDIR "/sdext/source/pdfimport/wrapper/keyword_list" ) == 0 )
|| hasPathnamePrefix(bufferName, SRCDIR "/external/")
|| isSamePathname(bufferName, SRCDIR "/sdext/source/pdfimport/wrapper/keyword_list") )
// workdir/CustomTarget/sdext/pdfimport/hash.cxx is generated from
// sdext/source/pdfimport/wrapper/keyword_list by gperf, which
// inserts various #line directives denoting the latter into the
......@@ -55,7 +56,7 @@ bool Plugin::ignoreLocation( SourceLocation loc )
// generated into the start of hash.cxx, #if'ed for __GNUC__, but
// for clang-cl it is an issue)
return true;
if( strncmp( bufferName, WORKDIR, strlen( WORKDIR )) == 0 )
if( hasPathnamePrefix(bufferName, WORKDIR) )
{
// workdir/CustomTarget/vcl/unx/kde4/tst_exclude_socket_notifiers.moc
// includes
......@@ -67,12 +68,12 @@ bool Plugin::ignoreLocation( SourceLocation loc )
}
std::string s(bufferName);
normalizeDotDotInFilePath(s);
if (strncmp(s.c_str(), WORKDIR, strlen(WORKDIR)) == 0) {
if (hasPathnamePrefix(s, WORKDIR)) {
return true;
}
}
if( strncmp( bufferName, BUILDDIR, strlen( BUILDDIR )) == 0
|| strncmp( bufferName, SRCDIR, strlen( SRCDIR )) == 0 )
if( hasPathnamePrefix(bufferName, BUILDDIR)
|| hasPathnamePrefix(bufferName, SRCDIR) )
return false; // ok
return true;
}
......@@ -165,19 +166,19 @@ bool Plugin::isInUnoIncludeFile(SourceLocation spellingLocation) const {
StringRef name {
compiler.getSourceManager().getFilename(spellingLocation) };
return compiler.getSourceManager().isInMainFile(spellingLocation)
? (name == SRCDIR "/cppu/source/cppu/compat.cxx"
|| name == SRCDIR "/cppuhelper/source/compat.cxx"
|| name == SRCDIR "/sal/osl/all/compat.cxx")
: (name.startswith(SRCDIR "/include/com/")
|| name.startswith(SRCDIR "/include/cppu/")
|| name.startswith(SRCDIR "/include/cppuhelper/")
|| name.startswith(SRCDIR "/include/osl/")
|| name.startswith(SRCDIR "/include/rtl/")
|| name.startswith(SRCDIR "/include/sal/")
|| name.startswith(SRCDIR "/include/salhelper/")
|| name.startswith(SRCDIR "/include/systools/")
|| name.startswith(SRCDIR "/include/typelib/")
|| name.startswith(SRCDIR "/include/uno/"));
? (isSamePathname(name, SRCDIR "/cppu/source/cppu/compat.cxx")
|| isSamePathname(name, SRCDIR "/cppuhelper/source/compat.cxx")
|| isSamePathname(name, SRCDIR "/sal/osl/all/compat.cxx"))
: (hasPathnamePrefix(name, SRCDIR "/include/com/")
|| hasPathnamePrefix(name, SRCDIR "/include/cppu/")
|| hasPathnamePrefix(name, SRCDIR "/include/cppuhelper/")
|| hasPathnamePrefix(name, SRCDIR "/include/osl/")
|| hasPathnamePrefix(name, SRCDIR "/include/rtl/")
|| hasPathnamePrefix(name, SRCDIR "/include/sal/")
|| hasPathnamePrefix(name, SRCDIR "/include/salhelper/")
|| hasPathnamePrefix(name, SRCDIR "/include/systools/")
|| hasPathnamePrefix(name, SRCDIR "/include/typelib/")
|| hasPathnamePrefix(name, SRCDIR "/include/uno/"));
}
bool Plugin::isInUnoIncludeFile(const FunctionDecl* functionDecl) const {
......@@ -423,6 +424,44 @@ bool RewritePlugin::reportEditFailure( SourceLocation loc )
return false;
}
namespace {
template<typename Fn> bool checkPathname(
StringRef pathname, StringRef against, Fn check)
{
if (check(pathname, against)) {
return true;
}
#if defined _WIN32
for (std::size_t n = 0;;) {
std::size_t n1 = pathname.find('\\', n);
if (n1 >= against.size()) {
return check(pathname.substr(n), against.substr(n));
}
if (against[n1] != '/'
|| pathname.substr(n, n1 - n) != against.substr(n, n1 - n))
{
break;
}
n = n1 + 1;
}
#endif
return false;
}
}
bool hasPathnamePrefix(StringRef pathname, StringRef prefix) {
return checkPathname(
pathname, prefix,
[](StringRef p, StringRef a) { return p.startswith(a); });
}
bool isSamePathname(StringRef pathname, StringRef other) {
return checkPathname(
pathname, other, [](StringRef p, StringRef a) { return p == a; });
}
} // namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -222,6 +222,14 @@ RewritePlugin::RewriteOption operator|( RewritePlugin::RewriteOption option1, Re
return static_cast< RewritePlugin::RewriteOption >( int( option1 ) | int( option2 ));
}
// Same as pathname.startswith(prefix), except on Windows, where pathname (but
// not prefix) may also contain backslashes:
bool hasPathnamePrefix(StringRef pathname, StringRef prefix);
// Same as pathname == other, except on Windows, where pathname (but not other)
// may also contain backslashes:
bool isSamePathname(StringRef pathname, StringRef other);
} // namespace
#endif // COMPILEPLUGIN_H
......
......@@ -448,7 +448,7 @@ bool RefCounting::VisitVarDecl(const VarDecl * varDecl) {
if (containsSalhelperReferenceObjectSubclass(varDecl->getType().getTypePtr())) {
StringRef name { compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(varDecl->getLocation())) };
// this is playing games that it believes is safe
if (name == SRCDIR "/stoc/source/security/permissions.cxx")
if (loplugin::isSamePathname(name, SRCDIR "/stoc/source/security/permissions.cxx"))
return true;
report(
DiagnosticsEngine::Warning,
......
......@@ -75,8 +75,14 @@ void ReservedId::run() {
if (loc.isValid() && !ignoreLocation(loc)) {
auto file = compiler.getSourceManager()
.getFilename(loc);
if (file != SRCDIR "/include/cppuhelper/implbase_ex_post.hxx"
&& file != SRCDIR "/include/cppuhelper/implbase_ex_pre.hxx")
if (!loplugin::isSamePathname(
file,
SRCDIR
"/include/cppuhelper/implbase_ex_post.hxx")
&& !loplugin::isSamePathname(
file,
SRCDIR
"/include/cppuhelper/implbase_ex_pre.hxx"))
{
report(
DiagnosticsEngine::Warning,
......@@ -102,7 +108,7 @@ bool ReservedId::VisitNamedDecl(NamedDecl const * decl) {
return true;
}
auto filename = compiler.getSourceManager().getFilename(spelLoc);
if (filename.startswith(SRCDIR "/bridges/source/cpp_uno/")
if (loplugin::hasPathnamePrefix(filename, SRCDIR "/bridges/source/cpp_uno/")
&& filename.endswith("share.hxx"))
{
return true;
......@@ -215,7 +221,8 @@ ReservedId::Kind ReservedId::determineKind(llvm::StringRef const & id) {
}
bool ReservedId::isInLokIncludeFile(SourceLocation spellingLocation) const {
return compiler.getSourceManager().getFilename(spellingLocation).startswith(
return loplugin::hasPathnamePrefix(
compiler.getSourceManager().getFilename(spellingLocation),
SRCDIR "/include/LibreOfficeKit/");
}
......
......@@ -763,8 +763,9 @@ bool SalBool::TraverseStaticAssertDecl(StaticAssertDecl * decl) {
//
// inside static_assert in cppu/source/uno/check.cxx:
return
(compiler.getSourceManager().getFilename(decl->getLocation())
== SRCDIR "/cppu/source/uno/check.cxx")
loplugin::isSamePathname(
compiler.getSourceManager().getFilename(decl->getLocation()),
SRCDIR "/cppu/source/uno/check.cxx")
|| RecursiveASTVisitor::TraverseStaticAssertDecl(decl);
}
......@@ -800,8 +801,9 @@ bool SalBool::isInSpecialMainFile(SourceLocation spellingLocation) const {
return false;
}
auto f = compiler.getSourceManager().getFilename(spellingLocation);
return f == SRCDIR "/cppu/qa/test_any.cxx"
|| f == SRCDIR "/cppu/source/uno/check.cxx"; // TODO: the offset checks
return loplugin::isSamePathname(f, SRCDIR "/cppu/qa/test_any.cxx")
|| loplugin::isSamePathname(f, SRCDIR "/cppu/source/uno/check.cxx");
// TODO: the offset checks
}
bool SalBool::rewrite(SourceLocation location) {
......
......@@ -99,12 +99,12 @@ bool StaticMethods::TraverseCXXMethodDecl(const CXXMethodDecl * pCXXMethodDecl)
return true;
}
// don't mess with the backwards compatibility stuff
if (getFilename(pCXXMethodDecl->getLocStart()) == SRCDIR "/cppuhelper/source/compat.cxx") {
if (loplugin::isSamePathname(getFilename(pCXXMethodDecl->getLocStart()), SRCDIR "/cppuhelper/source/compat.cxx")) {
return true;
}
// the DDE has a dummy implementation on Linux and a real one on Windows
std::string aFilename = getFilename(pCXXMethodDecl->getCanonicalDecl()->getLocStart());
if (aFilename == SRCDIR "/include/svl/svdde.hxx") {
if (loplugin::isSamePathname(aFilename, SRCDIR "/include/svl/svdde.hxx")) {
return true;
}
auto cdc = loplugin::DeclCheck(pCXXMethodDecl->getParent());
......@@ -124,17 +124,17 @@ bool StaticMethods::TraverseCXXMethodDecl(const CXXMethodDecl * pCXXMethodDecl)
return true;
}
// the unotools and svl config code stuff is doing weird stuff with a reference-counted statically allocated pImpl class
if (startsWith(aFilename, SRCDIR "/include/unotools")) {
if (loplugin::hasPathnamePrefix(aFilename, SRCDIR "/include/unotools")) {
return true;