Clang: Pass on file paths with native separators

libclang 3.8 seems to be sensitive to file paths separators [1]. On Windows,
this led to not updated document annotations and/or crashes after reparsing.

When passing file paths to libclang, convert to native separators.
When getting file paths from libclang, convert back.

This handles:
 * main file path
 * file paths of the unsaved files
 * -I<DIR> arguments, the resource path (for builtins) and the paths to the
   wrapped qt headers
 * included header files from libclang
 * source locations from libclang

Also, minimize the conversion in SourceLocation to a minimum by making
filePath() lazy.

[1] https://llvm.org/bugs/show_bug.cgi?id=28381

Change-Id: If5866f34a6fdc6b34b16c022d3988e8e6eae2a0a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Nikolai Kosjar
2016-07-01 15:07:32 +02:00
parent a12184ea32
commit 36e7f4541f
18 changed files with 221 additions and 26 deletions

View File

@@ -25,6 +25,7 @@
#include "unsavedfile.h"
#include "clangfilepath.h"
#include "utf8string.h"
#include "utf8positionfromlinecolumn.h"
@@ -40,10 +41,12 @@ UnsavedFile::UnsavedFile()
UnsavedFile::UnsavedFile(const Utf8String &filePath, const Utf8String &fileContent)
{
char *cxUnsavedFilePath = new char[filePath.byteSize() + 1];
const Utf8String nativeFilePath = FilePath::toNativeSeparators(filePath);
char *cxUnsavedFilePath = new char[nativeFilePath.byteSize() + 1];
char *cxUnsavedFileContent = new char[fileContent.byteSize() + 1];
std::memcpy(cxUnsavedFilePath, filePath.constData(), filePath.byteSize() + 1);
std::memcpy(cxUnsavedFilePath, nativeFilePath.constData(), nativeFilePath.byteSize() + 1);
std::memcpy(cxUnsavedFileContent, fileContent.constData(), fileContent.byteSize() + 1);
cxUnsavedFile = CXUnsavedFile{cxUnsavedFilePath,
@@ -66,7 +69,14 @@ UnsavedFile &UnsavedFile::operator=(UnsavedFile &&other) Q_DECL_NOEXCEPT
return *this;
}
const char *UnsavedFile::filePath() const
Utf8String UnsavedFile::filePath() const
{
const Utf8String nativeFilePathAsUtf8String = Utf8String::fromUtf8(nativeFilePath());
return FilePath::fromNativeSeparators(nativeFilePathAsUtf8String);
}
const char *UnsavedFile::nativeFilePath() const
{
return cxUnsavedFile.Filename;
}
@@ -105,7 +115,7 @@ bool UnsavedFile::replaceAt(uint position, uint length, const Utf8String &replac
Utf8String modifiedContent(cxUnsavedFile.Contents, cxUnsavedFile.Length);
modifiedContent.replace(int(position), int(length), replacement);
*this = UnsavedFile(Utf8String::fromUtf8(filePath()), modifiedContent);
*this = UnsavedFile(Utf8String::fromUtf8(nativeFilePath()), modifiedContent);
return true;
}