Refactoring: TOKEN::next renamed to _next, getter and setter functions for it added next() and next(TOKEN*).

This commit is contained in:
Reijo Tomperi 2008-12-08 21:49:05 +00:00
parent 5bb81294c0
commit 51024235a3
13 changed files with 297 additions and 282 deletions

View File

@ -78,13 +78,13 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c
const char *num = tok->strAt(2 + varc); const char *num = tok->strAt(2 + varc);
if (strtol(num, NULL, 10) >= size) if (strtol(num, NULL, 10) >= size)
{ {
ReportError(tok->next, "Array index out of bounds"); ReportError(tok->next(), "Array index out of bounds");
} }
} }
int indentlevel = 0; int indentlevel = 0;
for ( ; tok; tok = tok->next ) for ( ; tok; tok = tok->next() )
{ {
if (tok->str() == "{") if (tok->str() == "{")
{ {
@ -99,12 +99,12 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c
} }
// Array index.. // Array index..
if ( !tok->isName() && !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); const char *num = tok->next()->strAt(2 + varc);
if (strtol(num, NULL, 10) >= size) if (strtol(num, NULL, 10) >= size)
{ {
ReportError(tok->next, "Array index out of bounds"); ReportError(tok->next(), "Array index out of bounds");
} }
tok = tok->tokAt(4); tok = tok->tokAt(4);
continue; continue;
@ -114,8 +114,8 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c
// memset, memcmp, memcpy, strncpy, fgets.. // memset, memcmp, memcpy, strncpy, fgets..
if (TOKEN::Match(tok,"memset|memcpy|memmove|memcmp|strncpy|fgets") ) if (TOKEN::Match(tok,"memset|memcpy|memmove|memcmp|strncpy|fgets") )
{ {
if ( TOKEN::Match( tok->next, "( %var1% , %num% , %num% )", varname ) || if ( TOKEN::Match( tok->next(), "( %var1% , %num% , %num% )", varname ) ||
TOKEN::Match( tok->next, "( %var% , %var1% , %num% )", varname ) ) TOKEN::Match( tok->next(), "( %var% , %var1% , %num% )", varname ) )
{ {
const char *num = tok->strAt(varc + 6); const char *num = tok->strAt(varc + 6);
if ( atoi(num) > total_size ) if ( atoi(num) > total_size )
@ -148,13 +148,13 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c
// Get index variable and stopsize. // Get index variable and stopsize.
const char *strindex = tok2->aaaa(); const char *strindex = tok2->aaaa();
int value = ((tok2->next->aaaa1() == '=') ? 1 : 0) + atoi(tok2->strAt(2)); int value = ((tok2->next()->aaaa1() == '=') ? 1 : 0) + atoi(tok2->strAt(2));
if ( value <= size ) if ( value <= size )
continue; continue;
// Goto the end of the for loop.. // Goto the end of the for loop..
while (tok2 && !TOKEN::Match(tok2,")")) while (tok2 && !TOKEN::Match(tok2,")"))
tok2 = tok2->next; tok2 = tok2->next();
if (!(tok2->tokAt(5))) if (!(tok2->tokAt(5)))
break; break;
@ -183,7 +183,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c
break; break;
} }
tok2 = tok2->next; tok2 = tok2->next();
} }
continue; continue;
} }
@ -223,7 +223,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c
continue; continue;
unsigned int parlevel = 0, par = 0; unsigned int parlevel = 0, par = 0;
for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next ) for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next() )
{ {
if ( tok2->str() == "(" ) if ( tok2->str() == "(" )
{ {
@ -283,8 +283,8 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c
// Goto function body.. // Goto function body..
while ( ftok && (ftok->str() != "{") ) while ( ftok && (ftok->str() != "{") )
ftok = ftok->next; ftok = ftok->next();
ftok = ftok ? ftok->next : 0; ftok = ftok ? ftok->next() : 0;
// Check variable usage in the function.. // Check variable usage in the function..
_callStack.push_back( tok ); _callStack.push_back( tok );
@ -295,7 +295,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c
break; break;
} }
ftok = ftok->next; ftok = ftok->next();
} }
} }
} }
@ -309,7 +309,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c
void CheckBufferOverrunClass::CheckBufferOverrun_LocalVariable() void CheckBufferOverrunClass::CheckBufferOverrun_LocalVariable()
{ {
int indentlevel = 0; int indentlevel = 0;
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
if (tok->str() == "{") if (tok->str() == "{")
indentlevel++; indentlevel++;
@ -362,30 +362,30 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable()
const char *declstruct_pattern[] = {"","","{",0}; const char *declstruct_pattern[] = {"","","{",0};
for ( const TOKEN * tok = TOKEN::findtoken( _tokenizer->tokens(), declstruct_pattern ); for ( const TOKEN * tok = TOKEN::findtoken( _tokenizer->tokens(), declstruct_pattern );
tok; tok;
tok = TOKEN::findtoken( tok->next, declstruct_pattern ) ) tok = TOKEN::findtoken( tok->next(), declstruct_pattern ) )
{ {
if ( ! TOKEN::Match(tok,"struct|class") ) if ( ! TOKEN::Match(tok,"struct|class") )
continue; continue;
const char *structname = tok->next->aaaa(); const char *structname = tok->next()->aaaa();
if ( !(tok->next->isName()) ) if ( !(tok->next()->isName()) )
continue; continue;
// Found a struct declaration. Search for arrays.. // Found a struct declaration. Search for arrays..
for ( TOKEN * tok2 = tok->next->next; tok2; tok2 = tok2->next ) for ( const TOKEN * tok2 = tok->next()->next(); tok2; tok2 = tok2->next() )
{ {
if ( TOKEN::Match(tok2, "}") ) if ( TOKEN::Match(tok2, "}") )
break; break;
int ivar = 0; int ivar = 0;
if ( TOKEN::Match(tok2->next, "%type% %var% [ %num% ] ;") ) if ( TOKEN::Match(tok2->next(), "%type% %var% [ %num% ] ;") )
ivar = 2; ivar = 2;
else if ( TOKEN::Match(tok2->next, "%type% %type% %var% [ %num% ] ;") ) else if ( TOKEN::Match(tok2->next(), "%type% %type% %var% [ %num% ] ;") )
ivar = 3; ivar = 3;
else if ( TOKEN::Match(tok2->next, "%type% * %var% [ %num% ] ;") ) else if ( TOKEN::Match(tok2->next(), "%type% * %var% [ %num% ] ;") )
ivar = 3; ivar = 3;
else if ( TOKEN::Match(tok2->next, "%type% %type% * %var% [ %num% ] ;") ) else if ( TOKEN::Match(tok2->next(), "%type% %type% * %var% [ %num% ] ;") )
ivar = 4; ivar = 4;
else else
continue; continue;
@ -393,7 +393,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable()
const char *varname[3] = {0,0,0}; const char *varname[3] = {0,0,0};
varname[1] = tok2->strAt(ivar); varname[1] = tok2->strAt(ivar);
int arrsize = atoi(tok2->strAt(ivar+2)); int arrsize = atoi(tok2->strAt(ivar+2));
int total_size = arrsize * _tokenizer->SizeOfType(tok2->next->aaaa()); int total_size = arrsize * _tokenizer->SizeOfType(tok2->next()->aaaa());
if (total_size == 0) if (total_size == 0)
continue; continue;
@ -405,7 +405,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable()
const TOKEN *tok3 = TOKEN::findmatch(_tokenizer->tokens(), func_pattern.c_str()); const TOKEN *tok3 = TOKEN::findmatch(_tokenizer->tokens(), func_pattern.c_str());
while ( tok3 ) while ( tok3 )
{ {
for ( const TOKEN *tok4 = tok3; tok4; tok4 = tok4->next ) for ( const TOKEN *tok4 = tok3; tok4; tok4 = tok4->next() )
{ {
if ( TOKEN::Match(tok4,"[;{}]") ) if ( TOKEN::Match(tok4,"[;{}]") )
break; break;
@ -417,21 +417,21 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable()
break; break;
} }
} }
tok3 = TOKEN::findmatch(tok3->next, func_pattern.c_str()); tok3 = TOKEN::findmatch(tok3->next(), func_pattern.c_str());
} }
} }
for ( const TOKEN *tok3 = _tokenizer->tokens(); tok3; tok3 = tok3->next ) for ( const TOKEN *tok3 = _tokenizer->tokens(); tok3; tok3 = tok3->next() )
{ {
if ( strcmp(tok3->aaaa(), structname) ) if ( strcmp(tok3->aaaa(), structname) )
continue; continue;
// Declare variable: Fred fred1; // Declare variable: Fred fred1;
if ( TOKEN::Match( tok3->next, "%var% ;" ) ) if ( TOKEN::Match( tok3->next(), "%var% ;" ) )
varname[0] = tok3->strAt(1); varname[0] = tok3->strAt(1);
// Declare pointer: Fred *fred1 // Declare pointer: Fred *fred1
else if ( TOKEN::Match(tok3->next, "* %var% [,);=]") ) else if ( TOKEN::Match(tok3->next(), "* %var% [,);=]") )
varname[0] = tok3->strAt(2); varname[0] = tok3->strAt(2);
else else
@ -460,7 +460,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_StructVariable()
break; break;
} }
tok3 = tok3->next; tok3 = tok3->next();
} }
if ( ! tok3 ) if ( ! tok3 )
@ -499,7 +499,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun()
void CheckBufferOverrunClass::WarningDangerousFunctions() void CheckBufferOverrunClass::WarningDangerousFunctions()
{ {
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
if (TOKEN::Match(tok, "gets (")) if (TOKEN::Match(tok, "gets ("))
{ {

View File

@ -52,9 +52,9 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1)
// Get variable list.. // Get variable list..
struct VAR *varlist = NULL; struct VAR *varlist = NULL;
unsigned int indentlevel = 0; unsigned int indentlevel = 0;
for (const TOKEN *tok = tok1; tok; tok = tok->next) for (const TOKEN *tok = tok1; tok; tok = tok->next())
{ {
if (!tok->next) if (!tok->next())
break; break;
if (tok->aaaa0() == '{') if (tok->aaaa0() == '{')
@ -69,7 +69,7 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1)
if (indentlevel==1 && (strchr(";{}", tok->aaaa0()) || (tok->aaaa0()!=':' && strchr(tok->aaaa(), ':')))) if (indentlevel==1 && (strchr(";{}", tok->aaaa0()) || (tok->aaaa0()!=':' && strchr(tok->aaaa(), ':'))))
{ {
const TOKEN *next = tok->next; const TOKEN *next = tok->next();
const char *varname = 0; const char *varname = 0;
@ -81,7 +81,7 @@ struct CheckClass::VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1)
{ {
if ( strcmp(next->aaaa(), types[type]) == 0) if ( strcmp(next->aaaa(), types[type]) == 0)
{ {
varname = next->next->aaaa(); varname = next->next()->aaaa();
break; break;
} }
} }
@ -123,14 +123,14 @@ const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classn
std::ostringstream externalPattern; std::ostringstream externalPattern;
externalPattern << classname << " :: " << funcname << " ("; externalPattern << classname << " :: " << funcname << " (";
for ( ;tok; tok = tok->next ) for ( ;tok; tok = tok->next() )
{ {
if ( indentlevel == 0 && TOKEN::Match(tok, classPattern.str().c_str()) ) if ( indentlevel == 0 && TOKEN::Match(tok, classPattern.str().c_str()) )
{ {
while ( tok && tok->str() != "{" ) while ( tok && tok->str() != "{" )
tok = tok->next; tok = tok->next();
if ( tok ) if ( tok )
tok = tok->next; tok = tok->next();
if ( ! tok ) if ( ! tok )
break; break;
indentlevel = 1; indentlevel = 1;
@ -144,7 +144,7 @@ const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classn
else else
{ {
for ( ; tok; tok = tok->next ) for ( ; tok; tok = tok->next() )
{ {
if ( tok->str() == "{" ) if ( tok->str() == "{" )
++indentlevel; ++indentlevel;
@ -172,13 +172,13 @@ const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classn
if ( indentlevel == 1 ) if ( indentlevel == 1 )
{ {
// Member function implemented in the class declaration? // Member function implemented in the class declaration?
if (!TOKEN::Match(tok,"~") && TOKEN::Match(tok->next, internalPattern.str().c_str())) if (!TOKEN::Match(tok,"~") && TOKEN::Match(tok->next(), internalPattern.str().c_str()))
{ {
const TOKEN *tok2 = tok; const TOKEN *tok2 = tok;
while ( tok2 && tok2->str() != "{" && tok2->str() != ";" ) while ( tok2 && tok2->str() != "{" && tok2->str() != ";" )
tok2 = tok2->next; tok2 = tok2->next();
if ( tok2 && tok2->str() == "{" ) if ( tok2 && tok2->str() == "{" )
return tok->next; return tok->next();
} }
} }
@ -211,9 +211,9 @@ void CheckClass::ClassChecking_VarList_Initialize(const TOKEN *tok1, const TOKEN
bool Assign = false; bool Assign = false;
unsigned int indentlevel = 0; unsigned int indentlevel = 0;
for (; ftok; ftok = ftok->next) for (; ftok; ftok = ftok->next())
{ {
if (!ftok->next) if (!ftok->next())
break; break;
// Class constructor.. initializing variables like this // Class constructor.. initializing variables like this
@ -250,18 +250,18 @@ void CheckClass::ClassChecking_VarList_Initialize(const TOKEN *tok1, const TOKEN
continue; continue;
// Using the operator= function to initialize all variables.. // Using the operator= function to initialize all variables..
if ( TOKEN::Match(ftok->next, "* this = ") ) if ( TOKEN::Match(ftok->next(), "* this = ") )
{ {
for (struct VAR *var = varlist; var; var = var->next) for (struct VAR *var = varlist; var; var = var->next)
var->init = true; var->init = true;
break; break;
} }
if (!TOKEN::Match(ftok->next, "%var%") && !TOKEN::Match(ftok->next, "this . %var%")) if (!TOKEN::Match(ftok->next(), "%var%") && !TOKEN::Match(ftok->next(), "this . %var%"))
continue; continue;
// Goto the first token in this statement.. // Goto the first token in this statement..
ftok = ftok->next; ftok = ftok->next();
// Skip "this->" // Skip "this->"
if ( TOKEN::Match(ftok, "this .") ) if ( TOKEN::Match(ftok, "this .") )
@ -328,7 +328,7 @@ void CheckClass::CheckConstructors()
{ {
int indentlevel = 0; int indentlevel = 0;
bool isPrivate = true; bool isPrivate = true;
for ( const TOKEN *tok = tok1; tok; tok = tok->next ) for ( const TOKEN *tok = tok1; tok; tok = tok->next() )
{ {
// Indentation // Indentation
if ( tok->str() == "{" ) if ( tok->str() == "{" )
@ -364,14 +364,14 @@ void CheckClass::CheckConstructors()
{ {
// TODO: Handle private constructors. // TODO: Handle private constructors.
// Right now to avoid false positives I just bail out // Right now to avoid false positives I just bail out
tok1 = TOKEN::findmatch( tok1->next, pattern_class ); tok1 = TOKEN::findmatch( tok1->next(), pattern_class );
continue; continue;
} }
// Are there a class constructor? // Are there a class constructor?
const TOKEN *constructor_token = TOKEN::findmatch( tok1, "%any% %var1% (", className ); const TOKEN *constructor_token = TOKEN::findmatch( tok1, "%any% %var1% (", className );
while ( TOKEN::Match( constructor_token, "~" ) ) while ( TOKEN::Match( constructor_token, "~" ) )
constructor_token = TOKEN::findmatch( constructor_token->next, "%any% %var1% (", className ); constructor_token = TOKEN::findmatch( constructor_token->next(), "%any% %var1% (", className );
// There are no constructor. // There are no constructor.
if ( ! constructor_token ) if ( ! constructor_token )
@ -397,7 +397,7 @@ void CheckClass::CheckConstructors()
} }
} }
tok1 = TOKEN::findmatch( tok1->next, pattern_class ); tok1 = TOKEN::findmatch( tok1->next(), pattern_class );
continue; continue;
} }
@ -418,7 +418,7 @@ void CheckClass::CheckConstructors()
varlist = nextvar; varlist = nextvar;
} }
tok1 = TOKEN::findmatch( tok1->next, pattern_class ); tok1 = TOKEN::findmatch( tok1->next(), pattern_class );
} }
} }
@ -454,7 +454,7 @@ void CheckClass::CheckConstructors(const TOKEN *tok1, struct VAR *varlist, const
for ( struct VAR *var = varlist; var; var = var->next ) for ( struct VAR *var = varlist; var; var = var->next )
var->init = false; var->init = false;
constructor_token = FindClassFunction( constructor_token->next, className, funcname, indentlevel ); constructor_token = FindClassFunction( constructor_token->next(), className, funcname, indentlevel );
callstack.clear(); callstack.clear();
ClassChecking_VarList_Initialize(tok1, constructor_token, varlist, className, callstack); ClassChecking_VarList_Initialize(tok1, constructor_token, varlist, className, callstack);
} }
@ -469,9 +469,9 @@ void CheckClass::CheckUnusedPrivateFunctions()
{ {
// Locate some class // Locate some class
const char *pattern_class[] = {"class","","{",NULL}; const char *pattern_class[] = {"class","","{",NULL};
for (const TOKEN *tok1 = TOKEN::findtoken(_tokenizer->tokens(), pattern_class); tok1; tok1 = TOKEN::findtoken(tok1->next, pattern_class)) for (const TOKEN *tok1 = TOKEN::findtoken(_tokenizer->tokens(), pattern_class); tok1; tok1 = TOKEN::findtoken(tok1->next(), pattern_class))
{ {
const char *classname = tok1->next->aaaa(); const char *classname = tok1->next()->aaaa();
// The class implementation must be available.. // The class implementation must be available..
const char *pattern_classconstructor[] = {"","::","",NULL}; const char *pattern_classconstructor[] = {"","::","",NULL};
@ -485,7 +485,7 @@ void CheckClass::CheckUnusedPrivateFunctions()
FuncList.clear(); FuncList.clear();
bool priv = false; bool priv = false;
unsigned int indent_level = 0; unsigned int indent_level = 0;
for (const TOKEN *tok = tok1; tok; tok = tok->next) for (const TOKEN *tok = tok1; tok; tok = tok->next())
{ {
if (TOKEN::Match(tok,"friend %var%")) if (TOKEN::Match(tok,"friend %var%"))
{ {
@ -538,7 +538,7 @@ void CheckClass::CheckUnusedPrivateFunctions()
numpar++; numpar++;
else if (ftok->aaaa0() == ')') else if (ftok->aaaa0() == ')')
numpar--; numpar--;
ftok = ftok->next; ftok = ftok->next();
} }
if (!ftok) if (!ftok)
@ -559,14 +559,14 @@ void CheckClass::CheckUnusedPrivateFunctions()
break; break;
indent_level--; indent_level--;
} }
if (ftok->next && ftok->next->aaaa0() == '(') if (ftok->next() && ftok->next()->aaaa0() == '(')
FuncList.remove(ftok->aaaa()); FuncList.remove(ftok->aaaa());
ftok = ftok->next; ftok = ftok->next();
} }
} }
if (ftok) if (ftok)
ftok = ftok->next; ftok = ftok->next();
} }
while (HasFuncImpl && !FuncList.empty()) while (HasFuncImpl && !FuncList.empty())
@ -604,7 +604,7 @@ void CheckClass::CheckUnusedPrivateFunctions()
void CheckClass::CheckMemset() void CheckClass::CheckMemset()
{ {
// Locate all 'memset' tokens.. // Locate all 'memset' tokens..
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
if (!TOKEN::Match(tok,"memset") && !TOKEN::Match(tok,"memcpy") && !TOKEN::Match(tok,"memmove")) if (!TOKEN::Match(tok,"memset") && !TOKEN::Match(tok,"memcpy") && !TOKEN::Match(tok,"memmove"))
continue; continue;
@ -640,7 +640,7 @@ void CheckClass::CheckMemset()
// Warn if type is a struct that contains any std::* // Warn if type is a struct that contains any std::*
const char *pattern2[] = {"struct","","{",NULL}; const char *pattern2[] = {"struct","","{",NULL};
pattern2[1] = type; pattern2[1] = type;
for (const TOKEN *tstruct = TOKEN::findtoken(_tokenizer->tokens(), pattern2); tstruct; tstruct = tstruct->next) for (const TOKEN *tstruct = TOKEN::findtoken(_tokenizer->tokens(), pattern2); tstruct; tstruct = tstruct->next())
{ {
if (tstruct->aaaa0() == '}') if (tstruct->aaaa0() == '}')
break; break;
@ -697,7 +697,7 @@ void CheckClass::virtualDestructor()
// What kind of inheritance is it.. public|protected|private // What kind of inheritance is it.. public|protected|private
if ( TOKEN::Match( derived, "public|protected|private" ) ) if ( TOKEN::Match( derived, "public|protected|private" ) )
derived = derived->next; derived = derived->next();
// Name of base class.. // Name of base class..
const char *baseName[2]; const char *baseName[2];
@ -705,9 +705,9 @@ void CheckClass::virtualDestructor()
baseName[1] = 0; baseName[1] = 0;
// Update derived so it's ready for the next loop. // Update derived so it's ready for the next loop.
derived = derived->next; derived = derived->next();
if ( TOKEN::Match(derived, ",") ) if ( TOKEN::Match(derived, ",") )
derived = derived->next; derived = derived->next();
// If not public inheritance, skip checking of this base class.. // If not public inheritance, skip checking of this base class..
if ( ! isPublic ) if ( ! isPublic )
@ -716,7 +716,7 @@ void CheckClass::virtualDestructor()
// Find the destructor declaration for the base class. // Find the destructor declaration for the base class.
const TOKEN *base = TOKEN::findmatch(_tokenizer->tokens(), "%any% ~ %var1% (", baseName); const TOKEN *base = TOKEN::findmatch(_tokenizer->tokens(), "%any% ~ %var1% (", baseName);
while (TOKEN::Match(base, "::")) while (TOKEN::Match(base, "::"))
base = TOKEN::findmatch(base->next, "%any% ~ %var1% (", baseName); base = TOKEN::findmatch(base->next(), "%any% ~ %var1% (", baseName);
// Check that there is a destructor.. // Check that there is a destructor..
if ( ! base ) if ( ! base )

View File

@ -44,7 +44,7 @@ CheckFunctionUsage::~CheckFunctionUsage()
void CheckFunctionUsage::parseTokens( const Tokenizer &tokenizer ) void CheckFunctionUsage::parseTokens( const Tokenizer &tokenizer )
{ {
// Function declarations.. // Function declarations..
for ( const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next ) for ( const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next() )
{ {
if ( tok->FileIndex != 0 ) if ( tok->FileIndex != 0 )
continue; continue;
@ -59,7 +59,7 @@ void CheckFunctionUsage::parseTokens( const Tokenizer &tokenizer )
funcname = tok->tokAt(2); funcname = tok->tokAt(2);
// Check that ") {" is found.. // Check that ") {" is found..
for (const TOKEN *tok2 = funcname; tok2; tok2 = tok2->next) for (const TOKEN *tok2 = funcname; tok2; tok2 = tok2->next())
{ {
if ( TOKEN::Match(tok2, ")") ) if ( TOKEN::Match(tok2, ")") )
{ {
@ -87,7 +87,7 @@ void CheckFunctionUsage::parseTokens( const Tokenizer &tokenizer )
} }
// Function usage.. // Function usage..
for ( const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next ) for ( const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next() )
{ {
const TOKEN *funcname = 0; const TOKEN *funcname = 0;
@ -99,13 +99,13 @@ void CheckFunctionUsage::parseTokens( const Tokenizer &tokenizer )
TOKEN::Match(tok, "|| %var% (") || TOKEN::Match(tok, "|| %var% (") ||
TOKEN::Match(tok, "else %var% (") || TOKEN::Match(tok, "else %var% (") ||
TOKEN::Match(tok, "return %var% (") ) TOKEN::Match(tok, "return %var% (") )
funcname = tok->next; funcname = tok->next();
// funcname ( => Assert that the end paranthesis isn't followed by { // funcname ( => Assert that the end paranthesis isn't followed by {
if ( TOKEN::Match(funcname, "%var% (") ) if ( TOKEN::Match(funcname, "%var% (") )
{ {
int parlevel = 0; int parlevel = 0;
for ( const TOKEN *tok2 = funcname; tok2; tok2 = tok2->next ) for ( const TOKEN *tok2 = funcname; tok2; tok2 = tok2->next() )
{ {
if (tok2->str() == "(") if (tok2->str() == "(")
++parlevel; ++parlevel;

View File

@ -48,7 +48,7 @@ CheckHeaders::~CheckHeaders()
void CheckHeaders::WarningHeaderWithImplementation() void CheckHeaders::WarningHeaderWithImplementation()
{ {
for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
// Only interested in included file // Only interested in included file
if (tok->FileIndex == 0) if (tok->FileIndex == 0)
@ -62,8 +62,8 @@ void CheckHeaders::WarningHeaderWithImplementation()
// Goto next file.. // Goto next file..
unsigned int fileindex = tok->FileIndex; unsigned int fileindex = tok->FileIndex;
while ( tok->next && tok->FileIndex == fileindex ) while ( tok->next() && tok->FileIndex == fileindex )
tok = tok->next; tok = tok->next();
} }
} }
} }
@ -83,14 +83,14 @@ void CheckHeaders::WarningHeaderWithImplementation()
void CheckHeaders::WarningIncludeHeader() void CheckHeaders::WarningIncludeHeader()
{ {
// Including.. // Including..
for ( const TOKEN *includetok = _tokenizer->tokens(); includetok; includetok = includetok->next) for ( const TOKEN *includetok = _tokenizer->tokens(); includetok; includetok = includetok->next())
{ {
if (includetok->str() != "#include") if (includetok->str() != "#include")
continue; continue;
// 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->next()->aaaa();
while (hfile < _tokenizer->getFiles()->size()) while (hfile < _tokenizer->getFiles()->size())
{ {
if ( Tokenizer::SameFileName( _tokenizer->getFiles()->at(hfile).c_str(), includefile ) ) if ( Tokenizer::SameFileName( _tokenizer->getFiles()->at(hfile).c_str(), includefile ) )
@ -112,7 +112,7 @@ void CheckHeaders::WarningIncludeHeader()
// Extract classes and names in the header.. // Extract classes and names in the header..
int indentlevel = 0; int indentlevel = 0;
for ( const TOKEN *tok1 = _tokenizer->tokens(); tok1; tok1 = tok1->next ) for ( const TOKEN *tok1 = _tokenizer->tokens(); tok1; tok1 = tok1->next() )
{ {
if ( tok1->FileIndex != hfile ) if ( tok1->FileIndex != hfile )
continue; continue;
@ -150,12 +150,12 @@ void CheckHeaders::WarningIncludeHeader()
// -------------------------------------- // --------------------------------------
else if (tok1->str() == "enum") else if (tok1->str() == "enum")
{ {
tok1 = tok1->next; tok1 = tok1->next();
while ( ! TOKEN::Match( tok1, "; %any%" ) ) while ( ! TOKEN::Match( tok1, "; %any%" ) )
{ {
if ( tok1->isName() ) if ( tok1->isName() )
namelist.push_back(tok1->str()); namelist.push_back(tok1->str());
tok1 = tok1->next; tok1 = tok1->next();
} }
} }
@ -180,7 +180,7 @@ void CheckHeaders::WarningIncludeHeader()
if (strcmp(tok1->strAt(1),"enum")==0) if (strcmp(tok1->strAt(1),"enum")==0)
continue; continue;
int parlevel = 0; int parlevel = 0;
while (tok1->next) while (tok1->next())
{ {
if ( TOKEN::Match(tok1, "[({]") ) if ( TOKEN::Match(tok1, "[({]") )
parlevel++; parlevel++;
@ -197,7 +197,7 @@ void CheckHeaders::WarningIncludeHeader()
namelist.push_back(tok1->str()); namelist.push_back(tok1->str());
} }
tok1 = tok1->next; tok1 = tok1->next();
} }
} }
} }
@ -206,7 +206,7 @@ void CheckHeaders::WarningIncludeHeader()
// Check if the extracted names are used... // Check if the extracted names are used...
bool Needed = false; bool Needed = false;
bool NeedDeclaration = false; bool NeedDeclaration = false;
for ( const TOKEN *tok1 = _tokenizer->tokens(); tok1; tok1 = tok1->next) for ( const TOKEN *tok1 = _tokenizer->tokens(); tok1; tok1 = tok1->next())
{ {
if (tok1->FileIndex != includetok->FileIndex) if (tok1->FileIndex != includetok->FileIndex)
continue; continue;

View File

@ -73,8 +73,8 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetAllocationType( const T
if ( tok2 && tok2->str() == "(" ) if ( tok2 && tok2->str() == "(" )
{ {
while ( tok2 && tok2->str() != ")" ) while ( tok2 && tok2->str() != ")" )
tok2 = tok2->next; tok2 = tok2->next();
tok2 = tok2 ? tok2->next : NULL; tok2 = tok2 ? tok2->next() : NULL;
} }
if ( ! tok2 ) if ( ! tok2 )
return No; return No;
@ -144,8 +144,8 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetReallocationType( const
if ( tok2 && tok2->str() == "(" ) if ( tok2 && tok2->str() == "(" )
{ {
while ( tok2 && tok2->str() != ")" ) while ( tok2 && tok2->str() != ")" )
tok2 = tok2->next; tok2 = tok2->next();
tok2 = tok2 ? tok2->next : NULL; tok2 = tok2 ? tok2->next() : NULL;
} }
if ( ! tok2 ) if ( ! tok2 )
return No; return No;
@ -209,7 +209,7 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list<const
int par = 1; int par = 1;
int parlevel = 0; int parlevel = 0;
for ( ; tok; tok = tok->next ) for ( ; tok; tok = tok->next() )
{ {
if ( tok->str() == "(" ) if ( tok->str() == "(" )
++parlevel; ++parlevel;
@ -232,14 +232,14 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list<const
return "use"; return "use";
// Check if the function deallocates the variable.. // Check if the function deallocates the variable..
while ( ftok && (ftok->str() != "{") ) while ( ftok && (ftok->str() != "{") )
ftok = ftok->next; ftok = ftok->next();
TOKEN *func = getcode( ftok->tokAt(1), callstack, parname, alloctype, dealloctype ); TOKEN *func = getcode( ftok->tokAt(1), callstack, parname, alloctype, dealloctype );
simplifycode( func ); simplifycode( func );
const TOKEN *func_ = func; const TOKEN *func_ = func;
while ( func_ && func_->str() == ";" ) while ( func_ && func_->str() == ";" )
func_ = func_->next; func_ = func_->next();
/* /*
for (const TOKEN *t = func; t; t = t->next) for (const TOKEN *t = func; t; t = t->next())
{ {
std::cout << t->str() << "\n"; std::cout << t->str() << "\n";
}*/ }*/
@ -290,8 +290,8 @@ void CheckMemoryLeakClass::instoken(TOKEN *tok, const char str[])
{ {
TOKEN *newtok = new TOKEN; TOKEN *newtok = new TOKEN;
newtok->setstr(str); newtok->setstr(str);
newtok->next = tok->next; newtok->next( tok->next() );
tok->next = newtok; tok->next( newtok );
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -318,9 +318,9 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
newtok->setstr(_str); \ newtok->setstr(_str); \
newtok->linenr = tok->linenr; \ newtok->linenr = tok->linenr; \
newtok->FileIndex = tok->FileIndex; \ newtok->FileIndex = tok->FileIndex; \
newtok->next = 0; \ newtok->next( 0 ); \
if (rettail) \ if (rettail) \
rettail->next = newtok; \ rettail->next( newtok ); \
else \ else \
rethead = newtok; \ rethead = newtok; \
rettail=newtok; \ rettail=newtok; \
@ -335,7 +335,7 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
int indentlevel = 0; int indentlevel = 0;
int parlevel = 0; int parlevel = 0;
for ( ; tok; tok = tok->next ) for ( ; tok; tok = tok->next() )
{ {
if ( tok->str() == "{" ) if ( tok->str() == "{" )
{ {
@ -420,7 +420,7 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
// Make sure the "use" will not be added // Make sure the "use" will not be added
while ( tok->str() != ")" ) while ( tok->str() != ")" )
tok = tok->next; tok = tok->next();
} }
else if ( TOKEN::Match(tok, "if (") && notvar(tok->tokAt(2), varnames) ) else if ( TOKEN::Match(tok, "if (") && notvar(tok->tokAt(2), varnames) )
{ {
@ -439,7 +439,7 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
// Check if the condition depends on var somehow.. // Check if the condition depends on var somehow..
bool dep = false; bool dep = false;
int parlevel = 0; int parlevel = 0;
for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next ) for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next() )
{ {
if ( tok2->str() == "(" ) if ( tok2->str() == "(" )
++parlevel; ++parlevel;
@ -450,8 +450,8 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
break; break;
} }
if ( (tok2->str() != ".") && if ( (tok2->str() != ".") &&
TOKEN::Match(tok2->next, "%var1%", varnames) && TOKEN::Match(tok2->next(), "%var1%", varnames) &&
!TOKEN::Match(tok2->next, "%var1% .", varnames) ) !TOKEN::Match(tok2->next(), "%var1% .", varnames) )
{ {
dep = true; dep = true;
break; break;
@ -530,7 +530,7 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
// Callback.. // Callback..
if ( TOKEN::Match(tok, "( * %var% ) (") ) if ( TOKEN::Match(tok, "( * %var% ) (") )
{ {
for ( const TOKEN *tok2 = tok->tokAt(5); tok2; tok2 = tok2->next ) for ( const TOKEN *tok2 = tok->tokAt(5); tok2; tok2 = tok2->next() )
{ {
if ( TOKEN::Match(tok2, ";{") ) if ( TOKEN::Match(tok2, ";{") )
break; break;
@ -558,10 +558,10 @@ void CheckMemoryLeakClass::erase(TOKEN *begin, const TOKEN *end)
if ( ! begin ) if ( ! begin )
return; return;
while ( begin->next && begin->next != end ) while ( begin->next() && begin->next() != end )
{ {
TOKEN *next = begin->next; TOKEN *next = begin->next();
begin->next = begin->next->next; begin->next( begin->next()->next() );
delete next; delete next;
} }
} }
@ -574,7 +574,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
{ {
done = true; done = true;
for (TOKEN *tok2 = tok; tok2; tok2 = tok2 ? tok2->next : NULL ) for ( TOKEN *tok2 = tok; tok2; tok2 = tok2 ? tok2->next() : NULL )
{ {
// Delete extra ";" // Delete extra ";"
while (TOKEN::Match(tok2,"[;{}] ;")) while (TOKEN::Match(tok2,"[;{}] ;"))
@ -584,30 +584,30 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
} }
// Replace "{ }" with ";" // Replace "{ }" with ";"
if ( TOKEN::Match(tok2->next, "{ }") ) if ( TOKEN::Match(tok2->next(), "{ }") )
{ {
tok2->next->setstr(";"); tok2->next()->setstr(";");
erase(tok2->next, tok2->tokAt(3)); erase(tok2->next(), tok2->tokAt(3));
done = false; done = false;
} }
// Delete braces around a single instruction.. // Delete braces around a single instruction..
if ( TOKEN::Match(tok2->next, "{ %var% ; }") ) if ( TOKEN::Match(tok2->next(), "{ %var% ; }") )
{ {
erase( tok2, tok2->tokAt(2) ); erase( tok2, tok2->tokAt(2) );
erase( tok2->next->next, tok2->tokAt(4) ); erase( tok2->next()->next(), tok2->tokAt(4) );
done = false; done = false;
} }
if ( TOKEN::Match(tok2->next, "{ %var% %var% ; }") ) if ( TOKEN::Match(tok2->next(), "{ %var% %var% ; }") )
{ {
erase( tok2, tok2->tokAt(2) ); erase( tok2, tok2->tokAt(2) );
erase( tok2->next->next->next, tok2->tokAt(5) ); erase( tok2->next()->next()->next(), tok2->tokAt(5) );
done = false; done = false;
} }
// Delete empty if that is not followed by an else // Delete empty if that is not followed by an else
if (tok2->tokAt(2) && if (tok2->tokAt(2) &&
(tok2->next->str().find("if") == 0) && (tok2->next()->str().find("if") == 0) &&
TOKEN::Match(tok2->tokAt(2), ";") && TOKEN::Match(tok2->tokAt(2), ";") &&
!TOKEN::Match(tok2->tokAt(3), "else")) !TOKEN::Match(tok2->tokAt(3), "else"))
{ {
@ -616,7 +616,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
} }
// Delete "if ; else ;" // Delete "if ; else ;"
if ( TOKEN::Match(tok2->next, "if ; else ;") ) if ( TOKEN::Match(tok2->next(), "if ; else ;") )
{ {
erase( tok2, tok2->tokAt(4) ); erase( tok2, tok2->tokAt(4) );
done = false; done = false;
@ -659,7 +659,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
} }
// Reduce "else ;" => ";" // Reduce "else ;" => ";"
if ( TOKEN::Match(tok2->next, "else ;") ) if ( TOKEN::Match(tok2->next(), "else ;") )
{ {
erase(tok2, tok2->tokAt(2)); erase(tok2, tok2->tokAt(2));
done = false; done = false;
@ -684,7 +684,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
if (TOKEN::Match(tok2,"[;{}] if alloc ; else return ;")) if (TOKEN::Match(tok2,"[;{}] if alloc ; else return ;"))
{ {
erase(tok2, tok2->tokAt(2)); // Remove "if" erase(tok2, tok2->tokAt(2)); // Remove "if"
erase(tok2->next, tok2->tokAt(5)); // Remove "; else return" erase(tok2->next(), tok2->tokAt(5)); // Remove "; else return"
done = false; done = false;
} }
@ -722,15 +722,15 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
} }
// Reduce "do { alloc ; } " => "alloc ;" // Reduce "do { alloc ; } " => "alloc ;"
if ( TOKEN::Match(tok2->next, "do { alloc ; }") ) if ( TOKEN::Match(tok2->next(), "do { alloc ; }") )
{ {
erase(tok2, tok2->tokAt(3)); erase(tok2, tok2->tokAt(3));
erase(tok2->next->next, tok2->tokAt(4)); erase(tok2->next()->next(), tok2->tokAt(4));
done = false; done = false;
} }
// Reduce "loop if break ; => ";" // Reduce "loop if break ; => ";"
if ( TOKEN::Match( tok2->next, "loop %var%" ) && if ( TOKEN::Match( tok2->next(), "loop %var%" ) &&
tok2->tokAt(2)->str().find("if") == 0 && tok2->tokAt(2)->str().find("if") == 0 &&
(TOKEN::Match( tok2->tokAt(3), "break ; ") || TOKEN::Match( tok2->tokAt(3), "continue ;")) && (TOKEN::Match( tok2->tokAt(3), "break ; ") || TOKEN::Match( tok2->tokAt(3), "continue ;")) &&
!TOKEN::Match(tok2->tokAt(5),"else") ) !TOKEN::Match(tok2->tokAt(5),"else") )
@ -740,36 +740,36 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
} }
// Reduce "if(true) X ;" => "X ;" // Reduce "if(true) X ;" => "X ;"
if (TOKEN::Match(tok2->next, "if(true) %var% ;") && !TOKEN::Match(tok2->tokAt(4),"else")) if (TOKEN::Match(tok2->next(), "if(true) %var% ;") && !TOKEN::Match(tok2->tokAt(4),"else"))
{ {
erase( tok2, tok2->tokAt(2) ); erase( tok2, tok2->tokAt(2) );
done = false; done = false;
} }
// Replace "loop { X ; break ; }" with "X ;" // Replace "loop { X ; break ; }" with "X ;"
if ( TOKEN::Match(tok2->next, "loop { %var% ; break ; }") ) if ( TOKEN::Match(tok2->next(), "loop { %var% ; break ; }") )
{ {
erase(tok2, tok2->tokAt(3)); erase(tok2, tok2->tokAt(3));
erase(tok2->next->next, tok2->tokAt(6)); erase(tok2->next()->next(), tok2->tokAt(6));
done = false; done = false;
} }
// Replace "loop ;" with ";" // Replace "loop ;" with ";"
if ( TOKEN::Match(tok2->next, "loop ;") ) if ( TOKEN::Match(tok2->next(), "loop ;") )
{ {
erase(tok2, tok2->tokAt(2)); erase(tok2, tok2->tokAt(2));
done = false; done = false;
} }
// Replace "loop !var ;" with ";" // Replace "loop !var ;" with ";"
if ( TOKEN::Match(tok2->next, "loop !var ;") ) if ( TOKEN::Match(tok2->next(), "loop !var ;") )
{ {
erase(tok2, tok2->tokAt(4)); erase(tok2, tok2->tokAt(4));
done = false; done = false;
} }
// Replace "loop !var alloc ;" with " alloc ;" // Replace "loop !var alloc ;" with " alloc ;"
if ( TOKEN::Match(tok2->next, "loop !var alloc ;") ) if ( TOKEN::Match(tok2->next(), "loop !var alloc ;") )
{ {
erase(tok2, tok2->tokAt(3)); erase(tok2, tok2->tokAt(3));
done = false; done = false;
@ -790,7 +790,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
} }
// Reduce "if return ; if return ;" => "if return ;" // Reduce "if return ; if return ;" => "if return ;"
if ( TOKEN::Match(tok2->next, "if return ; if return ;") ) if ( TOKEN::Match(tok2->next(), "if return ; if return ;") )
{ {
erase( tok2, tok2->tokAt(4) ); erase( tok2, tok2->tokAt(4) );
done = false; done = false;
@ -799,26 +799,26 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
// Reduce "[;{}] return ; %var%" => "[;{}] return ;" // Reduce "[;{}] return ; %var%" => "[;{}] return ;"
if ( TOKEN::Match(tok2, "[;{}] return ; %var%") ) if ( TOKEN::Match(tok2, "[;{}] return ; %var%") )
{ {
erase( tok2->next->next, tok2->tokAt(4) ); erase( tok2->next()->next(), tok2->tokAt(4) );
done = false; done = false;
} }
// Reduce "[;{}] return use ; %var%" => "[;{}] return use ;" // Reduce "[;{}] return use ; %var%" => "[;{}] return use ;"
if ( TOKEN::Match(tok2, "[;{}] return use ; %var%") ) if ( TOKEN::Match(tok2, "[;{}] return use ; %var%") )
{ {
erase( tok2->next->next->next, tok2->tokAt(5) ); erase( tok2->next()->next()->next(), tok2->tokAt(5) );
done = false; done = false;
} }
// Reduce "if(var) return use ;" => "return use ;" // Reduce "if(var) return use ;" => "return use ;"
if ( TOKEN::Match(tok2->next, "if(var) return use ;") && !TOKEN::Match(tok2->tokAt(5),"else")) if ( TOKEN::Match(tok2->next(), "if(var) return use ;") && !TOKEN::Match(tok2->tokAt(5),"else"))
{ {
erase( tok2, tok2->tokAt(2) ); erase( tok2, tok2->tokAt(2) );
done = false; done = false;
} }
// Reduce "if(var) use ;" => "use ;" // Reduce "if(var) use ;" => "use ;"
if ( TOKEN::Match(tok2->next, "if(var) use ;") && !TOKEN::Match(tok2->tokAt(4),"else")) if ( TOKEN::Match(tok2->next(), "if(var) use ;") && !TOKEN::Match(tok2->tokAt(4),"else"))
{ {
erase( tok2, tok2->tokAt(2) ); erase( tok2, tok2->tokAt(2) );
done = false; done = false;
@ -833,7 +833,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
// Reduce "if* alloc ; dealloc ;" => ";" // Reduce "if* alloc ; dealloc ;" => ";"
if ( TOKEN::Match(tok2->tokAt(2), "alloc ; dealloc ;") && if ( TOKEN::Match(tok2->tokAt(2), "alloc ; dealloc ;") &&
tok2->next->str().find("if") == 0 ) tok2->next()->str().find("if") == 0 )
{ {
erase( tok2, tok2->tokAt(5) ); erase( tok2, tok2->tokAt(5) );
done = false; done = false;
@ -873,7 +873,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
// Right now, I just handle if there are a few case and perhaps a default. // Right now, I just handle if there are a few case and perhaps a default.
bool valid = false; bool valid = false;
bool incase = false; bool incase = false;
for ( const TOKEN * _tok = tok2->tokAt(2); _tok; _tok = _tok->next ) for ( const TOKEN * _tok = tok2->tokAt(2); _tok; _tok = _tok->next() )
{ {
if ( _tok->str() == "{" ) if ( _tok->str() == "{" )
break; break;
@ -905,7 +905,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
done = false; done = false;
tok2->setstr(";"); tok2->setstr(";");
erase( tok2, tok2->tokAt(2) ); erase( tok2, tok2->tokAt(2) );
tok2 = tok2->next; tok2 = tok2->next();
bool first = true; bool first = true;
while (TOKEN::Match(tok2,"case") || TOKEN::Match(tok2,"default")) while (TOKEN::Match(tok2,"case") || TOKEN::Match(tok2,"default"))
{ {
@ -925,11 +925,11 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
instoken( tok2, "else" ); instoken( tok2, "else" );
} }
while ( tok2 && tok2->str() != "}" && ! TOKEN::Match(tok2,"break ;") ) while ( tok2 && tok2->str() != "}" && ! TOKEN::Match(tok2,"break ;") )
tok2 = tok2->next; tok2 = tok2->next();
if (TOKEN::Match(tok2,"break ;")) if (TOKEN::Match(tok2,"break ;"))
{ {
tok2->setstr(";"); tok2->setstr(";");
tok2 = tok2->next->next; tok2 = tok2->next()->next();
} }
} }
} }
@ -1000,8 +1000,8 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const
! TOKEN::findmatch(tok,"return use ;") ) ! TOKEN::findmatch(tok,"return use ;") )
{ {
const TOKEN *last = tok; const TOKEN *last = tok;
while (last->next) while (last->next())
last = last->next; last = last->next();
MemoryLeak(last, varname); MemoryLeak(last, varname);
} }
@ -1010,7 +1010,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const
{ {
TOKEN *first = tok; TOKEN *first = tok;
while ( first && first->str() == ";" ) while ( first && first->str() == ";" )
first = first->next; first = first->next();
bool noerr = false; bool noerr = false;
noerr |= TOKEN::Match( first, "alloc ; }" ); noerr |= TOKEN::Match( first, "alloc ; }" );
@ -1028,7 +1028,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const
if ( ! noerr ) if ( ! noerr )
{ {
std::cout << "Token listing..\n "; std::cout << "Token listing..\n ";
for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next ) for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next() )
std::cout << " " << tok2->str(); std::cout << " " << tok2->str();
std::cout << "\n"; std::cout << "\n";
} }
@ -1049,7 +1049,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_InFunction()
{ {
bool infunc = false; bool infunc = false;
int indentlevel = 0; int indentlevel = 0;
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
if (tok->str() == "{") if (tok->str() == "{")
indentlevel++; indentlevel++;
@ -1072,10 +1072,10 @@ void CheckMemoryLeakClass::CheckMemoryLeak_InFunction()
if (indentlevel>0 && infunc) if (indentlevel>0 && infunc)
{ {
if ( TOKEN::Match(tok, "[{};] %type% * %var% [;=]") ) if ( TOKEN::Match(tok, "[{};] %type% * %var% [;=]") )
CheckMemoryLeak_CheckScope( tok->next, tok->strAt(3) ); CheckMemoryLeak_CheckScope( tok->next(), tok->strAt(3) );
else if ( TOKEN::Match(tok, "[{};] %type% %type% * %var% [;=]") ) else if ( TOKEN::Match(tok, "[{};] %type% %type% * %var% [;=]") )
CheckMemoryLeak_CheckScope( tok->next, tok->strAt(4) ); CheckMemoryLeak_CheckScope( tok->next(), tok->strAt(4) );
} }
} }
} }
@ -1092,7 +1092,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_InFunction()
void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers() void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers()
{ {
int indentlevel = 0; int indentlevel = 0;
for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next ) for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next() )
{ {
if ( tok->str() == "{" ) if ( tok->str() == "{" )
indentlevel++; indentlevel++;
@ -1114,12 +1114,12 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN
{ {
// Go into class. // Go into class.
while ( tok1 && tok1->str() != "{" ) while ( tok1 && tok1->str() != "{" )
tok1 = tok1->next; tok1 = tok1->next();
if ( tok1 ) if ( tok1 )
tok1 = tok1->next; tok1 = tok1->next();
int indentlevel = 0; int indentlevel = 0;
for ( const TOKEN *tok = tok1; tok; tok = tok->next ) for ( const TOKEN *tok = tok1; tok; tok = tok->next() )
{ {
if ( tok->str() == "{" ) if ( tok->str() == "{" )
indentlevel++; indentlevel++;
@ -1144,7 +1144,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN
} }
// Declaring member variable.. check allocations and deallocations // Declaring member variable.. check allocations and deallocations
if ( TOKEN::Match(tok->next, "%type% * %var% ;") ) if ( TOKEN::Match(tok->next(), "%type% * %var% ;") )
{ {
if ( tok->isName() || TOKEN::Match(tok, "[;}]")) if ( tok->isName() || TOKEN::Match(tok, "[;}]"))
{ {
@ -1190,7 +1190,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable( const std::vec
// Loop through all tokens. Inspect member functions // Loop through all tokens. Inspect member functions
bool memberfunction = false; bool memberfunction = false;
int indentlevel = 0; int indentlevel = 0;
for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next ) for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next() )
{ {
if ( tok->str() == "{" ) if ( tok->str() == "{" )
indentlevel++; indentlevel++;

View File

@ -47,7 +47,7 @@ CheckOther::~CheckOther()
void CheckOther::WarningOldStylePointerCast() void CheckOther::WarningOldStylePointerCast()
{ {
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
// Old style pointer casting.. // Old style pointer casting..
if (!TOKEN::Match(tok, "( %type% * ) %var%")) if (!TOKEN::Match(tok, "( %type% * ) %var%"))
@ -74,7 +74,7 @@ void CheckOther::WarningOldStylePointerCast()
void CheckOther::WarningIsDigit() void CheckOther::WarningIsDigit()
{ {
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
bool err = false; bool err = false;
err |= TOKEN::Match(tok, "%var% >= '0' && %var% <= '9'"); err |= TOKEN::Match(tok, "%var% >= '0' && %var% <= '9'");
@ -99,7 +99,7 @@ void CheckOther::WarningIsDigit()
void CheckOther::WarningIsAlpha() void CheckOther::WarningIsAlpha()
{ {
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
if ( tok->str() != "(" ) if ( tok->str() != "(" )
continue; continue;
@ -159,7 +159,7 @@ void CheckOther::WarningRedundantCode()
{ {
// if (p) delete p // if (p) delete p
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
if ( tok->str() != "if" ) if ( tok->str() != "if" )
continue; continue;
@ -182,7 +182,7 @@ void CheckOther::WarningRedundantCode()
continue; continue;
if ( tok2->str() == "{" ) if ( tok2->str() == "{" )
tok2 = tok2->next; tok2 = tok2->next();
bool err = false; bool err = false;
if (TOKEN::Match(tok2,"delete %var% ;")) if (TOKEN::Match(tok2,"delete %var% ;"))
@ -221,12 +221,12 @@ void CheckOther::WarningIf()
{ {
// Search for 'if (condition);' // Search for 'if (condition);'
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
if (tok->str() == "if") if (tok->str() == "if")
{ {
int parlevel = 0; int parlevel = 0;
for (const TOKEN *tok2 = tok->next; tok2; tok2 = tok2->next) for (const TOKEN *tok2 = tok->next(); tok2; tok2 = tok2->next())
{ {
if (tok2->str() == "(") if (tok2->str() == "(")
parlevel++; parlevel++;
@ -250,12 +250,12 @@ void CheckOther::WarningIf()
} }
// Search for 'a=b; if (a==b)' // Search for 'a=b; if (a==b)'
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
// Begin statement? // Begin statement?
if ( ! TOKEN::Match(tok, "[;{}]") ) if ( ! TOKEN::Match(tok, "[;{}]") )
continue; continue;
tok = tok->next; tok = tok->next();
if ( ! tok ) if ( ! tok )
break; break;
@ -316,7 +316,7 @@ void CheckOther::WarningIf()
void CheckOther::InvalidFunctionUsage() void CheckOther::InvalidFunctionUsage()
{ {
for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next ) for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next() )
{ {
if ((tok->str() != "strtol") && (tok->str() != "strtoul")) if ((tok->str() != "strtol") && (tok->str() != "strtoul"))
continue; continue;
@ -324,7 +324,7 @@ void CheckOther::InvalidFunctionUsage()
// Locate the third parameter of the function call.. // Locate the third parameter of the function call..
int parlevel = 0; int parlevel = 0;
int param = 1; int param = 1;
for ( const TOKEN *tok2 = tok->next; tok2; tok2 = tok2->next ) for ( const TOKEN *tok2 = tok->next(); tok2; tok2 = tok2->next() )
{ {
if ( TOKEN::Match(tok2, "(") ) if ( TOKEN::Match(tok2, "(") )
parlevel++; parlevel++;
@ -360,7 +360,7 @@ void CheckOther::InvalidFunctionUsage()
void CheckOther::CheckIfAssignment() void CheckOther::CheckIfAssignment()
{ {
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
if (TOKEN::Match(tok, "if ( %var% = %num% )") || if (TOKEN::Match(tok, "if ( %var% = %num% )") ||
TOKEN::Match(tok, "if ( %var% = %str% )") || TOKEN::Match(tok, "if ( %var% = %str% )") ||
@ -383,7 +383,7 @@ void CheckOther::CheckUnsignedDivision()
{ {
// Check for "ivar / uvar" and "uvar / ivar" // Check for "ivar / uvar" and "uvar / ivar"
std::map<std::string, char> varsign; std::map<std::string, char> varsign;
for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next ) for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next() )
{ {
if ( TOKEN::Match(tok, "[{};(,] %type% %var% [;=,)]") ) if ( TOKEN::Match(tok, "[{};(,] %type% %var% [;=,)]") )
{ {
@ -395,7 +395,7 @@ void CheckOther::CheckUnsignedDivision()
else if ( TOKEN::Match(tok, "[{};(,] unsigned %type% %var% [;=,)]") ) else if ( TOKEN::Match(tok, "[{};(,] unsigned %type% %var% [;=,)]") )
varsign[tok->strAt(3)] = 'u'; varsign[tok->strAt(3)] = 'u';
else if (!TOKEN::Match(tok,"[).]") && TOKEN::Match(tok->next, "%var% / %var%")) else if (!TOKEN::Match(tok,"[).]") && TOKEN::Match(tok->next(), "%var% / %var%"))
{ {
const char *varname1 = tok->strAt(1); const char *varname1 = tok->strAt(1);
const char *varname2 = tok->strAt(3); const char *varname2 = tok->strAt(3);
@ -406,19 +406,19 @@ void CheckOther::CheckUnsignedDivision()
{ {
// One of the operands are signed, the other is unsigned.. // One of the operands are signed, the other is unsigned..
std::ostringstream ostr; std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok->next) << ": Warning: Division with signed and unsigned operators"; ostr << _tokenizer->fileLine(tok->next()) << ": Warning: Division with signed and unsigned operators";
_errorLogger->reportErr(ostr.str()); _errorLogger->reportErr(ostr.str());
} }
} }
else if (!TOKEN::Match(tok,"[).]") && TOKEN::Match(tok->next, "%var% / - %num%")) else if (!TOKEN::Match(tok,"[).]") && TOKEN::Match(tok->next(), "%var% / - %num%"))
{ {
const char *varname1 = tok->strAt(1); const char *varname1 = tok->strAt(1);
char sign1 = varsign[varname1]; char sign1 = varsign[varname1];
if ( sign1 == 'u' ) if ( sign1 == 'u' )
{ {
std::ostringstream ostr; std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok->next) << ": Unsigned division. The result will be wrong."; ostr << _tokenizer->fileLine(tok->next()) << ": Unsigned division. The result will be wrong.";
_errorLogger->reportErr(ostr.str()); _errorLogger->reportErr(ostr.str());
} }
} }
@ -430,7 +430,7 @@ void CheckOther::CheckUnsignedDivision()
if ( sign2 == 'u' ) if ( sign2 == 'u' )
{ {
std::ostringstream ostr; std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok->next) << ": Unsigned division. The result will be wrong."; ostr << _tokenizer->fileLine(tok->next()) << ": Unsigned division. The result will be wrong.";
_errorLogger->reportErr(ostr.str()); _errorLogger->reportErr(ostr.str());
} }
} }
@ -450,17 +450,17 @@ void CheckOther::CheckVariableScope()
// Walk through all tokens.. // Walk through all tokens..
bool func = false; bool func = false;
int indentlevel = 0; int indentlevel = 0;
for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next ) for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next() )
{ {
// Skip class and struct declarations.. // Skip class and struct declarations..
if ( (tok->str() == "class") || (tok->str() == "struct") ) if ( (tok->str() == "class") || (tok->str() == "struct") )
{ {
for (const TOKEN *tok2 = tok; tok2; tok2 = tok2->next) for (const TOKEN *tok2 = tok; tok2; tok2 = tok2->next())
{ {
if ( tok2->str() == "{" ) if ( tok2->str() == "{" )
{ {
int _indentlevel = 0; int _indentlevel = 0;
for (tok = tok2; tok; tok = tok->next) for (tok = tok2; tok; tok = tok->next())
{ {
if ( tok->str() == "{" ) if ( tok->str() == "{" )
{ {
@ -471,7 +471,7 @@ void CheckOther::CheckVariableScope()
_indentlevel--; _indentlevel--;
if ( _indentlevel <= 0 ) if ( _indentlevel <= 0 )
{ {
tok = tok->next; tok = tok->next();
break; break;
} }
} }
@ -504,7 +504,7 @@ void CheckOther::CheckVariableScope()
if ( indentlevel > 0 && func && TOKEN::Match(tok, "[{};]") ) if ( indentlevel > 0 && func && TOKEN::Match(tok, "[{};]") )
{ {
// First token of statement.. // First token of statement..
const TOKEN *tok1 = tok->next; const TOKEN *tok1 = tok->next();
if ( ! tok1 ) if ( ! tok1 )
continue; continue;
@ -532,7 +532,7 @@ void CheckOther::CheckVariableScope_LookupVar( const TOKEN *tok1, const char var
// Skip the variable declaration.. // Skip the variable declaration..
while (tok && !TOKEN::Match(tok,";")) while (tok && !TOKEN::Match(tok,";"))
tok = tok->next; tok = tok->next();
// Check if the variable is used in this indentlevel.. // Check if the variable is used in this indentlevel..
bool used = false, used1 = false; bool used = false, used1 = false;
@ -584,7 +584,7 @@ void CheckOther::CheckVariableScope_LookupVar( const TOKEN *tok1, const char var
for_or_while = false; for_or_while = false;
} }
tok = tok->next; tok = tok->next();
} }
// Warning if "used" is true // Warning if "used" is true
@ -601,7 +601,7 @@ void CheckOther::CheckVariableScope_LookupVar( const TOKEN *tok1, const char var
void CheckOther::CheckConstantFunctionParameter() void CheckOther::CheckConstantFunctionParameter()
{ {
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
if ( TOKEN::Match(tok,"[,(] const std :: %type% %var% [,)]") ) if ( TOKEN::Match(tok,"[,(] const std :: %type% %var% [,)]") )
{ {
@ -642,7 +642,7 @@ void CheckOther::CheckStructMemberUsage()
{ {
const char *structname = 0; const char *structname = 0;
for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next ) for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next() )
{ {
if ( tok->FileIndex != 0 ) if ( tok->FileIndex != 0 )
continue; continue;
@ -654,13 +654,13 @@ void CheckOther::CheckStructMemberUsage()
if (structname && TOKEN::Match(tok, "[{;]")) if (structname && TOKEN::Match(tok, "[{;]"))
{ {
const char *varname = 0; const char *varname = 0;
if (TOKEN::Match(tok->next, "%type% %var% [;[]")) if (TOKEN::Match(tok->next(), "%type% %var% [;[]"))
varname = tok->strAt( 2 ); varname = tok->strAt( 2 );
else if (TOKEN::Match(tok->next, "%type% %type% %var% [;[]")) else if (TOKEN::Match(tok->next(), "%type% %type% %var% [;[]"))
varname = tok->strAt( 2 ); varname = tok->strAt( 2 );
else if (TOKEN::Match(tok->next, "%type% * %var% [;[]")) else if (TOKEN::Match(tok->next(), "%type% * %var% [;[]"))
varname = tok->strAt( 3 ); varname = tok->strAt( 3 );
else if (TOKEN::Match(tok->next, "%type% %type% * %var% [;[]")) else if (TOKEN::Match(tok->next(), "%type% %type% * %var% [;[]"))
varname = tok->strAt( 4 ); varname = tok->strAt( 4 );
else else
continue; continue;
@ -669,7 +669,7 @@ void CheckOther::CheckStructMemberUsage()
varnames[0] = varname; varnames[0] = varname;
varnames[1] = 0; varnames[1] = 0;
bool used = false; bool used = false;
for ( const TOKEN *tok2 = _tokenizer->tokens(); tok2; tok2 = tok2->next ) for ( const TOKEN *tok2 = _tokenizer->tokens(); tok2; tok2 = tok2->next() )
{ {
if ( tok->FileIndex != 0 ) if ( tok->FileIndex != 0 )
continue; continue;
@ -703,7 +703,7 @@ void CheckOther::CheckStructMemberUsage()
void CheckOther::CheckCharVariable() void CheckOther::CheckCharVariable()
{ {
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next) for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
// Declaring the variable.. // Declaring the variable..
if ( TOKEN::Match(tok, "[{};(,] char %var% [;=,)]") ) if ( TOKEN::Match(tok, "[{};(,] char %var% [;=,)]") )
@ -713,7 +713,7 @@ void CheckOther::CheckCharVariable()
// Check usage of char variable.. // Check usage of char variable..
int indentlevel = 0; int indentlevel = 0;
for ( const TOKEN *tok2 = tok->next; tok2; tok2 = tok2->next ) for ( const TOKEN *tok2 = tok->next(); tok2; tok2 = tok2->next() )
{ {
if ( tok2->str() == "{" ) if ( tok2->str() == "{" )
++indentlevel; ++indentlevel;
@ -725,10 +725,10 @@ void CheckOther::CheckCharVariable()
break; break;
} }
if ((tok2->str() != ".") && TOKEN::Match(tok2->next, "%var% [ %var1% ]", varname)) if ((tok2->str() != ".") && TOKEN::Match(tok2->next(), "%var% [ %var1% ]", varname))
{ {
std::ostringstream errmsg; std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok2->next) << ": Warning - using char variable as array index"; errmsg << _tokenizer->fileLine(tok2->next()) << ": Warning - using char variable as array index";
_errorLogger->reportErr(errmsg.str()); _errorLogger->reportErr(errmsg.str());
break; break;
} }
@ -759,7 +759,7 @@ void CheckOther::CheckIncompleteStatement()
{ {
int parlevel = 0; int parlevel = 0;
for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next ) for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next() )
{ {
if ( tok->str() == "(" ) if ( tok->str() == "(" )
++parlevel; ++parlevel;
@ -769,17 +769,17 @@ void CheckOther::CheckIncompleteStatement()
if ( parlevel != 0 ) if ( parlevel != 0 )
continue; continue;
if ( (tok->str() != "#") && 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; std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok->next) << ": Redundant code: Found a statement that begins with string constant"; errmsg << _tokenizer->fileLine(tok->next()) << ": Redundant code: Found a statement that begins with string constant";
_errorLogger->reportErr(errmsg.str()); _errorLogger->reportErr(errmsg.str());
} }
if ( !TOKEN::Match(tok,"#") && TOKEN::Match(tok->next,"; %num%") && !TOKEN::Match(tok->tokAt(3), ",") ) if ( !TOKEN::Match(tok,"#") && TOKEN::Match(tok->next(),"; %num%") && !TOKEN::Match(tok->tokAt(3), ",") )
{ {
std::ostringstream errmsg; std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok->next) << ": Redundant code: Found a statement that begins with numeric constant"; errmsg << _tokenizer->fileLine(tok->next()) << ": Redundant code: Found a statement that begins with numeric constant";
_errorLogger->reportErr(errmsg.str()); _errorLogger->reportErr(errmsg.str());
} }
} }
@ -801,19 +801,19 @@ void CheckOther::unreachableCode()
while ( tok ) while ( tok )
{ {
// Goto the 'return' token // Goto the 'return' token
tok = tok->next; tok = tok->next();
// Locate the end of the 'return' statement // Locate the end of the 'return' statement
while ( tok && ! TOKEN::Match(tok, ";") ) while ( tok && ! TOKEN::Match(tok, ";") )
tok = tok->next; tok = tok->next();
while ( tok && TOKEN::Match(tok->next, ";") ) while ( tok && TOKEN::Match(tok->next(), ";") )
tok = tok->next; tok = tok->next();
// If there is a statement below the return it is unreachable // If there is a statement below the return it is unreachable
if (!TOKEN::Match(tok, "; case|default|}|#") && !TOKEN::Match(tok, "; %var% :")) if (!TOKEN::Match(tok, "; case|default|}|#") && !TOKEN::Match(tok, "; %var% :"))
{ {
std::ostringstream errmsg; std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok->next) << ": Unreachable code below a 'return'"; errmsg << _tokenizer->fileLine(tok->next()) << ": Unreachable code below a 'return'";
_errorLogger->reportErr(errmsg.str()); _errorLogger->reportErr(errmsg.str());
} }
@ -860,7 +860,7 @@ void CheckOther::functionVariableUsage()
static const unsigned int USAGE_WRITE = 4; static const unsigned int USAGE_WRITE = 4;
int indentlevel = 0; int indentlevel = 0;
for ( const TOKEN *tok = tok1; tok; tok = tok->next ) for ( const TOKEN *tok = tok1; tok; tok = tok->next() )
{ {
if ( tok->str() == "{" ) if ( tok->str() == "{" )
++indentlevel; ++indentlevel;
@ -889,10 +889,10 @@ void CheckOther::functionVariableUsage()
if ( TOKEN::Match(tok, ">>|& %var%") ) if ( TOKEN::Match(tok, ">>|& %var%") )
varUsage[ tok->strAt(1) ] |= USAGE_WRITE; varUsage[ tok->strAt(1) ] |= USAGE_WRITE;
if ((TOKEN::Match(tok,"[(=&!]") || isOp(tok)) && TOKEN::Match(tok->next, "%var%")) if ((TOKEN::Match(tok,"[(=&!]") || isOp(tok)) && TOKEN::Match(tok->next(), "%var%"))
varUsage[ tok->strAt(1) ] |= USAGE_READ; varUsage[ tok->strAt(1) ] |= USAGE_READ;
if (TOKEN::Match(tok, "%var%") && (tok->next->str()==")" || isOp(tok->next))) if (TOKEN::Match(tok, "%var%") && (tok->next()->str()==")" || isOp(tok->next())))
varUsage[ tok->str() ] |= USAGE_READ; varUsage[ tok->str() ] |= USAGE_READ;
if ( TOKEN::Match(tok, "[(,] %var% [,)]") ) if ( TOKEN::Match(tok, "[(,] %var% [,)]") )
@ -914,26 +914,26 @@ void CheckOther::functionVariableUsage()
if ( usage == USAGE_DECLARE ) if ( usage == USAGE_DECLARE )
{ {
std::ostringstream errmsg; std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok1->next) << ": Unused variable '" << varname << "'"; errmsg << _tokenizer->fileLine(tok1->next()) << ": Unused variable '" << varname << "'";
_errorLogger->reportErr(errmsg.str()); _errorLogger->reportErr(errmsg.str());
} }
else if ( ! (usage & USAGE_READ) ) else if ( ! (usage & USAGE_READ) )
{ {
std::ostringstream errmsg; std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok1->next) << ": Variable '" << varname << "' is assigned a value that is never used"; errmsg << _tokenizer->fileLine(tok1->next()) << ": Variable '" << varname << "' is assigned a value that is never used";
_errorLogger->reportErr(errmsg.str()); _errorLogger->reportErr(errmsg.str());
} }
else if ( ! (usage & USAGE_WRITE) ) else if ( ! (usage & USAGE_WRITE) )
{ {
std::ostringstream errmsg; std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok1->next) << ": Variable '" << varname << "' is not assigned a value"; errmsg << _tokenizer->fileLine(tok1->next()) << ": Variable '" << varname << "' is not assigned a value";
_errorLogger->reportErr(errmsg.str()); _errorLogger->reportErr(errmsg.str());
} }
} }
// Goto next executing scope.. // Goto next executing scope..
tok1 = TOKEN::findmatch( tok1->next, ") const| {" ); tok1 = TOKEN::findmatch( tok1->next(), ") const| {" );
} }
} }

View File

@ -28,6 +28,8 @@
class ErrorLogger class ErrorLogger
{ {
public: public:
virtual ~ErrorLogger() {}
/** /**
* Errors and warnings are directed here. * Errors and warnings are directed here.
* *

View File

@ -300,7 +300,7 @@ private:
"\n" "\n"
"static void f()\n" "static void f()\n"
"{\n" "{\n"
" for ( ABC *abc = abc1; abc; abc = abc->next )\n" " for ( ABC *abc = abc1; abc; abc = abc->next() )\n"
" {\n" " {\n"
" abc->str[10] = 0;\n" " abc->str[10] = 0;\n"
" }\n" " }\n"

View File

@ -47,7 +47,7 @@ private:
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
std::string ret; std::string ret;
for ( const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next ) for ( const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next() )
{ {
ret += std::string(tok->aaaa()) + " "; ret += std::string(tok->aaaa()) + " ";
} }

View File

@ -59,7 +59,7 @@ private:
bool cmptok(const char *expected[], const TOKEN *actual) bool cmptok(const char *expected[], const TOKEN *actual)
{ {
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->aaaa() ) != 0)
return false; return false;
@ -210,7 +210,7 @@ private:
tokenizer.simplifyTokenList(); tokenizer.simplifyTokenList();
std::ostringstream ostr; std::ostringstream ostr;
for (const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next) for (const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next())
ostr << " " << tok->str(); ostr << " " << tok->str();
ASSERT_EQUALS( std::string(" void f ( ) { if ( true ) ; }"), ostr.str() ); ASSERT_EQUALS( std::string(" void f ( ) { if ( true ) ; }"), ostr.str() );
} }
@ -281,7 +281,7 @@ private:
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.setVarId(); tokenizer.setVarId();
for ( const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next ) for ( const TOKEN *tok = tokenizer.tokens(); tok; tok = tok->next() )
{ {
if ( tok->str() != "i" ) if ( tok->str() != "i" )
ASSERT_EQUALS( 0, tok->varId() ); ASSERT_EQUALS( 0, tok->varId() );

View File

@ -31,7 +31,8 @@ TOKEN::TOKEN()
_cstr = 0; _cstr = 0;
_str = ""; _str = "";
linenr = 0; linenr = 0;
next = 0; _next = 0;
_varId = 0;
_isName = false; _isName = false;
_isNumber = false; _isNumber = false;
} }
@ -56,9 +57,9 @@ void TOKEN::setstr( const char s[] )
void TOKEN::combineWithNext(const char str1[], const char str2[]) void TOKEN::combineWithNext(const char str1[], const char str2[])
{ {
if (!(next)) if (!(_next))
return; return;
if (_str!=str1 || next->_str!=str2) if (_str!=str1 || _next->_str!=str2)
return; return;
std::string newstr(std::string(str1) + std::string(str2)); std::string newstr(std::string(str1) + std::string(str2));
@ -68,8 +69,8 @@ void TOKEN::combineWithNext(const char str1[], const char str2[])
void TOKEN::deleteNext() void TOKEN::deleteNext()
{ {
TOKEN *n = next; TOKEN *n = _next;
next = n->next; _next = n->next();
delete n; delete n;
} }
@ -78,7 +79,7 @@ const TOKEN *TOKEN::tokAt(int index) const
const TOKEN *tok = this; const TOKEN *tok = this;
while (index>0 && tok) while (index>0 && tok)
{ {
tok = tok->next; tok = tok->next();
index--; index--;
} }
return tok; return tok;
@ -247,7 +248,7 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
else if (str != tok->_str) else if (str != tok->_str)
return false; return false;
tok = tok->next; tok = tok->next();
if (!tok && *p) if (!tok && *p)
return false; return false;
} }
@ -279,7 +280,7 @@ bool TOKEN::isStandardType() const
const TOKEN *TOKEN::findmatch(const TOKEN *tok, const char pattern[], const char *varname1[], const char *varname2[]) const TOKEN *TOKEN::findmatch(const TOKEN *tok, const char pattern[], const char *varname1[], const char *varname2[])
{ {
for ( ; tok; tok = tok->next) for ( ; tok; tok = tok->next())
{ {
if ( TOKEN::Match(tok, pattern, varname1, varname2) ) if ( TOKEN::Match(tok, pattern, varname1, varname2) )
return tok; return tok;
@ -289,7 +290,7 @@ const TOKEN *TOKEN::findmatch(const TOKEN *tok, const char pattern[], const char
const TOKEN *TOKEN::findtoken(const TOKEN *tok1, const char *tokenstr[]) const TOKEN *TOKEN::findtoken(const TOKEN *tok1, const char *tokenstr[])
{ {
for (const TOKEN *ret = tok1; ret; ret = ret->next) for (const TOKEN *ret = tok1; ret; ret = ret->next())
{ {
unsigned int i = 0; unsigned int i = 0;
const TOKEN *tok = ret; const TOKEN *tok = ret;
@ -299,7 +300,7 @@ const TOKEN *TOKEN::findtoken(const TOKEN *tok1, const char *tokenstr[])
return NULL; return NULL;
if (*(tokenstr[i]) && (tokenstr[i] != tok->_str)) if (*(tokenstr[i]) && (tokenstr[i] != tok->_str))
break; break;
tok = tok->next; tok = tok->next();
i++; i++;
} }
if (!tokenstr[i]) if (!tokenstr[i])
@ -317,3 +318,14 @@ void TOKEN::varId( unsigned int id )
{ {
_varId = id; _varId = id;
} }
TOKEN *TOKEN::next() const
{
return _next;
}
void TOKEN::next( TOKEN *next )
{
_next = next;
}

View File

@ -114,9 +114,9 @@ public:
unsigned int FileIndex; unsigned int FileIndex;
unsigned int linenr; unsigned int linenr;
TOKEN *next() const;
void next( TOKEN *next );
TOKEN *next;
unsigned int varId() const; unsigned int varId() const;
void varId( unsigned int id ); void varId( unsigned int id );
@ -126,6 +126,7 @@ private:
bool _isName; bool _isName;
bool _isNumber; bool _isNumber;
unsigned int _varId; unsigned int _varId;
TOKEN *_next;
}; };
#endif // TOKEN_H #endif // TOKEN_H

View File

@ -68,7 +68,7 @@ TOKEN *Tokenizer::_gettok(TOKEN *tok, int index)
{ {
while (tok && index>0) while (tok && index>0)
{ {
tok = tok->next; tok = tok->next();
index--; index--;
} }
return tok; return tok;
@ -165,7 +165,7 @@ void Tokenizer::addtoken(const char str[], const unsigned int lineno, const unsi
newtoken->FileIndex = fileno; newtoken->FileIndex = fileno;
if (_tokensBack) if (_tokensBack)
{ {
_tokensBack->next = newtoken; _tokensBack->next( newtoken );
_tokensBack = newtoken; _tokensBack = newtoken;
} }
else else
@ -217,11 +217,11 @@ void Tokenizer::InsertTokens(TOKEN *dest, TOKEN *src, unsigned int n)
NewToken->linenr = src->linenr; NewToken->linenr = src->linenr;
NewToken->setstr(src->aaaa()); NewToken->setstr(src->aaaa());
NewToken->next = dest->next; NewToken->next( dest->next() );
dest->next = NewToken; dest->next( NewToken );
dest = dest->next; dest = dest->next();
src = src->next; src = src->next();
n--; n--;
} }
} }
@ -498,7 +498,7 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
addtoken( CurrentToken.c_str(), lineno, FileIndex ); addtoken( CurrentToken.c_str(), lineno, FileIndex );
// Combine tokens.. // Combine tokens..
for (TOKEN *tok = _tokens; tok && tok->next; tok = tok->next) for (TOKEN *tok = _tokens; tok && tok->next(); tok = tok->next())
{ {
tok->combineWithNext("<", "<"); tok->combineWithNext("<", "<");
tok->combineWithNext(">", ">"); tok->combineWithNext(">", ">");
@ -527,7 +527,7 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
} }
// Replace "->" with "." // Replace "->" with "."
for ( TOKEN *tok = _tokens; tok; tok = tok->next ) for ( TOKEN *tok = _tokens; tok; tok = tok->next() )
{ {
if ( tok->str() == "->" ) if ( tok->str() == "->" )
{ {
@ -536,13 +536,13 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
} }
// typedef.. // typedef..
for ( TOKEN *tok = _tokens; tok; tok = tok->next ) for ( TOKEN *tok = _tokens; tok; tok = tok->next() )
{ {
if (TOKEN::Match(tok, "typedef %type% %type% ;")) if (TOKEN::Match(tok, "typedef %type% %type% ;"))
{ {
const char *type1 = tok->strAt( 1); const char *type1 = tok->strAt( 1);
const char *type2 = tok->strAt( 2); const char *type2 = tok->strAt( 2);
for ( TOKEN *tok2 = tok; tok2; tok2 = tok2->next ) for ( TOKEN *tok2 = tok; tok2; tok2 = tok2->next() )
{ {
if (tok2->aaaa()!=type1 && tok2->aaaa()!=type2 && (tok2->str() == type2)) if (tok2->aaaa()!=type1 && tok2->aaaa()!=type2 && (tok2->str() == type2))
{ {
@ -559,9 +559,9 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
TOKEN *tok2 = tok; TOKEN *tok2 = tok;
while ( ! TOKEN::Match(tok2, ";") ) while ( ! TOKEN::Match(tok2, ";") )
tok2 = tok2->next; tok2 = tok2->next();
for ( ; tok2; tok2 = tok2->next ) for ( ; tok2; tok2 = tok2->next() )
{ {
if (tok2->aaaa()!=type3 && (tok2->str() == type3)) if (tok2->aaaa()!=type3 && (tok2->str() == type3))
{ {
@ -571,8 +571,8 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
newtok->setstr(type2); newtok->setstr(type2);
newtok->FileIndex = tok2->FileIndex; newtok->FileIndex = tok2->FileIndex;
newtok->linenr = tok2->linenr; newtok->linenr = tok2->linenr;
newtok->next = tok2->next; newtok->next( tok2->next() );
tok2->next = newtok; tok2->next( newtok );
tok2 = newtok; tok2 = newtok;
} }
} }
@ -581,17 +581,17 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
// Remove __asm.. // Remove __asm..
for ( TOKEN *tok = _tokens; tok; tok = tok->next ) for ( TOKEN *tok = _tokens; tok; tok = tok->next() )
{ {
if ( TOKEN::Match(tok->next, "__asm {") ) if ( TOKEN::Match(tok->next(), "__asm {") )
{ {
while ( tok->next ) while ( tok->next() )
{ {
bool last = TOKEN::Match( tok->next, "}" ); bool last = TOKEN::Match( tok->next(), "}" );
// Unlink and delete tok->next // Unlink and delete tok->next()
TOKEN *next = tok->next; TOKEN *next = tok->next();
tok->next = tok->next->next; tok->next( tok->next()->next() );
delete next; delete next;
// break if this was the last token to delete.. // break if this was the last token to delete..
@ -605,12 +605,12 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
while ( TOKEN::Match(_tokens, "volatile") ) while ( TOKEN::Match(_tokens, "volatile") )
{ {
TOKEN *tok = _tokens; TOKEN *tok = _tokens;
_tokens = _tokens->next; _tokens = _tokens->next();
delete tok; delete tok;
} }
for ( TOKEN *tok = _tokens; tok; tok = tok->next ) for ( TOKEN *tok = _tokens; tok; tok = tok->next() )
{ {
while ( TOKEN::Match(tok->next, "volatile") ) while ( TOKEN::Match(tok->next(), "volatile") )
{ {
tok->deleteNext(); tok->deleteNext();
} }
@ -623,26 +623,26 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
void Tokenizer::setVarId() void Tokenizer::setVarId()
{ {
// Clear all variable ids // Clear all variable ids
for ( TOKEN *tok = _tokens; tok; tok = tok->next ) for ( TOKEN *tok = _tokens; tok; tok = tok->next() )
tok->varId( 0 ); tok->varId( 0 );
// Set variable ids.. // Set variable ids..
unsigned int _varId = 0; unsigned int _varId = 0;
for ( TOKEN *tok = _tokens; tok; tok = tok->next ) for ( TOKEN *tok = _tokens; tok; tok = tok->next() )
{ {
if ( ! TOKEN::Match(tok, "[;{}(] %type% %var%") ) if ( ! TOKEN::Match(tok, "[;{}(] %type% %var%") )
continue; continue;
// Determine name of declared variable.. // Determine name of declared variable..
const char *varname = 0; const char *varname = 0;
TOKEN *tok2 = tok->next; TOKEN *tok2 = tok->next();
while ( ! TOKEN::Match( tok2, "[;[=(]" ) ) while ( ! TOKEN::Match( tok2, "[;[=(]" ) )
{ {
if ( tok2->isName() ) if ( tok2->isName() )
varname = tok2->strAt(0); varname = tok2->strAt(0);
else if ( tok2->str() != "*" ) else if ( tok2->str() != "*" )
break; break;
tok2 = tok2->next; tok2 = tok2->next();
} }
// Variable declaration found => Set variable ids // Variable declaration found => Set variable ids
@ -651,7 +651,7 @@ void Tokenizer::setVarId()
++_varId; ++_varId;
int indentlevel = 0; int indentlevel = 0;
int parlevel = 0; int parlevel = 0;
for ( tok2 = tok->next; tok2 && indentlevel >= 0; tok2 = tok2->next ) for ( tok2 = tok->next(); tok2 && indentlevel >= 0; tok2 = tok2->next() )
{ {
if ( tok2->str() == varname ) if ( tok2->str() == varname )
tok2->varId( _varId ); tok2->varId( _varId );
@ -679,23 +679,23 @@ void Tokenizer::simplifyTokenList()
{ {
// Remove the keyword 'unsigned' // Remove the keyword 'unsigned'
for ( TOKEN *tok = _tokens; tok; tok = tok->next ) for ( TOKEN *tok = _tokens; tok; tok = tok->next() )
{ {
if (tok->next && (tok->next->str() == "unsigned")) if (tok->next() && (tok->next()->str() == "unsigned"))
{ {
tok->deleteNext(); tok->deleteNext();
} }
} }
// Replace constants.. // Replace constants..
for (TOKEN *tok = _tokens; tok; tok = tok->next) for (TOKEN *tok = _tokens; tok; tok = tok->next())
{ {
if (TOKEN::Match(tok,"const %type% %var% = %num% ;")) if (TOKEN::Match(tok,"const %type% %var% = %num% ;"))
{ {
const char *sym = tok->strAt(2); const char *sym = tok->strAt(2);
const char *num = tok->strAt(4); const char *num = tok->strAt(4);
for (TOKEN *tok2 = _gettok(tok,6); tok2; tok2 = tok2->next) for (TOKEN *tok2 = _gettok(tok,6); tok2; tok2 = tok2->next())
{ {
if (tok2->str() == sym) if (tok2->str() == sym)
{ {
@ -714,7 +714,7 @@ void Tokenizer::simplifyTokenList()
_typeSize["long"] = sizeof(long); _typeSize["long"] = sizeof(long);
_typeSize["float"] = sizeof(float); _typeSize["float"] = sizeof(float);
_typeSize["double"] = sizeof(double); _typeSize["double"] = sizeof(double);
for (TOKEN *tok = _tokens; tok; tok = tok->next) for (TOKEN *tok = _tokens; tok; tok = tok->next())
{ {
if (TOKEN::Match(tok,"class %var%")) if (TOKEN::Match(tok,"class %var%"))
{ {
@ -729,7 +729,7 @@ void Tokenizer::simplifyTokenList()
// Replace 'sizeof(type)'.. // Replace 'sizeof(type)'..
for (TOKEN *tok = _tokens; tok; tok = tok->next) for (TOKEN *tok = _tokens; tok; tok = tok->next())
{ {
if (tok->str() != "sizeof") if (tok->str() != "sizeof")
continue; continue;
@ -772,7 +772,7 @@ void Tokenizer::simplifyTokenList()
} }
// Replace 'sizeof(var)' // Replace 'sizeof(var)'
for (TOKEN *tok = _tokens; tok; tok = tok->next) for (TOKEN *tok = _tokens; tok; tok = tok->next())
{ {
// type array [ num ] ; // type array [ num ] ;
if ( ! TOKEN::Match(tok, "%type% %var% [ %num% ] ;") ) if ( ! TOKEN::Match(tok, "%type% %var% [ %num% ] ;") )
@ -787,7 +787,7 @@ void Tokenizer::simplifyTokenList()
// Replace 'sizeof(var)' with number // Replace 'sizeof(var)' with number
int indentlevel = 0; int indentlevel = 0;
for ( TOKEN *tok2 = _gettok(tok,5); tok2; tok2 = tok2->next ) for ( TOKEN *tok2 = _gettok(tok,5); tok2; tok2 = tok2->next() )
{ {
if (tok2->str() == "{") if (tok2->str() == "{")
{ {
@ -825,9 +825,9 @@ void Tokenizer::simplifyTokenList()
// Simple calculations.. // Simple calculations..
for ( bool done = false; !done; done = true ) for ( bool done = false; !done; done = true )
{ {
for (TOKEN *tok = _tokens; tok; tok = tok->next) for (TOKEN *tok = _tokens; tok; tok = tok->next())
{ {
if (TOKEN::Match(tok->next, "* 1") || TOKEN::Match(tok->next, "1 *")) if (TOKEN::Match(tok->next(), "* 1") || TOKEN::Match(tok->next(), "1 *"))
{ {
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
tok->deleteNext(); tok->deleteNext();
@ -851,7 +851,7 @@ void Tokenizer::simplifyTokenList()
case '*': i1 *= i2; break; case '*': i1 *= i2; break;
case '/': i1 /= i2; break; case '/': i1 /= i2; break;
} }
tok = tok->next; tok = tok->next();
std::ostringstream str; std::ostringstream str;
str << i1; str << i1;
tok->setstr(str.str().c_str()); tok->setstr(str.str().c_str());
@ -867,12 +867,12 @@ 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->aaaa0()) )
continue; continue;
TOKEN *next = tok->next; TOKEN *next = tok->next();
if ( ! next ) if ( ! next )
break; break;
@ -884,7 +884,7 @@ void Tokenizer::simplifyTokenList()
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
tok = tok->next; tok = tok->next();
tok->setstr(str[i]); tok->setstr(str[i]);
} }
@ -896,12 +896,12 @@ void Tokenizer::simplifyTokenList()
// Split up variable declarations if possible.. // Split up variable declarations if possible..
for (TOKEN *tok = _tokens; tok; tok = tok->next) for (TOKEN *tok = _tokens; tok; tok = tok->next())
{ {
if ( ! TOKEN::Match(tok, "[{};]") ) if ( ! TOKEN::Match(tok, "[{};]") )
continue; continue;
TOKEN *type0 = tok->next; TOKEN *type0 = tok->next();
if (!TOKEN::Match(type0, "%type%")) if (!TOKEN::Match(type0, "%type%"))
continue; continue;
if (TOKEN::Match(type0, "else") || TOKEN::Match(type0, "return")) if (TOKEN::Match(type0, "else") || TOKEN::Match(type0, "return"))
@ -912,7 +912,7 @@ void Tokenizer::simplifyTokenList()
if ( TOKEN::Match(type0, "%type% %var% ,|=") ) if ( TOKEN::Match(type0, "%type% %var% ,|=") )
{ {
if ( type0->next->str() != "operator" ) if ( type0->next()->str() != "operator" )
{ {
tok2 = _gettok(type0, 2); // The ',' or '=' token tok2 = _gettok(type0, 2); // The ',' or '=' token
typelen = 1; typelen = 1;
@ -921,7 +921,7 @@ void Tokenizer::simplifyTokenList()
else if ( TOKEN::Match(type0, "%type% * %var% ,|=") ) else if ( TOKEN::Match(type0, "%type% * %var% ,|=") )
{ {
if ( type0->next->next->str() != "operator" ) if ( type0->next()->next()->str() != "operator" )
{ {
tok2 = _gettok(type0, 3); // The ',' token tok2 = _gettok(type0, 3); // The ',' token
typelen = 1; typelen = 1;
@ -985,7 +985,7 @@ void Tokenizer::simplifyTokenList()
// "type var =" => "type var; var =" // "type var =" => "type var; var ="
TOKEN *VarTok = _gettok(type0,typelen); TOKEN *VarTok = _gettok(type0,typelen);
if (VarTok->aaaa0()=='*') if (VarTok->aaaa0()=='*')
VarTok = VarTok->next; VarTok = VarTok->next();
InsertTokens(eq, VarTok, 2); InsertTokens(eq, VarTok, 2);
eq->setstr(";"); eq->setstr(";");
@ -998,25 +998,25 @@ void Tokenizer::simplifyTokenList()
break; break;
} }
tok2 = tok2->next; tok2 = tok2->next();
} }
} }
} }
} }
// Replace NULL with 0.. // Replace NULL with 0..
for ( TOKEN *tok = _tokens; tok; tok = tok->next ) for ( TOKEN *tok = _tokens; tok; tok = tok->next() )
{ {
if ( TOKEN::Match(tok, "NULL") ) if ( TOKEN::Match(tok, "NULL") )
tok->setstr("0"); tok->setstr("0");
} }
// Replace pointer casts of 0.. "(char *)0" => "0" // Replace pointer casts of 0.. "(char *)0" => "0"
for ( TOKEN *tok = _tokens; tok; tok = tok->next ) for ( TOKEN *tok = _tokens; tok; tok = tok->next() )
{ {
if ( TOKEN::Match(tok->next, "( %type% * ) 0") || TOKEN::Match(tok->next,"( %type% %type% * ) 0") ) if ( TOKEN::Match(tok->next(), "( %type% * ) 0") || TOKEN::Match(tok->next(),"( %type% %type% * ) 0") )
{ {
while (!TOKEN::Match(tok->next,"0")) while (!TOKEN::Match(tok->next(),"0"))
tok->deleteNext(); tok->deleteNext();
} }
} }
@ -1034,16 +1034,16 @@ bool Tokenizer::simplifyConditions()
{ {
bool ret = true; bool ret = true;
for ( TOKEN *tok = _tokens; tok; tok = tok->next ) for ( TOKEN *tok = _tokens; tok; tok = tok->next() )
{ {
if (TOKEN::Match(tok, "( true &&") || TOKEN::Match(tok, "&& true &&") || TOKEN::Match(tok->next, "&& true )")) if (TOKEN::Match(tok, "( true &&") || TOKEN::Match(tok, "&& true &&") || TOKEN::Match(tok->next(), "&& true )"))
{ {
tok->deleteNext(); tok->deleteNext();
tok->deleteNext(); tok->deleteNext();
ret = false; ret = false;
} }
else if (TOKEN::Match(tok, "( false ||") || TOKEN::Match(tok, "|| false ||") || TOKEN::Match(tok->next, "|| false )")) else if (TOKEN::Match(tok, "( false ||") || TOKEN::Match(tok, "|| false ||") || TOKEN::Match(tok->next(), "|| false )"))
{ {
tok->deleteNext(); tok->deleteNext();
tok->deleteNext(); tok->deleteNext();
@ -1053,10 +1053,10 @@ bool Tokenizer::simplifyConditions()
// Change numeric constant in condition to "true" or "false" // Change numeric constant in condition to "true" or "false"
const TOKEN *tok2 = tok->tokAt(2); const TOKEN *tok2 = tok->tokAt(2);
if ((TOKEN::Match(tok, "(") || TOKEN::Match(tok, "&&") || TOKEN::Match(tok, "||")) && if ((TOKEN::Match(tok, "(") || TOKEN::Match(tok, "&&") || TOKEN::Match(tok, "||")) &&
TOKEN::Match(tok->next, "%num%") && TOKEN::Match(tok->next(), "%num%") &&
(TOKEN::Match(tok2, ")") || TOKEN::Match(tok2, "&&") || TOKEN::Match(tok2, "||")) ) (TOKEN::Match(tok2, ")") || TOKEN::Match(tok2, "&&") || TOKEN::Match(tok2, "||")) )
{ {
tok->next->setstr((tok->next->str() != "0") ? "true" : "false"); tok->next()->setstr((tok->next()->str() != "0") ? "true" : "false");
ret = false; ret = false;
} }
@ -1087,7 +1087,7 @@ bool Tokenizer::simplifyConditions()
if ( ! cmp.empty() ) if ( ! cmp.empty() )
{ {
tok = tok->next; tok = tok->next();
tok->deleteNext(); tok->deleteNext();
tok->deleteNext(); tok->deleteNext();
@ -1130,7 +1130,7 @@ void Tokenizer::fillFunctionList()
bool classfunc = false; bool classfunc = false;
int indentlevel = 0; int indentlevel = 0;
for ( const TOKEN *tok = _tokens; tok; tok = tok->next ) for ( const TOKEN *tok = _tokens; tok; tok = tok->next() )
{ {
if ( tok->str() == "{" ) if ( tok->str() == "{" )
++indentlevel; ++indentlevel;
@ -1155,7 +1155,7 @@ void Tokenizer::fillFunctionList()
else if (TOKEN::Match(tok, "%var% (")) else if (TOKEN::Match(tok, "%var% ("))
{ {
// Check if this is the first token of a function implementation.. // Check if this is the first token of a function implementation..
for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next ) for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next() )
{ {
if ( tok2->str() == ";" ) if ( tok2->str() == ";" )
{ {
@ -1178,8 +1178,8 @@ void Tokenizer::fillFunctionList()
else else
{ {
tok = tok2; tok = tok2;
while (tok->next && !strchr(";{", tok->next->aaaa0())) while (tok->next() && !strchr(";{", tok->next()->aaaa0()))
tok = tok->next; tok = tok->next();
} }
break; break;
} }
@ -1241,7 +1241,7 @@ void Tokenizer::deleteTokens(TOKEN *tok)
{ {
while (tok) while (tok)
{ {
TOKEN *next = tok->next; TOKEN *next = tok->next();
delete tok; delete tok;
tok = next; tok = next;
} }
@ -1252,7 +1252,7 @@ void Tokenizer::deleteTokens(TOKEN *tok)
const char *Tokenizer::getParameterName( const TOKEN *ftok, int par ) const char *Tokenizer::getParameterName( const TOKEN *ftok, int par )
{ {
int _par = 1; int _par = 1;
for ( ; ftok; ftok = ftok->next) for ( ; ftok; ftok = ftok->next())
{ {
if ( TOKEN::Match(ftok, ",") ) if ( TOKEN::Match(ftok, ",") )
++_par; ++_par;