Merge pull request #910 from mathbunnyru/asalikhov/improve_readability

improve readability
This commit is contained in:
Daniel Marjamäki 2017-06-03 14:33:21 +02:00 committed by GitHub
commit bbde3cc23a
9 changed files with 19 additions and 29 deletions

View File

@ -231,19 +231,13 @@ void FileLister::addFiles(std::map<std::string, std::size_t> &files, const std::
bool FileLister::isDirectory(const std::string &path) bool FileLister::isDirectory(const std::string &path)
{ {
struct stat file_stat; struct stat file_stat;
if (stat(path.c_str(), &file_stat) != -1) return (stat(path.c_str(), &file_stat) != -1 && (file_stat.st_mode & S_IFMT) == S_IFDIR);
return ((file_stat.st_mode & S_IFMT) == S_IFDIR);
return false;
} }
bool FileLister::fileExists(const std::string &path) bool FileLister::fileExists(const std::string &path)
{ {
struct stat file_stat; struct stat file_stat;
if (stat(path.c_str(), &file_stat) != -1) return (stat(path.c_str(), &file_stat) != -1 && (file_stat.st_mode & S_IFMT) == S_IFREG);
return ((file_stat.st_mode & S_IFMT) == S_IFREG);
return false;
} }
#endif #endif

View File

@ -1064,7 +1064,7 @@ public:
/** is variable unused? */ /** is variable unused? */
bool unused() const { bool unused() const {
return (_read == false && _write == false); return (!_read && !_write);
} }
const Token *_name; const Token *_name;

View File

@ -396,7 +396,7 @@ bool CheckAutoVariables::returnTemporary(const Token *tok)
if (!func && tok->type()) if (!func && tok->type())
return true; return true;
return bool(!retref && retvalue); return (!retref && retvalue);
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -651,7 +651,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
tok = tok->next(); tok = tok->next();
} }
return bool(noreturn==nullptr); return (noreturn == nullptr);
} }
// variable is seen.. // variable is seen..

View File

@ -82,7 +82,7 @@ std::string Path::simplifyPath(std::string originalPath)
std::vector<std::string> pathParts; std::vector<std::string> pathParts;
for (std::size_t i = 0; i < originalPath.size(); ++i) { for (std::size_t i = 0; i < originalPath.size(); ++i) {
if (originalPath[i] == '/' || originalPath[i] == '\\') { if (originalPath[i] == '/' || originalPath[i] == '\\') {
if (subPath.length() > 0) { if (!subPath.empty()) {
pathParts.push_back(subPath); pathParts.push_back(subPath);
subPath.clear(); subPath.clear();
} }
@ -92,7 +92,7 @@ std::string Path::simplifyPath(std::string originalPath)
subPath.append(1, originalPath[i]); subPath.append(1, originalPath[i]);
} }
if (subPath.length() > 0) if (!subPath.empty())
pathParts.push_back(subPath); pathParts.push_back(subPath);
// First filter out all double slashes // First filter out all double slashes
@ -146,13 +146,13 @@ std::string Path::getPathFromFilename(const std::string &filename)
bool Path::sameFileName(const std::string &fname1, const std::string &fname2) bool Path::sameFileName(const std::string &fname1, const std::string &fname2)
{ {
#if defined(__linux__) || defined(__sun) || defined(__hpux) #if defined(__linux__) || defined(__sun) || defined(__hpux)
return bool(fname1 == fname2); return (fname1 == fname2);
#elif defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32)) #elif defined(_MSC_VER) || (defined(__GNUC__) && defined(_WIN32))
return bool(_stricmp(fname1.c_str(), fname2.c_str()) == 0); return (_stricmp(fname1.c_str(), fname2.c_str()) == 0);
#elif defined(__GNUC__) #elif defined(__GNUC__)
return bool(strcasecmp(fname1.c_str(), fname2.c_str()) == 0); return (strcasecmp(fname1.c_str(), fname2.c_str()) == 0);
#elif defined(__BORLANDC__) #elif defined(__BORLANDC__)
return bool(stricmp(fname1.c_str(), fname2.c_str()) == 0); return (stricmp(fname1.c_str(), fname2.c_str()) == 0);
#else #else
#error Platform filename compare function needed #error Platform filename compare function needed
#endif #endif
@ -251,7 +251,7 @@ bool Path::isC(const std::string &path)
bool Path::isCPP(const std::string &path) bool Path::isCPP(const std::string &path)
{ {
const std::string extension = getFilenameExtensionInLowerCase(path); const std::string extension = getFilenameExtensionInLowerCase(path);
if (extension == ".cpp" || return extension == ".cpp" ||
extension == ".cxx" || extension == ".cxx" ||
extension == ".cc" || extension == ".cc" ||
extension == ".c++" || extension == ".c++" ||
@ -259,12 +259,8 @@ bool Path::isCPP(const std::string &path)
extension == ".hxx" || extension == ".hxx" ||
extension == ".hh" || extension == ".hh" ||
extension == ".tpp" || extension == ".tpp" ||
extension == ".txx") { extension == ".txx" ||
return true; getFilenameExtension(path) == ".C"; // In unix, ".C" is considered C++ file
}
// In unix, ".C" is considered C++ file
return (getFilenameExtension(path) == ".C");
} }
bool Path::acceptFile(const std::string &path, const std::set<std::string> &extra) bool Path::acceptFile(const std::string &path, const std::set<std::string> &extra)

View File

@ -185,7 +185,7 @@ class CPPCHECKLIB Variable {
* @return true if flag set or false in flag not set * @return true if flag set or false in flag not set
*/ */
bool getFlag(unsigned int flag_) const { bool getFlag(unsigned int flag_) const {
return bool((_flags & flag_) != 0); return ((_flags & flag_) != 0);
} }
/** /**
@ -656,7 +656,7 @@ class CPPCHECKLIB Function {
* @return true if flag set or false in flag not set * @return true if flag set or false in flag not set
*/ */
bool getFlag(unsigned int flag) const { bool getFlag(unsigned int flag) const {
return bool((flags & flag) != 0); return ((flags & flag) != 0);
} }
/** /**

View File

@ -893,7 +893,7 @@ private:
* @return true if flag set or false in flag not set * @return true if flag set or false in flag not set
*/ */
bool getFlag(unsigned int flag_) const { bool getFlag(unsigned int flag_) const {
return bool((_flags & flag_) != 0); return ((_flags & flag_) != 0);
} }
/** /**

View File

@ -2369,7 +2369,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
return false; return false;
} }
return bool(typeCount >= 2 && tok2 && Token::Match(tok2->tokAt(-2), "!!:: %type%")); return (typeCount >= 2 && tok2 && Token::Match(tok2->tokAt(-2), "!!:: %type%"));
} }

View File

@ -4436,7 +4436,7 @@ private:
" x = 0;\n" " x = 0;\n"
" }\n" " }\n"
" bool isValid() {\n" " bool isValid() {\n"
" return bool(x == 0x11224488);\n" " return (x == 0x11224488);\n"
" }\n" " }\n"
"};"); "};");
ASSERT_EQUALS("[test.cpp:9]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const.\n", errout.str()); ASSERT_EQUALS("[test.cpp:9]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const.\n", errout.str());