CheckStl: Added comments

This commit is contained in:
Daniel Marjamäki 2011-01-06 12:20:54 +01:00
parent 616914c1ff
commit ca294544ca
1 changed files with 25 additions and 4 deletions

View File

@ -229,18 +229,24 @@ void CheckStl::stlOutOfBounds()
if (Token::Match(tok2, "; %var% <= %var% . size ( ) ;")) if (Token::Match(tok2, "; %var% <= %var% . size ( ) ;"))
{ {
unsigned int indent2 = 0; // Count { and } for tok3
unsigned int indent3 = 0;
// variable id for loop variable.
unsigned int numId = tok2->tokAt(1)->varId(); unsigned int numId = tok2->tokAt(1)->varId();
// variable id for the container variable
unsigned int varId = tok2->tokAt(3)->varId(); unsigned int varId = tok2->tokAt(3)->varId();
for (const Token *tok3 = tok2->tokAt(8); tok3; tok3 = tok3->next()) for (const Token *tok3 = tok2->tokAt(8); tok3; tok3 = tok3->next())
{ {
if (tok3->str() == "{") if (tok3->str() == "{")
++indent2; ++indent3;
else if (tok3->str() == "}") else if (tok3->str() == "}")
{ {
if (indent2 <= 1) if (indent3 <= 1)
break; break;
--indent2; --indent3;
} }
else if (tok3->varId() == varId) else if (tok3->varId() == varId)
{ {
@ -470,11 +476,16 @@ void CheckStl::pushback()
{ {
if (Token::Match(tok, "%var% = & %var% [")) if (Token::Match(tok, "%var% = & %var% ["))
{ {
// Variable id for pointer
const unsigned int pointerId(tok->varId()); const unsigned int pointerId(tok->varId());
// Variable id for the container variable
const unsigned int containerId(tok->tokAt(3)->varId()); const unsigned int containerId(tok->tokAt(3)->varId());
if (pointerId == 0 || containerId == 0) if (pointerId == 0 || containerId == 0)
continue; continue;
// Count { , } and parantheses for tok2
int indent = 0; int indent = 0;
bool invalidPointer = false; bool invalidPointer = false;
for (const Token *tok2 = tok; indent >= 0 && tok2; tok2 = tok2->next()) for (const Token *tok2 = tok; indent >= 0 && tok2; tok2 = tok2->next())
@ -537,8 +548,12 @@ void CheckStl::pushback()
tok = tok->tokAt(3); tok = tok->tokAt(3);
} }
// the variable id for the vector
unsigned int vectorid = 0; unsigned int vectorid = 0;
// count { , } and parantheses for tok2
int indent = 0; int indent = 0;
std::string invalidIterator; std::string invalidIterator;
for (const Token *tok2 = tok; indent >= 0 && tok2; tok2 = tok2->next()) for (const Token *tok2 = tok; indent >= 0 && tok2; tok2 = tok2->next())
{ {
@ -560,11 +575,14 @@ void CheckStl::pushback()
if (Token::Match(tok2, "%varid% = %var% . begin ( ) ; %varid% != %var% . end ( ) ; ++| %varid% ++| ) {", iteratorid)) if (Token::Match(tok2, "%varid% = %var% . begin ( ) ; %varid% != %var% . end ( ) ; ++| %varid% ++| ) {", iteratorid))
{ {
// variable id for the loop iterator
const unsigned int varId(tok2->tokAt(2)->varId()); const unsigned int varId(tok2->tokAt(2)->varId());
if (varId == 0) if (varId == 0)
continue; continue;
const Token *pushbackTok = 0; const Token *pushbackTok = 0;
// Count { and } for tok3
unsigned int indent3 = 0; unsigned int indent3 = 0;
for (const Token *tok3 = tok2->tokAt(20); tok3; tok3 = tok3->next()) for (const Token *tok3 = tok2->tokAt(20); tok3; tok3 = tok3->next())
{ {
@ -929,7 +947,10 @@ void CheckStl::missingComparison()
continue; continue;
const Token *incrementToken = 0; const Token *incrementToken = 0;
// Count { and } for tok3
unsigned int indentlevel = 0; unsigned int indentlevel = 0;
// Parse loop.. // Parse loop..
for (const Token *tok3 = tok2->tokAt(20); tok3; tok3 = tok3->next()) for (const Token *tok3 = tok2->tokAt(20); tok3; tok3 = tok3->next())
{ {