From 7f6b8d3399dd841b0d29bf74d2b31021738c4ef8 Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Wed, 1 Jun 2016 23:29:53 +0200 Subject: [PATCH] Simplify boolean expressions Use clang-tidy's readability-simplify-boolean-expr checker. After applying the fix-its, revise all changes *very* carefully. Be aware of false positives and invalid changes. --- Source/CPack/IFW/cmCPackIFWRepository.cxx | 14 +++++--------- Source/CPack/cmCPackArchiveGenerator.cxx | 6 +----- Source/CPack/cmCPackDebGenerator.cxx | 6 +----- Source/CPack/cmCPackRPMGenerator.cxx | 6 +----- Source/CPack/cpack.cxx | 6 +----- Source/CTest/cmCTestCoverageHandler.cxx | 16 ++++------------ Source/CTest/cmCTestLaunch.cxx | 8 ++------ Source/CTest/cmCTestMemCheckHandler.cxx | 15 +++------------ Source/CTest/cmCTestSubmitHandler.cxx | 9 +-------- Source/CTest/cmCTestTestHandler.cxx | 2 +- Source/CTest/cmParsePHPCoverage.cxx | 5 +---- Source/CursesDialog/cmCursesBoolWidget.cxx | 6 +----- Source/cmCacheManager.cxx | 2 +- Source/cmComputeLinkInformation.cxx | 3 +-- Source/cmCustomCommand.cxx | 2 +- Source/cmDependsC.cxx | 6 +++--- Source/cmDependsFortran.cxx | 5 ++--- Source/cmELF.cxx | 6 +++--- Source/cmExtraCodeBlocksGenerator.cxx | 8 ++++---- Source/cmExtraCodeLiteGenerator.cxx | 2 +- Source/cmExtraEclipseCDT4Generator.cxx | 2 +- Source/cmGeneratedFileStream.cxx | 4 ++-- Source/cmGeneratorTarget.cxx | 6 +----- Source/cmGlobalGenerator.cxx | 3 +-- Source/cmGlobalNinjaGenerator.cxx | 6 +++--- Source/cmGraphVizWriter.cxx | 14 +++++++------- Source/cmListFileCache.cxx | 5 +---- Source/cmLocalUnixMakefileGenerator3.cxx | 2 +- Source/cmMakefile.cxx | 17 ++++------------- Source/cmMakefileLibraryTargetGenerator.cxx | 3 +-- Source/cmNinjaTargetGenerator.cxx | 3 +-- Source/cmPropertyDefinitionMap.cxx | 7 +------ Source/cmQtAutoGenerators.cxx | 11 +++++------ Source/cmSourceFileLocation.cxx | 5 +---- Source/cmSourceGroup.cxx | 6 +----- Source/cmSystemTools.cxx | 7 ++----- Source/cmcmd.cxx | 8 ++------ 37 files changed, 73 insertions(+), 169 deletions(-) diff --git a/Source/CPack/IFW/cmCPackIFWRepository.cxx b/Source/CPack/IFW/cmCPackIFWRepository.cxx index b149f81430..18380054dc 100644 --- a/Source/CPack/IFW/cmCPackIFWRepository.cxx +++ b/Source/CPack/IFW/cmCPackIFWRepository.cxx @@ -45,16 +45,16 @@ bool cmCPackIFWRepository::IsValid() const switch (Update) { case None: - valid = Url.empty() ? false : true; + valid = !Url.empty(); break; case Add: - valid = Url.empty() ? false : true; + valid = !Url.empty(); break; case Remove: - valid = Url.empty() ? false : true; + valid = !Url.empty(); break; case Replace: - valid = (OldUrl.empty() || NewUrl.empty()) ? false : true; + valid = !OldUrl.empty() && !NewUrl.empty(); break; } @@ -244,11 +244,7 @@ bool cmCPackIFWRepository::PatchUpdatesXml() fout.Close(); - if (!cmSystemTools::RenameFile(updatesPatchXml.data(), updatesXml.data())) { - return false; - } - - return true; + return cmSystemTools::RenameFile(updatesPatchXml.data(), updatesXml.data()); } void cmCPackIFWRepository::WriteRepositoryConfig(cmXMLWriter& xout) diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx index 7db20a429c..baf6719ca0 100644 --- a/Source/CPack/cmCPackArchiveGenerator.cxx +++ b/Source/CPack/cmCPackArchiveGenerator.cxx @@ -269,9 +269,5 @@ bool cmCPackArchiveGenerator::SupportsComponentInstallation() const // The Component installation support should only // be activated if explicitly requested by the user // (for backward compatibility reason) - if (IsOn("CPACK_ARCHIVE_COMPONENT_INSTALL")) { - return true; - } else { - return false; - } + return IsOn("CPACK_ARCHIVE_COMPONENT_INSTALL"); } diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index 1ad4152512..ddaa483b65 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -675,11 +675,7 @@ int cmCPackDebGenerator::createDeb() bool cmCPackDebGenerator::SupportsComponentInstallation() const { - if (IsOn("CPACK_DEB_COMPONENT_INSTALL")) { - return true; - } else { - return false; - } + return IsOn("CPACK_DEB_COMPONENT_INSTALL"); } std::string cmCPackDebGenerator::GetComponentInstallDirNameSuffix( diff --git a/Source/CPack/cmCPackRPMGenerator.cxx b/Source/CPack/cmCPackRPMGenerator.cxx index 9827b70999..bc101118f4 100644 --- a/Source/CPack/cmCPackRPMGenerator.cxx +++ b/Source/CPack/cmCPackRPMGenerator.cxx @@ -228,11 +228,7 @@ int cmCPackRPMGenerator::PackageFiles() bool cmCPackRPMGenerator::SupportsComponentInstallation() const { - if (IsOn("CPACK_RPM_COMPONENT_INSTALL")) { - return true; - } else { - return false; - } + return IsOn("CPACK_RPM_COMPONENT_INSTALL"); } std::string cmCPackRPMGenerator::GetComponentInstallDirNameSuffix( diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index 94e16154bc..425afd9e89 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -209,11 +209,7 @@ int main(int argc, char const* const* argv) * should launch cpack using "cpackConfigFile" if it exists * in the current directory. */ - if ((doc.CheckOptions(argc, argv, "-G")) && !(argc == 1)) { - help = true; - } else { - help = false; - } + help = doc.CheckOptions(argc, argv, "-G") && argc != 1; // This part is used for cpack documentation lookup as well. cminst.AddCMakePaths(); diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index daefb5914b..ba9e5469e3 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -90,11 +90,8 @@ public: cmsysProcess_Execute(this->Process); this->PipeState = cmsysProcess_GetState(this->Process); // if the process is running or exited return true - if (this->PipeState == cmsysProcess_State_Executing || - this->PipeState == cmsysProcess_State_Exited) { - return true; - } - return false; + return this->PipeState == cmsysProcess_State_Executing || + this->PipeState == cmsysProcess_State_Exited; } void SetStdoutFile(const char* fname) { @@ -705,13 +702,8 @@ bool IsFileInDir(const std::string& infile, const std::string& indir) std::string file = cmSystemTools::CollapseFullPath(infile); std::string dir = cmSystemTools::CollapseFullPath(indir); - if (file.size() > dir.size() && - (fnc(file.substr(0, dir.size())) == fnc(dir)) && - file[dir.size()] == '/') { - return true; - } - - return false; + return file.size() > dir.size() && + fnc(file.substr(0, dir.size())) == fnc(dir) && file[dir.size()] == '/'; } int cmCTestCoverageHandler::HandlePHPCoverage( diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index 4a408a278c..99fa9e7c3f 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -594,12 +594,8 @@ bool cmCTestLaunch::Match(std::string const& line, bool cmCTestLaunch::MatchesFilterPrefix(std::string const& line) const { - if (!this->OptionFilterPrefix.empty() && - cmSystemTools::StringStartsWith(line.c_str(), - this->OptionFilterPrefix.c_str())) { - return true; - } - return false; + return !this->OptionFilterPrefix.empty() && + cmSystemTools::StringStartsWith(line, this->OptionFilterPrefix.c_str()); } int cmCTestLaunch::Main(int argc, const char* const argv[]) diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index 5ae98aff56..f8ffd432a8 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -722,10 +722,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckSanitizerOutput( ostr << *i << std::endl; } log = ostr.str(); - if (defects) { - return false; - } - return true; + return defects == 0; } bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput( const std::string& str, std::string& log, std::vector& results) @@ -766,10 +763,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput( } log = ostr.str(); - if (defects) { - return false; - } - return true; + return defects == 0; } bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput( @@ -904,10 +898,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput( << (cmSystemTools::GetTime() - sttime) << std::endl, this->Quiet); log = ostr.str(); - if (defects) { - return false; - } - return true; + return defects == 0; } bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput( diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index f373348674..32975df624 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -845,10 +845,7 @@ bool cmCTestSubmitHandler::SubmitUsingSCP(const std::string& scp_command, } } cmsysProcess_Delete(cp); - if (problems) { - return false; - } - return true; + return problems == 0; } bool cmCTestSubmitHandler::SubmitUsingCP(const std::string& localprefix, @@ -870,7 +867,6 @@ bool cmCTestSubmitHandler::SubmitUsingCP(const std::string& localprefix, } cmCTest::SetOfStrings::const_iterator file; - bool problems = false; for (file = files.begin(); file != files.end(); ++file) { std::string lfname = localprefix; cmSystemTools::ConvertToUnixSlashes(lfname); @@ -883,9 +879,6 @@ bool cmCTestSubmitHandler::SubmitUsingCP(const std::string& localprefix, } std::string tagDoneFile = destination + "/" + remoteprefix + "DONE"; cmSystemTools::Touch(tagDoneFile, true); - if (problems) { - return false; - } return true; } diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 20ef6930d0..55a6518f9b 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1406,7 +1406,7 @@ void cmCTestTestHandler::UseIncludeRegExp() void cmCTestTestHandler::UseExcludeRegExp() { this->UseExcludeRegExpFlag = true; - this->UseExcludeRegExpFirst = this->UseIncludeRegExpFlag ? false : true; + this->UseExcludeRegExpFirst = !this->UseIncludeRegExpFlag; } const char* cmCTestTestHandler::GetTestStatus(int status) diff --git a/Source/CTest/cmParsePHPCoverage.cxx b/Source/CTest/cmParsePHPCoverage.cxx index eb0d962d62..5ec27189b6 100644 --- a/Source/CTest/cmParsePHPCoverage.cxx +++ b/Source/CTest/cmParsePHPCoverage.cxx @@ -27,10 +27,7 @@ bool cmParsePHPCoverage::ReadUntil(std::istream& in, char until) char c = 0; while (in.get(c) && c != until) { } - if (c != until) { - return false; - } - return true; + return c == until; } bool cmParsePHPCoverage::ReadCoverageArray(std::istream& in, std::string const& fileName) diff --git a/Source/CursesDialog/cmCursesBoolWidget.cxx b/Source/CursesDialog/cmCursesBoolWidget.cxx index 0055e88367..9bcf0507b8 100644 --- a/Source/CursesDialog/cmCursesBoolWidget.cxx +++ b/Source/CursesDialog/cmCursesBoolWidget.cxx @@ -54,9 +54,5 @@ void cmCursesBoolWidget::SetValueAsBool(bool value) bool cmCursesBoolWidget::GetValueAsBool() { - if (this->Value == "ON") { - return true; - } else { - return false; - } + return this->Value == "ON"; } diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index d143193f14..676e84a2a0 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -642,5 +642,5 @@ void cmCacheManager::CacheIterator::SetProperty(const std::string& p, bool v) bool cmCacheManager::CacheIterator::PropertyExists( const std::string& prop) const { - return this->GetProperty(prop) ? true : false; + return this->GetProperty(prop) != NULL; } diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index e1a7bee305..1eefbb1d76 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -274,8 +274,7 @@ cmComputeLinkInformation::cmComputeLinkInformation( // Check whether we should use an import library for linking a target. this->UseImportLibrary = - this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX") ? true - : false; + this->Makefile->IsDefinitionSet("CMAKE_IMPORT_LIBRARY_SUFFIX"); // Check whether we should skip dependencies on shared library files. this->LinkDependsNoShared = diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index 7c00c80a10..4c5bd03207 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -38,7 +38,7 @@ cmCustomCommand::cmCustomCommand(cmMakefile const* mf, , Backtrace() , Comment(comment ? comment : "") , WorkingDirectory(workingDirectory ? workingDirectory : "") - , HaveComment(comment ? true : false) + , HaveComment(comment != NULL) , EscapeAllowMakeVars(false) , EscapeOldStyle(true) { diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx index 78bb1b2764..5be527ccd1 100644 --- a/Source/cmDependsC.cxx +++ b/Source/cmDependsC.cxx @@ -278,21 +278,21 @@ void cmDependsC::ReadCacheFile() continue; } // the first line after an empty line is the name of the parsed file - if (haveFileName == false) { + if (!haveFileName) { haveFileName = true; int newer = 0; cmFileTimeComparison comp; bool res = comp.FileTimeCompare(this->CacheFileName.c_str(), line.c_str(), &newer); - if ((res == true) && (newer == 1)) // cache is newer than the parsed file + if (res && newer == 1) // cache is newer than the parsed file { cacheEntry = new cmIncludeLines; this->FileCache[line] = cacheEntry; } // file doesn't exist, check that the regular expressions // haven't changed - else if (res == false) { + else if (!res) { if (line.find(INCLUDE_REGEX_LINE_MARKER) == 0) { if (line != this->IncludeRegexLineString) { return; diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index 38e319d72f..a20fb9819f 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -654,10 +654,9 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile, // but also do not include a date so we can fall through to // compare them without skipping any prefix. unsigned char hdr[2]; - bool okay = - finModFile.read(reinterpret_cast(hdr), 2) ? true : false; + bool okay = !finModFile.read(reinterpret_cast(hdr), 2).fail(); finModFile.seekg(0); - if (!(okay && hdr[0] == 0x1f && hdr[1] == 0x8b)) { + if (!okay || hdr[0] != 0x1f || hdr[1] != 0x8b) { const char seq[1] = { '\n' }; const int seqlen = 1; diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx index 26f1a44e8e..c7f8a2d62d 100644 --- a/Source/cmELF.cxx +++ b/Source/cmELF.cxx @@ -143,7 +143,7 @@ public: { this->Stream.seekg(pos); this->Stream.read(buf, size); - return this->Stream ? true : false; + return !this->Stream.fail(); } // Lookup the SONAME in the DYNAMIC section. @@ -497,7 +497,7 @@ private: this->NeedSwap) { ByteSwap(x); } - return this->Stream ? true : false; + return !this->Stream.fail(); } bool Read(ELF_Dyn& x) { @@ -505,7 +505,7 @@ private: this->NeedSwap) { ByteSwap(x); } - return this->Stream ? true : false; + return !this->Stream.fail(); } bool LoadSectionHeader(ELF_Half i) diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index 2070b1f7ff..40cff785c4 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -655,11 +655,11 @@ std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf) // projects with C/C++ and Fortran are handled as C/C++ projects bool pureFortran = false; std::string compilerIdVar; - if (this->GlobalGenerator->GetLanguageEnabled("CXX") == true) { + if (this->GlobalGenerator->GetLanguageEnabled("CXX")) { compilerIdVar = "CMAKE_CXX_COMPILER_ID"; - } else if (this->GlobalGenerator->GetLanguageEnabled("C") == true) { + } else if (this->GlobalGenerator->GetLanguageEnabled("C")) { compilerIdVar = "CMAKE_C_COMPILER_ID"; - } else if (this->GlobalGenerator->GetLanguageEnabled("Fortran") == true) { + } else if (this->GlobalGenerator->GetLanguageEnabled("Fortran")) { compilerIdVar = "CMAKE_Fortran_COMPILER_ID"; pureFortran = true; } @@ -667,7 +667,7 @@ std::string cmExtraCodeBlocksGenerator::GetCBCompilerId(const cmMakefile* mf) std::string compilerId = mf->GetSafeDefinition(compilerIdVar); std::string compiler = "gcc"; // default to gcc if (compilerId == "MSVC") { - if (mf->IsDefinitionSet("MSVC10") == true) { + if (mf->IsDefinitionSet("MSVC10")) { compiler = "msvc10"; } else { compiler = "msvc8"; diff --git a/Source/cmExtraCodeLiteGenerator.cxx b/Source/cmExtraCodeLiteGenerator.cxx index ba5876736b..dd10b656aa 100644 --- a/Source/cmExtraCodeLiteGenerator.cxx +++ b/Source/cmExtraCodeLiteGenerator.cxx @@ -407,7 +407,7 @@ std::string cmExtraCodeLiteGenerator::GetCodeLiteCompilerName( // figure out which language to use // for now care only for C and C++ std::string compilerIdVar = "CMAKE_CXX_COMPILER_ID"; - if (this->GlobalGenerator->GetLanguageEnabled("CXX") == false) { + if (!this->GlobalGenerator->GetLanguageEnabled("CXX")) { compilerIdVar = "CMAKE_C_COMPILER_ID"; } diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index f24e7fb43f..bc217afb9d 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -129,7 +129,7 @@ void cmExtraEclipseCDT4Generator::Generate() (this->IsOutOfSourceBuild && mf->IsOn("CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT")); - if ((this->GenerateSourceProject == false) && + if (!this->GenerateSourceProject && (mf->IsOn("ECLIPSE_CDT4_GENERATE_SOURCE_PROJECT"))) { mf->IssueMessage( cmake::WARNING, diff --git a/Source/cmGeneratedFileStream.cxx b/Source/cmGeneratedFileStream.cxx index 2c059139aa..dee174b7f7 100644 --- a/Source/cmGeneratedFileStream.cxx +++ b/Source/cmGeneratedFileStream.cxx @@ -42,7 +42,7 @@ cmGeneratedFileStream::~cmGeneratedFileStream() // stream will be destroyed which will close the temporary file. // Finally the base destructor will be called to replace the // destination file. - this->Okay = (*this) ? true : false; + this->Okay = !this->fail(); } cmGeneratedFileStream& cmGeneratedFileStream::Open(const char* name, @@ -71,7 +71,7 @@ cmGeneratedFileStream& cmGeneratedFileStream::Open(const char* name, bool cmGeneratedFileStream::Close() { // Save whether the temporary output file is valid before closing. - this->Okay = (*this) ? true : false; + this->Okay = !this->fail(); // Close the temporary output file. this->Stream::close(); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 3856091c7a..1607dd937a 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1306,11 +1306,7 @@ bool cmGeneratorTarget::MacOSXRpathInstallNameDirDefault() const this->GetName()); } - if (cmp0042 == cmPolicies::NEW) { - return true; - } - - return false; + return cmp0042 == cmPolicies::NEW; } std::string cmGeneratorTarget::GetSOName(const std::string& config) const diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index a1764a38ab..fc34b8b215 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -180,8 +180,7 @@ void cmGlobalGenerator::ResolveLanguageCompiler(const std::string& lang, } else { path = name; } - if ((path.empty() || !cmSystemTools::FileExists(path.c_str())) && - (optional == false)) { + if (!optional && (path.empty() || !cmSystemTools::FileExists(path))) { return; } const char* cname = diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 143ad9213c..3abcba3987 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -1227,9 +1227,9 @@ std::string cmGlobalNinjaGenerator::ninjaCmd() const bool cmGlobalNinjaGenerator::SupportsConsolePool() const { - return cmSystemTools::VersionCompare( - cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), - RequiredNinjaVersionForConsolePool().c_str()) == false; + return !cmSystemTools::VersionCompare( + cmSystemTools::OP_LESS, this->NinjaVersion.c_str(), + RequiredNinjaVersionForConsolePool().c_str()); } void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os) diff --git a/Source/cmGraphVizWriter.cxx b/Source/cmGraphVizWriter.cxx index 20cd171192..6b3a870733 100644 --- a/Source/cmGraphVizWriter.cxx +++ b/Source/cmGraphVizWriter.cxx @@ -140,7 +140,7 @@ void cmGraphVizWriter::ReadSettings(const char* settingsFileName, // which other targets depend on it. void cmGraphVizWriter::WriteTargetDependersFiles(const char* fileName) { - if (this->GenerateDependers == false) { + if (!this->GenerateDependers) { return; } @@ -153,7 +153,7 @@ void cmGraphVizWriter::WriteTargetDependersFiles(const char* fileName) continue; } - if (this->GenerateForTargetType(ptrIt->second->GetType()) == false) { + if (!this->GenerateForTargetType(ptrIt->second->GetType())) { continue; } @@ -184,7 +184,7 @@ void cmGraphVizWriter::WriteTargetDependersFiles(const char* fileName) // on which targets it depends. void cmGraphVizWriter::WritePerTargetFiles(const char* fileName) { - if (this->GeneratePerTarget == false) { + if (!this->GeneratePerTarget) { return; } @@ -197,7 +197,7 @@ void cmGraphVizWriter::WritePerTargetFiles(const char* fileName) continue; } - if (this->GenerateForTargetType(ptrIt->second->GetType()) == false) { + if (!this->GenerateForTargetType(ptrIt->second->GetType())) { continue; } @@ -243,7 +243,7 @@ void cmGraphVizWriter::WriteGlobalFile(const char* fileName) continue; } - if (this->GenerateForTargetType(ptrIt->second->GetType()) == false) { + if (!this->GenerateForTargetType(ptrIt->second->GetType())) { continue; } @@ -344,7 +344,7 @@ void cmGraphVizWriter::WriteDependerConnections( continue; } - if (this->GenerateForTargetType(dependerIt->second->GetType()) == false) { + if (!this->GenerateForTargetType(dependerIt->second->GetType())) { continue; } @@ -403,7 +403,7 @@ void cmGraphVizWriter::WriteNode(const std::string& targetName, void cmGraphVizWriter::CollectTargetsAndLibs() { - if (this->HaveTargetsAndLibs == false) { + if (!this->HaveTargetsAndLibs) { this->HaveTargetsAndLibs = true; int cnt = this->CollectAllTargets(); if (this->GenerateForExternals) { diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index f47e9b66f2..33731e0473 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -202,10 +202,7 @@ bool cmListFile::ParseFile(const char* filename, bool topLevel, cmMakefile* mf) this->Functions.insert(this->Functions.begin(), project); } } - if (parseError) { - return false; - } - return true; + return !parseError; } bool cmListFileParser::ParseFunction(const char* name, long line) diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index f60a595e47..4b5af8b873 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1322,7 +1322,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(const char* tgtInfo, // not be considered. std::map validDependencies; bool needRescanDependencies = false; - if (needRescanDirInfo == false) { + if (!needRescanDirInfo) { cmDependsC checker; checker.SetVerbose(verbose); checker.SetFileComparison(ftc); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index e684689f0f..45fb7cf34f 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2124,20 +2124,11 @@ bool cmMakefile::CanIWriteThisFile(const char* fileName) const // If we are doing an in-source build, then the test will always fail if (cmSystemTools::SameFile(this->GetHomeDirectory(), this->GetHomeOutputDirectory())) { - if (this->IsOn("CMAKE_DISABLE_IN_SOURCE_BUILD")) { - return false; - } - return true; + return !this->IsOn("CMAKE_DISABLE_IN_SOURCE_BUILD"); } - // Check if this is a subdirectory of the source tree but not a - // subdirectory of the build tree - if (cmSystemTools::IsSubDirectory(fileName, this->GetHomeDirectory()) && - !cmSystemTools::IsSubDirectory(fileName, - this->GetHomeOutputDirectory())) { - return false; - } - return true; + return !cmSystemTools::IsSubDirectory(fileName, this->GetHomeDirectory()) || + cmSystemTools::IsSubDirectory(fileName, this->GetHomeOutputDirectory()); } const char* cmMakefile::GetRequiredDefinition(const std::string& name) const @@ -2166,7 +2157,7 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const } } #endif - return def ? true : false; + return def != NULL; } const char* cmMakefile::GetDefinition(const std::string& name) const diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 8f7dd7e444..128291d29d 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -454,8 +454,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules( std::vector archiveFinishCommands; std::string::size_type archiveCommandLimit = std::string::npos; if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY) { - haveStaticLibraryRule = - this->Makefile->GetDefinition(linkRuleVar) ? true : false; + haveStaticLibraryRule = this->Makefile->IsDefinitionSet(linkRuleVar); std::string arCreateVar = "CMAKE_"; arCreateVar += linkLanguage; arCreateVar += "_ARCHIVE_CREATE"; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 1aa2ddb28d..b0f0d9b47c 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -130,8 +130,7 @@ void cmNinjaTargetGenerator::AddIncludeFlags(std::string& languageFlags, // Add include directory flags. std::string includeFlags = this->LocalGenerator->GetIncludeFlags( includes, this->GeneratorTarget, language, - language == "RC" ? true : false, // full include paths for RC - // needed by cmcldeps + language == "RC", // full include paths for RC needed by cmcldeps false, this->GetConfigName()); if (this->GetGlobalGenerator()->IsGCCOnWindows()) std::replace(includeFlags.begin(), includeFlags.end(), '\\', '/'); diff --git a/Source/cmPropertyDefinitionMap.cxx b/Source/cmPropertyDefinitionMap.cxx index ebc2caa3b1..0ba35e716a 100644 --- a/Source/cmPropertyDefinitionMap.cxx +++ b/Source/cmPropertyDefinitionMap.cxx @@ -31,12 +31,7 @@ void cmPropertyDefinitionMap::DefineProperty(const std::string& name, bool cmPropertyDefinitionMap::IsPropertyDefined(const std::string& name) const { - cmPropertyDefinitionMap::const_iterator it = this->find(name); - if (it == this->end()) { - return false; - } - - return true; + return this->find(name) != this->end(); } bool cmPropertyDefinitionMap::IsPropertyChained(const std::string& name) const diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index ac64397cd7..dc44f3e6a0 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -636,14 +636,14 @@ void cmQtAutoGenerators::ParseCppFile( } } else { std::string fileToMoc = absFilename; - if ((basename != scannedFileBasename) || (requiresMoc == false)) { + if (!requiresMoc || basename != scannedFileBasename) { std::string mocSubDir = extractSubDir(absPath, currentMoc); std::string headerToMoc = findMatchingHeader(absPath, mocSubDir, basename, headerExtensions); if (!headerToMoc.empty()) { // this is for KDE4 compatibility: fileToMoc = headerToMoc; - if ((requiresMoc == false) && (basename == scannedFileBasename)) { + if (!requiresMoc && basename == scannedFileBasename) { std::stringstream err; err << "AUTOGEN: warning: " << absFilename << ": The file " @@ -696,8 +696,8 @@ void cmQtAutoGenerators::ParseCppFile( // If this is the case, the moc_foo.cpp should probably be generated from // foo.cpp instead of foo.h, because otherwise it won't build. // But warn, since this is not how it is supposed to be used. - if ((dotMocIncluded == false) && (requiresMoc == true)) { - if (mocUnderscoreIncluded == true) { + if (!dotMocIncluded && requiresMoc) { + if (mocUnderscoreIncluded) { // this is for KDE4 compatibility: std::stringstream err; err << "AUTOGEN: warning: " << absFilename << ": The file " @@ -833,8 +833,7 @@ void cmQtAutoGenerators::StrictParseCppFile( // foo.cpp instead of foo.h, because otherwise it won't build. // But warn, since this is not how it is supposed to be used. std::string macroName; - if ((dotMocIncluded == false) && - (requiresMocing(contentsString, macroName))) { + if (!dotMocIncluded && requiresMocing(contentsString, macroName)) { // otherwise always error out since it will not compile: std::stringstream err; err << "AUTOGEN: error: " << absFilename << ": The file " diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx index 3219f3678b..a89d1e8e34 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -177,10 +177,7 @@ bool cmSourceFileLocation::MatchesAmbiguousExtension( } std::vector hdrExts = mf->GetCMakeInstance()->GetHeaderExtensions(); - if (std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end()) { - return true; - } - return false; + return std::find(hdrExts.begin(), hdrExts.end(), ext) != hdrExts.end(); } bool cmSourceFileLocation::Matches(cmSourceFileLocation const& loc) diff --git a/Source/cmSourceGroup.cxx b/Source/cmSourceGroup.cxx index 394b33a473..f27b572fdc 100644 --- a/Source/cmSourceGroup.cxx +++ b/Source/cmSourceGroup.cxx @@ -86,11 +86,7 @@ bool cmSourceGroup::MatchesRegex(const char* name) bool cmSourceGroup::MatchesFiles(const char* name) { - std::set::const_iterator i = this->GroupFiles.find(name); - if (i != this->GroupFiles.end()) { - return true; - } - return false; + return this->GroupFiles.find(name) != this->GroupFiles.end(); } void cmSourceGroup::AssignSource(const cmSourceFile* sf) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 7dece47893..71569483a5 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -2108,11 +2108,8 @@ bool cmSystemTools::GuessLibrarySOName(std::string const& fullPath, // If the symlink points at an extended version of the same name // assume it is the soname. std::string name = cmSystemTools::GetFilenameName(fullPath); - if (soname.length() > name.length() && - soname.substr(0, name.length()) == name) { - return true; - } - return false; + return soname.length() > name.length() && + soname.compare(0, name.length(), name) == 0; } bool cmSystemTools::GuessLibraryInstallName(std::string const& fullPath, diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 471028a2f7..535dead226 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1027,11 +1027,7 @@ int cmcmd::ExecuteEchoColor(std::vector& args) // Enable or disable color based on the switch value. std::string value = args[i].substr(9); if (!value.empty()) { - if (cmSystemTools::IsOn(value.c_str())) { - enabled = true; - } else { - enabled = false; - } + enabled = cmSystemTools::IsOn(value.c_str()); } } else if (cmHasLiteralPrefix(args[i], "--progress-dir=")) { progressDir = args[i].substr(15); @@ -1226,7 +1222,7 @@ int cmcmd::VisualStudioLink(std::vector& args, int type) if (args.size() < 2) { return -1; } - bool verbose = cmSystemTools::GetEnv("VERBOSE") ? true : false; + bool verbose = cmSystemTools::GetEnv("VERBOSE") != NULL; std::vector expandedArgs; for (std::vector::iterator i = args.begin(); i != args.end(); ++i) {