Fix #279 (Refactoring: replace and remove Token::aaaa , Token::aaaa0 and Token::aaaa1)

http://apps.sourceforge.net/trac/cppcheck/ticket/279
This commit is contained in:
Reijo Tomperi 2009-05-03 21:10:59 +03:00
parent c9eab77683
commit cb209bbd41
8 changed files with 29 additions and 44 deletions

View File

@ -220,8 +220,8 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
continue; continue;
// Get index variable and stopsize. // Get index variable and stopsize.
const char *strindex = tok2->aaaa(); const char *strindex = tok2->str().c_str();
int value = ((tok2->next()->aaaa1() == '=') ? 1 : 0) + std::atoi(tok2->strAt(2)); int value = ((tok2->strAt(1)[1] == '=') ? 1 : 0) + std::atoi(tok2->strAt(2));
if (value <= size) if (value <= size)
continue; continue;
@ -305,10 +305,10 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
int len = 0; int len = 0;
for (const Token *tok2 = tok->tokAt(6); tok2 && tok2->str() != ")"; tok2 = tok2->next()) for (const Token *tok2 = tok->tokAt(6); tok2 && tok2->str() != ")"; tok2 = tok2->next())
{ {
if (tok2->aaaa0() == '\"') if (tok2->str()[0] == '\"')
{ {
len -= 2; len -= 2;
const char *str = tok->strAt(0); const char *str = tok->str().c_str();
while (*str) while (*str)
{ {
if (*str == '\\') if (*str == '\\')
@ -385,7 +385,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
continue; continue;
// Find function.. // Find function..
const Token *ftok = _tokenizer->GetFunctionTokenByName(tok->aaaa()); const Token *ftok = _tokenizer->GetFunctionTokenByName(tok->str().c_str());
if (!ftok) if (!ftok)
continue; continue;
@ -407,7 +407,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
{ {
// Parameter name.. // Parameter name..
const char *parname[2]; const char *parname[2];
parname[0] = ftok->aaaa(); parname[0] = ftok->str().c_str();
parname[1] = 0; parname[1] = 0;
// Goto function body.. // Goto function body..
@ -456,7 +456,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_GlobalAndLocalVariable()
{ {
varname[0] = tok->strAt(1); varname[0] = tok->strAt(1);
size = std::strtoul(tok->strAt(3), NULL, 10); size = std::strtoul(tok->strAt(3), NULL, 10);
type = tok->aaaa(); type = tok->str().c_str();
varid = tok->tokAt(1)->varId(); varid = tok->tokAt(1)->varId();
nextTok = 6; nextTok = 6;
} }

View File

@ -160,7 +160,7 @@ void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token
{ {
if (Assign && Token::Match(ftok, "%var% (")) if (Assign && Token::Match(ftok, "%var% ("))
{ {
InitVar(varlist, ftok->aaaa()); InitVar(varlist, ftok->str().c_str());
} }
Assign |= (ftok->str() == ":"); Assign |= (ftok->str() == ":");
@ -186,7 +186,7 @@ void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token
// Variable getting value from stream? // Variable getting value from stream?
if (Token::Match(ftok, ">> %var%")) if (Token::Match(ftok, ">> %var%"))
{ {
InitVar(varlist, ftok->next()->aaaa()); InitVar(varlist, ftok->next()->str().c_str());
} }
// Before a new statement there is "[{};)=]" or "else" // Before a new statement there is "[{};)=]" or "else"
@ -227,7 +227,7 @@ void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token
{ {
callstack.push_back(ftok->str()); callstack.push_back(ftok->str());
int i = 0; int i = 0;
const Token *ftok2 = Tokenizer::FindClassFunction(tok1, classname, ftok->aaaa(), i); const Token *ftok2 = Tokenizer::FindClassFunction(tok1, classname, ftok->str().c_str(), i);
ClassChecking_VarList_Initialize(tok1, ftok2, varlist, classname, callstack); ClassChecking_VarList_Initialize(tok1, ftok2, varlist, classname, callstack);
} }
} }
@ -235,13 +235,13 @@ void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token
// Assignment of member variable? // Assignment of member variable?
else if (Token::Match(ftok, "%var% =")) else if (Token::Match(ftok, "%var% ="))
{ {
InitVar(varlist, ftok->aaaa()); InitVar(varlist, ftok->str().c_str());
} }
// The functions 'clear' and 'Clear' are supposed to initialize variable. // The functions 'clear' and 'Clear' are supposed to initialize variable.
if (Token::Match(ftok, "%var% . clear|Clear (")) if (Token::Match(ftok, "%var% . clear|Clear ("))
{ {
InitVar(varlist, ftok->aaaa()); InitVar(varlist, ftok->str().c_str());
} }
} }
} }

View File

@ -97,7 +97,7 @@ void CheckHeaders::WarningIncludeHeader()
// Get fileindex of included file.. // Get fileindex of included file..
unsigned int hfile = 0; unsigned int hfile = 0;
const char *includefile = includetok->next()->aaaa(); const char *includefile = includetok->strAt(1);
while (hfile < _tokenizer->getFiles()->size()) while (hfile < _tokenizer->getFiles()->size())
{ {
if (FileLister::SameFileName(_tokenizer->getFiles()->at(hfile).c_str(), includefile)) if (FileLister::SameFileName(_tokenizer->getFiles()->at(hfile).c_str(), includefile))
@ -231,14 +231,14 @@ void CheckHeaders::WarningIncludeHeader()
if (! tok1->isName()) if (! tok1->isName())
continue; continue;
if (std::find(namelist.begin(), namelist.end(), tok1->aaaa()) != namelist.end()) if (std::find(namelist.begin(), namelist.end(), tok1->str().c_str()) != namelist.end())
{ {
Needed = true; Needed = true;
break; break;
} }
if (! NeedDeclaration) if (! NeedDeclaration)
NeedDeclaration = (std::find(classlist.begin(), classlist.end(), tok1->aaaa()) != classlist.end()); NeedDeclaration = (std::find(classlist.begin(), classlist.end(), tok1->str().c_str()) != classlist.end());
} }

View File

@ -574,7 +574,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
if ((tok->str() == "else") || (tok->str() == "switch")) if ((tok->str() == "else") || (tok->str() == "switch"))
{ {
addtoken(tok->aaaa()); addtoken(tok->str().c_str());
} }
if ((tok->str() == "case")) if ((tok->str() == "case"))
@ -1159,7 +1159,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
break; break;
} }
else if (strncmp(_tok->aaaa(), "if", 2) == 0) else if (strncmp(_tok->str().c_str(), "if", 2) == 0)
break; break;
else if (_tok->str() == "switch") else if (_tok->str() == "switch")

View File

@ -380,7 +380,7 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
// Parse "not" options. Token can be anything except the given one // Parse "not" options. Token can be anything except the given one
else if (str[1] == '!' && str[0] == '!' && str[2] != '\0') else if (str[1] == '!' && str[0] == '!' && str[2] != '\0')
{ {
if (strcmp(tok->aaaa(), &(str[2])) == 0) if (strcmp(tok->str().c_str(), &(str[2])) == 0)
return false; return false;
} }

View File

@ -36,21 +36,6 @@ public:
return _str; return _str;
} }
const char *aaaa() const
{
return _str.c_str();
}
char aaaa0() const
{
return _str[0];
}
char aaaa1() const
{
return _str[1];
}
/** /**
* Unlink and delete next token. * Unlink and delete next token.
*/ */

View File

@ -138,7 +138,7 @@ void Tokenizer::InsertTokens(Token *dest, Token *src, unsigned int n)
{ {
while (n > 0) while (n > 0)
{ {
dest->insertToken(src->aaaa()); dest->insertToken(src->str().c_str());
dest = dest->next(); dest = dest->next();
dest->fileIndex(src->fileIndex()); dest->fileIndex(src->fileIndex());
dest->linenr(src->linenr()); dest->linenr(src->linenr());
@ -1166,7 +1166,7 @@ void Tokenizer::simplifyTokenList()
if (! Token::Match(tok, "%type% %var% [ %num% ] ;")) if (! Token::Match(tok, "%type% %var% [ %num% ] ;"))
continue; continue;
int size = SizeOfType(tok->aaaa()); int size = SizeOfType(tok->str().c_str());
if (size <= 0) if (size <= 0)
continue; continue;
@ -1247,7 +1247,7 @@ void Tokenizer::simplifyTokenList()
// Replace "*(str + num)" => "str[num]" // Replace "*(str + num)" => "str[num]"
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
{ {
if (! strchr(";{}(=<>", tok->aaaa0())) if (! strchr(";{}(=<>", tok->str()[0]))
continue; continue;
Token *next = tok->next(); Token *next = tok->next();
@ -1928,23 +1928,23 @@ bool Tokenizer::simplifyVarDecl()
int parlevel = 0; int parlevel = 0;
while (tok2) while (tok2)
{ {
if (strchr("{(", tok2->aaaa0())) if (strchr("{(", tok2->str()[0]))
{ {
++parlevel; ++parlevel;
} }
else if (strchr("})", tok2->aaaa0())) else if (strchr("})", tok2->str()[0]))
{ {
if (parlevel < 0) if (parlevel < 0)
break; break;
--parlevel; --parlevel;
} }
else if (parlevel == 0 && strchr(";,", tok2->aaaa0())) else if (parlevel == 0 && strchr(";,", tok2->str()[0]))
{ {
// "type var =" => "type var; var =" // "type var =" => "type var; var ="
Token *VarTok = type0->tokAt(typelen); Token *VarTok = type0->tokAt(typelen);
if (VarTok->aaaa0() == '*') if (VarTok->str()[0] == '*')
VarTok = VarTok->next(); VarTok = VarTok->next();
InsertTokens(eq, VarTok, 2); InsertTokens(eq, VarTok, 2);
eq->str(";"); eq->str(";");
@ -2369,7 +2369,7 @@ void Tokenizer::fillFunctionList()
else else
{ {
tok = tok2; tok = tok2;
while (tok->next() && !strchr(";{", tok->next()->aaaa0())) while (tok->next() && !strchr(";{", tok->strAt(1)[0]))
tok = tok->next(); tok = tok->next();
} }
break; break;
@ -2438,7 +2438,7 @@ const char *Tokenizer::getParameterName(const Token *ftok, int par)
if (ftok->str() == ",") if (ftok->str() == ",")
++_par; ++_par;
if (par == _par && Token::Match(ftok, "%var% [,)]")) if (par == _par && Token::Match(ftok, "%var% [,)]"))
return ftok->aaaa(); return ftok->str().c_str();
} }
return NULL; return NULL;
} }

View File

@ -147,7 +147,7 @@ private:
unsigned int i = 0; unsigned int i = 0;
for (; expected[i] && actual; ++i, actual = actual->next()) for (; expected[i] && actual; ++i, actual = actual->next())
{ {
if (strcmp(expected[i], actual->aaaa()) != 0) if (strcmp(expected[i], actual->str().c_str()) != 0)
return false; return false;
} }
return (expected[i] == NULL && actual == NULL); return (expected[i] == NULL && actual == NULL);
@ -264,7 +264,7 @@ private:
tokenizer.fillFunctionList(); tokenizer.fillFunctionList();
ASSERT_EQUALS(1, static_cast<unsigned int>(tokenizer.getFunctionList().size())); ASSERT_EQUALS(1, static_cast<unsigned int>(tokenizer.getFunctionList().size()));
ASSERT_EQUALS(std::string("b"), tokenizer.getFunctionList()[0]->aaaa()); ASSERT_EQUALS(std::string("b"), tokenizer.getFunctionList()[0]->str());
} }
void const_and_volatile_functions() void const_and_volatile_functions()