aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-06 09:28:28 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-07 14:24:58 +0200
commitba6179ceba84e925748068b83624c1921cfbf6d7 (patch)
tree975adb7e81e6d850ffafd2f589250b8976d082b4 /sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp
parenta53318e661238ae155f9cd5692bf255c333ee292 (diff)
shiboken6/Clang parser: Refactor include checking
In the base class BaseVisitor of the clang parser, check whether the file has changed by comparing the CXFile. If it has changed, convert the file name to a QString and call visitLocation(). The code is then faster since the file name checks are only performed when the CXFile changes. The check code operating on QString becomes simpler and can be extended more easily. Task-number: PYSIDE-802 Task-number: PYSIDE-1660 Pick-to: 6.2 Change-Id: I1dd22ef91a4a7b96d05507b43511313507281fd6 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp')
-rw-r--r--sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp34
1 files changed, 31 insertions, 3 deletions
diff --git a/sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp b/sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp
index 8cf35641b..15be8f5a4 100644
--- a/sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp
+++ b/sources/shiboken6/ApiExtractor/clangparser/clangparser.cpp
@@ -108,9 +108,9 @@ std::string_view SourceFileCache::getCodeSnippet(const CXCursor &cursor,
BaseVisitor::BaseVisitor() = default;
BaseVisitor::~BaseVisitor() = default;
-bool BaseVisitor::visitLocation(const CXSourceLocation &location) const
+bool BaseVisitor::visitLocation(const QString &, LocationType locationType) const
{
- return clang_Location_isFromMainFile(location) != 0;
+ return locationType != LocationType::System;
}
BaseVisitor::StartTokenResult BaseVisitor::cbHandleStartToken(const CXCursor &cursor)
@@ -148,6 +148,34 @@ std::string_view BaseVisitor::getCodeSnippet(const CXCursor &cursor)
return result;
}
+bool BaseVisitor::_handleVisitLocation(const CXSourceLocation &location)
+{
+ CXFile cxFile; // void *
+ unsigned line;
+ unsigned column;
+ unsigned offset;
+ clang_getExpansionLocation(location, &cxFile, &line, &column, &offset);
+
+ if (cxFile == m_currentCxFile) // Same file?
+ return m_visitCurrent;
+
+ const QString fileName = getFileName(cxFile);
+
+ LocationType locationType = LocationType::Unknown;
+ if (!fileName.isEmpty()) {
+ if (clang_Location_isFromMainFile(location) != 0)
+ locationType = LocationType::Main;
+ else if (clang_Location_isInSystemHeader(location) != 0)
+ locationType = LocationType::System;
+ else
+ locationType = LocationType::Other;
+ }
+
+ m_currentCxFile = cxFile;
+ m_visitCurrent = visitLocation(fileName, locationType);
+ return m_visitCurrent;
+}
+
QString BaseVisitor::getCodeSnippetString(const CXCursor &cursor)
{
const std::string_view result = getCodeSnippet(cursor);
@@ -162,7 +190,7 @@ static CXChildVisitResult
auto *bv = reinterpret_cast<BaseVisitor *>(clientData);
const CXSourceLocation location = clang_getCursorLocation(cursor);
- if (!bv->visitLocation(location))
+ if (!bv->_handleVisitLocation(location))
return CXChildVisit_Continue;
const BaseVisitor::StartTokenResult startResult = bv->cbHandleStartToken(cursor);