Fix #1322 (Add cppcheckError and unusedFunction to --errorlist, give out internal errors in xml)

http://sourceforge.net/apps/trac/cppcheck/ticket/1322
This commit is contained in:
Reijo Tomperi 2010-04-04 23:55:28 +03:00
parent f5b1a4db36
commit 6db663f6de
4 changed files with 39 additions and 5 deletions

View File

@ -196,5 +196,7 @@ void CheckUnusedFunctions::check()
} }
} }
void CheckUnusedFunctions::unusedFunctionError(const Token *tok)
{
reportError(tok, Severity::style, "unusedFunction", "The function 'funcName' is never used");
}

View File

@ -22,13 +22,14 @@
#define checkunusedfunctionsH #define checkunusedfunctionsH
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#include "check.h"
#include "tokenize.h" #include "tokenize.h"
#include "errorlogger.h" #include "errorlogger.h"
/// @addtogroup Checks /// @addtogroup Checks
/// @{ /// @{
class CheckUnusedFunctions class CheckUnusedFunctions: public Check
{ {
public: public:
CheckUnusedFunctions(ErrorLogger *errorLogger = 0); CheckUnusedFunctions(ErrorLogger *errorLogger = 0);
@ -50,6 +51,35 @@ public:
void check(); void check();
private: private:
void getErrorMessages()
{
unusedFunctionError(0);
}
/**
* Dummy implementation, just to provide error for --errorlist
*/
void unusedFunctionError(const Token *tok);
/**
* Dummy implementation, just to provide error for --errorlist
*/
void runSimplifiedChecks(const Tokenizer */*tokenizer*/, const Settings */*settings*/, ErrorLogger */*errorLogger*/)
{
}
std::string name() const
{
return "Unused functions";
}
std::string classInfo() const
{
return "Check for functions that are never called\n";
}
ErrorLogger *_errorLogger; ErrorLogger *_errorLogger;

View File

@ -333,8 +333,7 @@ void CppCheck::parseFromArgs(int argc, const char* const argv[])
doc << "===" << (*it)->name() << "===\n" doc << "===" << (*it)->name() << "===\n"
<< (*it)->classInfo() << "\n\n"; << (*it)->classInfo() << "\n\n";
} }
doc << "===" << "Unused functions" << "===\n"
<< "Check for functions that are never called\n";
std::string doc2(doc.str()); std::string doc2(doc.str());
while (doc2.find("\n\n\n") != std::string::npos) while (doc2.find("\n\n\n") != std::string::npos)
doc2.erase(doc2.find("\n\n\n"), 1); doc2.erase(doc2.find("\n\n\n"), 1);

View File

@ -6304,6 +6304,8 @@ void Tokenizer::cppcheckError(const Token *tok) const
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
else
Check::reportError(errmsg);
} }
@ -6783,6 +6785,7 @@ void Tokenizer::simplifyConst()
void Tokenizer::getErrorMessages() void Tokenizer::getErrorMessages()
{ {
syntaxError(0, ' '); syntaxError(0, ' ');
cppcheckError(0);
} }
/** find pattern */ /** find pattern */