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

Stephan Bergmann sbergman at redhat.com
Wed Jan 29 00:58:39 PST 2014


 compilerplugins/clang/literaltoboolconversion.cxx |   40 +++++++++++++++++++---
 1 file changed, 35 insertions(+), 5 deletions(-)

New commits:
commit d433d8245b821f8cf0510f2497ecd82aff036609
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Jan 29 09:58:10 2014 +0100

    Fix for old Clang versions
    
    Change-Id: Ib902535c03a9f1b93a2c4ff3dd61d29e316bfd49

diff --git a/compilerplugins/clang/literaltoboolconversion.cxx b/compilerplugins/clang/literaltoboolconversion.cxx
index a3779e2..1ede8b5 100644
--- a/compilerplugins/clang/literaltoboolconversion.cxx
+++ b/compilerplugins/clang/literaltoboolconversion.cxx
@@ -25,6 +25,11 @@ public:
     { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
 
     bool VisitImplicitCastExpr(ImplicitCastExpr const * expr);
+
+private:
+    bool isFromCIncludeFile(SourceLocation spellingLocation) const;
+
+    bool isMacroBodyExpansion(SourceLocation location) const;
 };
 
 bool LiteralToBoolConversion::VisitImplicitCastExpr(
@@ -46,17 +51,15 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
         while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
             loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
         }
-        if (compiler.getSourceManager().isMacroBodyExpansion(loc)) {
+        if (isMacroBodyExpansion(loc)) {
             StringRef name { Lexer::getImmediateMacroName(
                 loc, compiler.getSourceManager(), compiler.getLangOpts()) };
             if (name == "sal_False" || name == "sal_True") {
                 loc = compiler.getSourceManager().getImmediateExpansionRange(
                     loc).first;
             }
-            SourceLocation spl { compiler.getSourceManager().getSpellingLoc(
-                loc) };
-            if (!compiler.getSourceManager().isInMainFile(spl)
-                && compiler.getSourceManager().getFilename(spl).endswith(".h"))
+            if (isFromCIncludeFile(
+                    compiler.getSourceManager().getSpellingLoc(loc)))
             {
                 return true;
             }
@@ -134,6 +137,33 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
     return true;
 }
 
+bool LiteralToBoolConversion::isFromCIncludeFile(
+    SourceLocation spellingLocation) const
+{
+#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
+    if (compiler.getSourceManager().isInMainFile(spellingLocation)) {
+        return false;
+    }
+#else
+    if (compiler.getSourceManager().isFromMainFile(spellingLocation)) {
+        return false;
+    }
+#endif
+    return compiler.getSourceManager().getFilename(spellingLocation).endswith(
+        ".h");
+}
+
+bool LiteralToBoolConversion::isMacroBodyExpansion(SourceLocation location)
+    const
+{
+#if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
+    return compiler.getSourceManager().isMacroBodyExpansion(location);
+#else
+    return location.isMacroID()
+        && !compiler.getSourceManager().isMacroArgExpansion(location);
+#endif
+}
+
 loplugin::Plugin::Registration<LiteralToBoolConversion> X(
     "literaltoboolconversion", true);
 


More information about the Libreoffice-commits mailing list