diff options
author | Sergio Martins <smartins@kde.org> | 2019-10-01 18:22:20 +0100 |
---|---|---|
committer | Sergio Martins <smartins@kde.org> | 2019-10-01 18:22:20 +0100 |
commit | f8a1d3050c55cdf803a83a7f9fda7652370a4352 (patch) | |
tree | 065ba2f0610f7bc6b4b931a9fc85dc13029e9b32 /src | |
parent | 61640dabc6e7590f11b53c9db56653b99dc225d4 (diff) |
Allow to visit typedefs even in system headers
As some checks need to know about all typedefs
Diffstat (limited to 'src')
-rw-r--r-- | src/Clazy.cpp | 3 | ||||
-rw-r--r-- | src/ClazyContext.cpp | 12 | ||||
-rw-r--r-- | src/ClazyContext.h | 4 |
3 files changed, 18 insertions, 1 deletions
diff --git a/src/Clazy.cpp b/src/Clazy.cpp index 3e21377e..592c03f1 100644 --- a/src/Clazy.cpp +++ b/src/Clazy.cpp @@ -107,8 +107,9 @@ bool ClazyASTConsumer::VisitDecl(Decl *decl) if (AccessSpecifierManager *a = m_context->accessSpecifierManager) // Needs to visit system headers too (qobject.h for example) a->VisitDeclaration(decl); + const bool isTypeDefToVisit = m_context->visitsAllTypedefs() && isa<TypedefNameDecl>(decl); const SourceLocation locStart = clazy::getLocStart(decl); - if (locStart.isInvalid() || m_context->sm.isInSystemHeader(locStart)) + if (locStart.isInvalid() || (m_context->sm.isInSystemHeader(locStart) && !isTypeDefToVisit)) return true; const bool isFromIgnorableInclude = m_context->ignoresIncludedFiles() && !Utils::isMainFile(m_context->sm, locStart); diff --git a/src/ClazyContext.cpp b/src/ClazyContext.cpp index 5e824c54..e1c4f4a8 100644 --- a/src/ClazyContext.cpp +++ b/src/ClazyContext.cpp @@ -104,6 +104,18 @@ void ClazyContext::enablePreprocessorVisitor() preprocessorVisitor = new PreProcessorVisitor(ci); } +void ClazyContext::enableVisitallTypeDefs() +{ + // By default we only process decls from the .cpp file we're processing, not stuff included (for performance) + /// But we might need to process all typedefs, not only the ones in our current .cpp files + m_visitsAllTypeDefs = true; +} + +bool ClazyContext::visitsAllTypedefs() const +{ + return m_visitsAllTypeDefs; +} + bool ClazyContext::isQt() const { static const bool s_isQt = [this] { diff --git a/src/ClazyContext.h b/src/ClazyContext.h index 69219d2f..aa3fe133 100644 --- a/src/ClazyContext.h +++ b/src/ClazyContext.h @@ -161,6 +161,9 @@ public: */ void enableAccessSpecifierManager(); void enablePreprocessorVisitor(); + void enableVisitallTypeDefs(); + bool visitsAllTypedefs() const; + bool isQt() const; // TODO: More things will follow @@ -171,6 +174,7 @@ public: PreProcessorVisitor *preprocessorVisitor = nullptr; SuppressionManager suppressionManager; const bool m_noWerror; + bool m_visitsAllTypeDefs = false; clang::ParentMap *parentMap = nullptr; const ClazyOptions options; const std::vector<std::string> extraOptions; |