Refactoring: Renamed CheckNullPointer::isPointer to Token::isUpperCaseName

This commit is contained in:
Daniel Marjamäki 2012-06-21 19:00:53 +02:00
parent ee0d18a9e4
commit edea4ef131
8 changed files with 18 additions and 23 deletions

View File

@ -26,8 +26,6 @@
#include "errorlogger.h" #include "errorlogger.h"
#include "symboldatabase.h" #include "symboldatabase.h"
#include "checknullpointer.h" // <- isUpper
#include <fstream> #include <fstream>
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -269,7 +267,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
// track the execution for a later if condition. // track the execution for a later if condition.
if (Token::Match(tok->tokAt(2), "%num% ;") && MathLib::toLongNumber(tok->strAt(2)) != 0) if (Token::Match(tok->tokAt(2), "%num% ;") && MathLib::toLongNumber(tok->strAt(2)) != 0)
notzero.insert(tok->varId()); 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()); notzero.insert(tok->varId());
else else
notzero.erase(tok->varId()); notzero.erase(tok->varId());

View File

@ -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 * @brief parse a function call and extract information about variable usage
* @param tok first token * @param tok first token
@ -932,7 +921,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
// - if (x) { } else { ... } // - if (x) { } else { ... }
// If the if-body ends with a unknown macro then bailout // 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; continue;
// vartok : token for the variable // vartok : token for the variable

View File

@ -59,9 +59,6 @@ public:
checkNullPointer.executionPaths(); checkNullPointer.executionPaths();
} }
/** Is string uppercase? */
static bool isUpper(const std::string &str);
/** /**
* @brief parse a function call and extract information about variable usage * @brief parse a function call and extract information about variable usage
* @param tok first token * @param tok first token

View File

@ -670,7 +670,7 @@ private:
} }
// ticket #2367 : unexpanded macro that uses sizeof|typeof? // 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(); tok2 = tok2->next()->link();
if (!tok2) if (!tok2)
break; break;
@ -689,7 +689,7 @@ private:
functionCall = functionCall ? functionCall->previous() : 0; functionCall = functionCall ? functionCall->previous() : 0;
if (functionCall) { 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()); ExecutionPath::bailOutVar(checks, tok2->varId());
} }
} }

View File

@ -24,7 +24,6 @@
#include "settings.h" #include "settings.h"
#include "errorlogger.h" #include "errorlogger.h"
#include "check.h" #include "check.h"
#include "checknullpointer.h" // isUpper
#include <string> #include <string>
#include <sstream> #include <sstream>
@ -99,7 +98,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
// Namespace and unknown macro (#3854) // Namespace and unknown macro (#3854)
else if (Token::Match(tok, "namespace %var% %type% (") && else if (Token::Match(tok, "namespace %var% %type% (") &&
_tokenizer->isCPP() && _tokenizer->isCPP() &&
CheckNullPointer::isUpper(tok->strAt(2)) && tok->tokAt(2)->isUpperCaseName() &&
Token::simpleMatch(tok->linkAt(3), ") {")) { Token::simpleMatch(tok->linkAt(3), ") {")) {
scopeList.push_back(Scope(this, tok, scope)); scopeList.push_back(Scope(this, tok, scope));

View File

@ -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) void Token::str(const std::string &s)
{ {
_str = s; _str = s;

View File

@ -170,6 +170,7 @@ public:
return _type == eName || _type == eType || _type == eVariable || _type == eFunction || return _type == eName || _type == eType || _type == eVariable || _type == eFunction ||
_type == eBoolean; // TODO: "true"/"false" aren't really a name... _type == eBoolean; // TODO: "true"/"false" aren't really a name...
} }
bool isUpperCaseName() const;
bool isNumber() const { bool isNumber() const {
return _type == eNumber; return _type == eNumber;
} }

View File

@ -3454,7 +3454,7 @@ void Tokenizer::removeMacrosInGlobalScope()
tok->deleteNext(); 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); const Token *tok2 = tok->tokAt(2);
if (tok2 && tok2->str() == "(") { if (tok2 && tok2->str() == "(") {
unsigned int par = 0; unsigned int par = 0;