#include "SourceGroupCxxEmpty.h" #include "ApplicationSettings.h" #include "CxxIndexerCommandProvider.h" #include "FileManager.h" #include "IndexerCommandCxx.h" #include "RefreshInfo.h" #include "SourceGroupSettingsCEmpty.h" #include "SourceGroupSettingsCppEmpty.h" #include "SourceGroupSettingsWithCStandard.h" #include "SourceGroupSettingsWithCppStandard.h" #include "SourceGroupSettingsWithCxxPathsAndFlags.h" #include "TaskLambda.h" #include "logging.h" #include "utility.h" #include "utilitySourceGroupCxx.h" SourceGroupCxxEmpty::SourceGroupCxxEmpty(std::shared_ptr settings) : m_settings(settings) { } std::set SourceGroupCxxEmpty::filterToContainedFilePaths(const std::set& filePaths) const { std::vector indexedPaths; std::vector excludeFilters; if (std::shared_ptr settings = std::dynamic_pointer_cast(m_settings)) { indexedPaths = settings->getSourcePathsExpandedAndAbsolute(); excludeFilters = settings->getExcludeFiltersExpandedAndAbsolute(); } else if ( std::shared_ptr settings = std::dynamic_pointer_cast(m_settings)) { indexedPaths = settings->getSourcePathsExpandedAndAbsolute(); excludeFilters = settings->getExcludeFiltersExpandedAndAbsolute(); } return SourceGroup::filterToContainedFilePaths( filePaths, std::set(), utility::toSet(indexedPaths), excludeFilters); } std::set SourceGroupCxxEmpty::getAllSourceFilePaths() const { FileManager fileManager; if (std::shared_ptr settings = std::dynamic_pointer_cast(m_settings)) { fileManager.update( settings->getSourcePathsExpandedAndAbsolute(), settings->getExcludeFiltersExpandedAndAbsolute(), settings->getSourceExtensions()); } else if ( std::shared_ptr settings = std::dynamic_pointer_cast(m_settings)) { fileManager.update( settings->getSourcePathsExpandedAndAbsolute(), settings->getExcludeFiltersExpandedAndAbsolute(), settings->getSourceExtensions()); } return fileManager.getAllSourceFilePaths(); } std::shared_ptr SourceGroupCxxEmpty::getIndexerCommandProvider( const RefreshInfo& info) const { std::set indexedPaths; std::set excludeFilters; if (std::shared_ptr settings = std::dynamic_pointer_cast(m_settings)) { indexedPaths = utility::toSet(settings->getSourcePathsExpandedAndAbsolute()); excludeFilters = utility::toSet(settings->getExcludeFiltersExpandedAndAbsolute()); } else if ( std::shared_ptr settings = std::dynamic_pointer_cast(m_settings)) { indexedPaths = utility::toSet(settings->getSourcePathsExpandedAndAbsolute()); excludeFilters = utility::toSet(settings->getExcludeFiltersExpandedAndAbsolute()); } std::vector compilerFlags = getBaseCompilerFlags(); utility::append( compilerFlags, dynamic_cast(m_settings.get()) ->getCompilerFlags()); utility::append( compilerFlags, utility::getIncludePchFlags( dynamic_cast(m_settings.get()))); std::shared_ptr provider = std::make_shared(); for (const FilePath& sourcePath: getAllSourceFilePaths()) { if (info.filesToIndex.find(sourcePath) != info.filesToIndex.end()) { provider->addCommand(std::make_shared( sourcePath, indexedPaths, excludeFilters, std::set(), m_settings->getProjectDirectoryPath(), utility::concat(compilerFlags, sourcePath.wstr()))); } } return provider; } std::vector> SourceGroupCxxEmpty::getIndexerCommands( const RefreshInfo& info) const { return getIndexerCommandProvider(info)->consumeAllCommands(); } std::shared_ptr SourceGroupCxxEmpty::getPreIndexTask( std::shared_ptr storageProvider, std::shared_ptr dialogView) const { const SourceGroupSettingsWithCxxPchOptions* pchSettings = dynamic_cast(m_settings.get()); if (!pchSettings || pchSettings->getPchInputFilePath().empty()) { return std::make_shared([]() {}); } std::vector compilerFlags = getBaseCompilerFlags(); if (std::shared_ptr pchSettings = std::dynamic_pointer_cast(m_settings)) { if (pchSettings->getUseCompilerFlags()) { utility::append( compilerFlags, dynamic_cast(m_settings.get()) ->getCompilerFlags()); } utility::append(compilerFlags, pchSettings->getPchFlags()); } return utility::createBuildPchTask( dynamic_cast(m_settings.get()), compilerFlags, storageProvider, dialogView); } std::shared_ptr SourceGroupCxxEmpty::getSourceGroupSettings() { return m_settings; } std::shared_ptr SourceGroupCxxEmpty::getSourceGroupSettings() const { return m_settings; } std::vector SourceGroupCxxEmpty::getBaseCompilerFlags() const { std::vector compilerFlags; std::shared_ptr appSettings = ApplicationSettings::getInstance(); std::set indexedPaths; std::wstring targetFlag; std::wstring languageStandard = SourceGroupSettingsWithCppStandard::getDefaultCppStandardStatic(); if (std::shared_ptr settings = std::dynamic_pointer_cast(m_settings)) { indexedPaths = utility::toSet(settings->getSourcePathsExpandedAndAbsolute()); targetFlag = settings->getTargetFlag(); languageStandard = settings->getCStandard(); } else if ( std::shared_ptr settings = std::dynamic_pointer_cast(m_settings)) { indexedPaths = utility::toSet(settings->getSourcePathsExpandedAndAbsolute()); targetFlag = settings->getTargetFlag(); languageStandard = settings->getCppStandard(); } else { LOG_ERROR( L"Source group doesn't specify language standard. Falling back to \"" + languageStandard + L"\"."); } if (!targetFlag.empty()) { compilerFlags.push_back(targetFlag); } compilerFlags.push_back(IndexerCommandCxx::getCompilerFlagLanguageStandard(languageStandard)); if (std::dynamic_pointer_cast(m_settings)) { compilerFlags.push_back(L"-x"); compilerFlags.push_back(L"c"); } else if (std::dynamic_pointer_cast(m_settings)) { compilerFlags.push_back(L"-x"); compilerFlags.push_back(L"c++"); } const SourceGroupSettingsWithCxxPathsAndFlags* settingsCxx = dynamic_cast(m_settings.get()); if (!settingsCxx) { LOG_ERROR(L"Source group doesn't specify cxx headers and flags."); return compilerFlags; } { // Add the source paths as HeaderSearchPaths as well, so clang will also look here when // searching include files. std::vector indexedDirectoryPaths; for (const FilePath& sourcePath: indexedPaths) { if (sourcePath.isDirectory()) { indexedDirectoryPaths.push_back(sourcePath); } } utility::append( compilerFlags, IndexerCommandCxx::getCompilerFlagsForSystemHeaderSearchPaths(utility::concat( indexedDirectoryPaths, utility::concat( settingsCxx->getHeaderSearchPathsExpandedAndAbsolute(), appSettings->getHeaderSearchPathsExpanded())))); } { utility::append( compilerFlags, IndexerCommandCxx::getCompilerFlagsForFrameworkSearchPaths(utility::concat( settingsCxx->getFrameworkSearchPathsExpandedAndAbsolute(), appSettings->getFrameworkSearchPathsExpanded()))); } return compilerFlags; }