From bc267bbca5344a61395729922439e1bf68c74781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 24 Nov 2008 19:38:08 +0000 Subject: [PATCH] TOKEN: Refactoring the 'str' member variable --- CheckBufferOverrun.cpp | 46 +++++++++--------- CheckClass.cpp | 82 +++++++++++++++---------------- CheckFunctionUsage.cpp | 8 +-- CheckHeaders.cpp | 28 +++++------ CheckMemoryLeak.cpp | 108 ++++++++++++++++++++--------------------- CheckOther.cpp | 62 +++++++++++------------ testsimplifytokens.cpp | 2 +- testtokenize.cpp | 6 +-- token.cpp | 36 +++++++------- token.h | 20 +++++++- tokenize.cpp | 64 ++++++++++++------------ 11 files changed, 239 insertions(+), 223 deletions(-) diff --git a/CheckBufferOverrun.cpp b/CheckBufferOverrun.cpp index 623461c0b..d28d791f5 100644 --- a/CheckBufferOverrun.cpp +++ b/CheckBufferOverrun.cpp @@ -85,12 +85,12 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c int indentlevel = 0; for ( ; tok; tok = tok->next ) { - if (TOKEN::Match(tok, "{")) + if (tok->str() == "{") { indentlevel++; } - else if (TOKEN::Match(tok, "}")) + else if (tok->str() == "}") { indentlevel--; if ( indentlevel < 0 ) @@ -98,7 +98,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c } // Array index.. - if ( !TOKEN::Match(tok, "%var%") && !TOKEN::Match(tok,"[.&]") && TOKEN::Match(tok->next, "%var1% [ %num% ]", varname) ) + if ( !tok->isName() && !TOKEN::Match(tok,"[.&]") && TOKEN::Match(tok->next, "%var1% [ %num% ]", varname) ) { const char *num = tok->next->strAt(2 + varc); if (strtol(num, NULL, 10) >= size) @@ -151,8 +151,8 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c continue; // Get index variable and stopsize. - const char *strindex = tok2->str; - int value = (tok2->next->str[1] ? 1 : 0) + atoi(tok2->strAt(2)); + const char *strindex = tok2->aaaa(); + int value = ((tok2->next->aaaa1() == '=') ? 1 : 0) + atoi(tok2->strAt(2)); if ( value <= size ) continue; @@ -168,13 +168,13 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c int indentlevel2 = 0; while (tok2) { - if ( TOKEN::Match(tok2, ";") && indentlevel2 == 0 ) + if ( (tok2->str() == ";") && indentlevel2 == 0 ) break; - if ( TOKEN::Match(tok2, "{") ) + if ( tok2->str() == "{" ) indentlevel2++; - if ( TOKEN::Match(tok2, "}") ) + if ( tok2->str() == "}" ) { indentlevel2--; if ( indentlevel2 <= 0 ) @@ -225,12 +225,12 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c unsigned int parlevel = 0, par = 0; for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next ) { - if ( TOKEN::Match(tok2, "(") ) + if ( tok2->str() == "(" ) { parlevel++; } - else if ( TOKEN::Match(tok2, ")") ) + else if ( tok2->str() == ")" ) { parlevel--; if ( parlevel < 1 ) @@ -240,7 +240,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c } } - else if ( parlevel == 1 && TOKEN::Match(tok2, ",") ) + else if ( parlevel == 1 && (tok2->str() == ",") ) { par++; } @@ -256,7 +256,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c continue; // Find function.. - const TOKEN *ftok = _tokenizer->GetFunctionTokenByName( tok->str ); + const TOKEN *ftok = _tokenizer->GetFunctionTokenByName( tok->aaaa() ); if ( ! ftok ) continue; @@ -265,24 +265,24 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c parlevel = 1; while ( ftok && parlevel == 1 && par >= 1 ) { - if ( TOKEN::Match(ftok, "(") ) + if ( ftok->str() == "(" ) parlevel++; - else if ( TOKEN::Match(ftok, ")") ) + else if ( ftok->str() == ")" ) parlevel--; - else if ( TOKEN::Match(ftok, ",") ) + else if ( ftok->str() == "," ) par--; else if (par==1 && parlevel==1 && (TOKEN::Match(ftok, "%var% ,") || TOKEN::Match(ftok, "%var% )"))) { // Parameter name.. const char *parname[2]; - parname[0] = ftok->str; + parname[0] = ftok->aaaa(); parname[1] = 0; // Goto function body.. - while ( ftok && !TOKEN::Match(ftok,"{") ) + while ( ftok && (ftok->str() != "{") ) ftok = ftok->next; ftok = ftok ? ftok->next : 0; @@ -311,10 +311,10 @@ void CheckBufferOverrunClass::CheckBufferOverrun_LocalVariable() int indentlevel = 0; for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) { - if (TOKEN::Match(tok, "{")) + if (tok->str() == "{") indentlevel++; - else if (TOKEN::Match(tok, "}")) + else if (tok->str() == "}") indentlevel--; else if (indentlevel > 0) @@ -327,7 +327,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_LocalVariable() { varname[0] = tok->strAt(1); size = strtoul(tok->strAt(3), NULL, 10); - type = tok->str; + type = tok->aaaa(); } else if (indentlevel > 0 && TOKEN::Match(tok, "[*;{}] %var% = new %type% [ %num% ]")) { @@ -367,7 +367,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable() if (!TOKEN::Match(tok,"struct") && !TOKEN::Match(tok,"class")) continue; - const char *structname = tok->next->str; + const char *structname = tok->next->aaaa(); if ( !(tok->next->isName()) ) continue; @@ -393,7 +393,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable() const char *varname[3] = {0,0,0}; varname[1] = tok2->strAt(ivar); int arrsize = atoi(tok2->strAt(ivar+2)); - int total_size = arrsize * _tokenizer->SizeOfType(tok2->next->str); + int total_size = arrsize * _tokenizer->SizeOfType(tok2->next->aaaa()); if (total_size == 0) continue; @@ -423,7 +423,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable() for ( const TOKEN *tok3 = _tokenizer->tokens(); tok3; tok3 = tok3->next ) { - if ( strcmp(tok3->str, structname) ) + if ( strcmp(tok3->aaaa(), structname) ) continue; // Declare variable: Fred fred1; diff --git a/CheckClass.cpp b/CheckClass.cpp index fcbaf8e98..ac85c1c3d 100644 --- a/CheckClass.cpp +++ b/CheckClass.cpp @@ -57,9 +57,9 @@ struct VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1) if (!tok->next) break; - if (tok->str[0] == '{') + if (tok->aaaa0() == '{') indentlevel++; - if (tok->str[0] == '}') + if (tok->aaaa0() == '}') { if (indentlevel <= 1) break; @@ -67,7 +67,7 @@ struct VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1) } - if (indentlevel==1 && (strchr(";{}", tok->str[0]) || (tok->str[0]!=':' && strchr(tok->str, ':')))) + if (indentlevel==1 && (strchr(";{}", tok->aaaa0()) || (tok->aaaa0()!=':' && strchr(tok->aaaa(), ':')))) { const TOKEN *next = tok->next; @@ -79,9 +79,9 @@ struct VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1) const char *types[] = {"bool", "char", "int", "short", "long", "float", "double", 0}; for ( int type = 0; types[type]; type++ ) { - if ( strcmp(next->str, types[type]) == 0) + if ( strcmp(next->aaaa(), types[type]) == 0) { - varname = next->next->str; + varname = next->next->aaaa(); break; } } @@ -132,7 +132,7 @@ const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classn indentlevel = 1; } - if ( tok->str[0] == '{' ) + if ( tok->aaaa0() == '{' ) { // If indentlevel==0 don't go to indentlevel 1. Skip the block. if ( indentlevel > 0 ) @@ -142,9 +142,9 @@ const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classn { for ( ; tok; tok = tok->next ) { - if ( tok->str[0] == '{' ) + if ( tok->aaaa0() == '{' ) ++indentlevel; - else if ( tok->str[0] == '}' ) + else if ( tok->aaaa0() == '}' ) { --indentlevel; if ( indentlevel <= 0 ) @@ -158,7 +158,7 @@ const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classn } } - if ( tok->str[0] == '}' ) + if ( tok->aaaa0() == '}' ) { indentlevel--; if ( indentlevel < 0 ) @@ -171,9 +171,9 @@ const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classn if ( TOKEN::Match( tok, "%var1% (", _funcname ) ) { const TOKEN *tok2 = tok; - while ( tok2 && tok2->str[0] != '{' && tok2->str[0] != ';' ) + while ( tok2 && tok2->aaaa0() != '{' && tok2->aaaa0() != ';' ) tok2 = tok2->next; - if ( tok2 && tok2->str[0] == '{' ) + if ( tok2 && tok2->aaaa0() == '{' ) return tok; } } @@ -218,20 +218,20 @@ void CheckClass::ClassChecking_VarList_Initialize(const TOKEN *tok1, const TOKEN { if (Assign && TOKEN::Match(ftok, "%var% (")) { - InitVar( varlist, ftok->str ); + InitVar( varlist, ftok->aaaa() ); } - Assign |= (ftok->str[0] == ':'); + Assign |= (ftok->aaaa0() == ':'); } - if (ftok->str[0] == '{') + if (ftok->aaaa0() == '{') { indentlevel++; Assign = false; } - if (ftok->str[0] == '}') + if (ftok->aaaa0() == '}') { if (indentlevel <= 1) break; @@ -275,11 +275,11 @@ void CheckClass::ClassChecking_VarList_Initialize(const TOKEN *tok1, const TOKEN else if (TOKEN::Match(ftok, "%var% (")) { // No recursive calls! - if ( std::find(callstack.begin(),callstack.end(),ftok->str) == callstack.end() ) + if ( std::find(callstack.begin(),callstack.end(),ftok->aaaa()) == callstack.end() ) { - callstack.push_back( ftok->str ); + callstack.push_back( ftok->aaaa() ); int i = 0; - const TOKEN *ftok2 = FindClassFunction( tok1, classname, ftok->str, i ); + const TOKEN *ftok2 = FindClassFunction( tok1, classname, ftok->aaaa(), i ); ClassChecking_VarList_Initialize(tok1, ftok2, varlist, classname, callstack); } } @@ -287,13 +287,13 @@ void CheckClass::ClassChecking_VarList_Initialize(const TOKEN *tok1, const TOKEN // Assignment of member variable? else if (TOKEN::Match(ftok, "%var% =")) { - InitVar( varlist, ftok->str ); + InitVar( varlist, ftok->aaaa() ); } // The functions 'clear' and 'Clear' are supposed to initialize variable. if (TOKEN::Match(ftok,"%var% . clear (") || TOKEN::Match(ftok,"%var% . Clear (")) { - InitVar( varlist, ftok->str ); + InitVar( varlist, ftok->aaaa() ); } } } @@ -314,7 +314,7 @@ void CheckClass::CheckConstructors() const TOKEN *tok1 = TOKEN::findtoken(_tokenizer->tokens(), pattern_classname); while (tok1) { - const char *classname = tok1->next->str; + const char *classname = tok1->next->aaaa(); if ( !(tok1->next->isName()) ) { tok1 = TOKEN::findtoken( tok1->next, pattern_classname ); @@ -325,7 +325,7 @@ void CheckClass::CheckConstructors() const char *constructor_pattern[] = {"","clKalle","(",NULL}; constructor_pattern[1] = classname; const TOKEN *constructor_token = TOKEN::findtoken( _tokenizer->tokens(), constructor_pattern ); - while ( constructor_token && constructor_token->str[0] == '~' ) + while ( constructor_token && constructor_token->aaaa0() == '~' ) constructor_token = TOKEN::findtoken( constructor_token->next, constructor_pattern ); if ( ! constructor_token ) { @@ -414,7 +414,7 @@ void CheckClass::CheckUnusedPrivateFunctions() const char *pattern_class[] = {"class","","{",NULL}; for (const TOKEN *tok1 = TOKEN::findtoken(_tokenizer->tokens(), pattern_class); tok1; tok1 = TOKEN::findtoken(tok1->next, pattern_class)) { - const char *classname = tok1->next->str; + const char *classname = tok1->next->aaaa(); // The class implementation must be available.. const char *pattern_classconstructor[] = {"","::","",NULL}; @@ -437,21 +437,21 @@ void CheckClass::CheckUnusedPrivateFunctions() break; } - if (tok->str[0] == '{') + if (tok->aaaa0() == '{') indent_level++; - if (tok->str[0] == '}') + if (tok->aaaa0() == '}') { if (indent_level <= 1) break; indent_level--; } - if (strcmp(tok->str,"};") == 0) + if (strcmp(tok->aaaa(),"};") == 0) break; - if (strcmp(tok->str,"private:") == 0) + if (strcmp(tok->aaaa(),"private:") == 0) priv = true; - else if (strcmp(tok->str,"public:") == 0) + else if (strcmp(tok->aaaa(),"public:") == 0) priv = false; - else if (strcmp(tok->str,"protected:") == 0) + else if (strcmp(tok->aaaa(),"protected:") == 0) priv = false; else if (priv && indent_level == 1) { @@ -461,7 +461,7 @@ void CheckClass::CheckUnusedPrivateFunctions() if (TOKEN::Match(tok, "%var% (") && !TOKEN::Match(tok,classname)) { - FuncList.push_back(tok->str); + FuncList.push_back(tok->aaaa()); } } } @@ -475,11 +475,11 @@ void CheckClass::CheckUnusedPrivateFunctions() { ftok = TOKEN::findtoken(ftok,pattern_function); int numpar = 0; - while (ftok && ftok->str[0]!=';' && ftok->str[0]!='{') + while (ftok && ftok->aaaa0()!=';' && ftok->aaaa0()!='{') { - if (ftok->str[0] == '(') + if (ftok->aaaa0() == '(') numpar++; - else if (ftok->str[0] == ')') + else if (ftok->aaaa0() == ')') numpar--; ftok = ftok->next; } @@ -487,23 +487,23 @@ void CheckClass::CheckUnusedPrivateFunctions() if (!ftok) break; - if (ftok->str[0] != ';' && numpar == 0) + if (ftok->aaaa0() != ';' && numpar == 0) { HasFuncImpl = true; indent_level = 0; while (ftok) { - if (ftok->str[0] == '{') + if (ftok->aaaa0() == '{') indent_level++; - if (ftok->str[0] == '}') + if (ftok->aaaa0() == '}') { if (indent_level<=1) break; indent_level--; } - if (ftok->next && ftok->next->str[0] == '(') - FuncList.remove(ftok->str); + if (ftok->next && ftok->next->aaaa0() == '(') + FuncList.remove(ftok->aaaa()); ftok = ftok->next; } } @@ -575,7 +575,7 @@ void CheckClass::CheckMemset() if (TOKEN::findtoken(_tokenizer->tokens(),pattern1)) { std::ostringstream ostr; - ostr << _tokenizer->fileLine(tok) << ": Using '" << tok->str << "' on class."; + ostr << _tokenizer->fileLine(tok) << ": Using '" << tok->aaaa() << "' on class."; _errorLogger->reportErr(ostr.str()); continue; } @@ -585,13 +585,13 @@ void CheckClass::CheckMemset() pattern2[1] = type; for (const TOKEN *tstruct = TOKEN::findtoken(_tokenizer->tokens(), pattern2); tstruct; tstruct = tstruct->next) { - if (tstruct->str[0] == '}') + if (tstruct->aaaa0() == '}') break; if (TOKEN::Match(tstruct, "std :: %type% %var% ;")) { std::ostringstream ostr; - ostr << _tokenizer->fileLine(tok) << ": Using '" << tok->str << "' on struct that contains a 'std::" << tstruct->strAt(2) << "'"; + ostr << _tokenizer->fileLine(tok) << ": Using '" << tok->aaaa() << "' on struct that contains a 'std::" << tstruct->strAt(2) << "'"; _errorLogger->reportErr(ostr.str()); break; } diff --git a/CheckFunctionUsage.cpp b/CheckFunctionUsage.cpp index 47155f115..136a1939a 100644 --- a/CheckFunctionUsage.cpp +++ b/CheckFunctionUsage.cpp @@ -71,7 +71,7 @@ void CheckFunctionUsage::parseTokens( const Tokenizer &tokenizer ) if ( funcname ) { - FunctionUsage &func = _functions[ funcname->str ]; + FunctionUsage &func = _functions[ funcname->aaaa() ]; // No filename set yet.. if (func.filename.empty()) @@ -107,10 +107,10 @@ void CheckFunctionUsage::parseTokens( const Tokenizer &tokenizer ) int parlevel = 0; for ( const TOKEN *tok2 = funcname; tok2; tok2 = tok2->next ) { - if (TOKEN::Match(tok2, "(")) + if (tok2->str() == "(") ++parlevel; - else if (TOKEN::Match(tok2, ")")) + else if (tok2->str() == ")") { --parlevel; if (parlevel == 0 && (TOKEN::Match(tok2, ") {") || TOKEN::Match(tok2, ") const"))) @@ -123,7 +123,7 @@ void CheckFunctionUsage::parseTokens( const Tokenizer &tokenizer ) if ( funcname ) { - FunctionUsage &func = _functions[ funcname->str ]; + FunctionUsage &func = _functions[ funcname->aaaa() ]; if ( func.filename.empty() || func.filename == "+" ) func.usedOtherFile = true; diff --git a/CheckHeaders.cpp b/CheckHeaders.cpp index 014bee1b7..e2c6d95a6 100644 --- a/CheckHeaders.cpp +++ b/CheckHeaders.cpp @@ -85,12 +85,12 @@ void CheckHeaders::WarningIncludeHeader() // Including.. for ( const TOKEN *includetok = _tokenizer->tokens(); includetok; includetok = includetok->next) { - if (strcmp(includetok->str, "#include") != 0) + if (strcmp(includetok->aaaa(), "#include") != 0) continue; // Get fileindex of included file.. unsigned int hfile = 0; - const char *includefile = includetok->next->str; + const char *includefile = includetok->next->aaaa(); while (hfile < _tokenizer->getFiles()->size()) { if ( Tokenizer::SameFileName( _tokenizer->getFiles()->at(hfile).c_str(), includefile ) ) @@ -118,10 +118,10 @@ void CheckHeaders::WarningIncludeHeader() continue; // I'm only interested in stuff that is declared at indentlevel 0 - if (tok1->str[0] == '{') + if (tok1->aaaa0() == '{') indentlevel++; - else if (tok1->str[0] == '}') + else if (tok1->aaaa0() == '}') indentlevel--; if (indentlevel != 0) @@ -148,13 +148,13 @@ void CheckHeaders::WarningIncludeHeader() // enum.. // -------------------------------------- - else if (strcmp(tok1->str, "enum") == 0) + else if (strcmp(tok1->aaaa(), "enum") == 0) { tok1 = tok1->next; - while (tok1->next && tok1->str[0]!=';') + while (tok1->next && tok1->aaaa0()!=';') { if ( tok1->isName() ) - namelist.push_back(tok1->str); + namelist.push_back(tok1->aaaa()); tok1 = tok1->next; } } @@ -175,26 +175,26 @@ void CheckHeaders::WarningIncludeHeader() // typedef.. // -------------------------------------- - else if (strcmp(tok1->str,"typedef")==0) + else if (strcmp(tok1->aaaa(),"typedef")==0) { if (strcmp(tok1->strAt(1),"enum")==0) continue; int parlevel = 0; while (tok1->next) { - if ( strchr("({", tok1->str[0]) ) + if ( strchr("({", tok1->aaaa0()) ) parlevel++; - else if ( strchr(")}", tok1->str[0]) ) + else if ( strchr(")}", tok1->aaaa0()) ) parlevel--; else if (parlevel == 0) { - if ( tok1->str[0] == ';' ) + if ( tok1->aaaa0() == ';' ) break; if ( TOKEN::Match(tok1, "%var% ;") ) - namelist.push_back(tok1->str); + namelist.push_back(tok1->aaaa()); } tok1 = tok1->next; @@ -224,14 +224,14 @@ void CheckHeaders::WarningIncludeHeader() if ( ! tok1->isName() ) continue; - if (std::find(namelist.begin(),namelist.end(),tok1->str ) != namelist.end()) + if (std::find(namelist.begin(),namelist.end(),tok1->aaaa() ) != namelist.end()) { Needed = true; break; } if ( ! NeedDeclaration ) - NeedDeclaration = (std::find(classlist.begin(),classlist.end(),tok1->str ) != classlist.end()); + NeedDeclaration = (std::find(classlist.begin(),classlist.end(),tok1->aaaa() ) != classlist.end()); } diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index c803fde27..6890bbc07 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -74,9 +74,9 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetAllocationType( const T // * var = (char *)malloc(10); // * var = new char[10]; // * var = strdup("hello"); - if ( tok2 && tok2->str[0] == '(' ) + if ( tok2 && tok2->aaaa0() == '(' ) { - while ( tok2 && tok2->str[0] != ')' ) + while ( tok2 && tok2->aaaa0() != ')' ) tok2 = tok2->next; tok2 = tok2 ? tok2->next : NULL; } @@ -93,7 +93,7 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetAllocationType( const T 0}; for ( unsigned int i = 0; mallocfunc[i]; i++ ) { - if ( strcmp(mallocfunc[i], tok2->str) == 0 ) + if ( strcmp(mallocfunc[i], tok2->aaaa()) == 0 ) return Malloc; } @@ -115,7 +115,7 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetAllocationType( const T 0}; for ( unsigned int i = 0; gmallocfunc[i]; i++ ) { - if ( strcmp(gmallocfunc[i], tok2->str) == 0 ) + if ( strcmp(gmallocfunc[i], tok2->aaaa()) == 0 ) return gMalloc; } @@ -135,7 +135,7 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetAllocationType( const T std::list::const_iterator it = _listAllocFunc.begin(); while ( it != _listAllocFunc.end() ) { - if ( strcmp(tok2->str, it->funcname) == 0 ) + if ( strcmp(tok2->aaaa(), it->funcname) == 0 ) return it->alloctype; ++it; } @@ -149,7 +149,7 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetDeallocationType( const if ( TOKEN::Match(tok, "if ( %var1% )", varnames) ) { tok = tok->tokAt(4); - if ( TOKEN::Match(tok,"{") ) + if (tok->str() =="{") tok = tok->next; } @@ -189,10 +189,10 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list 2 ) return "dealloc"; - const char *funcname = tok->str; + const char *funcname = tok->aaaa(); for ( std::list::const_iterator it = callstack.begin(); it != callstack.end(); ++it ) { - if ( std::string(funcname) == (*it)->str ) + if ( std::string(funcname) == (*it)->aaaa() ) return "dealloc"; } callstack.push_back(tok); @@ -201,9 +201,9 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::listnext ) { - if ( TOKEN::Match(tok, "(") ) + if ( tok->str() == "(" ) ++parlevel; - else if ( TOKEN::Match(tok, ")") ) + else if ( tok->str() == ")" ) { --parlevel; if ( parlevel < 1 ) @@ -212,7 +212,7 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::liststr() == "," ) ++par; if ( TOKEN::Match(tok, "[,()] %var1% [,()]", varnames) ) { @@ -221,7 +221,7 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::liststr() != "{") ) ftok = ftok->next; TOKEN *func = getcode( ftok->tokAt(1), callstack, parname, alloctype, dealloctype ); simplifycode( func ); @@ -312,12 +312,12 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list int parlevel = 0; for ( ; tok; tok = tok->next ) { - if ( tok->str[0] == '{' ) + if ( tok->aaaa0() == '{' ) { addtoken( "{" ); indentlevel++; } - else if ( tok->str[0] == '}' ) + else if ( tok->aaaa0() == '}' ) { addtoken( "}" ); if ( indentlevel <= 0 ) @@ -325,13 +325,13 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list indentlevel--; } - if ( tok->str[0] == '(' ) + if ( tok->aaaa0() == '(' ) parlevel++; - else if ( tok->str[0] == ')' ) + else if ( tok->aaaa0() == ')' ) parlevel--; isloop &= ( parlevel > 0 ); - if ( parlevel == 0 && tok->str[0]==';') + if ( parlevel == 0 && tok->aaaa0()==';') addtoken(";"); if (TOKEN::Match(tok, "[(;{}] %var1% =", varnames)) @@ -397,15 +397,15 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list int parlevel = 0; for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next ) { - if ( TOKEN::Match(tok2,"(") ) + if ( tok2->str() == "(" ) ++parlevel; - if ( TOKEN::Match(tok2,")") ) + if ( tok2->str() == ")" ) { --parlevel; if ( parlevel <= 0 ) break; } - if ( !TOKEN::Match(tok2,".") && + if ( (tok2->str() != ".") && TOKEN::Match(tok2->next, "%var1%", varnames) && !TOKEN::Match(tok2->next, "%var1% .", varnames) ) { @@ -415,30 +415,30 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list } addtoken( (dep ? "ifv" : "if") ); } - else if ( TOKEN::Match(tok, "else") || TOKEN::Match(tok, "switch") ) + else if ( (tok->str() == "else") || (tok->str() == "switch") ) { - addtoken(tok->str); + addtoken(tok->aaaa()); } - if ( TOKEN::Match(tok, "case") ) + if ( (tok->str() == "case") ) { addtoken("case"); addtoken(";"); } - if ( TOKEN::Match(tok, "default") ) + if ( (tok->str() == "default") ) { addtoken("case"); addtoken(";"); } // Loops.. - if (TOKEN::Match(tok, "for") || TOKEN::Match(tok, "while") ) + if ((tok->str() == "for") || (tok->str() == "while") ) { addtoken("loop"); isloop = true; } - if ( TOKEN::Match(tok, "do") ) + if ( (tok->str() == "do") ) { addtoken("do"); } @@ -446,19 +446,19 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list addtoken("!var"); // continue / break.. - if ( TOKEN::Match(tok, "continue") ) + if ( tok->str() == "continue" ) addtoken("continue"); - if ( TOKEN::Match(tok, "break") ) + if ( tok->str() == "break" ) addtoken("break"); // goto.. - if ( TOKEN::Match(tok, "goto") ) + if ( tok->str() == "goto" ) { addtoken("goto"); } // Return.. - if ( TOKEN::Match(tok, "return") ) + if ( tok->str() == "return" ) { addtoken("return"); if ( TOKEN::Match(tok, "return %var1%", varnames) || @@ -467,7 +467,7 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list } // throw.. - if ( TOKEN::Match(tok, "throw") ) + if ( tok->str() == "throw" ) addtoken("throw"); // Assignment.. @@ -532,13 +532,13 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok) int indentlevel = 0; for ( tok2_ = tok2; tok2_ && indentlevel>=0; tok2_ = tok2_->next ) { - if ( TOKEN::Match(tok2_, "{") ) + if ( tok2_->str() == "{" ) ++indentlevel; - else if ( TOKEN::Match(tok2_, "}") ) + else if ( tok2_->str() == "}" ) --indentlevel; - else if ( indentlevel == 0 && TOKEN::Match(tok2_->next, ";") ) + else if ( indentlevel == 0 && (tok2_->next->str() == ";") ) break; } @@ -550,13 +550,13 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok) indentlevel = 0; do { - if ( TOKEN::Match( tok2, "{" ) ) + if ( tok2->str() == "{" ) ++indentlevel; - else if ( TOKEN::Match(tok2, "}") ) + else if ( tok2->str() == "}" ) --indentlevel; // Copy token.. - instoken( tok2_, tok2->str ); + instoken( tok2_, tok2->aaaa() ); // Next token.. tok2 = tok2->next; @@ -713,22 +713,22 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok) bool incase = false; for ( const TOKEN * _tok = tok2->tokAt(2); _tok; _tok = _tok->next ) { - if ( _tok->str[0] == '{' ) + if ( _tok->aaaa0() == '{' ) break; - else if ( _tok->str[0] == '}' ) + else if ( _tok->aaaa0() == '}' ) { valid = true; break; } - else if (strncmp(_tok->str,"if",2)==0) + else if (strncmp(_tok->aaaa(),"if",2)==0) break; - else if (strcmp(_tok->str,"switch")==0) + else if (strcmp(_tok->aaaa(),"switch")==0) break; - else if (strcmp(_tok->str,"loop")==0) + else if (strcmp(_tok->aaaa(),"loop")==0) break; else if (incase && TOKEN::Match(_tok,"case")) @@ -762,7 +762,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok) instoken( tok2, "if" ); instoken( tok2, "else" ); } - while ( tok2 && tok2->str[0] != '}' && ! TOKEN::Match(tok2,"break ;") ) + while ( tok2 && tok2->aaaa0() != '}' && ! TOKEN::Match(tok2,"break ;") ) tok2 = tok2->next; if (TOKEN::Match(tok2,"break ;")) { @@ -885,10 +885,10 @@ void CheckMemoryLeakClass::CheckMemoryLeak_InFunction() int indentlevel = 0; for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) { - if (tok->str[0]=='{') + if (tok->aaaa0()=='{') indentlevel++; - else if (tok->str[0]=='}') + else if (tok->aaaa0()=='}') indentlevel--; @@ -928,10 +928,10 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers() int indentlevel = 0; for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next ) { - if ( tok->str[0] == '{' ) + if ( tok->aaaa0() == '{' ) indentlevel++; - else if ( tok->str[0] == '}' ) + else if ( tok->aaaa0() == '}' ) indentlevel--; else if ( indentlevel == 0 && TOKEN::Match(tok, "class %var% [{:]") ) @@ -947,7 +947,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers() void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN *tok1, std::vector &classname ) { // Go into class. - while ( tok1 && tok1->str[0] != '{' ) + while ( tok1 && tok1->aaaa0() != '{' ) tok1 = tok1->next; if ( tok1 ) tok1 = tok1->next; @@ -955,10 +955,10 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN int indentlevel = 0; for ( const TOKEN *tok = tok1; tok; tok = tok->next ) { - if ( tok->str[0] == '{' ) + if ( tok->aaaa0() == '{' ) indentlevel++; - else if ( tok->str[0] == '}' ) + else if ( tok->aaaa0() == '}' ) { indentlevel--; if ( indentlevel < 0 ) @@ -980,7 +980,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN // Declaring member variable.. check allocations and deallocations if ( TOKEN::Match(tok->next, "%type% * %var% ;") ) { - if ( tok->isName() || strchr(";}", tok->str[0]) ) + if ( tok->isName() || strchr(";}", tok->aaaa0()) ) { if (_settings._showAll || !isclass(tok->strAt(1))) CheckMemoryLeak_ClassMembers_Variable( classname, tok->strAt(3) ); @@ -1026,16 +1026,16 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable( const std::vec int indentlevel = 0; for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next ) { - if ( tok->str[0] == '{' ) + if ( tok->aaaa0() == '{' ) indentlevel++; - else if ( tok->str[0] == '}' ) + else if ( tok->aaaa0() == '}' ) indentlevel--; // Set the 'memberfunction' variable.. if ( indentlevel == 0 ) { - if ( strchr(";}", tok->str[0]) ) + if ( strchr(";}", tok->aaaa0()) ) memberfunction = false; else if ( TOKEN::Match( tok, fpattern.str().c_str() ) || TOKEN::Match( tok, destructor.str().c_str() ) ) memberfunction = true; diff --git a/CheckOther.cpp b/CheckOther.cpp index 376dc2363..81d2f3c4d 100644 --- a/CheckOther.cpp +++ b/CheckOther.cpp @@ -101,7 +101,7 @@ void CheckOther::WarningIsAlpha() { for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) { - if ( ! TOKEN::Match(tok, "(") ) + if ( tok->str() != "(" ) continue; bool err = false; @@ -161,7 +161,7 @@ void CheckOther::WarningRedundantCode() // if (p) delete p for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) { - if (!TOKEN::Match(tok,"if")) + if ( tok->str() != "if" ) continue; const char *varname1 = NULL; @@ -181,7 +181,7 @@ void CheckOther::WarningRedundantCode() if (varname1==NULL || tok2==NULL) continue; - if ( TOKEN::Match(tok2, "{") ) + if ( tok2->str() == "{" ) tok2 = tok2->next; bool err = false; @@ -223,14 +223,14 @@ void CheckOther::WarningIf() // Search for 'if (condition);' for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) { - if (TOKEN::Match(tok,"if")) + if (tok->str() == "if") { int parlevel = 0; for (const TOKEN *tok2 = tok->next; tok2; tok2 = tok2->next) { - if (TOKEN::Match(tok2,"(")) + if (tok2->str() == "(") parlevel++; - else if (TOKEN::Match(tok2,")")) + else if (tok2->str() == ")") { parlevel--; if (parlevel<=0) @@ -312,7 +312,7 @@ void CheckOther::InvalidFunctionUsage() { for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next ) { - if (!TOKEN::Match(tok, "strtol") && !TOKEN::Match(tok, "strtoul")) + if ((tok->str() != "strtol") && (tok->str() != "strtoul")) continue; // Locate the third parameter of the function call.. @@ -447,21 +447,21 @@ void CheckOther::CheckVariableScope() for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next ) { // Skip class and struct declarations.. - if ( TOKEN::Match(tok, "class") || TOKEN::Match(tok, "struct") ) + if ( (tok->str() == "class") || (tok->str() == "struct") ) { for (const TOKEN *tok2 = tok; tok2; tok2 = tok2->next) { - if ( TOKEN::Match(tok2, "{") ) + if ( tok2->str() == "{" ) { int _indentlevel = 0; tok = tok2; for (tok = tok2; tok; tok = tok->next) { - if ( TOKEN::Match(tok, "{") ) + if ( tok->str() == "{" ) { _indentlevel++; } - if ( TOKEN::Match(tok, "}") ) + if ( tok->str() == "}" ) { _indentlevel--; if ( _indentlevel <= 0 ) @@ -482,11 +482,11 @@ void CheckOther::CheckVariableScope() break; } - if ( TOKEN::Match(tok, "{") ) + if ( tok->str() == "{" ) { indentlevel++; } - if ( TOKEN::Match(tok, "}") ) + if ( tok->str() == "}" ) { indentlevel--; if ( indentlevel == 0 ) @@ -503,10 +503,10 @@ void CheckOther::CheckVariableScope() if ( ! tok1 ) continue; - if (TOKEN::Match(tok1,"return") || - TOKEN::Match(tok1,"delete") || - TOKEN::Match(tok1,"goto") || - TOKEN::Match(tok1,"else")) + if ((tok1->str() == "return") || + (tok1->str() == "delete") || + (tok1->str() == "goto") || + (tok1->str() == "else")) continue; // Variable declaration? @@ -536,12 +536,12 @@ void CheckOther::CheckVariableScope_LookupVar( const TOKEN *tok1, const char var bool for_or_while = false; while ( indentlevel >= 0 && tok ) { - if ( TOKEN::Match(tok, "{") ) + if ( tok->str() == "{" ) { indentlevel++; } - else if ( TOKEN::Match(tok, "}") ) + else if ( tok->str() == "}" ) { indentlevel--; if ( indentlevel == 0 ) @@ -553,18 +553,18 @@ void CheckOther::CheckVariableScope_LookupVar( const TOKEN *tok1, const char var } } - else if ( TOKEN::Match(tok, "(") ) + else if ( tok->str() == "(" ) { parlevel++; } - else if ( TOKEN::Match(tok, ")") ) + else if ( tok->str() == ")" ) { parlevel--; } - else if ( strcmp(tok->strAt( 0), varname) == 0 ) + else if ( tok->str() == varname ) { if ( indentlevel == 0 || used1 ) return; @@ -573,9 +573,9 @@ void CheckOther::CheckVariableScope_LookupVar( const TOKEN *tok1, const char var else if ( indentlevel==0 ) { - if ( TOKEN::Match(tok,"for") || TOKEN::Match(tok,"while") ) + if ( (tok->str() == "for") || (tok->str() == "while") ) for_or_while = true; - if ( parlevel == 0 && TOKEN::Match(tok, ";") ) + if ( parlevel == 0 && (tok->str() == ";") ) for_or_while = false; } @@ -641,7 +641,7 @@ void CheckOther::CheckStructMemberUsage() { if ( tok->FileIndex != 0 ) continue; - if ( TOKEN::Match(tok,"}") ) + if ( tok->str() == "}" ) structname = 0; if ( TOKEN::Match(tok, "struct %type% {") ) structname = tok->strAt( 1); @@ -710,17 +710,17 @@ void CheckOther::CheckCharVariable() int indentlevel = 0; for ( const TOKEN *tok2 = tok->next; tok2; tok2 = tok2->next ) { - if ( TOKEN::Match(tok2, "{") ) + if ( tok2->str() == "{" ) ++indentlevel; - else if ( TOKEN::Match(tok2, "}") ) + else if ( tok2->str() == "}" ) { --indentlevel; if ( indentlevel <= 0 ) break; } - if (!TOKEN::Match(tok2,".") && TOKEN::Match(tok2->next, "%var% [ %var1% ]", varname)) + if ((tok2->str() != ".") && TOKEN::Match(tok2->next, "%var% [ %var1% ]", varname)) { std::ostringstream errmsg; errmsg << _tokenizer->fileLine(tok2->next) << ": Warning - using char variable as array index"; @@ -756,15 +756,15 @@ void CheckOther::CheckIncompleteStatement() for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next ) { - if ( TOKEN::Match(tok, "(") ) + if ( tok->str() == "(" ) ++parlevel; - else if ( TOKEN::Match(tok, ")") ) + else if ( tok->str() == ")" ) --parlevel; if ( parlevel != 0 ) continue; - if ( !TOKEN::Match(tok,"#") && TOKEN::Match(tok->next,"; %str%") && !TOKEN::Match(tok->tokAt(3), ",") ) + if ( (tok->str() != "#") && TOKEN::Match(tok->next,"; %str%") && !TOKEN::Match(tok->tokAt(3), ",") ) { std::ostringstream errmsg; errmsg << _tokenizer->fileLine(tok->next) << ": Redundant code: Found a statement that begins with string constant"; diff --git a/testsimplifytokens.cpp b/testsimplifytokens.cpp index a8ed8658b..8007bd026 100644 --- a/testsimplifytokens.cpp +++ b/testsimplifytokens.cpp @@ -49,7 +49,7 @@ private: std::string ret; for ( const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next ) { - ret += std::string(tok->str) + " "; + ret += std::string(tok->aaaa()) + " "; } return ret; diff --git a/testtokenize.cpp b/testtokenize.cpp index 1f28b6798..0cea45f6e 100644 --- a/testtokenize.cpp +++ b/testtokenize.cpp @@ -51,7 +51,7 @@ private: unsigned int i = 0; for (; expected[i] && actual; ++i, actual = actual->next) { - if ( strcmp( expected[i], actual->str ) != 0) + if ( strcmp( expected[i], actual->aaaa() ) != 0) return false; } return (expected[i] == NULL && actual == NULL); @@ -94,7 +94,7 @@ private: tokenizer.TokenizeCode(istr, 0); // Expected result.. - ASSERT_EQUALS( std::string(10000,'a'), std::string(tokenizer.tokens()->str) ); + ASSERT_EQUALS( std::string(10000,'a'), std::string(tokenizer.tokens()->aaaa()) ); } @@ -149,7 +149,7 @@ private: tokenizer.fillFunctionList(); ASSERT_EQUALS( 1, tokenizer._functionList.size() ); - ASSERT_EQUALS( std::string("b"), tokenizer._functionList[0]->str ); + ASSERT_EQUALS( std::string("b"), tokenizer._functionList[0]->aaaa() ); } }; diff --git a/token.cpp b/token.cpp index 6f3e79361..ac33013ea 100644 --- a/token.cpp +++ b/token.cpp @@ -28,7 +28,8 @@ TOKEN::TOKEN() { FileIndex = 0; - _str = 0; + _cstr = 0; + _str = ""; linenr = 0; next = 0; _isName = false; @@ -37,28 +38,27 @@ TOKEN::TOKEN() TOKEN::~TOKEN() { - std::free(_str); + std::free(_cstr); } void TOKEN::setstr( const char s[] ) -{ - std::free(_str); +{ + _str = s; + std::free(_cstr); #ifndef _MSC_VER - _str = strdup(s); + _cstr = strdup(s); #else - _str = _strdup(s); + _cstr = _strdup(s); #endif - str = _str ? _str : ""; - - _isName = bool(str[0]=='_' || isalpha(str[0])); - _isNumber = bool(isdigit(str[0]) != 0); + _isName = bool(_str[0]=='_' || isalpha(_str[0])); + _isNumber = bool(isdigit(_str[0]) != 0); } void TOKEN::combineWithNext(const char str1[], const char str2[]) { if (!(next)) return; - if (strcmp(str,str1) || strcmp(next->str,str2)) + if (_str!=str1 || next->_str!=str2) return; std::string newstr(std::string(str1) + std::string(str2)); @@ -87,7 +87,7 @@ const TOKEN *TOKEN::tokAt(int index) const const char *TOKEN::strAt(int index) const { const TOKEN *tok = this->tokAt(index); - return tok ? tok->str : ""; + return tok ? tok->_cstr : ""; } bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[], const char *varname2[]) @@ -132,7 +132,7 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[] if ( ! varname ) return false; - if (strcmp(tok->str, varname[0]) != 0) + if (tok->_str != varname[0]) return false; for ( int i = 1; varname[i]; i++ ) @@ -159,19 +159,19 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[] else if (strcmp(str,"%str%")==0) { - if ( tok->str[0] != '\"' ) + if ( tok->_str[0] != '\"' ) return false; } // [.. => search for a one-character token.. - else if (str[0]=='[' && strchr(str, ']') && tok->str[1] == 0) + else if (str[0]=='[' && strchr(str, ']') && tok->_str[1] == 0) { *strrchr(str, ']') = 0; - if ( strchr( str + 1, tok->str[0] ) == 0 ) + if ( strchr( str + 1, tok->_str[0] ) == 0 ) return false; } - else if (strcmp(str, tok->str) != 0) + else if (str != tok->_str) return false; tok = tok->next; @@ -227,7 +227,7 @@ const TOKEN *TOKEN::findtoken(const TOKEN *tok1, const char *tokenstr[]) { if (!tok) return NULL; - if (*(tokenstr[i]) && strcmp(tokenstr[i],tok->str)) + if (*(tokenstr[i]) && (tokenstr[i] != tok->_str)) break; tok = tok->next; i++; diff --git a/token.h b/token.h index b71df60a6..cdbb79c68 100644 --- a/token.h +++ b/token.h @@ -19,6 +19,8 @@ #ifndef TOKEN_H #define TOKEN_H +#include + class TOKEN { public: @@ -26,6 +28,19 @@ public: ~TOKEN(); void setstr( const char s[] ); + const std::string &str() const + { return _str; } + + const char *aaaa() const + { return _cstr; } + + char aaaa0() const + { return _cstr[0]; } + + char aaaa1() const + { return _cstr[1]; } + + /** * Combine two tokens that belong to each other. * Ex: "<" and "=" may become "<=" @@ -52,13 +67,14 @@ public: static bool IsStandardType(const char str[]); static const TOKEN *findmatch(const TOKEN *tok, const char pattern[], const char *varname1[]=0, const char *varname2[]=0); static const TOKEN *findtoken(const TOKEN *tok1, const char *tokenstr[]); - const char *str; + unsigned int FileIndex; unsigned int linenr; TOKEN *next; private: - char * _str; + std::string _str; + char * _cstr; bool _isName; bool _isNumber; }; diff --git a/tokenize.cpp b/tokenize.cpp index f0d30cbc9..4a8a75e23 100644 --- a/tokenize.cpp +++ b/tokenize.cpp @@ -215,7 +215,7 @@ void Tokenizer::InsertTokens(TOKEN *dest, TOKEN *src, unsigned int n) TOKEN *NewToken = new TOKEN; NewToken->FileIndex = src->FileIndex; NewToken->linenr = src->linenr; - NewToken->setstr(src->str); + NewToken->setstr(src->aaaa()); NewToken->next = dest->next; dest->next = NewToken; @@ -526,7 +526,7 @@ void Tokenizer::TokenizeCode(std::istream &code, const unsigned int FileIndex) // Replace "->" with "." for ( TOKEN *tok = _tokens; tok; tok = tok->next ) { - if ( strcmp(tok->str, "->") == 0 ) + if ( strcmp(tok->aaaa(), "->") == 0 ) { tok->setstr("."); } @@ -541,7 +541,7 @@ void Tokenizer::TokenizeCode(std::istream &code, const unsigned int FileIndex) const char *type2 = tok->strAt( 2); for ( TOKEN *tok2 = tok; tok2; tok2 = tok2->next ) { - if (tok2->str!=type1 && tok2->str!=type2 && strcmp(tok2->str,type2)==0) + if (tok2->aaaa()!=type1 && tok2->aaaa()!=type2 && strcmp(tok2->aaaa(),type2)==0) { tok2->setstr(type1); } @@ -560,7 +560,7 @@ void Tokenizer::TokenizeCode(std::istream &code, const unsigned int FileIndex) for ( ; tok2; tok2 = tok2->next ) { - if (tok2->str!=type3 && strcmp(tok2->str,type3)==0) + if (tok2->aaaa()!=type3 && strcmp(tok2->aaaa(),type3)==0) { tok2->setstr(type1); @@ -611,7 +611,7 @@ void Tokenizer::SimplifyTokenList() // Remove the keyword 'unsigned' for ( TOKEN *tok = _tokens; tok; tok = tok->next ) { - if (tok->next && strcmp(tok->next->str,"unsigned")==0) + if (tok->next && strcmp(tok->next->aaaa(),"unsigned")==0) { tok->deleteNext(); } @@ -627,7 +627,7 @@ void Tokenizer::SimplifyTokenList() for (TOKEN *tok2 = _gettok(tok,6); tok2; tok2 = tok2->next) { - if (strcmp(tok2->str,sym) == 0) + if (strcmp(tok2->aaaa(),sym) == 0) { tok2->setstr(num); } @@ -661,7 +661,7 @@ void Tokenizer::SimplifyTokenList() // Replace 'sizeof(type)'.. for (TOKEN *tok = _tokens; tok; tok = tok->next) { - if (strcmp(tok->str,"sizeof") != 0) + if (strcmp(tok->aaaa(),"sizeof") != 0) continue; if (TOKEN::Match(tok, "sizeof ( %type% * )")) @@ -708,7 +708,7 @@ void Tokenizer::SimplifyTokenList() if ( ! TOKEN::Match(tok, "%type% %var% [ %num% ] ;") ) continue; - int size = SizeOfType(tok->str); + int size = SizeOfType(tok->aaaa()); if (size <= 0) continue; @@ -719,12 +719,12 @@ void Tokenizer::SimplifyTokenList() int indentlevel = 0; for ( TOKEN *tok2 = _gettok(tok,5); tok2; tok2 = tok2->next ) { - if (tok2->str[0] == '{') + if (tok2->aaaa0() == '{') { indentlevel++; } - else if (tok2->str[0] == '}') + else if (tok2->aaaa0() == '}') { indentlevel--; if (indentlevel < 0) @@ -765,7 +765,7 @@ void Tokenizer::SimplifyTokenList() } // (1-2) - if (strchr("[,(=<>",tok->str[0]) && + if (strchr("[,(=<>",tok->aaaa0()) && (tok->tokAt(1) && tok->tokAt(1)->isNumber()) && strchr("+-*/",*(tok->strAt(2))) && (tok->tokAt(3) && tok->tokAt(3)->isNumber()) && @@ -803,7 +803,7 @@ void Tokenizer::SimplifyTokenList() // Replace "*(str + num)" => "str[num]" for (TOKEN *tok = _tokens; tok; tok = tok->next) { - if ( ! strchr(";{}(=<>", tok->str[0]) ) + if ( ! strchr(";{}(=<>", tok->aaaa0()) ) continue; TOKEN *next = tok->next; @@ -832,7 +832,7 @@ void Tokenizer::SimplifyTokenList() // Split up variable declarations if possible.. for (TOKEN *tok = _tokens; tok; tok = tok->next) { - if ( ! strchr("{};", tok->str[0]) ) + if ( ! strchr("{};", tok->aaaa0()) ) continue; TOKEN *type0 = tok->next; @@ -901,7 +901,7 @@ void Tokenizer::SimplifyTokenList() if (tok2) { - if (tok2->str[0] == ',') + if (tok2->aaaa0() == ',') { tok2->setstr(";"); InsertTokens(tok2, type0, typelen); @@ -914,29 +914,29 @@ void Tokenizer::SimplifyTokenList() int parlevel = 0; while (tok2) { - if ( strchr("{(", tok2->str[0]) ) + if ( strchr("{(", tok2->aaaa0()) ) { parlevel++; } - else if ( strchr("})", tok2->str[0]) ) + else if ( strchr("})", tok2->aaaa0()) ) { if (parlevel<0) break; parlevel--; } - else if ( parlevel==0 && strchr(";,",tok2->str[0]) ) + else if ( parlevel==0 && strchr(";,",tok2->aaaa0()) ) { // "type var =" => "type var; var =" TOKEN *VarTok = _gettok(type0,typelen); - if (VarTok->str[0]=='*') + if (VarTok->aaaa0()=='*') VarTok = VarTok->next; InsertTokens(eq, VarTok, 2); eq->setstr(";"); // "= x, " => "= x; type " - if (tok2->str[0] == ',') + if (tok2->aaaa0() == ',') { tok2->setstr(";"); InsertTokens( tok2, type0, typelen ); @@ -1002,7 +1002,7 @@ bool Tokenizer::simplifyConditions() TOKEN::Match(tok->next, "%num%") && (TOKEN::Match(tok2, ")") || TOKEN::Match(tok2, "&&") || TOKEN::Match(tok2, "||")) ) { - tok->next->setstr((strcmp(tok->next->str, "0")!=0) ? "true" : "false"); + tok->next->setstr((strcmp(tok->next->aaaa(), "0")!=0) ? "true" : "false"); ret = false; } } @@ -1023,7 +1023,7 @@ const TOKEN *Tokenizer::GetFunctionTokenByName( const char funcname[] ) const { for ( unsigned int i = 0; i < _functionList.size(); ++i ) { - if ( strcmp( _functionList[i]->str, funcname ) == 0 ) + if ( strcmp( _functionList[i]->aaaa(), funcname ) == 0 ) { return _functionList[i]; } @@ -1042,10 +1042,10 @@ void Tokenizer::fillFunctionList() int indentlevel = 0; for ( const TOKEN *tok = _tokens; tok; tok = tok->next ) { - if ( tok->str[0] == '{' ) + if ( tok->aaaa0() == '{' ) indentlevel++; - else if ( tok->str[0] == '}' ) + else if ( tok->aaaa0() == '}' ) indentlevel--; if (indentlevel > 0) @@ -1053,13 +1053,13 @@ void Tokenizer::fillFunctionList() continue; } - if (strchr("};", tok->str[0])) + if (strchr("};", tok->aaaa0())) staticfunc = classfunc = false; - else if ( strcmp( tok->str, "static" ) == 0 ) + else if ( strcmp( tok->aaaa(), "static" ) == 0 ) staticfunc = true; - else if ( strcmp( tok->str, "::" ) == 0 ) + else if ( strcmp( tok->aaaa(), "::" ) == 0 ) classfunc = true; else if (TOKEN::Match(tok, "%var% (")) @@ -1067,18 +1067,18 @@ void Tokenizer::fillFunctionList() // Check if this is the first token of a function implementation.. for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next ) { - if ( tok2->str[0] == ';' ) + if ( tok2->aaaa0() == ';' ) { tok = tok2; break; } - else if ( tok2->str[0] == '{' ) + else if ( tok2->aaaa0() == '{' ) { break; } - else if ( tok2->str[0] == ')' ) + else if ( tok2->aaaa0() == ')' ) { if ( TOKEN::Match(tok2, ") {") ) { @@ -1088,7 +1088,7 @@ void Tokenizer::fillFunctionList() else { tok = tok2; - while (tok->next && !strchr(";{", tok->next->str[0])) + while (tok->next && !strchr(";{", tok->next->aaaa0())) tok = tok->next; } break; @@ -1104,7 +1104,7 @@ void Tokenizer::fillFunctionList() bool hasDuplicates = false; for ( unsigned int func2 = func1 + 1; func2 < _functionList.size(); ) { - if ( strcmp(_functionList[func1]->str, _functionList[func2]->str) == 0 ) + if ( strcmp(_functionList[func1]->aaaa(), _functionList[func2]->aaaa()) == 0 ) { hasDuplicates = true; _functionList.erase( _functionList.begin() + func2 ); @@ -1172,7 +1172,7 @@ const char *Tokenizer::getParameterName( const TOKEN *ftok, int par ) if ( TOKEN::Match(ftok, ",") ) ++_par; if ( par==_par && TOKEN::Match(ftok, "%var% [,)]") ) - return ftok->str; + return ftok->aaaa(); } return NULL; }