Refactor ErrorMessage constructor to take Severity::SeverityType.

This removes lots of unneeded casting as everybody now uses the
Severity::SeverityType.
This commit is contained in:
Kimmo Varis 2010-07-14 23:11:32 +03:00
parent d811970531
commit ad0394939a
7 changed files with 17 additions and 19 deletions

View File

@ -127,7 +127,7 @@ protected:
} }
/** report an error */ /** report an error */
void reportError(const std::list<const Token *> &callstack, const Severity::SeverityType severity, const std::string &id, std::string msg) void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, std::string msg)
{ {
// If the verbose flag hasn't been given, don't show verbose information // If the verbose flag hasn't been given, don't show verbose information
if (!_settings || !_settings->_verbose) if (!_settings || !_settings->_verbose)
@ -150,7 +150,7 @@ protected:
locationList.push_back(loc); locationList.push_back(loc);
} }
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::toString(severity), msg, id); const ErrorLogger::ErrorMessage errmsg(locationList, severity, msg, id);
if (_errorLogger) if (_errorLogger)
_errorLogger->reportErr(errmsg); _errorLogger->reportErr(errmsg);
else else

View File

@ -325,7 +325,7 @@ void CheckMemoryLeak::reportErr(const std::list<const Token *> &callstack, Sever
locations.push_back(loc); locations.push_back(loc);
} }
const ErrorLogger::ErrorMessage errmsg(locations, Severity::toString(severity), msg, id); const ErrorLogger::ErrorMessage errmsg(locations, severity, msg, id);
if (errorLogger) if (errorLogger)
errorLogger->reportErr(errmsg); errorLogger->reportErr(errmsg);

View File

@ -192,7 +192,7 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger,
locationList.push_back(fileLoc); locationList.push_back(fileLoc);
} }
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::toString(Severity::style), "The function '" + funcname + "' is never used", "unusedFunction"); const ErrorLogger::ErrorMessage errmsg(locationList, Severity::style, "The function '" + funcname + "' is never used", "unusedFunction");
if (errorLogger) if (errorLogger)
errorLogger->reportErr(errmsg); errorLogger->reportErr(errmsg);
else else

View File

@ -23,15 +23,15 @@
#include <sstream> #include <sstream>
ErrorLogger::ErrorMessage::ErrorMessage() ErrorLogger::ErrorMessage::ErrorMessage()
:_severity(Severity::none) :_severity(Severity::none)
{ {
} }
#include <iostream> #include <iostream>
ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, const std::string &severity, const std::string &msg, const std::string &id) ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id)
{ {
_callStack = callStack; _callStack = callStack;
_severity = Severity::fromString(severity); _severity = severity;
_msg = msg; _msg = msg;
_id = id; _id = id;
} }
@ -224,12 +224,10 @@ void ErrorLogger::_writemsg(const Tokenizer *tokenizer, const std::list<const To
locationList.push_back(loc); locationList.push_back(loc);
} }
reportErr(ErrorLogger::ErrorMessage(locationList, severity, msg, id)); std::string strseverity(severity);
reportErr(ErrorLogger::ErrorMessage(locationList, Severity::fromString(strseverity), msg, id));
} }
std::string ErrorLogger::callStackToString(const std::list<ErrorLogger::ErrorMessage::FileLocation> &callStack) std::string ErrorLogger::callStackToString(const std::list<ErrorLogger::ErrorMessage::FileLocation> &callStack)
{ {
std::ostringstream ostr; std::ostringstream ostr;

View File

@ -95,7 +95,7 @@ public:
unsigned int line; unsigned int line;
}; };
ErrorMessage(const std::list<FileLocation> &callStack, const std::string &severity, const std::string &msg, const std::string &id); ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id);
ErrorMessage(); ErrorMessage();
std::string toXML() const; std::string toXML() const;

View File

@ -49,7 +49,7 @@ void Preprocessor::writeError(const std::string &fileName, const int linenr, Err
loc.file = fileName; loc.file = fileName;
locationList.push_back(loc); locationList.push_back(loc);
errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList, errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
"error", Severity::error,
errorText, errorText,
errorType)); errorType));
} }

View File

@ -415,7 +415,7 @@ void Tokenizer::duplicateTypedefError(const Token *tok1, const Token *tok2, cons
locationList.push_back(loc); locationList.push_back(loc);
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
"style", Severity::style,
std::string(type + " '" + tok2->str() + std::string(type + " '" + tok2->str() +
"' hides typedef with same name"), "' hides typedef with same name"),
"variableHidingTypedef"); "variableHidingTypedef");
@ -441,7 +441,7 @@ void Tokenizer::duplicateDeclarationError(const Token *tok1, const Token *tok2,
locationList.push_back(loc); locationList.push_back(loc);
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
"style", Severity::style,
std::string(type + " '" + tok2->str() + std::string(type + " '" + tok2->str() +
"' forward declaration unnecessary, already declared"), "' forward declaration unnecessary, already declared"),
"unnecessaryForwardDeclaration"); "unnecessaryForwardDeclaration");
@ -2288,7 +2288,7 @@ void Tokenizer::simplifyTemplates()
locationList.push_back(loc); locationList.push_back(loc);
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
"debug", Severity::debug,
"Failed to instantiate template. The checking continues anyway.", "Failed to instantiate template. The checking continues anyway.",
"templateInstantiate"); "templateInstantiate");
@ -6184,7 +6184,7 @@ void Tokenizer::duplicateEnumError(const Token * tok1, const Token * tok2, const
locationList.push_back(loc); locationList.push_back(loc);
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
"style", Severity::style,
std::string(type + " '" + tok2->str() + std::string(type + " '" + tok2->str() +
"' hides enumerator with same name"), "' hides enumerator with same name"),
"variableHidingEnum"); "variableHidingEnum");
@ -6931,7 +6931,7 @@ void Tokenizer::syntaxError(const Token *tok, char c)
} }
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
"error", Severity::error,
std::string("Invalid number of character (") + std::string("Invalid number of character (") +
c + c +
") " + ") " +
@ -6974,7 +6974,7 @@ void Tokenizer::cppcheckError(const Token *tok) const
} }
const ErrorLogger::ErrorMessage errmsg(locationList, const ErrorLogger::ErrorMessage errmsg(locationList,
"error", Severity::error,
"### Internal error in Cppcheck. Please report it.", "### Internal error in Cppcheck. Please report it.",
"cppcheckError"); "cppcheckError");