Refactoring: Prefer ++i; over i++;

This commit is contained in:
Reijo Tomperi 2009-01-01 22:22:28 +00:00
parent ca550fb03e
commit 94923cca1a
11 changed files with 64 additions and 64 deletions

View File

@ -68,7 +68,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const TOKEN *tok, co
{
unsigned int varc = 1;
while ( varname[varc] )
varc++;
++varc;
varc = 2 * (varc - 1);
@ -99,12 +99,12 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const TOKEN *tok, co
{
if (tok->str() == "{")
{
indentlevel++;
++indentlevel;
}
else if (tok->str() == "}")
{
indentlevel--;
--indentlevel;
if ( indentlevel < 0 )
return;
}
@ -206,11 +206,11 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const TOKEN *tok, co
break;
if ( tok2->str() == "{" )
indentlevel2++;
++indentlevel2;
if ( tok2->str() == "}" )
{
indentlevel2--;
--indentlevel2;
if ( indentlevel2 <= 0 )
break;
}
@ -234,9 +234,9 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const TOKEN *tok, co
while ( *str )
{
if (*str=='\\')
str++;
str++;
len++;
++str;
++str;
++len;
}
if (len > 2 && len >= (int)size + 2)
{
@ -264,12 +264,12 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const TOKEN *tok, co
{
if ( tok2->str() == "(" )
{
parlevel++;
++parlevel;
}
else if ( tok2->str() == ")" )
{
parlevel--;
--parlevel;
if ( parlevel < 1 )
{
par = 0;
@ -279,12 +279,12 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const TOKEN *tok, co
else if ( parlevel == 1 && (tok2->str() == ",") )
{
par++;
++par;
}
if ( parlevel == 1 && TOKEN::Match(tok2, "[(,] %var1% [,)]", varname) )
{
par++;
++par;
break;
}
}
@ -303,13 +303,13 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const TOKEN *tok, co
while ( ftok && parlevel == 1 && par >= 1 )
{
if ( ftok->str() == "(" )
parlevel++;
++parlevel;
else if ( ftok->str() == ")" )
parlevel--;
--parlevel;
else if ( ftok->str() == "," )
par--;
--par;
else if ( par==1 && parlevel==1 && TOKEN::Match(ftok, "%var% [,)]") )
{
@ -349,10 +349,10 @@ void CheckBufferOverrunClass::CheckBufferOverrun_LocalVariable()
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (tok->str() == "{")
indentlevel++;
++indentlevel;
else if (tok->str() == "}")
indentlevel--;
--indentlevel;
else if (indentlevel > 0)
{

View File

@ -164,7 +164,7 @@ const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classn
if ( tok->str() == "}" )
{
indentlevel--;
--indentlevel;
if ( indentlevel < 0 )
return NULL;
}
@ -231,7 +231,7 @@ void CheckClass::ClassChecking_VarList_Initialize(const TOKEN *tok1, const TOKEN
if (ftok->str() == "{")
{
indentlevel++;
++indentlevel;
Assign = false;
}
@ -239,7 +239,7 @@ void CheckClass::ClassChecking_VarList_Initialize(const TOKEN *tok1, const TOKEN
{
if (indentlevel <= 1)
break;
indentlevel--;
--indentlevel;
}
if ( indentlevel < 1 )
@ -492,12 +492,12 @@ void CheckClass::privateFunctions()
}
if (tok->str() == "{")
indent_level++;
++indent_level;
else if (tok->str() == "}")
{
if (indent_level <= 1)
break;
indent_level--;
--indent_level;
}
else if (tok->str() == "private:")
priv = true;
@ -546,12 +546,12 @@ void CheckClass::privateFunctions()
while (ftok)
{
if (ftok->str() == "{")
indent_level++;
++indent_level;
if (ftok->str() == "}")
{
if (indent_level<=1)
break;
indent_level--;
--indent_level;
}
if (TOKEN::Match( ftok->next(), "(") )
FuncList.remove(ftok->str());

View File

@ -95,7 +95,7 @@ void CheckHeaders::WarningIncludeHeader()
{
if ( Tokenizer::SameFileName( _tokenizer->getFiles()->at(hfile).c_str(), includefile ) )
break;
hfile++;
++hfile;
}
if (hfile == _tokenizer->getFiles()->size())
continue;
@ -183,10 +183,10 @@ void CheckHeaders::WarningIncludeHeader()
while (tok1->next())
{
if ( TOKEN::Match(tok1, "[({]") )
parlevel++;
++parlevel;
else if ( TOKEN::Match(tok1, "[)}]") )
parlevel--;
--parlevel;
else if (parlevel == 0)
{

View File

@ -363,20 +363,20 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
if ( tok->str() == "{" )
{
addtoken( "{" );
indentlevel++;
++indentlevel;
}
else if ( tok->str() == "}" )
{
addtoken( "}" );
if ( indentlevel <= 0 )
break;
indentlevel--;
--indentlevel;
}
if ( tok->str() == "(" )
parlevel++;
++parlevel;
else if ( tok->str() == ")" )
parlevel--;
--parlevel;
isloop &= ( parlevel > 0 );
if ( parlevel == 0 && tok->str()==";")
@ -1209,10 +1209,10 @@ void CheckMemoryLeakClass::CheckMemoryLeak_InFunction()
for (const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (tok->str() == "{")
indentlevel++;
++indentlevel;
else if (tok->str() == "}")
indentlevel--;
--indentlevel;
// In function..
@ -1252,10 +1252,10 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers()
for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next() )
{
if ( tok->str() == "{" )
indentlevel++;
++indentlevel;
else if ( tok->str() == "}" )
indentlevel--;
--indentlevel;
else if ( indentlevel == 0 && TOKEN::Match(tok, "class %var% [{:]") )
{
@ -1279,11 +1279,11 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN
for ( const TOKEN *tok = tok1; tok; tok = tok->next() )
{
if ( tok->str() == "{" )
indentlevel++;
++indentlevel;
else if ( tok->str() == "}" )
{
indentlevel--;
--indentlevel;
if ( indentlevel < 0 )
return;
}
@ -1350,10 +1350,10 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable( const std::vec
for ( const TOKEN *tok = _tokenizer->tokens(); tok; tok = tok->next() )
{
if ( tok->str() == "{" )
indentlevel++;
++indentlevel;
else if ( tok->str() == "}" )
indentlevel--;
--indentlevel;
// Set the 'memberfunction' variable..
if ( indentlevel == 0 )

View File

@ -307,12 +307,12 @@ void CheckOther::InvalidFunctionUsage()
for ( const TOKEN *tok2 = tok->next(); tok2; tok2 = tok2->next() )
{
if ( TOKEN::Match(tok2, "(") )
parlevel++;
++parlevel;
else if (TOKEN::Match(tok2, ")"))
parlevel--;
--parlevel;
else if (parlevel == 1 && TOKEN::Match(tok2, ","))
{
param++;
++param;
if (param==3)
{
if ( TOKEN::Match(tok2, ", %num% )") )
@ -439,17 +439,17 @@ void CheckOther::CheckVariableScope()
{
if ( tok2->str() == "{" )
{
int _indentlevel = 0;
int indentlevel2 = 0;
for (tok = tok2; tok; tok = tok->next())
{
if ( tok->str() == "{" )
{
_indentlevel++;
++indentlevel2;
}
if ( tok->str() == "}" )
{
_indentlevel--;
if ( _indentlevel <= 0 )
--indentlevel2;
if ( indentlevel2 <= 0 )
{
tok = tok->next();
break;

View File

@ -189,7 +189,7 @@ void CppCheck::check()
_errorLogger->reportOut( std::string( "Checking " ) + fname + ": "+cfg+std::string( "..." ) );
checkFile( codeWithoutCfg, _filenames[c].c_str());
checkCount++;
++checkCount;
}
if ( _settings._errorsOnly == false && _errout.str().empty() )

View File

@ -166,7 +166,7 @@ std::string Preprocessor::removeSpaceNearNL( const std::string &str )
else
{
tmp.append( 1,str[i] );
prev++;
++prev;
}
}

View File

@ -718,7 +718,7 @@ private:
" int i = 0;\n"
" for( ;; )\n"
" {\n"
" i++;\n"
" ++i;\n"
" a = realloc( a, i );\n"
" if( !a )\n"
" return 0;\n"

View File

@ -74,7 +74,7 @@ bool TestFixture::runTest(const char testname[])
{
if ( testToRun.empty() || testToRun == testname )
{
countTests++;
++countTests;
std::cout << classname << "::" << testname << "\n";
return true;
}

View File

@ -75,7 +75,7 @@ const TOKEN *TOKEN::tokAt(int index) const
while (index>0 && tok)
{
tok = tok->next();
index--;
--index;
}
return tok;
}
@ -121,7 +121,7 @@ int TOKEN::multiCompare( const char *needle, const char *haystack )
}
// All characters in haystack and needle have matched this far
haystackPointer++;
++haystackPointer;
}
// If both needle and haystack are at the end, then we have a match.
@ -171,7 +171,7 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
{
// Skip spaces in pattern..
while ( *p == ' ' )
p++;
++p;
if (!tok)
{
@ -189,8 +189,8 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
while (*p && *p!=' ')
{
*s = *p;
s++;
p++;
++s;
++p;
}
*s = 0;

View File

@ -66,7 +66,7 @@ TOKEN *Tokenizer::_gettok(TOKEN *tok, int index)
while (tok && index>0)
{
tok = tok->next();
index--;
--index;
}
return tok;
}
@ -216,7 +216,7 @@ void Tokenizer::InsertTokens(TOKEN *dest, TOKEN *src, unsigned int n)
dest->linenr( src->linenr() );
dest->varId( src->varId() );
src = src->next();
n--;
--n;
}
}
//---------------------------------------------------------------------------
@ -347,7 +347,7 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
addtoken(";", lineno, FileIndex);
}
lineno++;
++lineno;
continue;
}
@ -394,7 +394,7 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
addtoken( ";", lineno, FileIndex );
}
lineno++;
++lineno;
continue;
}
@ -408,7 +408,7 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
chPrev = ch;
ch = (char)code.get();
if (ch == '\n')
lineno++;
++lineno;
}
continue;
}
@ -979,14 +979,14 @@ void Tokenizer::simplifyTokenList()
{
if ( strchr("{(", tok2->aaaa0()) )
{
parlevel++;
++parlevel;
}
else if ( strchr("})", tok2->aaaa0()) )
{
if (parlevel<0)
break;
parlevel--;
--parlevel;
}
else if ( parlevel==0 && strchr(";,",tok2->aaaa0()) )
@ -1056,12 +1056,12 @@ const TOKEN *Tokenizer::findClosing( const TOKEN *tok, const char *start, const
{
if( closing->str() == start )
{
indentLevel++;
++indentLevel;
continue;
}
if( closing->str() == end )
indentLevel--;
--indentLevel;
if( indentLevel >= 0 )
continue;