[Libreoffice-commits] core.git: compilerplugins/clang

Stephan Bergmann sbergman at redhat.com
Fri Oct 27 14:00:22 UTC 2017


 compilerplugins/clang/includeform.cxx |   11 ++++++++++-
 compilerplugins/clang/plugin.cxx      |   29 +++++++++++++++++++++--------
 compilerplugins/clang/plugin.hxx      |    8 ++++----
 3 files changed, 35 insertions(+), 13 deletions(-)

New commits:
commit 2db621da6660d56f3ff1954adf4ed8ce71834bf6
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Oct 27 15:57:48 2017 +0200

    Adapt loplugin:includeform to Windows \ path separator
    
    This can also call loplugin::isSamePathname with two paths that both contain
    backslashes, so finally make it (and hasPathnamePrefix) symmetric in which
    arguments my contain backslashes.
    
    Change-Id: I0465988d9d41e21c5660cbdbd1558543860ae1ad

diff --git a/compilerplugins/clang/includeform.cxx b/compilerplugins/clang/includeform.cxx
index b3ab195fbe09..11bf2865c58c 100644
--- a/compilerplugins/clang/includeform.cxx
+++ b/compilerplugins/clang/includeform.cxx
@@ -52,7 +52,16 @@ private:
             auto const file = StringRef(
                 compiler.getSourceManager().getPresumedLoc(HashLoc)
                 .getFilename());
-            auto const dir = compat::take_front(file, file.rfind('/'));
+            auto pos = file.rfind('/');
+#if defined _WIN32
+            auto const pos2 = file.rfind('\\');
+            if (pos2 != StringRef::npos
+                && (pos == StringRef::npos || pos2 > pos))
+            {
+                pos = pos2;
+            }
+#endif
+            auto const dir = compat::take_front(file, pos);
             shouldUseAngles = !loplugin::isSamePathname(SearchPath, dir);
         }
         if (shouldUseAngles == IsAngled) {
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index 077b24370f71..7d53e71dfd61 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -442,15 +442,28 @@ template<typename Fn> bool checkPathname(
     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;
+        std::size_t n2 = against.find('\\', n);
+        if (n1 <= n2) {
+            if (n1 >= against.size()) {
+                return check(pathname.substr(n), against.substr(n));
+            }
+            if ((against[n1] != '/' && against[n1] != '\\')
+                || pathname.substr(n, n1 - n) != against.substr(n, n1 - n))
+            {
+                break;
+            }
+            n = n1 + 1;
+        } else {
+            if (n2 >= pathname.size()) {
+                return check(pathname.substr(n), against.substr(n));
+            }
+            if (pathname[n2] != '/'
+                || pathname.substr(n, n2 - n) != against.substr(n, n2 - n))
+            {
+                break;
+            }
+            n = n2 + 1;
         }
-        n = n1 + 1;
     }
 #endif
     return false;
diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx
index 1f57dfeb0ffa..89d9999255df 100644
--- a/compilerplugins/clang/plugin.hxx
+++ b/compilerplugins/clang/plugin.hxx
@@ -215,12 +215,12 @@ 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:
+// Same as pathname.startswith(prefix), except on Windows, where pathname and
+// 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:
+// Same as pathname == other, except on Windows, where pathname and other may
+// also contain backslashes:
 bool isSamePathname(StringRef pathname, StringRef other);
 
 } // namespace


More information about the Libreoffice-commits mailing list