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();
_tokenizer.simplifyTokenList();
bool result = _tokenizer.simplifyTokenList();
TIMER_END("Tokenizer::simplifyTokenList");
if (!result)
{
std::cerr << "### A bug in the Cppcheck itself, while checking: " << FileName << "\n";
return;
}
}
if (_settings._unusedFunctions)

View File

@ -598,6 +598,11 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
removeExceptionSpecifications(_tokens);
setVarId();
if (!validate())
{
std::cerr << "### A bug in the Cppcheck itself, while checking: " << FileName << "\n";
return false;
}
return true;
}
@ -1786,7 +1791,7 @@ void Tokenizer::simplifySizeof()
}
void Tokenizer::simplifyTokenList()
bool Tokenizer::simplifyTokenList()
{
for (Token *tok = _tokens; tok; tok = tok->next())
{
@ -2097,6 +2102,8 @@ void Tokenizer::simplifyTokenList()
{
_tokens->printOut();
}
return validate();
}
//---------------------------------------------------------------------------
@ -4465,31 +4472,69 @@ void Tokenizer::removeExceptionSpecifications(Token *tok) 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;
for (const Token *tok = tokens(); tok; tok = tok->next())
{
if (Token::Match(tok, "[{([]"))
{
assert(tok->link() != 0);
if (tok->link() == 0)
{
assert(0);
return false;
}
linktok.push(tok);
continue;
}
else if (Token::Match(tok, "[})]]"))
{
assert(tok->link() != 0);
assert(linktok.empty() == false);
assert(tok->link() == linktok.top());
assert(tok == tok->link()->link());
if (tok->link() == 0)
{
assert(0);
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();
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;
}

View File

@ -77,8 +77,13 @@ public:
/** Set variable id */
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 const char *getParameterName(const Token *ftok, int par);