forked from qt-creator/qt-creator
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:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "sourcelocation.h"
|
||||
|
||||
#include "clangfilepath.h"
|
||||
#include "clangstring.h"
|
||||
#include "clangtranslationunit.h"
|
||||
|
||||
@@ -42,6 +43,12 @@ SourceLocation::SourceLocation()
|
||||
|
||||
const Utf8String &SourceLocation::filePath() const
|
||||
{
|
||||
if (isFilePathNormalized_)
|
||||
return filePath_;
|
||||
|
||||
isFilePathNormalized_ = true;
|
||||
filePath_ = FilePath::fromNativeSeparators(filePath_);
|
||||
|
||||
return filePath_;
|
||||
}
|
||||
|
||||
@@ -62,7 +69,7 @@ uint SourceLocation::offset() const
|
||||
|
||||
SourceLocationContainer SourceLocation::toSourceLocationContainer() const
|
||||
{
|
||||
return SourceLocationContainer(filePath_, line_, column_);
|
||||
return SourceLocationContainer(filePath(), line_, column_);
|
||||
}
|
||||
|
||||
SourceLocation::SourceLocation(CXSourceLocation cxSourceLocation)
|
||||
@@ -77,6 +84,7 @@ SourceLocation::SourceLocation(CXSourceLocation cxSourceLocation)
|
||||
&offset_);
|
||||
|
||||
filePath_ = ClangString(clang_getFileName(cxFile));
|
||||
isFilePathNormalized_ = false;
|
||||
}
|
||||
|
||||
SourceLocation::SourceLocation(CXTranslationUnit cxTranslationUnit,
|
||||
@@ -90,7 +98,8 @@ SourceLocation::SourceLocation(CXTranslationUnit cxTranslationUnit,
|
||||
column)),
|
||||
filePath_(filePath),
|
||||
line_(line),
|
||||
column_(column)
|
||||
column_(column),
|
||||
isFilePathNormalized_(true)
|
||||
{
|
||||
clang_getFileLocation(cxSourceLocation, 0, 0, 0, &offset_);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user