aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-06-18 13:17:20 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2020-06-19 09:14:24 +0000
commitf9a5ad4d3cf85f93beb87f34e023e2be4acd7415 (patch)
treefebadf295949de1979135130dc9be633ad06efd3 /src/tools
parent176fbc1698c9bb845e8e064dc549d93fcf99d47f (diff)
ClangBackEnd: Adapt skipped source ranges from libclang
... so that the first #if is not grayed out. Fixes: QTCREATORBUG-23714 Change-Id: Ia014fd8cd768ea9530567ba8c712bdc0c4063091 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/clangbackend/source/skippedsourceranges.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/tools/clangbackend/source/skippedsourceranges.cpp b/src/tools/clangbackend/source/skippedsourceranges.cpp
index c2005996d18..83384fcc534 100644
--- a/src/tools/clangbackend/source/skippedsourceranges.cpp
+++ b/src/tools/clangbackend/source/skippedsourceranges.cpp
@@ -58,15 +58,20 @@ SkippedSourceRanges &SkippedSourceRanges::operator=(SkippedSourceRanges &&other)
return *this;
}
-// The source range reported by clang includes the e.g. #endif line, but we do
-// not want to have that grayed out, too. Overwrite the column number with 1 to
-// exclude the line.
+// For some reason, libclang starts the skipped range on the line containing the
+// preprocessor directive preceding the ifdef'ed out code (i.e. #if or #else)
+// and ends it on the line following the ifdef'ed out code (#else or #endif, respectively).
+// We don't want the preprocessor directives grayed out, so adapt the locations.
static SourceRange adaptedSourceRange(CXTranslationUnit cxTranslationUnit, const SourceRange &range)
{
const SourceLocation end = range.end();
return SourceRange {
- range.start(),
+ SourceLocation(cxTranslationUnit,
+ clang_getLocation(cxTranslationUnit,
+ clang_getFile(cxTranslationUnit,
+ end.filePath().constData()),
+ range.start().line() + 1, 1)),
SourceLocation(cxTranslationUnit,
clang_getLocation(cxTranslationUnit,
clang_getFile(cxTranslationUnit,