Cppcheck
singleexecutor.cpp
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2024 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "singleexecutor.h"
20 
21 #include "cppcheck.h"
22 #include "filesettings.h"
23 #include "settings.h"
24 #include "timer.h"
25 
26 #include <cassert>
27 #include <list>
28 #include <numeric>
29 #include <utility>
30 
31 class ErrorLogger;
32 
33 SingleExecutor::SingleExecutor(CppCheck &cppcheck, const std::list<FileWithDetails> &files, const std::list<FileSettings>& fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger)
34  : Executor(files, fileSettings, settings, suppressions, errorLogger)
35  , mCppcheck(cppcheck)
36 {
37  assert(mSettings.jobs == 1);
38 }
39 
40 // TODO: markup handling is not performed with multiple jobs
41 unsigned int SingleExecutor::check()
42 {
43  unsigned int result = 0;
44 
45  const std::size_t totalfilesize = std::accumulate(mFiles.cbegin(), mFiles.cend(), std::size_t(0), [](std::size_t v, const FileWithDetails& f) {
46  return v + f.size();
47  });
48 
49  std::size_t processedsize = 0;
50  unsigned int c = 0;
51 
52  for (std::list<FileWithDetails>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i) {
53  result += mCppcheck.check(i->path());
54  processedsize += i->size();
55  ++c;
56  if (!mSettings.quiet)
57  reportStatus(c, mFiles.size(), processedsize, totalfilesize);
58  // TODO: call analyseClangTidy()?
59  }
60 
61  // filesettings
62  // check all files of the project
63  for (const FileSettings &fs : mFileSettings) {
64  result += mCppcheck.check(fs);
65  ++c;
66  if (!mSettings.quiet)
67  reportStatus(c, mFileSettings.size(), c, mFileSettings.size());
68  if (mSettings.clangTidy)
70  }
71 
73  result++;
74 
77 
78  return result;
79 }
This is the base class which will use other classes to do static code analysis for C and C++ code to ...
Definition: cppcheck.h:60
bool analyseWholeProgram()
Analyse whole program, run this after all TUs has been scanned.
Definition: cppcheck.cpp:1733
static void printTimerResults(SHOWTIME_MODES mode)
Definition: cppcheck.cpp:1850
unsigned int check(const std::string &path)
This starts the actual checking.
Definition: cppcheck.cpp:542
void analyseClangTidy(const FileSettings &fileSettings)
Analyze all files using clang-tidy.
Definition: cppcheck.cpp:1656
This is an interface, which the class responsible of error logging should implement.
Definition: errorlogger.h:214
This class will take a list of filenames and settings and check then all files using threads.
Definition: executor.h:43
const std::list< FileSettings > & mFileSettings
Definition: executor.h:72
const std::list< FileWithDetails > & mFiles
Definition: executor.h:71
void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal)
Information about how many files have been checked.
Definition: executor.cpp:61
const Settings & mSettings
Definition: executor.h:73
This is just a container for general settings so that we don't need to pass individual values to func...
Definition: settings.h:95
bool quiet
Is –quiet given?
Definition: settings.h:282
bool clangTidy
Use clang-tidy.
Definition: settings.h:156
unsigned int jobs
How many processes/threads should do checking at the same time.
Definition: settings.h:231
SHOWTIME_MODES showtime
show timing information (–showtime=file|summary|top5)
Definition: settings.h:363
SingleExecutor(CppCheck &cppcheck, const std::list< FileWithDetails > &files, const std::list< FileSettings > &fileSettings, const Settings &settings, SuppressionList &suppressions, ErrorLogger &errorLogger)
CppCheck & mCppcheck
unsigned int check() override
class for handling suppressions
Definition: suppressions.h:42
File settings.
Definition: filesettings.h:57