@@ -2097,183 +2097,3 @@ std::vector<checkers::Info> checkers::certCppInfo{
2097
2097
{" MSC53-CPP" , " L2" },
2098
2098
{" MSC54-CPP" , " L2" },
2099
2099
};
2100
-
2101
- namespace checkers {
2102
- std::string getClassification (const std::string &guideline, ReportType reportType) {
2103
- if (guideline.empty ())
2104
- return " " ;
2105
-
2106
- const auto getClassification = [](const std::vector<checkers::Info> &info, const std::string &guideline) -> std::string {
2107
- const auto it = std::find_if (info.cbegin (), info.cend (), [&](const checkers::Info &i) {
2108
- return caseInsensitiveStringCompare (i.guideline , guideline) == 0 ;
2109
- });
2110
- if (it == info.cend ())
2111
- return " " ;
2112
- return it->classification ;
2113
- };
2114
-
2115
- switch (reportType) {
2116
- case ReportType::autosar:
2117
- return getClassification (checkers::autosarInfo, guideline);
2118
- case ReportType::certC:
2119
- return getClassification (checkers::certCInfo, guideline);
2120
- case ReportType::certCpp:
2121
- return getClassification (checkers::certCppInfo, guideline);
2122
- case ReportType::misraC:
2123
- {
2124
- auto components = splitString<std::vector>(guideline, ' .' );
2125
- if (components.size () != 2 )
2126
- return " " ;
2127
-
2128
- const int a = std::stoi (components[0 ]);
2129
- const int b = std::stoi (components[1 ]);
2130
-
2131
- const std::vector<checkers::MisraInfo> &info = checkers::misraC2012Rules;
2132
- const auto it = std::find_if (info.cbegin (), info.cend (), [&](const checkers::MisraInfo &i) {
2133
- return i.a == a && i.b == b;
2134
- });
2135
-
2136
- if (it == info.cend ())
2137
- return " " ;
2138
-
2139
- return it->str ;
2140
- }
2141
- case ReportType::misraCpp2008:
2142
- case ReportType::misraCpp2023:
2143
- {
2144
- char delim;
2145
- const std::vector<checkers::MisraCppInfo> *info;
2146
- if (reportType == ReportType::misraCpp2008) {
2147
- delim = ' -' ;
2148
- info = &checkers::misraCpp2008Rules;
2149
- } else {
2150
- delim = ' .' ;
2151
- info = &checkers::misraCpp2023Rules;
2152
- }
2153
-
2154
- auto components = splitString<std::vector>(guideline, delim);
2155
- if (components.size () != 3 )
2156
- return " " ;
2157
-
2158
- const int a = std::stoi (components[0 ]);
2159
- const int b = std::stoi (components[1 ]);
2160
- const int c = std::stoi (components[2 ]);
2161
-
2162
- const auto it = std::find_if (info->cbegin (), info->cend (), [&](const checkers::MisraCppInfo &i) {
2163
- return i.a == a && i.b == b && i.c == c;
2164
- });
2165
-
2166
- if (it == info->cend ())
2167
- return " " ;
2168
-
2169
- return it->classification ;
2170
- }
2171
- default :
2172
- return " " ;
2173
- }
2174
- }
2175
-
2176
- std::string getGuideline (const std::string &errId, ReportType reportType,
2177
- const std::map<std::string, std::string> &guidelineMapping,
2178
- Severity severity)
2179
- {
2180
- std::string guideline;
2181
-
2182
- switch (reportType) {
2183
- case ReportType::autosar:
2184
- if (errId.rfind (" premium-autosar-" , 0 ) == 0 ) {
2185
- guideline = errId.substr (16 );
2186
- break ;
2187
- }
2188
- if (errId.rfind (" premium-misra-cpp-2008-" , 0 ) == 0 )
2189
- guideline = " M" + errId.substr (23 );
2190
- break ;
2191
- case ReportType::certC:
2192
- case ReportType::certCpp:
2193
- if (errId.rfind (" premium-cert-" , 0 ) == 0 ) {
2194
- guideline = errId.substr (13 );
2195
- std::transform (guideline.begin (), guideline.end (),
2196
- guideline.begin (), static_cast <int (*)(int )>(std::toupper));
2197
- }
2198
- break ;
2199
- case ReportType::misraC:
2200
- if (errId.rfind (" misra-c20" , 0 ) == 0 )
2201
- guideline = errId.substr (errId.rfind (' -' ) + 1 );
2202
- break ;
2203
- case ReportType::misraCpp2008:
2204
- if (errId.rfind (" misra-cpp-2008-" , 0 ) == 0 )
2205
- guideline = errId.substr (15 );
2206
- break ;
2207
- case ReportType::misraCpp2023:
2208
- if (errId.rfind (" misra-cpp-2023-" , 0 ) == 0 )
2209
- guideline = errId.substr (15 );
2210
- break ;
2211
- default :
2212
- break ;
2213
- }
2214
-
2215
- if (!guideline.empty ())
2216
- return guideline;
2217
-
2218
- auto it = guidelineMapping.find (errId);
2219
-
2220
- if (it != guidelineMapping.cend ())
2221
- return it->second ;
2222
-
2223
- if (severity != Severity::error && severity != Severity::warning)
2224
- return " " ;
2225
-
2226
- it = guidelineMapping.find (errId);
2227
-
2228
- if (it != guidelineMapping.cend ())
2229
- return it->second ;
2230
-
2231
- return " " ;
2232
- }
2233
-
2234
- std::map<std::string, std::string> createGuidelineMapping (ReportType reportType) {
2235
- std::map<std::string, std::string> guidelineMapping;
2236
- const std::vector<IdMapping> *idMapping1 = nullptr ;
2237
- const std::vector<IdMapping> *idMapping2 = nullptr ;
2238
- std::string ext1, ext2;
2239
-
2240
- switch (reportType) {
2241
- case ReportType::autosar:
2242
- idMapping1 = &idMappingAutosar;
2243
- break ;
2244
- case ReportType::certCpp:
2245
- idMapping2 = &idMappingCertCpp;
2246
- ext2 = " -CPP" ;
2247
- FALLTHROUGH;
2248
- case ReportType::certC:
2249
- idMapping1 = &idMappingCertC;
2250
- ext1 = " -C" ;
2251
- break ;
2252
- case ReportType::misraC:
2253
- idMapping1 = &idMappingMisraC;
2254
- break ;
2255
- case ReportType::misraCpp2008:
2256
- idMapping1 = &idMappingMisraCpp2008;
2257
- break ;
2258
- case ReportType::misraCpp2023:
2259
- idMapping1 = &idMappingMisraCpp2023;
2260
- break ;
2261
- default :
2262
- break ;
2263
- }
2264
-
2265
- if (idMapping1) {
2266
- for (const auto &i : *idMapping1)
2267
- for (const std::string &cppcheckId : splitString<std::vector>(i.cppcheckId , ' ,' ))
2268
- guidelineMapping[cppcheckId] = i.guideline + ext1;
2269
- }
2270
-
2271
- if (idMapping2) {
2272
- for (const auto &i : *idMapping2)
2273
- for (const std::string &cppcheckId : splitString<std::vector>(i.cppcheckId , ' ,' ))
2274
- guidelineMapping[cppcheckId] = i.guideline + ext2;
2275
- }
2276
-
2277
- return guidelineMapping;
2278
- }
2279
- }
0 commit comments