Revert "cppcheck: Now it's possible to change the output format, for example to a visual studio compliant format"

This reverts commit 91a8dbd7b9.
This commit is contained in:
Daniel Marjamäki 2009-07-10 22:38:26 +02:00
parent ad4532f5e3
commit 59372199e3
9 changed files with 17 additions and 57 deletions

View File

@ -35,7 +35,6 @@
//---------------------------------------------------------------------------
CppCheck::CppCheck(ErrorLogger &errorLogger)
: ErrorLogger(errorLogger)
{
_errorLogger = &errorLogger;
}
@ -196,12 +195,6 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
}
}
// Use visual studio compliant output format
else if (strcmp(argv[i], "--output-format=VS") == 0)
{
_settings._outputFormat = "file(line)";
}
// auto deallocated classes..
else if (strcmp(argv[i], "--auto-dealloc") == 0)
{
@ -301,7 +294,6 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
" several paths. First given path is checked first. If\n"
" paths are relative to source files, this is not needed\n"
" -j [jobs] Start [jobs] threads to do the checking simultaneously.\n"
" --output-format=VS Use Visual Studio compliant output format.\n"
" -q, --quiet Only print error messages\n"
" -s, --style Check coding style\n"
" --unused-functions Check if there are unused functions\n"
@ -332,7 +324,6 @@ std::string CppCheck::parseFromArgs(int argc, const char* const argv[])
unsigned int CppCheck::check()
{
_errorLogger->outputFormat(_settings._outputFormat);
_checkUnusedFunctions.setErrorLogger(this);
std::sort(_filenames.begin(), _filenames.end());
for (unsigned int c = 0; c < _filenames.size(); c++)
@ -464,7 +455,7 @@ Settings CppCheck::settings() const
void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg)
{
std::string errmsg = toText(msg);
std::string errmsg = msg.toText();
// Alert only about unique errors
if (std::find(_errorList.begin(), _errorList.end(), errmsg) != _errorList.end())

View File

@ -112,6 +112,6 @@ void CppCheckExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
}
else
{
reportErr(toText(msg));
reportErr(msg.toText());
}
}

View File

@ -158,14 +158,14 @@ std::string ErrorLogger::ErrorMessage::toXML() const
return xml.str();
}
std::string ErrorLogger::toText(const ErrorLogger::ErrorMessage &msg) const
std::string ErrorLogger::ErrorMessage::toText() const
{
std::ostringstream text;
if (!msg._callStack.empty())
text << callStackToString(msg._callStack) << ": ";
if (!msg._severity.empty())
text << "(" << msg._severity << ") ";
text << msg._msg;
if (!_callStack.empty())
text << callStackToString(_callStack) << ": ";
if (!_severity.empty())
text << "(" << _severity << ") ";
text << _msg;
return text.str();
}
@ -191,30 +191,13 @@ void ErrorLogger::_writemsg(const Tokenizer *tokenizer, const std::list<const To
}
static void replace(std::string &s, const std::string &s1, const std::string &s2)
{
std::string::size_type pos = s.find(s1);
if (pos == std::string::npos)
return;
s.erase(pos, s1.length());
s.insert(pos, s2);
}
std::string ErrorLogger::callStackToString(const std::list<ErrorLogger::ErrorMessage::FileLocation> &callStack) const
std::string ErrorLogger::callStackToString(const std::list<ErrorLogger::ErrorMessage::FileLocation> &callStack)
{
std::ostringstream ostr;
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator tok = callStack.begin(); tok != callStack.end(); ++tok)
{
if (tok != callStack.begin())
ostr << " -> ";
std::string s = _outputFormat;
replace(s, "file", (*tok).getfile());
std::ostringstream line;
line << (*tok).line;
replace(s, "line", line.str());
ostr << s;
}
ostr << (tok == callStack.begin() ? "" : " -> ") << "[" << (*tok).getfile() << ":" << (*tok).line << "]";
return ostr.str();
}

View File

@ -63,7 +63,7 @@ public:
static std::string getXMLHeader();
static std::string getXMLFooter();
//std::string toText() const;
std::string toText() const;
std::string serialize() const;
bool deserialize(const std::string &data);
std::list<FileLocation> _callStack;
@ -72,17 +72,9 @@ public:
std::string _id;
};
ErrorLogger() : _outputFormat("[file:line]") { }
ErrorLogger() { }
virtual ~ErrorLogger() { }
/** Change the output format */
void outputFormat(const std::string &of)
{
_outputFormat = of;
}
std::string toText(const ErrorMessage &msg) const;
/**
* Information about progress is directed here.
* Override this to receive the progress messages.
@ -342,12 +334,10 @@ public:
}
std::string callStackToString(const std::list<ErrorLogger::ErrorMessage::FileLocation> &callStack) const;
static std::string callStackToString(const std::list<ErrorLogger::ErrorMessage::FileLocation> &callStack);
private:
void _writemsg(const Tokenizer *tokenizer, const Token *tok, const char severity[], const std::string &msg, const std::string &id);
void _writemsg(const Tokenizer *tokenizer, const std::list<const Token *> &callstack, const char severity[], const std::string &msg, const std::string &id);
std::string _outputFormat;
};
#endif

View File

@ -33,7 +33,6 @@ Settings::Settings()
_security = false;
_jobs = 1;
_exitCode = 0;
_outputFormat = "[file:line]";
}
Settings::~Settings()

View File

@ -50,9 +50,6 @@ public:
/** write xml results */
bool _xml;
/** output formatting */
std::string _outputFormat;
/** Checking if there are unused functions */
bool _unusedFunctions;

View File

@ -30,7 +30,7 @@
#endif
ThreadExecutor::ThreadExecutor(const std::vector<std::string> &filenames, const Settings &settings, ErrorLogger &errorLogger)
: ErrorLogger(errorLogger), _filenames(filenames), _settings(settings), _errorLogger(errorLogger), _fileCount(0)
: _filenames(filenames), _settings(settings), _errorLogger(errorLogger), _fileCount(0)
{
}
@ -84,7 +84,7 @@ bool ThreadExecutor::handleRead(unsigned int &result)
msg.deserialize(buf);
// Alert only about unique errors
std::string errmsg = toText(msg);
std::string errmsg = msg.toText();
if (std::find(_errorList.begin(), _errorList.end(), errmsg) == _errorList.end())
{
_errorList.push_back(errmsg);

View File

@ -101,7 +101,7 @@ private:
loc.file = "ab/cd/../ef.h";
errmsg._callStack.push_back(loc);
ASSERT_EQUALS("<error file=\"ab/ef.h\" line=\"0\" id=\"\" severity=\"\" msg=\"\"/>", errmsg.toXML());
//ASSERT_EQUALS("[ab/ef.h:0]: ", errorLogger.toText(errmsg));
ASSERT_EQUALS("[ab/ef.h:0]: ", errmsg.toText());
}
};

View File

@ -179,5 +179,5 @@ void TestFixture::reportOut(const std::string & /*outmsg*/)
void TestFixture::reportErr(const ErrorLogger::ErrorMessage &msg)
{
errout << toText(msg) << std::endl;
errout << msg.toText() << std::endl;
}