Use validate after tokenize and simplifyTokenlist calls. Disabled until known problems fixed.

This commit is contained in:
Reijo Tomperi 2009-11-10 23:10:56 +02:00
parent 39614a699e
commit 4372b3aa92
3 changed files with 66 additions and 11 deletions

View File

@ -521,8 +521,13 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
{ {
TIMER_START(); TIMER_START();
_tokenizer.simplifyTokenList(); bool result = _tokenizer.simplifyTokenList();
TIMER_END("Tokenizer::simplifyTokenList"); TIMER_END("Tokenizer::simplifyTokenList");
if (!result)
{
std::cerr << "### A bug in the Cppcheck itself, while checking: " << FileName << "\n";
return;
}
} }
if (_settings._unusedFunctions) if (_settings._unusedFunctions)

View File

@ -598,6 +598,11 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
removeExceptionSpecifications(_tokens); removeExceptionSpecifications(_tokens);
setVarId(); setVarId();
if (!validate())
{
std::cerr << "### A bug in the Cppcheck itself, while checking: " << FileName << "\n";
return false;
}
return true; return true;
} }
@ -1786,7 +1791,7 @@ void Tokenizer::simplifySizeof()
} }
void Tokenizer::simplifyTokenList() bool Tokenizer::simplifyTokenList()
{ {
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
{ {
@ -2097,6 +2102,8 @@ void Tokenizer::simplifyTokenList()
{ {
_tokens->printOut(); _tokens->printOut();
} }
return validate();
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -4465,31 +4472,69 @@ void Tokenizer::removeExceptionSpecifications(Token *tok) const
bool Tokenizer::validate() const bool Tokenizer::validate() const
{ {
// TODO, this is here just to prevent errors, until
// the known problems are fixed. When testrunner works
// with validate enabled, this can be removed.
if (true) return true;
std::stack<const Token *> linktok; std::stack<const Token *> linktok;
for (const Token *tok = tokens(); tok; tok = tok->next()) for (const Token *tok = tokens(); tok; tok = tok->next())
{ {
if (Token::Match(tok, "[{([]")) if (Token::Match(tok, "[{([]"))
{ {
assert(tok->link() != 0); if (tok->link() == 0)
{
assert(0);
return false;
}
linktok.push(tok); linktok.push(tok);
continue; continue;
} }
else if (Token::Match(tok, "[})]]")) else if (Token::Match(tok, "[})]]"))
{ {
assert(tok->link() != 0); if (tok->link() == 0)
assert(linktok.empty() == false); {
assert(tok->link() == linktok.top()); assert(0);
assert(tok == tok->link()->link()); return false;
}
if (linktok.empty() == true)
{
assert(0);
return false;
}
if (tok->link() != linktok.top())
{
assert(0);
return false;
}
if (tok != tok->link()->link())
{
assert(0);
return false;
}
linktok.pop(); linktok.pop();
continue; continue;
} }
assert(tok->link() == 0); if (tok->link() != 0)
{
assert(0);
return false;
}
} }
assert(linktok.empty()); if (!linktok.empty())
{
assert(0);
return false;
}
return true; return true;
} }

View File

@ -77,8 +77,13 @@ public:
/** Set variable id */ /** Set variable id */
void setVarId(); void setVarId();
/** Simplify tokenlist */ /**
void simplifyTokenList(); * Simplify tokenlist
*
* @return false if there is an error that requires aborting
* the checking of this file.
*/
bool simplifyTokenList();
static void deleteTokens(Token *tok); static void deleteTokens(Token *tok);
static const char *getParameterName(const Token *ftok, int par); static const char *getParameterName(const Token *ftok, int par);