diff options
author | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2016-11-29 17:32:34 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2016-12-12 13:49:09 +0000 |
commit | 3a369552c68cf897ae7d1712f35c938f0d047492 (patch) | |
tree | c9f4e389abfe6cad6e74e5d00d1fd206bb0b87e9 /src/plugins/cpptools/cppprojectfilecategorizer.cpp | |
parent | f54d4fc3db2d2472a46e6fda68d55624e0bbe344 (diff) |
CppTools: Classify ambiguous headers depending on other files
This applies for all project managers, except qmake. The qmake project
manager will make use of this in follow up changes.
Before, "foo.h" was always recognized as a CXXHeader. Now, it depends on
the other files. E.g. in a file list {"foo.h", "foo.c"} foo.h is now a
CHeader. In {"foo.h", "foo.c", "bar.cpp"} the file "foo.h" is ambiguous
and we will create two project parts, one where it is a CHeader, the
other where it is a CXXHeader.
Change-Id: I50505163368742584b1380c284d42cbe07cb4fc9
Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/cpptools/cppprojectfilecategorizer.cpp')
-rw-r--r-- | src/plugins/cpptools/cppprojectfilecategorizer.cpp | 101 |
1 files changed, 72 insertions, 29 deletions
diff --git a/src/plugins/cpptools/cppprojectfilecategorizer.cpp b/src/plugins/cpptools/cppprojectfilecategorizer.cpp index b4298deca6..808448c1db 100644 --- a/src/plugins/cpptools/cppprojectfilecategorizer.cpp +++ b/src/plugins/cpptools/cppprojectfilecategorizer.cpp @@ -32,55 +32,98 @@ ProjectFileCategorizer::ProjectFileCategorizer(const QString &projectPartName, ProjectPartBuilder::FileClassifier fileClassifier) : m_partName(projectPartName) { - ProjectFiles cHeaders; - ProjectFiles cxxHeaders; + const QStringList ambiguousHeaders = classifyFiles(filePaths, fileClassifier); + expandSourcesWithAmbiguousHeaders(ambiguousHeaders); + + m_partCount = (m_cSources.isEmpty() ? 0 : 1) + + (m_cxxSources.isEmpty() ? 0 : 1) + + (m_objcSources.isEmpty() ? 0 : 1) + + (m_objcxxSources.isEmpty() ? 0 : 1); +} + +QString ProjectFileCategorizer::partName(const QString &languageName) const +{ + if (hasMultipleParts()) + return QString::fromLatin1("%1 (%2)").arg(m_partName).arg(languageName); + + return m_partName; +} + +QStringList ProjectFileCategorizer::classifyFiles( + const QStringList &filePaths, + ProjectPartBuilder::FileClassifier fileClassifier) +{ + QStringList ambiguousHeaders; foreach (const QString &filePath, filePaths) { const ProjectFile::Kind kind = fileClassifier ? fileClassifier(filePath) : ProjectFile::classify(filePath); - const ProjectFile projectFile(filePath, kind); switch (kind) { - case ProjectFile::CSource: m_cSources += projectFile; break; - case ProjectFile::CHeader: cHeaders += projectFile; break; - case ProjectFile::CXXSource: m_cxxSources += projectFile; break; - case ProjectFile::CXXHeader: cxxHeaders += projectFile; break; - case ProjectFile::ObjCSource: m_objcSources += projectFile; break; - case ProjectFile::ObjCXXSource: m_objcxxSources += projectFile; break; + case ProjectFile::AmbiguousHeader: + ambiguousHeaders += filePath; + break; + case ProjectFile::CXXSource: + case ProjectFile::CXXHeader: + m_cxxSources += ProjectFile(filePath, kind); + break; + case ProjectFile::ObjCXXSource: + case ProjectFile::ObjCXXHeader: + m_objcxxSources += ProjectFile(filePath, kind); + break; + case ProjectFile::CSource: + case ProjectFile::CHeader: + m_cSources += ProjectFile(filePath, kind); + break; + case ProjectFile::ObjCSource: + case ProjectFile::ObjCHeader: + m_objcSources += ProjectFile(filePath, kind); + break; default: continue; } } + return ambiguousHeaders; +} + +static ProjectFiles toProjectFilesWithKind(const QStringList &filePaths, + const ProjectFile::Kind kind) +{ + ProjectFiles projectFiles; + projectFiles.reserve(filePaths.size()); + + foreach (const QString &filePath, filePaths) + projectFiles += ProjectFile(filePath, kind); + + return projectFiles; +} + +void ProjectFileCategorizer::expandSourcesWithAmbiguousHeaders(const QStringList &ambiguousHeaders) +{ const bool hasC = !m_cSources.isEmpty(); const bool hasCxx = !m_cxxSources.isEmpty(); const bool hasObjc = !m_objcSources.isEmpty(); const bool hasObjcxx = !m_objcxxSources.isEmpty(); + const bool hasOnlyAmbiguousHeaders + = !hasC + && !hasCxx + && !hasObjc + && !hasObjcxx + && !ambiguousHeaders.isEmpty(); - if (hasObjcxx) - m_objcxxSources += cxxHeaders + cHeaders; - if (hasCxx) - m_cxxSources += cxxHeaders + cHeaders; - else if (!hasObjcxx) - m_cxxSources += cxxHeaders; - if (hasObjc) - m_objcSources += cHeaders; - if (hasC || (!hasObjc && !hasObjcxx && !hasCxx)) - m_cSources += cHeaders; + if (hasC || hasOnlyAmbiguousHeaders) + m_cSources += toProjectFilesWithKind(ambiguousHeaders, ProjectFile::CHeader); - m_partCount = (m_cSources.isEmpty() ? 0 : 1) - + (m_cxxSources.isEmpty() ? 0 : 1) - + (m_objcSources.isEmpty() ? 0 : 1) - + (m_objcxxSources.isEmpty() ? 0 : 1); -} + if (hasCxx || hasOnlyAmbiguousHeaders) + m_cxxSources += toProjectFilesWithKind(ambiguousHeaders, ProjectFile::CXXHeader); -QString ProjectFileCategorizer::partName(const QString &languageName) const -{ - if (hasMultipleParts()) - return QString::fromLatin1("%1 (%2)").arg(m_partName).arg(languageName); + if (hasObjc || hasOnlyAmbiguousHeaders) + m_objcSources += toProjectFilesWithKind(ambiguousHeaders, ProjectFile::ObjCHeader); - return m_partName; + if (hasObjcxx || hasOnlyAmbiguousHeaders) + m_objcxxSources += toProjectFilesWithKind(ambiguousHeaders, ProjectFile::ObjCXXHeader); } } // namespace CppTools |