diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-07 15:52:42 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-09 19:34:08 +0200 |
| commit | 3a0b9ebc9e2980af8dc5fbf4ac8bc6ddfd49c9d9 (patch) | |
| tree | a9a499b128090c2131db7590e934d83241d21cf8 /sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp | |
| parent | fb2dc48389c1099bef3aaed97f16ce2bd1b90fee (diff) | |
shiboken2/clangparser: Refactor code snippet extraction handling
Code snippets resulting from macro expansion have a 0 range.
Detect this first thing and return an empty snippet before
starting to convert file names and reading files.
For that purpose, use a CXFile instead of a QString
in SourceLocation. For all other cases, output a verbose warning.
Provide a function to obtain the file name from a CXFile
with caching in the builder.
Task-number: PYSIDE-1339
Task-number: PYSIDE-904
Change-Id: Ie30563f5b25d0d21b3a1ceb0c9da37cfc8d808dd
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp')
| -rw-r--r-- | sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp index df2476100..6bf2e3ab0 100644 --- a/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp +++ b/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp @@ -60,15 +60,25 @@ QtCompatHashFunctionType qHash(const CXType &ct, QtCompatHashFunctionType seed) namespace clang { +bool SourceLocation::equals(const SourceLocation &rhs) const +{ + return file == rhs.file && offset == rhs.offset; +} + SourceLocation getExpansionLocation(const CXSourceLocation &location) { SourceLocation result; - CXFile file; // void * - clang_getExpansionLocation(location, &file, &result.line, &result.column, &result.offset); + clang_getExpansionLocation(location, &result.file, &result.line, &result.column, &result.offset); + return result; +} + +QString getFileName(CXFile file) +{ + QString result; const CXString cxFileName = clang_getFileName(file); // Has been observed to be 0 for invalid locations if (const char *cFileName = clang_getCString(cxFileName)) - result.file = QString::fromUtf8(cFileName); + result = QString::fromUtf8(cFileName); clang_disposeString(cxFileName); return result; } @@ -226,7 +236,7 @@ QDebug operator<<(QDebug s, const SourceLocation &l) QDebugStateSaver saver(s); s.nospace(); s.noquote(); - s << QDir::toNativeSeparators(l.file) << ':' << l.line; + s << QDir::toNativeSeparators(clang::getFileName(l.file)) << ':' << l.line; if (l.column) s << ':' << l.column; return s; |
