diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-10-16 15:45:41 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-10-17 19:08:18 +0200 |
commit | 1899b7bf10ef39de79d608a71822840ad99e3aad (patch) | |
tree | aa944a4b379315fc79a1686a7900bb8365e7d4ad | |
parent | a51fc3b524d075bc84c1f746e8bbf6016c07790b (diff) |
shiboken6: Add additional debug statements regarding include parsing
Output whether system headers are parsed or skipped to the
'qt.shiboken' logging category.
Pick-to: 6.6
Task-number: PYSIDE-1958
Change-Id: If845f57091a39167ea9e36d6736328498290a51b
Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r-- | sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp index 14d647541..cb965e8db 100644 --- a/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp +++ b/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp @@ -117,6 +117,14 @@ class BuilderPrivate { public: Q_DISABLE_COPY_MOVE(BuilderPrivate) + enum class SpecialSystemHeader { + None, + Types, + OpenGL, + WhiteListed, + WhiteListedPath + }; + using CursorClassHash = QHash<CXCursor, ClassModelItem>; using TypeInfoHash = QHash<CXType, TypeInfo>; @@ -183,7 +191,9 @@ public: std::pair<QString, ClassModelItem> getBaseClass(CXType type) const; void addBaseClass(const CXCursor &cursor); + SpecialSystemHeader specialSystemHeader(const QString &fileName) const; bool visitHeader(const QString &fileName) const; + static const char *specialSystemHeaderReason(SpecialSystemHeader sh); void setFileName(const CXCursor &cursor, _CodeModelItem *item); @@ -214,6 +224,7 @@ public: int m_anonymousEnumCount = 0; CodeModel::FunctionType m_currentFunctionType = CodeModel::Normal; bool m_withinFriendDecl = false; + mutable QHash<QString, SpecialSystemHeader> m_systemHeaders; }; bool BuilderPrivate::addClass(const CXCursor &cursor, CodeModel::ClassType t) @@ -772,8 +783,38 @@ static QString baseName(QString path) return path; } +const char * BuilderPrivate::specialSystemHeaderReason(BuilderPrivate::SpecialSystemHeader sh) +{ + static const QHash<SpecialSystemHeader, const char *> mapping { + {SpecialSystemHeader::OpenGL, "OpenGL"}, + {SpecialSystemHeader::Types, "types"}, + {SpecialSystemHeader::WhiteListed, "white listed"}, + {SpecialSystemHeader::WhiteListedPath, "white listed path"} + }; + return mapping.value(sh, ""); +} + bool BuilderPrivate::visitHeader(const QString &fileName) const { + auto it = m_systemHeaders.find(fileName); + if (it == m_systemHeaders.end()) { + it = m_systemHeaders.insert(fileName, specialSystemHeader(fileName)); + if (ReportHandler::isDebug(ReportHandler::MediumDebug)) { + const QString &name = QDir::toNativeSeparators(fileName); + if (it.value() == SpecialSystemHeader::None) { + qCInfo(lcShiboken, "Skipping system header %s", qPrintable(name)); + } else { + qCInfo(lcShiboken, "Parsing system header %s (%s)", + qPrintable(name), specialSystemHeaderReason(it.value())); + } + } + } + return it.value() != SpecialSystemHeader::None; +} + +BuilderPrivate::SpecialSystemHeader + BuilderPrivate::specialSystemHeader(const QString &fileName) const +{ // Resolve OpenGL typedefs although the header is considered a system header. const QString baseName = clang::baseName(fileName); if (baseName == u"gl.h" @@ -782,8 +823,8 @@ bool BuilderPrivate::visitHeader(const QString &fileName) const || baseName == u"gl31.h" || baseName == u"gl32.h" || baseName == u"stdint.h" // Windows: int32_t, uint32_t - || baseName == u"stddef.h") { // size_t - return true; + || baseName == u"stddef.h") { // size_t` + return SpecialSystemHeader::OpenGL; } switch (clang::platform()) { @@ -792,7 +833,7 @@ bool BuilderPrivate::visitHeader(const QString &fileName) const || baseName == u"types.h" || baseName == u"stdint-intn.h" // int32_t || baseName == u"stdint-uintn.h") { // uint32_t - return true; + return SpecialSystemHeader::Types; } break; case Platform::macOS: @@ -802,22 +843,22 @@ bool BuilderPrivate::visitHeader(const QString &fileName) const if (baseName == u"gltypes.h" || fileName.contains(u"/usr/include/_types") || fileName.contains(u"/usr/include/sys/_types")) { - return true; + return SpecialSystemHeader::Types; } break; default: break; } - for (const auto &systemInclude : m_systemIncludes) { - if (systemInclude == baseName) - return true; - } - for (const auto &systemIncludePath : m_systemIncludePaths) { - if (fileName.startsWith(systemIncludePath)) - return true; + if (m_systemIncludes.contains(baseName)) + return SpecialSystemHeader::WhiteListed; + + if (std::any_of(m_systemIncludePaths.cbegin(), m_systemIncludePaths.cend(), + [fileName](const QString &p) { return fileName.startsWith(p); })) { + return SpecialSystemHeader::WhiteListedPath; } - return false; + + return SpecialSystemHeader::None; } bool Builder::visitLocation(const QString &fileName, LocationType locationType) const |