diff options
author | Brad King <brad.king@kitware.com> | 2022-11-30 12:28:44 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-11-30 12:29:01 (GMT) |
commit | d340fcdbb7c25e51343d3502bf4e971407f74f0d (patch) | |
tree | 2b54617ed78e414742af7e3603641c10f9d84fd1 /Source | |
parent | 3b19541518d96fe803b26d4f20a23b71005af41c (diff) | |
parent | 66ca5b6137cf1c7aa40c30cbba255537b540d1ea (diff) | |
download | CMake-d340fcdbb7c25e51343d3502bf4e971407f74f0d.zip CMake-d340fcdbb7c25e51343d3502bf4e971407f74f0d.tar.gz CMake-d340fcdbb7c25e51343d3502bf4e971407f74f0d.tar.bz2 |
Merge topic 'vs-clang-tidy-cleanup'
66ca5b6137 clang-tidy: fix `readability-redundant-smartptr-get` lints
32c38a269a clang-tidy: fix `modernize-make-unique` lints
4a960f7186 clang-tidy: fix `performance-for-range-copy` lints
fc9b5193e4 clang-tidy: fix `readability-redundant-string-init` lints
ccb5ecac0b clang-tidy: fix `readability-const-return-type` lints
2381634e7f clang-tidy: fix `readability-qualified-auto` lints
707172c66e clang-tidy: fix `readability-use-anyofallof` lints
501408338a clang-tidy: fix `readability-isolate-declaration` lints
...
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7950
Diffstat (limited to 'Source')
34 files changed, 531 insertions, 528 deletions
diff --git a/Source/cmCallVisualStudioMacro.h b/Source/cmCallVisualStudioMacro.h index 795b863..78f22ae 100644 --- a/Source/cmCallVisualStudioMacro.h +++ b/Source/cmCallVisualStudioMacro.h @@ -19,8 +19,7 @@ public: //! given solution file open. Pass "ALL" for slnFile to call the //! macro in each Visual Studio instance. static int CallMacro(const std::string& slnFile, const std::string& macro, - const std::string& args, - const bool logErrorsAsMessages); + const std::string& args, bool logErrorsAsMessages); //! Count the number of running instances of Visual Studio with the //! given solution file open. Pass "ALL" for slnFile to count all diff --git a/Source/cmGlobalMSYSMakefileGenerator.h b/Source/cmGlobalMSYSMakefileGenerator.h index a8516a4..ee9a4ee 100644 --- a/Source/cmGlobalMSYSMakefileGenerator.h +++ b/Source/cmGlobalMSYSMakefileGenerator.h @@ -28,7 +28,7 @@ public: } //! Get the name for the generator. - virtual std::string GetName() const + std::string GetName() const override { return cmGlobalMSYSMakefileGenerator::GetActualName(); } @@ -41,8 +41,8 @@ public: * Try to determine system information such as shared library * extension, pthreads, byte order etc. */ - virtual void EnableLanguage(std::vector<std::string> const& languages, - cmMakefile*, bool optional); + void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*, + bool optional) override; private: std::string FindMinGW(std::string const& makeloc); diff --git a/Source/cmGlobalMinGWMakefileGenerator.h b/Source/cmGlobalMinGWMakefileGenerator.h index b39db03..7dd968b 100644 --- a/Source/cmGlobalMinGWMakefileGenerator.h +++ b/Source/cmGlobalMinGWMakefileGenerator.h @@ -27,7 +27,7 @@ public: new cmGlobalGeneratorSimpleFactory<cmGlobalMinGWMakefileGenerator>()); } //! Get the name for the generator. - virtual std::string GetName() const + std::string GetName() const override { return cmGlobalMinGWMakefileGenerator::GetActualName(); } diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 266e08d..192663d 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -302,7 +302,7 @@ bool cmGlobalVisualStudio10Generator::ParseGeneratorToolset( std::string const& ts, cmMakefile* mf) { std::vector<std::string> const fields = cmTokenize(ts, ","); - std::vector<std::string>::const_iterator fi = fields.begin(); + auto fi = fields.begin(); if (fi == fields.end()) { return true; } @@ -501,7 +501,8 @@ bool cmGlobalVisualStudio10Generator::InitializeWindowsStore(cmMakefile* mf) bool cmGlobalVisualStudio10Generator::InitializeTegraAndroid(cmMakefile* mf) { - std::string v = this->GetInstalledNsightTegraVersion(); + std::string v = + cmGlobalVisualStudio10Generator::GetInstalledNsightTegraVersion(); if (v.empty()) { mf->IssueMessage(MessageType::FATAL_ERROR, "CMAKE_SYSTEM_NAME is 'Android' but " @@ -773,9 +774,9 @@ std::string cmGlobalVisualStudio10Generator::FindMSBuildCommand() // Search in standard location. mskey = cmStrCat( - "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\", + R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\)", this->GetToolsVersion(), ";MSBuildToolsPath"); - if (cmSystemTools::ReadRegistryValue(mskey.c_str(), msbuild, + if (cmSystemTools::ReadRegistryValue(mskey, msbuild, cmSystemTools::KeyWOW64_32)) { cmSystemTools::ConvertToUnixSlashes(msbuild); msbuild += "/MSBuild.exe"; @@ -798,6 +799,7 @@ std::string cmGlobalVisualStudio10Generator::FindDevEnvCommand() } // Skip over the cmGlobalVisualStudio8Generator implementation because // we expect a real devenv and do not want to look for VCExpress. + // NOLINTNEXTLINE(bugprone-parent-virtual-call) return this->cmGlobalVisualStudio71Generator::FindDevEnvCommand(); } @@ -1108,8 +1110,9 @@ cmGlobalVisualStudio10Generator::GenerateBuildCommand( // Decide if a restore is performed, based on a cache variable. if (cmValue cached = this->CMakeInstance->GetState()->GetCacheEntryValue( - "CMAKE_VS_NUGET_PACKAGE_RESTORE")) + "CMAKE_VS_NUGET_PACKAGE_RESTORE")) { restorePackages = cached.IsOn(); + } } if (restorePackages) { @@ -1137,7 +1140,7 @@ cmGlobalVisualStudio10Generator::GenerateBuildCommand( std::string extension = cmSystemTools::GetFilenameLastExtension(proj->GetRelativePath()); extension = cmSystemTools::LowerCase(extension); - if (extension.compare(".csproj") == 0) { + if (extension == ".csproj") { // Use correct platform name platform = slnData.GetConfigurationTarget(tname, plainConfig, platform); @@ -1502,19 +1505,23 @@ std::string cmGlobalVisualStudio10Generator::GetClFlagTableName() const if (toolset == "v142") { return "v142"; - } else if (toolset == "v141") { + } + if (toolset == "v141") { return "v141"; - } else if (useToolset == "v140") { + } + if (useToolset == "v140") { return "v140"; - } else if (useToolset == "v120") { + } + if (useToolset == "v120") { return "v12"; - } else if (useToolset == "v110") { + } + if (useToolset == "v110") { return "v11"; - } else if (useToolset == "v100") { + } + if (useToolset == "v100") { return "v10"; - } else { - return ""; } + return ""; } std::string cmGlobalVisualStudio10Generator::GetCSharpFlagTableName() const @@ -1524,19 +1531,23 @@ std::string cmGlobalVisualStudio10Generator::GetCSharpFlagTableName() const if (useToolset == "v142") { return "v142"; - } else if (useToolset == "v141") { + } + if (useToolset == "v141") { return "v141"; - } else if (useToolset == "v140") { + } + if (useToolset == "v140") { return "v140"; - } else if (useToolset == "v120") { + } + if (useToolset == "v120") { return "v12"; - } else if (useToolset == "v110") { + } + if (useToolset == "v110") { return "v11"; - } else if (useToolset == "v100") { + } + if (useToolset == "v100") { return "v10"; - } else { - return ""; } + return ""; } std::string cmGlobalVisualStudio10Generator::GetRcFlagTableName() const @@ -1547,15 +1558,17 @@ std::string cmGlobalVisualStudio10Generator::GetRcFlagTableName() const if ((useToolset == "v140") || (useToolset == "v141") || (useToolset == "v142")) { return "v14"; - } else if (useToolset == "v120") { + } + if (useToolset == "v120") { return "v12"; - } else if (useToolset == "v110") { + } + if (useToolset == "v110") { return "v11"; - } else if (useToolset == "v100") { + } + if (useToolset == "v100") { return "v10"; - } else { - return ""; } + return ""; } std::string cmGlobalVisualStudio10Generator::GetLibFlagTableName() const @@ -1566,15 +1579,17 @@ std::string cmGlobalVisualStudio10Generator::GetLibFlagTableName() const if ((useToolset == "v140") || (useToolset == "v141") || (useToolset == "v142")) { return "v14"; - } else if (useToolset == "v120") { + } + if (useToolset == "v120") { return "v12"; - } else if (useToolset == "v110") { + } + if (useToolset == "v110") { return "v11"; - } else if (useToolset == "v100") { + } + if (useToolset == "v100") { return "v10"; - } else { - return ""; } + return ""; } std::string cmGlobalVisualStudio10Generator::GetLinkFlagTableName() const @@ -1584,19 +1599,23 @@ std::string cmGlobalVisualStudio10Generator::GetLinkFlagTableName() const if (useToolset == "v142") { return "v142"; - } else if (useToolset == "v141") { + } + if (useToolset == "v141") { return "v141"; - } else if (useToolset == "v140") { + } + if (useToolset == "v140") { return "v140"; - } else if (useToolset == "v120") { + } + if (useToolset == "v120") { return "v12"; - } else if (useToolset == "v110") { + } + if (useToolset == "v110") { return "v11"; - } else if (useToolset == "v100") { + } + if (useToolset == "v100") { return "v10"; - } else { - return ""; } + return ""; } std::string cmGlobalVisualStudio10Generator::GetMasmFlagTableName() const @@ -1607,15 +1626,17 @@ std::string cmGlobalVisualStudio10Generator::GetMasmFlagTableName() const if ((useToolset == "v140") || (useToolset == "v141") || (useToolset == "v142")) { return "v14"; - } else if (useToolset == "v120") { + } + if (useToolset == "v120") { return "v12"; - } else if (useToolset == "v110") { + } + if (useToolset == "v110") { return "v11"; - } else if (useToolset == "v100") { + } + if (useToolset == "v100") { return "v10"; - } else { - return ""; } + return ""; } std::string cmGlobalVisualStudio10Generator::CanonicalToolsetName( diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index b3d9552..63c21c5 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -241,15 +241,10 @@ protected: private: struct LongestSourcePath { - LongestSourcePath() - : Length(0) - , Target(0) - , SourceFile(0) - { - } - size_t Length; - cmGeneratorTarget* Target; - cmSourceFile const* SourceFile; + LongestSourcePath() = default; + size_t Length = 0; + cmGeneratorTarget* Target = nullptr; + cmSourceFile const* SourceFile = nullptr; std::string SourceRel; }; LongestSourcePath LongestSource; diff --git a/Source/cmGlobalVisualStudio11Generator.cxx b/Source/cmGlobalVisualStudio11Generator.cxx index 75e3df8..3ad10eb 100644 --- a/Source/cmGlobalVisualStudio11Generator.cxx +++ b/Source/cmGlobalVisualStudio11Generator.cxx @@ -22,7 +22,7 @@ static const char* cmVS11GenName(const std::string& name, std::string& genName) { if (strncmp(name.c_str(), vs11generatorName, sizeof(vs11generatorName) - 6) != 0) { - return 0; + return nullptr; } const char* p = name.c_str() + sizeof(vs11generatorName) - 6; if (cmHasLiteralPrefix(p, " 2012")) { @@ -216,9 +216,8 @@ bool cmGlobalVisualStudio11Generator::SelectWindowsPhoneToolset( this->IsWindowsDesktopToolsetInstalled()) { toolset = "v110_wp80"; return true; - } else { - return false; } + return false; } return this->cmGlobalVisualStudio10Generator::SelectWindowsPhoneToolset( toolset); @@ -232,9 +231,8 @@ bool cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset( this->IsWindowsDesktopToolsetInstalled()) { toolset = "v110"; return true; - } else { - return false; } + return false; } return this->cmGlobalVisualStudio10Generator::SelectWindowsStoreToolset( toolset); @@ -245,6 +243,7 @@ bool cmGlobalVisualStudio11Generator::UseFolderProperty() const // Intentionally skip up to the top-level class implementation. // Folders are not supported by the Express editions in VS10 and earlier, // but they are in VS11 Express and above. + // NOLINTNEXTLINE(bugprone-parent-virtual-call) return cmGlobalGenerator::UseFolderProperty(); } diff --git a/Source/cmGlobalVisualStudio12Generator.cxx b/Source/cmGlobalVisualStudio12Generator.cxx index 7e56a78..d417f9e 100644 --- a/Source/cmGlobalVisualStudio12Generator.cxx +++ b/Source/cmGlobalVisualStudio12Generator.cxx @@ -21,7 +21,7 @@ static const char* cmVS12GenName(const std::string& name, std::string& genName) { if (strncmp(name.c_str(), vs12generatorName, sizeof(vs12generatorName) - 6) != 0) { - return 0; + return nullptr; } const char* p = name.c_str() + sizeof(vs12generatorName) - 6; if (cmHasLiteralPrefix(p, " 2013")) { @@ -194,9 +194,8 @@ bool cmGlobalVisualStudio12Generator::SelectWindowsPhoneToolset( this->IsWindowsDesktopToolsetInstalled()) { toolset = "v120_wp81"; return true; - } else { - return false; } + return false; } return this->cmGlobalVisualStudio11Generator::SelectWindowsPhoneToolset( toolset); @@ -210,9 +209,8 @@ bool cmGlobalVisualStudio12Generator::SelectWindowsStoreToolset( this->IsWindowsDesktopToolsetInstalled()) { toolset = "v120"; return true; - } else { - return false; } + return false; } return this->cmGlobalVisualStudio11Generator::SelectWindowsStoreToolset( toolset); diff --git a/Source/cmGlobalVisualStudio14Generator.cxx b/Source/cmGlobalVisualStudio14Generator.cxx index 0e05083..7424ca3 100644 --- a/Source/cmGlobalVisualStudio14Generator.cxx +++ b/Source/cmGlobalVisualStudio14Generator.cxx @@ -23,7 +23,7 @@ static const char* cmVS14GenName(const std::string& name, std::string& genName) { if (strncmp(name.c_str(), vs14generatorName, sizeof(vs14generatorName) - 6) != 0) { - return 0; + return nullptr; } const char* p = name.c_str() + sizeof(vs14generatorName) - 6; if (cmHasLiteralPrefix(p, " 2015")) { @@ -213,9 +213,8 @@ bool cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset( this->IsWindowsDesktopToolsetInstalled()) { toolset = "v140"; return true; - } else { - return false; } + return false; } return this->cmGlobalVisualStudio12Generator::SelectWindowsStoreToolset( toolset); @@ -255,7 +254,7 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKMaxVersion( return std::string(); } // If the value is something else, trust that it is a valid SDK value. - else if (value) { + if (value) { return *value; } // If value is an invalid pointer, leave result unchanged. @@ -373,6 +372,7 @@ std::string cmGlobalVisualStudio14Generator::GetWindows10SDKVersion( return sdks.at(0); } #endif + (void)mf; // Return an empty string return std::string(); } diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx index 758ce83..06fd61c 100644 --- a/Source/cmGlobalVisualStudio71Generator.cxx +++ b/Source/cmGlobalVisualStudio71Generator.cxx @@ -101,14 +101,14 @@ void cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout, // check to see if this is a fortran build std::string ext = ".vcproj"; const char* project = - "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""; + R"(Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = ")"; if (this->TargetIsFortranOnly(t)) { ext = ".vfproj"; - project = "Project(\"{6989167D-11E4-40FE-8C1A-2192A86A7E90}\") = \""; + project = R"(Project("{6989167D-11E4-40FE-8C1A-2192A86A7E90}") = ")"; } if (t->IsCSharpOnly()) { ext = ".csproj"; - project = "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \""; + project = R"(Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = ")"; } cmValue targetExt = t->GetProperty("GENERATOR_FILE_NAME_EXT"); if (targetExt) { @@ -125,11 +125,11 @@ void cmGlobalVisualStudio71Generator::WriteProject(std::ostream& fout, fout << "EndProject\n"; - UtilityDependsMap::iterator ui = this->UtilityDepends.find(t); + auto ui = this->UtilityDepends.find(t); if (ui != this->UtilityDepends.end()) { const char* uname = ui->second.c_str(); /* clang-format off */ - fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"" + fout << R"(Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = ")" << uname << "\", \"" << this->ConvertToSolutionPath(dir) << (dir[0]? "\\":"") << uname << ".vcproj" << "\", \"{" @@ -169,7 +169,9 @@ void cmGlobalVisualStudio71Generator::WriteExternalProject( { fout << "Project(\"{" << (typeGuid ? typeGuid - : std::string(this->ExternalProjectType(location))) + : std::string( + cmGlobalVisualStudio71Generator::ExternalProjectType( + location))) << "}\") = \"" << name << "\", \"" << this->ConvertToSolutionPath(location) << "\", \"{" << this->GetGUID(name) << "}\"\n"; @@ -216,8 +218,7 @@ void cmGlobalVisualStudio71Generator::WriteProjectConfigurations( } fout << "\t\t{" << guid << "}." << i << ".ActiveCfg = " << dstConfig << "|" << platformName << std::endl; - std::set<std::string>::const_iterator ci = - configsPartOfDefaultBuild.find(i); + auto ci = configsPartOfDefaultBuild.find(i); if (!(ci == configsPartOfDefaultBuild.end())) { fout << "\t\t{" << guid << "}." << i << ".Build.0 = " << dstConfig << "|" << platformName << std::endl; diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 7431176..c375d60 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -76,9 +76,7 @@ cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator( this->ExtraFlagTable = cmVS7ExtraFlagTable; } -cmGlobalVisualStudio7Generator::~cmGlobalVisualStudio7Generator() -{ -} +cmGlobalVisualStudio7Generator::~cmGlobalVisualStudio7Generator() = default; // Package GUID of Intel Visual Fortran plugin to VS IDE #define CM_INTEL_PLUGIN_GUID "{B68A201D-CB9B-47AF-A52F-7EEC72E217E4}" @@ -160,7 +158,7 @@ std::string cmGlobalVisualStudio7Generator::FindDevEnvCommand() // Search in standard location. vskey = this->GetRegistryBase() + ";InstallDir"; - if (cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd, + if (cmSystemTools::ReadRegistryValue(vskey, vscmd, cmSystemTools::KeyWOW64_32)) { cmSystemTools::ConvertToUnixSlashes(vscmd); vscmd += "/devenv.com"; @@ -171,9 +169,9 @@ std::string cmGlobalVisualStudio7Generator::FindDevEnvCommand() // Search where VS15Preview places it. vskey = cmStrCat( - "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;", + R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\SxS\VS7;)", this->GetIDEVersion()); - if (cmSystemTools::ReadRegistryValue(vskey.c_str(), vscmd, + if (cmSystemTools::ReadRegistryValue(vskey, vscmd, cmSystemTools::KeyWOW64_32)) { cmSystemTools::ConvertToUnixSlashes(vscmd); vscmd += "/Common7/IDE/devenv.com"; @@ -192,17 +190,23 @@ const char* cmGlobalVisualStudio7Generator::ExternalProjectType( std::string extension = cmSystemTools::GetFilenameLastExtension(location); if (extension == ".vbproj") { return "F184B08F-C81C-45F6-A57F-5ABD9991F28F"; - } else if (extension == ".csproj") { + } + if (extension == ".csproj") { return "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC"; - } else if (extension == ".fsproj") { + } + if (extension == ".fsproj") { return "F2A71F9B-5D33-465A-A702-920D77279786"; - } else if (extension == ".vdproj") { + } + if (extension == ".vdproj") { return "54435603-DBB4-11D2-8724-00A0C9A8B90C"; - } else if (extension == ".dbproj") { + } + if (extension == ".dbproj") { return "C8D11400-126E-41CD-887F-60BD40844F9E"; - } else if (extension == ".wixproj") { + } + if (extension == ".wixproj") { return "930C7802-8A8C-48F9-8165-68863BCCD9DD"; - } else if (extension == ".pyproj") { + } + if (extension == ".pyproj") { return "888888A0-9F3D-457C-B088-3A5042F75D52"; } return "8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942"; @@ -334,7 +338,7 @@ void cmGlobalVisualStudio7Generator::OutputSLNFile( } this->CurrentProject = root->GetProjectName(); std::string fname = GetSLNFile(root); - cmGeneratedFileStream fout(fname.c_str()); + cmGeneratedFileStream fout(fname); fout.SetCopyIfDifferent(true); if (!fout) { return; @@ -380,7 +384,8 @@ void cmGlobalVisualStudio7Generator::WriteTargetConfigurations( // On VS 19 and above, always map .NET SDK projects to "Any CPU". if (target->IsDotNetSdkTarget() && this->GetVersion() >= VSVersion::VS16 && - !this->IsReservedTarget(target->GetName())) { + !cmGlobalVisualStudio7Generator::IsReservedTarget( + target->GetName())) { mapping = "Any CPU"; } this->WriteProjectConfigurations(fout, *vcprojName, *target, configs, @@ -421,7 +426,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( cmValue expath = target->GetProperty("EXTERNAL_MSPROJECT"); if (expath) { std::string project = target->GetName(); - std::string location = *expath; + std::string const& location = *expath; this->WriteExternalProject(fout, project, location, target->GetProperty("VS_PROJECT_TYPE"), @@ -452,7 +457,7 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( std::string cumulativePath; for (std::string const& iter : tokens) { - if (!iter.size()) { + if (iter.empty()) { continue; } @@ -501,7 +506,7 @@ void cmGlobalVisualStudio7Generator::WriteFoldersContent(std::ostream& fout) std::string guidParent(this->GetGUID(key)); for (std::string const& it : iter.second) { - std::string value(it); + std::string const& value(it); std::string guid(this->GetGUID(value)); fout << "\t\t{" << guid << "} = {" << guidParent << "}\n"; @@ -517,7 +522,7 @@ std::string cmGlobalVisualStudio7Generator::ConvertToSolutionPath( // use windows slashes. std::string d = path; std::string::size_type pos = 0; - while ((pos = d.find('/', pos)) != d.npos) { + while ((pos = d.find('/', pos)) != std::string::npos) { d[pos++] = '\\'; } return d; @@ -541,8 +546,9 @@ void cmGlobalVisualStudio7Generator::WriteSLNGlobalSections( } else if (cmHasLiteralPrefix(name, "POST_")) { name = name.substr(5); sectionType = "postSolution"; - } else + } else { continue; + } if (!name.empty()) { bool addGuid = false; if (name == "ExtensibilityGlobals" && sectionType == "postSolution") { @@ -580,9 +586,10 @@ void cmGlobalVisualStudio7Generator::WriteSLNGlobalSections( << "\t\tSolutionGuid = {" << guid << "}\n" << "\tEndGlobalSection\n"; } - if (!extensibilityAddInsOverridden) + if (!extensibilityAddInsOverridden) { fout << "\tGlobalSection(ExtensibilityAddIns) = postSolution\n" << "\tEndGlobalSection\n"; + } } // Standard end of dsw file @@ -601,13 +608,13 @@ std::string cmGlobalVisualStudio7Generator::WriteUtilityDepend( std::string fname = cmStrCat(target->GetLocalGenerator()->GetCurrentBinaryDirectory(), '/', pname, ".vcproj"); - cmGeneratedFileStream fout(fname.c_str()); + cmGeneratedFileStream fout(fname); fout.SetCopyIfDifferent(true); - std::string guid = this->GetGUID(pname.c_str()); + std::string guid = this->GetGUID(pname); /* clang-format off */ fout << - "<?xml version=\"1.0\" encoding = \"" + R"(<?xml version="1.0" encoding = ")" << this->Encoding() << "\"?>\n" "<VisualStudioProject\n" "\tProjectType=\"Visual C++\"\n" @@ -730,13 +737,12 @@ std::set<std::string> cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild( bool cmGlobalVisualStudio7Generator::IsDependedOn( OrderedTargetDependSet const& projectTargets, cmGeneratorTarget const* gtIn) { - for (cmTargetDepend const& l : projectTargets) { - TargetDependSet const& tgtdeps = this->GetTargetDirectDepends(l); - if (tgtdeps.count(gtIn)) { - return true; - } - } - return false; + return std::any_of(projectTargets.begin(), projectTargets.end(), + [this, gtIn](cmTargetDepend const& l) { + TargetDependSet const& tgtdeps = + this->GetTargetDirectDepends(l); + return tgtdeps.count(gtIn); + }); } std::string cmGlobalVisualStudio7Generator::Encoding() diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index e901ecd..1594457 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -31,7 +31,7 @@ class BT; class cmGlobalVisualStudio7Generator : public cmGlobalVisualStudioGenerator { public: - ~cmGlobalVisualStudio7Generator(); + ~cmGlobalVisualStudio7Generator() override; //! Create a local generator appropriate to this Global Generator std::unique_ptr<cmLocalGenerator> CreateLocalGenerator( diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 323ee67..647fc2d 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -44,7 +44,8 @@ cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator( { this->ProjectConfigurationSectionName = "ProjectConfigurationPlatforms"; this->Name = name; - this->ExtraFlagTable = this->GetExtraFlagTableVS8(); + this->ExtraFlagTable = + cmGlobalVisualStudio8Generator::GetExtraFlagTableVS8(); } std::string cmGlobalVisualStudio8Generator::FindDevEnvCommand() @@ -52,9 +53,9 @@ std::string cmGlobalVisualStudio8Generator::FindDevEnvCommand() // First look for VCExpress. std::string vsxcmd; std::string vsxkey = - cmStrCat("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\", + cmStrCat(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VCExpress\)", this->GetIDEVersion(), ";InstallDir"); - if (cmSystemTools::ReadRegistryValue(vsxkey.c_str(), vsxcmd, + if (cmSystemTools::ReadRegistryValue(vsxkey, vsxcmd, cmSystemTools::KeyWOW64_32)) { cmSystemTools::ConvertToUnixSlashes(vsxcmd); vsxcmd += "/VCExpress.exe"; @@ -149,6 +150,7 @@ void cmGlobalVisualStudio8Generator::Configure() bool cmGlobalVisualStudio8Generator::UseFolderProperty() const { + // NOLINTNEXTLINE(bugprone-parent-virtual-call) return IsExpressEdition() ? false : cmGlobalGenerator::UseFolderProperty(); } @@ -172,7 +174,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() std::move(cc)); auto ptr = cm::make_unique<cmGeneratorTarget>(tgt, &lg); - auto gt = ptr.get(); + auto* gt = ptr.get(); lg.AddGeneratorTarget(std::move(ptr)); // Organize in the "predefined targets" folder: @@ -190,7 +192,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() cmStrCat(generators[0]->GetMakefile()->GetCurrentBinaryDirectory(), '/', stampList); std::string stampFile; - cmGeneratedFileStream fout(stampListFile.c_str()); + cmGeneratedFileStream fout(stampListFile); for (const auto& gi : generators) { stampFile = cmStrCat(gi->GetMakefile()->GetCurrentBinaryDirectory(), "/CMakeFiles/generate.stamp"); @@ -237,8 +239,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() // Sort the list of input files and remove duplicates. std::sort(listFiles.begin(), listFiles.end(), std::less<std::string>()); - std::vector<std::string>::iterator new_end = - std::unique(listFiles.begin(), listFiles.end()); + auto new_end = std::unique(listFiles.begin(), listFiles.end()); listFiles.erase(new_end, listFiles.end()); // Create a rule to re-run CMake. @@ -277,8 +278,8 @@ void cmGlobalVisualStudio8Generator::AddExtraIDETargets() { cmGlobalVisualStudio7Generator::AddExtraIDETargets(); if (this->AddCheckTarget()) { - for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) { - const auto& tgts = this->LocalGenerators[i]->GetGeneratorTargets(); + for (auto& LocalGenerator : this->LocalGenerators) { + const auto& tgts = LocalGenerator->GetGeneratorTargets(); // All targets depend on the build-system check target. for (const auto& ti : tgts) { if (ti->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET) { @@ -324,8 +325,7 @@ void cmGlobalVisualStudio8Generator::WriteProjectConfigurations( << (!platformMapping.empty() ? platformMapping : this->GetPlatformName()) << "\n"; - std::set<std::string>::const_iterator ci = - configsPartOfDefaultBuild.find(i); + auto ci = configsPartOfDefaultBuild.find(i); if (!(ci == configsPartOfDefaultBuild.end())) { fout << "\t\t{" << guid << "}." << i << "|" << this->GetPlatformName() << ".Build.0 = " << dstConfig << "|" @@ -382,6 +382,7 @@ bool cmGlobalVisualStudio8Generator::ComputeTargetDepends() { // Skip over the cmGlobalVisualStudioGenerator implementation! // We do not need the support that VS <= 7.1 needs. + // NOLINTNEXTLINE(bugprone-parent-virtual-call) return this->cmGlobalGenerator::ComputeTargetDepends(); } @@ -404,20 +405,23 @@ bool cmGlobalVisualStudio8Generator::NeedLinkLibraryDependencies( cmGeneratorTarget* target) { // Look for utility dependencies that magically link. - for (BT<std::pair<std::string, bool>> const& ui : target->GetUtilities()) { - if (cmGeneratorTarget* depTarget = - target->GetLocalGenerator()->FindGeneratorTargetToUse( - ui.Value.first)) { - if (depTarget->IsInBuildSystem() && - depTarget->GetProperty("EXTERNAL_MSPROJECT")) { - // This utility dependency names an external .vcproj target. - // We use LinkLibraryDependencies="true" to link to it without - // predicting the .lib file location or name. - return true; + auto const& utilities = target->GetUtilities(); + return std::any_of( + utilities.begin(), utilities.end(), + [target](BT<std::pair<std::string, bool>> const& ui) { + if (cmGeneratorTarget* depTarget = + target->GetLocalGenerator()->FindGeneratorTargetToUse( + ui.Value.first)) { + if (depTarget->IsInBuildSystem() && + depTarget->GetProperty("EXTERNAL_MSPROJECT")) { + // This utility dependency names an external .vcproj target. + // We use LinkLibraryDependencies="true" to link to it without + // predicting the .lib file location or name. + return true; + } } - } - } - return false; + return false; + }); } static cmVS7FlagTable cmVS8ExtraFlagTable[] = { diff --git a/Source/cmGlobalVisualStudio9Generator.cxx b/Source/cmGlobalVisualStudio9Generator.cxx index cd0b114..9f6550b 100644 --- a/Source/cmGlobalVisualStudio9Generator.cxx +++ b/Source/cmGlobalVisualStudio9Generator.cxx @@ -158,5 +158,5 @@ std::string cmGlobalVisualStudio9Generator::GetUserMacrosDirectory() std::string cmGlobalVisualStudio9Generator::GetUserMacrosRegKeyBase() { - return "Software\\Microsoft\\VisualStudio\\9.0\\vsmacros"; + return R"(Software\Microsoft\VisualStudio\9.0\vsmacros)"; } diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 9d168d0..31f6f77 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -51,9 +51,7 @@ cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator( } } -cmGlobalVisualStudioGenerator::~cmGlobalVisualStudioGenerator() -{ -} +cmGlobalVisualStudioGenerator::~cmGlobalVisualStudioGenerator() = default; cmGlobalVisualStudioGenerator::VSVersion cmGlobalVisualStudioGenerator::GetVersion() const @@ -188,7 +186,7 @@ std::string cmGlobalVisualStudioGenerator::GetRegistryBase() std::string cmGlobalVisualStudioGenerator::GetRegistryBase(const char* version) { - std::string key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\"; + std::string key = R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\)"; return key + version; } @@ -520,13 +518,12 @@ std::string cmGlobalVisualStudioGenerator::GetStartupProjectName( std::string startup = *n; if (this->FindTarget(startup)) { return startup; - } else { - root->GetMakefile()->IssueMessage( - MessageType::AUTHOR_WARNING, - "Directory property VS_STARTUP_PROJECT specifies target " - "'" + - startup + "' that does not exist. Ignoring."); } + root->GetMakefile()->IssueMessage( + MessageType::AUTHOR_WARNING, + "Directory property VS_STARTUP_PROJECT specifies target " + "'" + + startup + "' that does not exist. Ignoring."); } // default, if not specified @@ -961,7 +958,7 @@ void cmGlobalVisualStudioGenerator::AddSymbolExportCommand( commands.push_back(std::move(command)); } -static bool OpenSolution(std::string sln) +static bool OpenSolution(std::string const& sln) { HRESULT comInitialized = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h index 576e4f2..3e20ada 100644 --- a/Source/cmGlobalVisualStudioGenerator.h +++ b/Source/cmGlobalVisualStudioGenerator.h @@ -44,7 +44,7 @@ public: VS17 = 170 }; - virtual ~cmGlobalVisualStudioGenerator(); + ~cmGlobalVisualStudioGenerator() override; VSVersion GetVersion() const; void SetVersion(VSVersion v); @@ -133,8 +133,8 @@ public: std::string First; public: - TargetCompare(std::string const& first) - : First(first) + TargetCompare(std::string first) + : First(std::move(first)) { } bool operator()(cmGeneratorTarget const* l, @@ -193,7 +193,6 @@ protected: using UtilityDependsMap = std::map<cmGeneratorTarget const*, std::string>; UtilityDependsMap UtilityDepends; -protected: VSVersion Version; bool ExpressEdition; diff --git a/Source/cmGlobalVisualStudioVersionedGenerator.cxx b/Source/cmGlobalVisualStudioVersionedGenerator.cxx index ee24f05..59f1dc2 100644 --- a/Source/cmGlobalVisualStudioVersionedGenerator.cxx +++ b/Source/cmGlobalVisualStudioVersionedGenerator.cxx @@ -53,7 +53,8 @@ static bool VSIsArm64Host() # undef CM_VS_GCC_DIAGNOSTIC_PUSHED #endif - USHORT processMachine, nativeMachine; + USHORT processMachine; + USHORT nativeMachine; return s_IsWow64Process2Impl != nullptr && s_IsWow64Process2Impl(GetCurrentProcess(), &processMachine, @@ -65,7 +66,7 @@ static bool VSHasDotNETFrameworkArm64() { std::string dotNetArm64; return cmSystemTools::ReadRegistryValue( - "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\.NETFramework;InstallRootArm64", + R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework;InstallRootArm64)", dotNetArm64, cmSystemTools::KeyWOW64_64); } @@ -85,19 +86,19 @@ static std::string VSHostPlatformName() { if (VSIsArm64Host()) { return "ARM64"; - } else if (VSIsWow64()) { + } + if (VSIsWow64()) { return "x64"; - } else { + } #if defined(_M_ARM) - return "ARM"; + return "ARM"; #elif defined(_M_IA64) - return "Itanium"; + return "Itanium"; #elif defined(_WIN64) - return "x64"; + return "x64"; #else - return "Win32"; + return "Win32"; #endif - } } static std::string VSHostArchitecture( @@ -105,19 +106,19 @@ static std::string VSHostArchitecture( { if (VSIsArm64Host()) { return v >= cmGlobalVisualStudioGenerator::VSVersion::VS17 ? "ARM64" : ""; - } else if (VSIsWow64()) { + } + if (VSIsWow64()) { return "x64"; - } else { + } #if defined(_M_ARM) - return ""; + return ""; #elif defined(_M_IA64) - return ""; + return ""; #elif defined(_WIN64) - return "x64"; + return "x64"; #else - return "x86"; + return "x86"; #endif - } } static unsigned int VSVersionToMajor( @@ -211,7 +212,7 @@ static const char* cmVS15GenName(const std::string& name, std::string& genName) { if (strncmp(name.c_str(), vs15generatorName, sizeof(vs15generatorName) - 6) != 0) { - return 0; + return nullptr; } const char* p = name.c_str() + sizeof(vs15generatorName) - 6; if (cmHasLiteralPrefix(p, " 2017")) { @@ -306,7 +307,7 @@ static const char* cmVS16GenName(const std::string& name, std::string& genName) { if (strncmp(name.c_str(), vs16generatorName, sizeof(vs16generatorName) - 6) != 0) { - return 0; + return nullptr; } const char* p = name.c_str() + sizeof(vs16generatorName) - 6; if (cmHasLiteralPrefix(p, " 2019")) { @@ -320,7 +321,7 @@ static const char* cmVS17GenName(const std::string& name, std::string& genName) { if (strncmp(name.c_str(), vs17generatorName, sizeof(vs17generatorName) - 6) != 0) { - return 0; + return nullptr; } const char* p = name.c_str() + sizeof(vs17generatorName) - 6; if (cmHasLiteralPrefix(p, " 2022")) { @@ -530,7 +531,7 @@ bool cmGlobalVisualStudioVersionedGenerator::SetGeneratorInstance( if (!this->GeneratorInstanceVersion.empty()) { std::string const majorStr = VSVersionToMajorString(this->Version); cmsys::RegularExpression versionRegex( - cmStrCat("^", majorStr, "\\.[0-9]+\\.[0-9]+\\.[0-9]+$")); + cmStrCat("^", majorStr, R"(\.[0-9]+\.[0-9]+\.[0-9]+$)")); if (!versionRegex.find(this->GeneratorInstanceVersion)) { std::ostringstream e; /* clang-format off */ @@ -606,7 +607,7 @@ bool cmGlobalVisualStudioVersionedGenerator::ParseGeneratorInstance( this->GeneratorInstanceVersion.clear(); std::vector<std::string> const fields = cmTokenize(is, ","); - std::vector<std::string>::const_iterator fi = fields.begin(); + auto fi = fields.begin(); if (fi == fields.end()) { return true; } @@ -900,9 +901,8 @@ bool cmGlobalVisualStudioVersionedGenerator::SelectWindowsStoreToolset( this->IsWindowsDesktopToolsetInstalled()) { toolset = VSVersionToToolset(this->Version); return true; - } else { - return false; } + return false; } return this->cmGlobalVisualStudio14Generator::SelectWindowsStoreToolset( toolset); diff --git a/Source/cmIDEOptions.cxx b/Source/cmIDEOptions.cxx index c09aa46..9468d4a 100644 --- a/Source/cmIDEOptions.cxx +++ b/Source/cmIDEOptions.cxx @@ -20,15 +20,13 @@ cmIDEOptions::cmIDEOptions() this->AllowDefine = true; this->DoingInclude = false; this->AllowSlash = false; - this->DoingFollowing = 0; - for (int i = 0; i < FlagTableCount; ++i) { - this->FlagTable[i] = 0; + this->DoingFollowing = nullptr; + for (auto& flag : this->FlagTable) { + flag = nullptr; } } -cmIDEOptions::~cmIDEOptions() -{ -} +cmIDEOptions::~cmIDEOptions() = default; void cmIDEOptions::HandleFlag(std::string const& flag) { @@ -49,7 +47,7 @@ void cmIDEOptions::HandleFlag(std::string const& flag) // If the last option expected a following value, this is it. if (this->DoingFollowing) { this->FlagMapUpdate(this->DoingFollowing, flag); - this->DoingFollowing = 0; + this->DoingFollowing = nullptr; return; } @@ -248,8 +246,7 @@ bool cmIDEOptions::HasFlag(std::string const& flag) const const char* cmIDEOptions::GetFlag(std::string const& flag) const { // This method works only for single-valued flags! - std::map<std::string, FlagValue>::const_iterator i = - this->FlagMap.find(flag); + auto i = this->FlagMap.find(flag); if (i != this->FlagMap.cend() && i->second.size() == 1) { return i->second[0].c_str(); } diff --git a/Source/cmLocalVisualStudio10Generator.cxx b/Source/cmLocalVisualStudio10Generator.cxx index 4c0d2eea..8fe6677 100644 --- a/Source/cmLocalVisualStudio10Generator.cxx +++ b/Source/cmLocalVisualStudio10Generator.cxx @@ -18,8 +18,8 @@ class cmGeneratorTarget; class cmVS10XMLParser : public cmXMLParser { public: - virtual void EndElement(const std::string& /* name */) {} - virtual void CharacterDataHandler(const char* data, int length) + void EndElement(const std::string& /* name */) override {} + void CharacterDataHandler(const char* data, int length) override { if (this->DoGUID) { if (data[0] == '{') { @@ -31,7 +31,7 @@ public: this->DoGUID = false; } } - virtual void StartElement(const std::string& name, const char**) + void StartElement(const std::string& name, const char**) override { // once the GUID is found do nothing if (!this->GUID.empty()) { @@ -41,7 +41,7 @@ public: this->DoGUID = true; } } - int InitializeParser() + int InitializeParser() override { this->DoGUID = false; int ret = cmXMLParser::InitializeParser(); @@ -63,9 +63,7 @@ cmLocalVisualStudio10Generator::cmLocalVisualStudio10Generator( { } -cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator() -{ -} +cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator() = default; void cmLocalVisualStudio10Generator::GenerateTarget(cmGeneratorTarget* target) { diff --git a/Source/cmLocalVisualStudio10Generator.h b/Source/cmLocalVisualStudio10Generator.h index 7bfe3b7..fe44bb5 100644 --- a/Source/cmLocalVisualStudio10Generator.h +++ b/Source/cmLocalVisualStudio10Generator.h @@ -24,7 +24,7 @@ public: //! Set cache only and recurse to false by default. cmLocalVisualStudio10Generator(cmGlobalGenerator* gg, cmMakefile* mf); - virtual ~cmLocalVisualStudio10Generator(); + ~cmLocalVisualStudio10Generator() override; void ReadAndStoreExternalGUID(const std::string& name, const char* path) override; diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 538c036..ded1647 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -57,7 +57,7 @@ public: using ItemVector = cmComputeLinkInformation::ItemVector; void OutputLibraries(std::ostream& fout, ItemVector const& libs); void OutputObjects(std::ostream& fout, cmGeneratorTarget* t, - std::string const& config, const char* isep = 0); + std::string const& config, const char* isep = nullptr); private: cmLocalVisualStudio7Generator* LocalGenerator; @@ -108,8 +108,8 @@ void cmLocalVisualStudio7Generator::Generate() } auto& gtVisited = this->GetSourcesVisited(gt); - auto& deps = this->GlobalGenerator->GetTargetDirectDepends(gt); - for (auto& d : deps) { + auto const& deps = this->GlobalGenerator->GetTargetDirectDepends(gt); + for (auto const& d : deps) { // Take the union of visited source files of custom commands auto depVisited = this->GetSourcesVisited(d); gtVisited.insert(depVisited.begin(), depVisited.end()); @@ -127,7 +127,7 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets() // commands for targets in which no sources are built. Add dummy // rules to force these targets to build. const auto& tgts = this->GetGeneratorTargets(); - for (auto& l : tgts) { + for (auto const& l : tgts) { if (l->GetType() == cmStateEnums::GLOBAL_TARGET) { cmCustomCommandLines force_commands = cmMakeSingleCommandLine({ "cd", "." }); @@ -179,8 +179,7 @@ void cmLocalVisualStudio7Generator::WriteStampFiles() // Sort the list of input files and remove duplicates. std::sort(listFiles.begin(), listFiles.end(), std::less<std::string>()); - std::vector<std::string>::iterator new_end = - std::unique(listFiles.begin(), listFiles.end()); + auto new_end = std::unique(listFiles.begin(), listFiles.end()); listFiles.erase(new_end, listFiles.end()); for (const std::string& lf : listFiles) { @@ -217,7 +216,7 @@ void cmLocalVisualStudio7Generator::GenerateTarget(cmGeneratorTarget* target) // Generate the project file and replace it atomically with // copy-if-different. We use a separate timestamp so that the IDE // does not reload project files unnecessarily. - cmGeneratedFileStream fout(fname.c_str()); + cmGeneratedFileStream fout(fname); fout.SetCopyIfDifferent(true); this->WriteVCProjFile(fout, lname, target); if (fout.Close()) { @@ -253,8 +252,7 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule() // Sort the list of input files and remove duplicates. std::sort(listFiles.begin(), listFiles.end(), std::less<std::string>()); - std::vector<std::string>::iterator new_end = - std::unique(listFiles.begin(), listFiles.end()); + auto new_end = std::unique(listFiles.begin(), listFiles.end()); listFiles.erase(new_end, listFiles.end()); std::string argS = cmStrCat("-S", this->GetSourceDirectory()); @@ -280,10 +278,9 @@ cmSourceFile* cmLocalVisualStudio7Generator::CreateVCProjBuildRule() // the generator validated all project-named sources. file->ResolveFullPath(); return file; - } else { - cmSystemTools::Error("Error adding rule for " + makefileIn); - return nullptr; } + cmSystemTools::Error("Error adding rule for " + makefileIn); + return nullptr; } void cmLocalVisualStudio7Generator::WriteConfigurations( @@ -559,12 +556,11 @@ cmVS7FlagTable cmLocalVisualStudio7GeneratorFortranLinkFlagTable[] = { class cmLocalVisualStudio7Generator::EventWriter { public: - EventWriter(cmLocalVisualStudio7Generator* lg, const std::string& config, + EventWriter(cmLocalVisualStudio7Generator* lg, std::string config, std::ostream& os) : LG(lg) - , Config(config) + , Config(std::move(config)) , Stream(os) - , First(true) { } void Start(const char* tool) @@ -610,7 +606,7 @@ private: cmLocalVisualStudio7Generator* LG; std::string Config; std::ostream& Stream; - bool First; + bool First = true; }; void cmLocalVisualStudio7Generator::WriteConfiguration( @@ -634,7 +630,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( // 1 == executable // 10 == utility const char* configType = "10"; - const char* projectType = 0; + const char* projectType = nullptr; bool targetBuilds = true; switch (target->GetType()) { @@ -843,7 +839,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( } fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool if (gg->IsMarmasmEnabled() && !this->FortranProject) { - Options marmasmOptions(this, Options::MarmasmCompiler, 0, 0); + Options marmasmOptions(this, Options::MarmasmCompiler, nullptr, nullptr); /* clang-format off */ fout << "\t\t\t<Tool\n" @@ -861,7 +857,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( /* clang-format on */ } if (gg->IsMasmEnabled() && !this->FortranProject) { - Options masmOptions(this, Options::MasmCompiler, 0, 0); + Options masmOptions(this, Options::MasmCompiler, nullptr, nullptr); /* clang-format off */ fout << "\t\t\t<Tool\n" @@ -957,7 +953,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration( } std::string cmLocalVisualStudio7Generator::GetBuildTypeLinkerFlags( - std::string rootLinkerFlags, const std::string& configName) + std::string const& rootLinkerFlags, const std::string& configName) { std::string configTypeUpper = cmSystemTools::UpperCase(configName); std::string extraLinkOptionsBuildTypeDef = @@ -1439,8 +1435,7 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, fout << "\t<Files>\n"; // Loop through every source group. - for (unsigned int i = 0; i < sourceGroups.size(); ++i) { - cmSourceGroup sg = sourceGroups[i]; + for (auto const& sg : sourceGroups) { this->WriteGroup(&sg, target, fout, libName, configs, sources); } @@ -1634,10 +1629,9 @@ std::string cmLocalVisualStudio7Generator::ComputeLongestObjectDirectory( // Compute the maximum length configuration name. std::string config_max; - for (std::vector<std::string>::iterator i = configs.begin(); - i != configs.end(); ++i) { - if (i->size() > config_max.size()) { - config_max = *i; + for (auto& config : configs) { + if (config.size() > config_max.size()) { + config_max = config; } } @@ -1663,9 +1657,8 @@ bool cmLocalVisualStudio7Generator::WriteGroup( // Write the children to temporary output. bool hasChildrenWithSources = false; std::ostringstream tmpOut; - for (unsigned int i = 0; i < children.size(); ++i) { - if (this->WriteGroup(&children[i], target, tmpOut, libName, configs, - sources)) { + for (const auto& child : children) { + if (this->WriteGroup(&child, target, tmpOut, libName, configs, sources)) { hasChildrenWithSources = true; } } @@ -1691,8 +1684,7 @@ bool cmLocalVisualStudio7Generator::WriteGroup( target->GetType() == cmStateEnums::GLOBAL_TARGET || target->GetType() == cmStateEnums::INTERFACE_LIBRARY) { // Look up the source kind and configs. - std::map<cmSourceFile const*, size_t>::const_iterator map_it = - sources.Index.find(sf); + auto map_it = sources.Index.find(sf); // The map entry must exist because we populated it earlier. assert(map_it != sources.Index.end()); cmGeneratorTarget::AllConfigSource const& acs = @@ -1943,7 +1935,7 @@ void cmLocalVisualStudio7Generator::OutputTargetRules( } std::unique_ptr<cmCustomCommand> pcc( this->MaybeCreateImplibDir(target, configName, this->FortranProject)); - if (pcc.get()) { + if (pcc) { event.Write(*pcc); } event.Finish(); @@ -1986,7 +1978,7 @@ void cmLocalVisualStudio7Generator::WriteProjectStartFortran( cmGlobalVisualStudio7Generator* gg = static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator); /* clang-format off */ - fout << "<?xml version=\"1.0\" encoding = \"" + fout << R"(<?xml version="1.0" encoding = ")" << gg->Encoding() << "\"?>\n" << "<VisualStudioProject\n" << "\tProjectCreator=\"Intel Fortran\"\n" @@ -1994,7 +1986,7 @@ void cmLocalVisualStudio7Generator::WriteProjectStartFortran( /* clang-format on */ cmValue p = target->GetProperty("VS_KEYWORD"); const char* keyword = p ? p->c_str() : "Console Application"; - const char* projectType = 0; + const char* projectType = nullptr; switch (target->GetType()) { case cmStateEnums::OBJECT_LIBRARY: case cmStateEnums::STATIC_LIBRARY: @@ -2014,7 +2006,7 @@ void cmLocalVisualStudio7Generator::WriteProjectStartFortran( if (!keyword) { keyword = "Console Application"; } - projectType = 0; + projectType = nullptr; break; case cmStateEnums::UTILITY: case cmStateEnums::GLOBAL_TARGET: @@ -2048,7 +2040,7 @@ void cmLocalVisualStudio7Generator::WriteProjectStart( static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator); /* clang-format off */ - fout << "<?xml version=\"1.0\" encoding = \"" + fout << R"(<?xml version="1.0" encoding = ")" << gg->Encoding() << "\"?>\n" << "<VisualStudioProject\n" << "\tProjectType=\"Visual C++\"\n"; @@ -2166,8 +2158,8 @@ void cmVS7GeneratorOptions::OutputFlag(std::ostream& fout, int indent, class cmVS7XMLParser : public cmXMLParser { public: - virtual void EndElement(const std::string& /* name */) {} - virtual void StartElement(const std::string& name, const char** atts) + void EndElement(const std::string& /* name */) override {} + void StartElement(const std::string& name, const char** atts) override { // once the GUID is found do nothing if (!this->GUID.empty()) { @@ -2192,7 +2184,7 @@ public: } } } - int InitializeParser() + int InitializeParser() override { int ret = cmXMLParser::InitializeParser(); if (ret == 0) { @@ -2235,7 +2227,7 @@ static bool cmLVS7G_IsFAT(const char* dir) volRoot[0] = dir[0]; char fsName[16]; if (GetVolumeInformationA(volRoot, 0, 0, 0, 0, 0, fsName, 16) && - strstr(fsName, "FAT") != 0) { + strstr(fsName, "FAT") != nullptr) { return true; } } diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index d95ebc2..ce1156f 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -48,7 +48,7 @@ public: //! Set cache only and recurse to false by default. cmLocalVisualStudio7Generator(cmGlobalGenerator* gg, cmMakefile* mf); - virtual ~cmLocalVisualStudio7Generator(); + ~cmLocalVisualStudio7Generator() override; cmLocalVisualStudio7Generator(const cmLocalVisualStudio7Generator&) = delete; const cmLocalVisualStudio7Generator& operator=( @@ -97,7 +97,7 @@ protected: private: using Options = cmVS7GeneratorOptions; using FCInfo = cmLocalVisualStudio7GeneratorFCInfo; - std::string GetBuildTypeLinkerFlags(std::string rootLinkerFlags, + std::string GetBuildTypeLinkerFlags(std::string const& rootLinkerFlags, const std::string& configName); void FixGlobalTargets(); void WriteVCProjHeader(std::ostream& fout, const std::string& libName, diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index 2703c7b..58d46f1 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -4,6 +4,8 @@ #include <utility> +#include <cm/memory> + #include "windows.h" #include "cmCustomCommand.h" @@ -24,9 +26,7 @@ cmLocalVisualStudioGenerator::cmLocalVisualStudioGenerator( { } -cmLocalVisualStudioGenerator::~cmLocalVisualStudioGenerator() -{ -} +cmLocalVisualStudioGenerator::~cmLocalVisualStudioGenerator() = default; cmGlobalVisualStudioGenerator::VSVersion cmLocalVisualStudioGenerator::GetVersion() const @@ -107,7 +107,7 @@ cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmGeneratorTarget* target, // Add a pre-build event to create the directory. cmCustomCommandLines commands = cmMakeSingleCommandLine( { cmSystemTools::GetCMakeCommand(), "-E", "make_directory", impDir }); - pcc.reset(new cmCustomCommand()); + pcc = cm::make_unique<cmCustomCommand>(); pcc->SetCommandLines(commands); pcc->SetStdPipesUTF8(true); pcc->SetEscapeOldStyle(false); diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h index cf4f4d9..8fed1bd 100644 --- a/Source/cmLocalVisualStudioGenerator.h +++ b/Source/cmLocalVisualStudioGenerator.h @@ -29,7 +29,7 @@ class cmLocalVisualStudioGenerator : public cmLocalGenerator { public: cmLocalVisualStudioGenerator(cmGlobalGenerator* gg, cmMakefile* mf); - virtual ~cmLocalVisualStudioGenerator(); + ~cmLocalVisualStudioGenerator() override; std::string ConstructScript(cmCustomCommandGenerator const& ccg, const std::string& newline = "\n"); @@ -47,7 +47,7 @@ public: void ComputeObjectFilenames( std::map<cmSourceFile const*, std::string>& mapping, - cmGeneratorTarget const* = 0) override; + cmGeneratorTarget const* = nullptr) override; protected: virtual const char* ReportErrorLabel() const; diff --git a/Source/cmVSSetupHelper.cxx b/Source/cmVSSetupHelper.cxx index 8764f21..6702b7b 100644 --- a/Source/cmVSSetupHelper.cxx +++ b/Source/cmVSSetupHelper.cxx @@ -87,12 +87,11 @@ std::string VSInstanceInfo::GetInstallLocation() const cmVSSetupAPIHelper::cmVSSetupAPIHelper(unsigned int version) : Version(version) - , setupConfig(NULL) - , setupConfig2(NULL) - , setupHelper(NULL) - , initializationFailure(false) + , setupConfig(nullptr) + , setupConfig2(nullptr) + , setupHelper(nullptr) { - comInitialized = CoInitializeEx(NULL, 0); + comInitialized = CoInitializeEx(nullptr, 0); if (SUCCEEDED(comInitialized)) { Initialize(); } else { @@ -102,11 +101,12 @@ cmVSSetupAPIHelper::cmVSSetupAPIHelper(unsigned int version) cmVSSetupAPIHelper::~cmVSSetupAPIHelper() { - setupHelper = NULL; - setupConfig2 = NULL; - setupConfig = NULL; - if (SUCCEEDED(comInitialized)) + setupHelper = nullptr; + setupConfig2 = nullptr; + setupConfig = nullptr; + if (SUCCEEDED(comInitialized)) { CoUninitialize(); + } } bool cmVSSetupAPIHelper::SetVSInstance(std::string const& vsInstallLocation, @@ -159,12 +159,12 @@ bool cmVSSetupAPIHelper::CheckInstalledComponent( // the // component name ex: Microsoft.VisualStudio.Component.Windows10SDK.10240 if (id.find(Win10SDKComponent) != std::wstring::npos && - type.compare(ComponentType) == 0) { + type == ComponentType) { bWin10SDK = true; ret = true; } - if (id.compare(Win81SDKComponent) == 0 && type.compare(ComponentType) == 0) { + if (id == Win81SDKComponent && type == ComponentType) { bWin81SDK = true; ret = true; } @@ -177,8 +177,9 @@ bool cmVSSetupAPIHelper::CheckInstalledComponent( bool cmVSSetupAPIHelper::GetVSInstanceInfo( SmartCOMPtr<ISetupInstance2> pInstance, VSInstanceInfo& vsInstanceInfo) { - if (pInstance == NULL) + if (pInstance == nullptr) { return false; + } InstanceState state; if (FAILED(pInstance->GetState(&state))) { @@ -188,21 +189,19 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo( SmartBSTR bstrVersion; if (FAILED(pInstance->GetInstallationVersion(&bstrVersion))) { return false; - } else { - vsInstanceInfo.Version = - cmsys::Encoding::ToNarrow(std::wstring(bstrVersion)); } + vsInstanceInfo.Version = + cmsys::Encoding::ToNarrow(std::wstring(bstrVersion)); // Reboot may have been required before the installation path was created. SmartBSTR bstrInstallationPath; if ((eLocal & state) == eLocal) { if (FAILED(pInstance->GetInstallationPath(&bstrInstallationPath))) { return false; - } else { - vsInstanceInfo.VSInstallLocation = - cmsys::Encoding::ToNarrow(std::wstring(bstrInstallationPath)); - cmSystemTools::ConvertToUnixSlashes(vsInstanceInfo.VSInstallLocation); } + vsInstanceInfo.VSInstallLocation = + cmsys::Encoding::ToNarrow(std::wstring(bstrInstallationPath)); + cmSystemTools::ConvertToUnixSlashes(vsInstanceInfo.VSInstallLocation); } // Check if a compiler is installed with this instance. @@ -220,7 +219,7 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo( LPSAFEARRAY lpsaPackages; if (FAILED(pInstance->GetPackages(&lpsaPackages)) || - lpsaPackages == NULL) { + lpsaPackages == nullptr) { return false; } @@ -229,11 +228,12 @@ bool cmVSSetupAPIHelper::GetVSInstanceInfo( IUnknown** ppData = (IUnknown**)lpsaPackages->pvData; for (int i = lower; i < upper; i++) { - SmartCOMPtr<ISetupPackageReference> package = NULL; + SmartCOMPtr<ISetupPackageReference> package = nullptr; if (FAILED(ppData[i]->QueryInterface(IID_ISetupPackageReference, (void**)&package)) || - package == NULL) + package == nullptr) { continue; + } bool win10SDKInstalled = false; bool win81SDkInstalled = false; @@ -289,7 +289,8 @@ bool cmVSSetupAPIHelper::GetVCToolsetVersion(std::string& vsToolsetVersion) bool cmVSSetupAPIHelper::IsEWDKEnabled() { - std::string envEnterpriseWDK, envDisableRegistryUse; + std::string envEnterpriseWDK; + std::string envDisableRegistryUse; cmSystemTools::GetEnv("EnterpriseWDK", envEnterpriseWDK); cmSystemTools::GetEnv("DisableRegistryUse", envDisableRegistryUse); if (!cmSystemTools::Strucmp(envEnterpriseWDK.c_str(), "True") && @@ -370,11 +371,12 @@ bool cmVSSetupAPIHelper::EnumerateVSInstancesWithVswhere( bool cmVSSetupAPIHelper::EnumerateVSInstancesWithCOM( std::vector<VSInstanceInfo>& VSInstances) { - if (initializationFailure || setupConfig == NULL || setupConfig2 == NULL || - setupHelper == NULL) + if (initializationFailure || setupConfig == nullptr || + setupConfig2 == nullptr || setupHelper == nullptr) { return false; + } - SmartCOMPtr<IEnumSetupInstances> enumInstances = NULL; + SmartCOMPtr<IEnumSetupInstances> enumInstances = nullptr; if (FAILED( setupConfig2->EnumInstances((IEnumSetupInstances**)&enumInstances)) || !enumInstances) { @@ -382,20 +384,21 @@ bool cmVSSetupAPIHelper::EnumerateVSInstancesWithCOM( } SmartCOMPtr<ISetupInstance> instance; - while (SUCCEEDED(enumInstances->Next(1, &instance, NULL)) && instance) { - SmartCOMPtr<ISetupInstance2> instance2 = NULL; + while (SUCCEEDED(enumInstances->Next(1, &instance, nullptr)) && instance) { + SmartCOMPtr<ISetupInstance2> instance2 = nullptr; if (FAILED( instance->QueryInterface(IID_ISetupInstance2, (void**)&instance2)) || !instance2) { - instance = NULL; + instance = nullptr; continue; } VSInstanceInfo instanceInfo; bool isInstalled = GetVSInstanceInfo(instance2, instanceInfo); - instance = instance2 = NULL; - if (isInstalled) + instance = instance2 = nullptr; + if (isInstalled) { VSInstances.push_back(instanceInfo); + } } return true; } @@ -403,18 +406,21 @@ bool cmVSSetupAPIHelper::EnumerateVSInstancesWithCOM( bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance() { bool isVSInstanceExists = false; - if (chosenInstanceInfo.VSInstallLocation.compare("") != 0) { + if (!chosenInstanceInfo.VSInstallLocation.empty()) { return true; } if (this->IsEWDKEnabled()) { - std::string envWindowsSdkDir81, envVSVersion, envVsInstallDir; + std::string envWindowsSdkDir81; + std::string envVSVersion; + std::string envVsInstallDir; cmSystemTools::GetEnv("WindowsSdkDir_81", envWindowsSdkDir81); cmSystemTools::GetEnv("VisualStudioVersion", envVSVersion); cmSystemTools::GetEnv("VSINSTALLDIR", envVsInstallDir); - if (envVSVersion.empty() || envVsInstallDir.empty()) + if (envVSVersion.empty() || envVsInstallDir.empty()) { return false; + } chosenInstanceInfo.VSInstallLocation = envVsInstallDir; chosenInstanceInfo.Version = envVSVersion; @@ -499,7 +505,7 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance() return this->LoadSpecifiedVSInstanceFromDisk(); } - if (vecVSInstances.size() > 0) { + if (!vecVSInstances.empty()) { isVSInstanceExists = true; int index = ChooseVSInstance(vecVSInstances); chosenInstanceInfo = vecVSInstances[index]; @@ -511,11 +517,13 @@ bool cmVSSetupAPIHelper::EnumerateAndChooseVSInstance() int cmVSSetupAPIHelper::ChooseVSInstance( const std::vector<VSInstanceInfo>& vecVSInstances) { - if (vecVSInstances.size() == 0) + if (vecVSInstances.empty()) { return -1; + } - if (vecVSInstances.size() == 1) + if (vecVSInstances.size() == 1) { return 0; + } unsigned int chosenIndex = 0; for (unsigned int i = 1; i < vecVSInstances.size(); i++) { @@ -589,32 +597,33 @@ bool cmVSSetupAPIHelper::LoadSpecifiedVSInstanceFromDisk() bool cmVSSetupAPIHelper::Initialize() { - if (initializationFailure) + if (initializationFailure) { return false; + } if (FAILED(comInitialized)) { initializationFailure = true; return false; } - if (FAILED(setupConfig.CoCreateInstance(CLSID_SetupConfiguration, NULL, + if (FAILED(setupConfig.CoCreateInstance(CLSID_SetupConfiguration, nullptr, IID_ISetupConfiguration, CLSCTX_INPROC_SERVER)) || - setupConfig == NULL) { + setupConfig == nullptr) { initializationFailure = true; return false; } if (FAILED(setupConfig.QueryInterface(IID_ISetupConfiguration2, (void**)&setupConfig2)) || - setupConfig2 == NULL) { + setupConfig2 == nullptr) { initializationFailure = true; return false; } if (FAILED( setupConfig.QueryInterface(IID_ISetupHelper, (void**)&setupHelper)) || - setupHelper == NULL) { + setupHelper == nullptr) { initializationFailure = true; return false; } diff --git a/Source/cmVSSetupHelper.h b/Source/cmVSSetupHelper.h index a16f00b..b8be9b9 100644 --- a/Source/cmVSSetupHelper.h +++ b/Source/cmVSSetupHelper.h @@ -17,18 +17,20 @@ template <class T> class SmartCOMPtr { public: - SmartCOMPtr() { ptr = NULL; } + SmartCOMPtr() = default; SmartCOMPtr(T* p) { ptr = p; - if (ptr != NULL) + if (ptr != nullptr) { ptr->AddRef(); + } } SmartCOMPtr(const SmartCOMPtr<T>& sptr) { ptr = sptr.ptr; - if (ptr != NULL) + if (ptr != nullptr) { ptr->AddRef(); + } } T** operator&() { return &ptr; } T* operator->() { return ptr; } @@ -36,8 +38,9 @@ public: { if (*this != p) { ptr = p; - if (ptr != NULL) + if (ptr != nullptr) { ptr->AddRef(); + } } return *this; } @@ -45,11 +48,10 @@ public: template <class I> HRESULT QueryInterface(REFCLSID rclsid, I** pp) { - if (pp != NULL) { + if (pp != nullptr) { return ptr->QueryInterface(rclsid, (void**)pp); - } else { - return E_FAIL; } + return E_FAIL; } HRESULT CoCreateInstance(REFCLSID clsid, IUnknown* pUnknown, REFIID interfaceId, DWORD dwClsContext = CLSCTX_ALL) @@ -60,18 +62,19 @@ public: } ~SmartCOMPtr() { - if (ptr != NULL) + if (ptr != nullptr) { ptr->Release(); + } } private: - T* ptr; + T* ptr = nullptr; }; class SmartBSTR { public: - SmartBSTR() { str = NULL; } + SmartBSTR() = default; SmartBSTR(const SmartBSTR& src) = delete; SmartBSTR& operator=(const SmartBSTR& src) = delete; operator BSTR() const { return str; } @@ -79,7 +82,7 @@ public: ~SmartBSTR() throw() { ::SysFreeString(str); } private: - BSTR str; + BSTR str = nullptr; }; struct VSInstanceInfo @@ -129,7 +132,7 @@ private: SmartCOMPtr<ISetupConfiguration2> setupConfig2; SmartCOMPtr<ISetupHelper> setupHelper; // used to indicate failure in Initialize(), so we don't have to call again - bool initializationFailure; + bool initializationFailure = false; // indicated if COM initialization is successful HRESULT comInitialized; // current best instance of VS selected diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index cd73551..e06dc9b 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -80,10 +80,10 @@ struct cmVisualStudio10TargetGenerator::Elem bool HasContent = false; std::string Tag; - Elem(std::ostream& s, const std::string& tag) + Elem(std::ostream& s, std::string tag) : S(s) , Indent(0) - , Tag(tag) + , Tag(std::move(tag)) { this->StartElement(); } @@ -200,7 +200,7 @@ struct cmVisualStudio10TargetGenerator::OptionsHelper } }; -static std::string cmVS10EscapeComment(std::string comment) +static std::string cmVS10EscapeComment(std::string const& comment) { // MSBuild takes the CDATA of a <Message></Message> element and just // does "echo $CDATA" with no escapes. We must encode the string. @@ -275,8 +275,8 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( this->Makefile->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig); this->NsightTegra = gg->IsNsightTegra(); this->Android = gg->TargetsAndroid(); - for (int i = 0; i < 4; ++i) { - this->NsightTegraVersion[i] = 0; + for (unsigned int& version : this->NsightTegraVersion) { + version = 0; } sscanf(gg->GetNsightTegraVersion().c_str(), "%u.%u.%u.%u", &this->NsightTegraVersion[0], &this->NsightTegraVersion[1], @@ -293,9 +293,7 @@ cmVisualStudio10TargetGenerator::cmVisualStudio10TargetGenerator( this->ClassifyAllConfigSources(); } -cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator() -{ -} +cmVisualStudio10TargetGenerator::~cmVisualStudio10TargetGenerator() = default; std::string cmVisualStudio10TargetGenerator::CalcCondition( const std::string& config) const @@ -426,7 +424,7 @@ void cmVisualStudio10TargetGenerator::Generate() cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), '/', this->Name, ProjectFileExtension); cmGeneratedFileStream BuildFileStream(path); - const std::string PathToProjectFile = path; + const std::string& PathToProjectFile = path; BuildFileStream.SetCopyIfDifferent(true); // Write the encoding header into the file @@ -456,7 +454,7 @@ void cmVisualStudio10TargetGenerator::Generate() void cmVisualStudio10TargetGenerator::WriteClassicMsBuildProjectFile( cmGeneratedFileStream& BuildFileStream) { - BuildFileStream << "<?xml version=\"1.0\" encoding=\"" + BuildFileStream << R"(<?xml version="1.0" encoding=")" << this->GlobalGenerator->Encoding() << "\"?>"; { Elem e0(BuildFileStream, "Project"); @@ -728,7 +726,7 @@ void cmVisualStudio10TargetGenerator::WriteClassicMsBuildProjectFile( : customDir + this->GlobalGenerator ->GetPlatformToolsetCudaVSIntegrationSubdirString() + - "extras\\visual_studio_integration\\MSBuildExtensions\\"; + R"(extras\visual_studio_integration\MSBuildExtensions\)"; Elem(e1, "Import") .Attribute("Project", std::move(cudaPath) + "CUDA " + @@ -831,7 +829,7 @@ void cmVisualStudio10TargetGenerator::WriteClassicMsBuildProjectFile( : customDir + this->GlobalGenerator ->GetPlatformToolsetCudaVSIntegrationSubdirString() + - "extras\\visual_studio_integration\\MSBuildExtensions\\"; + R"(extras\visual_studio_integration\MSBuildExtensions\)"; Elem(e1, "Import") .Attribute("Project", std::move(cudaPath) + "CUDA " + @@ -1033,8 +1031,9 @@ void cmVisualStudio10TargetGenerator::WriteCommonPropertyGroupGlobals(Elem& e1) std::vector<std::string> keys = this->GeneratorTarget->GetPropertyKeys(); for (std::string const& keyIt : keys) { static const cm::string_view prefix = "VS_GLOBAL_"; - if (!cmHasPrefix(keyIt, prefix)) + if (!cmHasPrefix(keyIt, prefix)) { continue; + } cm::string_view globalKey = cm::string_view(keyIt).substr(prefix.length()); // Skip invalid or separately-handled properties. if (globalKey.empty() || globalKey == "PROJECT_TYPES" || @@ -1042,8 +1041,9 @@ void cmVisualStudio10TargetGenerator::WriteCommonPropertyGroupGlobals(Elem& e1) continue; } cmValue value = this->GeneratorTarget->GetProperty(keyIt); - if (!value) + if (!value) { continue; + } e1.Element(globalKey, *value); } } @@ -1056,14 +1056,11 @@ bool cmVisualStudio10TargetGenerator::HasCustomCommands() const return true; } - for (cmGeneratorTarget::AllConfigSource const& si : - this->GeneratorTarget->GetAllConfigSources()) { - if (si.Source->GetCustomCommand()) { - return true; - } - } - - return false; + auto const& config_sources = this->GeneratorTarget->GetAllConfigSources(); + return std::any_of(config_sources.begin(), config_sources.end(), + [](cmGeneratorTarget::AllConfigSource const& si) { + return si.Source->GetCustomCommand(); + }); } void cmVisualStudio10TargetGenerator::WritePackageReferences(Elem& e0) @@ -1233,7 +1230,7 @@ void cmVisualStudio10TargetGenerator::WriteEmbeddedResourceGroup(Elem& e0) e2.Attribute("Include", obj); if (this->ProjectType != VsProjectType::csproj) { - std::string hFileName = obj.substr(0, obj.find_last_of(".")) + ".h"; + std::string hFileName = obj.substr(0, obj.find_last_of('.')) + ".h"; e2.Element("DependentUpon", hFileName); for (std::string const& c : this->Configurations) { @@ -1925,7 +1922,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups() char magic[] = { char(0xEF), char(0xBB), char(0xBF) }; fout.write(magic, 3); - fout << "<?xml version=\"1.0\" encoding=\"" + fout << R"(<?xml version="1.0" encoding=")" << this->GlobalGenerator->Encoding() << "\"?>"; { Elem e0(fout, "Project"); @@ -2081,7 +2078,7 @@ void cmVisualStudio10TargetGenerator::WriteHeaderSource( e2.Element("FileType", "CppForm"); } else if (this->IsXamlHeader(fileName)) { e2.Element("DependentUpon", - fileName.substr(0, fileName.find_last_of("."))); + fileName.substr(0, fileName.find_last_of('.'))); } this->FinishWritingSource(e2, toolSettings); } @@ -2117,7 +2114,7 @@ void cmVisualStudio10TargetGenerator::ParseSettingsProperty( bool cmVisualStudio10TargetGenerator::PropertyIsSameInAllConfigs( const ConfigToSettings& toolSettings, const std::string& propName) { - std::string firstPropValue = ""; + std::string firstPropValue; for (const auto& configToSettings : toolSettings) { const std::unordered_map<std::string, std::string>& settings = configToSettings.second; @@ -2338,19 +2335,16 @@ void cmVisualStudio10TargetGenerator::WriteExtraSource( if (!deployLocation.empty()) { e2.Element("Link", deployLocation + "\\%(FileName)%(Extension)"); } - for (size_t i = 0; i != this->Configurations.size(); ++i) { - if (cge->Evaluate(this->LocalGenerator, this->Configurations[i]) == - "1") { + for (auto& config : this->Configurations) { + if (cge->Evaluate(this->LocalGenerator, config) == "1") { e2.WritePlatformConfigTag("DeploymentContent", "'$(Configuration)|$(Platform)'=='" + - this->Configurations[i] + "|" + - this->Platform + "'", + config + "|" + this->Platform + "'", "true"); } else { e2.WritePlatformConfigTag("ExcludedFromBuild", "'$(Configuration)|$(Platform)'=='" + - this->Configurations[i] + "|" + - this->Platform + "'", + config + "|" + this->Platform + "'", "true"); } } @@ -2401,8 +2395,9 @@ void cmVisualStudio10TargetGenerator::WriteSource(Elem& e2, // added with the plain filename without any path. This means the file will // show up at root-level of the csproj (where CMakeLists.txt etc. are). std::string link = this->GetCSharpSourceLink(sf); - if (link.empty()) + if (link.empty()) { link = cmsys::SystemTools::GetFilenameName(sf->GetFullPath()); + } e2.Element("Link", link); } @@ -2535,7 +2530,7 @@ void cmVisualStudio10TargetGenerator::WriteAllSources(Elem& e0) Elem e2(e1, tool); bool isCSharp = (si.Source->GetLanguage() == "CSharp"); - if (isCSharp && exclude_configs.size() > 0) { + if (isCSharp && !exclude_configs.empty()) { std::stringstream conditions; bool firstConditionSet{ false }; for (const auto& ci : include_configs) { @@ -2677,7 +2672,7 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( ? "C" : this->GlobalGenerator->GetLanguageFromExtension(ext.c_str()); std::string lang = this->LocalGenerator->GetSourceFileLanguage(sf); - const char* compileAs = 0; + const char* compileAs = nullptr; if (lang != extLang) { if (lang == "CXX") { // force a C++ file type @@ -2861,10 +2856,9 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( if (this->IsXamlSource(source->GetFullPath())) { const std::string& fileName = source->GetFullPath(); e2.Element("DependentUpon", - fileName.substr(0, fileName.find_last_of("."))); + fileName.substr(0, fileName.find_last_of('.'))); } if (this->ProjectType == VsProjectType::csproj) { - std::string f = source->GetFullPath(); using CsPropMap = std::map<std::string, std::string>; CsPropMap sourceFileTags; this->GetCSharpSourceProperties(&sf, sourceFileTags); @@ -2905,7 +2899,7 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions( if (ttype >= cmStateEnums::UTILITY) { e1.WritePlatformConfigTag( - "IntDir", cond, "$(Platform)\\$(Configuration)\\$(ProjectName)\\"); + "IntDir", cond, R"($(Platform)\$(Configuration)\$(ProjectName)\)"); } else { std::string intermediateDir = cmStrCat( this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), '/', @@ -3072,12 +3066,9 @@ std::vector<std::string> cmVisualStudio10TargetGenerator::GetIncludes( bool cmVisualStudio10TargetGenerator::ComputeClOptions() { - for (std::string const& c : this->Configurations) { - if (!this->ComputeClOptions(c)) { - return false; - } - } - return true; + return std::all_of( + this->Configurations.begin(), this->Configurations.end(), + [this](std::string const& c) { return this->ComputeClOptions(c); }); } bool cmVisualStudio10TargetGenerator::ComputeClOptions( @@ -3435,7 +3426,7 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( // add AdditionalUsingDirectories if (this->AdditionalUsingDirectories.count(configName) > 0) { std::string dirs; - for (auto u : this->AdditionalUsingDirectories[configName]) { + for (auto const& u : this->AdditionalUsingDirectories[configName]) { if (!dirs.empty()) { dirs.append(";"); } @@ -3448,12 +3439,9 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( bool cmVisualStudio10TargetGenerator::ComputeRcOptions() { - for (std::string const& c : this->Configurations) { - if (!this->ComputeRcOptions(c)) { - return false; - } - } - return true; + return std::all_of( + this->Configurations.begin(), this->Configurations.end(), + [this](std::string const& c) { return this->ComputeRcOptions(c); }); } bool cmVisualStudio10TargetGenerator::ComputeRcOptions( @@ -3502,13 +3490,12 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions() if (!this->GlobalGenerator->IsCudaEnabled()) { return true; } - for (std::string const& c : this->Configurations) { - if (this->GeneratorTarget->IsLanguageUsed("CUDA", c) && - !this->ComputeCudaOptions(c)) { - return false; - } - } - return true; + return std::all_of(this->Configurations.begin(), this->Configurations.end(), + [this](std::string const& c) { + return !this->GeneratorTarget->IsLanguageUsed("CUDA", + c) || + this->ComputeCudaOptions(c); + }); } bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( @@ -3594,7 +3581,7 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions( // limitation by creating the directory and passing the flag ourselves. pdb = this->ConvertPath(pdb, true); ConvertToWindowsSlash(pdb); - std::string const clFd = "-Xcompiler=\"-Fd\\\"" + pdb + "\\\"\""; + std::string const clFd = R"(-Xcompiler="-Fd\")" + pdb + R"(\"")"; cudaOptions.AppendFlagString("AdditionalOptions", clFd); } } @@ -3678,12 +3665,9 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions() if (!this->GlobalGenerator->IsCudaEnabled()) { return true; } - for (std::string const& c : this->Configurations) { - if (!this->ComputeCudaLinkOptions(c)) { - return false; - } - } - return true; + return std::all_of( + this->Configurations.begin(), this->Configurations.end(), + [this](std::string const& c) { return this->ComputeCudaLinkOptions(c); }); } bool cmVisualStudio10TargetGenerator::ComputeCudaLinkOptions( @@ -3777,12 +3761,9 @@ bool cmVisualStudio10TargetGenerator::ComputeMarmasmOptions() if (!this->GlobalGenerator->IsMarmasmEnabled()) { return true; } - for (std::string const& c : this->Configurations) { - if (!this->ComputeMarmasmOptions(c)) { - return false; - } - } - return true; + return std::all_of( + this->Configurations.begin(), this->Configurations.end(), + [this](std::string const& c) { return this->ComputeMarmasmOptions(c); }); } bool cmVisualStudio10TargetGenerator::ComputeMarmasmOptions( @@ -3830,12 +3811,9 @@ bool cmVisualStudio10TargetGenerator::ComputeMasmOptions() if (!this->GlobalGenerator->IsMasmEnabled()) { return true; } - for (std::string const& c : this->Configurations) { - if (!this->ComputeMasmOptions(c)) { - return false; - } - } - return true; + return std::all_of( + this->Configurations.begin(), this->Configurations.end(), + [this](std::string const& c) { return this->ComputeMasmOptions(c); }); } bool cmVisualStudio10TargetGenerator::ComputeMasmOptions( @@ -3883,12 +3861,9 @@ bool cmVisualStudio10TargetGenerator::ComputeNasmOptions() if (!this->GlobalGenerator->IsNasmEnabled()) { return true; } - for (std::string const& c : this->Configurations) { - if (!this->ComputeNasmOptions(c)) { - return false; - } - } - return true; + return std::all_of( + this->Configurations.begin(), this->Configurations.end(), + [this](std::string const& c) { return this->ComputeNasmOptions(c); }); } bool cmVisualStudio10TargetGenerator::ComputeNasmOptions( diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 60e9736..166cdf7 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -203,7 +203,6 @@ private: void WriteStdOutEncodingUtf8(Elem& e1); void UpdateCache(); -private: friend class cmVS10GeneratorOptions; using Options = cmVS10GeneratorOptions; using OptionsMap = std::map<std::string, std::unique_ptr<Options>>; diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx index e6f5ece..6e98874 100644 --- a/Source/cmVisualStudioGeneratorOptions.cxx +++ b/Source/cmVisualStudioGeneratorOptions.cxx @@ -51,9 +51,9 @@ cmVisualStudioGeneratorOptions::cmVisualStudioGeneratorOptions( void cmVisualStudioGeneratorOptions::AddTable(cmVS7FlagTable const* table) { if (table) { - for (int i = 0; i < FlagTableCount; ++i) { - if (!this->FlagTable[i]) { - this->FlagTable[i] = table; + for (auto& flag : this->FlagTable) { + if (!flag) { + flag = table; break; } } @@ -62,8 +62,8 @@ void cmVisualStudioGeneratorOptions::AddTable(cmVS7FlagTable const* table) void cmVisualStudioGeneratorOptions::ClearTables() { - for (int i = 0; i < FlagTableCount; ++i) { - this->FlagTable[i] = nullptr; + for (auto& flag : this->FlagTable) { + flag = nullptr; } } @@ -115,8 +115,7 @@ bool cmVisualStudioGeneratorOptions::IsDebug() const if (this->CurrentTool != CSharpCompiler) { return this->FlagMap.find("DebugInformationFormat") != this->FlagMap.end(); } - std::map<std::string, FlagValue>::const_iterator i = - this->FlagMap.find("DebugType"); + auto i = this->FlagMap.find("DebugType"); if (i != this->FlagMap.end()) { if (i->second.size() == 1) { return i->second[0] != "none"; @@ -138,22 +137,14 @@ bool cmVisualStudioGeneratorOptions::IsManaged() const bool cmVisualStudioGeneratorOptions::UsingUnicode() const { // Look for a _UNICODE definition. - for (std::string const& di : this->Defines) { - if (di == "_UNICODE") { - return true; - } - } - return false; + return std::any_of(this->Defines.begin(), this->Defines.end(), + [](std::string const& di) { return di == "_UNICODE"; }); } bool cmVisualStudioGeneratorOptions::UsingSBCS() const { // Look for a _SBCS definition. - for (std::string const& di : this->Defines) { - if (di == "_SBCS") { - return true; - } - } - return false; + return std::any_of(this->Defines.begin(), this->Defines.end(), + [](std::string const& di) { return di == "_SBCS"; }); } void cmVisualStudioGeneratorOptions::FixCudaCodeGeneration() @@ -267,8 +258,7 @@ void cmVisualStudioGeneratorOptions::ParseFinish() } if (this->CurrentTool == CudaCompiler) { - std::map<std::string, FlagValue>::iterator i = - this->FlagMap.find("CudaRuntime"); + auto i = this->FlagMap.find("CudaRuntime"); if (i != this->FlagMap.end() && i->second.size() == 1) { std::string& cudaRuntime = i->second[0]; if (cudaRuntime == "static") { @@ -285,7 +275,7 @@ void cmVisualStudioGeneratorOptions::ParseFinish() void cmVisualStudioGeneratorOptions::PrependInheritedString( std::string const& key) { - std::map<std::string, FlagValue>::iterator i = this->FlagMap.find(key); + auto i = this->FlagMap.find(key); if (i == this->FlagMap.end() || i->second.size() != 1) { return; } @@ -295,7 +285,7 @@ void cmVisualStudioGeneratorOptions::PrependInheritedString( void cmVisualStudioGeneratorOptions::Reparse(std::string const& key) { - std::map<std::string, FlagValue>::iterator i = this->FlagMap.find(key); + auto i = this->FlagMap.find(key); if (i == this->FlagMap.end() || i->second.size() != 1) { return; } @@ -339,7 +329,7 @@ cmIDEOptions::FlagValue cmVisualStudioGeneratorOptions::TakeFlag( std::string const& key) { FlagValue value; - std::map<std::string, FlagValue>::iterator i = this->FlagMap.find(key); + auto i = this->FlagMap.find(key); if (i != this->FlagMap.end()) { value = i->second; this->FlagMap.erase(i); @@ -373,8 +363,7 @@ void cmVisualStudioGeneratorOptions::OutputPreprocessorDefinitions( if (this->Version != cmGlobalVisualStudioGenerator::VSVersion::VS9) { oss << "%(" << tag << ")"; } - std::vector<std::string>::const_iterator de = - cmRemoveDuplicates(this->Defines); + auto de = cmRemoveDuplicates(this->Defines); for (std::string const& di : cmMakeRange(this->Defines.cbegin(), de)) { // Escape the definition for the compiler. std::string define; diff --git a/Source/cmVisualStudioSlnData.cxx b/Source/cmVisualStudioSlnData.cxx index 2a6dfc4..4b6754e 100644 --- a/Source/cmVisualStudioSlnData.cxx +++ b/Source/cmVisualStudioSlnData.cxx @@ -20,33 +20,34 @@ std::string cmSlnProjectEntry::GetProjectConfiguration( return projectConfigurationMap[solutionConfiguration]; } -const cm::optional<cmSlnProjectEntry> cmSlnData::GetProjectByGUID( +cm::optional<cmSlnProjectEntry> cmSlnData::GetProjectByGUID( const std::string& projectGUID) const { - ProjectStorage::const_iterator it(ProjectsByGUID.find(projectGUID)); - if (it != ProjectsByGUID.end()) + auto it(ProjectsByGUID.find(projectGUID)); + if (it != ProjectsByGUID.end()) { return it->second; - else - return cm::nullopt; + } + return cm::nullopt; } -const cm::optional<cmSlnProjectEntry> cmSlnData::GetProjectByName( +cm::optional<cmSlnProjectEntry> cmSlnData::GetProjectByName( const std::string& projectName) const { - ProjectStringIndex::const_iterator it(ProjectNameIndex.find(projectName)); - if (it != ProjectNameIndex.end()) + auto it(ProjectNameIndex.find(projectName)); + if (it != ProjectNameIndex.end()) { return it->second->second; - else - return cm::nullopt; + } + return cm::nullopt; } std::vector<cmSlnProjectEntry> cmSlnData::GetProjects() const { - ProjectStringIndex::const_iterator it(this->ProjectNameIndex.begin()), - itEnd(this->ProjectNameIndex.end()); + auto it(this->ProjectNameIndex.begin()); + auto itEnd(this->ProjectNameIndex.end()); std::vector<cmSlnProjectEntry> result; - for (; it != itEnd; ++it) + for (; it != itEnd; ++it) { result.push_back(it->second->second); + } return result; } @@ -54,9 +55,10 @@ cmSlnProjectEntry* cmSlnData::AddProject( const std::string& projectGUID, const std::string& projectName, const std::string& projectRelativePath) { - ProjectStorage::iterator it(ProjectsByGUID.find(projectGUID)); - if (it != ProjectsByGUID.end()) - return NULL; + auto it(ProjectsByGUID.find(projectGUID)); + if (it != ProjectsByGUID.end()) { + return nullptr; + } it = ProjectsByGUID .insert(ProjectStorage::value_type( projectGUID, @@ -72,17 +74,20 @@ std::string cmSlnData::GetConfigurationTarget( { std::string solutionTarget = solutionConfiguration + "|" + platformName; cm::optional<cmSlnProjectEntry> project = GetProjectByName(projectName); - if (!project) + if (!project) { return platformName; + } std::string projectTarget = project->GetProjectConfiguration(solutionTarget); - if (projectTarget.empty()) + if (projectTarget.empty()) { return platformName; + } std::vector<std::string> targetElements = cmSystemTools::SplitString(projectTarget, '|'); - if (targetElements.size() != 2) + if (targetElements.size() != 2) { return platformName; + } return targetElements[1]; } diff --git a/Source/cmVisualStudioSlnData.h b/Source/cmVisualStudioSlnData.h index 100dd9b..5f03895 100644 --- a/Source/cmVisualStudioSlnData.h +++ b/Source/cmVisualStudioSlnData.h @@ -13,12 +13,12 @@ class cmSlnProjectEntry { public: - cmSlnProjectEntry() {} - cmSlnProjectEntry(const std::string& guid, const std::string& name, - const std::string& relativePath) - : Guid(guid) - , Name(name) - , RelativePath(relativePath) + cmSlnProjectEntry() = default; + cmSlnProjectEntry(std::string guid, std::string name, + std::string relativePath) + : Guid(std::move(guid)) + , Name(std::move(name)) + , RelativePath(std::move(relativePath)) { } @@ -56,10 +56,10 @@ public: minimumVisualStudioVersion = version; } - const cm::optional<cmSlnProjectEntry> GetProjectByGUID( + cm::optional<cmSlnProjectEntry> GetProjectByGUID( const std::string& projectGUID) const; - const cm::optional<cmSlnProjectEntry> GetProjectByName( + cm::optional<cmSlnProjectEntry> GetProjectByName( const std::string& projectName) const; std::vector<cmSlnProjectEntry> GetProjects() const; diff --git a/Source/cmVisualStudioSlnParser.cxx b/Source/cmVisualStudioSlnParser.cxx index feab895..71c758e 100644 --- a/Source/cmVisualStudioSlnParser.cxx +++ b/Source/cmVisualStudioSlnParser.cxx @@ -80,19 +80,19 @@ bool cmVisualStudioSlnParser::ParsedLine::IsKeyValuePair() const std::string cmVisualStudioSlnParser::ParsedLine::GetArgVerbatim() const { - if (this->Arg.second) + if (this->Arg.second) { return Quote + this->Arg.first + Quote; - else - return this->Arg.first; + } + return this->Arg.first; } const std::string& cmVisualStudioSlnParser::ParsedLine::GetValue( size_t idxValue) const { - if (idxValue < this->Values.size()) + if (idxValue < this->Values.size()) { return this->Values[idxValue].first; - else - return BadString; + } + return BadString; } std::string cmVisualStudioSlnParser::ParsedLine::GetValueVerbatim( @@ -100,12 +100,12 @@ std::string cmVisualStudioSlnParser::ParsedLine::GetValueVerbatim( { if (idxValue < this->Values.size()) { const StringData& data = this->Values[idxValue]; - if (data.second) + if (data.second) { return Quote + data.first + Quote; - else - return data.first; - } else - return BadString; + } + return data.first; + } + return BadString; } class cmVisualStudioSlnParser::State @@ -140,17 +140,17 @@ private: std::stack<FileState> Stack; std::string EndIgnoreTag; DataGroupSet RequestedData; - size_t CurrentLine; + size_t CurrentLine = 0; void IgnoreUntilTag(const std::string& endTag); }; cmVisualStudioSlnParser::State::State(DataGroupSet requestedData) : RequestedData(requestedData) - , CurrentLine(0) { - if (this->RequestedData.test(DataGroupProjectDependenciesBit)) + if (this->RequestedData.test(DataGroupProjectDependenciesBit)) { this->RequestedData.set(DataGroupProjectsBit); + } this->Stack.push(FileStateStart); } @@ -206,7 +206,7 @@ bool cmVisualStudioSlnParser::State::Process( this->Stack.push(FileStateTopLevel); break; case FileStateTopLevel: - if (line.GetTag().compare("Project") == 0) { + if (line.GetTag() == "Project") { if (line.GetValueCount() != 3) { result.SetError(ResultErrorInputStructure, this->GetCurrentLine()); return false; @@ -218,14 +218,15 @@ bool cmVisualStudioSlnParser::State::Process( return false; } this->Stack.push(FileStateProject); - } else + } else { this->IgnoreUntilTag("EndProject"); - } else if (line.GetTag().compare("Global") == 0) { + } + } else if (line.GetTag() == "Global") { this->Stack.push(FileStateGlobal); - } else if (line.GetTag().compare("VisualStudioVersion") == 0) { + } else if (line.GetTag() == "VisualStudioVersion") { output.SetVisualStudioVersion(line.GetValue(0)); - } else if (line.GetTag().compare("MinimumVisualStudioVersion") == 0) { + } else if (line.GetTag() == "MinimumVisualStudioVersion") { output.SetMinimumVisualStudioVersion(line.GetValue(0)); } else { result.SetError(ResultErrorInputStructure, this->GetCurrentLine()); @@ -233,69 +234,75 @@ bool cmVisualStudioSlnParser::State::Process( } break; case FileStateProject: - if (line.GetTag().compare("EndProject") == 0) + if (line.GetTag() == "EndProject") { this->Stack.pop(); - else if (line.GetTag().compare("ProjectSection") == 0) { - if (line.GetArg().compare("ProjectDependencies") == 0 && - line.GetValue(0).compare("postProject") == 0) { - if (this->RequestedData.test(DataGroupProjectDependenciesBit)) + } else if (line.GetTag() == "ProjectSection") { + if (line.GetArg() == "ProjectDependencies" && + line.GetValue(0) == "postProject") { + if (this->RequestedData.test(DataGroupProjectDependenciesBit)) { this->Stack.push(FileStateProjectDependencies); - else + } else { this->IgnoreUntilTag("EndProjectSection"); - } else + } + } else { this->IgnoreUntilTag("EndProjectSection"); + } } else { result.SetError(ResultErrorInputStructure, this->GetCurrentLine()); return false; } break; case FileStateProjectDependencies: - if (line.GetTag().compare("EndProjectSection") == 0) + if (line.GetTag() == "EndProjectSection") { this->Stack.pop(); - else if (line.IsKeyValuePair()) + } else if (line.IsKeyValuePair()) { // implement dependency storing here, once needed ; - else { + } else { result.SetError(ResultErrorInputStructure, this->GetCurrentLine()); return false; } break; case FileStateGlobal: - if (line.GetTag().compare("EndGlobal") == 0) + if (line.GetTag() == "EndGlobal") { this->Stack.pop(); - else if (line.GetTag().compare("GlobalSection") == 0) { - if (line.GetArg().compare("SolutionConfigurationPlatforms") == 0 && - line.GetValue(0).compare("preSolution") == 0) { - if (this->RequestedData.test(DataGroupSolutionConfigurationsBit)) + } else if (line.GetTag() == "GlobalSection") { + if (line.GetArg() == "SolutionConfigurationPlatforms" && + line.GetValue(0) == "preSolution") { + if (this->RequestedData.test(DataGroupSolutionConfigurationsBit)) { this->Stack.push(FileStateSolutionConfigurations); - else + } else { this->IgnoreUntilTag("EndGlobalSection"); - } else if (line.GetArg().compare("ProjectConfigurationPlatforms") == - 0 && - line.GetValue(0).compare("postSolution") == 0) { - if (this->RequestedData.test(DataGroupProjectConfigurationsBit)) + } + } else if (line.GetArg() == "ProjectConfigurationPlatforms" && + line.GetValue(0) == "postSolution") { + if (this->RequestedData.test(DataGroupProjectConfigurationsBit)) { this->Stack.push(FileStateProjectConfigurations); - else + } else { this->IgnoreUntilTag("EndGlobalSection"); - } else if (line.GetArg().compare("NestedProjects") == 0 && - line.GetValue(0).compare("preSolution") == 0) { - if (this->RequestedData.test(DataGroupSolutionFiltersBit)) + } + } else if (line.GetArg() == "NestedProjects" && + line.GetValue(0) == "preSolution") { + if (this->RequestedData.test(DataGroupSolutionFiltersBit)) { this->Stack.push(FileStateSolutionFilters); - else + } else { this->IgnoreUntilTag("EndGlobalSection"); - } else if (this->RequestedData.test(DataGroupGenericGlobalSectionsBit)) + } + } else if (this->RequestedData.test( + DataGroupGenericGlobalSectionsBit)) { this->Stack.push(FileStateGlobalSection); - else + } else { this->IgnoreUntilTag("EndGlobalSection"); + } } else { result.SetError(ResultErrorInputStructure, this->GetCurrentLine()); return false; } break; case FileStateSolutionConfigurations: - if (line.GetTag().compare("EndGlobalSection") == 0) + if (line.GetTag() == "EndGlobalSection") { this->Stack.pop(); - else if (line.IsKeyValuePair()) { + } else if (line.IsKeyValuePair()) { output.AddConfiguration(line.GetValue(0)); } else { result.SetError(ResultErrorInputStructure, this->GetCurrentLine()); @@ -303,9 +310,9 @@ bool cmVisualStudioSlnParser::State::Process( } break; case FileStateProjectConfigurations: - if (line.GetTag().compare("EndGlobalSection") == 0) + if (line.GetTag() == "EndGlobalSection") { this->Stack.pop(); - else if (line.IsKeyValuePair()) { + } else if (line.IsKeyValuePair()) { std::vector<std::string> tagElements = cmSystemTools::SplitString(line.GetTag(), '.'); if (tagElements.size() != 3 && tagElements.size() != 4) { @@ -324,7 +331,7 @@ bool cmVisualStudioSlnParser::State::Process( return false; } - if (activeBuild.compare("ActiveCfg") == 0) { + if (activeBuild == "ActiveCfg") { projectEntry->AddProjectConfiguration(solutionConfiguration, line.GetValue(0)); } @@ -334,23 +341,23 @@ bool cmVisualStudioSlnParser::State::Process( } break; case FileStateSolutionFilters: - if (line.GetTag().compare("EndGlobalSection") == 0) + if (line.GetTag() == "EndGlobalSection") { this->Stack.pop(); - else if (line.IsKeyValuePair()) + } else if (line.IsKeyValuePair()) { // implement filter storing here, once needed ; - else { + } else { result.SetError(ResultErrorInputStructure, this->GetCurrentLine()); return false; } break; case FileStateGlobalSection: - if (line.GetTag().compare("EndGlobalSection") == 0) + if (line.GetTag() == "EndGlobalSection") { this->Stack.pop(); - else if (line.IsKeyValuePair()) + } else if (line.IsKeyValuePair()) { // implement section storing here, once needed ; - else { + } else { result.SetError(ResultErrorInputStructure, this->GetCurrentLine()); return false; } @@ -385,11 +392,7 @@ void cmVisualStudioSlnParser::State::IgnoreUntilTag(const std::string& endTag) this->EndIgnoreTag = endTag; } -cmVisualStudioSlnParser::ResultData::ResultData() - : Result(ResultOK) - , ResultLine(0) -{ -} +cmVisualStudioSlnParser::ResultData::ResultData() = default; void cmVisualStudioSlnParser::ResultData::Clear() { @@ -487,34 +490,41 @@ bool cmVisualStudioSlnParser::ParseImpl(std::istream& input, cmSlnData& output, { std::string line; // Does the .sln start with a Byte Order Mark? - if (!this->ParseBOM(input, line, state)) + if (!this->ParseBOM(input, line, state)) { return false; + } do { line = cmTrimWhitespace(line); - if (line.empty()) + if (line.empty()) { continue; + } ParsedLine parsedLine; switch (state.NextLineFormat()) { case LineMultiValueTag: - if (!this->ParseMultiValueTag(line, parsedLine, state)) + if (!this->ParseMultiValueTag(line, parsedLine, state)) { return false; + } break; case LineSingleValueTag: - if (!this->ParseSingleValueTag(line, parsedLine, state)) + if (!this->ParseSingleValueTag(line, parsedLine, state)) { return false; + } break; case LineKeyValuePair: - if (!this->ParseKeyValuePair(line, parsedLine, state)) + if (!this->ParseKeyValuePair(line, parsedLine, state)) { return false; + } break; case LineVerbatim: parsedLine.CopyVerbatim(line); break; } - if (parsedLine.IsComment()) + if (parsedLine.IsComment()) { continue; - if (!state.Process(parsedLine, output, this->LastResult)) + } + if (!state.Process(parsedLine, output, this->LastResult)) { return false; + } } while (state.ReadLine(input, line)); return state.Finished(this->LastResult); } @@ -533,8 +543,9 @@ bool cmVisualStudioSlnParser::ParseBOM(std::istream& input, std::string& line, this->LastResult.SetError(ResultErrorReadingInput, 1); return false; } - if (!this->LastResult.HadBOM) + if (!this->LastResult.HadBOM) { line = bom + line; // it wasn't a BOM, prepend it to first line + } return true; } @@ -544,9 +555,10 @@ bool cmVisualStudioSlnParser::ParseMultiValueTag(const std::string& line, { size_t idxEqualSign = line.find('='); auto fullTag = cm::string_view(line).substr(0, idxEqualSign); - if (!this->ParseTag(fullTag, parsedLine, state)) + if (!this->ParseTag(fullTag, parsedLine, state)) { return false; - if (idxEqualSign != line.npos) { + } + if (idxEqualSign != std::string::npos) { size_t idxFieldStart = idxEqualSign + 1; if (idxFieldStart < line.size()) { size_t idxParsing = idxFieldStart; @@ -554,24 +566,27 @@ bool cmVisualStudioSlnParser::ParseMultiValueTag(const std::string& line, for (;;) { idxParsing = line.find_first_of(",\"", idxParsing); bool fieldOver = false; - if (idxParsing == line.npos) { + if (idxParsing == std::string::npos) { fieldOver = true; if (inQuotes) { this->LastResult.SetError(ResultErrorInputStructure, state.GetCurrentLine()); return false; } - } else if (line[idxParsing] == ',' && !inQuotes) + } else if (line[idxParsing] == ',' && !inQuotes) { fieldOver = true; - else if (line[idxParsing] == '"') + } else if (line[idxParsing] == '"') { inQuotes = !inQuotes; + } if (fieldOver) { if (!this->ParseValue( line.substr(idxFieldStart, idxParsing - idxFieldStart), - parsedLine)) + parsedLine)) { return false; - if (idxParsing == line.npos) + } + if (idxParsing == std::string::npos) { break; // end of last field + } idxFieldStart = idxParsing + 1; } ++idxParsing; @@ -587,11 +602,13 @@ bool cmVisualStudioSlnParser::ParseSingleValueTag(const std::string& line, { size_t idxEqualSign = line.find('='); auto fullTag = cm::string_view(line).substr(0, idxEqualSign); - if (!this->ParseTag(fullTag, parsedLine, state)) + if (!this->ParseTag(fullTag, parsedLine, state)) { return false; - if (idxEqualSign != line.npos) { - if (!this->ParseValue(line.substr(idxEqualSign + 1), parsedLine)) + } + if (idxEqualSign != std::string::npos) { + if (!this->ParseValue(line.substr(idxEqualSign + 1), parsedLine)) { return false; + } } return true; } @@ -601,7 +618,7 @@ bool cmVisualStudioSlnParser::ParseKeyValuePair(const std::string& line, State& /*state*/) { size_t idxEqualSign = line.find('='); - if (idxEqualSign == line.npos) { + if (idxEqualSign == std::string::npos) { parsedLine.CopyVerbatim(line); return true; } @@ -636,8 +653,9 @@ bool cmVisualStudioSlnParser::ParseTag(cm::string_view fullTag, return false; } parsedLine.SetQuotedArg(arg.substr(1, arg.size() - 2)); - } else + } else { parsedLine.SetArg(arg); + } return true; } @@ -645,11 +663,12 @@ bool cmVisualStudioSlnParser::ParseValue(const std::string& value, ParsedLine& parsedLine) { const std::string& trimmed = cmTrimWhitespace(value); - if (trimmed.empty()) + if (trimmed.empty()) { parsedLine.AddValue(trimmed); - else if (trimmed.front() == '"' && trimmed.back() == '"') + } else if (trimmed.front() == '"' && trimmed.back() == '"') { parsedLine.AddQuotedValue(trimmed.substr(1, trimmed.size() - 2)); - else + } else { parsedLine.AddValue(trimmed); + } return true; } diff --git a/Source/cmVisualStudioSlnParser.h b/Source/cmVisualStudioSlnParser.h index 60be598..0cac140 100644 --- a/Source/cmVisualStudioSlnParser.h +++ b/Source/cmVisualStudioSlnParser.h @@ -73,8 +73,8 @@ protected: struct ResultData { - ParseResult Result; - size_t ResultLine; + ParseResult Result = ResultOK; + size_t ResultLine = 0; bool HadBOM; ResultData(); diff --git a/Source/cmVisualStudioWCEPlatformParser.cxx b/Source/cmVisualStudioWCEPlatformParser.cxx index 2f71cf5..d8d0da9 100644 --- a/Source/cmVisualStudioWCEPlatformParser.cxx +++ b/Source/cmVisualStudioWCEPlatformParser.cxx @@ -16,9 +16,9 @@ int cmVisualStudioWCEPlatformParser::ParseVersion(const char* version) const std::string vckey = registryBase + "\\Setup\\VC;ProductDir"; const std::string vskey = registryBase + "\\Setup\\VS;ProductDir"; - if (!cmSystemTools::ReadRegistryValue(vckey.c_str(), this->VcInstallDir, + if (!cmSystemTools::ReadRegistryValue(vckey, this->VcInstallDir, cmSystemTools::KeyWOW64_32) || - !cmSystemTools::ReadRegistryValue(vskey.c_str(), this->VsInstallDir, + !cmSystemTools::ReadRegistryValue(vskey, this->VsInstallDir, cmSystemTools::KeyWOW64_32)) { return 0; } @@ -44,13 +44,12 @@ std::string cmVisualStudioWCEPlatformParser::GetOSVersion() const const char* cmVisualStudioWCEPlatformParser::GetArchitectureFamily() const { - std::map<std::string, std::string>::const_iterator it = - this->Macros.find("ARCHFAM"); + auto it = this->Macros.find("ARCHFAM"); if (it != this->Macros.end()) { return it->second.c_str(); } - return 0; + return nullptr; } void cmVisualStudioWCEPlatformParser::StartElement(const std::string& name, diff --git a/Source/cmVisualStudioWCEPlatformParser.h b/Source/cmVisualStudioWCEPlatformParser.h index 2fff91c..895a90d 100644 --- a/Source/cmVisualStudioWCEPlatformParser.h +++ b/Source/cmVisualStudioWCEPlatformParser.h @@ -16,9 +16,8 @@ class cmVisualStudioWCEPlatformParser : public cmXMLParser { public: - cmVisualStudioWCEPlatformParser(const char* name = NULL) + cmVisualStudioWCEPlatformParser(const char* name = nullptr) : RequiredName(name) - , FoundRequiredName(false) { } @@ -42,9 +41,9 @@ public: } protected: - virtual void StartElement(const std::string& name, const char** attributes); - void EndElement(const std::string& name); - void CharacterDataHandler(const char* data, int length); + void StartElement(const std::string& name, const char** attributes) override; + void EndElement(const std::string& name) override; + void CharacterDataHandler(const char* data, int length) override; private: std::string FixPaths(const std::string& paths) const; @@ -61,7 +60,7 @@ private: std::vector<std::string> AvailablePlatforms; const char* RequiredName; - bool FoundRequiredName; + bool FoundRequiredName = false; std::string VcInstallDir; std::string VsInstallDir; }; |