[Libreoffice-commits] dev-tools.git: clang/bin clang/find-unprefixed-members.cxx clang/rename.cxx

Miklos Vajna vmiklos at collabora.co.uk
Mon Jan 18 00:39:13 PST 2016


 clang/bin/rename-wrapper          |   19 ++++++++
 clang/find-unprefixed-members.cxx |   85 +++++++++++++++++++++++++++++++-------
 clang/rename.cxx                  |    2 
 3 files changed, 90 insertions(+), 16 deletions(-)

New commits:
commit aa9424be6303cec6e1c8bcba369b66e2b7701fa3
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Jan 18 09:38:45 2016 +0100

    clang: initial online.git support
    
    1) Support autotools next to gbuild in rename-wrapper.
    
    2) Support Poco-style naming convention in find-unprefixed-members.

diff --git a/clang/bin/rename-wrapper b/clang/bin/rename-wrapper
index a67743f..b13fb90 100755
--- a/clang/bin/rename-wrapper
+++ b/clang/bin/rename-wrapper
@@ -6,16 +6,33 @@ if [ -h $0 ]; then
 fi
 
 c=
+o=
+file=
 for i in "$@"
 do
     if [ "$i" = "-c" ]; then
         c=1
+    elif [ "$i" = "-o" ]; then
+        o=1
+    elif [ -n "$o" ]; then
+        o=
     elif [ -n "$c" ]; then
         file=$i
         break
     fi
 done
 
-exec $mydir/rename $RENAME_ARGS $file -- "$@"
+ret=0
+if [ -n "$file" ]; then
+    $mydir/rename $RENAME_ARGS $file -- "$@"
+    ret=$?
+fi
+
+# gbuild detected or error: no need to call the real compiler
+if [ $ret -gt 0 -o -n "$COMPILER_EXTERNAL_TOOL" ]; then
+    exit $ret
+fi
+
+exec "$@"
 
 # vi:set shiftwidth=4 expandtab:
diff --git a/clang/find-unprefixed-members.cxx b/clang/find-unprefixed-members.cxx
index 9cb3503..981b4b7 100644
--- a/clang/find-unprefixed-members.cxx
+++ b/clang/find-unprefixed-members.cxx
@@ -14,21 +14,78 @@ class Context
 {
     std::string m_aClassName;
     std::string m_aClassPrefix;
+    std::set<std::string> m_aClassExcludedPrefixes;
+    bool m_bPoco;
 
 public:
-    Context(const std::string& rClassName, const std::string& rClassPrefix)
+    Context(const std::string& rClassName, const std::string& rClassPrefix, const std::string& rClassExcludedPrefix, bool bPoco)
         : m_aClassName(rClassName),
-          m_aClassPrefix(rClassPrefix)
+          m_aClassPrefix(rClassPrefix),
+          m_bPoco(bPoco)
     {
+        std::stringstream aStream(rClassExcludedPrefix);
+        std::string aExclude;
+        while (std::getline(aStream, aExclude, ','))
+            m_aClassExcludedPrefixes.insert(aExclude);
     }
 
     bool match(const std::string& rName) const
     {
         if (m_aClassName == "")
-            return rName.find(m_aClassPrefix) == 0;
+        {
+            bool bRet = rName.find(m_aClassPrefix) == 0;
+            if (bRet)
+            {
+                for (const std::string& rPrefix : m_aClassExcludedPrefixes)
+                    if (rName.find(rPrefix) == 0)
+                        return false;
+                return true;
+            }
+            else
+                return false;
+        }
         else
             return rName == m_aClassName;
     }
+
+    /// Checks if a non-static member has an expected name
+    bool checkNonStatic(const std::string& rName) const
+    {
+        if (m_bPoco)
+            return rName.find("_") == 0;
+        else
+            return rName.find("m") == 0;
+    }
+
+    /// Checks if a static member has an expected name
+    bool checkStatic(const std::string& rName) const
+    {
+        if (m_bPoco)
+            return !rName.empty() && rName[0] >= 'A' && rName[0] <= 'Z';
+        else
+            return rName.find("s") == 0;
+    }
+
+    /// Suggest a better name, provided that checkNonStatic() returned false.
+    void suggestNonStatic(std::string& rName) const
+    {
+        if (m_bPoco)
+            rName.insert(0, "_");
+        else
+            rName.insert(0, "m_");
+    }
+
+    /// Suggest a better name, provided that checkStatic() returned false.
+    void suggestStatic(std::string& rName) const
+    {
+        if (m_bPoco)
+        {
+            if (!rName.empty())
+                rName[0] = toupper(rName[0]);
+        }
+        else
+            rName.insert(0, "s_");
+    }
 };
 
 class Visitor : public clang::RecursiveASTVisitor<Visitor>
@@ -69,9 +126,9 @@ public:
         if (m_rContext.match(pRecord->getQualifiedNameAsString()))
         {
             std::string aName = pDecl->getNameAsString();
-            if (aName.find("m") != 0)
+            if (!m_rContext.checkNonStatic(aName))
             {
-                aName.insert(0, "m_");
+                m_rContext.suggestNonStatic(aName);
                 std::stringstream ss;
                 ss << pDecl->getNameAsString() << "," << aName;
                 m_aResults.push_back(std::make_pair(pRecord->getQualifiedNameAsString(), ss.str()));
@@ -98,9 +155,9 @@ public:
         if (pRecord && m_rContext.match(pRecord->getQualifiedNameAsString()))
         {
             std::string aName = pDecl->getNameAsString();
-            if (aName.find("s") != 0)
+            if (!m_rContext.checkStatic(aName))
             {
-                aName.insert(0, "s_");
+                m_rContext.suggestStatic(aName);
                 std::stringstream ss;
                 ss << pDecl->getNameAsString() << "," << aName;
                 m_aResults.push_back(std::make_pair(pRecord->getQualifiedNameAsString(), ss.str()));
@@ -193,17 +250,17 @@ int main(int argc, const char** argv)
     llvm::cl::opt<std::string> aClassPrefix("class-prefix",
                                             llvm::cl::desc("Qualified name prefix (e.g. namespace::Cl)."),
                                             llvm::cl::cat(aCategory));
+    llvm::cl::opt<std::string> aClassExcludedPrefix("class-excluded-prefix",
+            llvm::cl::desc("Qualified name prefix to exclude (e.g. std::), has priority over the -class-prefix include."),
+            llvm::cl::cat(aCategory));
+    llvm::cl::opt<bool> bPoco("poco",
+                              llvm::cl::desc("Expect Poco-style '_' instead of LibreOffice-style 'm_' as prefix."),
+                              llvm::cl::cat(aCategory));
     clang::tooling::CommonOptionsParser aParser(argc, argv, aCategory);
 
-    if (aClassName.empty() && aClassPrefix.empty())
-    {
-        std::cerr << "-class-name or -class-prefix is required." << std::endl;
-        return 1;
-    }
-
     clang::tooling::ClangTool aTool(aParser.getCompilations(), aParser.getSourcePathList());
 
-    Context aContext(aClassName, aClassPrefix);
+    Context aContext(aClassName, aClassPrefix, aClassExcludedPrefix, bPoco);
     FrontendAction aAction(aContext);
     std::unique_ptr<clang::tooling::FrontendActionFactory> pFactory = clang::tooling::newFrontendActionFactory(&aAction);
     return aTool.run(pFactory.get());
diff --git a/clang/rename.cxx b/clang/rename.cxx
index 352a90b..902c6d5 100644
--- a/clang/rename.cxx
+++ b/clang/rename.cxx
@@ -19,7 +19,7 @@ class RenameRewriter : public clang::Rewriter
 public:
     RenameRewriter(const std::map<std::string, std::string>& rNameMap, bool bDump)
         : maNameMap(rNameMap),
-        mbDump(bDump)
+          mbDump(bDump)
     {
     }
 


More information about the Libreoffice-commits mailing list