ClangTools: Add header files to the list of files to be analyzed

Now that the CMakeProjectManager is reporting the header files as
source files, it makes sense to analyze the headers as source files.

Note that the header type needs to change to source type since the
"cxx-header" argument that will be send if the Kind is CxxHeader is
handled by the compiler as an argument to produce a precompiled
header, which is not what we want.

Fixes: QTCREATORBUG-21452
Fixes: QTCREATORBUG-25644
Fixes: QTCREATORBUG-25782
Change-Id: Icd674962ff8312b8fbfa46491938eb721edd761d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Cristian Adam
2021-10-01 16:32:47 +02:00
parent 2fcd764d56
commit 60fca0596a
4 changed files with 42 additions and 4 deletions

View File

@@ -340,9 +340,12 @@ static FileInfos sortedFileInfos(const QVector<CppEditor::ProjectPart::ConstPtr>
if (file.path == CppEditor::CppModelManager::configurationFileName()) if (file.path == CppEditor::CppModelManager::configurationFileName())
continue; continue;
if (file.active && CppEditor::ProjectFile::isSource(file.kind)) { if (file.active
&& (CppEditor::ProjectFile::isSource(file.kind)
|| CppEditor::ProjectFile::isHeader(file.kind))) {
ProjectFile::Kind sourceKind = CppEditor::ProjectFile::sourceKind(file.kind);
fileInfos.emplace_back(Utils::FilePath::fromString(file.path), fileInfos.emplace_back(Utils::FilePath::fromString(file.path),
file.kind, sourceKind,
projectPart); projectPart);
} }
} }

View File

@@ -160,11 +160,12 @@ static FileInfo getFileInfo(const FilePath &file, Project *project)
if (!projectFile.active) if (!projectFile.active)
continue; continue;
// found the best candidate, early return // found the best candidate, early return
ProjectFile::Kind sourceKind = ProjectFile::sourceKind(projectFile.kind);
if (projectPart->buildTargetType != BuildTargetType::Unknown) if (projectPart->buildTargetType != BuildTargetType::Unknown)
return FileInfo(projectFilePath, projectFile.kind, projectPart); return FileInfo(projectFilePath, sourceKind, projectPart);
// found something but keep looking for better candidates // found something but keep looking for better candidates
if (candidate.projectPart.isNull()) if (candidate.projectPart.isNull())
candidate = FileInfo(projectFilePath, projectFile.kind, projectPart); candidate = FileInfo(projectFilePath, sourceKind, projectPart);
} }
} }

View File

@@ -87,6 +87,37 @@ bool ProjectFile::isAmbiguousHeader(const QString &filePath)
return filePath.endsWith(".h"); return filePath.endsWith(".h");
} }
ProjectFile::Kind ProjectFile::sourceForHeaderKind(ProjectFile::Kind kind)
{
ProjectFile::Kind sourceKind;
switch (kind) {
case ProjectFile::CHeader:
sourceKind = ProjectFile::CSource;
break;
case ProjectFile::ObjCHeader:
sourceKind = ProjectFile::ObjCSource;
break;
case ProjectFile::ObjCXXHeader:
sourceKind = ProjectFile::ObjCXXSource;
break;
case ProjectFile::Unsupported: // no file extension, e.g. stl headers
case ProjectFile::AmbiguousHeader:
case ProjectFile::CXXHeader:
default:
sourceKind = ProjectFile::CXXSource;
}
return sourceKind;
}
ProjectFile::Kind ProjectFile::sourceKind(Kind kind)
{
ProjectFile::Kind sourceKind = kind;
if (ProjectFile::isHeader(kind))
sourceKind = ProjectFile::sourceForHeaderKind(kind);
return sourceKind;
}
bool ProjectFile::isHeader(ProjectFile::Kind kind) bool ProjectFile::isHeader(ProjectFile::Kind kind)
{ {
switch (kind) { switch (kind) {

View File

@@ -53,6 +53,9 @@ public:
static Kind classifyByMimeType(const QString &mt); static Kind classifyByMimeType(const QString &mt);
static Kind classify(const QString &filePath); static Kind classify(const QString &filePath);
static Kind sourceForHeaderKind(Kind kind);
static Kind sourceKind(Kind kind);
static bool isSource(Kind kind); static bool isSource(Kind kind);
static bool isHeader(Kind kind); static bool isHeader(Kind kind);
static bool isC(Kind kind); static bool isC(Kind kind);