Skip to content

Commit

Permalink
removed unnecessary encapsulation of severity enum and made it an `en…
Browse files Browse the repository at this point in the history
…um class`
  • Loading branch information
firewave committed Oct 11, 2023
1 parent d757f8b commit be12b0e
Show file tree
Hide file tree
Showing 28 changed files with 164 additions and 169 deletions.
2 changes: 1 addition & 1 deletion cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
if (message) {
const tinyxml2::XMLElement *severity = message->FirstChildElement("severity");
if (severity)
rule.severity = Severity::fromString(severity->GetText());
rule.severity = severityFromString(severity->GetText());

const tinyxml2::XMLElement *id = message->FirstChildElement("id");
if (id)
Expand Down
12 changes: 6 additions & 6 deletions gui/checkthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
errorItem.errorPath.last().line = r1MatchRes.captured(2).toInt();
errorItem.errorPath.last().column = r1MatchRes.captured(3).toInt();
if (r1MatchRes.captured(4) == "warning")
errorItem.severity = Severity::SeverityType::warning;
errorItem.severity = Severity::warning;
else if (r1MatchRes.captured(4) == "error" || r1MatchRes.captured(4) == "fatal error")
errorItem.severity = Severity::SeverityType::error;
errorItem.severity = Severity::error;

QString message,id;
const QRegularExpressionMatch r2MatchRes = r2.match(r1MatchRes.captured(5));
Expand All @@ -362,13 +362,13 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
id = tool + '-' + r2MatchRes.captured(2);
if (tool == CLANG_TIDY) {
if (id1.startsWith("performance"))
errorItem.severity = Severity::SeverityType::performance;
errorItem.severity = Severity::performance;
else if (id1.startsWith("portability"))
errorItem.severity = Severity::SeverityType::portability;
errorItem.severity = Severity::portability;
else if (id1.startsWith("misc") && !id1.contains("unused"))
errorItem.severity = Severity::SeverityType::warning;
errorItem.severity = Severity::warning;
else
errorItem.severity = Severity::SeverityType::style;
errorItem.severity = Severity::style;
}
} else {
message = r1MatchRes.captured(5);
Expand Down
12 changes: 6 additions & 6 deletions gui/erroritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
*/
class GuiSeverity {
public:
static QString toString(Severity::SeverityType severity) {
return QString::fromStdString(Severity::toString(severity));
static QString toString(Severity severity) {
return QString::fromStdString(severityToString(severity));
}

static Severity::SeverityType fromString(const QString &severity) {
return Severity::fromString(severity.toStdString());
static Severity fromString(const QString &severity) {
return severityFromString(severity.toStdString());
}
};

Expand Down Expand Up @@ -83,7 +83,7 @@ class ErrorItem {

QString file0;
QString errorId;
Severity::SeverityType severity;
Severity severity;
bool inconclusive;
QString summary;
QString message;
Expand Down Expand Up @@ -117,7 +117,7 @@ class ErrorLine {
int cwe;
unsigned long long hash;
bool inconclusive;
Severity::SeverityType severity;
Severity severity;
QString summary;
QString message;
QString sinceDate;
Expand Down
6 changes: 3 additions & 3 deletions gui/resultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ QStandardItem *ResultsTree::addBacktraceFiles(QStandardItem *parent,
return list[0];
}

QString ResultsTree::severityToTranslatedString(Severity::SeverityType severity)
QString ResultsTree::severityToTranslatedString(Severity severity)
{
switch (severity) {
case Severity::style:
Expand Down Expand Up @@ -901,7 +901,7 @@ void ResultsTree::copy()
QString inconclusive = data[INCONCLUSIVE].toBool() ? ",inconclusive" : "";
text += '[' + data[FILENAME].toString() + ':' + QString::number(data[LINE].toInt())
+ "] ("
+ QString::fromStdString(Severity::toString(ShowTypes::ShowTypeToSeverity((ShowTypes::ShowType)data[SEVERITY].toInt()))) + inconclusive
+ QString::fromStdString(severityToString(ShowTypes::ShowTypeToSeverity((ShowTypes::ShowType)data[SEVERITY].toInt()))) + inconclusive
+ ") "
+ data[MESSAGE].toString()
+ " ["
Expand Down Expand Up @@ -1155,7 +1155,7 @@ QString ResultsTree::getFilePath(const QStandardItem *target, bool fullPath)
return QString();
}

QString ResultsTree::severityToIcon(Severity::SeverityType severity)
QString ResultsTree::severityToIcon(Severity severity)
{
switch (severity) {
case Severity::error:
Expand Down
4 changes: 2 additions & 2 deletions gui/resultstree.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ protected slots:
*
* @param severity Severity
*/
static QString severityToIcon(Severity::SeverityType severity);
static QString severityToIcon(Severity severity);

/**
* @brief Helper function to open an error within target with application*
Expand Down Expand Up @@ -382,7 +382,7 @@ protected slots:
* @param severity Severity to convert
* @return Severity as translated string
*/
static QString severityToTranslatedString(Severity::SeverityType severity);
static QString severityToTranslatedString(Severity severity);

/**
* @brief Load all settings
Expand Down
6 changes: 3 additions & 3 deletions gui/showtypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ShowTypes::~ShowTypes()
save();
}

ShowTypes::ShowType ShowTypes::SeverityToShowType(Severity::SeverityType severity)
ShowTypes::ShowType ShowTypes::SeverityToShowType(Severity severity)
{
switch (severity) {
case Severity::none:
Expand All @@ -54,7 +54,7 @@ ShowTypes::ShowType ShowTypes::SeverityToShowType(Severity::SeverityType severit
}
}

Severity::SeverityType ShowTypes::ShowTypeToSeverity(ShowTypes::ShowType type)
Severity ShowTypes::ShowTypeToSeverity(ShowTypes::ShowType type)
{
switch (type) {
case ShowTypes::ShowStyle:
Expand Down Expand Up @@ -117,7 +117,7 @@ bool ShowTypes::isShown(ShowTypes::ShowType category) const
return mVisible[category];
}

bool ShowTypes::isShown(Severity::SeverityType severity) const
bool ShowTypes::isShown(Severity severity) const
{
return isShown(ShowTypes::SeverityToShowType(severity));
}
Expand Down
6 changes: 3 additions & 3 deletions gui/showtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ShowTypes {
* @param severity severity to check.
* @return true if the severity is visible.
*/
bool isShown(Severity::SeverityType severity) const;
bool isShown(Severity severity) const;

/**
* @brief Show/hide the showtype.
Expand All @@ -99,14 +99,14 @@ class ShowTypes {
* @param severity Error severity
* @return Severity converted to ShowTypes value
*/
static ShowTypes::ShowType SeverityToShowType(Severity::SeverityType severity);
static ShowTypes::ShowType SeverityToShowType(Severity severity);

/**
* @brief Convert ShowType to severity string
* @param type ShowType to convert
* @return ShowType converted to severity
*/
static Severity::SeverityType ShowTypeToSeverity(ShowTypes::ShowType type);
static Severity ShowTypeToSeverity(ShowTypes::ShowType type);

/**
* @brief Convert QVariant (that contains an int) to Showtypes value
Expand Down
4 changes: 2 additions & 2 deletions lib/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void Check::writeToErrorList(const ErrorMessage &errmsg)
}


void Check::reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty)
void Check::reportError(const std::list<const Token *> &callstack, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty)
{
const ErrorMessage errmsg(callstack, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, certainty);
if (mErrorLogger)
Expand All @@ -70,7 +70,7 @@ void Check::reportError(const std::list<const Token *> &callstack, Severity::Sev
writeToErrorList(errmsg);
}

void Check::reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
void Check::reportError(const ErrorPath &errorPath, Severity severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
{
const ErrorMessage errmsg(errorPath, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, certainty);
if (mErrorLogger)
Expand Down
10 changes: 5 additions & 5 deletions lib/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,25 @@ class CPPCHECKLIB Check {
ErrorLogger* const mErrorLogger{};

/** report an error */
void reportError(const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg) {
void reportError(const Token *tok, const Severity severity, const std::string &id, const std::string &msg) {
reportError(tok, severity, id, msg, CWE(0U), Certainty::normal);
}

/** report an error */
void reportError(const Token *tok, const Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty) {
void reportError(const Token *tok, const Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty) {
const std::list<const Token *> callstack(1, tok);
reportError(callstack, severity, id, msg, cwe, certainty);
}

/** report an error */
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg) {
void reportError(const std::list<const Token *> &callstack, Severity severity, const std::string &id, const std::string &msg) {
reportError(callstack, severity, id, msg, CWE(0U), Certainty::normal);
}

/** report an error */
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty);
void reportError(const std::list<const Token *> &callstack, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty);

void reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty);
void reportError(const ErrorPath &errorPath, Severity severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty);

/** log checker */
void logChecker(const char id[]);
Expand Down
22 changes: 11 additions & 11 deletions lib/checkio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ void CheckIO::wrongPrintfScanfArgumentsError(const Token* tok,
nonneg int numFormat,
nonneg int numFunction)
{
const Severity::SeverityType severity = numFormat > numFunction ? Severity::error : Severity::warning;
const Severity severity = numFormat > numFunction ? Severity::error : Severity::warning;
if (severity != Severity::error && !mSettings->severity.isEnabled(Severity::warning))
return;

Expand Down Expand Up @@ -1749,7 +1749,7 @@ void CheckIO::wrongPrintfScanfPosixParameterPositionError(const Token* tok, cons

void CheckIO::invalidScanfArgTypeError_s(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
{
const Severity::SeverityType severity = getSeverity(argInfo);
const Severity severity = getSeverity(argInfo);
if (!mSettings->severity.isEnabled(severity))
return;
std::ostringstream errmsg;
Expand All @@ -1765,7 +1765,7 @@ void CheckIO::invalidScanfArgTypeError_s(const Token* tok, nonneg int numFormat,
}
void CheckIO::invalidScanfArgTypeError_int(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo, bool isUnsigned)
{
const Severity::SeverityType severity = getSeverity(argInfo);
const Severity severity = getSeverity(argInfo);
if (!mSettings->severity.isEnabled(severity))
return;
std::ostringstream errmsg;
Expand Down Expand Up @@ -1810,7 +1810,7 @@ void CheckIO::invalidScanfArgTypeError_int(const Token* tok, nonneg int numForma
}
void CheckIO::invalidScanfArgTypeError_float(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
{
const Severity::SeverityType severity = getSeverity(argInfo);
const Severity severity = getSeverity(argInfo);
if (!mSettings->severity.isEnabled(severity))
return;
std::ostringstream errmsg;
Expand All @@ -1829,7 +1829,7 @@ void CheckIO::invalidScanfArgTypeError_float(const Token* tok, nonneg int numFor

void CheckIO::invalidPrintfArgTypeError_s(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo)
{
const Severity::SeverityType severity = getSeverity(argInfo);
const Severity severity = getSeverity(argInfo);
if (!mSettings->severity.isEnabled(severity))
return;
std::ostringstream errmsg;
Expand All @@ -1840,7 +1840,7 @@ void CheckIO::invalidPrintfArgTypeError_s(const Token* tok, nonneg int numFormat
}
void CheckIO::invalidPrintfArgTypeError_n(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo)
{
const Severity::SeverityType severity = getSeverity(argInfo);
const Severity severity = getSeverity(argInfo);
if (!mSettings->severity.isEnabled(severity))
return;
std::ostringstream errmsg;
Expand All @@ -1851,7 +1851,7 @@ void CheckIO::invalidPrintfArgTypeError_n(const Token* tok, nonneg int numFormat
}
void CheckIO::invalidPrintfArgTypeError_p(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo)
{
const Severity::SeverityType severity = getSeverity(argInfo);
const Severity severity = getSeverity(argInfo);
if (!mSettings->severity.isEnabled(severity))
return;
std::ostringstream errmsg;
Expand Down Expand Up @@ -1901,7 +1901,7 @@ static void printfFormatType(std::ostream& os, const std::string& specifier, boo

void CheckIO::invalidPrintfArgTypeError_uint(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
{
const Severity::SeverityType severity = getSeverity(argInfo);
const Severity severity = getSeverity(argInfo);
if (!mSettings->severity.isEnabled(severity))
return;
std::ostringstream errmsg;
Expand All @@ -1915,7 +1915,7 @@ void CheckIO::invalidPrintfArgTypeError_uint(const Token* tok, nonneg int numFor

void CheckIO::invalidPrintfArgTypeError_sint(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
{
const Severity::SeverityType severity = getSeverity(argInfo);
const Severity severity = getSeverity(argInfo);
if (!mSettings->severity.isEnabled(severity))
return;
std::ostringstream errmsg;
Expand All @@ -1928,7 +1928,7 @@ void CheckIO::invalidPrintfArgTypeError_sint(const Token* tok, nonneg int numFor
}
void CheckIO::invalidPrintfArgTypeError_float(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
{
const Severity::SeverityType severity = getSeverity(argInfo);
const Severity severity = getSeverity(argInfo);
if (!mSettings->severity.isEnabled(severity))
return;
std::ostringstream errmsg;
Expand All @@ -1941,7 +1941,7 @@ void CheckIO::invalidPrintfArgTypeError_float(const Token* tok, nonneg int numFo
reportError(tok, severity, "invalidPrintfArgType_float", errmsg.str(), CWE686, Certainty::normal);
}

Severity::SeverityType CheckIO::getSeverity(const CheckIO::ArgumentInfo *argInfo)
Severity CheckIO::getSeverity(const CheckIO::ArgumentInfo *argInfo)
{
return (argInfo && argInfo->typeToken && !argInfo->typeToken->originalName().empty()) ? Severity::portability : Severity::warning;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/checkio.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class CPPCHECKLIB CheckIO : public Check {
void invalidLengthModifierError(const Token* tok, nonneg int numFormat, const std::string& modifier);
void invalidScanfFormatWidthError(const Token* tok, nonneg int numFormat, int width, const Variable *var, const std::string& specifier);
static void argumentType(std::ostream & os, const ArgumentInfo * argInfo);
static Severity::SeverityType getSeverity(const ArgumentInfo *argInfo);
static Severity getSeverity(const ArgumentInfo *argInfo);

void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
CheckIO c(nullptr, settings, errorLogger);
Expand Down
4 changes: 2 additions & 2 deletions lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void CheckMemoryLeak::memoryLeak(const Token *tok, const std::string &varname, A
}
//---------------------------------------------------------------------------

void CheckMemoryLeak::reportErr(const Token *tok, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const
void CheckMemoryLeak::reportErr(const Token *tok, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe) const
{
std::list<const Token *> callstack;

Expand All @@ -289,7 +289,7 @@ void CheckMemoryLeak::reportErr(const Token *tok, Severity::SeverityType severit
reportErr(callstack, severity, id, msg, cwe);
}

void CheckMemoryLeak::reportErr(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const
void CheckMemoryLeak::reportErr(const std::list<const Token *> &callstack, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe) const
{
const ErrorMessage errmsg(callstack, mTokenizer_ ? &mTokenizer_->list : nullptr, severity, id, msg, cwe, Certainty::normal);
if (mErrorLogger_)
Expand Down
4 changes: 2 additions & 2 deletions lib/checkmemoryleak.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class CPPCHECKLIB CheckMemoryLeak {
* @param msg text
* @param cwe cwe number
*/
void reportErr(const Token *tok, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const;
void reportErr(const Token *tok, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe) const;

/**
* Report error. Similar with the function Check::reportError
Expand All @@ -80,7 +80,7 @@ class CPPCHECKLIB CheckMemoryLeak {
* @param msg text
* @param cwe cwe number
*/
void reportErr(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const;
void reportErr(const std::list<const Token *> &callstack, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe) const;

public:
CheckMemoryLeak() = delete;
Expand Down
2 changes: 1 addition & 1 deletion lib/checktype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void CheckType::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, con
}


Severity::SeverityType severity = rhsbits.errorSeverity() ? Severity::error : Severity::warning;
Severity severity = rhsbits.errorSeverity() ? Severity::error : Severity::warning;
if (cpp14)
severity = Severity::portability;

Expand Down
Loading

0 comments on commit be12b0e

Please sign in to comment.