Skip to content

Commit 01b94e7

Browse files
committed
add separate report types for misra C editions
1 parent 3181f13 commit 01b94e7

File tree

8 files changed

+79
-27
lines changed

8 files changed

+79
-27
lines changed

cli/cmdlineparser.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,8 +1305,12 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
13051305
mSettings.reportType = ReportType::certC;
13061306
} else if (typeStr == "cert-cpp-2016") {
13071307
mSettings.reportType = ReportType::certCpp;
1308-
} else if (typeStr == "misra-c-2012" || typeStr == "misra-c-2023") {
1309-
mSettings.reportType = ReportType::misraC;
1308+
} else if (typeStr == "misra-c-2012") {
1309+
mSettings.reportType = ReportType::misraC2012;
1310+
} else if (typeStr == "misra-c-2023") {
1311+
mSettings.reportType = ReportType::misraC2023;
1312+
} else if (typeStr == "misra-c-2025") {
1313+
mSettings.reportType = ReportType::misraC2025;
13101314
} else if (typeStr == "misra-cpp-2008") {
13111315
mSettings.reportType = ReportType::misraCpp2008;
13121316
} else if (typeStr == "misra-cpp-2023") {
@@ -1957,6 +1961,7 @@ void CmdLineParser::printHelp() const
19571961
" * cert-cpp-2016 Cert C++ 2016\n"
19581962
" * misra-c-2012 Misra C 2012\n"
19591963
" * misra-c-2023 Misra C 2023\n"
1964+
" * misra-c-2025 Misra C 2025\n"
19601965
" * misra-cpp-2008 Misra C++ 2008\n"
19611966
" * misra-cpp-2023 Misra C++ 2023\n"
19621967
" --rule=<rule> Match regular expression.\n"

gui/mainwindow.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ void MainWindow::loadSettings()
391391
mUI->mActionReportAutosar->setChecked(reportType == ReportType::autosar);
392392
mUI->mActionReportCertC->setChecked(reportType == ReportType::certC);
393393
mUI->mActionReportCertCpp->setChecked(reportType == ReportType::certCpp);
394-
mUI->mActionReportMisraC->setChecked(reportType == ReportType::misraC);
394+
mUI->mActionReportMisraC->setChecked(reportType == ReportType::misraC2012 ||
395+
reportType == ReportType::misraC2023 ||
396+
reportType == ReportType::misraC2025);
395397
mUI->mActionReportMisraCpp2008->setChecked(reportType == ReportType::misraCpp2008);
396398
mUI->mActionReportMisraCpp2023->setChecked(reportType == ReportType::misraCpp2023);
397399

@@ -470,6 +472,15 @@ void MainWindow::loadSettings()
470472
}
471473
}
472474

475+
static ReportType getMisraCReportType(const QStringList &standards)
476+
{
477+
if (standards.contains(CODING_STANDARD_MISRA_C_2023))
478+
return ReportType::misraC2023;
479+
if (standards.contains(CODING_STANDARD_MISRA_C_2025))
480+
return ReportType::misraC2025;
481+
return ReportType::misraC2012;
482+
}
483+
473484
void MainWindow::saveSettings() const
474485
{
475486
// Window/dialog sizes
@@ -480,7 +491,7 @@ void MainWindow::saveSettings() const
480491
const ReportType reportType = mUI->mActionReportAutosar->isChecked() ? ReportType::autosar :
481492
mUI->mActionReportCertC->isChecked() ? ReportType::certC :
482493
mUI->mActionReportCertCpp->isChecked() ? ReportType::certCpp :
483-
mUI->mActionReportMisraC->isChecked() ? ReportType::misraC :
494+
mUI->mActionReportMisraC->isChecked() ? getMisraCReportType(mProjectFile->getCodingStandards()) :
484495
mUI->mActionReportMisraCpp2008->isChecked() ? ReportType::misraCpp2008 :
485496
mUI->mActionReportMisraCpp2023->isChecked() ? ReportType::misraCpp2023 :
486497
ReportType::normal;
@@ -2283,7 +2294,7 @@ void MainWindow::changeReportType() {
22832294
const ReportType reportType = mUI->mActionReportAutosar->isChecked() ? ReportType::autosar :
22842295
mUI->mActionReportCertC->isChecked() ? ReportType::certC :
22852296
mUI->mActionReportCertCpp->isChecked() ? ReportType::certCpp :
2286-
mUI->mActionReportMisraC->isChecked() ? ReportType::misraC :
2297+
mUI->mActionReportMisraC->isChecked() ? getMisraCReportType(mProjectFile->getCodingStandards()) :
22872298
mUI->mActionReportMisraCpp2008->isChecked() ? ReportType::misraCpp2008 :
22882299
mUI->mActionReportMisraCpp2023->isChecked() ? ReportType::misraCpp2023 :
22892300
ReportType::normal;

gui/projectfiledialog.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@
5959
#include <QSpinBox>
6060
#include <QVariant>
6161

62-
static constexpr char ADDON_MISRA[] = "misra";
63-
static constexpr char CODING_STANDARD_MISRA_C_2023[] = "misra-c-2023";
64-
static constexpr char CODING_STANDARD_MISRA_C_2025[] = "misra-c-2025";
65-
static constexpr char CODING_STANDARD_MISRA_CPP_2008[] = "misra-cpp-2008";
66-
static constexpr char CODING_STANDARD_MISRA_CPP_2023[] = "misra-cpp-2023";
67-
static constexpr char CODING_STANDARD_CERT_C[] = "cert-c-2016";
68-
static constexpr char CODING_STANDARD_CERT_CPP[] = "cert-cpp-2016";
69-
static constexpr char CODING_STANDARD_AUTOSAR[] = "autosar";
62+
constexpr char ADDON_MISRA[] = "misra";
63+
constexpr char CODING_STANDARD_MISRA_C_2023[] = "misra-c-2023";
64+
constexpr char CODING_STANDARD_MISRA_C_2025[] = "misra-c-2025";
65+
constexpr char CODING_STANDARD_MISRA_CPP_2008[] = "misra-cpp-2008";
66+
constexpr char CODING_STANDARD_MISRA_CPP_2023[] = "misra-cpp-2023";
67+
constexpr char CODING_STANDARD_CERT_C[] = "cert-c-2016";
68+
constexpr char CODING_STANDARD_CERT_CPP[] = "cert-cpp-2016";
69+
constexpr char CODING_STANDARD_AUTOSAR[] = "autosar";
7070

7171
/** Return paths from QListWidget */
7272
static QStringList getPaths(const QListWidget *list)

gui/projectfiledialog.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ namespace Ui {
3333
class ProjectFile;
3434
}
3535

36+
extern const char ADDON_MISRA[];
37+
extern const char CODING_STANDARD_MISRA_C_2023[];
38+
extern const char CODING_STANDARD_MISRA_C_2025[];
39+
extern const char CODING_STANDARD_MISRA_CPP_2008[];
40+
extern const char CODING_STANDARD_MISRA_CPP_2023[];
41+
extern const char CODING_STANDARD_CERT_C[];
42+
extern const char CODING_STANDARD_CERT_CPP[];
43+
extern const char CODING_STANDARD_AUTOSAR[];
44+
3645
/// @addtogroup GUI
3746
/// @{
3847

gui/resultstree.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,9 @@ bool ResultsTree::isCertReport() const {
15341534

15351535
bool ResultsTree::isAutosarMisraReport() const {
15361536
return mReportType == ReportType::autosar ||
1537-
mReportType == ReportType::misraC ||
1537+
mReportType == ReportType::misraC2012 ||
1538+
mReportType == ReportType::misraC2023 ||
1539+
mReportType == ReportType::misraC2025 ||
15381540
mReportType == ReportType::misraCpp2008 ||
15391541
mReportType == ReportType::misraCpp2023;
15401542
}

lib/checkers.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ enum class ReportType : std::uint8_t {
3131
autosar = 1,
3232
certC = 2,
3333
certCpp = 3,
34-
misraC = 4,
35-
misraCpp2008 = 5,
36-
misraCpp2023 = 6,
34+
misraC2012 = 4,
35+
misraC2023 = 5,
36+
misraC2025 = 6,
37+
misraCpp2008 = 7,
38+
misraCpp2023 = 8,
3739
};
3840

3941
namespace checkers {

lib/errorlogger.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -945,24 +945,40 @@ std::string getClassification(const std::string &guideline, ReportType reportTyp
945945
return getClassification(checkers::certCInfo, guideline);
946946
case ReportType::certCpp:
947947
return getClassification(checkers::certCppInfo, guideline);
948-
case ReportType::misraC:
948+
case ReportType::misraC2012:
949+
case ReportType::misraC2023:
950+
case ReportType::misraC2025:
949951
{
950-
auto components = splitString(guideline, '.');
952+
const bool isDirective = guideline.find("Dir ") == 0;
953+
954+
const std::size_t offset = isDirective ? 4 : 0;
955+
auto components = splitString(guideline.substr(offset), '.');
951956
if (components.size() != 2)
952957
return "";
953958

954959
const int a = std::stoi(components[0]);
955960
const int b = std::stoi(components[1]);
956961

957-
const std::vector<checkers::MisraInfo> &info = checkers::misraC2012Rules;
958-
const auto it = std::find_if(info.cbegin(), info.cend(), [&](const checkers::MisraInfo &i) {
962+
const std::vector<checkers::MisraInfo> *info = nullptr;
963+
switch (reportType) {
964+
case ReportType::misraC2012:
965+
info = isDirective ? &checkers::misraC2012Directives : &checkers::misraC2012Rules;
966+
break;
967+
case ReportType::misraC2023:
968+
info = isDirective ? &checkers::misraC2023Directives : &checkers::misraC2023Rules;
969+
break;
970+
case ReportType::misraC2025:
971+
info = isDirective ? &checkers::misraC2025Directives : &checkers::misraC2025Rules;
972+
break;
973+
default:
974+
break;
975+
}
976+
977+
const auto it = std::find_if(info->cbegin(), info->cend(), [&](const checkers::MisraInfo &i) {
959978
return i.a == a && i.b == b;
960979
});
961980

962-
if (it == info.cend())
963-
return "";
964-
965-
return it->str;
981+
return it == info->cend() ? "" : it->str;
966982
}
967983
case ReportType::misraCpp2008:
968984
case ReportType::misraCpp2023:
@@ -1022,9 +1038,13 @@ std::string getGuideline(const std::string &errId, ReportType reportType,
10221038
guideline.begin(), static_cast<int (*)(int)>(std::toupper));
10231039
}
10241040
break;
1025-
case ReportType::misraC:
1041+
case ReportType::misraC2012:
1042+
case ReportType::misraC2023:
1043+
case ReportType::misraC2025:
10261044
if (errId.rfind("misra-c20", 0) == 0 || errId.rfind("premium-misra-c-20", 0) == 0)
10271045
guideline = errId.substr(errId.rfind('-') + 1);
1046+
if (errId.find("dir") != std::string::npos)
1047+
guideline = "Dir " + guideline;
10281048
break;
10291049
case ReportType::misraCpp2008:
10301050
if (errId.rfind("misra-cpp-2008-", 0) == 0)
@@ -1074,7 +1094,9 @@ std::map<std::string, std::string> createGuidelineMapping(ReportType reportType)
10741094
idMapping1 = &checkers::idMappingCertC;
10751095
ext1 = "-C";
10761096
break;
1077-
case ReportType::misraC:
1097+
case ReportType::misraC2012:
1098+
case ReportType::misraC2023:
1099+
case ReportType::misraC2025:
10781100
idMapping1 = &checkers::idMappingMisraC;
10791101
break;
10801102
case ReportType::misraCpp2008:

man/cppcheck.1.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ There are false positives with this option. Each result must be carefully invest
594594
<glossentry><glossterm>cert-cpp-2016</glossterm><glossdef><para>Cert C++ 2016</para></glossdef></glossentry>
595595
<glossentry><glossterm>misra-c-2012</glossterm><glossdef><para>Misra C 2012</para></glossdef></glossentry>
596596
<glossentry><glossterm>misra-c-2023</glossterm><glossdef><para>Misra C 2023</para></glossdef></glossentry>
597+
<glossentry><glossterm>misra-c-2025</glossterm><glossdef><para>Misra C 2025</para></glossdef></glossentry>
597598
<glossentry><glossterm>misra-cpp-2008</glossterm><glossdef><para>Misra C++ 2008</para></glossdef></glossentry>
598599
<glossentry><glossterm>misra-cpp-2023</glossterm><glossdef><para>Misra C++ 2023</para></glossdef></glossentry>
599600
</glosslist>

0 commit comments

Comments
 (0)