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

View File

@ -160,7 +160,7 @@ void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token
{
if (Assign && Token::Match(ftok, "%var% ("))
{
InitVar(varlist, ftok->aaaa());
InitVar(varlist, ftok->str().c_str());
}
Assign |= (ftok->str() == ":");
@ -186,7 +186,7 @@ void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token
// Variable getting value from stream?
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"
@ -227,7 +227,7 @@ void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token
{
callstack.push_back(ftok->str());
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);
}
}
@ -235,13 +235,13 @@ void CheckClass::ClassChecking_VarList_Initialize(const Token *tok1, const Token
// Assignment of member variable?
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.
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..
unsigned int hfile = 0;
const char *includefile = includetok->next()->aaaa();
const char *includefile = includetok->strAt(1);
while (hfile < _tokenizer->getFiles()->size())
{
if (FileLister::SameFileName(_tokenizer->getFiles()->at(hfile).c_str(), includefile))
@ -231,14 +231,14 @@ void CheckHeaders::WarningIncludeHeader()
if (! tok1->isName())
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;
break;
}
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"))
{
addtoken(tok->aaaa());
addtoken(tok->str().c_str());
}
if ((tok->str() == "case"))
@ -1159,7 +1159,7 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
break;
}
else if (strncmp(_tok->aaaa(), "if", 2) == 0)
else if (strncmp(_tok->str().c_str(), "if", 2) == 0)
break;
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
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;
}

View File

@ -36,21 +36,6 @@ public:
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.
*/

View File

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

View File

@ -147,7 +147,7 @@ private:
unsigned int i = 0;
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 (expected[i] == NULL && actual == NULL);
@ -264,7 +264,7 @@ private:
tokenizer.fillFunctionList();
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()