@@ -2173,38 +2173,107 @@ namespace checkers {
21732173 }
21742174 }
21752175
2176- std::string getGuideline (const std::string &errId, ReportType reportType)
2176+ std::string getGuideline (const std::string &errId, ReportType reportType,
2177+ const std::map<std::string, std::string> &guidelineMapping,
2178+ Severity severity)
21772179 {
2180+ std::string guideline;
2181+
21782182 switch (reportType) {
21792183 case ReportType::autosar:
2180- if (errId.rfind (" premium-autosar-" , 0 ) == 0 )
2181- return errId.substr (16 );
2184+ if (errId.rfind (" premium-autosar-" , 0 ) == 0 ) {
2185+ guideline = errId.substr (16 );
2186+ break ;
2187+ }
21822188 if (errId.rfind (" premium-misra-cpp-2008-" , 0 ) == 0 )
2183- return " M" + errId.substr (23 );
2184- return " " ;
2189+ guideline = " M" + errId.substr (23 );
2190+ break ;
21852191 case ReportType::certC:
21862192 case ReportType::certCpp:
21872193 if (errId.rfind (" premium-cert-" , 0 ) == 0 ) {
2188- std::string guideline = errId.substr (13 );
2194+ guideline = errId.substr (13 );
21892195 std::transform (guideline.begin (), guideline.end (),
21902196 guideline.begin (), static_cast <int (*)(int )>(std::toupper));
2191- return guideline;
21922197 }
2193- return " " ;
2198+ break ;
21942199 case ReportType::misraC:
21952200 if (errId.rfind (" misra-c20" , 0 ) == 0 )
2196- return errId.substr (errId.rfind (' -' ) + 1 );
2197- return " " ;
2201+ guideline = errId.substr (errId.rfind (' -' ) + 1 );
2202+ break ;
21982203 case ReportType::misraCpp2008:
21992204 if (errId.rfind (" misra-cpp-2008-" , 0 ) == 0 )
2200- return errId.substr (15 );
2201- return " " ;
2205+ guideline = errId.substr (15 );
2206+ break ;
22022207 case ReportType::misraCpp2023:
22032208 if (errId.rfind (" misra-cpp-2023-" , 0 ) == 0 )
2204- return errId.substr (15 );
2205- return " " ;
2209+ guideline = errId.substr (15 );
2210+ break ;
22062211 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)
22072224 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 : splitStringVector (i.cppcheckId , ' ,' ))
2268+ guidelineMapping[cppcheckId] = i.guideline + ext1;
22082269 }
2270+
2271+ if (idMapping2) {
2272+ for (const auto &i : *idMapping2)
2273+ for (const std::string &cppcheckId : splitStringVector (i.cppcheckId , ' ,' ))
2274+ guidelineMapping[cppcheckId] = i.guideline + ext2;
2275+ }
2276+
2277+ return guidelineMapping;
22092278 }
22102279}
0 commit comments