3030#include " path.h"
3131#include " pathmatch.h"
3232#include " settings.h"
33+ #include " singleexecutor.h"
3334#include " suppressions.h"
3435#include " utils.h"
36+
3537#include " checkunusedfunctions.h"
3638
3739#if defined(THREADING_MODEL_THREAD)
5153#include < sstream> // IWYU pragma: keep
5254#include < utility>
5355#include < vector>
54- #include < numeric>
5556
5657#ifdef USE_UNIX_SIGNAL_HANDLING
5758#include " cppcheckexecutorsig.h"
@@ -242,7 +243,7 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF
242243 return false ;
243244
244245 bool err = false ;
245- if (settings.jointSuppressionReport ) {
246+ if (settings.useSingleJob () ) {
246247 for (std::map<std::string, std::size_t >::const_iterator i = files.cbegin (); i != files.cend (); ++i) {
247248 err |= errorLogger.reportUnmatchedSuppressions (
248249 settings.nomsg .getUnmatchedLocalSuppressions (i->first , unusedFunctionCheckEnabled));
@@ -310,54 +311,10 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
310311 }
311312
312313 unsigned int returnValue = 0 ;
313- if (settings.jobs == 1 ) {
314+ if (settings.useSingleJob () ) {
314315 // Single process
315- settings.jointSuppressionReport = true ;
316-
317- const std::size_t totalfilesize = std::accumulate (mFiles .cbegin (), mFiles .cend (), std::size_t (0 ), [](std::size_t v, const std::pair<std::string, std::size_t >& f) {
318- return v + f.second ;
319- });
320-
321- std::size_t processedsize = 0 ;
322- unsigned int c = 0 ;
323- if (settings.project .fileSettings .empty ()) {
324- for (std::map<std::string, std::size_t >::const_iterator i = mFiles .cbegin (); i != mFiles .cend (); ++i) {
325- if (!settings.library .markupFile (i->first )
326- || !settings.library .processMarkupAfterCode (i->first )) {
327- returnValue += cppcheck.check (i->first );
328- processedsize += i->second ;
329- if (!settings.quiet )
330- reportStatus (c + 1 , mFiles .size (), processedsize, totalfilesize);
331- c++;
332- }
333- }
334- } else {
335- // filesettings
336- // check all files of the project
337- for (const ImportProject::FileSettings &fs : settings.project .fileSettings ) {
338- returnValue += cppcheck.check (fs);
339- ++c;
340- if (!settings.quiet )
341- reportStatus (c, settings.project .fileSettings .size (), c, settings.project .fileSettings .size ());
342- if (settings.clangTidy )
343- cppcheck.analyseClangTidy (fs);
344- }
345- }
346-
347- // TODO: not performed when multiple jobs are being used
348- // second loop to parse all markup files which may not work until all
349- // c/cpp files have been parsed and checked
350- for (std::map<std::string, std::size_t >::const_iterator i = mFiles .cbegin (); i != mFiles .cend (); ++i) {
351- if (settings.library .markupFile (i->first ) && settings.library .processMarkupAfterCode (i->first )) {
352- returnValue += cppcheck.check (i->first );
353- processedsize += i->second ;
354- if (!settings.quiet )
355- reportStatus (c + 1 , mFiles .size (), processedsize, totalfilesize);
356- c++;
357- }
358- }
359- if (cppcheck.analyseWholeProgram ())
360- returnValue++;
316+ SingleExecutor executor (cppcheck, mFiles , settings, *this );
317+ returnValue = executor.check ();
361318 } else {
362319#if defined(THREADING_MODEL_THREAD)
363320 ThreadExecutor executor (mFiles , settings, *this );
@@ -423,8 +380,10 @@ void CppCheckExecutor::reportErr(const std::string &errmsg)
423380
424381void CppCheckExecutor::reportOut (const std::string &outmsg, Color c)
425382{
426- // TODO: do not unconditionally apply colors
427- std::cout << c << ansiToOEM (outmsg, true ) << Color::Reset << std::endl;
383+ if (c == Color::Reset)
384+ std::cout << ansiToOEM (outmsg, true ) << std::endl;
385+ else
386+ std::cout << toString (c) << ansiToOEM (outmsg, true ) << toString (Color::Reset) << std::endl;
428387}
429388
430389void CppCheckExecutor::reportProgress (const std::string &filename, const char stage[], const std::size_t value)
@@ -450,19 +409,6 @@ void CppCheckExecutor::reportProgress(const std::string &filename, const char st
450409 }
451410}
452411
453- void CppCheckExecutor::reportStatus (std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal)
454- {
455- if (filecount > 1 ) {
456- std::ostringstream oss;
457- const long percentDone = (sizetotal > 0 ) ? static_cast <long >(static_cast <long double >(sizedone) / sizetotal * 100 ) : 0 ;
458- oss << fileindex << ' /' << filecount
459- << " files checked " << percentDone
460- << " % done" ;
461- // TODO: do not unconditionally print in color
462- std::cout << Color::FgBlue << oss.str () << Color::Reset << std::endl;
463- }
464- }
465-
466412void CppCheckExecutor::reportErr (const ErrorMessage &msg)
467413{
468414 if (mShowAllErrors ) {
0 commit comments