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

Noel Grandin noel at peralex.com
Tue Jun 24 03:58:47 PDT 2014


 compilerplugins/clang/inlinesimplememberfunctions.cxx |   34 +-----------------
 compilerplugins/clang/plugin.cxx                      |   23 ++++++++++++
 compilerplugins/clang/plugin.hxx                      |    5 ++
 compilerplugins/clang/returnbyref.cxx                 |   32 ----------------
 compilerplugins/clang/store/salbool.cxx               |   34 ------------------
 compilerplugins/clang/unreffun.cxx                    |   22 -----------
 6 files changed, 31 insertions(+), 119 deletions(-)

New commits:
commit a74193306a10a98902d192b8f7cecb92b4817c23
Author: Noel Grandin <noel at peralex.com>
Date:   Tue Jun 24 12:47:28 2014 +0200

    compilerplugins: move isUnoIncludeFile to base class
    
    to reduce copy-pasted code
    
    Change-Id: I7728d85dea7d0161998c326d6648ca681a8250d0

diff --git a/compilerplugins/clang/inlinesimplememberfunctions.cxx b/compilerplugins/clang/inlinesimplememberfunctions.cxx
index 7fa43a4..42dd256 100644
--- a/compilerplugins/clang/inlinesimplememberfunctions.cxx
+++ b/compilerplugins/clang/inlinesimplememberfunctions.cxx
@@ -10,6 +10,7 @@
 #include <string>
 
 #include "plugin.hxx"
+#include "compat.hxx"
 
 // Methods that purely return a local field should be declared in the header and be declared inline.
 // So that the compiler can elide the function call and turn it into a simple fixed-offset-load instruction.
@@ -26,8 +27,6 @@ public:
 
     bool VisitCXXMethodDecl(const CXXMethodDecl * decl);
 private:
-    bool isInUnoIncludeFile(SourceLocation spellingLocation) const;
-    bool isInMainFile(SourceLocation spellingLocation) const;
     bool rewrite(const CXXMethodDecl * functionDecl);
 };
 
@@ -216,35 +215,6 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct
     return true;
 }
 
-bool InlineSimpleMemberFunctions::isInUnoIncludeFile(SourceLocation spellingLocation) const {
-    StringRef name {
-        compiler.getSourceManager().getFilename(spellingLocation) };
-    return 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/")
-           || name.startswith(SRCDIR "/workdir/")
-           || name == SRCDIR "/include/comphelper/implbase_var.hxx");
-}
-
-bool InlineSimpleMemberFunctions::isInMainFile(SourceLocation spellingLocation) const {
-#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
-    return compiler.getSourceManager().isInMainFile(spellingLocation);
-#else
-    return compiler.getSourceManager().isFromMainFile(spellingLocation);
-#endif
-}
-
 static std::string ReplaceString(std::string subject, const std::string& search,
                           const std::string& replace) {
     size_t pos = 0;
@@ -264,7 +234,7 @@ bool InlineSimpleMemberFunctions::rewrite(const CXXMethodDecl * functionDecl) {
     // definition (in a main file only processed later) to fail
     // with a "mismatch" error before the rewriter had a chance
     // to act upon the definition.
-    if (!isInMainFile(
+    if (!compat::isInMainFile( compiler.getSourceManager(),
                compiler.getSourceManager().getSpellingLoc(
                    functionDecl->getNameInfo().getLoc()))) {
         return false;
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index f319e60..4a39182 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -17,6 +17,7 @@
 #include <clang/Lex/Lexer.h>
 
 #include "pluginhandler.hxx"
+#include "compat.hxx"
 
 /*
 Base classes for plugin actions.
@@ -73,6 +74,28 @@ Stmt* Plugin::parentStmt( Stmt* stmt )
     return const_cast< Stmt* >( parents[ stmt ] );
     }
 
+
+bool Plugin::isInUnoIncludeFile(SourceLocation spellingLocation) const {
+    StringRef name {
+        compiler.getSourceManager().getFilename(spellingLocation) };
+    return compat::isInMainFile(compiler.getSourceManager(), 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/")
+           || name.startswith(SRCDIR "/workdir/")
+           || name == SRCDIR "/include/comphelper/implbase_var.hxx");
+}
+
 namespace
 {
 class ParentBuilder
diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx
index afdecdd..867396c 100644
--- a/compilerplugins/clang/plugin.hxx
+++ b/compilerplugins/clang/plugin.hxx
@@ -73,6 +73,11 @@ class Plugin
         */
         const Stmt* parentStmt( const Stmt* stmt );
         Stmt* parentStmt( Stmt* stmt );
+        /**
+         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.
+        */
+        bool isInUnoIncludeFile(SourceLocation spellingLocation) const;
     private:
         static void registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault );
         template< typename T > static Plugin* createHelper( const InstantiationData& data );
diff --git a/compilerplugins/clang/returnbyref.cxx b/compilerplugins/clang/returnbyref.cxx
index b5f32ee..59bee67 100644
--- a/compilerplugins/clang/returnbyref.cxx
+++ b/compilerplugins/clang/returnbyref.cxx
@@ -34,9 +34,6 @@ public:
     virtual void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
 
     bool VisitCXXMethodDecl(const CXXMethodDecl * decl);
-private:
-    bool isInUnoIncludeFile(SourceLocation spellingLocation) const;
-    bool isInMainFile(SourceLocation spellingLocation) const;
 };
 
 bool ReturnByRef::VisitCXXMethodDecl(const CXXMethodDecl * functionDecl) {
@@ -118,35 +115,6 @@ bool ReturnByRef::VisitCXXMethodDecl(const CXXMethodDecl * functionDecl) {
     return true;
 }
 
-bool ReturnByRef::isInUnoIncludeFile(SourceLocation spellingLocation) const {
-    StringRef name {
-        compiler.getSourceManager().getFilename(spellingLocation) };
-    return 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/")
-           || name.startswith(SRCDIR "/workdir/")
-           || name == SRCDIR "/include/comphelper/implbase_var.hxx");
-}
-
-bool ReturnByRef::isInMainFile(SourceLocation spellingLocation) const {
-#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
-    return compiler.getSourceManager().isInMainFile(spellingLocation);
-#else
-    return compiler.getSourceManager().isFromMainFile(spellingLocation);
-#endif
-}
-
 loplugin::Plugin::Registration< ReturnByRef > X("returnbyref");
 
 }
diff --git a/compilerplugins/clang/store/salbool.cxx b/compilerplugins/clang/store/salbool.cxx
index 1ad076a..abef250 100644
--- a/compilerplugins/clang/store/salbool.cxx
+++ b/compilerplugins/clang/store/salbool.cxx
@@ -133,12 +133,8 @@ public:
     bool VisitValueDecl(ValueDecl const * decl);
 
 private:
-    bool isInUnoIncludeFile(SourceLocation spellingLocation) const;
-
     bool isInSpecialMainFile(SourceLocation spellingLocation) const;
 
-    bool isInMainFile(SourceLocation spellingLocation) const;
-
     bool isMacroBodyExpansion(SourceLocation location) const;
 
     bool rewrite(SourceLocation location);
@@ -501,40 +497,12 @@ bool SalBool::VisitValueDecl(ValueDecl const * decl) {
     return true;
 }
 
-bool SalBool::isInUnoIncludeFile(SourceLocation spellingLocation) const {
-    StringRef name {
-        compiler.getSourceManager().getFilename(spellingLocation) };
-    return 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/")
-           || name == SRCDIR "/include/comphelper/implbase_var.hxx");
-}
-
 bool SalBool::isInSpecialMainFile(SourceLocation spellingLocation) const {
-    return isInMainFile(spellingLocation)
+    return compat::isInMainFile(spellingLocation)
         && (compiler.getSourceManager().getFilename(spellingLocation)
             == SRCDIR "/cppu/qa/test_any.cxx");
 }
 
-bool SalBool::isInMainFile(SourceLocation spellingLocation) const {
-#if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3
-    return compiler.getSourceManager().isInMainFile(spellingLocation);
-#else
-    return compiler.getSourceManager().isFromMainFile(spellingLocation);
-#endif
-}
-
 bool SalBool::isMacroBodyExpansion(SourceLocation location) const {
 #if (__clang_major__ == 3 && __clang_minor__ >= 3) || __clang_major__ > 3
     return compiler.getSourceManager().isMacroBodyExpansion(location);
diff --git a/compilerplugins/clang/unreffun.cxx b/compilerplugins/clang/unreffun.cxx
index d49ad29..eece97f 100644
--- a/compilerplugins/clang/unreffun.cxx
+++ b/compilerplugins/clang/unreffun.cxx
@@ -53,9 +53,6 @@ public:
     { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
 
     bool VisitFunctionDecl(FunctionDecl const * decl);
-
-private:
-    bool isInUnoIncludeFile(SourceLocation spellingLocation) const;
 };
 
 bool UnrefFun::VisitFunctionDecl(FunctionDecl const * decl) {
@@ -122,25 +119,6 @@ bool UnrefFun::VisitFunctionDecl(FunctionDecl const * decl) {
     return true;
 }
 
-bool UnrefFun::isInUnoIncludeFile(SourceLocation spellingLocation) const {
-    StringRef name {
-        compiler.getSourceManager().getFilename(spellingLocation) };
-    return compat::isInMainFile(compiler.getSourceManager(), 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/"));
-}
-
 loplugin::Plugin::Registration<UnrefFun> X("unreffun");
 
 }


More information about the Libreoffice-commits mailing list