diff options
author | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2017-11-29 16:08:06 +0100 |
---|---|---|
committer | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-01-26 15:39:31 +0000 |
commit | 09310bcdc68e4242106e3f15761116797f8f0d78 (patch) | |
tree | 478b750fe83632d4c66f131792322a11df4a6193 /src/tools/clangbackend/source/sourcelocation.cpp | |
parent | 6deec195f1b00ba941c12eee9ea1024d3ddabc54 (diff) | |
download | qt-creator-09310bcdc68e4242106e3f15761116797f8f0d78.tar.gz |
Clang: fix utf8 related column numbers
Use new clang_getFileContents to efficiently convert
utf8 byte offsets from line start to column numbers.
Also provide simplier backwards convertion to pass
resulting utf8 offset to clang.
Task-number: QTCREATORBUG-16941
Change-Id: If0e58fe01ad3e281b7e952e972b9e86f6e75aadb
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'src/tools/clangbackend/source/sourcelocation.cpp')
-rw-r--r-- | src/tools/clangbackend/source/sourcelocation.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/tools/clangbackend/source/sourcelocation.cpp b/src/tools/clangbackend/source/sourcelocation.cpp index 161ed5b0a5..d015cad4ee 100644 --- a/src/tools/clangbackend/source/sourcelocation.cpp +++ b/src/tools/clangbackend/source/sourcelocation.cpp @@ -29,10 +29,13 @@ #include "clangfilepath.h" #include "clangstring.h" -#include <utf8string.h> +#include <clangsupport/sourcelocationcontainer.h> + +#include <sqlite/utf8string.h> + +#include <utils/textutils.h> #include <ostream> -#include <sourcelocationcontainer.h> namespace ClangBackEnd { @@ -72,8 +75,10 @@ SourceLocationContainer SourceLocation::toSourceLocationContainer() const return SourceLocationContainer(filePath(), line_, column_); } -SourceLocation::SourceLocation(CXSourceLocation cxSourceLocation) +SourceLocation::SourceLocation(CXTranslationUnit cxTranslationUnit, + CXSourceLocation cxSourceLocation) : cxSourceLocation(cxSourceLocation) + , cxTranslationUnit(cxTranslationUnit) { CXFile cxFile; @@ -83,8 +88,22 @@ SourceLocation::SourceLocation(CXSourceLocation cxSourceLocation) &column_, &offset_); - filePath_ = ClangString(clang_getFileName(cxFile)); isFilePathNormalized_ = false; + if (!cxFile) + return; + + filePath_ = ClangString(clang_getFileName(cxFile)); +// CLANG-UPGRADE-CHECK: Remove HAS_GETFILECONTENTS_BACKPORTED check once we require clang >= 6.0 +#if defined(CINDEX_VERSION_HAS_GETFILECONTENTS_BACKPORTED) || CINDEX_VERSION_MINOR >= 44 + if (column_ > 1) { + const uint lineStart = offset_ + 1 - column_; + const char *contents = clang_getFileContents(cxTranslationUnit, cxFile, nullptr); + if (!contents) + return; + column_ = static_cast<uint>(QString::fromUtf8(&contents[lineStart], + static_cast<int>(column_)).size()); + } +#endif } SourceLocation::SourceLocation(CXTranslationUnit cxTranslationUnit, @@ -96,6 +115,7 @@ SourceLocation::SourceLocation(CXTranslationUnit cxTranslationUnit, filePath.constData()), line, column)), + cxTranslationUnit(cxTranslationUnit), filePath_(filePath), line_(line), column_(column), |