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

View File

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

View File

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

View File

@ -48,7 +48,7 @@ CheckHeaders::~CheckHeaders()
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
if (tok->FileIndex == 0)
@ -62,8 +62,8 @@ void CheckHeaders::WarningHeaderWithImplementation()
// Goto next file..
unsigned int fileindex = tok->FileIndex;
while ( tok->next && tok->FileIndex == fileindex )
tok = tok->next;
while ( tok->next() && tok->FileIndex == fileindex )
tok = tok->next();
}
}
}
@ -83,14 +83,14 @@ void CheckHeaders::WarningHeaderWithImplementation()
void CheckHeaders::WarningIncludeHeader()
{
// 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")
continue;
// Get fileindex of included file..
unsigned int hfile = 0;
const char *includefile = includetok->next->aaaa();
const char *includefile = includetok->next()->aaaa();
while (hfile < _tokenizer->getFiles()->size())
{
if ( Tokenizer::SameFileName( _tokenizer->getFiles()->at(hfile).c_str(), includefile ) )
@ -112,7 +112,7 @@ void CheckHeaders::WarningIncludeHeader()
// Extract classes and names in the header..
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 )
continue;
@ -150,12 +150,12 @@ void CheckHeaders::WarningIncludeHeader()
// --------------------------------------
else if (tok1->str() == "enum")
{
tok1 = tok1->next;
tok1 = tok1->next();
while ( ! TOKEN::Match( tok1, "; %any%" ) )
{
if ( tok1->isName() )
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)
continue;
int parlevel = 0;
while (tok1->next)
while (tok1->next())
{
if ( TOKEN::Match(tok1, "[({]") )
parlevel++;
@ -197,7 +197,7 @@ void CheckHeaders::WarningIncludeHeader()
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...
bool Needed = 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)
continue;

View File

@ -73,8 +73,8 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetAllocationType( const T
if ( tok2 && tok2->str() == "(" )
{
while ( tok2 && tok2->str() != ")" )
tok2 = tok2->next;
tok2 = tok2 ? tok2->next : NULL;
tok2 = tok2->next();
tok2 = tok2 ? tok2->next() : NULL;
}
if ( ! tok2 )
return No;
@ -144,8 +144,8 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetReallocationType( const
if ( tok2 && tok2->str() == "(" )
{
while ( tok2 && tok2->str() != ")" )
tok2 = tok2->next;
tok2 = tok2 ? tok2->next : NULL;
tok2 = tok2->next();
tok2 = tok2 ? tok2->next() : NULL;
}
if ( ! tok2 )
return No;
@ -209,7 +209,7 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list<const
int par = 1;
int parlevel = 0;
for ( ; tok; tok = tok->next )
for ( ; tok; tok = tok->next() )
{
if ( tok->str() == "(" )
++parlevel;
@ -232,14 +232,14 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list<const
return "use";
// Check if the function deallocates the variable..
while ( ftok && (ftok->str() != "{") )
ftok = ftok->next;
ftok = ftok->next();
TOKEN *func = getcode( ftok->tokAt(1), callstack, parname, alloctype, dealloctype );
simplifycode( func );
const TOKEN *func_ = func;
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";
}*/
@ -290,8 +290,8 @@ void CheckMemoryLeakClass::instoken(TOKEN *tok, const char str[])
{
TOKEN *newtok = new TOKEN;
newtok->setstr(str);
newtok->next = tok->next;
tok->next = newtok;
newtok->next( tok->next() );
tok->next( newtok );
}
//---------------------------------------------------------------------------
@ -318,9 +318,9 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
newtok->setstr(_str); \
newtok->linenr = tok->linenr; \
newtok->FileIndex = tok->FileIndex; \
newtok->next = 0; \
newtok->next( 0 ); \
if (rettail) \
rettail->next = newtok; \
rettail->next( newtok ); \
else \
rethead = newtok; \
rettail=newtok; \
@ -335,7 +335,7 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
int indentlevel = 0;
int parlevel = 0;
for ( ; tok; tok = tok->next )
for ( ; tok; tok = tok->next() )
{
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
while ( tok->str() != ")" )
tok = tok->next;
tok = tok->next();
}
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..
bool dep = false;
int parlevel = 0;
for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next )
for ( const TOKEN *tok2 = tok; tok2; tok2 = tok2->next() )
{
if ( tok2->str() == "(" )
++parlevel;
@ -450,8 +450,8 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
break;
}
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;
break;
@ -530,7 +530,7 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
// Callback..
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, ";{") )
break;
@ -558,10 +558,10 @@ void CheckMemoryLeakClass::erase(TOKEN *begin, const TOKEN *end)
if ( ! begin )
return;
while ( begin->next && begin->next != end )
while ( begin->next() && begin->next() != end )
{
TOKEN *next = begin->next;
begin->next = begin->next->next;
TOKEN *next = begin->next();
begin->next( begin->next()->next() );
delete next;
}
}
@ -574,7 +574,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
{
done = true;
for (TOKEN *tok2 = tok; tok2; tok2 = tok2 ? tok2->next : NULL )
for ( TOKEN *tok2 = tok; tok2; tok2 = tok2 ? tok2->next() : NULL )
{
// Delete extra ";"
while (TOKEN::Match(tok2,"[;{}] ;"))
@ -584,30 +584,30 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
}
// Replace "{ }" with ";"
if ( TOKEN::Match(tok2->next, "{ }") )
if ( TOKEN::Match(tok2->next(), "{ }") )
{
tok2->next->setstr(";");
erase(tok2->next, tok2->tokAt(3));
tok2->next()->setstr(";");
erase(tok2->next(), tok2->tokAt(3));
done = false;
}
// 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->next->next, tok2->tokAt(4) );
erase( tok2->next()->next(), tok2->tokAt(4) );
done = false;
}
if ( TOKEN::Match(tok2->next, "{ %var% %var% ; }") )
if ( TOKEN::Match(tok2->next(), "{ %var% %var% ; }") )
{
erase( tok2, tok2->tokAt(2) );
erase( tok2->next->next->next, tok2->tokAt(5) );
erase( tok2->next()->next()->next(), tok2->tokAt(5) );
done = false;
}
// Delete empty if that is not followed by an else
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(3), "else"))
{
@ -616,7 +616,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
}
// Delete "if ; else ;"
if ( TOKEN::Match(tok2->next, "if ; else ;") )
if ( TOKEN::Match(tok2->next(), "if ; else ;") )
{
erase( tok2, tok2->tokAt(4) );
done = false;
@ -659,7 +659,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
}
// Reduce "else ;" => ";"
if ( TOKEN::Match(tok2->next, "else ;") )
if ( TOKEN::Match(tok2->next(), "else ;") )
{
erase(tok2, tok2->tokAt(2));
done = false;
@ -684,7 +684,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
if (TOKEN::Match(tok2,"[;{}] if alloc ; else return ;"))
{
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;
}
@ -722,15 +722,15 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
}
// 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->next->next, tok2->tokAt(4));
erase(tok2->next()->next(), tok2->tokAt(4));
done = false;
}
// 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 &&
(TOKEN::Match( tok2->tokAt(3), "break ; ") || TOKEN::Match( tok2->tokAt(3), "continue ;")) &&
!TOKEN::Match(tok2->tokAt(5),"else") )
@ -740,36 +740,36 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
}
// 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) );
done = false;
}
// 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->next->next, tok2->tokAt(6));
erase(tok2->next()->next(), tok2->tokAt(6));
done = false;
}
// Replace "loop ;" with ";"
if ( TOKEN::Match(tok2->next, "loop ;") )
if ( TOKEN::Match(tok2->next(), "loop ;") )
{
erase(tok2, tok2->tokAt(2));
done = false;
}
// Replace "loop !var ;" with ";"
if ( TOKEN::Match(tok2->next, "loop !var ;") )
if ( TOKEN::Match(tok2->next(), "loop !var ;") )
{
erase(tok2, tok2->tokAt(4));
done = false;
}
// 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));
done = false;
@ -790,7 +790,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
}
// 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) );
done = false;
@ -799,26 +799,26 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
// Reduce "[;{}] return ; %var%" => "[;{}] return ;"
if ( TOKEN::Match(tok2, "[;{}] return ; %var%") )
{
erase( tok2->next->next, tok2->tokAt(4) );
erase( tok2->next()->next(), tok2->tokAt(4) );
done = false;
}
// Reduce "[;{}] return use ; %var%" => "[;{}] return use ;"
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;
}
// 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) );
done = false;
}
// 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) );
done = false;
@ -833,7 +833,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
// Reduce "if* 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) );
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.
bool valid = 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() == "{" )
break;
@ -905,7 +905,7 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
done = false;
tok2->setstr(";");
erase( tok2, tok2->tokAt(2) );
tok2 = tok2->next;
tok2 = tok2->next();
bool first = true;
while (TOKEN::Match(tok2,"case") || TOKEN::Match(tok2,"default"))
{
@ -925,11 +925,11 @@ void CheckMemoryLeakClass::simplifycode(TOKEN *tok)
instoken( tok2, "else" );
}
while ( tok2 && tok2->str() != "}" && ! TOKEN::Match(tok2,"break ;") )
tok2 = tok2->next;
tok2 = tok2->next();
if (TOKEN::Match(tok2,"break ;"))
{
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 ;") )
{
const TOKEN *last = tok;
while (last->next)
last = last->next;
while (last->next())
last = last->next();
MemoryLeak(last, varname);
}
@ -1010,7 +1010,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const
{
TOKEN *first = tok;
while ( first && first->str() == ";" )
first = first->next;
first = first->next();
bool noerr = false;
noerr |= TOKEN::Match( first, "alloc ; }" );
@ -1028,7 +1028,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const
if ( ! noerr )
{
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 << "\n";
}
@ -1049,7 +1049,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_InFunction()
{
bool infunc = false;
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() == "{")
indentlevel++;
@ -1072,10 +1072,10 @@ void CheckMemoryLeakClass::CheckMemoryLeak_InFunction()
if (indentlevel>0 && infunc)
{
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% [;=]") )
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()
{
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() == "{" )
indentlevel++;
@ -1114,12 +1114,12 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN
{
// Go into class.
while ( tok1 && tok1->str() != "{" )
tok1 = tok1->next;
tok1 = tok1->next();
if ( tok1 )
tok1 = tok1->next;
tok1 = tok1->next();
int indentlevel = 0;
for ( const TOKEN *tok = tok1; tok; tok = tok->next )
for ( const TOKEN *tok = tok1; tok; tok = tok->next() )
{
if ( tok->str() == "{" )
indentlevel++;
@ -1144,7 +1144,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN
}
// 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, "[;}]"))
{
@ -1190,7 +1190,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable( const std::vec
// Loop through all tokens. Inspect member functions
bool memberfunction = false;
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() == "{" )
indentlevel++;

View File

@ -47,7 +47,7 @@ CheckOther::~CheckOther()
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..
if (!TOKEN::Match(tok, "( %type% * ) %var%"))
@ -74,7 +74,7 @@ void CheckOther::WarningOldStylePointerCast()
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;
err |= TOKEN::Match(tok, "%var% >= '0' && %var% <= '9'");
@ -99,7 +99,7 @@ void CheckOther::WarningIsDigit()
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() != "(" )
continue;
@ -159,7 +159,7 @@ void CheckOther::WarningRedundantCode()
{
// 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" )
continue;
@ -182,7 +182,7 @@ void CheckOther::WarningRedundantCode()
continue;
if ( tok2->str() == "{" )
tok2 = tok2->next;
tok2 = tok2->next();
bool err = false;
if (TOKEN::Match(tok2,"delete %var% ;"))
@ -221,12 +221,12 @@ void CheckOther::WarningIf()
{
// 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")
{
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() == "(")
parlevel++;
@ -250,12 +250,12 @@ void CheckOther::WarningIf()
}
// 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?
if ( ! TOKEN::Match(tok, "[;{}]") )
continue;
tok = tok->next;
tok = tok->next();
if ( ! tok )
break;
@ -316,7 +316,7 @@ void CheckOther::WarningIf()
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"))
continue;
@ -324,7 +324,7 @@ void CheckOther::InvalidFunctionUsage()
// Locate the third parameter of the function call..
int parlevel = 0;
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, "(") )
parlevel++;
@ -360,7 +360,7 @@ void CheckOther::InvalidFunctionUsage()
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% )") ||
TOKEN::Match(tok, "if ( %var% = %str% )") ||
@ -383,7 +383,7 @@ void CheckOther::CheckUnsignedDivision()
{
// Check for "ivar / uvar" and "uvar / ivar"
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% [;=,)]") )
{
@ -395,7 +395,7 @@ void CheckOther::CheckUnsignedDivision()
else if ( TOKEN::Match(tok, "[{};(,] unsigned %type% %var% [;=,)]") )
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 *varname2 = tok->strAt(3);
@ -406,19 +406,19 @@ void CheckOther::CheckUnsignedDivision()
{
// One of the operands are signed, the other is unsigned..
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());
}
}
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);
char sign1 = varsign[varname1];
if ( sign1 == 'u' )
{
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());
}
}
@ -430,7 +430,7 @@ void CheckOther::CheckUnsignedDivision()
if ( sign2 == 'u' )
{
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());
}
}
@ -450,17 +450,17 @@ void CheckOther::CheckVariableScope()
// Walk through all tokens..
bool func = false;
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..
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() == "{" )
{
int _indentlevel = 0;
for (tok = tok2; tok; tok = tok->next)
for (tok = tok2; tok; tok = tok->next())
{
if ( tok->str() == "{" )
{
@ -471,7 +471,7 @@ void CheckOther::CheckVariableScope()
_indentlevel--;
if ( _indentlevel <= 0 )
{
tok = tok->next;
tok = tok->next();
break;
}
}
@ -504,7 +504,7 @@ void CheckOther::CheckVariableScope()
if ( indentlevel > 0 && func && TOKEN::Match(tok, "[{};]") )
{
// First token of statement..
const TOKEN *tok1 = tok->next;
const TOKEN *tok1 = tok->next();
if ( ! tok1 )
continue;
@ -532,7 +532,7 @@ void CheckOther::CheckVariableScope_LookupVar( const TOKEN *tok1, const char var
// Skip the variable declaration..
while (tok && !TOKEN::Match(tok,";"))
tok = tok->next;
tok = tok->next();
// Check if the variable is used in this indentlevel..
bool used = false, used1 = false;
@ -584,7 +584,7 @@ void CheckOther::CheckVariableScope_LookupVar( const TOKEN *tok1, const char var
for_or_while = false;
}
tok = tok->next;
tok = tok->next();
}
// Warning if "used" is true
@ -601,7 +601,7 @@ void CheckOther::CheckVariableScope_LookupVar( const TOKEN *tok1, const char var
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% [,)]") )
{
@ -642,7 +642,7 @@ void CheckOther::CheckStructMemberUsage()
{
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 )
continue;
@ -654,13 +654,13 @@ void CheckOther::CheckStructMemberUsage()
if (structname && TOKEN::Match(tok, "[{;]"))
{
const char *varname = 0;
if (TOKEN::Match(tok->next, "%type% %var% [;[]"))
if (TOKEN::Match(tok->next(), "%type% %var% [;[]"))
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 );
else if (TOKEN::Match(tok->next, "%type% * %var% [;[]"))
else if (TOKEN::Match(tok->next(), "%type% * %var% [;[]"))
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 );
else
continue;
@ -669,7 +669,7 @@ void CheckOther::CheckStructMemberUsage()
varnames[0] = varname;
varnames[1] = 0;
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 )
continue;
@ -703,7 +703,7 @@ void CheckOther::CheckStructMemberUsage()
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..
if ( TOKEN::Match(tok, "[{};(,] char %var% [;=,)]") )
@ -713,7 +713,7 @@ void CheckOther::CheckCharVariable()
// Check usage of char variable..
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() == "{" )
++indentlevel;
@ -725,10 +725,10 @@ void CheckOther::CheckCharVariable()
break;
}
if ((tok2->str() != ".") && 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";
errmsg << _tokenizer->fileLine(tok2->next()) << ": Warning - using char variable as array index";
_errorLogger->reportErr(errmsg.str());
break;
}
@ -759,7 +759,7 @@ void CheckOther::CheckIncompleteStatement()
{
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() == "(" )
++parlevel;
@ -769,17 +769,17 @@ void CheckOther::CheckIncompleteStatement()
if ( parlevel != 0 )
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;
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());
}
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;
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());
}
}
@ -801,19 +801,19 @@ void CheckOther::unreachableCode()
while ( tok )
{
// Goto the 'return' token
tok = tok->next;
tok = tok->next();
// Locate the end of the 'return' statement
while ( tok && ! TOKEN::Match(tok, ";") )
tok = tok->next;
while ( tok && TOKEN::Match(tok->next, ";") )
tok = tok->next;
tok = tok->next();
while ( tok && TOKEN::Match(tok->next(), ";") )
tok = tok->next();
// If there is a statement below the return it is unreachable
if (!TOKEN::Match(tok, "; case|default|}|#") && !TOKEN::Match(tok, "; %var% :"))
{
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());
}
@ -860,7 +860,7 @@ void CheckOther::functionVariableUsage()
static const unsigned int USAGE_WRITE = 4;
int indentlevel = 0;
for ( const TOKEN *tok = tok1; tok; tok = tok->next )
for ( const TOKEN *tok = tok1; tok; tok = tok->next() )
{
if ( tok->str() == "{" )
++indentlevel;
@ -889,10 +889,10 @@ void CheckOther::functionVariableUsage()
if ( TOKEN::Match(tok, ">>|& %var%") )
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;
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;
if ( TOKEN::Match(tok, "[(,] %var% [,)]") )
@ -914,26 +914,26 @@ void CheckOther::functionVariableUsage()
if ( usage == USAGE_DECLARE )
{
std::ostringstream errmsg;
errmsg << _tokenizer->fileLine(tok1->next) << ": Unused variable '" << varname << "'";
errmsg << _tokenizer->fileLine(tok1->next()) << ": Unused variable '" << varname << "'";
_errorLogger->reportErr(errmsg.str());
}
else if ( ! (usage & USAGE_READ) )
{
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());
}
else if ( ! (usage & USAGE_WRITE) )
{
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());
}
}
// Goto next executing scope..
tok1 = TOKEN::findmatch( tok1->next, ") const| {" );
tok1 = TOKEN::findmatch( tok1->next(), ") const| {" );
}
}

View File

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

View File

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

View File

@ -47,7 +47,7 @@ private:
tokenizer.simplifyTokenList();
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()) + " ";
}

View File

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

View File

@ -31,7 +31,8 @@ TOKEN::TOKEN()
_cstr = 0;
_str = "";
linenr = 0;
next = 0;
_next = 0;
_varId = 0;
_isName = false;
_isNumber = false;
}
@ -56,9 +57,9 @@ void TOKEN::setstr( const char s[] )
void TOKEN::combineWithNext(const char str1[], const char str2[])
{
if (!(next))
if (!(_next))
return;
if (_str!=str1 || next->_str!=str2)
if (_str!=str1 || _next->_str!=str2)
return;
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()
{
TOKEN *n = next;
next = n->next;
TOKEN *n = _next;
_next = n->next();
delete n;
}
@ -78,7 +79,7 @@ const TOKEN *TOKEN::tokAt(int index) const
const TOKEN *tok = this;
while (index>0 && tok)
{
tok = tok->next;
tok = tok->next();
index--;
}
return tok;
@ -247,7 +248,7 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
else if (str != tok->_str)
return false;
tok = tok->next;
tok = tok->next();
if (!tok && *p)
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[])
{
for ( ; tok; tok = tok->next)
for ( ; tok; tok = tok->next())
{
if ( TOKEN::Match(tok, pattern, varname1, varname2) )
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[])
{
for (const TOKEN *ret = tok1; ret; ret = ret->next)
for (const TOKEN *ret = tok1; ret; ret = ret->next())
{
unsigned int i = 0;
const TOKEN *tok = ret;
@ -299,7 +300,7 @@ const TOKEN *TOKEN::findtoken(const TOKEN *tok1, const char *tokenstr[])
return NULL;
if (*(tokenstr[i]) && (tokenstr[i] != tok->_str))
break;
tok = tok->next;
tok = tok->next();
i++;
}
if (!tokenstr[i])
@ -317,3 +318,14 @@ void TOKEN::varId( unsigned int 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 linenr;
TOKEN *next() const;
void next( TOKEN *next );
TOKEN *next;
unsigned int varId() const;
void varId( unsigned int id );
@ -126,6 +126,7 @@ private:
bool _isName;
bool _isNumber;
unsigned int _varId;
TOKEN *_next;
};
#endif // TOKEN_H

View File

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