validator bugs are now printed using the errorlogger

This commit is contained in:
Reijo Tomperi 2009-11-28 23:08:43 +02:00
parent f927375b7e
commit 57aac9270a
3 changed files with 49 additions and 13 deletions

View File

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

View File

@ -605,10 +605,7 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
setVarId();
if (!validate())
{
std::cerr << "### A bug in the Cppcheck itself, while checking: " << FileName << "\n";
return false;
}
return true;
}
@ -4293,6 +4290,42 @@ void Tokenizer::syntaxError(const Token *tok, char c)
}
void Tokenizer::cppcheckError(const Token *tok) const
{
if (!_errorLogger && tok)
{
std::ostringstream err;
err << "### Unlogged error at Tokenizer::cppcheckError";
if (_settings && _settings->_debug)
{
throw std::runtime_error(err.str());
}
else
{
std::cerr << err.str() << std::endl;
}
return;
}
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
if (tok)
{
ErrorLogger::ErrorMessage::FileLocation loc;
loc.line = tok->linenr();
loc.file = file(tok);
locationList.push_back(loc);
}
const ErrorLogger::ErrorMessage errmsg(locationList,
"error",
"### A bug was found from cppcheck. Please report it.",
"cppcheckError");
if (_errorLogger)
_errorLogger->reportErr(errmsg);
}
void Tokenizer::simplifyMathFunctions()
{
for (Token *tok = _tokens; tok; tok = tok->next())
@ -4554,7 +4587,7 @@ bool Tokenizer::validate() const
{
if (tok->link() == 0)
{
assert(0);
cppcheckError(tok);
return false;
}
@ -4566,25 +4599,25 @@ bool Tokenizer::validate() const
{
if (tok->link() == 0)
{
assert(0);
cppcheckError(tok);
return false;
}
if (linktok.empty() == true)
{
assert(0);
cppcheckError(tok);
return false;
}
if (tok->link() != linktok.top())
{
assert(0);
cppcheckError(tok);
return false;
}
if (tok != tok->link()->link())
{
assert(0);
cppcheckError(tok);
return false;
}
@ -4594,14 +4627,14 @@ bool Tokenizer::validate() const
if (tok->link() != 0)
{
assert(0);
cppcheckError(tok);
return false;
}
}
if (!linktok.empty())
{
assert(0);
cppcheckError(linktok.top());
return false;
}

View File

@ -328,6 +328,12 @@ private:
void insertTokens(Token *dest, const Token *src, unsigned int n);
/**
* Send error message to error logger about internal bug.
* @param tok, the token that this bug concerns.
*/
void cppcheckError(const Token *tok) const;
/**
* Setup links for tokens so that one can call Token::link().
*