Skip to content

Commit c31bc0e

Browse files
committed
add separate report types for misra C editions
1 parent e006e02 commit c31bc0e

4 files changed

Lines changed: 45 additions & 15 deletions

File tree

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"

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)