2020
2121#include " analyzerinfo.h"
2222#include " checkers.h"
23+ #include " checkersreport.h"
2324#include " cmdlineparser.h"
2425#include " color.h"
2526#include " config.h"
@@ -337,60 +338,13 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
337338 return 0 ;
338339}
339340
340- static bool isCppcheckPremium (const Settings& settings) {
341- return (settings.cppcheckCfgProductName .compare (0 , 16 , " Cppcheck Premium" ) == 0 );
342- }
343-
344- static std::string getMisraRuleSeverity (const std::string& rule) {
345- if (checkers::misraRuleSeverity.count (rule) > 0 )
346- return checkers::misraRuleSeverity.at (rule);
347- return " style" ;
348- }
349-
350- static bool isMisraRuleInconclusive (const std::string& rule) {
351- return rule == " 8.3" ;
352- }
353-
354- static bool isMisraRuleActive (const std::string& rule, int amendment, const std::string& severity, const Settings& settings) {
355- if (!isCppcheckPremium (settings) && amendment >= 3 )
356- return false ;
357- const bool inconclusive = isMisraRuleInconclusive (rule);
358- if (inconclusive && !settings.certainty .isEnabled (Certainty::inconclusive))
359- return false ;
360- if (severity == " warning" )
361- return settings.severity .isEnabled (Severity::warning);
362- if (severity == " style" )
363- return settings.severity .isEnabled (Severity::style);
364- return true ; // error severity
365- }
366-
367341void CppCheckExecutor::writeCheckersReport (const Settings& settings) const
368342{
343+ CheckersReport checkersReport (settings, mActiveCheckers );
344+
369345 if (!settings.quiet ) {
370- int activeCheckers = 0 ;
371- int totalCheckers = 0 ;
372- for (const auto & checkReq: checkers::allCheckers) {
373- if (mActiveCheckers .count (checkReq.first ) > 0 )
374- ++activeCheckers;
375- ++totalCheckers;
376- }
377- if (isCppcheckPremium (settings)) {
378- for (const auto & checkReq: checkers::premiumCheckers) {
379- if (mActiveCheckers .count (checkReq.first ) > 0 )
380- ++activeCheckers;
381- ++totalCheckers;
382- }
383- }
384- if (mSettings ->premiumArgs .find (" misra-c-" ) != std::string::npos || mSettings ->addons .count (" misra" )) {
385- for (const checkers::MisraInfo& info: checkers::misraC2012Rules) {
386- const std::string rule = std::to_string (info.a ) + " ." + std::to_string (info.b );
387- const std::string severity = getMisraRuleSeverity (rule);
388- const bool active = isMisraRuleActive (rule, info.amendment , severity, settings);
389- if (active)
390- ++activeCheckers;
391- ++totalCheckers;
392- }
393- }
346+ const int activeCheckers = checkersReport.getActiveCheckersCount ();
347+ const int totalCheckers = checkersReport.getAllCheckersCount ();
394348
395349 const std::string extra = settings.verbose ? " (use --checkers-report=<filename> to see details)" : " " ;
396350 if (mCriticalErrors .empty ())
@@ -403,111 +357,9 @@ void CppCheckExecutor::writeCheckersReport(const Settings& settings) const
403357 return ;
404358
405359 std::ofstream fout (settings.checkersReportFilename );
406- if (! fout.is_open ())
407- return ;
360+ if (fout.is_open ())
361+ fout << checkersReport. getReport ( mCriticalErrors ) ;
408362
409- fout << " Critical errors" << std::endl;
410- fout << " ---------------" << std::endl;
411- if (!mCriticalErrors .empty ()) {
412- fout << " There was critical errors (" << mCriticalErrors << " )" << std::endl;
413- fout << " All checking is skipped for a file with such error" << std::endl;
414- } else {
415- fout << " No critical errors, all files were checked." << std::endl;
416- fout << " Important: Analysis is still not guaranteed to be 'complete' it is possible there are false negatives." << std::endl;
417- }
418-
419- fout << std::endl << std::endl;
420- fout << " Open source checkers" << std::endl;
421- fout << " --------------------" << std::endl;
422-
423- int maxCheckerSize = 0 ;
424- for (const auto & checkReq: checkers::allCheckers) {
425- const std::string& checker = checkReq.first ;
426- if (checker.size () > maxCheckerSize)
427- maxCheckerSize = checker.size ();
428- }
429- for (const auto & checkReq: checkers::allCheckers) {
430- const std::string& checker = checkReq.first ;
431- const bool active = mActiveCheckers .count (checkReq.first ) > 0 ;
432- const std::string& req = checkReq.second ;
433- fout << (active ? " Yes " : " No " ) << checker;
434- if (!active && !req.empty ())
435- fout << std::string (maxCheckerSize + 4 - checker.size (), ' ' ) << " require:" + req;
436- fout << std::endl;
437- }
438-
439- const bool cppcheckPremium = isCppcheckPremium (settings);
440-
441- if (cppcheckPremium) {
442- fout << std::endl << std::endl;
443- fout << " Premium checkers" << std::endl;
444- fout << " ----------------" << std::endl;
445-
446- maxCheckerSize = 0 ;
447- for (const auto & checkReq: checkers::premiumCheckers) {
448- const std::string& checker = checkReq.first ;
449- if (checker.size () > maxCheckerSize)
450- maxCheckerSize = checker.size ();
451- }
452- for (const auto & checkReq: checkers::premiumCheckers) {
453- const std::string& checker = checkReq.first ;
454- std::string req = checkReq.second ;
455- bool active = cppcheckPremium;
456- if (req == " warning" )
457- active &= mSettings ->severity .isEnabled (Severity::warning);
458- else if (req == " style" )
459- active &= mSettings ->severity .isEnabled (Severity::style);
460- fout << (active ? " Yes " : " No " ) << checker;
461- if (!req.empty ())
462- req = " premium," + req;
463- else
464- req = " premium" ;
465- if (!active)
466- fout << std::string (maxCheckerSize + 4 - checker.size (), ' ' ) << " require:" + req;
467- fout << std::endl;
468- }
469- }
470-
471- int misra = 0 ;
472- if (mSettings ->premiumArgs .find (" misra-c-2012" ) != std::string::npos)
473- misra = 2012 ;
474- else if (mSettings ->premiumArgs .find (" misra-c-2023" ) != std::string::npos)
475- misra = 2023 ;
476- else if (mSettings ->addons .count (" misra" ))
477- misra = 2012 ;
478-
479- if (misra == 0 ) {
480- fout << std::endl << std::endl;
481- fout << " Misra C" << std::endl;
482- fout << " -------" << std::endl;
483- fout << " Misra is not enabled" << std::endl;
484- } else {
485- fout << std::endl << std::endl;
486- fout << " Misra C " << misra << std::endl;
487- fout << " ------------" << std::endl;
488- for (const checkers::MisraInfo& info: checkers::misraC2012Rules) {
489- const std::string rule = std::to_string (info.a ) + " ." + std::to_string (info.b );
490- const std::string severity = getMisraRuleSeverity (rule);
491- const bool active = isMisraRuleActive (rule, info.amendment , severity, settings);
492- const bool inconclusive = isMisraRuleInconclusive (rule);
493- fout << (active ? " Yes " : " No " ) << rule;
494- std::string extra;
495- if (misra == 2012 && info.amendment >= 1 )
496- extra = " amendment:" + std::to_string (info.amendment );
497- std::string reqs;
498- if (info.amendment >= 3 )
499- reqs += " ,premium" ;
500- if (severity != " error" )
501- reqs += " ," + severity;
502- if (inconclusive)
503- reqs += " ,inconclusive" ;
504- if (!active && !reqs.empty ())
505- extra += " require:" + reqs.substr (1 );
506- if (!extra.empty ())
507- fout << std::string (7 - rule.size (), ' ' ) << extra;
508- fout << ' \n ' ;
509- }
510- }
511363}
512364
513365bool CppCheckExecutor::loadLibraries (Settings& settings)
@@ -607,7 +459,7 @@ void CppCheckExecutor::reportErr(const ErrorMessage &msg)
607459{
608460 assert (mSettings != nullptr );
609461
610- if (msg.severity == Severity::none && msg.id == " logChecker" ) {
462+ if (msg.severity == Severity::none && ( msg.id == " logChecker" || endsWith (msg. id , " -logChecker " )) ) {
611463 const std::string& checker = msg.shortMessage ();
612464 mActiveCheckers .emplace (checker);
613465 return ;
0 commit comments