From cb209bbd414dff4196cdac9f76f53887d7d2a2de Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sun, 3 May 2009 21:10:59 +0300 Subject: [PATCH] Fix #279 (Refactoring: replace and remove Token::aaaa , Token::aaaa0 and Token::aaaa1) http://apps.sourceforge.net/trac/cppcheck/ticket/279 --- src/checkbufferoverrun.cpp | 14 +++++++------- src/checkclass.cpp | 10 +++++----- src/checkheaders.cpp | 6 +++--- src/checkmemoryleak.cpp | 4 ++-- src/token.cpp | 2 +- src/token.h | 15 --------------- src/tokenize.cpp | 18 +++++++++--------- test/testtokenize.cpp | 4 ++-- 8 files changed, 29 insertions(+), 44 deletions(-) diff --git a/src/checkbufferoverrun.cpp b/src/checkbufferoverrun.cpp index d07e09782..5d455670d 100644 --- a/src/checkbufferoverrun.cpp +++ b/src/checkbufferoverrun.cpp @@ -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; } diff --git a/src/checkclass.cpp b/src/checkclass.cpp index 30477e77c..7dbc8b970 100644 --- a/src/checkclass.cpp +++ b/src/checkclass.cpp @@ -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()); } } } diff --git a/src/checkheaders.cpp b/src/checkheaders.cpp index dee4ac01e..d2bbb24e7 100644 --- a/src/checkheaders.cpp +++ b/src/checkheaders.cpp @@ -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()); } diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index d51ddfe62..c407db8d4 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -574,7 +574,7 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list 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") diff --git a/src/token.cpp b/src/token.cpp index 68b9450c8..2b28f6854 100644 --- a/src/token.cpp +++ b/src/token.cpp @@ -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; } diff --git a/src/token.h b/src/token.h index 743425cb3..6cab748d3 100644 --- a/src/token.h +++ b/src/token.h @@ -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. */ diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 31c9158cd..2249e738e 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -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; } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 6c25fb68f..6b483fb82 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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(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()