clang/find-unprefixed-members.cxx | 62 +++++++++++++++++++++++++++++++------- clang/test.hxx | 5 +++ 2 files changed, 57 insertions(+), 10 deletions(-)
New commits: commit 49464ca6ecfcd7398ded778f047e002b5fa4cc60 Author: Miklos Vajna <[email protected]> Date: Tue Sep 29 21:29:09 2015 +0200 clang: ignore structs without ctor/dtor/member funs in find-unprefixed-members diff --git a/clang/find-unprefixed-members.cxx b/clang/find-unprefixed-members.cxx index 52b1529..1d5c67f 100644 --- a/clang/find-unprefixed-members.cxx +++ b/clang/find-unprefixed-members.cxx @@ -34,18 +34,23 @@ public: class Visitor : public clang::RecursiveASTVisitor<Visitor> { const Context m_rContext; - bool m_bFound; + std::vector<std::string> m_aResults; + std::set<std::string> m_aFunctions; public: Visitor(const Context& rContext) - : m_rContext(rContext), - m_bFound(false) + : m_rContext(rContext) { } - bool getFound() + const std::vector<std::string>& getResults() { - return m_bFound; + return m_aResults; + } + + const std::set<std::string>& getFunctions() + { + return m_aFunctions; } /* @@ -65,8 +70,9 @@ public: if (aName.find("m") != 0) { aName.insert(0, "m_"); - std::cout << pRecord->getQualifiedNameAsString() << "::" << pDecl->getNameAsString() << "," << aName << std::endl; - m_bFound = true; + std::stringstream ss; + ss << pRecord->getQualifiedNameAsString() << "::" << pDecl->getNameAsString() << "," << aName; + m_aResults.push_back(ss.str()); } } @@ -93,13 +99,35 @@ public: if (aName.find("m") != 0) { aName.insert(0, "m_"); - std::cout << pRecord->getQualifiedNameAsString() << "::" << pDecl->getNameAsString() << "," << aName << std::endl; - m_bFound = true; + std::stringstream ss; + ss << pRecord->getQualifiedNameAsString() << "::" << pDecl->getNameAsString() << "," << aName; + m_aResults.push_back(ss.str()); } } return true; } + + bool VisitCXXConstructorDecl(clang::CXXConstructorDecl* pDecl) + { + clang::CXXRecordDecl* pRecord = pDecl->getParent(); + m_aFunctions.insert(pRecord->getQualifiedNameAsString()); + return true; + } + + bool VisitCXXDestructorDecl(clang::CXXDestructorDecl* pDecl) + { + clang::CXXRecordDecl* pRecord = pDecl->getParent(); + m_aFunctions.insert(pRecord->getQualifiedNameAsString()); + return true; + } + + bool VisitCXXMethodDecl(clang::CXXMethodDecl* pDecl) + { + clang::CXXRecordDecl* pRecord = pDecl->getParent(); + m_aFunctions.insert(pRecord->getQualifiedNameAsString()); + return true; + } }; class ASTConsumer : public clang::ASTConsumer @@ -119,7 +147,21 @@ public: Visitor aVisitor(m_rContext); aVisitor.TraverseDecl(rContext.getTranslationUnitDecl()); - if (aVisitor.getFound()) + const std::set<std::string>& rFunctions = aVisitor.getFunctions(); + const std::vector<std::string>& rResults = aVisitor.getResults(); + bool bFound = false; + for (const std::string& rFunction : rFunctions) + { + for (const std::string& rResult : rResults) + { + if (rResult.find(rFunction) == 0) + { + std::cerr << rResult << std::endl; + bFound = true; + } + } + } + if (bFound) exit(1); } }; commit 8d53076838749c5d1de75b50955c54275e84f091 Author: Miklos Vajna <[email protected]> Date: Tue Sep 29 21:28:04 2015 +0200 clang: add struct test that is currently mishandled by find-unprefixed-members diff --git a/clang/test.hxx b/clang/test.hxx index 6b3d9c4..78ae7c2 100644 --- a/clang/test.hxx +++ b/clang/test.hxx @@ -25,6 +25,11 @@ public: C() { } }; +/// This has no ctor/dtor/member functions, so members are OK to be not prefixed. +struct S +{ + int nX, mnY, m_nZ; +}; } #define DELETEZ( p ) ( delete p,p = 0 ) _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
