From edea4ef13163219829d50be8b047be93a24cf25f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 21 Jun 2012 19:00:53 +0200 Subject: [PATCH] Refactoring: Renamed CheckNullPointer::isPointer to Token::isUpperCaseName --- lib/checkleakautovar.cpp | 4 +--- lib/checknullpointer.cpp | 13 +------------ lib/checknullpointer.h | 3 --- lib/checkuninitvar.cpp | 4 ++-- lib/symboldatabase.cpp | 3 +-- lib/token.cpp | 11 +++++++++++ lib/token.h | 1 + lib/tokenize.cpp | 2 +- 8 files changed, 18 insertions(+), 23 deletions(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 2f1f0f271..8b6853cc4 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -26,8 +26,6 @@ #include "errorlogger.h" #include "symboldatabase.h" -#include "checknullpointer.h" // <- isUpper - #include //--------------------------------------------------------------------------- @@ -269,7 +267,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, // track the execution for a later if condition. if (Token::Match(tok->tokAt(2), "%num% ;") && MathLib::toLongNumber(tok->strAt(2)) != 0) notzero.insert(tok->varId()); - else if (Token::Match(tok->tokAt(2), "- %type% ;") && CheckNullPointer::isUpper(tok->strAt(3))) + else if (Token::Match(tok->tokAt(2), "- %type% ;") && tok->tokAt(3)->isUpperCaseName()) notzero.insert(tok->varId()); else notzero.erase(tok->varId()); diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 56e328b87..33c0e4032 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -32,17 +32,6 @@ namespace { //--------------------------------------------------------------------------- - -/** Is string uppercase? */ -bool CheckNullPointer::isUpper(const std::string &str) -{ - for (unsigned int i = 0; i < str.length(); ++i) { - if (std::islower(str[i])) - return false; - } - return true; -} - /** * @brief parse a function call and extract information about variable usage * @param tok first token @@ -932,7 +921,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() // - if (x) { } else { ... } // If the if-body ends with a unknown macro then bailout - if (Token::Match(i->classEnd->tokAt(-3), "[;{}] %var% ;") && isUpper(i->classEnd->strAt(-2))) + if (Token::Match(i->classEnd->tokAt(-3), "[;{}] %var% ;") && i->classEnd->tokAt(-2)->isUpperCaseName()) continue; // vartok : token for the variable diff --git a/lib/checknullpointer.h b/lib/checknullpointer.h index c4b25a2de..967921cf5 100644 --- a/lib/checknullpointer.h +++ b/lib/checknullpointer.h @@ -59,9 +59,6 @@ public: checkNullPointer.executionPaths(); } - /** Is string uppercase? */ - static bool isUpper(const std::string &str); - /** * @brief parse a function call and extract information about variable usage * @param tok first token diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index def045c35..9fc1dfca3 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -670,7 +670,7 @@ private: } // ticket #2367 : unexpanded macro that uses sizeof|typeof? - else if (Token::Match(tok2, "%type% (") && CheckNullPointer::isUpper(tok2->str())) { + else if (Token::Match(tok2, "%type% (") && tok2->isUpperCaseName()) { tok2 = tok2->next()->link(); if (!tok2) break; @@ -689,7 +689,7 @@ private: functionCall = functionCall ? functionCall->previous() : 0; if (functionCall) { - if (functionCall->isName() && !CheckNullPointer::isUpper(functionCall->str()) && use_dead_pointer(checks, tok2)) + if (functionCall->isName() && !functionCall->isUpperCaseName() && use_dead_pointer(checks, tok2)) ExecutionPath::bailOutVar(checks, tok2->varId()); } } diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 67aaf1c4d..ba90f23fe 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -24,7 +24,6 @@ #include "settings.h" #include "errorlogger.h" #include "check.h" -#include "checknullpointer.h" // isUpper #include #include @@ -99,7 +98,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti // Namespace and unknown macro (#3854) else if (Token::Match(tok, "namespace %var% %type% (") && _tokenizer->isCPP() && - CheckNullPointer::isUpper(tok->strAt(2)) && + tok->tokAt(2)->isUpperCaseName() && Token::simpleMatch(tok->linkAt(3), ") {")) { scopeList.push_back(Scope(this, tok, scope)); diff --git a/lib/token.cpp b/lib/token.cpp index 6a315a264..26bdd9bed 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -130,6 +130,17 @@ void Token::update_property_isStandardType() } +bool Token::isUpperCaseName() const +{ + if (!isName()) + return false; + for (unsigned int i = 0; i < _str.length(); ++i) { + if (std::islower(_str[i])) + return false; + } + return true; +} + void Token::str(const std::string &s) { _str = s; diff --git a/lib/token.h b/lib/token.h index 82479de40..36861d7bc 100644 --- a/lib/token.h +++ b/lib/token.h @@ -170,6 +170,7 @@ public: return _type == eName || _type == eType || _type == eVariable || _type == eFunction || _type == eBoolean; // TODO: "true"/"false" aren't really a name... } + bool isUpperCaseName() const; bool isNumber() const { return _type == eNumber; } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a2899436a..ef7cd68d2 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3454,7 +3454,7 @@ void Tokenizer::removeMacrosInGlobalScope() tok->deleteNext(); } - if (Token::Match(tok, "[;{}] %type%") && CheckNullPointer::isUpper(tok->next()->str())) { + if (Token::Match(tok, "[;{}] %type%") && tok->next()->isUpperCaseName()) { const Token *tok2 = tok->tokAt(2); if (tok2 && tok2->str() == "(") { unsigned int par = 0;