refactoring: generate error message in the class

This commit is contained in:
Daniel Marjamäki 2009-03-20 20:09:44 +01:00
parent 8e4af409e7
commit 272d455e2d
3 changed files with 18 additions and 5 deletions

View File

@ -29,14 +29,14 @@
class Check
{
public:
// This constructor is used when registering the CheckClass
/** This constructor is used when registering the CheckClass */
Check()
: _tokenizer(0), _settings(0), _errorLogger(0)
{
instances().push_back(this);
}
// This constructor is used when running checks..
/** This constructor is used when running checks.. */
Check(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: _tokenizer(tokenizer), _settings(settings), _errorLogger(errorLogger)
{ }
@ -61,7 +61,8 @@ protected:
const Settings * const _settings;
ErrorLogger * const _errorLogger;
void reportError(const Token *tok, const char severity[], const char id[], const char msg[])
/** report an error */
void reportError(const Token *tok, const std::string severity, const std::string id, const std::string msg)
{
ErrorLogger::ErrorMessage::FileLocation loc;
loc.line = tok->linenr();

View File

@ -28,6 +28,14 @@ namespace
CheckStl instance;
}
// Error message for bad iterator usage..
void CheckStl::iteratorsError(const Token *tok, const std::string &container1, const std::string &container2)
{
reportError(tok, "error", "Same iterator is used with both " + container1 + " and " + container2, "iterators");
}
void CheckStl::iterators()
{
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
@ -41,7 +49,7 @@ void CheckStl::iterators()
// Same container..
if (tok->tokAt(2)->str() == tok->tokAt(10)->str())
continue;
_errorLogger->iteratorUsage(_tokenizer, tok, tok->strAt(2), tok->strAt(10));
iteratorsError(tok, tok->strAt(2), tok->strAt(10));
}
// it = foo.begin();
@ -54,7 +62,8 @@ void CheckStl::iterators()
// Same container..
if (tok->tokAt(2)->str() == tok->tokAt(12)->str())
continue;
_errorLogger->iteratorUsage(_tokenizer, tok, tok->strAt(2), tok->strAt(12));
iteratorsError(tok, tok->strAt(2), tok->strAt(12));
}
}
}

View File

@ -78,6 +78,9 @@ private:
* @param it iterator token
*/
void eraseCheckLoop(const Token *it);
void iteratorsError(const Token *tok, const std::string &container1, const std::string &container2);
};
//---------------------------------------------------------------------------