Skip to content

Commit 8c0d43d

Browse files
authored
removed unnecessary encapsulation of severity enum and made it an enum class (cppcheck-opensource#5541)
1 parent 179d26f commit 8c0d43d

28 files changed

Lines changed: 164 additions & 169 deletions

cli/cmdlineparser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
791791
if (message) {
792792
const tinyxml2::XMLElement *severity = message->FirstChildElement("severity");
793793
if (severity)
794-
rule.severity = Severity::fromString(severity->GetText());
794+
rule.severity = severityFromString(severity->GetText());
795795

796796
const tinyxml2::XMLElement *id = message->FirstChildElement("id");
797797
if (id)

gui/checkthread.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,9 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
347347
errorItem.errorPath.last().line = r1MatchRes.captured(2).toInt();
348348
errorItem.errorPath.last().column = r1MatchRes.captured(3).toInt();
349349
if (r1MatchRes.captured(4) == "warning")
350-
errorItem.severity = Severity::SeverityType::warning;
350+
errorItem.severity = Severity::warning;
351351
else if (r1MatchRes.captured(4) == "error" || r1MatchRes.captured(4) == "fatal error")
352-
errorItem.severity = Severity::SeverityType::error;
352+
errorItem.severity = Severity::error;
353353

354354
QString message,id;
355355
const QRegularExpressionMatch r2MatchRes = r2.match(r1MatchRes.captured(5));
@@ -362,13 +362,13 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
362362
id = tool + '-' + r2MatchRes.captured(2);
363363
if (tool == CLANG_TIDY) {
364364
if (id1.startsWith("performance"))
365-
errorItem.severity = Severity::SeverityType::performance;
365+
errorItem.severity = Severity::performance;
366366
else if (id1.startsWith("portability"))
367-
errorItem.severity = Severity::SeverityType::portability;
367+
errorItem.severity = Severity::portability;
368368
else if (id1.startsWith("misc") && !id1.contains("unused"))
369-
errorItem.severity = Severity::SeverityType::warning;
369+
errorItem.severity = Severity::warning;
370370
else
371-
errorItem.severity = Severity::SeverityType::style;
371+
errorItem.severity = Severity::style;
372372
}
373373
} else {
374374
message = r1MatchRes.captured(5);

gui/erroritem.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
*/
3838
class GuiSeverity {
3939
public:
40-
static QString toString(Severity::SeverityType severity) {
41-
return QString::fromStdString(Severity::toString(severity));
40+
static QString toString(Severity severity) {
41+
return QString::fromStdString(severityToString(severity));
4242
}
4343

44-
static Severity::SeverityType fromString(const QString &severity) {
45-
return Severity::fromString(severity.toStdString());
44+
static Severity fromString(const QString &severity) {
45+
return severityFromString(severity.toStdString());
4646
}
4747
};
4848

@@ -83,7 +83,7 @@ class ErrorItem {
8383

8484
QString file0;
8585
QString errorId;
86-
Severity::SeverityType severity;
86+
Severity severity;
8787
bool inconclusive;
8888
QString summary;
8989
QString message;
@@ -117,7 +117,7 @@ class ErrorLine {
117117
int cwe;
118118
unsigned long long hash;
119119
bool inconclusive;
120-
Severity::SeverityType severity;
120+
Severity severity;
121121
QString summary;
122122
QString message;
123123
QString sinceDate;

gui/resultstree.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ QStandardItem *ResultsTree::addBacktraceFiles(QStandardItem *parent,
319319
return list[0];
320320
}
321321

322-
QString ResultsTree::severityToTranslatedString(Severity::SeverityType severity)
322+
QString ResultsTree::severityToTranslatedString(Severity severity)
323323
{
324324
switch (severity) {
325325
case Severity::style:
@@ -901,7 +901,7 @@ void ResultsTree::copy()
901901
QString inconclusive = data[INCONCLUSIVE].toBool() ? ",inconclusive" : "";
902902
text += '[' + data[FILENAME].toString() + ':' + QString::number(data[LINE].toInt())
903903
+ "] ("
904-
+ QString::fromStdString(Severity::toString(ShowTypes::ShowTypeToSeverity((ShowTypes::ShowType)data[SEVERITY].toInt()))) + inconclusive
904+
+ QString::fromStdString(severityToString(ShowTypes::ShowTypeToSeverity((ShowTypes::ShowType)data[SEVERITY].toInt()))) + inconclusive
905905
+ ") "
906906
+ data[MESSAGE].toString()
907907
+ " ["
@@ -1155,7 +1155,7 @@ QString ResultsTree::getFilePath(const QStandardItem *target, bool fullPath)
11551155
return QString();
11561156
}
11571157

1158-
QString ResultsTree::severityToIcon(Severity::SeverityType severity)
1158+
QString ResultsTree::severityToIcon(Severity severity)
11591159
{
11601160
switch (severity) {
11611161
case Severity::error:

gui/resultstree.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ protected slots:
335335
*
336336
* @param severity Severity
337337
*/
338-
static QString severityToIcon(Severity::SeverityType severity);
338+
static QString severityToIcon(Severity severity);
339339

340340
/**
341341
* @brief Helper function to open an error within target with application*
@@ -382,7 +382,7 @@ protected slots:
382382
* @param severity Severity to convert
383383
* @return Severity as translated string
384384
*/
385-
static QString severityToTranslatedString(Severity::SeverityType severity);
385+
static QString severityToTranslatedString(Severity severity);
386386

387387
/**
388388
* @brief Load all settings

gui/showtypes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ShowTypes::~ShowTypes()
3232
save();
3333
}
3434

35-
ShowTypes::ShowType ShowTypes::SeverityToShowType(Severity::SeverityType severity)
35+
ShowTypes::ShowType ShowTypes::SeverityToShowType(Severity severity)
3636
{
3737
switch (severity) {
3838
case Severity::none:
@@ -54,7 +54,7 @@ ShowTypes::ShowType ShowTypes::SeverityToShowType(Severity::SeverityType severit
5454
}
5555
}
5656

57-
Severity::SeverityType ShowTypes::ShowTypeToSeverity(ShowTypes::ShowType type)
57+
Severity ShowTypes::ShowTypeToSeverity(ShowTypes::ShowType type)
5858
{
5959
switch (type) {
6060
case ShowTypes::ShowStyle:
@@ -117,7 +117,7 @@ bool ShowTypes::isShown(ShowTypes::ShowType category) const
117117
return mVisible[category];
118118
}
119119

120-
bool ShowTypes::isShown(Severity::SeverityType severity) const
120+
bool ShowTypes::isShown(Severity severity) const
121121
{
122122
return isShown(ShowTypes::SeverityToShowType(severity));
123123
}

gui/showtypes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class ShowTypes {
8585
* @param severity severity to check.
8686
* @return true if the severity is visible.
8787
*/
88-
bool isShown(Severity::SeverityType severity) const;
88+
bool isShown(Severity severity) const;
8989

9090
/**
9191
* @brief Show/hide the showtype.
@@ -99,14 +99,14 @@ class ShowTypes {
9999
* @param severity Error severity
100100
* @return Severity converted to ShowTypes value
101101
*/
102-
static ShowTypes::ShowType SeverityToShowType(Severity::SeverityType severity);
102+
static ShowTypes::ShowType SeverityToShowType(Severity severity);
103103

104104
/**
105105
* @brief Convert ShowType to severity string
106106
* @param type ShowType to convert
107107
* @return ShowType converted to severity
108108
*/
109-
static Severity::SeverityType ShowTypeToSeverity(ShowTypes::ShowType type);
109+
static Severity ShowTypeToSeverity(ShowTypes::ShowType type);
110110

111111
/**
112112
* @brief Convert QVariant (that contains an int) to Showtypes value

lib/check.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void Check::writeToErrorList(const ErrorMessage &errmsg)
6161
}
6262

6363

64-
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)
64+
void Check::reportError(const std::list<const Token *> &callstack, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty)
6565
{
6666
const ErrorMessage errmsg(callstack, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, certainty);
6767
if (mErrorLogger)
@@ -70,7 +70,7 @@ void Check::reportError(const std::list<const Token *> &callstack, Severity::Sev
7070
writeToErrorList(errmsg);
7171
}
7272

73-
void Check::reportError(const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
73+
void Check::reportError(const ErrorPath &errorPath, Severity severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
7474
{
7575
const ErrorMessage errmsg(errorPath, mTokenizer ? &mTokenizer->list : nullptr, severity, id, msg, cwe, certainty);
7676
if (mErrorLogger)

lib/check.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,25 @@ class CPPCHECKLIB Check {
137137
ErrorLogger* const mErrorLogger{};
138138

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

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

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

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

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

160160
/** log checker */
161161
void logChecker(const char id[]);

lib/checkio.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,7 @@ void CheckIO::wrongPrintfScanfArgumentsError(const Token* tok,
17151715
nonneg int numFormat,
17161716
nonneg int numFunction)
17171717
{
1718-
const Severity::SeverityType severity = numFormat > numFunction ? Severity::error : Severity::warning;
1718+
const Severity severity = numFormat > numFunction ? Severity::error : Severity::warning;
17191719
if (severity != Severity::error && !mSettings->severity.isEnabled(Severity::warning))
17201720
return;
17211721

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

17501750
void CheckIO::invalidScanfArgTypeError_s(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
17511751
{
1752-
const Severity::SeverityType severity = getSeverity(argInfo);
1752+
const Severity severity = getSeverity(argInfo);
17531753
if (!mSettings->severity.isEnabled(severity))
17541754
return;
17551755
std::ostringstream errmsg;
@@ -1765,7 +1765,7 @@ void CheckIO::invalidScanfArgTypeError_s(const Token* tok, nonneg int numFormat,
17651765
}
17661766
void CheckIO::invalidScanfArgTypeError_int(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo, bool isUnsigned)
17671767
{
1768-
const Severity::SeverityType severity = getSeverity(argInfo);
1768+
const Severity severity = getSeverity(argInfo);
17691769
if (!mSettings->severity.isEnabled(severity))
17701770
return;
17711771
std::ostringstream errmsg;
@@ -1810,7 +1810,7 @@ void CheckIO::invalidScanfArgTypeError_int(const Token* tok, nonneg int numForma
18101810
}
18111811
void CheckIO::invalidScanfArgTypeError_float(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
18121812
{
1813-
const Severity::SeverityType severity = getSeverity(argInfo);
1813+
const Severity severity = getSeverity(argInfo);
18141814
if (!mSettings->severity.isEnabled(severity))
18151815
return;
18161816
std::ostringstream errmsg;
@@ -1829,7 +1829,7 @@ void CheckIO::invalidScanfArgTypeError_float(const Token* tok, nonneg int numFor
18291829

18301830
void CheckIO::invalidPrintfArgTypeError_s(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo)
18311831
{
1832-
const Severity::SeverityType severity = getSeverity(argInfo);
1832+
const Severity severity = getSeverity(argInfo);
18331833
if (!mSettings->severity.isEnabled(severity))
18341834
return;
18351835
std::ostringstream errmsg;
@@ -1840,7 +1840,7 @@ void CheckIO::invalidPrintfArgTypeError_s(const Token* tok, nonneg int numFormat
18401840
}
18411841
void CheckIO::invalidPrintfArgTypeError_n(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo)
18421842
{
1843-
const Severity::SeverityType severity = getSeverity(argInfo);
1843+
const Severity severity = getSeverity(argInfo);
18441844
if (!mSettings->severity.isEnabled(severity))
18451845
return;
18461846
std::ostringstream errmsg;
@@ -1851,7 +1851,7 @@ void CheckIO::invalidPrintfArgTypeError_n(const Token* tok, nonneg int numFormat
18511851
}
18521852
void CheckIO::invalidPrintfArgTypeError_p(const Token* tok, nonneg int numFormat, const ArgumentInfo* argInfo)
18531853
{
1854-
const Severity::SeverityType severity = getSeverity(argInfo);
1854+
const Severity severity = getSeverity(argInfo);
18551855
if (!mSettings->severity.isEnabled(severity))
18561856
return;
18571857
std::ostringstream errmsg;
@@ -1901,7 +1901,7 @@ static void printfFormatType(std::ostream& os, const std::string& specifier, boo
19011901

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

19161916
void CheckIO::invalidPrintfArgTypeError_sint(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
19171917
{
1918-
const Severity::SeverityType severity = getSeverity(argInfo);
1918+
const Severity severity = getSeverity(argInfo);
19191919
if (!mSettings->severity.isEnabled(severity))
19201920
return;
19211921
std::ostringstream errmsg;
@@ -1928,7 +1928,7 @@ void CheckIO::invalidPrintfArgTypeError_sint(const Token* tok, nonneg int numFor
19281928
}
19291929
void CheckIO::invalidPrintfArgTypeError_float(const Token* tok, nonneg int numFormat, const std::string& specifier, const ArgumentInfo* argInfo)
19301930
{
1931-
const Severity::SeverityType severity = getSeverity(argInfo);
1931+
const Severity severity = getSeverity(argInfo);
19321932
if (!mSettings->severity.isEnabled(severity))
19331933
return;
19341934
std::ostringstream errmsg;
@@ -1941,7 +1941,7 @@ void CheckIO::invalidPrintfArgTypeError_float(const Token* tok, nonneg int numFo
19411941
reportError(tok, severity, "invalidPrintfArgType_float", errmsg.str(), CWE686, Certainty::normal);
19421942
}
19431943

1944-
Severity::SeverityType CheckIO::getSeverity(const CheckIO::ArgumentInfo *argInfo)
1944+
Severity CheckIO::getSeverity(const CheckIO::ArgumentInfo *argInfo)
19451945
{
19461946
return (argInfo && argInfo->typeToken && !argInfo->typeToken->originalName().empty()) ? Severity::portability : Severity::warning;
19471947
}

0 commit comments

Comments
 (0)